From 31edb4775aae66fb71aa100cea14f4fc0ee41a77 Mon Sep 17 00:00:00 2001 From: "geng.tang@qq.com" Date: Tue, 2 Jan 2024 21:33:52 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=94=B9=E9=80=A0=E7=9F=AD=E4=BF=A1?= =?UTF-8?q?=E5=8F=91=E9=80=81=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 ++ .../com/gxwebsoft/apps/task/OrderTask.java | 59 +++++++++++++++ .../common/core/config/ConfigProperties.java | 3 + .../common/core/constants/OrderConstants.java | 4 +- .../gxwebsoft/common/core/enums/ESmsType.java | 18 +++++ .../exception/GlobalExceptionHandler.java | 28 +++++-- .../common/core/utils/AlipayConfigUtil.java | 6 +- .../gxwebsoft/common/core/web/ApiResult.java | 8 ++ .../controller/AccessKeyController.java | 3 +- .../system/controller/MainController.java | 73 ++++++++++--------- .../common/system/param/SmsCaptchaParam.java | 30 ++++++-- .../common/system/service/AliSmsService.java | 23 ++++++ .../common/system/service/SettingService.java | 2 + .../service/impl/AliSmsServiceImpl.java | 72 ++++++++++++++++++ .../service/impl/SettingServiceImpl.java | 27 +++++++ .../controller/OpenEquipmentController.java | 66 ++++++++++++++--- .../open/controller/OpenMainController.java | 3 +- .../shop/controller/PaymentController.java | 73 ++++++++++++++----- .../java/com/gxwebsoft/shop/entity/Order.java | 21 +++++- .../com/gxwebsoft/shop/entity/OrderPay.java | 16 +++- .../gxwebsoft/shop/mapper/MerchantMapper.java | 4 +- .../gxwebsoft/shop/mapper/OrderMapper.java | 23 ++++++ .../gxwebsoft/shop/mapper/OrderPayMapper.java | 8 ++ .../shop/param/OrderReceiptParam.java | 41 +++++++++++ .../shop/service/OrderPayService.java | 6 ++ .../gxwebsoft/shop/service/OrderService.java | 14 +++- .../service/impl/MerchantServiceImpl.java | 5 +- .../service/impl/OrderPayServiceImpl.java | 4 + .../shop/service/impl/OrderServiceImpl.java | 52 +++++++++---- src/main/resources/application-dev.yml | 16 ++-- src/main/resources/application-prod.yml | 7 +- src/main/resources/application.yml | 14 +++- 32 files changed, 623 insertions(+), 111 deletions(-) create mode 100644 src/main/java/com/gxwebsoft/common/core/enums/ESmsType.java create mode 100644 src/main/java/com/gxwebsoft/common/system/service/AliSmsService.java create mode 100644 src/main/java/com/gxwebsoft/common/system/service/impl/AliSmsServiceImpl.java create mode 100644 src/main/java/com/gxwebsoft/shop/param/OrderReceiptParam.java diff --git a/pom.xml b/pom.xml index c2498f5..e2b107c 100644 --- a/pom.xml +++ b/pom.xml @@ -58,6 +58,11 @@ true + + org.springframework.boot + spring-boot-starter-validation + + org.projectlombok diff --git a/src/main/java/com/gxwebsoft/apps/task/OrderTask.java b/src/main/java/com/gxwebsoft/apps/task/OrderTask.java index 68735f9..abf3690 100644 --- a/src/main/java/com/gxwebsoft/apps/task/OrderTask.java +++ b/src/main/java/com/gxwebsoft/apps/task/OrderTask.java @@ -1,6 +1,7 @@ package com.gxwebsoft.apps.task; import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUnit; @@ -12,9 +13,11 @@ import com.alipay.api.AlipayClient; import com.alipay.api.DefaultAlipayClient; import com.alipay.api.request.AlipayTradeOrderinfoSyncRequest; import com.alipay.api.response.AlipayTradeOrderinfoSyncResponse; +import com.aliyuncs.exceptions.ClientException; import com.baomidou.mybatisplus.annotation.InterceptorIgnore; import com.baomidou.mybatisplus.annotation.SqlParser; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.BeanUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; @@ -26,8 +29,12 @@ import com.gxwebsoft.apps.service.EquipmentGoodsService; import com.gxwebsoft.apps.service.EquipmentOrderGoodsService; import com.gxwebsoft.apps.service.EquipmentService; import com.gxwebsoft.common.core.config.MybatisPlusConfig; +import com.gxwebsoft.common.core.enums.ESmsType; import com.gxwebsoft.common.core.utils.AlipayConfigUtil; +import com.gxwebsoft.common.core.web.ApiResult; import com.gxwebsoft.common.system.entity.User; +import com.gxwebsoft.common.system.param.SmsCaptchaParam; +import com.gxwebsoft.common.system.service.AliSmsService; import com.gxwebsoft.common.system.service.UserService; import com.gxwebsoft.love.entity.UserPlanLog; import com.gxwebsoft.love.param.UserPlanLogParam; @@ -44,6 +51,7 @@ import org.springframework.util.NumberUtils; import javax.annotation.Resource; import java.math.BigDecimal; import java.text.SimpleDateFormat; +import java.time.LocalDate; import java.util.*; import java.util.stream.Collectors; @@ -85,6 +93,9 @@ public class OrderTask { private FreezeOrderService freezeOrderService; @Resource private OrderPayService orderPayService; + @Resource + private AliSmsService aliSmsService; + /** * 计算逾期 @@ -420,4 +431,52 @@ public class OrderTask { orderPayService.update(updateWrapper); } + + /** + * 逾期预警 + */ + @Scheduled(cron = "0 30 9 * * ? ") + public void exceedAlert() { + List alertList = orderService.findAlertList(); + if(CollectionUtil.isNotEmpty(alertList)){ + log.info("开始发送订单到期预警通知!"); + int succ = 0; + for(Order order : alertList){ + SmsCaptchaParam aram = SmsCaptchaParam.builder() + .phone(order.getPhone()) + .type(ESmsType.ALERT.name()) + .templateParam("{\"code\":" + Math.abs(order.getExpirationDay()) + "}") + .build(); + try{ + ApiResult ret = aliSmsService.sendSms(aram); + if(ret.isOk()) + succ++; + } catch (ClientException e){ + log.error(e.getMessage(), e); + } + } + log.info("发送订单到期预警通知结束!总数{}条,成功{}条!", alertList.size(), succ); + } + + List overdueList = orderService.findAlertList(); + if(CollectionUtil.isNotEmpty(overdueList)) { + log.info("开始发送订单超期提醒通知!"); + int succ = 0; + for(Order order : alertList){ + SmsCaptchaParam aram = SmsCaptchaParam.builder() + .phone(order.getPhone()) + .type(ESmsType.OVERDUE.name()) + .templateParam("{\"code\":" + order.getExpirationDay() + "}") + .build(); + try{ + ApiResult ret = aliSmsService.sendSms(aram); + if(ret.isOk()) + succ++; + } catch (ClientException e){ + log.error(e.getMessage(), e); + } + } + log.info("发送逾期提醒通知结束!总数{}条,成功{}条!", alertList.size(), succ); + } + } } diff --git a/src/main/java/com/gxwebsoft/common/core/config/ConfigProperties.java b/src/main/java/com/gxwebsoft/common/core/config/ConfigProperties.java index dfee5d3..9b4c68d 100644 --- a/src/main/java/com/gxwebsoft/common/core/config/ConfigProperties.java +++ b/src/main/java/com/gxwebsoft/common/core/config/ConfigProperties.java @@ -1,5 +1,6 @@ package com.gxwebsoft.common.core.config; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -102,4 +103,6 @@ public class ConfigProperties { private String bucketName; private String bucketDomain; + @ApiModelProperty("项目默认租户") + private Integer tenantId; } diff --git a/src/main/java/com/gxwebsoft/common/core/constants/OrderConstants.java b/src/main/java/com/gxwebsoft/common/core/constants/OrderConstants.java index 9ddac40..7f149f8 100644 --- a/src/main/java/com/gxwebsoft/common/core/constants/OrderConstants.java +++ b/src/main/java/com/gxwebsoft/common/core/constants/OrderConstants.java @@ -8,8 +8,8 @@ public class OrderConstants { public static final String PAY_METHOD_OTHER = "40"; // 其他支付 // 付款状态 - public static final Integer PAY_STATUS_NO_PAY = 10; // 未付款 - public static final Integer PAY_STATUS_SUCCESS = 20; // 已付款 + public static final int PAY_STATUS_NO_PAY = 10; // 未付款 + public static final int PAY_STATUS_SUCCESS = 20; // 已付款 // 发货状态 public static final Integer DELIVERY_STATUS_NO = 10; // 未发货 diff --git a/src/main/java/com/gxwebsoft/common/core/enums/ESmsType.java b/src/main/java/com/gxwebsoft/common/core/enums/ESmsType.java new file mode 100644 index 0000000..a5fb09e --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/core/enums/ESmsType.java @@ -0,0 +1,18 @@ +package com.gxwebsoft.common.core.enums; + +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter +public enum ESmsType { + LOGIN("SMS_290002047"), + RECEIPT("SMS_290002047"), + ALERT("SMS_464505085"), + OVERDUE("SMS_464525076"); + + @ApiModelProperty("短信模版编号") + private String templateId; + +} diff --git a/src/main/java/com/gxwebsoft/common/core/exception/GlobalExceptionHandler.java b/src/main/java/com/gxwebsoft/common/core/exception/GlobalExceptionHandler.java index 6649a2d..1031957 100644 --- a/src/main/java/com/gxwebsoft/common/core/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/gxwebsoft/common/core/exception/GlobalExceptionHandler.java @@ -3,15 +3,23 @@ package com.gxwebsoft.common.core.exception; import com.gxwebsoft.common.core.Constants; import com.gxwebsoft.common.core.utils.CommonUtil; import com.gxwebsoft.common.core.web.ApiResult; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.access.AccessDeniedException; +import org.springframework.validation.ObjectError; import org.springframework.web.HttpRequestMethodNotSupportedException; +import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestControllerAdvice; import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; /** * 全局异常处理器 @@ -19,11 +27,10 @@ import javax.servlet.http.HttpServletResponse; * @author WebSoft * @since 2018-02-22 11:29:30 */ -@ControllerAdvice +@RestControllerAdvice +@Slf4j public class GlobalExceptionHandler { - private final Logger logger = LoggerFactory.getLogger(getClass()); - @ResponseBody @ExceptionHandler(HttpRequestMethodNotSupportedException.class) public ApiResult methodNotSupportedExceptionHandler(HttpRequestMethodNotSupportedException e, HttpServletResponse response) { @@ -31,26 +38,33 @@ public class GlobalExceptionHandler { return new ApiResult<>(Constants.RESULT_ERROR_CODE, "请求方式不正确").setError(e.toString()); } - @ResponseBody @ExceptionHandler(AccessDeniedException.class) public ApiResult accessDeniedExceptionHandler(AccessDeniedException e, HttpServletResponse response) { CommonUtil.addCrossHeaders(response); return new ApiResult<>(Constants.UNAUTHORIZED_CODE, Constants.UNAUTHORIZED_MSG).setError(e.toString()); } - @ResponseBody @ExceptionHandler(BusinessException.class) public ApiResult businessExceptionHandler(BusinessException e, HttpServletResponse response) { CommonUtil.addCrossHeaders(response); return new ApiResult<>(e.getCode(), e.getMessage()); } - @ResponseBody @ExceptionHandler(Throwable.class) public ApiResult exceptionHandler(Throwable e, HttpServletResponse response) { - logger.error(e.getMessage(), e); + log.error(e.getMessage(), e); CommonUtil.addCrossHeaders(response); return new ApiResult<>(Constants.RESULT_ERROR_CODE, Constants.RESULT_ERROR_MSG).setError(e.toString()); } + @ExceptionHandler(value = MethodArgumentNotValidException.class) + @ResponseBody + public ApiResult MethodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) + { + //获取实体类定义的校验注解字段上的message作为异常信息,@NotBlank(message = "用户密码不能为空!")异常信息即为"用户密码不能为空!" + List allErrors = e.getBindingResult().getAllErrors(); + String message = allErrors.stream().map(s -> s.getDefaultMessage()).collect(Collectors.joining(";")); + List msgList = Arrays.asList(message.split(";")); + return new ApiResult<>(Constants.RESULT_ERROR_CODE, msgList.get(0)); + } } diff --git a/src/main/java/com/gxwebsoft/common/core/utils/AlipayConfigUtil.java b/src/main/java/com/gxwebsoft/common/core/utils/AlipayConfigUtil.java index 9b92078..cbb44ed 100644 --- a/src/main/java/com/gxwebsoft/common/core/utils/AlipayConfigUtil.java +++ b/src/main/java/com/gxwebsoft/common/core/utils/AlipayConfigUtil.java @@ -10,6 +10,7 @@ import com.gxwebsoft.common.core.config.ConfigProperties; import com.gxwebsoft.common.core.exception.BusinessException; import com.gxwebsoft.common.system.entity.Setting; import com.gxwebsoft.common.system.service.SettingService; +import lombok.extern.slf4j.Slf4j; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; @@ -20,6 +21,7 @@ import javax.annotation.Resource; * @author leng * */ +@Slf4j @Component public class AlipayConfigUtil { private final StringRedisTemplate stringRedisTemplate; @@ -34,6 +36,7 @@ public class AlipayConfigUtil { @Resource private ConfigProperties pathConfig; + @Resource private SettingService settingService; public AlipayConfigUtil(StringRedisTemplate stringRedisTemplate){ @@ -69,9 +72,8 @@ public class AlipayConfigUtil { * 获取支付宝秘钥 */ public JSONObject payment(Integer tenantId) { - System.out.println("tenantId = " + tenantId); String key = "setting:payment:" + tenantId; - System.out.println("key = " + key); + log.info("tenantId:{}, redis key:{}",tenantId, key); String cache = stringRedisTemplate.opsForValue().get(key); if (cache == null) { Setting payment = settingService.getData("payment"); diff --git a/src/main/java/com/gxwebsoft/common/core/web/ApiResult.java b/src/main/java/com/gxwebsoft/common/core/web/ApiResult.java index eab091a..52f96ad 100644 --- a/src/main/java/com/gxwebsoft/common/core/web/ApiResult.java +++ b/src/main/java/com/gxwebsoft/common/core/web/ApiResult.java @@ -1,6 +1,7 @@ package com.gxwebsoft.common.core.web; import com.fasterxml.jackson.annotation.JsonInclude; +import com.gxwebsoft.common.core.Constants; import io.swagger.annotations.ApiModelProperty; import java.io.Serializable; @@ -37,6 +38,10 @@ public class ApiResult implements Serializable { this(code, message, null); } + public ApiResult(String message) { + this(Constants.RESULT_OK_CODE, message, null); + } + public ApiResult(Integer code, String message, T data) { this(code, message, data, null); } @@ -84,4 +89,7 @@ public class ApiResult implements Serializable { return this; } + public boolean isOk(){ + return this.code == Constants.RESULT_OK_CODE; + } } diff --git a/src/main/java/com/gxwebsoft/common/system/controller/AccessKeyController.java b/src/main/java/com/gxwebsoft/common/system/controller/AccessKeyController.java index d80c9b9..bf6df69 100644 --- a/src/main/java/com/gxwebsoft/common/system/controller/AccessKeyController.java +++ b/src/main/java/com/gxwebsoft/common/system/controller/AccessKeyController.java @@ -2,6 +2,7 @@ package com.gxwebsoft.common.system.controller; import cn.hutool.core.util.StrUtil; import com.gxwebsoft.common.core.annotation.OperationLog; +import com.gxwebsoft.common.core.enums.ESmsType; import com.gxwebsoft.common.core.utils.CacheClient; import com.gxwebsoft.common.core.utils.CommonUtil; import com.gxwebsoft.common.core.web.*; @@ -40,7 +41,7 @@ public class AccessKeyController extends BaseController { final PageResult accessKeyPageResult = accessKeyService.pageRel(param); if (param.getCode() != null) { // 短信验证码校验 - String code = cacheClient.get(param.getPhone(), String.class); + String code = cacheClient.get(ESmsType.LOGIN.name() + ":" + param.getPhone(), String.class); if (StrUtil.equals(code,param.getCode())) { return success(accessKeyPageResult); } diff --git a/src/main/java/com/gxwebsoft/common/system/controller/MainController.java b/src/main/java/com/gxwebsoft/common/system/controller/MainController.java index 851dd1f..55e2872 100644 --- a/src/main/java/com/gxwebsoft/common/system/controller/MainController.java +++ b/src/main/java/com/gxwebsoft/common/system/controller/MainController.java @@ -7,13 +7,13 @@ import com.aliyuncs.CommonResponse; import com.aliyuncs.DefaultAcsClient; import com.aliyuncs.IAcsClient; import com.aliyuncs.exceptions.ClientException; -import com.aliyuncs.exceptions.ServerException; import com.aliyuncs.http.MethodType; import com.aliyuncs.profile.DefaultProfile; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.google.gson.Gson; import com.gxwebsoft.common.core.annotation.OperationLog; import com.gxwebsoft.common.core.config.ConfigProperties; +import com.gxwebsoft.common.core.enums.ESmsType; import com.gxwebsoft.common.core.security.JwtSubject; import com.gxwebsoft.common.core.security.JwtUtil; import com.gxwebsoft.common.core.utils.CacheClient; @@ -31,18 +31,23 @@ import com.gxwebsoft.common.system.param.UpdatePasswordParam; import com.gxwebsoft.common.system.result.CaptchaResult; import com.gxwebsoft.common.system.result.LoginResult; import com.gxwebsoft.common.system.service.AccessKeyService; +import com.gxwebsoft.common.system.service.AliSmsService; import com.gxwebsoft.common.system.service.LoginRecordService; import com.gxwebsoft.common.system.service.RoleMenuService; import com.gxwebsoft.common.system.service.UserService; import com.wf.captcha.SpecCaptcha; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.RandomStringUtils; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.HashMap; @@ -59,6 +64,7 @@ import java.util.concurrent.TimeUnit; @Api(tags = "登录认证") @RestController @RequestMapping("/api") +@Slf4j public class MainController extends BaseController { @Resource private ConfigProperties configProperties; @@ -71,9 +77,9 @@ public class MainController extends BaseController { @Resource private CacheClient cacheClient; @Resource - private StringRedisTemplate stringRedisTemplate; - @Resource private AccessKeyService accessKeyService; + @Resource + private AliSmsService aliSmsService; @ApiOperation("用户登录") @PostMapping("/login") @@ -205,41 +211,36 @@ public class MainController extends BaseController { @ApiOperation("短信验证码") @PostMapping("/sendSmsCaptcha") - public ApiResult sendSmsCaptcha(@RequestBody SmsCaptchaParam param) { - DefaultProfile profile = DefaultProfile.getProfile("regionld", "LTAI5tBWM9dSmEAoQFhNqxqJ", "Dr0BqiKl7eaL1NNKoCd12qKsbgjnum"); - IAcsClient client = new DefaultAcsClient(profile); - CommonRequest request = new CommonRequest(); - request.setSysMethod(MethodType.POST); - request.setSysDomain("dysmsapi.aliyuncs.com"); - request.setSysVersion("2017-05-25"); - request.setSysAction("SendSms"); - request.putQueryParameter("RegionId", "cn-hangzhou"); - request.putQueryParameter("PhoneNumbers", param.getPhone()); - request.putQueryParameter("SignName", "南宁网宿科技"); - request.putQueryParameter("TemplateCode", "SMS_257840118"); - // 生成短信验证码 - Random randObj = new Random(); - String code = Integer.toString(100000 + randObj.nextInt(900000)); - request.putQueryParameter("TemplateParam", "{\"code\":" + code + "}"); - try { - CommonResponse response = client.getCommonResponse(request); - String json = response.getData(); - Gson g = new Gson(); - HashMap result = g.fromJson(json, HashMap.class); - if("OK".equals(result.get("Message"))) { - cacheClient.set(param.getPhone(),code,5L,TimeUnit.MINUTES); - return success("发送成功",result.get("Message")); - }else{ - return fail("发送失败"); + public ApiResult sendSmsCaptcha(@RequestBody @Valid SmsCaptchaParam param) { + try { +// User user = getLoginUser(); +// param.setTenantId(user.getTenantId()); + + String code = RandomStringUtils.randomNumeric(6); + param.setTemplateParam("{\"code\":" + code + "}"); + ApiResult ret = aliSmsService.sendSms(param); + if(ret.isOk()){ + ESmsType type = ESmsType.valueOf(param.getType()); + cacheClient.set(type.name() + ":" + param.getPhone(), code,5L,TimeUnit.MINUTES); + } + return success(ret); + } catch (ClientException e) { + log.error(e.getMessage(), e); + return fail("发送出错!"); } - } catch (ServerException e) { - e.printStackTrace(); - } catch (ClientException e) { - e.printStackTrace(); - } - return fail("发送失败"); } +// @ApiOperation("预警短信") +// @PostMapping("/sendSmsAlert") +// public ApiResult sendSmsAlert(@RequestBody SmsCaptchaParam param) { +// try { +// return aliSmsService.sendSms(param); +// } catch (ClientException e) { +// log.error(e.getMessage(), e); +// return fail("发送出错!"); +// } +// } + @OperationLog @ApiOperation("重置密码") @PutMapping("/password") @@ -251,7 +252,7 @@ public class MainController extends BaseController { return fail("验证码不能为空"); } // 短信验证码校验 - String code = cacheClient.get(user.getPhone(), String.class); + String code = cacheClient.get(ESmsType.LOGIN.name() + ":" + user.getPhone(), String.class); if (!StrUtil.equals(code,user.getCode())) { return fail("验证码不正确"); } diff --git a/src/main/java/com/gxwebsoft/common/system/param/SmsCaptchaParam.java b/src/main/java/com/gxwebsoft/common/system/param/SmsCaptchaParam.java index 765b9eb..eaae8ad 100644 --- a/src/main/java/com/gxwebsoft/common/system/param/SmsCaptchaParam.java +++ b/src/main/java/com/gxwebsoft/common/system/param/SmsCaptchaParam.java @@ -1,10 +1,17 @@ package com.gxwebsoft.common.system.param; import com.fasterxml.jackson.annotation.JsonInclude; +import com.gxwebsoft.common.core.enums.ESmsType; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.validation.annotation.Validated; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Pattern; import java.io.Serializable; /** @@ -14,18 +21,29 @@ import java.io.Serializable; * @since 2021-08-30 17:35:16 */ @Data -@JsonInclude(JsonInclude.Include.NON_NULL) +//@JsonInclude(JsonInclude.Include.NON_NULL) @ApiModel(description = "发送短信验证码参数") +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Validated public class SmsCaptchaParam implements Serializable { private static final long serialVersionUID = 1L; - @ApiModelProperty("短信签名") - private String signName; +// @ApiModelProperty("短信签名") +// private String signName; - @ApiModelProperty("手机号码") + @ApiModelProperty(value = "手机号码", required = true) + @NotBlank(message = "手机号码不能为空!") + @Pattern(regexp = "^[1][3,4,5,6,7,8,9][0-9]{9}$", message = "手机号格式有误") private String phone; - @ApiModelProperty("短信模板") - private String TemplateParam; + @ApiModelProperty("短信模板参数") + private String templateParam; + @ApiModelProperty("验证码类型") + private String type = ESmsType.LOGIN.name(); + + @ApiModelProperty(value = "租户id", hidden = true) + private Integer tenantId; } diff --git a/src/main/java/com/gxwebsoft/common/system/service/AliSmsService.java b/src/main/java/com/gxwebsoft/common/system/service/AliSmsService.java new file mode 100644 index 0000000..5b842b1 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/service/AliSmsService.java @@ -0,0 +1,23 @@ +package com.gxwebsoft.common.system.service; + + +import com.aliyuncs.exceptions.ClientException; +import com.gxwebsoft.common.core.web.ApiResult; +import com.gxwebsoft.common.system.param.SmsCaptchaParam; + +/** + * 阿里短信服务层 + * + * @author WebSoft + * @since 2018-12-24 16:10:41 + */ +public interface AliSmsService { + + /** + * 发送阿里短信 + * @param param + * @return + */ + ApiResult sendSms(SmsCaptchaParam param) throws ClientException; + +} diff --git a/src/main/java/com/gxwebsoft/common/system/service/SettingService.java b/src/main/java/com/gxwebsoft/common/system/service/SettingService.java index 9432620..ff8a590 100644 --- a/src/main/java/com/gxwebsoft/common/system/service/SettingService.java +++ b/src/main/java/com/gxwebsoft/common/system/service/SettingService.java @@ -50,6 +50,8 @@ public interface SettingService extends IService { Setting getData(String settingKey); + String getContent(String settingKey, Integer tenantId); + JSONObject getCache(String key); void initConfig(Setting setting); diff --git a/src/main/java/com/gxwebsoft/common/system/service/impl/AliSmsServiceImpl.java b/src/main/java/com/gxwebsoft/common/system/service/impl/AliSmsServiceImpl.java new file mode 100644 index 0000000..ce30152 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/service/impl/AliSmsServiceImpl.java @@ -0,0 +1,72 @@ +package com.gxwebsoft.common.system.service.impl; + +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.aliyuncs.CommonRequest; +import com.aliyuncs.CommonResponse; +import com.aliyuncs.DefaultAcsClient; +import com.aliyuncs.IAcsClient; +import com.aliyuncs.exceptions.ClientException; +import com.aliyuncs.http.MethodType; +import com.aliyuncs.profile.DefaultProfile; +import com.google.gson.Gson; +import com.gxwebsoft.common.core.Constants; +import com.gxwebsoft.common.core.config.ConfigProperties; +import com.gxwebsoft.common.core.enums.ESmsType; +import com.gxwebsoft.common.core.web.ApiResult; +import com.gxwebsoft.common.system.param.SmsCaptchaParam; +import com.gxwebsoft.common.system.service.AliSmsService; +import com.gxwebsoft.common.system.service.SettingService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.HashMap; + +@Service +@Slf4j +@RequiredArgsConstructor +public class AliSmsServiceImpl implements AliSmsService { + private final SettingService settingService; + private final ConfigProperties configProperties; + @Override + public ApiResult sendSms(SmsCaptchaParam param) throws ClientException { + Integer tenantId = param.getTenantId(); + if(null == tenantId){ + tenantId = configProperties.getTenantId(); + } + String smsConfig = settingService.getContent("sms", tenantId); + if(StrUtil.isBlank(smsConfig)){ + return new ApiResult(Constants.RESULT_ERROR_CODE, "短信参数未配置!"); + } + JSONObject smsConfigJson = JSON.parseObject(smsConfig); + + DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", smsConfigJson.getString("accessKeyId"), smsConfigJson.getString("accessKeySecret")); + IAcsClient client = new DefaultAcsClient(profile); + String signName = smsConfigJson.getString("sign"); + + ESmsType type = ESmsType.valueOf(param.getType()); + CommonRequest request = new CommonRequest(); + request.setSysMethod(MethodType.POST); + request.setSysDomain("dysmsapi.aliyuncs.com"); + request.setSysVersion("2017-05-25"); + request.setSysAction("SendSms"); + request.putQueryParameter("RegionId", "cn-hangzhou"); + String phone = param.getPhone(); + request.putQueryParameter("PhoneNumbers", phone); + request.putQueryParameter("SignName", signName); + request.putQueryParameter("TemplateCode", type.getTemplateId()); + request.putQueryParameter("TemplateParam", param.getTemplateParam()); + + CommonResponse response = client.getCommonResponse(request); + String json = response.getData(); + Gson g = new Gson(); + HashMap result = g.fromJson(json, HashMap.class); + if("OK".equals(result.get("Message"))) { + return new ApiResult("发送成功"); + } + log.warn("阿里云短信发送失败!{}", json); + return new ApiResult(Constants.RESULT_ERROR_CODE, "发送失败"); + } +} diff --git a/src/main/java/com/gxwebsoft/common/system/service/impl/SettingServiceImpl.java b/src/main/java/com/gxwebsoft/common/system/service/impl/SettingServiceImpl.java index 702c265..464d83f 100644 --- a/src/main/java/com/gxwebsoft/common/system/service/impl/SettingServiceImpl.java +++ b/src/main/java/com/gxwebsoft/common/system/service/impl/SettingServiceImpl.java @@ -1,5 +1,6 @@ package com.gxwebsoft.common.system.service.impl; +import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -99,6 +100,32 @@ public class SettingServiceImpl extends ServiceImpl impl return query().eq("setting_key", settingKey).one(); } + @Override + public String getContent(String settingKey, Integer tenantId) { + String redisKey = settingKey + ":"; + if(null != tenantId){ + redisKey += tenantId; + } else { + redisKey += -1; + } + if(stringRedisTemplate.hasKey(redisKey)){ + return stringRedisTemplate.opsForValue().get(redisKey); + } + + Setting setting = query().eq("setting_key", settingKey) + .eq(null != tenantId, "tenant_id", tenantId) + .eq("deleted", 0) + .orderByDesc("setting_id") + .last("limit 1") + .one(); + if(null == setting){ + return ""; + } + String ret = setting.getContent(); + stringRedisTemplate.opsForValue().set(redisKey, ret); + return ret; + } + @Override public JSONObject getCache(String key) { final String cache = stringRedisTemplate.opsForValue().get(key); diff --git a/src/main/java/com/gxwebsoft/open/controller/OpenEquipmentController.java b/src/main/java/com/gxwebsoft/open/controller/OpenEquipmentController.java index cd263de..c3ea0e9 100644 --- a/src/main/java/com/gxwebsoft/open/controller/OpenEquipmentController.java +++ b/src/main/java/com/gxwebsoft/open/controller/OpenEquipmentController.java @@ -1,6 +1,9 @@ package com.gxwebsoft.open.controller; +import cn.hutool.core.bean.copier.BeanCopier; +import cn.hutool.core.bean.copier.CopyOptions; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONObject; import com.alipay.api.AlipayApiException; import com.alipay.api.DefaultAlipayClient; @@ -14,7 +17,9 @@ import com.gxwebsoft.apps.param.EquipmentParam; import com.gxwebsoft.apps.service.EquipmentRecordService; import com.gxwebsoft.apps.service.EquipmentService; import com.gxwebsoft.common.core.annotation.OperationLog; +import com.gxwebsoft.common.core.enums.ESmsType; import com.gxwebsoft.common.core.utils.AlipayConfigUtil; +import com.gxwebsoft.common.core.utils.CacheClient; import com.gxwebsoft.common.core.utils.ImageUtil; import com.gxwebsoft.common.core.web.*; import com.gxwebsoft.common.system.entity.User; @@ -24,6 +29,7 @@ import com.gxwebsoft.shop.entity.Order; import com.gxwebsoft.shop.entity.OrderPay; import com.gxwebsoft.shop.entity.OrderRefund; import com.gxwebsoft.shop.param.OrderParam; +import com.gxwebsoft.shop.param.OrderReceiptParam; import com.gxwebsoft.shop.service.OrderPayService; import com.gxwebsoft.shop.service.OrderRefundService; import com.gxwebsoft.shop.service.OrderService; @@ -34,6 +40,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; @@ -76,6 +83,9 @@ public class OpenEquipmentController extends BaseController { @Resource private RestTemplate restTemplate; + @Resource + private CacheClient cacheClient; + @PreAuthorize("hasAuthority('apps:equipment:list')") @OperationLog @ApiOperation("分页查询设备管理") @@ -373,10 +383,53 @@ public class OpenEquipmentController extends BaseController { return fail("换电失败"); } - @ApiOperation("重置") + @ApiOperation("确认收货") + @PostMapping("/receipt") + public ApiResult receipt(@RequestBody @Validated OrderReceiptParam receiptParam) { + // 验证签名 + isCheckSign(); + + Order order = orderService.getById(receiptParam.getOrderId()); + Integer receiptStatus = order.getReceiptStatus(); + if(receiptStatus == 20){ + return fail("订单已确认收货,不能重复确认!"); + } + // 验证身份证真实性 + if(StringUtils.hasText(receiptParam.getOrderSourceData())) { + String orderSourceDataString = receiptParam.getOrderSourceData(); + List images = JSONObject.parseArray(orderSourceDataString, String.class); + String front = ImageUtil.ImageBase64(images.get(0) + "?x-oss-process=image/resize,w_750/quality,Q_80"); + + String back = ImageUtil.ImageBase64(images.get(1) + "?x-oss-process=image/resize,w_750/quality,Q_80"); + + IdcardRespVO verify = idcardService.verify(front, back); + if(!"FP00000".equals(verify.getCode())) { + return fail("请上传身份证正面照片"); + } + if(verify.getIssueDate() == null || verify.getIssueOrg() == null || verify.getExpireDate() == null) { + return fail("请上传身份证反面照片"); + } + } + + // 短信验证码校验 + String receiptPhone = receiptParam.getCaptcha(); + String captcha = receiptParam.getCaptcha(); + String code = cacheClient.get(ESmsType.RECEIPT.name() + ":" + receiptPhone, String.class); + if (!StrUtil.equals(code, captcha)) { + return fail("验证码不正确"); + } + + BeanCopier.create(receiptParam, order, CopyOptions.create().ignoreNullValue()).copy(); + order.setReceiptStatus(20); + orderService.updateById(order); + return success("确认收货成功"); + } + + /*@ApiOperation("确认收货") @PostMapping("/receipt") public ApiResult receipt(@RequestBody Order order) { - + // 验证签名 + isCheckSign(); // 验证身份证真实性 if(StringUtils.hasText(order.getOrderSourceData())) { String orderSourceDataString = order.getOrderSourceData(); @@ -392,16 +445,11 @@ public class OpenEquipmentController extends BaseController { if(verify.getIssueDate() == null || verify.getIssueOrg() == null || verify.getExpireDate() == null) { return fail("请上传身份证反面照片"); } - } - - - // 验证签名 - isCheckSign(); orderService.updateById(order); - return success("重置成功"); - } + return success("确认收货成功"); + }*/ @ApiModelProperty("退租") @PostMapping("/rentingOut") diff --git a/src/main/java/com/gxwebsoft/open/controller/OpenMainController.java b/src/main/java/com/gxwebsoft/open/controller/OpenMainController.java index cfae984..deb112f 100644 --- a/src/main/java/com/gxwebsoft/open/controller/OpenMainController.java +++ b/src/main/java/com/gxwebsoft/open/controller/OpenMainController.java @@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.google.gson.Gson; import com.gxwebsoft.common.core.annotation.OperationLog; import com.gxwebsoft.common.core.config.ConfigProperties; +import com.gxwebsoft.common.core.enums.ESmsType; import com.gxwebsoft.common.core.exception.BusinessException; import com.gxwebsoft.common.core.security.JwtSubject; import com.gxwebsoft.common.core.security.JwtUtil; @@ -146,7 +147,7 @@ public class OpenMainController extends BaseController { String email = user.getEmail(); // 邮箱 // 短信验证 - if (!StrUtil.equals(code,cacheClient.get(phone,String.class)) && !StrUtil.equals(code,"170083")) { + if (!StrUtil.equals(code,cacheClient.get(ESmsType.LOGIN.name() + ":" + phone,String.class)) && !StrUtil.equals(code,"170083")) { throw new BusinessException("验证码不正确"); } user.setUsername(username); diff --git a/src/main/java/com/gxwebsoft/shop/controller/PaymentController.java b/src/main/java/com/gxwebsoft/shop/controller/PaymentController.java index 2cac759..bc85305 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/PaymentController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/PaymentController.java @@ -3,6 +3,9 @@ package com.gxwebsoft.shop.controller; import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alipay.api.AlipayApiException; import com.alipay.api.AlipayConstants; @@ -15,7 +18,6 @@ import com.alipay.api.response.AlipayTradeCreateResponse; import com.alipay.api.response.AlipayTradeQueryResponse; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.gxwebsoft.apps.entity.BcTemporary; -import com.gxwebsoft.apps.entity.EquipmentGoods; import com.gxwebsoft.apps.param.BcTemporaryParam; import com.gxwebsoft.apps.service.BcTemporaryService; import com.gxwebsoft.apps.service.EquipmentGoodsService; @@ -33,6 +35,7 @@ import com.gxwebsoft.shop.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; import org.springframework.core.env.Environment; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; @@ -42,6 +45,7 @@ import javax.annotation.Resource; import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Map; @@ -55,6 +59,7 @@ import static com.gxwebsoft.common.core.constants.OrderConstants.*; * @author 科技小王子 * @since 2022-12-15 19:11:07 */ +@Slf4j @Api(tags = "商城支付方式记录表管理") @RestController @RequestMapping("/api/shop/payment") @@ -256,7 +261,6 @@ public class PaymentController extends BaseController { // 订单数据 OrderPay order = orderPayService.getById(id); - Merchant merchant = merchantService.getMerchantByCode(order.getMerchantCode()); // final EquipmentGoods eg = equipmentGoodsService.getById(order.getGoodsId()); @@ -265,13 +269,13 @@ public class PaymentController extends BaseController { try { AlipayTradeCreateRequest request = new AlipayTradeCreateRequest(); // 配置公共请求参数 - request.setNotifyUrl(pathConfig.getServerUrl() + "/shop/payment/mp-alipay/notify"); + request.setNotifyUrl(pathConfig.getServerUrl() + "/shop/payment/mp-alipay/notify"); // request.setNotifyUrl("http://1.14.132.108:10090/api/shop/payment/mp-alipay/notify"); request.setReturnUrl(null); // 配置业务参数 JSONObject bizContent = new JSONObject(); - System.out.println("bizContent = " + order); - bizContent.put("out_trade_no", order.getOrderNo()); + String orderNo = order.getOrderNo(); + bizContent.put("out_trade_no", orderNo); bizContent.put("total_amount", order.getPayPrice()); bizContent.put("subject", merchant.getMerchantName()); // 拿不到手机号码?? @@ -279,11 +283,32 @@ public class PaymentController extends BaseController { request.setBizContent(bizContent.toString()); //SDK 已经封装掉了公共参数,这里只需要传入业务参数。 AlipayTradeCreateResponse response = alipayClient.certificateExecute(request); - System.out.println("response = " + response); +// log.info("支付宝支付返回信息:{}", response); + if(!response.isSuccess()){ + String subCode = response.getSubCode(); + if("ACQ.TRADE_HAS_CLOSE".equals(subCode)){ + String orderNoNew = IdUtil.getSnowflakeNextIdStr(); + log.warn("原支付宝支付订单{}已关闭!重新生成支付订单号{}!", orderNo, orderNoNew); + order.setOrderNo(orderNoNew); + orderPayService.updateById(order); + + bizContent.put("out_trade_no", orderNoNew); + request.setBizContent(bizContent.toString()); + response = alipayClient.certificateExecute(request); + if(response.isSuccess()){ + String trade_no = response.getTradeNo();// 获取返回的tradeNO。 + return success("支付成功", trade_no); + } + } + + log.error("发起支付宝支付失败!{}", JSON.toJSONString(response)); + return fail("发起支付宝支付失败!"); + } + String trade_no = response.getTradeNo();// 获取返回的tradeNO。 return success("支付成功", trade_no); } catch (AlipayApiException e) { - e.printStackTrace(); + log.error(e.getErrMsg(), e); throw new RuntimeException(); } } @@ -292,20 +317,24 @@ public class PaymentController extends BaseController { @OperationLog @PostMapping("/mp-alipay/notify") public String alipayNotify(@RequestParam Map params) throws AlipayApiException, ParseException { - System.out.println("异步处理>>>>"); - System.out.println("params = " + params); + log.info("异步处理支付宝通知消息>>>>param:{}", params); String outTradeNo = params.get("out_trade_no"); +// OrderPay order = orderPayService.selectByOutTransNo(outTradeNo); OrderPay order = orderPayService.lambdaQuery().eq(OrderPay::getOrderNo, outTradeNo).one(); if (order == null) { - throw new BusinessException("订单不存在"); + throw new BusinessException("订单不存在,第三方返回单号:" + outTradeNo); + } + + Integer payStatus = order.getPayStatus(); + if(payStatus >= PAY_STATUS_SUCCESS){ + throw new BusinessException("订单已支付成功"); } final JSONObject config = alipayConfig.payment(order.getTenantId()); // 生成环境证书路径 String alipayCertPublicKey = pathConfig.getUploadPath() + "file" + config.getString("alipayCertPublicKey"); // TODO 验签成功后,按照支付结果异步通知中的描述,对支付结果中的业务内容进行二次校验,校验成功后在response中返回success并继续商户自身业务处理,校验失败返回failure boolean flag = AlipaySignature.rsaCertCheckV1(params, alipayCertPublicKey, AlipayConstants.CHARSET_UTF8, AlipayConstants.SIGN_TYPE_RSA2); - System.out.println("flag>>>>>>>>>>>>>>>>>>>>>>>"); - System.out.println(flag); + log.info("flag>>>>>>>>>>>>>>>>>>>>>>>{}", flag); // 处理订单业务 if (flag) { final String tradeStatus = params.get("trade_status"); @@ -337,6 +366,7 @@ public class PaymentController extends BaseController { order.setPayTime(DateUtil.date()); order.setTradeId(trade_no); order.setSubject(subject); + order.setOrderNo(outTradeNo); Order parentOrder = orderService.getById(order.getRentOrderId()); parentOrder.setCurrPeriods(parentOrder.getCurrPeriods() + 1); @@ -380,6 +410,7 @@ public class PaymentController extends BaseController { isCheckSign(); // 订单数据 OrderPay order = orderPayService.getByIdRel(id); + // 当前登录用户id User user = new User(); // 代付款情况 @@ -530,6 +561,10 @@ public class PaymentController extends BaseController { isCheckSign(); // 订单数据 Order order = orderService.getByIdRel(id); + if(null == order){ + return fail("订单不存在"); + } + // 实例化客户端 DefaultAlipayClient alipayClient = alipayConfig.alipayClient(order.getTenantId()); AlipayTradeQueryRequest request = new AlipayTradeQueryRequest(); @@ -538,12 +573,9 @@ public class PaymentController extends BaseController { request.setBizContent(bizContent.toString()); AlipayTradeQueryResponse response = alipayClient.certificateExecute(request); if (response.isSuccess()) { - System.out.println("调用成功"); - orderService.paySuccess(response); - } else { - System.out.println("调用失败"); + return orderService.paySuccess(response); } - return success("调用成功", response); + return fail("支付宝返回失败!", response); } @ApiModelProperty("测试") @@ -585,4 +617,11 @@ public class PaymentController extends BaseController { // orderService.paySuccess(params); return "success"; } + +// @ApiModelProperty("测试JSON字段匹配") +// @GetMapping("/mp-alipay/testJson") +// public ApiResult testJson(String outTransNo) { +// OrderPay orderPay = orderPayService.selectByOutTransNo(outTransNo); +// return success(orderPay); +// } } diff --git a/src/main/java/com/gxwebsoft/shop/entity/Order.java b/src/main/java/com/gxwebsoft/shop/entity/Order.java index fb1c8bf..ba6c98e 100644 --- a/src/main/java/com/gxwebsoft/shop/entity/Order.java +++ b/src/main/java/com/gxwebsoft/shop/entity/Order.java @@ -36,7 +36,6 @@ public class Order implements Serializable { @ApiModelProperty(value = "订单号") private String orderNo; - @ApiModelProperty(value = "商品总金额(不含优惠折扣)") private BigDecimal totalPrice; @@ -217,6 +216,18 @@ public class Order implements Serializable { @ApiModelProperty(value = "备注") private String comments; + @ApiModelProperty(value = "收货人手机号") + private String receiptPhone; + + @ApiModelProperty(value = "紧急联系人") + private String emergentUser; + + @ApiModelProperty(value = "单位地址") + private String officeAddress; + + @ApiModelProperty(value = "家庭地址") + private String homeAddress; + @ApiModelProperty(value = "状态, 0正常, 1冻结") private Integer status; @@ -287,4 +298,12 @@ public class Order implements Serializable { @ApiModelProperty("芝麻免押") @TableField(exist = false) private String orderStr; + + @ApiModelProperty("下单用户手机号") + @TableField(exist = false) + private String userPhone; + + @ApiModelProperty("设备编码") + @TableField(exist = false) + private String equipmentCode; } diff --git a/src/main/java/com/gxwebsoft/shop/entity/OrderPay.java b/src/main/java/com/gxwebsoft/shop/entity/OrderPay.java index 098277b..7894b54 100644 --- a/src/main/java/com/gxwebsoft/shop/entity/OrderPay.java +++ b/src/main/java/com/gxwebsoft/shop/entity/OrderPay.java @@ -1,6 +1,9 @@ package com.gxwebsoft.shop.entity; import java.math.BigDecimal; + +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; @@ -9,11 +12,14 @@ import com.baomidou.mybatisplus.annotation.TableLogic; import java.io.Serializable; import java.util.Date; +import com.gxwebsoft.common.core.constants.OrderConstants; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; +import static com.gxwebsoft.common.core.constants.OrderConstants.PAY_STATUS_NO_PAY; + /** * 订单记录表 * @@ -158,7 +164,7 @@ public class OrderPay implements Serializable { private String dealerPhone; @ApiModelProperty(value = "逾期天数") - private Integer expirationDay; + private Long expirationDay; @ApiModelProperty(value = "租户id") private Integer tenantId; @@ -169,4 +175,12 @@ public class OrderPay implements Serializable { @ApiModelProperty(value = "修改时间") private Date updateTime; + public Long getExpirationDay() { + switch(payStatus){ + case OrderConstants.PAY_STATUS_NO_PAY: + case OrderConstants.PAY_STATUS_SUCCESS: + expirationDay = DateUtil.between(new Date(), expirationTime, DateUnit.DAY, false); + } + return expirationDay; + } } diff --git a/src/main/java/com/gxwebsoft/shop/mapper/MerchantMapper.java b/src/main/java/com/gxwebsoft/shop/mapper/MerchantMapper.java index aeaf966..f1ef538 100644 --- a/src/main/java/com/gxwebsoft/shop/mapper/MerchantMapper.java +++ b/src/main/java/com/gxwebsoft/shop/mapper/MerchantMapper.java @@ -2,6 +2,7 @@ package com.gxwebsoft.shop.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gxwebsoft.shop.entity.Merchant; import com.gxwebsoft.shop.param.MerchantParam; import org.apache.ibatis.annotations.Param; @@ -23,8 +24,7 @@ public interface MerchantMapper extends BaseMapper { * @param param 查询参数 * @return List */ - List selectPageRel(@Param("page") IPage page, - @Param("param") MerchantParam param); + Page selectPageRel(IPage page, @Param("param") MerchantParam param); /** * 查询全部 diff --git a/src/main/java/com/gxwebsoft/shop/mapper/OrderMapper.java b/src/main/java/com/gxwebsoft/shop/mapper/OrderMapper.java index 5fe85a1..670ba16 100644 --- a/src/main/java/com/gxwebsoft/shop/mapper/OrderMapper.java +++ b/src/main/java/com/gxwebsoft/shop/mapper/OrderMapper.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.gxwebsoft.shop.entity.Order; import com.gxwebsoft.shop.param.OrderParam; import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.ResultType; import org.apache.ibatis.annotations.Select; import java.util.List; @@ -56,4 +57,26 @@ public interface OrderMapper extends BaseMapper { @InterceptorIgnore(tenantLine = "true") void updateByIdSettled(@Param("param") Order order); + + /** + * 查找到期预警订单 + * @return + */ + @Select("select u.phone userPhone, DATEDIFF(o.expiration_time,CURDATE()) expirationDay " + + "from shop_order o join sys_user u on o.user_id = u.user_id " + + "where DATEDIFF(o.expiration_time,CURDATE()) in (-1, 0) and u.phone is not null " + + "and o.is_freeze = 1 and o.receipt_status != 10 and o.pay_status = 10 and o.is_renew = 1") + @ResultType(Order.class) + List selectAlertList(); + + /** + * 查找超期1天订单 + * @return + */ + @Select("select u.phone userPhone, DATEDIFF(o.expiration_time,CURDATE()) expirationDay " + + "from shop_order o join sys_user u on o.user_id = u.user_id " + + "where DATEDIFF(o.expiration_time,CURDATE()) = 1 and u.phone is not null " + + "and o.is_freeze = 1 and o.receipt_status != 10 and o.pay_status = 10 and o.is_renew = 1") + @ResultType(Order.class) + List selectOutOfOneDayList(); } diff --git a/src/main/java/com/gxwebsoft/shop/mapper/OrderPayMapper.java b/src/main/java/com/gxwebsoft/shop/mapper/OrderPayMapper.java index a116ff5..dfc2e73 100644 --- a/src/main/java/com/gxwebsoft/shop/mapper/OrderPayMapper.java +++ b/src/main/java/com/gxwebsoft/shop/mapper/OrderPayMapper.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.gxwebsoft.shop.entity.OrderPay; import com.gxwebsoft.shop.param.OrderPayParam; import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; import java.util.List; @@ -34,4 +35,11 @@ public interface OrderPayMapper extends BaseMapper { */ List selectListRel(@Param("param") OrderPayParam param); + /** + * 查询是否存在第三方支付订单号 + * @param outTradeNo + * @return + */ + @Select("select * from shop_order_pay where JSON_CONTAINS(out_trans_nos, JSON_ARRAY(#{outTradeNo}))") + OrderPay selectByOutTransNo(@Param("outTradeNo") String outTradeNo); } diff --git a/src/main/java/com/gxwebsoft/shop/param/OrderReceiptParam.java b/src/main/java/com/gxwebsoft/shop/param/OrderReceiptParam.java new file mode 100644 index 0000000..485a094 --- /dev/null +++ b/src/main/java/com/gxwebsoft/shop/param/OrderReceiptParam.java @@ -0,0 +1,41 @@ +package com.gxwebsoft.shop.param; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +@Data +@ApiModel("确认收货请求参数") +public class OrderReceiptParam implements Serializable { + @ApiModelProperty(value = "订单ID", required = true) + @NotNull(message = "订单编号不能为空!") + private Integer orderId; + +// @ApiModelProperty(value = "来源记录的参数 (json格式)", required = true) +// @NotBlank(message = "身份信息数据不能为空!") + private String orderSourceData; + + @ApiModelProperty(value = "验证码", required = true) + @NotBlank(message = "验证码不能为空!") + private String captcha; + + @ApiModelProperty(value = "收货人手机号", required = true) + @NotBlank(message = "收货人手机号不能为空!") + private String receiptPhone; + + @ApiModelProperty(value = "紧急联系人") + @NotBlank(message = "紧急联系人不能为空!") + private String emergentUser; + + @ApiModelProperty(value = "单位地址") + @NotBlank(message = "单位地址不能为空!") + private String officeAddress; + + @ApiModelProperty(value = "家庭地址") + @NotBlank(message = "家庭地址不能为空!") + private String homeAddress; +} diff --git a/src/main/java/com/gxwebsoft/shop/service/OrderPayService.java b/src/main/java/com/gxwebsoft/shop/service/OrderPayService.java index d86c12f..e04bf46 100644 --- a/src/main/java/com/gxwebsoft/shop/service/OrderPayService.java +++ b/src/main/java/com/gxwebsoft/shop/service/OrderPayService.java @@ -39,4 +39,10 @@ public interface OrderPayService extends IService { */ OrderPay getByIdRel(Integer id); + /** + * 根据第三方流水号获取支付订单信息 + * @param outTradeNo + * @return + */ + OrderPay selectByOutTransNo(String outTradeNo); } diff --git a/src/main/java/com/gxwebsoft/shop/service/OrderService.java b/src/main/java/com/gxwebsoft/shop/service/OrderService.java index a6efb9b..04772ab 100644 --- a/src/main/java/com/gxwebsoft/shop/service/OrderService.java +++ b/src/main/java/com/gxwebsoft/shop/service/OrderService.java @@ -3,6 +3,7 @@ package com.gxwebsoft.shop.service; import com.alipay.api.response.AlipayTradeQueryResponse; import com.baomidou.mybatisplus.annotation.InterceptorIgnore; import com.baomidou.mybatisplus.extension.service.IService; +import com.gxwebsoft.common.core.web.ApiResult; import com.gxwebsoft.common.core.web.PageResult; import com.gxwebsoft.shop.entity.Order; import com.gxwebsoft.shop.param.OrderParam; @@ -45,7 +46,7 @@ public interface OrderService extends IService { Order getByOutTradeNo(String outTradeNo); @InterceptorIgnore(tenantLine = "true") - void paySuccess(AlipayTradeQueryResponse params); + ApiResult paySuccess(AlipayTradeQueryResponse params); boolean allinPay(Map params); @@ -59,4 +60,15 @@ public interface OrderService extends IService { void updateByIdSettled(Order order); + /** + * 查找到期预警订单 + * @return + */ + List findAlertList(); + + /** + * 查找逾期提醒订单 + * @return + */ + List findOverdueList(); } diff --git a/src/main/java/com/gxwebsoft/shop/service/impl/MerchantServiceImpl.java b/src/main/java/com/gxwebsoft/shop/service/impl/MerchantServiceImpl.java index ea35961..61ce8ca 100644 --- a/src/main/java/com/gxwebsoft/shop/service/impl/MerchantServiceImpl.java +++ b/src/main/java/com/gxwebsoft/shop/service/impl/MerchantServiceImpl.java @@ -1,6 +1,7 @@ package com.gxwebsoft.shop.service.impl; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gxwebsoft.common.core.utils.CacheClient; import com.gxwebsoft.common.core.web.PageParam; @@ -40,8 +41,8 @@ public class MerchantServiceImpl extends ServiceImpl i public PageResult pageRel(MerchantParam param) { PageParam page = new PageParam<>(param); page.setDefaultOrder("create_time desc"); - List list = baseMapper.selectPageRel(page, param); - return new PageResult<>(list, page.getTotal()); + Page list = baseMapper.selectPageRel(page, param); + return new PageResult<>(list.getRecords(), list.getTotal()); } @Override diff --git a/src/main/java/com/gxwebsoft/shop/service/impl/OrderPayServiceImpl.java b/src/main/java/com/gxwebsoft/shop/service/impl/OrderPayServiceImpl.java index 12db533..54ee0e8 100644 --- a/src/main/java/com/gxwebsoft/shop/service/impl/OrderPayServiceImpl.java +++ b/src/main/java/com/gxwebsoft/shop/service/impl/OrderPayServiceImpl.java @@ -44,4 +44,8 @@ public class OrderPayServiceImpl extends ServiceImpl i return param.getOne(baseMapper.selectListRel(param)); } + @Override + public OrderPay selectByOutTransNo(String outTradeNo) { + return baseMapper.selectByOutTransNo(outTradeNo); + } } diff --git a/src/main/java/com/gxwebsoft/shop/service/impl/OrderServiceImpl.java b/src/main/java/com/gxwebsoft/shop/service/impl/OrderServiceImpl.java index 77a8bda..aaa8a44 100644 --- a/src/main/java/com/gxwebsoft/shop/service/impl/OrderServiceImpl.java +++ b/src/main/java/com/gxwebsoft/shop/service/impl/OrderServiceImpl.java @@ -3,6 +3,7 @@ package com.gxwebsoft.shop.service.impl; import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.StrUtil; import com.alipay.api.AlipayApiException; import com.alipay.api.response.AlipayTradeQueryResponse; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -11,7 +12,9 @@ import com.gxwebsoft.apps.entity.EquipmentOrderGoods; import com.gxwebsoft.apps.service.EquipmentGoodsService; import com.gxwebsoft.apps.service.EquipmentOrderGoodsService; import com.gxwebsoft.apps.service.EquipmentService; +import com.gxwebsoft.common.core.Constants; import com.gxwebsoft.common.core.utils.CacheClient; +import com.gxwebsoft.common.core.web.ApiResult; import com.gxwebsoft.common.core.web.PageParam; import com.gxwebsoft.common.core.web.PageResult; import com.gxwebsoft.shop.entity.Order; @@ -88,13 +91,26 @@ public class OrderServiceImpl extends ServiceImpl implements return new PageResult<>(list, page.getTotal()); } + // TODO 待优化:查询时自动排序并返回分页数据 @Override public List listRel(OrderParam param) { List list = baseMapper.selectListRel(param); // 排序 PageParam page = new PageParam<>(); - page.setDefaultOrder("create_time desc"); + String sort = param.getSort(); + String order = param.getOrder(); + if(StrUtil.isNotBlank(sort)){ + String orderStr = sort; + if(StrUtil.isNotBlank(order)){ + orderStr += " " + order; + } + page.setDefaultOrder(orderStr); + } + else { + page.setDefaultOrder("create_time desc"); + } + return page.sortRecords(list); } @@ -191,7 +207,7 @@ public class OrderServiceImpl extends ServiceImpl implements */ @Transactional(rollbackFor = {Exception.class}) @Override - public void paySuccess(AlipayTradeQueryResponse params) { + public ApiResult paySuccess(AlipayTradeQueryResponse params) { System.out.println("支付成功后处理的业务"); String outTradeNo = params.getOutTradeNo(); String totalAmount = params.getTotalAmount(); @@ -199,8 +215,12 @@ public class OrderServiceImpl extends ServiceImpl implements // 1.是否为商城订单 Order order = orderService.getByOutTradeNo(outTradeNo); if (order == null) { - System.out.println("订单不存在!"); - return; + return new ApiResult("订单不存在!"); + } + + Integer payStatus = order.getPayStatus(); + if(payStatus >= PAY_STATUS_SUCCESS){ + return new ApiResult("订单已支付!"); } // 2.订单金额是否一致 // 3.订单商户是否一致 @@ -208,8 +228,10 @@ public class OrderServiceImpl extends ServiceImpl implements // 5.判断交易状态 String tradeStatus = params.getTradeStatus(); if (!"TRADE_SUCCESS".equals(tradeStatus)) { - System.out.println("支付未成功"); - return; + if("TRADE_CLOSED".equals(tradeStatus)){ + // TODO 订单已关闭 + } + return new ApiResult("支付未成功!"); } // 6.修改订单状态 @@ -219,10 +241,6 @@ public class OrderServiceImpl extends ServiceImpl implements order.setPayTime(DateUtil.date()); order.setExpirationTime(DateUtil.nextMonth()); - - - - // 6. 续租订单 if (order.getRentOrderId() > 0) { Integer count = orderService.lambdaQuery().eq(Order::getRentOrderId, order.getRentOrderId()).eq(Order::getPayStatus, PAY_STATUS_SUCCESS).count(); @@ -261,11 +279,8 @@ public class OrderServiceImpl extends ServiceImpl implements } - - - orderService.updateById(order); - + return new ApiResult(Constants.RESULT_OK_CODE, "支付成功"); } /** @@ -285,4 +300,13 @@ public class OrderServiceImpl extends ServiceImpl implements } } + @Override + public List findAlertList() { + return baseMapper.selectAlertList(); + } + + @Override + public List findOverdueList() { + return baseMapper.selectOutOfOneDayList(); + } } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index b6cdb3b..9f60fa4 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -9,12 +9,6 @@ spring: driver-class-name: com.mysql.cj.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource -# 日志配置 -logging: - level: - com.gxwebsoft: DEBUG - com.baomidou.mybatisplus: DEBUG - socketio: host: localhost #IP地址 @@ -31,3 +25,13 @@ config: bucketName: oss-yunxinwei bucketDomain: https://oss.wsdns.cn aliyunDomain: https://oss-yunxinwei.oss-cn-shenzhen.aliyuncs.com + +# 日志配置 +logging: + level: + root: INFO + com.gxwebsoft: INFO + com.baomidou.mybatisplus: INFO + file: + path: E:\data\yxw\logs + name: yxw.log \ No newline at end of file diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index c0ce982..1d0314f 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -13,18 +13,21 @@ spring: logging: file: name: websoft-api.log + path: /www/wwwroot/api.yunxinwei.java/logs level: - root: WARN - com.gxwebsoft: ERROR + root: INFO + com.gxwebsoft: INFO com.baomidou.mybatisplus: ERROR socketio: host: 0.0.0.0 #IP地址 +# host: localhost # 框架配置 config: # 生产环境接口 server-url: https://yxw.wsdns.cn/api +# server-url: https://127.0.0.1:9090/api upload-path: /www/wwwroot/file.ws/ # 阿里云OSS云存储 diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 58a4055..0f057fe 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -7,7 +7,7 @@ socketio: # 多环境配置 spring: profiles: - active: dev + active: prod application: name: server @@ -91,6 +91,7 @@ config: file-server: https://file.wsdns.cn upload-path: /Users/gxwebsoft/Documents/uploads/ local-upload-path: /Users/gxwebsoft/Documents/uploads/ + tenantId: 6 # 阿里云OSS云存储 endpoint: https://oss-cn-shenzhen.aliyuncs.com @@ -99,5 +100,16 @@ config: bucketName: oss-gxwebsoft bucketDomain: https://oss.wsdns.cn aliyunDomain: https://oss-gxwebsoft.oss-cn-shenzhen.aliyuncs.com +# smsSign: ${SMS_SIGN:南宁网宿科技} +# smsKey: ${SMS_ACCESS_KEY:LTAI5tBWM9dSmEAoQFhNqxqJ} +# smsSecret: ${SMS_SECRET:Dr0BqiKl7eaL1NNKoCd12qKsbgjnum} + +# 日志配置 +#logging: +# level: +# com.gxwebsoft: ${LOG_LEVEL:INFO} +# com.baomidou.mybatisplus: ${LOG_LEVEL:INFO} +# file: +# path: {LOGGING_PATH: ../logs} From 2d1f3ed93b1734132f4a97f5293d17e27389c305 Mon Sep 17 00:00:00 2001 From: "geng.tang@qq.com" Date: Fri, 26 Jan 2024 15:30:26 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E7=AD=89=E7=9B=B8=E5=85=B3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apps/controller/EquipmentController.java | 15 +- .../apps/mapper/xml/EquipmentMapper.xml | 6 + .../gxwebsoft/apps/param/EquipmentParam.java | 2 + .../apps/service/EquipmentService.java | 1 + .../service/impl/EquipmentServiceImpl.java | 72 +++-- .../com/gxwebsoft/apps/task/OrderTask.java | 80 ++++-- .../core/aspect/OperationLogAspect.java | 3 +- .../core/config/HttpMessageConverter.java | 5 + .../core/config/RestTemplateConfig.java | 2 + .../core/constants/BalanceConstants.java | 4 +- .../common/core/constants/OrderConstants.java | 5 +- .../common/core/enums/EProfitScene.java | 25 ++ .../common/core/utils/AlipayConfigUtil.java | 18 +- .../common/core/utils/CacheClient.java | 5 +- .../common/core/utils/WxOfficialUtil.java | 11 - .../gxwebsoft/common/core/web/ApiResult.java | 12 + .../common/core/web/BaseController.java | 2 - .../gxwebsoft/common/core/web/PageResult.java | 22 +- .../system/controller/MainController.java | 4 +- .../common/system/mapper/xml/UserMapper.xml | 4 +- .../service/impl/AliSmsServiceImpl.java | 8 +- .../love/mapper/xml/ProfitMapper.xml | 12 +- .../controller/OpenEquipmentController.java | 95 +++--- .../open/controller/OpenOrderController.java | 11 +- .../controller/OpenOrderGoodsController.java | 14 +- .../controller/FreezeOrderController.java | 67 ++++- .../shop/controller/MerchantController.java | 2 + .../MerchantWithdrawController.java | 157 ++++++---- .../shop/controller/OrderController.java | 68 +++-- .../shop/controller/OrderPayController.java | 57 +++- .../controller/OrderRefundController.java | 59 ++-- .../shop/controller/PaymentController.java | 31 +- .../shop/controller/ProfitLogController.java | 27 +- .../controller/RechargeOrderController.java | 2 + .../gxwebsoft/shop/entity/FreezeOrder.java | 3 + .../shop/entity/MerchantWithdraw.java | 83 +++++- .../java/com/gxwebsoft/shop/entity/Order.java | 29 +- .../com/gxwebsoft/shop/entity/OrderPay.java | 21 ++ .../gxwebsoft/shop/entity/OrderRefund.java | 4 +- .../com/gxwebsoft/shop/entity/ProfitLog.java | 16 +- .../gxwebsoft/shop/entity/UserBalanceLog.java | 11 +- .../gxwebsoft/shop/mapper/OrderMapper.java | 12 +- .../gxwebsoft/shop/mapper/xml/OrderMapper.xml | 15 +- .../shop/mapper/xml/OrderRefundMapper.xml | 3 + .../shop/param/MerchantWithdrawParam.java | 62 +--- .../com/gxwebsoft/shop/param/OrderParam.java | 15 +- .../shop/param/OrderReceiptParam.java | 26 +- .../shop/param/OrderRefundParam.java | 3 + .../gxwebsoft/shop/param/ProfitLogParam.java | 45 ++- .../shop/param/WithdrawApplyParam.java | 58 ++++ .../shop/param/WithdrawAuditFailParam.java | 26 ++ .../shop/param/WithdrawAuditPassParam.java | 27 ++ .../shop/service/FreezeOrderService.java | 4 +- .../shop/service/MerchantWithdrawService.java | 24 ++ .../service/impl/FreezeOrderServiceImpl.java | 28 +- .../service/impl/MerchantServiceImpl.java | 2 - .../impl/MerchantWithdrawServiceImpl.java | 271 +++++++++++++++++- .../shop/service/impl/OrderServiceImpl.java | 5 +- src/main/resources/application-dev.yml | 7 +- src/main/resources/application-prod.yml | 14 +- src/main/resources/application.yml | 10 +- 61 files changed, 1283 insertions(+), 449 deletions(-) create mode 100644 src/main/java/com/gxwebsoft/common/core/enums/EProfitScene.java create mode 100644 src/main/java/com/gxwebsoft/shop/param/WithdrawApplyParam.java create mode 100644 src/main/java/com/gxwebsoft/shop/param/WithdrawAuditFailParam.java create mode 100644 src/main/java/com/gxwebsoft/shop/param/WithdrawAuditPassParam.java diff --git a/src/main/java/com/gxwebsoft/apps/controller/EquipmentController.java b/src/main/java/com/gxwebsoft/apps/controller/EquipmentController.java index 551130a..da64f12 100644 --- a/src/main/java/com/gxwebsoft/apps/controller/EquipmentController.java +++ b/src/main/java/com/gxwebsoft/apps/controller/EquipmentController.java @@ -24,6 +24,7 @@ import com.gxwebsoft.shop.service.MerchantService; import com.gxwebsoft.shop.service.OrderService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; @@ -39,6 +40,7 @@ import static com.gxwebsoft.common.core.constants.OrderConstants.*; * @author 科技小王子 * @since 2022-11-30 02:11:16 */ +@Slf4j @Api(tags = "设备管理管理") @RestController @RequestMapping("/api/apps/equipment") @@ -71,7 +73,7 @@ public class EquipmentController extends BaseController { @ApiOperation("查询全部设备管理") @GetMapping() public ApiResult> list(EquipmentParam param) { - PageParam page = new PageParam<>(param); +// PageParam page = new PageParam<>(param); // page.setDefaultOrder("create_time desc"); // return success(equipmentService.list(page.getOrderWrapper())); // 使用关联查询 @@ -131,6 +133,7 @@ public class EquipmentController extends BaseController { @OperationLog @ApiOperation("绑定设备") @PutMapping("/bind") + @Deprecated public ApiResult bindEquipment(@RequestBody Equipment equipment) { final Integer orderId = equipment.getOrderId(); final Order order = orderService.getById(orderId); @@ -159,7 +162,7 @@ public class EquipmentController extends BaseController { record.setMerchantCode(one.getMerchantCode()); equipmentRecordService.save(record); // 订单发货 - order.setDeliveryStatus(DELIVERY_STATUS_YES); + order.setDeliveryStatus(DELIVERY_STATUS_ACCEPT); order.setOrderStatus(ORDER_STATUS_COMPLETED); if(order.getOrderSource() == 10) { order.setOrderStatus(ORDER_STATUS_OVER); @@ -225,7 +228,7 @@ public class EquipmentController extends BaseController { AlipayOpenAppQrcodeCreateRequest request = new AlipayOpenAppQrcodeCreateRequest(); AlipayOpenAppQrcodeCreateModel model = new AlipayOpenAppQrcodeCreateModel(); model.setUrlParam("pages/equipment/equipment?equipmentId=".concat(equipment.getEquipmentId().toString())); - System.out.println("equipment = " + equipment); + log.info("equipment = " + equipment); // __id__=2&merchantCode=M311539&merchantId=52 // pages/equipment/equipment @@ -238,16 +241,15 @@ public class EquipmentController extends BaseController { model.setDescribe("扫码租赁电池"); request.setBizModel(model); AlipayOpenAppQrcodeCreateResponse response = alipayClient.certificateExecute(request); - System.out.println(response.getBody()); + log.info("支付宝扫码返回:{}", response.getBody()); if (response.isSuccess()) { - System.out.println("调用成功"); final JSONObject jsonObject = JSONObject.parseObject(response.getBody()); final String alipay_open_app_qrcode_create_response = jsonObject.getString("alipay_open_app_qrcode_create_response"); final JSONObject jsonObject1 = JSONObject.parseObject(alipay_open_app_qrcode_create_response); String qrCodeUrl = jsonObject1.getString("qr_code_url"); return qrCodeUrl; } else { - System.out.println("调用失败"); + log.error("支付宝扫码调用失败"); return null; } } @@ -255,6 +257,7 @@ public class EquipmentController extends BaseController { @PreAuthorize("hasAuthority('apps:equipment:update')") @ApiOperation("确认收货") @PostMapping("/receipt") + @Deprecated public ApiResult receipt(@RequestBody Order order) { orderService.updateById(order); return success("确认收货"); diff --git a/src/main/java/com/gxwebsoft/apps/mapper/xml/EquipmentMapper.xml b/src/main/java/com/gxwebsoft/apps/mapper/xml/EquipmentMapper.xml index 043de45..4dc0426 100644 --- a/src/main/java/com/gxwebsoft/apps/mapper/xml/EquipmentMapper.xml +++ b/src/main/java/com/gxwebsoft/apps/mapper/xml/EquipmentMapper.xml @@ -105,6 +105,12 @@ AND b.merchant_code = #{param.merchantCode} + + AND a.user_id = 0 + + + AND a.user_id > 0 + diff --git a/src/main/java/com/gxwebsoft/apps/param/EquipmentParam.java b/src/main/java/com/gxwebsoft/apps/param/EquipmentParam.java index 4500138..b9f1317 100644 --- a/src/main/java/com/gxwebsoft/apps/param/EquipmentParam.java +++ b/src/main/java/com/gxwebsoft/apps/param/EquipmentParam.java @@ -124,4 +124,6 @@ public class EquipmentParam extends BaseParam { @QueryField(type = QueryType.EQ) private String merchantName; + @ApiModelProperty(value = "是否绑定") + private Byte isBind; } diff --git a/src/main/java/com/gxwebsoft/apps/service/EquipmentService.java b/src/main/java/com/gxwebsoft/apps/service/EquipmentService.java index 246e367..fa06ad1 100644 --- a/src/main/java/com/gxwebsoft/apps/service/EquipmentService.java +++ b/src/main/java/com/gxwebsoft/apps/service/EquipmentService.java @@ -1,6 +1,7 @@ package com.gxwebsoft.apps.service; import com.baomidou.mybatisplus.extension.service.IService; +import com.gxwebsoft.common.core.web.PageParam; import com.gxwebsoft.common.core.web.PageResult; import com.gxwebsoft.apps.entity.Equipment; import com.gxwebsoft.apps.param.EquipmentParam; diff --git a/src/main/java/com/gxwebsoft/apps/service/impl/EquipmentServiceImpl.java b/src/main/java/com/gxwebsoft/apps/service/impl/EquipmentServiceImpl.java index 6537250..61f41db 100644 --- a/src/main/java/com/gxwebsoft/apps/service/impl/EquipmentServiceImpl.java +++ b/src/main/java/com/gxwebsoft/apps/service/impl/EquipmentServiceImpl.java @@ -1,5 +1,7 @@ package com.gxwebsoft.apps.service.impl; +import cn.hutool.core.collection.CollectionUtil; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gxwebsoft.apps.mapper.EquipmentMapper; @@ -10,6 +12,7 @@ import com.gxwebsoft.common.core.web.PageParam; import com.gxwebsoft.common.core.web.PageResult; import com.gxwebsoft.common.system.entity.User; import com.gxwebsoft.common.system.service.UserService; +import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; @@ -27,6 +30,7 @@ import java.util.stream.Collectors; * @author 科技小王子 * @since 2022-11-30 02:11:16 */ +@Slf4j @Service public class EquipmentServiceImpl extends ServiceImpl implements EquipmentService { @Resource @@ -42,8 +46,15 @@ public class EquipmentServiceImpl extends ServiceImpl list = baseMapper.selectPageRel(page, param); Set touziUserIds = list.stream().map(Equipment::getTouziUserId).collect(Collectors.toSet()); - List touziUserList = userService.lambdaQuery().in(User::getUserId, touziUserIds).list(); - Map> touziUserCollect = touziUserList.stream().collect(Collectors.groupingBy(User::getUserId)); + // List touziUserList = userService.lambdaQuery().in(User::getUserId, touziUserIds).list(); + Map touziUserCollect = null; + if(CollectionUtil.isNotEmpty(touziUserIds)){ + List touziUserList = userService.listByIds(touziUserIds); + if(CollectionUtil.isNotEmpty(touziUserList)){ + touziUserCollect = touziUserList.stream().collect(Collectors.toMap(User::getUserId, e->e)); + } + } + // 查询绑定电池的用户 for (Equipment equipment : list) { // 查询状态 @@ -52,31 +63,36 @@ public class EquipmentServiceImpl extends ServiceImpl users = touziUserCollect.get(equipment.getTouziUserId()); - if(!CollectionUtils.isEmpty(users)) { - equipment.setTouziUser(users.get(0)); - + if(CollectionUtil.isNotEmpty(touziUserCollect) && + equipment.getTouziUserId()!= null && !equipment.getTouziUserId().equals(0)) { + User tUser = touziUserCollect.get(equipment.getTouziUserId()); + if(null != tUser){ + equipment.setTouziUser(tUser); } } - } return new PageResult<>(list, page.getTotal()); } @@ -100,18 +116,20 @@ public class EquipmentServiceImpl extends ServiceImpl list = orderService.list(wrapper); if (CollectionUtils.isEmpty(list)) { return; } + Set ids = list.stream().map(Order::getOrderId).collect(Collectors.toSet()); + + LambdaQueryWrapper renewWrapper = Wrappers.lambdaQuery(); + renewWrapper.select(OrderPay::getRentOrderId) + .in(OrderPay::getRentOrderId, ids) + .eq(OrderPay::getPayStatus, PAY_STATUS_NO_PAY); + List renewOrders = orderPayService.list(renewWrapper); + if(CollectionUtil.isNotEmpty(renewOrders)){ + List orderIdRenews = renewOrders.stream().map(OrderPay::getRentOrderId).collect(Collectors.toList()); + + list = list.stream().filter(e->!orderIdRenews.contains(e.getOrderId())).collect(Collectors.toList()); + } + Map> collect = list.stream().collect(Collectors.groupingBy(Order::getOrderId)); - Set ids = collect.keySet(); // 是否已生成当期续费订单 - LambdaQueryWrapper renewWrapper = Wrappers.lambdaQuery(OrderPay.class).in(OrderPay::getRentOrderId, ids).groupBy(OrderPay::getRentOrderId).orderByDesc(OrderPay::getCreateTime); - Page page = new Page(1, 1); +// LambdaQueryWrapper renewWrapper = Wrappers.lambdaQuery(OrderPay.class) + renewWrapper.clear(); + renewWrapper + .in(OrderPay::getRentOrderId, ids) + .groupBy(OrderPay::getRentOrderId).orderByDesc(OrderPay::getCreateTime); + Page page = new Page<>(1, 1); List renewOrderList = orderPayService.page(page, renewWrapper).getRecords(); //查找订单关联的商品 @@ -135,7 +152,6 @@ public class OrderTask { // 计算逾期 EquipmentOrderGoods eg = orderGoodsMap.get(item.getRentOrderId()).get(0); - // 是否需要新增续费订单 if (item.getExpirationTime().before(now) && item.getCurrPeriods() < item.getPeriods()) { OrderPay newRenewOrder = new OrderPay(); @@ -174,7 +190,6 @@ public class OrderTask { newRenewOrder.setPayPrice(eg.getBatteryPrice()); } - orderPayService.save(newRenewOrder); // 已生成订单未付款 } else if (item.getPayStatus().equals(PAY_STATUS_NO_PAY) && now.isAfter(item.getStartTime())) { @@ -188,7 +203,6 @@ public class OrderTask { orderService.lambdaUpdate().eq(Order::getOrderId, item.getRentOrderId()).set(Order::getExpirationDay, between).update(); } - // if(between > 1) { // Order order = collect.get(item.getRentOrderId()).get(0); // // 电池停电 @@ -206,10 +220,10 @@ public class OrderTask { /** * 计算分润 */ - @Scheduled(cron="0 0/1 * * * ? ") +// @Scheduled(cron="0 0/2 * * * ? ") + @Scheduled(cron="${cron.profit:-}") @Transactional public void CalcProfit() { - log.info("开始计算分润"); // 查询所有未结算订单 LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(OrderPay.class) .eq(OrderPay::getIsSettled, ORDER_SETTLED_NO) @@ -329,24 +343,28 @@ public class OrderTask { } Equipment equipment = equipmentMap.get(order.getEquipmentId()); // 投资人收益 + String orderNo = order.getOrderNo(); if (touziProfit.compareTo(BigDecimal.ZERO) > 0 && equipment!= null) { User touziUser = touziUserMap.get(equipment.getTouziUserId()); if (touziUser != null) { - userService.updateBalanceByUserId(touziUser.getUserId(), touziProfit); + Integer userId = touziUser.getUserId(); + userService.updateBalanceByUserId(userId, touziProfit); ProfitLog profitLog = new ProfitLog(); - profitLog.setUserId(touziUser.getUserId()); + profitLog.setUserId(userId); profitLog.setMoney(touziProfit); profitLog.setScene(1); profitLog.setMerchantCode(merchant.getMerchantCode()); + profitLog.setMerchantName(merchant.getMerchantName()); profitLog.setOrderId(order.getId()); - profitLog.setOrderNo(order.getOrderNo()); + profitLog.setOrderNo(orderNo); + profitLog.setOrderUserName(orderUser.getNickname()); profitLog.setComments("投资设备:" + equipment.getEquipmentCode()); profitLog.setEquipmentCode(equipment.getEquipmentCode()); - profitLog.setMerchantName(merchant.getMerchantName()); profitLog.setOrderSource(order.getOrderSource()); // profitLog.setIsRenew(order.getIsRenew()); profitLogService.save(profitLog); + log.info("发放投资人{}分润,订单号{}!", userId, orderNo); } } @@ -354,20 +372,23 @@ public class OrderTask { if (tuijianProfit.compareTo(BigDecimal.ZERO) > 0) { User tuijianUser = tuijianUserMap.get(order.getDealerPhone()); if (tuijianUser != null) { - userService.updateBalanceByUserId(tuijianUser.getUserId(), tuijianProfit); + Integer tuijianUserUserId = tuijianUser.getUserId(); + userService.updateBalanceByUserId(tuijianUserUserId, tuijianProfit); ProfitLog profitLog = new ProfitLog(); - profitLog.setUserId(tuijianUser.getUserId()); + profitLog.setUserId(tuijianUserUserId); profitLog.setMoney(tuijianProfit); profitLog.setScene(3); profitLog.setMerchantCode(merchant.getMerchantCode()); + profitLog.setMerchantName(merchant.getMerchantName()); profitLog.setOrderId(order.getId()); - profitLog.setOrderNo(order.getOrderNo()); + profitLog.setOrderNo(orderNo); + profitLog.setOrderUserName(orderUser.getNickname()); profitLog.setComments("推广收益:" + order.getUserId()); profitLog.setEquipmentCode(equipment.getEquipmentCode()); - profitLog.setMerchantName(merchant.getMerchantName()); profitLog.setOrderSource(order.getOrderSource()); // profitLog.setIsRenew(order.getIsRenew()); profitLogService.save(profitLog); + log.info("发放推荐人{}分润,订单号{}!", tuijianUserUserId, orderNo); } } @@ -383,13 +404,15 @@ public class OrderTask { profitLog.setScene(4); profitLog.setMerchantCode(merchant.getMerchantCode()); profitLog.setOrderId(order.getId()); - profitLog.setOrderNo(order.getOrderNo()); + profitLog.setOrderNo(orderNo); + profitLog.setOrderUserName(orderUser.getNickname()); profitLog.setComments("门店收益:" + order.getMerchantCode()); profitLog.setEquipmentCode(equipment.getEquipmentCode()); profitLog.setMerchantName(merchant.getMerchantName()); profitLog.setOrderSource(order.getOrderSource()); // profitLog.setIsRenew(order.getIsRenew()); profitLogService.save(profitLog); + log.info("发放门店{}分润,订单号{}!", mendianUserId, orderNo); } } // 计算区域经理收益 @@ -406,20 +429,23 @@ public class OrderTask { }).findFirst().orElse(null); } if (manager != null) { - userService.updateBalanceByUserId(manager.getUserId(), jingliProfit); + Integer managerUserId = manager.getUserId(); + userService.updateBalanceByUserId(managerUserId, jingliProfit); ProfitLog profitLog = new ProfitLog(); - profitLog.setUserId(manager.getUserId()); + profitLog.setUserId(managerUserId); profitLog.setMoney(jingliProfit); profitLog.setMerchantCode(merchant.getMerchantCode()); profitLog.setScene(5); profitLog.setOrderId(order.getId()); - profitLog.setOrderNo(order.getOrderNo()); + profitLog.setOrderNo(orderNo); + profitLog.setOrderUserName(orderUser.getNickname()); profitLog.setComments("区域经理收益:" + order.getMerchantCode()); profitLog.setEquipmentCode(equipment.getEquipmentCode()); profitLog.setMerchantName(merchant.getMerchantName()); profitLog.setOrderSource(order.getOrderSource()); // profitLog.setIsRenew(order.getIsRenew()); profitLogService.save(profitLog); + log.info("发放区域经理{}分润,订单号{}!", managerUserId, orderNo); } } } @@ -435,7 +461,8 @@ public class OrderTask { /** * 逾期预警 */ - @Scheduled(cron = "0 30 9 * * ? ") +// @Scheduled(cron = "0 30 9 * * ? ") + @Scheduled(cron = "${cron.alert:-}") public void exceedAlert() { List alertList = orderService.findAlertList(); if(CollectionUtil.isNotEmpty(alertList)){ @@ -455,14 +482,14 @@ public class OrderTask { log.error(e.getMessage(), e); } } - log.info("发送订单到期预警通知结束!总数{}条,成功{}条!", alertList.size(), succ); + log.info(">>>>>>>>>>>>>>>>>>发送订单到期预警通知结束!总数{}条,成功{}条!", alertList.size(), succ); } List overdueList = orderService.findAlertList(); if(CollectionUtil.isNotEmpty(overdueList)) { log.info("开始发送订单超期提醒通知!"); int succ = 0; - for(Order order : alertList){ + for(Order order : overdueList){ SmsCaptchaParam aram = SmsCaptchaParam.builder() .phone(order.getPhone()) .type(ESmsType.OVERDUE.name()) @@ -476,7 +503,8 @@ public class OrderTask { log.error(e.getMessage(), e); } } - log.info("发送逾期提醒通知结束!总数{}条,成功{}条!", alertList.size(), succ); + log.info("====================发送逾期提醒通知结束!总数{}条,成功{}条!", overdueList.size(), succ); } + log.info("------------逾期预警处理结束!"); } } diff --git a/src/main/java/com/gxwebsoft/common/core/aspect/OperationLogAspect.java b/src/main/java/com/gxwebsoft/common/core/aspect/OperationLogAspect.java index ef29028..c022734 100644 --- a/src/main/java/com/gxwebsoft/common/core/aspect/OperationLogAspect.java +++ b/src/main/java/com/gxwebsoft/common/core/aspect/OperationLogAspect.java @@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.extra.servlet.ServletUtil; import cn.hutool.http.useragent.UserAgent; import cn.hutool.http.useragent.UserAgentUtil; +import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.gxwebsoft.common.core.annotation.OperationLog; import com.gxwebsoft.common.core.annotation.OperationModule; @@ -179,7 +180,7 @@ public class OperationLogAspect { || arg instanceof HttpServletResponse) { continue; } - sb.append(JSONUtil.toJSONString(arg)).append(" "); + sb.append(JSON.toJSONString(arg)).append(" "); } params = sb.toString(); } diff --git a/src/main/java/com/gxwebsoft/common/core/config/HttpMessageConverter.java b/src/main/java/com/gxwebsoft/common/core/config/HttpMessageConverter.java index 6bae59d..e1bfcc0 100644 --- a/src/main/java/com/gxwebsoft/common/core/config/HttpMessageConverter.java +++ b/src/main/java/com/gxwebsoft/common/core/config/HttpMessageConverter.java @@ -1,5 +1,7 @@ package com.gxwebsoft.common.core.config; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.http.MediaType; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; @@ -11,5 +13,8 @@ public class HttpMessageConverter extends MappingJackson2HttpMessageConverter { List mediaTypes = new ArrayList<>(); mediaTypes.add(MediaType.APPLICATION_FORM_URLENCODED); setSupportedMediaTypes(mediaTypes); + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + this.setObjectMapper(objectMapper); } } diff --git a/src/main/java/com/gxwebsoft/common/core/config/RestTemplateConfig.java b/src/main/java/com/gxwebsoft/common/core/config/RestTemplateConfig.java index 786798f..1502911 100644 --- a/src/main/java/com/gxwebsoft/common/core/config/RestTemplateConfig.java +++ b/src/main/java/com/gxwebsoft/common/core/config/RestTemplateConfig.java @@ -6,6 +6,8 @@ import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; +import javax.annotation.Resource; + @Configuration public class RestTemplateConfig { diff --git a/src/main/java/com/gxwebsoft/common/core/constants/BalanceConstants.java b/src/main/java/com/gxwebsoft/common/core/constants/BalanceConstants.java index 6857250..fec2d4d 100644 --- a/src/main/java/com/gxwebsoft/common/core/constants/BalanceConstants.java +++ b/src/main/java/com/gxwebsoft/common/core/constants/BalanceConstants.java @@ -1,10 +1,12 @@ package com.gxwebsoft.common.core.constants; -public class BalanceConstants { +public interface BalanceConstants { // 余额变动场景 public static final Integer BALANCE_RECHARGE = 10; // 用户充值 public static final Integer BALANCE_USE = 20; // 用户消费 public static final Integer BALANCE_RE_LET = 21; // 续租 public static final Integer BALANCE_ADMIN = 30; // 管理员操作 public static final Integer BALANCE_REFUND = 40; // 订单退款 + public static final Integer BALANCE_WITHDRAW = 50; // 提现 + public static final Integer BALANCE_WITHDRAW_REJECT = 60; // 提现失败 } diff --git a/src/main/java/com/gxwebsoft/common/core/constants/OrderConstants.java b/src/main/java/com/gxwebsoft/common/core/constants/OrderConstants.java index 7f149f8..5ed2ab2 100644 --- a/src/main/java/com/gxwebsoft/common/core/constants/OrderConstants.java +++ b/src/main/java/com/gxwebsoft/common/core/constants/OrderConstants.java @@ -15,6 +15,7 @@ public class OrderConstants { public static final Integer DELIVERY_STATUS_NO = 10; // 未发货 public static final Integer DELIVERY_STATUS_YES = 20; // 已发货 public static final Integer DELIVERY_STATUS_30 = 30; // 部分发货 + public static final Integer DELIVERY_STATUS_ACCEPT = 40; // 已绑定 // 收货状态 public static final Integer RECEIPT_STATUS_NO = 10; // 未收货 @@ -23,10 +24,10 @@ public class OrderConstants { public static final Integer RECEIPT_STATUS_RETURN = 30; // 已退货 // 订单状态 - public static final Integer ORDER_STATUS_DOING = 10; // 进行中 + public static final Integer ORDER_STATUS_DOING = 10; // 待付款 public static final Integer ORDER_STATUS_CANCEL = 20; // 已取消 public static final Integer ORDER_STATUS_TO_CANCEL = 21; // 待取消 - public static final Integer ORDER_STATUS_COMPLETED = 30; // 已绑定 + public static final Integer ORDER_STATUS_COMPLETED = 30; // 已付款 public static final Integer ORDER_STATUS_OVER = 40; // 已完成 // 订单结算状态 diff --git a/src/main/java/com/gxwebsoft/common/core/enums/EProfitScene.java b/src/main/java/com/gxwebsoft/common/core/enums/EProfitScene.java new file mode 100644 index 0000000..09b1d65 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/core/enums/EProfitScene.java @@ -0,0 +1,25 @@ +package com.gxwebsoft.common.core.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter +public enum EProfitScene { + ASSET(1, "资产收益"), + SERVICE(2, "服务费收益"), + PROMOTION(3, "推广收益"), + MERCHANT(4, "门店收益"), + SHOP(5, "资产收益"); + private Integer value; + private String desc; + + public static String getNameByValue(int value) { + for (EProfitScene myEnum : values()) { + if (myEnum.value == value) { + return myEnum.desc; + } + } + return ""; + } +} diff --git a/src/main/java/com/gxwebsoft/common/core/utils/AlipayConfigUtil.java b/src/main/java/com/gxwebsoft/common/core/utils/AlipayConfigUtil.java index cbb44ed..c603660 100644 --- a/src/main/java/com/gxwebsoft/common/core/utils/AlipayConfigUtil.java +++ b/src/main/java/com/gxwebsoft/common/core/utils/AlipayConfigUtil.java @@ -10,6 +10,7 @@ import com.gxwebsoft.common.core.config.ConfigProperties; import com.gxwebsoft.common.core.exception.BusinessException; import com.gxwebsoft.common.system.entity.Setting; import com.gxwebsoft.common.system.service.SettingService; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; @@ -23,16 +24,17 @@ import javax.annotation.Resource; */ @Slf4j @Component +@Getter public class AlipayConfigUtil { private final StringRedisTemplate stringRedisTemplate; - public Integer tenantId; - public String gateway; - public JSONObject config; - public String appId; - public String privateKey; - public String appCertPublicKey; - public String alipayCertPublicKey; - public String alipayRootCert; + private Integer tenantId; + private String gateway; + private JSONObject config; + private String appId; + private String privateKey; + private String appCertPublicKey; + private String alipayCertPublicKey; + private String alipayRootCert; @Resource private ConfigProperties pathConfig; diff --git a/src/main/java/com/gxwebsoft/common/core/utils/CacheClient.java b/src/main/java/com/gxwebsoft/common/core/utils/CacheClient.java index c56cd45..998c4a6 100644 --- a/src/main/java/com/gxwebsoft/common/core/utils/CacheClient.java +++ b/src/main/java/com/gxwebsoft/common/core/utils/CacheClient.java @@ -5,12 +5,14 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.gxwebsoft.common.system.entity.User; import com.gxwebsoft.common.system.result.RedisResult; +import lombok.RequiredArgsConstructor; import org.springframework.data.geo.Point; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; +import javax.annotation.Resource; import java.time.LocalDateTime; import java.util.List; import java.util.Map; @@ -22,7 +24,8 @@ import static com.gxwebsoft.common.core.constants.RedisConstants.CACHE_NULL_TTL; @Component public class CacheClient { - private final StringRedisTemplate stringRedisTemplate; + @Resource + private StringRedisTemplate stringRedisTemplate; public static Integer tenantId; public CacheClient(StringRedisTemplate stringRedisTemplate){ diff --git a/src/main/java/com/gxwebsoft/common/core/utils/WxOfficialUtil.java b/src/main/java/com/gxwebsoft/common/core/utils/WxOfficialUtil.java index 077e615..3df2b7b 100644 --- a/src/main/java/com/gxwebsoft/common/core/utils/WxOfficialUtil.java +++ b/src/main/java/com/gxwebsoft/common/core/utils/WxOfficialUtil.java @@ -3,13 +3,10 @@ package com.gxwebsoft.common.core.utils; import cn.hutool.core.util.CharsetUtil; import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSONObject; -import com.gxwebsoft.common.core.config.ConfigProperties; import com.gxwebsoft.common.core.exception.BusinessException; -import com.gxwebsoft.common.system.service.SettingService; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; -import javax.annotation.Resource; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; @@ -30,14 +27,6 @@ public class WxOfficialUtil { public String expires_in; public String nickname; - - @Resource - private SettingService settingService; - @Resource - private ConfigProperties pathConfig; - @Resource - private CacheClient cacheClient; - public WxOfficialUtil(StringRedisTemplate stringRedisTemplate){ this.stringRedisTemplate = stringRedisTemplate; } diff --git a/src/main/java/com/gxwebsoft/common/core/web/ApiResult.java b/src/main/java/com/gxwebsoft/common/core/web/ApiResult.java index 52f96ad..c61ccf5 100644 --- a/src/main/java/com/gxwebsoft/common/core/web/ApiResult.java +++ b/src/main/java/com/gxwebsoft/common/core/web/ApiResult.java @@ -92,4 +92,16 @@ public class ApiResult implements Serializable { public boolean isOk(){ return this.code == Constants.RESULT_OK_CODE; } + + public static ApiResult ok(T data){ + return new ApiResult(Constants.RESULT_OK_CODE, "成功", data); + } + + public static ApiResult ok(){ + return new ApiResult(Constants.RESULT_OK_CODE, "成功"); + } + + public static ApiResult fail(String message){ + return new ApiResult(Constants.RESULT_ERROR_CODE, message); + } } diff --git a/src/main/java/com/gxwebsoft/common/core/web/BaseController.java b/src/main/java/com/gxwebsoft/common/core/web/BaseController.java index 2361676..a656c37 100644 --- a/src/main/java/com/gxwebsoft/common/core/web/BaseController.java +++ b/src/main/java/com/gxwebsoft/common/core/web/BaseController.java @@ -42,8 +42,6 @@ public class BaseController { @Resource private MerchantClerkService merchantClerkService; @Resource - private CacheClient cacheClient; - @Resource private UserService userService; /** diff --git a/src/main/java/com/gxwebsoft/common/core/web/PageResult.java b/src/main/java/com/gxwebsoft/common/core/web/PageResult.java index 2ef9d0c..901d4f2 100644 --- a/src/main/java/com/gxwebsoft/common/core/web/PageResult.java +++ b/src/main/java/com/gxwebsoft/common/core/web/PageResult.java @@ -1,6 +1,8 @@ package com.gxwebsoft.common.core.web; +import com.alibaba.fastjson.JSONObject; import io.swagger.annotations.ApiModelProperty; +import lombok.Data; import java.io.Serializable; import java.util.List; @@ -11,6 +13,7 @@ import java.util.List; * @author WebSoft * @since 2017-06-10 10:10:02 */ +@Data public class PageResult implements Serializable { private static final long serialVersionUID = 1L; @@ -20,6 +23,9 @@ public class PageResult implements Serializable { @ApiModelProperty(value = "总数量") private Long count; + @ApiModelProperty(value = "其他数据") + private JSONObject otherData; + public PageResult() { } @@ -28,23 +34,7 @@ public class PageResult implements Serializable { } public PageResult(List list, Long count) { - setList(list); - setCount(count); - } - - public List getList() { - return this.list; - } - - public void setList(List list) { this.list = list; - } - - public Long getCount() { - return this.count; - } - - public void setCount(Long count) { this.count = count; } diff --git a/src/main/java/com/gxwebsoft/common/system/controller/MainController.java b/src/main/java/com/gxwebsoft/common/system/controller/MainController.java index 55e2872..66b4640 100644 --- a/src/main/java/com/gxwebsoft/common/system/controller/MainController.java +++ b/src/main/java/com/gxwebsoft/common/system/controller/MainController.java @@ -81,6 +81,7 @@ public class MainController extends BaseController { @Resource private AliSmsService aliSmsService; + @OperationLog @ApiOperation("用户登录") @PostMapping("/login") public ApiResult login(@RequestBody LoginParam param, HttpServletRequest request) { @@ -222,8 +223,9 @@ public class MainController extends BaseController { if(ret.isOk()){ ESmsType type = ESmsType.valueOf(param.getType()); cacheClient.set(type.name() + ":" + param.getPhone(), code,5L,TimeUnit.MINUTES); + log.info("发送验证码为{}", cacheClient.get(type.name() + ":" + param.getPhone())); } - return success(ret); + return ret; } catch (ClientException e) { log.error(e.getMessage(), e); return fail("发送出错!"); diff --git a/src/main/java/com/gxwebsoft/common/system/mapper/xml/UserMapper.xml b/src/main/java/com/gxwebsoft/common/system/mapper/xml/UserMapper.xml index ebf60c7..e849345 100644 --- a/src/main/java/com/gxwebsoft/common/system/mapper/xml/UserMapper.xml +++ b/src/main/java/com/gxwebsoft/common/system/mapper/xml/UserMapper.xml @@ -49,7 +49,7 @@ AND a.username LIKE CONCAT('%', #{param.username}, '%') - AND a.nickname LIKE CONCAT('%', #{param.nickname}, '%') + AND (a.nickname LIKE CONCAT('%', #{param.nickname}, '%') or a.phone like CONCAT(#{param.nickname}, '%')) AND a.type = #{param.type} @@ -108,7 +108,7 @@ AND a.user_id IN (SELECT user_id FROM sys_user_role WHERE role_id=#{param.roleId}) - + AND a.user_id IN #{item} diff --git a/src/main/java/com/gxwebsoft/common/system/service/impl/AliSmsServiceImpl.java b/src/main/java/com/gxwebsoft/common/system/service/impl/AliSmsServiceImpl.java index ce30152..52839ce 100644 --- a/src/main/java/com/gxwebsoft/common/system/service/impl/AliSmsServiceImpl.java +++ b/src/main/java/com/gxwebsoft/common/system/service/impl/AliSmsServiceImpl.java @@ -61,12 +61,12 @@ public class AliSmsServiceImpl implements AliSmsService { CommonResponse response = client.getCommonResponse(request); String json = response.getData(); - Gson g = new Gson(); - HashMap result = g.fromJson(json, HashMap.class); - if("OK".equals(result.get("Message"))) { + JSONObject result = JSON.parseObject(json); + String message = result.getString("Message"); + if("OK".equals(message)) { return new ApiResult("发送成功"); } log.warn("阿里云短信发送失败!{}", json); - return new ApiResult(Constants.RESULT_ERROR_CODE, "发送失败"); + return new ApiResult(Constants.RESULT_ERROR_CODE, "发送失败!" + message); } } diff --git a/src/main/java/com/gxwebsoft/love/mapper/xml/ProfitMapper.xml b/src/main/java/com/gxwebsoft/love/mapper/xml/ProfitMapper.xml index 131b972..d4b3072 100644 --- a/src/main/java/com/gxwebsoft/love/mapper/xml/ProfitMapper.xml +++ b/src/main/java/com/gxwebsoft/love/mapper/xml/ProfitMapper.xml @@ -19,7 +19,7 @@ AND a.user_id = #{param.userId} - + AND a.scene = #{param.scene} @@ -46,12 +46,10 @@ AND a.status = #{param.status} - - AND a.deleted = #{param.deleted} - - - AND a.deleted = 0 - + + AND a.deleted = #{param.deleted} + AND a.deleted = 0 + AND a.merchant_code LIKE CONCAT('%', #{param.merchantCode}, '%') diff --git a/src/main/java/com/gxwebsoft/open/controller/OpenEquipmentController.java b/src/main/java/com/gxwebsoft/open/controller/OpenEquipmentController.java index c3ea0e9..e4bcff4 100644 --- a/src/main/java/com/gxwebsoft/open/controller/OpenEquipmentController.java +++ b/src/main/java/com/gxwebsoft/open/controller/OpenEquipmentController.java @@ -17,6 +17,7 @@ import com.gxwebsoft.apps.param.EquipmentParam; import com.gxwebsoft.apps.service.EquipmentRecordService; import com.gxwebsoft.apps.service.EquipmentService; import com.gxwebsoft.common.core.annotation.OperationLog; +import com.gxwebsoft.common.core.constants.OrderConstants; import com.gxwebsoft.common.core.enums.ESmsType; import com.gxwebsoft.common.core.utils.AlipayConfigUtil; import com.gxwebsoft.common.core.utils.CacheClient; @@ -36,6 +37,7 @@ import com.gxwebsoft.shop.service.OrderService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; @@ -45,6 +47,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; +import javax.validation.Valid; import java.math.BigDecimal; import java.util.HashMap; import java.util.List; @@ -59,6 +62,7 @@ import static com.gxwebsoft.common.core.constants.OrderConstants.*; * @author 科技小王子 * @since 2022-11-30 02:11:16 */ +@Slf4j @Api(tags = "设备管理管理") @RestController @RequestMapping("/api/open/equipment") @@ -87,20 +91,16 @@ public class OpenEquipmentController extends BaseController { private CacheClient cacheClient; @PreAuthorize("hasAuthority('apps:equipment:list')") - @OperationLog @ApiOperation("分页查询设备管理") @GetMapping("/page") public ApiResult> page(EquipmentParam param) { // 使用关联查询 - PageParam page = new PageParam<>(param); - page.setDefaultOrder("create_time desc"); if (getMerchantCode() != null) { param.setMerchantCode(getMerchantCode()); } return success(equipmentService.pageRel(param)); } - @OperationLog @ApiOperation("查询全部设备管理") @GetMapping() public ApiResult> list(EquipmentParam param) { @@ -215,20 +215,19 @@ public class OpenEquipmentController extends BaseController { model.setDescribe("扫码租赁电池"); request.setBizModel(model); AlipayOpenAppQrcodeCreateResponse response = alipayClient.certificateExecute(request); - System.out.println(response.getBody()); + log.info("支付宝扫码返回:{}", response.getBody()); if (response.isSuccess()) { - System.out.println("调用成功"); final JSONObject jsonObject = JSONObject.parseObject(response.getBody()); final String alipay_open_app_qrcode_create_response = jsonObject.getString("alipay_open_app_qrcode_create_response"); final JSONObject jsonObject1 = JSONObject.parseObject(alipay_open_app_qrcode_create_response); return jsonObject1.getString("qr_code_url"); } else { - System.out.println("调用失败"); return null; } } @ApiOperation("绑定设备") + @OperationLog @PostMapping("/bind") @Transactional(rollbackFor = {Exception.class}) public ApiResult bindEquipment(@RequestBody Equipment equipment) { @@ -262,7 +261,7 @@ public class OpenEquipmentController extends BaseController { record.setMerchantCode(one.getMerchantCode()); equipmentRecordService.save(record); // 订单发货 - order.setDeliveryStatus(DELIVERY_STATUS_YES); + order.setDeliveryStatus(DELIVERY_STATUS_ACCEPT); order.setOrderStatus(ORDER_STATUS_COMPLETED); order.setReceiptStatus(RECEIPT_STATUS_YES); order.setExpirationTime(DateUtil.nextMonth()); @@ -270,13 +269,9 @@ public class OpenEquipmentController extends BaseController { if(order.getOrderSource() == 10) { order.setOrderStatus(ORDER_STATUS_OVER); - } orderService.updateById(order); - - - JSONObject param = new JSONObject(); param.put("userId", loginUser.getUserId()); param.put("userName", loginUser.getNickname()); @@ -285,18 +280,18 @@ public class OpenEquipmentController extends BaseController { try { ResponseEntity responseEntity = restTemplate.postForEntity("https://battery.zfdliot.com/api/battery/batteryBindUser", param, JSONObject.class); JSONObject body = responseEntity.getBody(); - System.out.println(body); + log.info("电池绑定调用第三方返回:{}", body.toString()); }catch (Exception e) { - e.printStackTrace(); + log.error(e.getMessage(), e); } - orderPayService.lambdaUpdate().set(OrderPay::getEquipmentId, one.getEquipmentId()).update(); return success("绑定成功"); } return fail("绑定失败"); } + @OperationLog @ApiOperation("更换设备") @PostMapping("/change") @Transactional(rollbackFor = {Exception.class}) @@ -313,23 +308,29 @@ public class OpenEquipmentController extends BaseController { // 新电池 Equipment one = equipmentService.getByEquipmentCode(equipmentCode); + if (one == null) { + return fail("新设备不存在"); + } + String newMerchantCode = one.getMerchantCode(); // 旧电池 Equipment old = equipmentService.getById(oldEqId); - String oldMerchantCode = old.getMerchantCode(); + String oldMerchantCode = order.getMerchantCode(); - - if (one == null) { - return fail("设备不存在"); - } - if (!one.getUserId().equals(0)) { + Integer userId = one.getUserId(); + if (null != userId && !userId.equals(0)) { return fail("该设备已被绑定"); } + Integer orderUserId = order.getUserId(); + if(null == orderUserId || 0 == orderUserId){ + orderUserId = loginUserId; + } + // 绑定新电池 Equipment saveData = new Equipment(); saveData.setEquipmentId(one.getEquipmentId()); - saveData.setUserId(loginUserId); + saveData.setUserId(orderUserId); saveData.setOrderId(orderId); saveData.setMerchantCode(oldMerchantCode); boolean b = equipmentService.updateById(saveData); @@ -337,9 +338,9 @@ public class OpenEquipmentController extends BaseController { EquipmentRecord record = new EquipmentRecord(); record.setEquipmentCode(equipmentCode); record.setEventType(EVENT_TYPE_BIND); - record.setUserId(loginUserId); + record.setUserId(orderUserId); record.setOrderId(orderId); - record.setMerchantCode(one.getMerchantCode()); + record.setMerchantCode(oldMerchantCode); equipmentRecordService.save(record); if (b) { @@ -351,7 +352,7 @@ public class OpenEquipmentController extends BaseController { // 记录明细 EquipmentRecord record2 = new EquipmentRecord(); record2.setEquipmentCode(old.getEquipmentCode()); - record2.setUserId(loginUserId); + record2.setUserId(orderUserId); record2.setOrderId(orderId); record2.setEventType(EVENT_TYPE_UNBIND); record2.setMerchantCode(one.getMerchantCode()); @@ -359,6 +360,7 @@ public class OpenEquipmentController extends BaseController { // 更新订单 order.setEquipmentId(one.getEquipmentId()); orderService.updateById(order); + User loginUser = getLoginUser(); // 通知第三方 /** @@ -376,7 +378,7 @@ public class OpenEquipmentController extends BaseController { param.put("battery_sn", one.getEquipmentCode()); ResponseEntity responseEntity = restTemplate.postForEntity("https://battery.zfdliot.com/api/battery/batteryBindUser", param, JSONObject.class); JSONObject body = responseEntity.getBody(); - System.out.println(body); + log.info("电池更换调用第三方返回:{}", body); return success("换电成功"); } @@ -385,7 +387,8 @@ public class OpenEquipmentController extends BaseController { @ApiOperation("确认收货") @PostMapping("/receipt") - public ApiResult receipt(@RequestBody @Validated OrderReceiptParam receiptParam) { + @OperationLog + public ApiResult receipt(@RequestBody @Valid OrderReceiptParam receiptParam) { // 验证签名 isCheckSign(); @@ -412,15 +415,19 @@ public class OpenEquipmentController extends BaseController { } // 短信验证码校验 - String receiptPhone = receiptParam.getCaptcha(); - String captcha = receiptParam.getCaptcha(); - String code = cacheClient.get(ESmsType.RECEIPT.name() + ":" + receiptPhone, String.class); - if (!StrUtil.equals(code, captcha)) { - return fail("验证码不正确"); + String receiptPhone = receiptParam.getReceiptPhone(); + if(StrUtil.isNotBlank(receiptPhone)){ + String captcha = receiptParam.getCaptcha(); + String code = cacheClient.get(ESmsType.RECEIPT.name() + ":" + receiptPhone); + if (!StrUtil.equals(code, captcha)) { + return fail("验证码不正确"); + } } BeanCopier.create(receiptParam, order, CopyOptions.create().ignoreNullValue()).copy(); - order.setReceiptStatus(20); + order.setOrderStatus(ORDER_STATUS_COMPLETED); + order.setDeliveryStatus(DELIVERY_STATUS_YES); + order.setReceiptStatus(RECEIPT_STATUS_YES); orderService.updateById(order); return success("确认收货成功"); } @@ -451,30 +458,34 @@ public class OpenEquipmentController extends BaseController { return success("确认收货成功"); }*/ + @OperationLog @ApiModelProperty("退租") @PostMapping("/rentingOut") public ApiResult rentingOut(@RequestBody Order order) { - // 验证签名 isCheckSign(); OrderRefund refund = orderRefundService.getOne(new LambdaQueryWrapper() - .eq(OrderRefund::getOrderId, order.getOrderId())); + .eq(OrderRefund::getOrderId, order.getOrderId()).last("limit 1")); // 已有记录 取消退租 if (refund != null) { - if(refund.getAuditStatus() == 10){ + Integer auditStatus = refund.getAuditStatus(); + if(auditStatus == 10){ orderRefundService.removeById(refund.getOrderRefundId()); - Order updateOrder = new Order(); - updateOrder.setReceiptStatus(RECEIPT_STATUS_YES); - updateOrder.setOrderId(order.getOrderId()); - orderService.updateById(updateOrder); - return success("退租申请已取消"); +// Order updateOrder = new Order(); +// updateOrder.setReceiptStatus(RECEIPT_STATUS_YES); +// updateOrder.setOrderId(order.getOrderId()); +// orderService.updateById(updateOrder); + order.setReceiptStatus(RECEIPT_STATUS_YES); + orderService.updateById(order); + return success("已申请退租"); } - if (refund.getAuditStatus() != 30) { + if (auditStatus != 30) { return fail("申请成功,请等待客服人员审核"); } }else { refund = new OrderRefund(); refund.setOrderId(order.getOrderId()); + refund.setOrderNo(order.getOrderNo()); refund.setOrderGoodsId(order.getGoodsId()); refund.setUserId(getLoginUserId()); refund.setType(10); diff --git a/src/main/java/com/gxwebsoft/open/controller/OpenOrderController.java b/src/main/java/com/gxwebsoft/open/controller/OpenOrderController.java index ab3d5f4..c083bde 100644 --- a/src/main/java/com/gxwebsoft/open/controller/OpenOrderController.java +++ b/src/main/java/com/gxwebsoft/open/controller/OpenOrderController.java @@ -20,6 +20,7 @@ import com.gxwebsoft.shop.param.OrderParam; import com.gxwebsoft.shop.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; @@ -38,6 +39,7 @@ import static com.gxwebsoft.common.core.constants.OrderConstants.*; * @author WebSoft * @since 2022-11-16 11:25:58 */ +@Slf4j @Api(tags = "订单记录表管理") @RestController @RequestMapping("/api/open/order") @@ -224,7 +226,6 @@ public class OpenOrderController extends BaseController { // 取消报餐截止时间 Date date = DateUtil.date(); int hours = date.getHours(); - System.out.println("hours = " + hours); if(hours > 19){ return fail("每天晚上8点后截止取消报餐"); } @@ -233,7 +234,6 @@ public class OpenOrderController extends BaseController { final Order orderInfo = orderService.getById(order.getOrderId()); // 退款 User user = userService.getById(orderInfo.getUserId()); - System.out.println("user = " + user); BigDecimal balance = user.getBalance().add(orderInfo.getPayPrice()); user.setBalance(balance); userService.updateById(user); @@ -241,9 +241,10 @@ public class OpenOrderController extends BaseController { UserBalanceLog userBalanceLog = new UserBalanceLog(); userBalanceLog.setUserId(orderInfo.getUserId()); userBalanceLog.setScene(BALANCE_REFUND); + userBalanceLog.setSceneId(orderInfo.getOrderId()); userBalanceLog.setMoney(orderInfo.getPayPrice()); userBalanceLog.setBalance(balance); - userBalanceLog.setComments(orderInfo.getOrderNo().toString()); + userBalanceLog.setComments("订单号:" + orderInfo.getOrderNo()); userBalanceLog.setMerchantCode(orderInfo.getMerchantCode()); userBalanceLogService.save(userBalanceLog); return success("订单取消成功",orderInfo); @@ -257,9 +258,9 @@ public class OpenOrderController extends BaseController { // 验证签名 isCheckSign(); try { - freezeOrderService.unfreeze(id); + freezeOrderService.unfreeze(id, BigDecimal.ZERO); }catch (Exception e) { - + log.error(e.getMessage(), e); } // Order order = orderService.getById(id); if (orderService.removeById(id)) { diff --git a/src/main/java/com/gxwebsoft/open/controller/OpenOrderGoodsController.java b/src/main/java/com/gxwebsoft/open/controller/OpenOrderGoodsController.java index c430e2e..90d269d 100644 --- a/src/main/java/com/gxwebsoft/open/controller/OpenOrderGoodsController.java +++ b/src/main/java/com/gxwebsoft/open/controller/OpenOrderGoodsController.java @@ -161,7 +161,8 @@ public class OpenOrderGoodsController extends BaseController { return fail("菜品不存在!"); } // System.out.println("orderGoods = " + orderGoods); - final Order byId = orderService.getById(orderGoods.getOrderId()); + Integer orderId = orderGoods.getOrderId(); + final Order byId = orderService.getById(orderId); // 取消报餐截止时间 orderGoodsService.removeById(orderGoods); // System.out.println("orderGoods = " + orderGoods); @@ -176,14 +177,15 @@ public class OpenOrderGoodsController extends BaseController { UserBalanceLog userBalanceLog = new UserBalanceLog(); userBalanceLog.setUserId(byId.getUserId()); userBalanceLog.setScene(BALANCE_REFUND); + userBalanceLog.setSceneId(orderId); userBalanceLog.setMoney(orderGoods.getGoodsPrice()); userBalanceLog.setBalance(balance); - userBalanceLog.setComments(orderGoods.getOrderId().toString()); + userBalanceLog.setComments("取消订单:" + orderId); userBalanceLogService.save(userBalanceLog); - final int count = orderGoodsService.count(new LambdaUpdateWrapper().eq(OrderGoods::getOrderId, orderGoods.getOrderId()).gt(OrderGoods::getTotalNum,0)); + final int count = orderGoodsService.count(new LambdaUpdateWrapper().eq(OrderGoods::getOrderId, orderId).gt(OrderGoods::getTotalNum,0)); // System.out.println("count = " + count); // 更新订单金额 - System.out.println("byId = " + byId); +// System.out.println("byId = " + byId); if (!byId.getTotalPrice().equals(0)) { byId.setTotalPrice(byId.getTotalPrice().subtract(orderGoods.getGoodsPrice())); orderService.updateById(byId); @@ -192,9 +194,9 @@ public class OpenOrderGoodsController extends BaseController { // 无菜品就把订单删除 if(count == 0){ final Order order = new Order(); - order.setOrderId(orderGoods.getOrderId()); + order.setOrderId(orderId); order.setOrderStatus(ORDER_STATUS_CANCEL); - orderService.removeById(orderGoods.getOrderId()); + orderService.removeById(orderId); } return success("菜品取消成功"); } diff --git a/src/main/java/com/gxwebsoft/shop/controller/FreezeOrderController.java b/src/main/java/com/gxwebsoft/shop/controller/FreezeOrderController.java index eba3ccc..4170f9f 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/FreezeOrderController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/FreezeOrderController.java @@ -4,11 +4,15 @@ import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alipay.api.AlipayApiException; import com.alipay.api.AlipayConstants; import com.alipay.api.internal.util.AlipaySignature; import com.alipay.api.response.AlipayFundAuthOperationDetailQueryResponse; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.gxwebsoft.apps.entity.EquipmentGoods; import com.gxwebsoft.apps.service.EquipmentGoodsService; import com.gxwebsoft.common.core.config.ConfigProperties; @@ -29,6 +33,7 @@ import com.gxwebsoft.shop.service.OrderPayService; import com.gxwebsoft.shop.service.OrderService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; @@ -50,6 +55,7 @@ import static com.gxwebsoft.common.core.constants.OrderConstants.PAY_STATUS_SUCC * @author 科技小王子 * @since 2023-10-08 10:15:22 */ +@Slf4j @Api(tags = "管理") @RestController @RequestMapping("/api/shop/freeze-order") @@ -182,6 +188,7 @@ public class FreezeOrderController extends BaseController { @PostMapping("/notify") @Transactional public void freezeNotify(@RequestParam Map params, HttpServletResponse response) throws AlipayApiException { + log.info("收到冻结通知!{}", JSON.toJSONString(params)); PrintWriter writer = null; DateTime now = DateUtil.date(); @@ -218,12 +225,13 @@ public class FreezeOrderController extends BaseController { String trade_status = params.get("trade_status"); String payee_user_id = params.get("payee_user_id"); - FreezeOrder one = freezeOrderService.lambdaQuery().eq(FreezeOrder::getNotifyId, notify_id).one(); + FreezeOrder one = freezeOrderService.lambdaQuery().eq(FreezeOrder::getNotifyId, notify_id).last("limit 1").one(); if(one == null) { FreezeOrder freezeOrder = freezeOrderService.lambdaQuery().eq(FreezeOrder::getOutRequestNo, out_request_no).one(); if(freezeOrder == null) { freezeOrder = new FreezeOrder(); } + freezeOrder.setOutOrderNo(out_order_no != null ?out_order_no: ""); freezeOrder.setOutRequestNo(out_request_no); freezeOrder.setOperationId(operation_id); @@ -240,6 +248,27 @@ public class FreezeOrderController extends BaseController { freezeOrder.setDetail(JSONObject.toJSONString(params)); freezeOrderService.saveOrUpdate(freezeOrder); + LambdaQueryWrapper fWrapper = Wrappers.lambdaQuery(); + fWrapper.eq(FreezeOrder::getRelOrderId, freezeOrder.getRelOrderId()) + .eq(FreezeOrder::getStatus, "INIT") + .eq(FreezeOrder::getId, freezeOrder.getId()); + boolean delRet = freezeOrderService.remove(fWrapper); + log.info("删除无效冻结订单{}条!冻结单号{}", delRet, out_order_no); + + BigDecimal bAmount = freezeOrder.getAmount(); + LambdaQueryWrapper orderWrapper = Wrappers.lambdaQuery(); + orderWrapper.eq(Order::getFreezeOrderNo, out_order_no).last("limit 1"); + Order order = orderService.getOne(orderWrapper); + order.setBatteryRent(bAmount); + orderService.updateById(order); + log.info("更新冻结金额!冻结单号{}", out_order_no); + + LambdaUpdateWrapper orderPayWrapper = Wrappers.lambdaUpdate(); + orderPayWrapper.eq(OrderPay::getRentOrderId, order.getOrderId()) + .set(OrderPay::getBatteryRent, bAmount); + boolean bOrderRet = orderPayService.update(null, orderPayWrapper); + log.info("更新冻结支付订单结果{}!冻结单号{}", bOrderRet, out_order_no); + try { writer = response.getWriter(); writer.write("success"); //一定要打印success @@ -253,6 +282,9 @@ public class FreezeOrderController extends BaseController { } // return "success"; } + else { + log.warn("解冻消息{}已处理!", notify_id); + } // return "fail"; @@ -261,27 +293,36 @@ public class FreezeOrderController extends BaseController { @PostMapping("/checkFreeze/{orderId}") public ApiResult checkFreeze(@PathVariable Integer orderId) throws AlipayApiException { - - DateTime now = DateUtil.date(); - Order order = orderService.getById(orderId); + Integer iFreeze = order.getIsFreeze(); - if (order.getOrderSource() == 30 || order.getOrderSource() == 40) { + if (iFreeze == 0 && (order.getOrderSource() == 30 || order.getOrderSource() == 40)) { AlipayFundAuthOperationDetailQueryResponse response = freezeOrderService.query(order); String status = response.getStatus(); - boolean isFreeze = response.isSuccess() && "SUCCESS".equals(status); - if( !isFreeze) { - return fail(); + String orderStatus = response.getOrderStatus(); + boolean bFreeze = response.isSuccess() && "SUCCESS".equals(status) && "FINISH".equals(orderStatus); + if(!bFreeze) { + log.info("请求支付宝冻结接口返回数据:{}", JSON.toJSONString(response)); + return fail("未支付押金!"); } + log.info("订单{}已支付押金!", orderId); + order.setIsFreeze(1); + orderService.updateById(order); } - final EquipmentGoods eg = equipmentGoodsService.getById(order.getOrderSourceId()); + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); + wrapper.eq(OrderPay::getRentOrderId, orderId).eq(OrderPay::getCurrPeriods, 1).last("limit 1"); + OrderPay renewOrder = orderPayService.getOne(wrapper); + if(null != renewOrder) { +// renewOrder.setOrderNo(IdUtil.getSnowflakeNextIdStr()); +// orderPayService.updateById(renewOrder); + return success(renewOrder); + } - order.setIsFreeze(1); - orderService.updateById(order); // 创建续费订单 - - OrderPay renewOrder = new OrderPay(); + DateTime now = DateUtil.date(); + final EquipmentGoods eg = equipmentGoodsService.getById(order.getOrderSourceId()); + renewOrder = new OrderPay(); renewOrder.setOrderNo(IdUtil.getSnowflakeNextIdStr()); renewOrder.setMerchantCode(order.getMerchantCode()); diff --git a/src/main/java/com/gxwebsoft/shop/controller/MerchantController.java b/src/main/java/com/gxwebsoft/shop/controller/MerchantController.java index 2e62015..9ded612 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/MerchantController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/MerchantController.java @@ -43,6 +43,8 @@ public class MerchantController extends BaseController { @GetMapping("/page") public ApiResult> page(MerchantParam param) { // 使用关联查询 + param.setStatus(0); + param.setLimit(20L); return success(merchantService.pageRel(param)); } diff --git a/src/main/java/com/gxwebsoft/shop/controller/MerchantWithdrawController.java b/src/main/java/com/gxwebsoft/shop/controller/MerchantWithdrawController.java index 045b69a..82c9dd8 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/MerchantWithdrawController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/MerchantWithdrawController.java @@ -3,15 +3,18 @@ package com.gxwebsoft.shop.controller; import com.gxwebsoft.common.core.annotation.OperationLog; import com.gxwebsoft.common.core.web.ApiResult; import com.gxwebsoft.common.core.web.BaseController; -import com.gxwebsoft.common.core.web.BatchParam; import com.gxwebsoft.common.core.web.PageResult; import com.gxwebsoft.common.system.entity.User; import com.gxwebsoft.shop.entity.MerchantWithdraw; import com.gxwebsoft.shop.param.MerchantWithdrawParam; +import com.gxwebsoft.shop.param.WithdrawApplyParam; +import com.gxwebsoft.shop.param.WithdrawAuditFailParam; +import com.gxwebsoft.shop.param.WithdrawAuditPassParam; import com.gxwebsoft.shop.service.MerchantWithdrawService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -23,7 +26,7 @@ import java.util.List; * @author 科技小王子 * @since 2022-12-02 00:41:09 */ -@Api(tags = "商户提现记录管理") +@Api(tags = "商户提现管理") @RestController @RequestMapping("/api/shop/merchant-withdraw") public class MerchantWithdrawController extends BaseController { @@ -31,7 +34,6 @@ public class MerchantWithdrawController extends BaseController { private MerchantWithdrawService merchantWithdrawService; @PreAuthorize("hasAuthority('shop:merchantWithdraw:list')") - @OperationLog @ApiOperation("分页查询商户提现记录") @GetMapping("/page") public ApiResult> page(MerchantWithdrawParam param) { @@ -40,7 +42,6 @@ public class MerchantWithdrawController extends BaseController { } @PreAuthorize("hasAuthority('shop:merchantWithdraw:list')") - @OperationLog @ApiOperation("查询全部商户提现记录") @GetMapping() public ApiResult> list(MerchantWithdrawParam param) { @@ -48,7 +49,6 @@ public class MerchantWithdrawController extends BaseController { } @PreAuthorize("hasAuthority('shop:merchantWithdraw:list')") - @OperationLog @ApiOperation("根据id查询商户提现记录") @GetMapping("/{id}") public ApiResult get(@PathVariable("id") Integer id) { @@ -56,75 +56,112 @@ public class MerchantWithdrawController extends BaseController { return success(merchantWithdrawService.getByIdRel(id)); } - @PreAuthorize("hasAuthority('shop:merchantWithdraw:save')") @OperationLog - @ApiOperation("添加商户提现记录") - @PostMapping() - public ApiResult save(@RequestBody MerchantWithdraw merchantWithdraw) { + @GetMapping("/page/app") + public ApiResult> appPage(MerchantWithdrawParam param) { + User loginUser = getLoginUser(); + param.setUserId(loginUser.getUserId()); + return success(merchantWithdrawService.pageRel(param)); + } + +// @PreAuthorize("hasAuthority('shop:merchantWithdraw:save')") +// @OperationLog +// @ApiOperation("添加商户提现记录") +// @PostMapping() +// public ApiResult save(@RequestBody MerchantWithdraw merchantWithdraw) { +// // 记录当前登录用户id、租户id +// User loginUser = getLoginUser(); +// if (loginUser != null) { +// merchantWithdraw.setUserId(loginUser.getUserId()); +// } +// if (merchantWithdrawService.save(merchantWithdraw)) { +// return success("添加成功"); +// } +// return fail("添加失败"); +// } + + @OperationLog + @ApiOperation("申请提现") + @PostMapping("apply") + public ApiResult apply(@RequestBody @Validated WithdrawApplyParam withdraw) { // 记录当前登录用户id、租户id User loginUser = getLoginUser(); if (loginUser != null) { - merchantWithdraw.setUserId(loginUser.getUserId()); + withdraw.setUserId(loginUser.getUserId()); + return merchantWithdrawService.apply(withdraw); } - if (merchantWithdrawService.save(merchantWithdraw)) { - return success("添加成功"); - } - return fail("添加失败"); + return fail("申请提现失败"); } @PreAuthorize("hasAuthority('shop:merchantWithdraw:update')") @OperationLog - @ApiOperation("修改商户提现记录") - @PutMapping() - public ApiResult update(@RequestBody MerchantWithdraw merchantWithdraw) { - if (merchantWithdrawService.updateById(merchantWithdraw)) { - return success("修改成功"); - } - return fail("修改失败"); - } - - @PreAuthorize("hasAuthority('shop:merchantWithdraw:remove')") - @OperationLog - @ApiOperation("删除商户提现记录") - @DeleteMapping("/{id}") - public ApiResult remove(@PathVariable("id") Integer id) { - if (merchantWithdrawService.removeById(id)) { - return success("删除成功"); - } - return fail("删除失败"); - } - - @PreAuthorize("hasAuthority('shop:merchantWithdraw:save')") - @OperationLog - @ApiOperation("批量添加商户提现记录") - @PostMapping("/batch") - public ApiResult saveBatch(@RequestBody List list) { - if (merchantWithdrawService.saveBatch(list)) { - return success("添加成功"); - } - return fail("添加失败"); + @ApiOperation("提现审核通过") + @PostMapping("audit/pass") + public ApiResult auditSuccess(@RequestBody @Validated WithdrawAuditPassParam passParam) { + return merchantWithdrawService.auditSuccess(passParam); } @PreAuthorize("hasAuthority('shop:merchantWithdraw:update')") @OperationLog - @ApiOperation("批量修改商户提现记录") - @PutMapping("/batch") - public ApiResult removeBatch(@RequestBody BatchParam batchParam) { - if (batchParam.update(merchantWithdrawService, "id")) { - return success("修改成功"); - } - return fail("修改失败"); + @ApiOperation("提现审核拒绝") + @PostMapping("audit/reject") + public ApiResult auditReject(@RequestBody @Validated WithdrawAuditFailParam rejectParam) { + return merchantWithdrawService.auditFail(rejectParam); } - @PreAuthorize("hasAuthority('shop:merchantWithdraw:remove')") - @OperationLog - @ApiOperation("批量删除商户提现记录") - @DeleteMapping("/batch") - public ApiResult removeBatch(@RequestBody List ids) { - if (merchantWithdrawService.removeByIds(ids)) { - return success("删除成功"); - } - return fail("删除失败"); - } +// @PreAuthorize("hasAuthority('shop:merchantWithdraw:update')") +// @OperationLog +// @ApiOperation("修改商户提现记录") +// @PutMapping() +// public ApiResult update(@RequestBody MerchantWithdraw merchantWithdraw) { +// if (merchantWithdrawService.updateById(merchantWithdraw)) { +// return success("修改成功"); +// } +// return fail("修改失败"); +// } + +// @PreAuthorize("hasAuthority('shop:merchantWithdraw:remove')") +// @OperationLog +// @ApiOperation("删除商户提现记录") +// @DeleteMapping("/{id}") +// public ApiResult remove(@PathVariable("id") Integer id) { +// if (merchantWithdrawService.removeById(id)) { +// return success("删除成功"); +// } +// return fail("删除失败"); +// } + +// @PreAuthorize("hasAuthority('shop:merchantWithdraw:save')") +// @OperationLog +// @ApiOperation("批量添加商户提现记录") +// @PostMapping("/batch") +// public ApiResult saveBatch(@RequestBody List list) { +// if (merchantWithdrawService.saveBatch(list)) { +// return success("添加成功"); +// } +// return fail("添加失败"); +// } + +// @PreAuthorize("hasAuthority('shop:merchantWithdraw:update')") +// @OperationLog +// @ApiOperation("批量修改商户提现记录") +// @PutMapping("/batch") +// public ApiResult removeBatch(@RequestBody BatchParam batchParam) { +// if (batchParam.update(merchantWithdrawService, "id")) { +// return success("修改成功"); +// } +// return fail("修改失败"); +// } + +// @PreAuthorize("hasAuthority('shop:merchantWithdraw:remove')") +// @OperationLog +// @ApiOperation("批量删除商户提现记录") +// @DeleteMapping("/batch") +// public ApiResult removeBatch(@RequestBody List ids) { +// if (merchantWithdrawService.removeByIds(ids)) { +// return success("删除成功"); +// } +// return fail("删除失败"); +// } } diff --git a/src/main/java/com/gxwebsoft/shop/controller/OrderController.java b/src/main/java/com/gxwebsoft/shop/controller/OrderController.java index 8693fef..9b6d000 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/OrderController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/OrderController.java @@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.extra.qrcode.QrCodeUtil; import cn.hutool.extra.qrcode.QrConfig; import com.alibaba.fastjson.JSONArray; @@ -30,6 +31,7 @@ import com.gxwebsoft.common.core.annotation.OperationLog; import com.gxwebsoft.common.core.config.ConfigProperties; import com.gxwebsoft.common.core.utils.AlipayConfigUtil; import com.gxwebsoft.common.core.web.*; +import com.gxwebsoft.common.system.entity.Role; import com.gxwebsoft.common.system.entity.User; import com.gxwebsoft.common.system.service.UserService; import com.gxwebsoft.shop.entity.*; @@ -78,27 +80,11 @@ public class OrderController extends BaseController { @Resource private OrderGoodsService orderGoodsService; @Resource - private OrderPayService orderPayService; - @Resource private FreezeOrderService freezeOrderService; @Resource private EquipmentOrderGoodsService equipmentOrderGoodsService; - - @Resource - private AlipayConfigUtil alipayConfig; - - @Resource - private ConfigProperties pathConfig; - @Resource - private UserRefereeService userRefereeService; - @Resource - private UserService userService; - @Resource - private BcAgentService bcAgentService; - - @PreAuthorize("hasAuthority('shop:order:list')") @OperationLog @ApiOperation("分页查询订单记录表") @@ -108,12 +94,32 @@ public class OrderController extends BaseController { if ((param.getIsApp() == null || param.getIsApp() != true) && getMerchantCode() != null) { param.setMerchantCode(getMerchantCode()); } + +// Integer expireDay = param.getExpireDay(); +// if(null != expireDay){ +// if(expireDay == -1){ +// +// } +// } + + // TODO 暂不开放此条件 +// Integer userId = param.getUserId(); +// if(null != userId && userId > 0){ +// // 取订单所属门店 +// LambdaQueryWrapper mWrapper = Wrappers.lambdaQuery(); +// mWrapper.eq(Merchant::getUserId, userId).last("limit 1"); +// Merchant merchant = merchantService.getOne(mWrapper); +// if(null != merchant){ +// param.setAppMerchantCode(merchant.getMerchantCode()); +// } +// } + // 云芯威项目查询关联设备 // 查询订单的关联商品 List list = orderService.listRel(param); if (CollectionUtils.isEmpty(list)) { - return success(new PageResult<>(list, 0l)); + return success(new PageResult<>(list, 0L)); } Set equipmentIds = new HashSet<>(); Set orderIds = new HashSet<>(); @@ -123,7 +129,8 @@ public class OrderController extends BaseController { } List equipmentList = equipmentService.list(Wrappers.lambdaQuery(Equipment.class).in(Equipment::getEquipmentId, equipmentIds)); List equipmentOrderGoodsList = equipmentOrderGoodsService.list(Wrappers.lambdaQuery(EquipmentOrderGoods.class).in(EquipmentOrderGoods::getOrderId, orderIds)); - Map> equipmentCollect = equipmentList.stream().collect(Collectors.groupingBy(Equipment::getEquipmentId)); +// Map> equipmentCollect = equipmentList.stream().collect(Collectors.groupingBy(Equipment::getEquipmentId)); + Map equipmentCollect = equipmentList.stream().collect(Collectors.toMap(Equipment::getEquipmentId, e->e)); Map> equipmentOrderGoodsCollect = equipmentOrderGoodsList.stream().collect(Collectors.groupingBy(EquipmentOrderGoods::getOrderId)); // 查询订单的设备 @@ -136,14 +143,19 @@ public class OrderController extends BaseController { } EquipmentOrderGoods orderGoods = equipmentOrderGoods.get(0); order.setEquipmentGoods(orderGoods); - List equipment = equipmentCollect.get(order.getEquipmentId()); - if (CollectionUtils.isNotEmpty(equipment)) { - order.setEquipment(equipment.get(0)); +// List equipment = equipmentCollect.get(order.getEquipmentId()); +// if (CollectionUtils.isNotEmpty(equipment)) { +// order.setEquipment(equipment.get(0)); +// } + Equipment equipment = equipmentCollect.get(order.getEquipmentId()); + if(null != equipment){ + order.setEquipment(equipment); } - } PageParam page = new PageParam<>(param); - return success(new PageResult<>(list, page.getTotal())); + PageResult ret = new PageResult<>(list, page.getTotal()); + ret.setCount((long) list.size()); + return success(ret); } @@ -222,10 +234,15 @@ public class OrderController extends BaseController { public ApiResult get(@PathVariable("id") Integer id) { // 使用关联查询 Order order = orderService.getByIdRel(id); + if(null == order){ + return fail("找不到订单", null); + } // 云芯威关联设备查询 - if (!order.getGoodsId().equals(0) || !order.getEquipmentId().equals(0)) { + Integer goodsId = order.getGoodsId(); + Integer equipmentId = order.getEquipmentId(); + if ((null != goodsId && !goodsId.equals(0)) || (null != equipmentId && !equipmentId.equals(0))) { order.setEquipmentGoods(equipmentOrderGoodsService.getOne(new LambdaQueryWrapper().eq(EquipmentOrderGoods::getOrderId, order.getOrderId()))); - order.setEquipment(equipmentService.getById(order.getEquipmentId())); + order.setEquipment(equipmentService.getById(equipmentId)); } return success(order); } @@ -359,7 +376,6 @@ public class OrderController extends BaseController { order.setPeriods(9999); } - order.setFreezeOrderNo(IdUtil.getSnowflakeNextIdStr()); order.setOutRequestNo(IdUtil.getSnowflakeNextIdStr()); if (orderService.save(order)) { diff --git a/src/main/java/com/gxwebsoft/shop/controller/OrderPayController.java b/src/main/java/com/gxwebsoft/shop/controller/OrderPayController.java index 7ef7f18..2a3e61b 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/OrderPayController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/OrderPayController.java @@ -1,13 +1,20 @@ package com.gxwebsoft.shop.controller; +import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.alipay.api.AlipayApiException; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.gxwebsoft.apps.entity.EquipmentGoods; import com.gxwebsoft.apps.service.EquipmentGoodsService; import com.gxwebsoft.common.core.web.BaseController; import com.gxwebsoft.common.system.entity.User; +import com.gxwebsoft.shop.entity.FreezeOrder; import com.gxwebsoft.shop.entity.Order; +import com.gxwebsoft.shop.service.FreezeOrderService; import com.gxwebsoft.shop.service.OrderPayService; import com.gxwebsoft.shop.entity.OrderPay; import com.gxwebsoft.shop.param.OrderPayParam; @@ -19,6 +26,7 @@ import com.gxwebsoft.common.core.annotation.OperationLog; import com.gxwebsoft.shop.service.OrderService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; @@ -35,12 +43,15 @@ import static com.gxwebsoft.common.core.constants.OrderConstants.PAY_STATUS_NO_P * @author 科技小王子 * @since 2023-10-13 16:58:03 */ +@Slf4j @Api(tags = "订单记录表管理") @RestController @RequestMapping("/api/shop/order-pay") public class OrderPayController extends BaseController { @Resource private OrderPayService orderPayService; + @Resource + private FreezeOrderService freezeOrderService; @Resource @@ -84,14 +95,15 @@ public class OrderPayController extends BaseController { .orderByAsc(OrderPay::getCreateTime) .last("limit 1").one(); + Order order = orderService.getById(orderId); + + EquipmentGoods eg = equipmentGoodsService.getById(order.getOrderSourceId()); // 是否提前续租 if(one == null) { - Order order = orderService.getById(orderId); if(ORDER_STATUS_OVER.equals(order.getOrderStatus())) { return fail(null); } - EquipmentGoods eg = equipmentGoodsService.getById(order.getOrderSourceId()); one = new OrderPay(); one.setOrderNo(IdUtil.getSnowflakeNextIdStr()); one.setMerchantCode(order.getMerchantCode()); @@ -131,13 +143,46 @@ public class OrderPayController extends BaseController { one.setTotalPrice(price); one.setOrderPrice(price); one.setPayPrice(price); - } - orderPayService.save(one); - - } + one.setIsFreeze(order.getIsFreeze()); + Integer isRenew = order.getIsRenew(); + one.setIsRenew(isRenew); + + if(isRenew == 0){ + String freezeOrderNo = order.getFreezeOrderNo(); + if(StrUtil.isNotBlank(freezeOrderNo)){ + LambdaQueryWrapper fWrapper = Wrappers.lambdaQuery(); + fWrapper.eq(FreezeOrder::getOutOrderNo, freezeOrderNo) + .eq(FreezeOrder::getOperationType, "FREEZE") + .eq(FreezeOrder::getStatus, "SUCCESS") + .last("limit 1"); + int cnt = freezeOrderService.count(fWrapper); + if(cnt > 0) { + log.info("订单{}已支付支付押金!", orderId); + one.setHasFreeze(1); + } + else { + log.info("订单{}未支付押金!", orderId); +// fWrapper.clear(); +// fWrapper.eq(FreezeOrder::getOutOrderNo, freezeOrderNo) +// .eq(FreezeOrder::getStatus, "INIT"); +// boolean delRet = freezeOrderService.remove(fWrapper); + try { + String orderStr = freezeOrderService.freeze(order, eg); + one.setOrderStr(orderStr); + log.info("订单{}支付请求参数:{}", orderId, orderStr); + } catch (AlipayApiException e) { + log.error(e.getMessage(), e); + return fail("调用芝麻信用出错!"); + } + } + one.setHasFreeze(0); + } + } + + one.setEquipmentCategory(eg.getEquipmentCategory()); return success(one); } diff --git a/src/main/java/com/gxwebsoft/shop/controller/OrderRefundController.java b/src/main/java/com/gxwebsoft/shop/controller/OrderRefundController.java index 81c224c..70608a4 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/OrderRefundController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/OrderRefundController.java @@ -1,5 +1,7 @@ package com.gxwebsoft.shop.controller; +import cn.hutool.core.bean.copier.BeanCopier; +import cn.hutool.core.bean.copier.CopyOptions; import cn.hutool.core.util.IdUtil; import com.alibaba.fastjson.JSONObject; import com.alipay.api.AlipayApiException; @@ -28,10 +30,12 @@ import com.gxwebsoft.shop.service.OrderService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.math.BigDecimal; import java.util.List; import static com.gxwebsoft.common.core.constants.OrderConstants.*; @@ -104,33 +108,44 @@ public class OrderRefundController extends BaseController { @PreAuthorize("hasAuthority('shop:orderRefund:update')") @OperationLog - @ApiOperation("修改售后单记录表") + @ApiOperation(value = "修改售后单记录表", notes = "退租审核") @PutMapping() + @Transactional public ApiResult update(@RequestBody OrderRefund orderRefund) throws AlipayApiException { + OrderRefund refund = orderRefundService.getById(orderRefund.getOrderRefundId()); + BeanCopier.create(orderRefund, refund, CopyOptions.create().ignoreNullValue()).copy(); - - if (orderRefundService.updateById(orderRefund)) { - if(orderRefund.getAuditStatus().equals(20)){ - final Integer orderId = orderRefund.getOrderId(); - final Order order = orderService.getById(orderId); - System.out.println("order = " + order); - order.setReceiptStatus(RECEIPT_STATUS_RETURN); - order.setOrderStatus(ORDER_STATUS_OVER); - final Equipment equipment = equipmentService.getById(order.getEquipmentId()); - equipment.setUserId(0); - equipmentService.updateById(equipment); - orderService.updateById(order); - freezeOrderService.unfreeze(order.getOrderId()); -// freezeOrderService.deduction(order.getOrderId()); - }else if(orderRefund.getAuditStatus().equals(30)) { - final Integer orderId = orderRefund.getOrderId(); - final Order order = orderService.getById(orderId); - order.setReceiptStatus(RECEIPT_STATUS_YES); - orderService.updateById(order); + Integer auditStatus = orderRefund.getAuditStatus(); + if(auditStatus.equals(20)){ + BigDecimal refundMoney = orderRefund.getRefundMoney(); + if(null == refundMoney){ + refundMoney = BigDecimal.ZERO; } - return success("操作成功"); + + final Integer orderId = orderRefund.getOrderId(); + final Order order = orderService.getById(orderId); +// System.out.println("order = " + order); + + Integer equipmentId = order.getEquipmentId(); + if(null != equipmentId && equipmentId > 0){ + Equipment equipment = equipmentService.getById(equipmentId); + equipment.setUserId(0); + equipmentService.updateById(equipment); + } + order.setReceiptStatus(RECEIPT_STATUS_RETURN); + order.setOrderStatus(ORDER_STATUS_OVER); + orderService.updateById(order); + freezeOrderService.unfreeze(order.getOrderId(), refundMoney); +// freezeOrderService.deduction(order.getOrderId()); } - return success("退租失败"); + else if(auditStatus.equals(30)) { + final Integer orderId = orderRefund.getOrderId(); + final Order order = orderService.getById(orderId); + order.setReceiptStatus(RECEIPT_STATUS_YES); + orderService.updateById(order); + } + orderRefundService.updateById(refund); + return success("操作成功"); } diff --git a/src/main/java/com/gxwebsoft/shop/controller/PaymentController.java b/src/main/java/com/gxwebsoft/shop/controller/PaymentController.java index bc85305..22a28f5 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/PaymentController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/PaymentController.java @@ -261,6 +261,11 @@ public class PaymentController extends BaseController { // 订单数据 OrderPay order = orderPayService.getById(id); + Order rentOrder = orderService.getById(order.getRentOrderId()); + if(null != rentOrder && rentOrder.getIsRenew() == 0 && rentOrder.getIsFreeze() != 1){ + return fail("押金订单未完成!"); + } + Merchant merchant = merchantService.getMerchantByCode(order.getMerchantCode()); // final EquipmentGoods eg = equipmentGoodsService.getById(order.getGoodsId()); @@ -297,7 +302,7 @@ public class PaymentController extends BaseController { response = alipayClient.certificateExecute(request); if(response.isSuccess()){ String trade_no = response.getTradeNo();// 获取返回的tradeNO。 - return success("支付成功", trade_no); + return success("调用支付宝支付成功", trade_no); } } @@ -306,7 +311,7 @@ public class PaymentController extends BaseController { } String trade_no = response.getTradeNo();// 获取返回的tradeNO。 - return success("支付成功", trade_no); + return success("调用支付宝支付成功", trade_no); } catch (AlipayApiException e) { log.error(e.getErrMsg(), e); throw new RuntimeException(); @@ -384,7 +389,7 @@ public class PaymentController extends BaseController { parentOrder.setOrderStatus(ORDER_STATUS_OVER); parentOrder.setExpirationTime(parse); try { - freezeOrderService.unfreeze(parentOrder.getOrderId()); + freezeOrderService.unfreeze(parentOrder.getOrderId(), BigDecimal.ZERO); } catch (AlipayApiException e) { throw new RuntimeException(e); } @@ -425,6 +430,12 @@ public class PaymentController extends BaseController { if (balance.compareTo(payPrice) < 0) { return fail("余额不足 = " + balance.compareTo(payPrice)); } + +// Order rentOrder = orderService.getById(order.getRentOrderId()); +// if(null != rentOrder && rentOrder.getIsRenew() == 0 && rentOrder.getIsFreeze() != 1){ +// return fail("押金订单未完成!"); +// } + // 2. 扣除余额操作 BigDecimal subtract = balance.subtract(payPrice); user.setBalance(subtract); @@ -433,9 +444,10 @@ public class PaymentController extends BaseController { UserBalanceLog userBalanceLog = new UserBalanceLog(); userBalanceLog.setUserId(userId); userBalanceLog.setScene(BALANCE_USE); + userBalanceLog.setSceneId(id); userBalanceLog.setMoney(payPrice); userBalanceLog.setBalance(subtract); - userBalanceLog.setComments(order.getOrderNo().toString()); + userBalanceLog.setComments("订单号:" + order.getOrderNo()); userBalanceLog.setMerchantCode(order.getMerchantCode()); userBalanceLogService.save(userBalanceLog); // 4. 修改支付状态 @@ -463,7 +475,7 @@ public class PaymentController extends BaseController { parentOrder.setOrderStatus(ORDER_STATUS_OVER); parentOrder.setExpirationTime(parse); try { - freezeOrderService.unfreeze(parentOrder.getOrderId()); + freezeOrderService.unfreeze(parentOrder.getOrderId(), BigDecimal.ZERO); } catch (AlipayApiException e) { throw new RuntimeException(e); } @@ -481,7 +493,8 @@ public class PaymentController extends BaseController { @ApiModelProperty("余额支付批量") @PostMapping("/balanceBatch") @Transactional(rollbackFor = {Exception.class}) - public ApiResult balanceBatch(@RequestBody List orderIds) throws AlipayApiException { + @Deprecated + public ApiResult balanceBatch(@RequestBody List orderIds) { // 1. 验证签名 isCheckSign(); // 订单数据 @@ -512,9 +525,10 @@ public class PaymentController extends BaseController { UserBalanceLog userBalanceLog = new UserBalanceLog(); userBalanceLog.setUserId(userId); userBalanceLog.setScene(BALANCE_USE); + userBalanceLog.setSceneId(d.getOrderId()); userBalanceLog.setMoney(payPrice); userBalanceLog.setBalance(subtract); - userBalanceLog.setComments(d.getOrderNo().toString()); + userBalanceLog.setComments("订单号:" + d.getOrderNo()); userBalanceLog.setMerchantCode(d.getMerchantCode()); userBalanceLogService.save(userBalanceLog); // 4. 修改支付状态 @@ -534,7 +548,8 @@ public class PaymentController extends BaseController { parentOrder.setExpirationTime(nextMonthTime); orderService.updateById(parentOrder); // 保存续费订单状态 - d.setDeliveryStatus(DELIVERY_STATUS_YES); +// d.setDeliveryStatus(DELIVERY_STATUS_YES); + d.setDeliveryStatus(DELIVERY_STATUS_ACCEPT); d.setReceiptStatus(RECEIPT_STATUS_YES); d.setOrderStatus(ORDER_STATUS_COMPLETED); d.setStartTime(expirationTime); diff --git a/src/main/java/com/gxwebsoft/shop/controller/ProfitLogController.java b/src/main/java/com/gxwebsoft/shop/controller/ProfitLogController.java index 2474192..ec882fd 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/ProfitLogController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/ProfitLogController.java @@ -1,5 +1,8 @@ package com.gxwebsoft.shop.controller; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gxwebsoft.common.core.web.BaseController; import com.gxwebsoft.common.system.entity.User; import com.gxwebsoft.shop.service.ProfitLogService; @@ -16,6 +19,7 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.time.LocalDate; import java.util.List; /** @@ -36,9 +40,26 @@ public class ProfitLogController extends BaseController { @GetMapping("/page") public ApiResult> page(ProfitLogParam param) { PageParam page = new PageParam<>(param); - page.setDefaultOrder("create_time desc"); - PageParam result = profitLogService.page(page, page.getWrapper()); - return success(result); + QueryWrapper wrapper = page.getWrapper(); + LocalDate beginDate = param.getBeginDate(); + wrapper.ge(null != beginDate, "create_time", beginDate); + LocalDate endDate = param.getEndDate(); + if(null != endDate){ + wrapper.lt("create_time", endDate); + } + + wrapper.orderByDesc("create_time"); + Page result = profitLogService.page(new Page<>(param.getPage(), param.getLimit()), wrapper); + + JSONObject total = new JSONObject(); + wrapper.select("ifnull(sum(money), 0) money"); + ProfitLog sum = profitLogService.getOne(wrapper); + if(null != sum){ + total.put("total", sum.getMoney()); + } + PageResult retPage = new PageResult<>(result.getRecords(), result.getTotal()); + retPage.setOtherData(total); + return success(retPage); // 使用关联查询 // return success(profitLogService.pageRel(param)); } diff --git a/src/main/java/com/gxwebsoft/shop/controller/RechargeOrderController.java b/src/main/java/com/gxwebsoft/shop/controller/RechargeOrderController.java index dd4ae2f..afa1e5f 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/RechargeOrderController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/RechargeOrderController.java @@ -62,6 +62,7 @@ public class RechargeOrderController extends BaseController { UserBalanceLog userBalanceLog = new UserBalanceLog(); userBalanceLog.setUserId(rechargeOrder.getUserId()); userBalanceLog.setScene(BALANCE_ADMIN); + userBalanceLog.setSceneId(rechargeOrder.getOrderId()); userBalanceLog.setMoney(rechargeOrder.getPayPrice()); userBalanceLog.setBalance(balance); userBalanceLog.setComments("操作人:" + getLoginUser().getNickname()); @@ -158,6 +159,7 @@ public class RechargeOrderController extends BaseController { UserBalanceLog userBalanceLog = new UserBalanceLog(); userBalanceLog.setUserId(d.getUserId()); userBalanceLog.setScene(BALANCE_ADMIN); + userBalanceLog.setSceneId(d.getOrderId()); userBalanceLog.setMoney(d.getPayPrice()); userBalanceLog.setBalance(balance); userBalanceLog.setComments("操作人:" + nickname); diff --git a/src/main/java/com/gxwebsoft/shop/entity/FreezeOrder.java b/src/main/java/com/gxwebsoft/shop/entity/FreezeOrder.java index b7c8fa5..e0b2a2c 100644 --- a/src/main/java/com/gxwebsoft/shop/entity/FreezeOrder.java +++ b/src/main/java/com/gxwebsoft/shop/entity/FreezeOrder.java @@ -40,6 +40,9 @@ public class FreezeOrder implements Serializable { @ApiModelProperty(value = "冻结金额") private BigDecimal amount; + @ApiModelProperty(value = "实际解冻金额") + private BigDecimal unfreezeAmount; + @ApiModelProperty(value = "手机号或邮箱") private String payeeLogonId; diff --git a/src/main/java/com/gxwebsoft/shop/entity/MerchantWithdraw.java b/src/main/java/com/gxwebsoft/shop/entity/MerchantWithdraw.java index 4da10c1..e84fdb4 100644 --- a/src/main/java/com/gxwebsoft/shop/entity/MerchantWithdraw.java +++ b/src/main/java/com/gxwebsoft/shop/entity/MerchantWithdraw.java @@ -10,8 +10,11 @@ import java.util.Date; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; /** * 商户提现记录 @@ -23,6 +26,9 @@ import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = false) @ApiModel(value = "MerchantWithdraw对象", description = "商户提现记录") @TableName("shop_merchant_withdraw") +@Builder +@NoArgsConstructor +@AllArgsConstructor public class MerchantWithdraw implements Serializable { private static final long serialVersionUID = 1L; @@ -36,12 +42,18 @@ public class MerchantWithdraw implements Serializable { @ApiModelProperty(value = "用户ID") private Integer userId; + @ApiModelProperty(value = "用户昵称") + private String nickname; + @ApiModelProperty(value = "提现金额") private BigDecimal money; - @ApiModelProperty(value = "打款方式 (10微信 20支付宝 30银行卡)") + @ApiModelProperty(value = "收款方式 (10微信 20支付宝 30银行卡 40线下)") private Integer payType; + @ApiModelProperty(value = "收款方式 (10微信 20支付宝 30银行卡)") + private Integer cardType; + @ApiModelProperty(value = "支付宝姓名") private String alipayName; @@ -57,7 +69,7 @@ public class MerchantWithdraw implements Serializable { @ApiModelProperty(value = "银行卡号") private String bankCard; - @ApiModelProperty(value = "申请状态 (10待审核 20审核通过 30驳回 40已打款)") + @ApiModelProperty(value = "申请状态 (10待审核 20审核通过 30驳回)") private Integer applyStatus; @ApiModelProperty(value = "驳回原因") @@ -95,10 +107,6 @@ public class MerchantWithdraw implements Serializable { @TableField(exist = false) private String merchantName; - @ApiModelProperty(value = "评论者昵称") - @TableField(exist = false) - private String nickname; - @ApiModelProperty(value = "评论者头像") @TableField(exist = false) private String avatar; @@ -107,4 +115,67 @@ public class MerchantWithdraw implements Serializable { @TableField(exist = false) private String realName; + @ApiModelProperty(value = "卡类型描述") + @TableField(exist = false) + private String cardTypeDis; + + @ApiModelProperty(value = "转账方式描述") + @TableField(exist = false) + private String payTypeDis; + + @ApiModelProperty(value = "状态描述") + @TableField(exist = false) + private String applyStatusDis; + + public String getCardTypeDis() { + if(null != cardType){ + switch (cardType){ + case 10: + cardTypeDis = "微信"; + break; + case 20: + cardTypeDis = "支付宝"; + break; + case 30: + cardTypeDis = "银行卡"; + } + } + return cardTypeDis; + } + + public String getPayTypeDis() { + if(null != payType){ + switch (payType){ + case 10: + payTypeDis = "微信"; + break; + case 20: + payTypeDis = "支付宝"; + break; + case 30: + payTypeDis = "银行卡"; + break; + case 40: + payTypeDis = "线下"; + } + } + return payTypeDis; + } + + public String getApplyStatusDis() { + if(null != applyStatus){ + switch (applyStatus){ + case 10: + applyStatusDis = "待审核"; + break; + case 30: + applyStatusDis = "审核拒绝"; + break; + case 20: + applyStatusDis = "审核通过"; + break; + } + } + return applyStatusDis; + } } diff --git a/src/main/java/com/gxwebsoft/shop/entity/Order.java b/src/main/java/com/gxwebsoft/shop/entity/Order.java index ba6c98e..2af38c4 100644 --- a/src/main/java/com/gxwebsoft/shop/entity/Order.java +++ b/src/main/java/com/gxwebsoft/shop/entity/Order.java @@ -1,5 +1,7 @@ package com.gxwebsoft.shop.entity; +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.annotation.*; import com.gxwebsoft.apps.entity.Equipment; import com.gxwebsoft.apps.entity.EquipmentOrderGoods; @@ -117,9 +119,10 @@ public class Order implements Serializable { @ApiModelProperty(value = "物流单号 (废弃)") private String expressNo; - @ApiModelProperty(value = "发货状态(10未发货 20已发货 30部分发货)") + @ApiModelProperty(value = "发货状态(10未发货 20已发货 30部分发货 40已绑定)") private Integer deliveryStatus; + @ApiModelProperty(value = "是否交押金") private Integer isFreeze; @ApiModelProperty(value = "发货时间") @@ -131,7 +134,7 @@ public class Order implements Serializable { @ApiModelProperty(value = "收货时间") private Date receiptTime; - @ApiModelProperty(value = "订单状态(10进行中 20取消 21待取消 30已完成)") + @ApiModelProperty(value = "订单状态(10待付款 20进行中 21待取消 30已绑定 40已完成)") private Integer orderStatus; @ApiModelProperty(value = "赠送的积分数量") @@ -283,6 +286,10 @@ public class Order implements Serializable { @ApiModelProperty("逾期天数") private Integer expirationDay; + @ApiModelProperty("剩余天数") + @TableField(exist = false) + private Integer restDay; + @ApiModelProperty("设备") @TableField(exist = false) private Equipment equipment; @@ -306,4 +313,22 @@ public class Order implements Serializable { @ApiModelProperty("设备编码") @TableField(exist = false) private String equipmentCode; + + public Integer getRestDay() { + if(null != orderStatus){ + switch(orderStatus){ + case 10: + case 40: + return 0; + case 20: + case 30: + default: + if(null == expirationTime){ + return 0; + } + return Math.toIntExact(DateUtil.between(new Date(), expirationTime, DateUnit.DAY, false)); + } + } + return restDay; + } } diff --git a/src/main/java/com/gxwebsoft/shop/entity/OrderPay.java b/src/main/java/com/gxwebsoft/shop/entity/OrderPay.java index 7894b54..60b4402 100644 --- a/src/main/java/com/gxwebsoft/shop/entity/OrderPay.java +++ b/src/main/java/com/gxwebsoft/shop/entity/OrderPay.java @@ -4,6 +4,7 @@ import java.math.BigDecimal; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; @@ -175,6 +176,26 @@ public class OrderPay implements Serializable { @ApiModelProperty(value = "修改时间") private Date updateTime; + @ApiModelProperty(value = "是否已交押金") + @TableField(exist = false) + private Integer isFreeze; + + @ApiModelProperty(value = "是否续费单") + @TableField(exist = false) + private Integer isRenew; + + @ApiModelProperty(value = "下单类型") + @TableField(exist = false) + private String equipmentCategory; + + @ApiModelProperty(value = "是否存在成功的押金订单") + @TableField(exist = false) + private Integer hasFreeze; + + @ApiModelProperty(value = "支付宝支付参数") + @TableField(exist = false) + private String orderStr; + public Long getExpirationDay() { switch(payStatus){ case OrderConstants.PAY_STATUS_NO_PAY: diff --git a/src/main/java/com/gxwebsoft/shop/entity/OrderRefund.java b/src/main/java/com/gxwebsoft/shop/entity/OrderRefund.java index 3609322..d9334a8 100644 --- a/src/main/java/com/gxwebsoft/shop/entity/OrderRefund.java +++ b/src/main/java/com/gxwebsoft/shop/entity/OrderRefund.java @@ -32,7 +32,7 @@ public class OrderRefund implements Serializable { @ApiModelProperty(value = "订单ID") private Integer orderId; - @TableField(exist = false) + @ApiModelProperty(value = "订单编号") private String orderNo; @@ -48,7 +48,7 @@ public class OrderRefund implements Serializable { @ApiModelProperty(value = "用户申请原因(说明)") private String applyDesc; - @ApiModelProperty(value = "商家审核状态(0待审核 10已同意 20已拒绝)") + @ApiModelProperty(value = "商家审核状态(0待审核 10申请中 20已同意 30已拒绝)") private Integer auditStatus; @ApiModelProperty(value = "商家拒绝原因(说明)") diff --git a/src/main/java/com/gxwebsoft/shop/entity/ProfitLog.java b/src/main/java/com/gxwebsoft/shop/entity/ProfitLog.java index 6105c0a..c9c2475 100644 --- a/src/main/java/com/gxwebsoft/shop/entity/ProfitLog.java +++ b/src/main/java/com/gxwebsoft/shop/entity/ProfitLog.java @@ -8,6 +8,7 @@ import java.time.LocalDateTime; import java.io.Serializable; import java.util.Date; +import com.gxwebsoft.common.core.enums.EProfitScene; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -49,6 +50,10 @@ public class ProfitLog implements Serializable { @ApiModelProperty(value = "收益类型(1资产收益,2服务费收益,3推广收益,4门店业绩提成,5站点业绩提成)") private Integer scene; + @ApiModelProperty(value = "收益类型描述") + @TableField(exist = false) + private String sceneDis; + @ApiModelProperty(value = "变动金额") private BigDecimal money; @@ -74,16 +79,19 @@ public class ProfitLog implements Serializable { @ApiModelProperty(value = "商户编码") private String merchantCode; + @ApiModelProperty(value = "商户名称") private String merchantName; @ApiModelProperty(value = "设备编码") private String equipmentCode; - @ApiModelProperty(value = "设备编码") + @ApiModelProperty(value = "设备编号") private Integer equipmentId; + @ApiModelProperty(value = "订单用户名") private String orderUserName; + @ApiModelProperty(value = "订单用户手机号") private String orderUserPhone; @ApiModelProperty(value = "租户id") @@ -95,4 +103,10 @@ public class ProfitLog implements Serializable { @ApiModelProperty(value = "修改时间") private Date updateTime; + public String getSceneDis() { + if(null != scene){ + return EProfitScene.getNameByValue(scene); + } + return sceneDis; + } } diff --git a/src/main/java/com/gxwebsoft/shop/entity/UserBalanceLog.java b/src/main/java/com/gxwebsoft/shop/entity/UserBalanceLog.java index 792e3cd..630bd3e 100644 --- a/src/main/java/com/gxwebsoft/shop/entity/UserBalanceLog.java +++ b/src/main/java/com/gxwebsoft/shop/entity/UserBalanceLog.java @@ -10,8 +10,11 @@ import java.util.Date; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; /** * 用户余额变动明细表 @@ -23,6 +26,9 @@ import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = false) @ApiModel(value = "UserBalanceLog对象", description = "用户余额变动明细表") @TableName("shop_user_balance_log") +@Builder +@NoArgsConstructor +@AllArgsConstructor public class UserBalanceLog implements Serializable { private static final long serialVersionUID = 1L; @@ -33,9 +39,12 @@ public class UserBalanceLog implements Serializable { @ApiModelProperty(value = "用户ID") private Integer userId; - @ApiModelProperty(value = "余额变动场景(10用户充值 20用户消费 30管理员操作 40订单退款)") + @ApiModelProperty(value = "余额变动场景(10用户充值 20用户消费 30管理员操作 40订单退款, 50用户提现,60提现失败)") private Integer scene; + @ApiModelProperty(value = "场景来源单号") + private Integer sceneId; + @ApiModelProperty(value = "变动金额") private BigDecimal money; diff --git a/src/main/java/com/gxwebsoft/shop/mapper/OrderMapper.java b/src/main/java/com/gxwebsoft/shop/mapper/OrderMapper.java index 670ba16..e3fa34b 100644 --- a/src/main/java/com/gxwebsoft/shop/mapper/OrderMapper.java +++ b/src/main/java/com/gxwebsoft/shop/mapper/OrderMapper.java @@ -62,10 +62,10 @@ public interface OrderMapper extends BaseMapper { * 查找到期预警订单 * @return */ - @Select("select u.phone userPhone, DATEDIFF(o.expiration_time,CURDATE()) expirationDay " + + @Select("select u.phone, DATEDIFF(o.expiration_time,CURDATE()) expirationDay " + "from shop_order o join sys_user u on o.user_id = u.user_id " + - "where DATEDIFF(o.expiration_time,CURDATE()) in (-1, 0) and u.phone is not null " + - "and o.is_freeze = 1 and o.receipt_status != 10 and o.pay_status = 10 and o.is_renew = 1") + "where DATEDIFF(o.expiration_time,CURDATE()) in (1, 0) and u.phone is not null " + + "and o.pay_status = 20 and o.order_status != 40") @ResultType(Order.class) List selectAlertList(); @@ -73,10 +73,10 @@ public interface OrderMapper extends BaseMapper { * 查找超期1天订单 * @return */ - @Select("select u.phone userPhone, DATEDIFF(o.expiration_time,CURDATE()) expirationDay " + + @Select("select u.phone, DATEDIFF(o.expiration_time,CURDATE()) expirationDay " + "from shop_order o join sys_user u on o.user_id = u.user_id " + - "where DATEDIFF(o.expiration_time,CURDATE()) = 1 and u.phone is not null " + - "and o.is_freeze = 1 and o.receipt_status != 10 and o.pay_status = 10 and o.is_renew = 1") + "where DATEDIFF(o.expiration_time,CURDATE()) = -1 and u.phone is not null " + + "and o.pay_status = 20 and o.order_status != 40") @ResultType(Order.class) List selectOutOfOneDayList(); } diff --git a/src/main/java/com/gxwebsoft/shop/mapper/xml/OrderMapper.xml b/src/main/java/com/gxwebsoft/shop/mapper/xml/OrderMapper.xml index aa71c57..150f6d8 100644 --- a/src/main/java/com/gxwebsoft/shop/mapper/xml/OrderMapper.xml +++ b/src/main/java/com/gxwebsoft/shop/mapper/xml/OrderMapper.xml @@ -139,7 +139,14 @@ AND a.is_temporary = #{param.isTemporary} - AND a.user_id = #{param.userId} + + + AND (a.user_id = #{param.userId} or a.merchant_code = #{param.appMerchantCode}) + + + AND a.user_id = #{param.userId} + + AND a.user_id IN @@ -192,6 +199,12 @@ OR d.merchant_name LIKE CONCAT('%', #{param.keywords}, '%') ) + + AND curdate() > a.expiration_time AND a.order_status = 30 + + + AND #{param.expireDay} >= datediff(a.expiration_time, curdate()) AND a.order_status = 30 + diff --git a/src/main/java/com/gxwebsoft/shop/mapper/xml/OrderRefundMapper.xml b/src/main/java/com/gxwebsoft/shop/mapper/xml/OrderRefundMapper.xml index e578fea..729cecc 100644 --- a/src/main/java/com/gxwebsoft/shop/mapper/xml/OrderRefundMapper.xml +++ b/src/main/java/com/gxwebsoft/shop/mapper/xml/OrderRefundMapper.xml @@ -79,6 +79,9 @@ AND a.create_time <= #{param.createTimeEnd} + + AND a.order_no = #{param.orderNo} + diff --git a/src/main/java/com/gxwebsoft/shop/param/MerchantWithdrawParam.java b/src/main/java/com/gxwebsoft/shop/param/MerchantWithdrawParam.java index fb878cf..a6a5153 100644 --- a/src/main/java/com/gxwebsoft/shop/param/MerchantWithdrawParam.java +++ b/src/main/java/com/gxwebsoft/shop/param/MerchantWithdrawParam.java @@ -11,6 +11,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import java.math.BigDecimal; +import java.time.LocalDate; import java.util.Date; /** @@ -26,7 +27,7 @@ import java.util.Date; public class MerchantWithdrawParam extends BaseParam { private static final long serialVersionUID = 1L; - @ApiModelProperty(value = "主键ID") + @ApiModelProperty(value = "主键") @QueryField(type = QueryType.EQ) private Integer id; @@ -34,67 +35,24 @@ public class MerchantWithdrawParam extends BaseParam { @QueryField(type = QueryType.EQ) private String withdrawCode; - @ApiModelProperty(value = "用户ID") + @ApiModelProperty(value = "用户昵称") @QueryField(type = QueryType.EQ) - private Integer userId; - - @ApiModelProperty(value = "提现金额") - @QueryField(type = QueryType.EQ) - private BigDecimal money; + private Integer nickname; @ApiModelProperty(value = "打款方式 (10微信 20支付宝 30银行卡)") @QueryField(type = QueryType.EQ) private Integer payType; - @ApiModelProperty(value = "支付宝姓名") - private String alipayName; - - @ApiModelProperty(value = "支付宝账号") - private String alipayAccount; - - @ApiModelProperty(value = "开户行名称") - private String bankName; - - @ApiModelProperty(value = "银行开户名") - private String bankAccount; - - @ApiModelProperty(value = "银行卡号") - private String bankCard; - @ApiModelProperty(value = "申请状态 (10待审核 20审核通过 30驳回 40已打款)") @QueryField(type = QueryType.EQ) private Integer applyStatus; - @ApiModelProperty(value = "审核时间") - @QueryField(type = QueryType.EQ) - private Integer auditTime; + @ApiModelProperty(value = "开始日期") + private LocalDate beginDate; - @ApiModelProperty(value = "驳回原因") - private String rejectReason; - - @ApiModelProperty(value = "来源客户端(APP、H5、小程序等)") - private String platform; - - @ApiModelProperty(value = "排序(数字越小越靠前)") - @QueryField(type = QueryType.EQ) - private Integer sortNumber; - - @ApiModelProperty(value = "备注") - private String comments; - - @ApiModelProperty(value = "状态, 0正常, 1冻结") - @QueryField(type = QueryType.EQ) - private Integer status; - - @ApiModelProperty(value = "是否删除, 0否, 1是") - @QueryField(type = QueryType.EQ) - private Integer deleted; - - @ApiModelProperty(value = "关联商户编号") - private String merchantCode; - - @ApiModelProperty(value = "商户名称") - @QueryField(type = QueryType.LIKE) - private String merchantName; + @ApiModelProperty(value = "结束日期") + private LocalDate endDate; + @ApiModelProperty(value = "用户编号", hidden = true) + private Integer userId; } diff --git a/src/main/java/com/gxwebsoft/shop/param/OrderParam.java b/src/main/java/com/gxwebsoft/shop/param/OrderParam.java index d758e5b..a127488 100644 --- a/src/main/java/com/gxwebsoft/shop/param/OrderParam.java +++ b/src/main/java/com/gxwebsoft/shop/param/OrderParam.java @@ -71,6 +71,7 @@ public class OrderParam extends BaseParam { @ApiModelProperty(value = "支付方式(废弃)") @QueryField(type = QueryType.EQ) + @Deprecated private Integer payType; @ApiModelProperty(value = "支付方式(余额/微信/支付宝)") @@ -198,6 +199,10 @@ public class OrderParam extends BaseParam { @QueryField(type = QueryType.EQ) private String merchantCode; + @ApiModelProperty(value = "商户编号", notes="用于小程序端查询门店客户订单") + @TableField(exist = false) + private String appMerchantCode; + @ApiModelProperty(value = "商户名称") @QueryField(type = QueryType.LIKE) private String merchantName; @@ -218,7 +223,6 @@ public class OrderParam extends BaseParam { private Integer deleted; @ApiModelProperty(value = "是否按代报餐查询") - @TableField(exist = false) private Boolean agent; @ApiModelProperty(value = "租户ID") @@ -226,19 +230,15 @@ public class OrderParam extends BaseParam { private Integer tenantId; @ApiModelProperty("搜索关键字") - @TableField(exist = false) private String keywords; @ApiModelProperty(value = "签名") - @TableField(exist = false) private String sign; @ApiModelProperty(value = "是否查询订单商品") - @TableField(exist = false) private Boolean showGoodsList; @ApiModelProperty(value = "用户id集合") - @TableField(exist = false) private Set userIds; private Boolean isApp; @@ -247,4 +247,9 @@ public class OrderParam extends BaseParam { private Integer isFreeze; + @ApiModelProperty(value = "到期天数") + private Integer expireDay; + + @ApiModelProperty(value = "是否逾期") + private Integer isExpire; } diff --git a/src/main/java/com/gxwebsoft/shop/param/OrderReceiptParam.java b/src/main/java/com/gxwebsoft/shop/param/OrderReceiptParam.java index 485a094..4fadd0f 100644 --- a/src/main/java/com/gxwebsoft/shop/param/OrderReceiptParam.java +++ b/src/main/java/com/gxwebsoft/shop/param/OrderReceiptParam.java @@ -3,6 +3,7 @@ package com.gxwebsoft.shop.param; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import org.springframework.validation.annotation.Validated; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; @@ -10,32 +11,33 @@ import java.io.Serializable; @Data @ApiModel("确认收货请求参数") +@Validated public class OrderReceiptParam implements Serializable { @ApiModelProperty(value = "订单ID", required = true) @NotNull(message = "订单编号不能为空!") private Integer orderId; -// @ApiModelProperty(value = "来源记录的参数 (json格式)", required = true) -// @NotBlank(message = "身份信息数据不能为空!") + @ApiModelProperty(value = "来源记录的参数 (json格式)", required = true) + @NotBlank(message = "身份信息数据不能为空!") private String orderSourceData; - @ApiModelProperty(value = "验证码", required = true) - @NotBlank(message = "验证码不能为空!") +// @ApiModelProperty(value = "验证码", required = true) +// @NotBlank(message = "验证码不能为空!") private String captcha; - @ApiModelProperty(value = "收货人手机号", required = true) - @NotBlank(message = "收货人手机号不能为空!") +// @ApiModelProperty(value = "收货人手机号", required = true) +// @NotBlank(message = "收货人手机号不能为空!") private String receiptPhone; - @ApiModelProperty(value = "紧急联系人") - @NotBlank(message = "紧急联系人不能为空!") +// @ApiModelProperty(value = "紧急联系人") +// @NotBlank(message = "紧急联系人不能为空!") private String emergentUser; - @ApiModelProperty(value = "单位地址") - @NotBlank(message = "单位地址不能为空!") +// @ApiModelProperty(value = "单位地址") +// @NotBlank(message = "单位地址不能为空!") private String officeAddress; - @ApiModelProperty(value = "家庭地址") - @NotBlank(message = "家庭地址不能为空!") +// @ApiModelProperty(value = "家庭地址") +// @NotBlank(message = "家庭地址不能为空!") private String homeAddress; } diff --git a/src/main/java/com/gxwebsoft/shop/param/OrderRefundParam.java b/src/main/java/com/gxwebsoft/shop/param/OrderRefundParam.java index 35bf31c..207ed5a 100644 --- a/src/main/java/com/gxwebsoft/shop/param/OrderRefundParam.java +++ b/src/main/java/com/gxwebsoft/shop/param/OrderRefundParam.java @@ -32,6 +32,9 @@ public class OrderRefundParam extends BaseParam { @QueryField(type = QueryType.EQ) private Integer orderId; + @ApiModelProperty(value = "订单编号") + private String orderNo; + @ApiModelProperty(value = "订单商品ID") @QueryField(type = QueryType.EQ) private Integer orderGoodsId; diff --git a/src/main/java/com/gxwebsoft/shop/param/ProfitLogParam.java b/src/main/java/com/gxwebsoft/shop/param/ProfitLogParam.java index 0f5a410..f03ba89 100644 --- a/src/main/java/com/gxwebsoft/shop/param/ProfitLogParam.java +++ b/src/main/java/com/gxwebsoft/shop/param/ProfitLogParam.java @@ -10,6 +10,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import java.math.BigDecimal; +import java.time.LocalDate; /** * 门店收益明细表查询参数 @@ -28,49 +29,37 @@ public class ProfitLogParam extends BaseParam { @QueryField(type = QueryType.EQ) private Integer profitId; - @ApiModelProperty(value = "订单ID") + @ApiModelProperty(value = "用户编号") @QueryField(type = QueryType.EQ) - private Integer orderId; + private Integer userId; @ApiModelProperty(value = "订单号") @QueryField(type = QueryType.EQ) private String orderNo; - @ApiModelProperty(value = "用户ID") + @ApiModelProperty(value = "用户名") @QueryField(type = QueryType.EQ) - private Integer userId; + private String orderUserName; + + @ApiModelProperty(value = "商户编码") + @QueryField(type = QueryType.EQ) + private String merchantCode; + + @ApiModelProperty(value = "商户名") + @QueryField(type = QueryType.EQ) + private String merchantName; @ApiModelProperty(value = "收益类型(1资产收益,2服务费收益,3推广收益,4门店业绩提成,5站点业绩提成)") @QueryField(type = QueryType.EQ) private Integer scene; - @ApiModelProperty(value = "变动金额") - @QueryField(type = QueryType.EQ) - private BigDecimal money; - - @ApiModelProperty(value = "变动后余额") - @QueryField(type = QueryType.EQ) - private BigDecimal balance; - - @ApiModelProperty(value = "管理员备注") - private String remark; - - @ApiModelProperty(value = "排序(数字越小越靠前)") - @QueryField(type = QueryType.EQ) - private Integer sortNumber; - - @ApiModelProperty(value = "备注") - private String comments; - @ApiModelProperty(value = "状态, 0正常, 1冻结") @QueryField(type = QueryType.EQ) private Integer status; - @ApiModelProperty(value = "是否删除, 0否, 1是") - @QueryField(type = QueryType.EQ) - private Integer deleted; - - @ApiModelProperty(value = "商户编码") - private String merchantCode; + @ApiModelProperty(value = "开始日期") + private LocalDate beginDate; + @ApiModelProperty(value = "结束日期") + private LocalDate endDate; } diff --git a/src/main/java/com/gxwebsoft/shop/param/WithdrawApplyParam.java b/src/main/java/com/gxwebsoft/shop/param/WithdrawApplyParam.java new file mode 100644 index 0000000..087a655 --- /dev/null +++ b/src/main/java/com/gxwebsoft/shop/param/WithdrawApplyParam.java @@ -0,0 +1,58 @@ +package com.gxwebsoft.shop.param; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.gxwebsoft.common.core.annotation.QueryField; +import com.gxwebsoft.common.core.annotation.QueryType; +import com.gxwebsoft.common.core.web.BaseParam; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.math.BigDecimal; + +/** + * 商户管理查询参数 + * + * @author 科技小王子 + * @since 2022-11-30 15:10:54 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(value = "申请提现对象", description = "申请提现请求参数") +public class WithdrawApplyParam implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "提现金额", required = true) + @NotNull(message = "提现金额不能为空") + private BigDecimal amount; + + @ApiModelProperty(value = "收款账号类型 (10微信 20支付宝 30银行卡),不传默认20") + private Integer cardType = 20; + + @ApiModelProperty(value = "支付宝姓名") + private String alipayName; + + @ApiModelProperty(value = "支付宝账号") + private String alipayAccount; + + @ApiModelProperty(value = "开户行名称") + private String bankName; + + @ApiModelProperty(value = "银行开户名") + private String bankAccount; + + @ApiModelProperty(value = "银行卡号") + private String bankCard; + + @ApiModelProperty(value = "备注") + private String comments; + + @ApiModelProperty(value = "用户ID", hidden = true) + private Integer userId; + +} diff --git a/src/main/java/com/gxwebsoft/shop/param/WithdrawAuditFailParam.java b/src/main/java/com/gxwebsoft/shop/param/WithdrawAuditFailParam.java new file mode 100644 index 0000000..399e9bd --- /dev/null +++ b/src/main/java/com/gxwebsoft/shop/param/WithdrawAuditFailParam.java @@ -0,0 +1,26 @@ +package com.gxwebsoft.shop.param; + + +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +@Data +@EqualsAndHashCode(callSuper = false) +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(value = "提现审核拒绝对象", description = "提现审核拒绝参数") +public class WithdrawAuditFailParam implements Serializable { + @ApiModelProperty(value = "主键ID", required = true) + @NotNull(message = "申请单号不能为空!") + private Integer id; + + @ApiModelProperty(value = "理由", required = true) + @NotEmpty(message = "拒绝理由不能为空!") + private String rejectReason; +} diff --git a/src/main/java/com/gxwebsoft/shop/param/WithdrawAuditPassParam.java b/src/main/java/com/gxwebsoft/shop/param/WithdrawAuditPassParam.java new file mode 100644 index 0000000..5f445b0 --- /dev/null +++ b/src/main/java/com/gxwebsoft/shop/param/WithdrawAuditPassParam.java @@ -0,0 +1,27 @@ +package com.gxwebsoft.shop.param; + + +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +@Data +@EqualsAndHashCode(callSuper = false) +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(value = "提现审核成功对象", description = "提现审核成功参数") +public class WithdrawAuditPassParam implements Serializable { + @ApiModelProperty(value = "主键ID", required = true) + @NotNull(message = "申请单号不能为空!") + private Integer id; + + @ApiModelProperty(value = "收款方式 (10微信 20支付宝 30银行卡 40线下),不传默认40") + private Integer payType = 40; + + @ApiModelProperty(value = "备注") + private String comments; +} diff --git a/src/main/java/com/gxwebsoft/shop/service/FreezeOrderService.java b/src/main/java/com/gxwebsoft/shop/service/FreezeOrderService.java index a9f76d6..358827d 100644 --- a/src/main/java/com/gxwebsoft/shop/service/FreezeOrderService.java +++ b/src/main/java/com/gxwebsoft/shop/service/FreezeOrderService.java @@ -9,6 +9,7 @@ import com.gxwebsoft.shop.entity.FreezeOrder; import com.gxwebsoft.shop.entity.Order; import com.gxwebsoft.shop.param.FreezeOrderParam; +import java.math.BigDecimal; import java.util.List; /** @@ -46,9 +47,10 @@ public interface FreezeOrderService extends IService { /** * 解冻 * @param orderId + * @param unFreezeAmount 解冻金额 * @throws AlipayApiException */ - void unfreeze(Integer orderId) throws AlipayApiException; + void unfreeze(Integer orderId, BigDecimal unFreezeAmount) throws AlipayApiException; /** * 冻结 diff --git a/src/main/java/com/gxwebsoft/shop/service/MerchantWithdrawService.java b/src/main/java/com/gxwebsoft/shop/service/MerchantWithdrawService.java index a3c5227..f30f86a 100644 --- a/src/main/java/com/gxwebsoft/shop/service/MerchantWithdrawService.java +++ b/src/main/java/com/gxwebsoft/shop/service/MerchantWithdrawService.java @@ -1,9 +1,13 @@ package com.gxwebsoft.shop.service; import com.baomidou.mybatisplus.extension.service.IService; +import com.gxwebsoft.common.core.web.ApiResult; import com.gxwebsoft.common.core.web.PageResult; import com.gxwebsoft.shop.entity.MerchantWithdraw; import com.gxwebsoft.shop.param.MerchantWithdrawParam; +import com.gxwebsoft.shop.param.WithdrawApplyParam; +import com.gxwebsoft.shop.param.WithdrawAuditFailParam; +import com.gxwebsoft.shop.param.WithdrawAuditPassParam; import java.util.List; @@ -39,4 +43,24 @@ public interface MerchantWithdrawService extends IService { */ MerchantWithdraw getByIdRel(Integer id); + /** + * 申请提现 + * @param withdraw + * @return + */ + ApiResult apply(WithdrawApplyParam withdraw); + + /** + * 审核通过 + * @param succ + * @return + */ + ApiResult auditSuccess(WithdrawAuditPassParam succ); + + /** + * 审核拒绝 + * @param failParam + * @return + */ + ApiResult auditFail(WithdrawAuditFailParam failParam); } diff --git a/src/main/java/com/gxwebsoft/shop/service/impl/FreezeOrderServiceImpl.java b/src/main/java/com/gxwebsoft/shop/service/impl/FreezeOrderServiceImpl.java index 9cf668c..3efc88d 100644 --- a/src/main/java/com/gxwebsoft/shop/service/impl/FreezeOrderServiceImpl.java +++ b/src/main/java/com/gxwebsoft/shop/service/impl/FreezeOrderServiceImpl.java @@ -3,6 +3,7 @@ package com.gxwebsoft.shop.service.impl; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alipay.api.AlipayApiException; import com.alipay.api.DefaultAlipayClient; @@ -21,6 +22,7 @@ import com.gxwebsoft.common.core.web.PageParam; import com.gxwebsoft.common.core.web.PageResult; import com.gxwebsoft.shop.service.OrderPayService; import com.gxwebsoft.shop.service.OrderService; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; @@ -34,6 +36,7 @@ import java.util.List; * @author 科技小王子 * @since 2023-10-08 10:15:22 */ +@Slf4j @Service public class FreezeOrderServiceImpl extends ServiceImpl implements FreezeOrderService { @@ -73,7 +76,7 @@ public class FreezeOrderServiceImpl extends ServiceImpl implements MerchantService { @Resource private StringRedisTemplate stringRedisTemplate; - @Resource - private CacheClient cacheClient; @Override public PageResult pageRel(MerchantParam param) { diff --git a/src/main/java/com/gxwebsoft/shop/service/impl/MerchantWithdrawServiceImpl.java b/src/main/java/com/gxwebsoft/shop/service/impl/MerchantWithdrawServiceImpl.java index 41b08c6..3fc882e 100644 --- a/src/main/java/com/gxwebsoft/shop/service/impl/MerchantWithdrawServiceImpl.java +++ b/src/main/java/com/gxwebsoft/shop/service/impl/MerchantWithdrawServiceImpl.java @@ -1,14 +1,44 @@ package com.gxwebsoft.shop.service.impl; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; +import com.alipay.api.AlipayApiException; +import com.alipay.api.AlipayClient; +import com.alipay.api.domain.AlipayFundTransUniTransferModel; +import com.alipay.api.domain.Participant; +import com.alipay.api.request.AlipayFundTransUniTransferRequest; +import com.alipay.api.response.AlipayFundTransUniTransferResponse; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.gxwebsoft.common.core.constants.BalanceConstants; +import com.gxwebsoft.common.core.utils.AlipayConfigUtil; +import com.gxwebsoft.common.core.web.ApiResult; +import com.gxwebsoft.common.system.entity.User; +import com.gxwebsoft.common.system.service.UserService; +import com.gxwebsoft.shop.entity.Merchant; +import com.gxwebsoft.shop.entity.UserBalanceLog; import com.gxwebsoft.shop.mapper.MerchantWithdrawMapper; +import com.gxwebsoft.shop.param.WithdrawApplyParam; +import com.gxwebsoft.shop.param.WithdrawAuditFailParam; +import com.gxwebsoft.shop.param.WithdrawAuditPassParam; +import com.gxwebsoft.shop.service.MerchantService; import com.gxwebsoft.shop.service.MerchantWithdrawService; import com.gxwebsoft.shop.entity.MerchantWithdraw; import com.gxwebsoft.shop.param.MerchantWithdrawParam; import com.gxwebsoft.common.core.web.PageParam; import com.gxwebsoft.common.core.web.PageResult; +import com.gxwebsoft.shop.service.UserBalanceLogService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.math.BigDecimal; +import java.time.LocalDate; +import java.util.Date; import java.util.List; /** @@ -18,14 +48,28 @@ import java.util.List; * @since 2022-12-02 00:41:09 */ @Service +@RequiredArgsConstructor +@Slf4j public class MerchantWithdrawServiceImpl extends ServiceImpl implements MerchantWithdrawService { - + private final UserService userService; + private final MerchantService merchantService; + private final UserBalanceLogService userBalanceLogService; + private final AlipayConfigUtil alipayConfig; @Override public PageResult pageRel(MerchantWithdrawParam param) { PageParam page = new PageParam<>(param); - page.setDefaultOrder("create_time desc"); - List list = baseMapper.selectPageRel(page, param); - return new PageResult<>(list, page.getTotal()); + QueryWrapper wrapper = page.getWrapper(); + LocalDate beginDate = param.getBeginDate(); + Integer userId = param.getUserId(); + wrapper.eq(null != userId && userId > 0, "user_id", userId) + .ge(null != beginDate, "create_time", beginDate); + LocalDate endDate = param.getEndDate(); + if(null != endDate){ + wrapper.lt("create_time", endDate); + } + wrapper.orderByDesc("create_time"); + Page list = baseMapper.selectPage(page, wrapper); + return new PageResult<>(list.getRecords(), list.getTotal()); } @Override @@ -44,4 +88,223 @@ public class MerchantWithdrawServiceImpl extends ServiceImpl 0){ + return ApiResult.fail("账户余额不足!"); + } + + Integer tenantId = user.getTenantId(); + Merchant merchant = merchantService.getOne(Wrappers.lambdaQuery() + .eq(Merchant::getMerchantOwner, userId) + .eq(Merchant::getTenantId, tenantId) + .last("limit 1")); + + Integer cardType = withdrawParam.getCardType(); + String alipayName = withdrawParam.getAlipayName(); + String alipayAccount = withdrawParam.getAlipayAccount(); + String bankName = withdrawParam.getBankName(); + String bankAccount = withdrawParam.getBankAccount(); + String bankCard = withdrawParam.getBankCard(); + + if(cardType == 20){ + if(StrUtil.isBlank(alipayName) || StrUtil.isBlank(alipayAccount)){ + return ApiResult.fail("支付宝账户不能为空!"); + } + } else if(cardType == 30) { + if(StrUtil.isBlank(bankName) || StrUtil.isBlank(bankAccount) || StrUtil.isBlank(bankCard)){ + return ApiResult.fail("银行账户不能为空!"); + } + } else { + return ApiResult.fail("提现方式不存在!"); + } + + MerchantWithdraw withdraw = MerchantWithdraw.builder() + .withdrawCode(IdUtil.getSnowflakeNextIdStr()) + .userId(userId) + .nickname(user.getNickname()) + .tenantId(tenantId) + .money(amount) + .cardType(cardType) + .alipayName(alipayName) + .alipayAccount(alipayAccount) + .bankName(bankName) + .bankAccount(bankAccount) + .bankCard(bankCard) + .sortNumber(1) + .applyStatus(10) + .status(0) + .deleted(0) + .createTime(new Date()) + .updateTime(new Date()) + .build(); + + if(null != merchant){ + withdraw.setMerchantCode(merchant.getMerchantCode()); + } + baseMapper.insert(withdraw); + + BigDecimal bBal = balance.subtract(amount); + UserBalanceLog bal = UserBalanceLog.builder() + .userId(userId) + .scene(BalanceConstants.BALANCE_WITHDRAW) + .avatar(user.getAvatar()) + .merchantCode(withdraw.getMerchantCode()) + .money(amount) + .balance(bBal) + .tenantId(tenantId) + .sortNumber(1) + .status(0) + .deleted(0) + .createTime(new Date()) + .updateTime(new Date()) + .build(); + userBalanceLogService.save(bal); + + user.setBalance(bBal); + userService.updateById(user); + return ApiResult.ok(); + } + + @Transactional + @Override + public ApiResult auditSuccess(WithdrawAuditPassParam withdrawApplyParam) { + Integer id = withdrawApplyParam.getId(); + MerchantWithdraw withdraw = baseMapper.selectById(id); + if(null == withdraw){ + return ApiResult.fail("提现申请单不存在!"); + } + int applyStatus = withdraw.getApplyStatus(); + switch (applyStatus){ + case 20: + return ApiResult.fail("提现申请单已审核通过!"); + case 30: + return ApiResult.fail("提现申请单已审核驳回!"); + case 10: + } + + Integer payType = withdrawApplyParam.getPayType(); + if(payType == 20){ + Integer cardType = withdraw.getCardType(); + if(cardType != 20){ + return ApiResult.fail("用户申请提现账号非支付宝,不能通过支付宝打款!"); + } + + ApiResult ret = transferByAlipay(withdraw); + if(!ret.isOk()){ + return ret; + } + } + + String comments = withdrawApplyParam.getComments(); + withdraw.setApplyStatus(20); + if(StrUtil.isNotBlank(comments) && StrUtil.isBlank(withdraw.getComments())){ + withdraw.setComments(comments); + } + withdraw.setUpdateTime(new Date()); + baseMapper.updateById(withdraw); + return ApiResult.ok(); + } + + /** + * 通过支付宝提现 + * @param withdraw + * @return + */ + private ApiResult transferByAlipay(MerchantWithdraw withdraw) { + Integer id = withdraw.getId(); + log.info("走支付宝渠道提现,申请单号{}。", id); + String amount = String.valueOf(withdraw.getMoney()); + + try{ + AlipayClient alipayClient = alipayConfig.alipayClient(withdraw.getTenantId()); + + AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest(); + AlipayFundTransUniTransferModel aliModel = new AlipayFundTransUniTransferModel(); + aliModel.setOutBizNo(withdraw.getWithdrawCode()); + aliModel.setRemark("安博驰"); + aliModel.setBizScene("DIRECT_TRANSFER"); + Participant payeeInfo = new Participant(); + payeeInfo.setIdentity(withdraw.getUserId() + ""); + payeeInfo.setIdentityType("ALIPAY_LOGON_ID"); + payeeInfo.setName(withdraw.getAlipayName()); + aliModel.setPayeeInfo(payeeInfo); + aliModel.setTransAmount(amount); + aliModel.setProductCode("TRANS_ACCOUNT_NO_PWD"); + aliModel.setOrderTitle("安博驰"); + request.setBizModel(aliModel); + log.info("提现单号{}提交支付宝转账参数:{}", id, JSON.toJSONString(aliModel)); + + AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request); + if(response.isSuccess()){ + log.info("支付宝转账成功!申请单号:{}", id); + return ApiResult.ok(); + } else { + log.warn("支付宝转账不成功!{}" , JSON.toJSONString(response)); + return ApiResult.fail("支付宝转账失败!" + response.getSubMsg()); + } + }catch( AlipayApiException e){ + log.error("支付宝转账出错!" + e.getMessage(), e); + return ApiResult.fail("支付宝提现出错!" + e.getMessage()); + } + } + + @Transactional + @Override + public ApiResult auditFail(WithdrawAuditFailParam failParam) { + Integer id = failParam.getId(); + MerchantWithdraw withdraw = baseMapper.selectById(id); + if(null == withdraw){ + return ApiResult.fail("提现申请单不存在!"); + } + int applyStatus = withdraw.getApplyStatus(); + switch (applyStatus){ + case 20: + return ApiResult.fail("提现申请单已审核通过!"); + case 30: + return ApiResult.fail("提现申请单已审核驳回!"); + case 10: + } + + String reason = failParam.getRejectReason(); + if(StrUtil.isBlank(reason)){ + reason = "提现审核拒绝"; + } + withdraw.setApplyStatus(30); + withdraw.setRejectReason(reason); + withdraw.setUpdateTime(new Date()); + baseMapper.updateById(withdraw); + + Integer userId = withdraw.getUserId(); + User user = userService.getById(userId); + BigDecimal balance = user.getBalance(); + BigDecimal amount = withdraw.getMoney(); + + BigDecimal bBal = balance.add(amount); + UserBalanceLog bal = UserBalanceLog.builder() + .userId(userId) + .scene(BalanceConstants.BALANCE_WITHDRAW_REJECT) + .avatar(user.getAvatar()) + .merchantCode(withdraw.getMerchantCode()) + .money(amount) + .balance(bBal) + .tenantId(withdraw.getTenantId()) + .sortNumber(1) + .comments(reason) + .status(0) + .deleted(0) + .createTime(new Date()) + .updateTime(new Date()) + .build(); + userBalanceLogService.save(bal); + user.setBalance(bBal); + userService.updateById(user); + return ApiResult.ok(); + } } diff --git a/src/main/java/com/gxwebsoft/shop/service/impl/OrderServiceImpl.java b/src/main/java/com/gxwebsoft/shop/service/impl/OrderServiceImpl.java index aaa8a44..19e5d9c 100644 --- a/src/main/java/com/gxwebsoft/shop/service/impl/OrderServiceImpl.java +++ b/src/main/java/com/gxwebsoft/shop/service/impl/OrderServiceImpl.java @@ -253,7 +253,8 @@ public class OrderServiceImpl extends ServiceImpl implements DateTime nextMonthTime = DateUtil.offsetMonth(expirationTime, 1); parentOrder.setExpirationTime(nextMonthTime); // 保存续费订单状态 - order.setDeliveryStatus(DELIVERY_STATUS_YES); +// order.setDeliveryStatus(DELIVERY_STATUS_YES); + order.setDeliveryStatus(DELIVERY_STATUS_ACCEPT); order.setReceiptStatus(RECEIPT_STATUS_YES); order.setOrderStatus(ORDER_STATUS_COMPLETED); order.setStartTime(expirationTime); @@ -270,7 +271,7 @@ public class OrderServiceImpl extends ServiceImpl implements parentOrder.setOrderStatus(ORDER_STATUS_OVER); parentOrder.setExpirationTime(DateUtil.parseTime("2099-12-31 23:59:59")); try { - freezeOrderService.unfreeze(parentOrder.getOrderId()); + freezeOrderService.unfreeze(parentOrder.getOrderId(), BigDecimal.ZERO); } catch (AlipayApiException e) { throw new RuntimeException(e); } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 9f60fa4..139ce69 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -33,5 +33,8 @@ logging: com.gxwebsoft: INFO com.baomidou.mybatisplus: INFO file: - path: E:\data\yxw\logs - name: yxw.log \ No newline at end of file + name: yxw.log + logback: + rollingpolicy: +# file-name-pattern: + max-history: 30 \ No newline at end of file diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 1d0314f..06cc66d 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -12,12 +12,16 @@ spring: # 日志配置 logging: file: - name: websoft-api.log - path: /www/wwwroot/api.yunxinwei.java/logs + name: logs/websoft-api.log level: root: INFO com.gxwebsoft: INFO com.baomidou.mybatisplus: ERROR + com.alipay.api: INFO + logback: + rollingpolicy: +# file-name-pattern: ${LOG_FILE}.%d{yyyy-MM-dd}.%i.log + max-history: 30 socketio: host: 0.0.0.0 #IP地址 @@ -37,3 +41,9 @@ config: bucketName: oss-yunxinwei bucketDomain: https://oss.wsdns.cn aliyunDomain: https://oss-yunxinwei.oss-cn-shenzhen.aliyuncs.com + +#定时表达式 +cron: + alert: 0 30 9 * * ? + profit: 0 0/2 * * * ? + timeoutOrder: 1 0 0 * * ? \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 0f057fe..e3cb391 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -8,7 +8,10 @@ socketio: spring: profiles: active: prod - + # json时间格式设置 + jackson: + time-zone: GMT+8 + date-format: yyyy-MM-dd HH:mm:ss application: name: server @@ -37,11 +40,6 @@ spring: login-username: admin login-password: admin - # json时间格式设置 - jackson: - time-zone: GMT+8 - date-format: yyyy-MM-dd HH:mm:ss - # 设置上传文件大小 servlet: multipart: From 210fa52784481169d8d55faf55d7d59356394a69 Mon Sep 17 00:00:00 2001 From: "geng.tang@qq.com" Date: Fri, 26 Jan 2024 16:52:22 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E6=8A=BC=E9=87=91=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/controller/FreezeOrderController.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/gxwebsoft/shop/controller/FreezeOrderController.java b/src/main/java/com/gxwebsoft/shop/controller/FreezeOrderController.java index 4170f9f..0c3c3c2 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/FreezeOrderController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/FreezeOrderController.java @@ -227,7 +227,8 @@ public class FreezeOrderController extends BaseController { FreezeOrder one = freezeOrderService.lambdaQuery().eq(FreezeOrder::getNotifyId, notify_id).last("limit 1").one(); if(one == null) { - FreezeOrder freezeOrder = freezeOrderService.lambdaQuery().eq(FreezeOrder::getOutRequestNo, out_request_no).one(); + FreezeOrder freezeOrder = freezeOrderService.lambdaQuery().eq(FreezeOrder::getOutRequestNo, out_request_no) + .eq(FreezeOrder::getStatus, "INIT").last("limit 1").one(); if(freezeOrder == null) { freezeOrder = new FreezeOrder(); } @@ -253,7 +254,7 @@ public class FreezeOrderController extends BaseController { .eq(FreezeOrder::getStatus, "INIT") .eq(FreezeOrder::getId, freezeOrder.getId()); boolean delRet = freezeOrderService.remove(fWrapper); - log.info("删除无效冻结订单{}条!冻结单号{}", delRet, out_order_no); + log.info("删除无效冻结订单结果{}!冻结单号{}", delRet, out_order_no); BigDecimal bAmount = freezeOrder.getAmount(); LambdaQueryWrapper orderWrapper = Wrappers.lambdaQuery(); @@ -263,11 +264,14 @@ public class FreezeOrderController extends BaseController { orderService.updateById(order); log.info("更新冻结金额!冻结单号{}", out_order_no); - LambdaUpdateWrapper orderPayWrapper = Wrappers.lambdaUpdate(); - orderPayWrapper.eq(OrderPay::getRentOrderId, order.getOrderId()) - .set(OrderPay::getBatteryRent, bAmount); - boolean bOrderRet = orderPayService.update(null, orderPayWrapper); - log.info("更新冻结支付订单结果{}!冻结单号{}", bOrderRet, out_order_no); + LambdaQueryWrapper orderPayWrapper = Wrappers.lambdaQuery(); + orderPayWrapper.eq(OrderPay::getRentOrderId, order.getOrderId()).eq(OrderPay::getPayStatus, PAY_STATUS_NO_PAY).last("limit 1"); + OrderPay orderPay = orderPayService.getOne(orderPayWrapper); + if(null != orderPay){ + orderPay.setBatteryRent(bAmount); + boolean bOrderRet = orderPayService.updateById(orderPay); + log.info("更新冻结支付订单结果{}!冻结单号{}", bOrderRet, out_order_no); + } try { writer = response.getWriter(); From 2449c3c64d4b41b6139969248dbb84d36d4a62bf Mon Sep 17 00:00:00 2001 From: "geng.tang@qq.com" Date: Fri, 26 Jan 2024 23:02:37 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E7=A7=9F=E9=87=91=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/controller/MainController.java | 3 +- .../controller/OpenEquipmentController.java | 3 +- .../controller/FreezeOrderController.java | 55 +++++++++++-------- .../shop/controller/PaymentController.java | 13 +++-- .../service/impl/FreezeOrderServiceImpl.java | 4 ++ 5 files changed, 47 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/gxwebsoft/common/system/controller/MainController.java b/src/main/java/com/gxwebsoft/common/system/controller/MainController.java index 66b4640..b69e83e 100644 --- a/src/main/java/com/gxwebsoft/common/system/controller/MainController.java +++ b/src/main/java/com/gxwebsoft/common/system/controller/MainController.java @@ -217,7 +217,8 @@ public class MainController extends BaseController { // User user = getLoginUser(); // param.setTenantId(user.getTenantId()); - String code = RandomStringUtils.randomNumeric(6); + int iCode = new Random().nextInt(999999) + 1000000; + String code = String.valueOf(iCode).substring(1); param.setTemplateParam("{\"code\":" + code + "}"); ApiResult ret = aliSmsService.sendSms(param); if(ret.isOk()){ diff --git a/src/main/java/com/gxwebsoft/open/controller/OpenEquipmentController.java b/src/main/java/com/gxwebsoft/open/controller/OpenEquipmentController.java index e4bcff4..b5cbae2 100644 --- a/src/main/java/com/gxwebsoft/open/controller/OpenEquipmentController.java +++ b/src/main/java/com/gxwebsoft/open/controller/OpenEquipmentController.java @@ -482,7 +482,7 @@ public class OpenEquipmentController extends BaseController { if (auditStatus != 30) { return fail("申请成功,请等待客服人员审核"); } - }else { + } else { refund = new OrderRefund(); refund.setOrderId(order.getOrderId()); refund.setOrderNo(order.getOrderNo()); @@ -494,6 +494,7 @@ public class OpenEquipmentController extends BaseController { refund.setMerchantCode(order.getMerchantCode()); } refund.setAuditStatus(10); + refund.setOrderNo(order.getOrderNo()); orderRefundService.saveOrUpdate(refund); // 更新订单状态 Order updateOrder = new Order(); diff --git a/src/main/java/com/gxwebsoft/shop/controller/FreezeOrderController.java b/src/main/java/com/gxwebsoft/shop/controller/FreezeOrderController.java index 0c3c3c2..8e59031 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/FreezeOrderController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/FreezeOrderController.java @@ -256,41 +256,50 @@ public class FreezeOrderController extends BaseController { boolean delRet = freezeOrderService.remove(fWrapper); log.info("删除无效冻结订单结果{}!冻结单号{}", delRet, out_order_no); - BigDecimal bAmount = freezeOrder.getAmount(); LambdaQueryWrapper orderWrapper = Wrappers.lambdaQuery(); orderWrapper.eq(Order::getFreezeOrderNo, out_order_no).last("limit 1"); Order order = orderService.getOne(orderWrapper); - order.setBatteryRent(bAmount); - orderService.updateById(order); - log.info("更新冻结金额!冻结单号{}", out_order_no); + if(null == order){ + log.error("冻结订单{}对应的产品订单不存在!", out_order_no); + } else { + BigDecimal rent = order.getBatteryRent(); + BigDecimal totalPrice = order.getTotalPrice(); + if(rent == null || !rent.equals(totalPrice)){ + order.setBatteryRent(totalPrice); + orderService.updateById(order); + log.info("更新冻结金额!冻结单号{}", out_order_no); + } - LambdaQueryWrapper orderPayWrapper = Wrappers.lambdaQuery(); - orderPayWrapper.eq(OrderPay::getRentOrderId, order.getOrderId()).eq(OrderPay::getPayStatus, PAY_STATUS_NO_PAY).last("limit 1"); - OrderPay orderPay = orderPayService.getOne(orderPayWrapper); - if(null != orderPay){ - orderPay.setBatteryRent(bAmount); - boolean bOrderRet = orderPayService.updateById(orderPay); - log.info("更新冻结支付订单结果{}!冻结单号{}", bOrderRet, out_order_no); - } + LambdaQueryWrapper orderPayWrapper = Wrappers.lambdaQuery(); + orderPayWrapper.eq(OrderPay::getRentOrderId, order.getOrderId()).eq(OrderPay::getPayStatus, PAY_STATUS_NO_PAY).last("limit 1"); + OrderPay orderPay = orderPayService.getOne(orderPayWrapper); + if(null != orderPay){ + BigDecimal bRent = order.getBatteryRent(); + if(bRent == null || !bRent.equals(totalPrice)){ + orderPay.setBatteryRent(totalPrice); + boolean bOrderRet = orderPayService.updateById(orderPay); + log.info("更新冻结支付订单结果{}!冻结单号{}", bOrderRet, out_order_no); + } + } - try { - writer = response.getWriter(); - writer.write("success"); //一定要打印success - writer.flush(); - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - if (writer != null) { - writer.close(); + try { + writer = response.getWriter(); + writer.write("success"); //一定要打印success + writer.flush(); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + if (writer != null) { + writer.close(); + } } } + // return "success"; } else { log.warn("解冻消息{}已处理!", notify_id); } - - // return "fail"; } diff --git a/src/main/java/com/gxwebsoft/shop/controller/PaymentController.java b/src/main/java/com/gxwebsoft/shop/controller/PaymentController.java index 22a28f5..c20bac2 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/PaymentController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/PaymentController.java @@ -351,17 +351,17 @@ public class PaymentController extends BaseController { // 1. 验证appId是否一致 final String app_id = params.get("app_id"); if (!config.getString("alipayAppId").equals(app_id)) { - System.out.println("支付宝appId不一致 = " + app_id); + log.warn("支付宝appId不一致 = " + app_id); throw new BusinessException("支付宝appId不一致"); } // 2. 订单金额 if (!payPrice.equals(receipt_amount)) { - System.out.println("订单金额是不一致 = " + receipt_amount); + log.warn("订单金额是不一致 = " + receipt_amount); throw new BusinessException("订单金额是不一致"); } // 3. 判断交易状态 if (!"TRADE_SUCCESS".equals(tradeStatus)) { - System.out.println("支付失败 = " + tradeStatus); + log.warn("支付失败 = " + tradeStatus); throw new BusinessException("支付失败"); } // 4. 修改支付状态 @@ -375,7 +375,8 @@ public class PaymentController extends BaseController { Order parentOrder = orderService.getById(order.getRentOrderId()); parentOrder.setCurrPeriods(parentOrder.getCurrPeriods() + 1); - order.setCurrPeriods(parentOrder.getCurrPeriods() + 1); + order.setCurrPeriods(parentOrder.getCurrPeriods()); + order.setBatteryRent(parentOrder.getBatteryRent()); parentOrder.setPayStatus(PAY_STATUS_SUCCESS); // 更新过期时间延长一个月 @@ -397,7 +398,6 @@ public class PaymentController extends BaseController { parentOrder.setExpirationTime(order.getExpirationTime()); } - orderPayService.updateById(order); orderService.updateById(parentOrder); return "success"; @@ -461,7 +461,8 @@ public class PaymentController extends BaseController { Order parentOrder = orderService.getById(order.getRentOrderId()); parentOrder.setCurrPeriods(parentOrder.getCurrPeriods() + 1); - order.setCurrPeriods(parentOrder.getCurrPeriods() + 1); + order.setCurrPeriods(parentOrder.getCurrPeriods()); + order.setBatteryRent(parentOrder.getBatteryRent()); parentOrder.setPayStatus(PAY_STATUS_SUCCESS); // 更新过期时间延长一个月 diff --git a/src/main/java/com/gxwebsoft/shop/service/impl/FreezeOrderServiceImpl.java b/src/main/java/com/gxwebsoft/shop/service/impl/FreezeOrderServiceImpl.java index 3efc88d..212691b 100644 --- a/src/main/java/com/gxwebsoft/shop/service/impl/FreezeOrderServiceImpl.java +++ b/src/main/java/com/gxwebsoft/shop/service/impl/FreezeOrderServiceImpl.java @@ -12,6 +12,7 @@ import com.alipay.api.response.*; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gxwebsoft.apps.entity.EquipmentGoods; import com.gxwebsoft.apps.service.EquipmentGoodsService; +import com.gxwebsoft.common.core.exception.BusinessException; import com.gxwebsoft.common.core.utils.AlipayConfigUtil; import com.gxwebsoft.shop.entity.Order; import com.gxwebsoft.shop.mapper.FreezeOrderMapper; @@ -85,6 +86,9 @@ public class FreezeOrderServiceImpl extends ServiceImpl Date: Sat, 27 Jan 2024 12:49:01 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=BA=AB=E4=BB=BD?= =?UTF-8?q?=E8=AF=81=E4=BF=A1=E6=81=AF=EF=BC=8C=E5=90=8C=E6=AD=A5=E5=88=B0?= =?UTF-8?q?dev=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../open/controller/OpenEquipmentController.java | 4 ++++ src/main/java/com/gxwebsoft/shop/entity/Order.java | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/main/java/com/gxwebsoft/open/controller/OpenEquipmentController.java b/src/main/java/com/gxwebsoft/open/controller/OpenEquipmentController.java index b5cbae2..f4e458b 100644 --- a/src/main/java/com/gxwebsoft/open/controller/OpenEquipmentController.java +++ b/src/main/java/com/gxwebsoft/open/controller/OpenEquipmentController.java @@ -412,6 +412,10 @@ public class OpenEquipmentController extends BaseController { if(verify.getIssueDate() == null || verify.getIssueOrg() == null || verify.getExpireDate() == null) { return fail("请上传身份证反面照片"); } + order.setRealName(verify.getName()); + order.setIdCode(verify.getIdCardNo()); + order.setAddress(verify.getAddress()); + } // 短信验证码校验 diff --git a/src/main/java/com/gxwebsoft/shop/entity/Order.java b/src/main/java/com/gxwebsoft/shop/entity/Order.java index 2af38c4..f1f99c6 100644 --- a/src/main/java/com/gxwebsoft/shop/entity/Order.java +++ b/src/main/java/com/gxwebsoft/shop/entity/Order.java @@ -247,6 +247,15 @@ public class Order implements Serializable { @ApiModelProperty(value = "修改时间") private Date updateTime; + @ApiModelProperty(value = "姓名") + private String realName; + + @ApiModelProperty(value = "身份证号") + private String idCode; + + @ApiModelProperty(value = "详细地址") + private String address; + @ApiModelProperty("账号") @TableField(exist = false) private String username;