From ba714629588e22f9ffaab83819f6b9200a6397b3 Mon Sep 17 00:00:00 2001 From: zhanglin8526 <852614290@qq.com> Date: 星期五, 04 八月 2023 22:59:08 +0800 Subject: [PATCH] 1、定时任务 商户进件状态查询 2、小程序下单统一支付提交 3、订单核销分账(未完成) --- ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/shop/ShopAuthenticationService.java | 22 ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/config/MyWxPayConfig.java | 7 ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/account/OrderPaymentServiceImpl.java | 35 + ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/AppOrderController.java | 63 +- ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/account/PaymentMessageServiceImpl.java | 13 ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/impl/shop/ShopProportionServiceImpl.java | 12 ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/poji/shop/ShopProportionVo.java | 4 ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/utils/SecurityUtils.java | 11 ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/controller/console/ShopController.java | 34 + ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/enums/WxApplyMentSignStateEnum.java | 20 ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/service/RemoteShopService.java | 13 ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/shop/ShopProportionService.java | 7 ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/shop/ShopService.java | 5 ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/account/OrderPaymentService.java | 23 + ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/account/PaymentMessageService.java | 8 ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/scheduler/ShopScheduler.java | 20 ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/vo/AppPlaceOrderVo.java | 2 ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/enums/WxApplyMentStateEnum.java | 30 + ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/impl/shop/ShopServiceImpl.java | 521 ++++++++++++---------- ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteShopFallbackFactory.java | 11 ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java | 206 ++++++-- ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/impl/shop/ShopAuthenticationServiceImpl.java | 81 +++ ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/util/WechatPayUtils.java | 11 ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/dto/AppBaseDto.java | 7 ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/enums/dict/IDict.java | 170 +++++++ ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/enums/dict/DictBean.java | 15 26 files changed, 1,018 insertions(+), 333 deletions(-) diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/dto/AppBaseDto.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/dto/AppBaseDto.java index 5dd92fc..90d616f 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/dto/AppBaseDto.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/dto/AppBaseDto.java @@ -13,7 +13,12 @@ @Data public class AppBaseDto { - @ApiModelProperty(value = "userId",hidden = true) + @ApiModelProperty(value = "userId", hidden = true) private Long userId; + @ApiModelProperty(value = "openid", hidden = true) + private String openid; + + @ApiModelProperty(value = "终端IP", hidden = true) + private String spbillCreateIp; } diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/poji/shop/ShopProportionVo.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/poji/shop/ShopProportionVo.java new file mode 100644 index 0000000..fc3d659 --- /dev/null +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/poji/shop/ShopProportionVo.java @@ -0,0 +1,4 @@ +package com.ruoyi.system.api.domain.poji.shop; + +public class ShopProportionVo { +} diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteShopFallbackFactory.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteShopFallbackFactory.java index 5e23e44..14b6f8e 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteShopFallbackFactory.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteShopFallbackFactory.java @@ -2,6 +2,7 @@ import com.ruoyi.common.core.domain.R; import com.ruoyi.system.api.domain.dto.*; +import com.ruoyi.system.api.domain.poji.shop.ShopProportionVo; import com.ruoyi.system.api.domain.vo.*; import com.ruoyi.system.api.model.QwH5LoginVo; import com.ruoyi.system.api.model.QwUserDetailDto; @@ -33,6 +34,11 @@ @Override public R<Shop> getShop(Long shopId) { return R.fail("获取商户失败:" + throwable.getMessage()); + } + + @Override + public R<String> getShopSubMchId(Long shopId) { + return R.fail("获取微信商户号失败:" + throwable.getMessage()); } @Override @@ -109,6 +115,11 @@ public R editMgtShopStaff(MgtShopStaffEditDto mgtShopStaffEditDto) { return R.fail("修改员工失败:" + throwable.getMessage()); } + + @Override + public R<ShopProportionVo> getShopProportion(Long shopId) { + return R.fail("获取商户分成信息失败:" + throwable.getMessage()); + } }; } } diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/service/RemoteShopService.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/service/RemoteShopService.java index 9891828..f849c0f 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/service/RemoteShopService.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/service/RemoteShopService.java @@ -4,6 +4,7 @@ import com.ruoyi.common.core.domain.R; import com.ruoyi.system.api.domain.dto.*; import com.ruoyi.system.api.domain.poji.shop.Shop; +import com.ruoyi.system.api.domain.poji.shop.ShopProportionVo; import com.ruoyi.system.api.domain.vo.*; import com.ruoyi.system.api.factory.RemoteShopFallbackFactory; import com.ruoyi.system.api.model.QwH5LoginVo; @@ -19,6 +20,10 @@ @PostMapping("/shop/getShop") public R<Shop> getShop(@RequestBody Long shopId); + + @PostMapping("/shop/getShopSubMchId") + public R<String> getShopSubMchId(@RequestBody Long shopId); + @PostMapping("/shop/getShopByUserId") public R<ShopRelUserVo> getShopByUserId(@RequestBody Long userId); @@ -149,4 +154,12 @@ */ @PostMapping("/shop/editMgtShopStaff") public R editMgtShopStaff(@RequestBody MgtShopStaffEditDto mgtShopStaffEditDto); + + /** + * 获取商户分成 + * @param shopId + * @return + */ + @PostMapping("/shop/getShopProportion") + R<ShopProportionVo> getShopProportion(@RequestBody Long shopId); } diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/utils/SecurityUtils.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/utils/SecurityUtils.java index 8171709..589eb06 100644 --- a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/utils/SecurityUtils.java +++ b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/utils/SecurityUtils.java @@ -1,6 +1,8 @@ package com.ruoyi.common.security.utils; import javax.servlet.http.HttpServletRequest; + +import com.ruoyi.system.api.domain.poji.sys.SysUser; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.common.core.constant.TokenConstants; @@ -11,7 +13,7 @@ /** * 权限获取工具类 - * + * * @author jqs */ public class SecurityUtils @@ -48,6 +50,11 @@ return SecurityContextHolder.get(SecurityConstants.LOGIN_USER, LoginUser.class); } + public static SysUser getSysUser() + { + return getLoginUser().getSysUser(); + } + /** * 获取请求token */ @@ -81,7 +88,7 @@ /** * 是否为管理员 - * + * * @param userId 用户ID * @return 结果 */ diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/config/MyWxPayConfig.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/config/MyWxPayConfig.java index 1dc0d70..00e56cc 100644 --- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/config/MyWxPayConfig.java +++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/config/MyWxPayConfig.java @@ -33,6 +33,13 @@ private static final String API_V3_KEY = ""; + // 分账特约商户 + private static final String PLATFORM_TY_MAC_ID = ""; + + public static String getPlatformTyMacId() { + return PLATFORM_TY_MAC_ID; + } + @Bean @ConditionalOnMissingBean public WxPayService wxService() { diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/AppOrderController.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/AppOrderController.java index ff9ee11..0af1e43 100644 --- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/AppOrderController.java +++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/AppOrderController.java @@ -15,6 +15,7 @@ import com.ruoyi.system.api.domain.dto.AppBaseGetDto; import com.ruoyi.system.api.domain.dto.AppMemberBindingDto; import com.ruoyi.system.api.domain.poji.member.Member; +import com.ruoyi.system.api.model.LoginUser; import com.ruoyi.system.api.service.RemoteConfigService; import com.ruoyi.system.api.service.RemoteMemberService; import io.swagger.annotations.Api; @@ -57,10 +58,10 @@ @ApiOperation(value = "购买商品") public R<AppSureOrderVo> buyGoods(@RequestBody AppSureOrderDto appSureOrderDto) { Long userId = SecurityUtils.getUserId(); - if(userId!=null){ + if (userId != null) { Member member = memberService.getMember(userId).getData(); appSureOrderDto.setUserId(userId); - if(member!=null&&member.getRelationShopId()!=null){ + if (member != null && member.getRelationShopId() != null) { appSureOrderDto.setShopId(member.getRelationShopId()); } } @@ -73,10 +74,10 @@ @ApiOperation(value = "抢购商品") public R<AppPanicBuyVo> panicBuyGoods(@RequestBody AppPanicBuyDto appPanicBuyDto) { Long userId = SecurityUtils.getUserId(); - if(userId!=null){ + if (userId != null) { Member member = memberService.getMember(userId).getData(); appPanicBuyDto.setUserId(userId); - if(member!=null&&member.getRelationShopId()!=null){ + if (member != null && member.getRelationShopId() != null) { appPanicBuyDto.setShopId(member.getRelationShopId()); } } @@ -87,20 +88,26 @@ @RequestMapping(value = "/placeOrder", method = RequestMethod.POST) @ApiOperation(value = "创建订单") public R<AppPlaceOrderVo> placeOrder(@RequestBody AppPlaceOrderDto appPlaceOrderDto) { - Long userId = SecurityUtils.getUserId(); - if(userId!=null){ + LoginUser loginUser = SecurityUtils.getLoginUser(); + Long userId = loginUser.getUserid(); + appPlaceOrderDto.setUserId(userId); + appPlaceOrderDto.setSpbillCreateIp(loginUser.getIpaddr()); + + if (userId != null) { Member member = memberService.getMember(userId).getData(); appPlaceOrderDto.setUserId(userId); - if(member!=null&&member.getRelationShopId()!=null){ + + if (member != null) { + appPlaceOrderDto.setOpenid(member.getMiniOpenid()); appPlaceOrderDto.setShopId(member.getRelationShopId()); - } - if(member.getBindingFlag()!=1){ - //绑定商户 - AppMemberBindingDto appMemberBindingDto = new AppMemberBindingDto(); - appMemberBindingDto.setShopId(appPlaceOrderDto.getShopId()); - appMemberBindingDto.setUserId(userId); - appMemberBindingDto.setBindingFlag(1); - memberService.updateMemberBinding(appMemberBindingDto); + if (member.getBindingFlag() != 1) { + //绑定商户 + AppMemberBindingDto appMemberBindingDto = new AppMemberBindingDto(); + appMemberBindingDto.setShopId(appPlaceOrderDto.getShopId()); + appMemberBindingDto.setUserId(userId); + appMemberBindingDto.setBindingFlag(1); + memberService.updateMemberBinding(appMemberBindingDto); + } } } AppPlaceOrderVo appPlaceOrderVo = orderService.placeOrder(appPlaceOrderDto); @@ -111,13 +118,13 @@ @ApiOperation(value = "创建活动订单") public R<AppPlaceOrderVo> placeActivityOrder(@Validated @RequestBody AppPlaceActivityDto appPlaceActivityDto) { Long userId = SecurityUtils.getUserId(); - if(userId!=null){ + if (userId != null) { Member member = memberService.getMember(userId).getData(); appPlaceActivityDto.setUserId(userId); - if(member!=null&&member.getRelationShopId()!=null){ + if (member != null && member.getRelationShopId() != null) { appPlaceActivityDto.setShopId(member.getRelationShopId()); } - if(member.getBindingFlag()!=1){ + if (member.getBindingFlag() != 1) { //绑定商户 AppMemberBindingDto appMemberBindingDto = new AppMemberBindingDto(); appMemberBindingDto.setShopId(appPlaceActivityDto.getShopId()); @@ -134,18 +141,18 @@ @ApiOperation(value = "分页获取用户订单") public R<Page<AppUserOrderPageVo>> pageUserOrder(@RequestBody AppUserOrderPageDto appUserOrderPageDto) { Long userId = SecurityUtils.getUserId(); - if(userId!=null){ + if (userId != null) { Member member = memberService.getMember(userId).getData(); appUserOrderPageDto.setUserId(userId); - if(member!=null&&member.getRelationShopId()!=null){ + if (member != null && member.getRelationShopId() != null) { appUserOrderPageDto.setShopId(member.getRelationShopId()); } } - logger.info("appUserOrderPageDto:"+appUserOrderPageDto.toString()); + logger.info("appUserOrderPageDto:" + appUserOrderPageDto.toString()); Page<AppUserOrderPageVo> page = new Page<>(); page.setSize(appUserOrderPageDto.getPageSize()); page.setCurrent(appUserOrderPageDto.getPageNum()); - List<AppUserOrderPageVo> appUserOrderPageVoList = orderService.pageUserOrder(page,appUserOrderPageDto); + List<AppUserOrderPageVo> appUserOrderPageVoList = orderService.pageUserOrder(page, appUserOrderPageDto); return R.ok(page.setRecords(appUserOrderPageVoList)); } @@ -154,17 +161,17 @@ public R<AppUserOrderGetVo> getAppOrderDetail(@RequestBody AppBaseGetDto appBaseGetDto) { Long userId = SecurityUtils.getUserId(); Long shopId = null; - if(userId!=null){ + if (userId != null) { Member member = memberService.getMember(userId).getData(); appBaseGetDto.setUserId(userId); - if(member!=null&&member.getRelationShopId()!=null){ + if (member != null && member.getRelationShopId() != null) { shopId = member.getRelationShopId(); } } AppUserOrderGetVo appUserOrderGetVo = orderService.getAppOrderDetail(appBaseGetDto); - if(shopId!=null&&appUserOrderGetVo.getShopId().equals(shopId)){ + if (shopId != null && appUserOrderGetVo.getShopId().equals(shopId)) { appUserOrderGetVo.setSameShop(1); - }else{ + } else { appUserOrderGetVo.setSameShop(0); } return R.ok(appUserOrderGetVo); @@ -184,12 +191,12 @@ appPlaceOrderVo.setPayMoney(order.getPayMoney()); appPlaceOrderVo.setUnpaidMoney(order.getPayMoney()); Integer delayTime = 30; - if(redisService.hasKey(SecurityConstant.AUTO_CANCEL_ORDER_TIME)){ + if (redisService.hasKey(SecurityConstant.AUTO_CANCEL_ORDER_TIME)) { delayTime = redisService.getCacheObject(SecurityConstant.AUTO_CANCEL_ORDER_TIME); } redisService.deleteObject(DelayTaskEnum.ORDER_AUTOMATIC_CANCEL.getCode() + "-" + order.getOrderId()); remoteConfigService.deleteDelayTask(DelayTaskEnum.ORDER_AUTOMATIC_CANCEL.getCode() + "-" + order.getOrderId()); - appPlaceOrderVo.setEndTime(DateUtils.addMinutes(order.getCreateTime(),delayTime)); + appPlaceOrderVo.setEndTime(DateUtils.addMinutes(order.getCreateTime(), delayTime)); return R.ok(appPlaceOrderVo); } diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/vo/AppPlaceOrderVo.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/vo/AppPlaceOrderVo.java index 3d53905..caa8138 100644 --- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/vo/AppPlaceOrderVo.java +++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/domain/vo/AppPlaceOrderVo.java @@ -54,7 +54,7 @@ private String packageStr; @ApiModelProperty(value = "签名方式") - private String tradeType; + private String signType; @ApiModelProperty(value = "签名") private String paySign; diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/account/OrderPaymentService.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/account/OrderPaymentService.java index b6065d2..7a74366 100644 --- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/account/OrderPaymentService.java +++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/account/OrderPaymentService.java @@ -3,6 +3,9 @@ import com.ruoyi.order.domain.pojo.account.OrderPayment; import com.baomidou.mybatisplus.extension.service.IService; +import java.math.BigDecimal; +import java.util.Date; + /** * <p> * 订单支付 服务类 @@ -13,4 +16,24 @@ */ public interface OrderPaymentService extends IService<OrderPayment> { + /** + * 保存支付记录 + * @param userId + * @param shopId + * @param orderId + * @param payMoney + * @param endTime + * @param profitSharing + * @param openid + * @param goodsNames + * @param prepayId + */ + void saveOrderPayment(Long userId, Long shopId, String orderId, BigDecimal payMoney, Date endTime, String profitSharing, String openid, String goodsNames, String prepayId); + + /** + * + * @param orderId + * @return + */ + OrderPayment getByOrderId(String orderId); } diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/account/PaymentMessageService.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/account/PaymentMessageService.java index 15c1bc9..41a7898 100644 --- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/account/PaymentMessageService.java +++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/account/PaymentMessageService.java @@ -13,4 +13,12 @@ */ public interface PaymentMessageService extends IService<PaymentMessage> { + /** + * 保存请求信息 + * @param sendType + * @param sendId + * @param sendMessage + * @param resultMessage + */ + void savePaymentMessage(String sendType, Long sendId, String sendMessage, String resultMessage); } diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/account/OrderPaymentServiceImpl.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/account/OrderPaymentServiceImpl.java index a9b6c40..66b6acd 100644 --- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/account/OrderPaymentServiceImpl.java +++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/account/OrderPaymentServiceImpl.java @@ -1,10 +1,16 @@ package com.ruoyi.order.service.impl.account; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ruoyi.common.core.utils.uuid.IdUtils; import com.ruoyi.order.domain.pojo.account.OrderPayment; import com.ruoyi.order.mapper.account.OrderPaymentMapper; import com.ruoyi.order.service.account.OrderPaymentService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.Date; /** * <p> @@ -17,4 +23,33 @@ @Service public class OrderPaymentServiceImpl extends ServiceImpl<OrderPaymentMapper, OrderPayment> implements OrderPaymentService { + @Override + public void saveOrderPayment(Long userId, Long shopId, String orderId, BigDecimal payMoney, Date endTime, + String profitSharing, String openid, String goodsNames, String prepayId) { + OrderPayment payment = new OrderPayment(); + payment.setPaymentId(IdUtils.simpleUUID()); + payment.setUserId(userId); + payment.setShopId(shopId); + payment.setOrderId(orderId); + payment.setPayMoney(payMoney); + payment.setTimeExpire(endTime); + // 0 否 1、是 + payment.setProfitSharing("Y".equals(profitSharing) ? 1 : 0); + payment.setUserOpenId(openid); + payment.setGoodsNames(goodsNames); + payment.setPrepayId(prepayId); + payment.setCreateTime(new Date()); + payment.setDelFlag(0); + this.saveOrUpdate(payment); + } + + @Override + public OrderPayment getByOrderId(String orderId) { + LambdaQueryWrapper<OrderPayment> queryWrapper = Wrappers.lambdaQuery(); + queryWrapper.eq(OrderPayment::getOrderId, orderId) + .eq(OrderPayment::getDelFlag, 0) + .eq(OrderPayment::getPayStatus, 2) + .last(" limit 1 "); + return this.getOne(queryWrapper); + } } diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/account/PaymentMessageServiceImpl.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/account/PaymentMessageServiceImpl.java index ef686da..93b5287 100644 --- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/account/PaymentMessageServiceImpl.java +++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/account/PaymentMessageServiceImpl.java @@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; +import java.util.Date; + /** * <p> * 支付报文 服务实现类 @@ -17,4 +19,15 @@ @Service public class PaymentMessageServiceImpl extends ServiceImpl<PaymentMessageMapper, PaymentMessage> implements PaymentMessageService { + @Override + public void savePaymentMessage(String sendType, Long sendId, String sendMessage, String resultMessage) { + PaymentMessage paymentMessage = new PaymentMessage(); + paymentMessage.setDelFlag("0"); + paymentMessage.setSendType(sendType); + paymentMessage.setSendId(sendId); + paymentMessage.setSendMessage(sendMessage); + paymentMessage.setResultMessage(resultMessage); + paymentMessage.setCreateTime(new Date()); + this.saveOrUpdate(paymentMessage); + } } diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java index f22e1a5..6303951 100644 --- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java +++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/order/OrderServiceImpl.java @@ -5,6 +5,17 @@ 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.github.binarywang.wxpay.bean.order.WxPayMpOrderResult; +import com.github.binarywang.wxpay.bean.profitsharingV3.ProfitSharingReceiver; +import com.github.binarywang.wxpay.bean.profitsharingV3.ProfitSharingRequest; +import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; +import com.github.binarywang.wxpay.config.WxPayConfig; +import com.github.binarywang.wxpay.constant.WxPayConstants; +import com.github.binarywang.wxpay.exception.WxPayException; +import com.github.binarywang.wxpay.service.WxPayService; +import com.google.common.base.Joiner; +import com.google.gson.Gson; +import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.common.core.utils.DateUtils; import com.ruoyi.common.core.utils.StringUtils; @@ -12,6 +23,7 @@ import com.ruoyi.common.redis.service.RedisService; import com.ruoyi.common.security.utils.CodeFactoryUtil; import com.ruoyi.common.security.utils.SecurityUtils; +import com.ruoyi.order.config.MyWxPayConfig; import com.ruoyi.order.domain.dto.*; import com.ruoyi.order.domain.pojo.account.OrderPayment; import com.ruoyi.order.domain.pojo.account.OrderRefund; @@ -21,6 +33,8 @@ import com.ruoyi.order.domain.pojo.order.PayRecord; import com.ruoyi.order.domain.vo.*; import com.ruoyi.order.mapper.order.OrderMapper; +import com.ruoyi.order.service.account.OrderPaymentService; +import com.ruoyi.order.service.account.PaymentMessageService; import com.ruoyi.order.service.order.*; import com.ruoyi.system.api.constant.AppErrorConstant; import com.ruoyi.system.api.constant.DelayTaskEnum; @@ -35,6 +49,7 @@ import com.ruoyi.system.api.domain.poji.member.MemberCoupon; import com.ruoyi.system.api.domain.poji.member.MemberGiftRecord; import com.ruoyi.system.api.domain.poji.shop.Shop; +import com.ruoyi.system.api.domain.poji.shop.ShopProportionVo; import com.ruoyi.system.api.domain.poji.sys.SysUser; import com.ruoyi.system.api.domain.vo.*; import com.ruoyi.system.api.service.*; @@ -110,24 +125,16 @@ @Autowired private RedissonClient redissonClient; - /** 商户号 */ - public static String merchantId = ""; - /** 商户API私钥路径 */ - public static String privateKeyPath = ""; - /** 商户证书序列号 */ - public static String merchantSerialNumber = ""; - /** 微信支付平台证书路径 */ - public static String wechatPayCertificatePath = ""; - /** 微信支付 APIv3 密钥 */ - public static String apiV3Key = ""; - /** 微信支付APPID */ - public static String appId=""; - /** 微信支付商户ID */ - public static String mchId=""; - /** 通知地址 */ - public static String notifyUrl=""; + @Autowired + private WxPayService wxService; - /** + @Resource + private PaymentMessageService paymentMessageService; + + @Resource + private OrderPaymentService orderPaymentService; + + /** * @description: buyGoods * @param: appSureOrderDto * @return: AppSureOrderVo @@ -510,7 +517,7 @@ Integer serviceNum; Integer goodsNum = 0; String memberCouponId; - Goods goods; + Goods goods = null; GoodsFile goodsFile; BigDecimal goodsPrice; BigDecimal goodsTotalPrice; @@ -542,6 +549,7 @@ HashSet<String> goodsTypeSet = new HashSet<>(); //使用优惠券 StringJoiner memberCouponSJ = new StringJoiner(","); + List<String> goodsNameList = new ArrayList<>(); // 遍历购买的商品列表 for (AppBuyGoodsDto appBuyGoodsDto : appBuyGoodsDtoList) { appSureOrderGoodsVo = new AppSureOrderGoodsVo(); @@ -551,6 +559,7 @@ memberCouponId = appBuyGoodsDto.getMemberCouponId(); // 获取商品信息 goods = goodsMap.get(goodsId); + goodsNameList.add(goods.getGoodsName()); // 设置商品信息 appSureOrderGoodsVo.setGoodsId(goodsId); appSureOrderGoodsVo.setGoodsName(goods.getGoodsName()); @@ -713,53 +722,90 @@ } appPlaceOrderVo.setOrderId(orderId); appPlaceOrderVo.setOrderNo(orderNo); - // 调用支付 - /* CombineTransactionsJsRequest request=new CombineTransactionsJsRequest(); - request.setCombineAppid(); - request.setCombineMchid(); - profitsSharingService.combineTransactions(request);*/ - //构建预下单支付对象 - /*PrepayRequest request = new PrepayRequest(); - Amount amount = new Amount(); - amount.setTotal(Integer.parseInt(order.getPayMoney().multiply(new BigDecimal(100)).toString())); - request.setAmount(amount); - request.setAppid(this.appId); - request.setMchid(this.mchId); - request.setDescription(order.getGoodsInfo()); - request.setNotifyUrl(this.notifyUrl); - request.setOutTradeNo(order.getOrderId()); - Payer payer = new Payer(); - payer.setOpenid("oLTPCuN5a-nBD4rAL_fa********"); - request.setPayer(payer);*/ - //返回前端唤醒支付结果信息 - /*PrepayWithRequestPaymentResponse res = this.getJsApIResponse(request); - appPlaceOrderVo.setAppId(this.appId); - appPlaceOrderVo.setTimeStamp(res.getTimeStamp()); - appPlaceOrderVo.setNonceStr(res.getNonceStr()); - appPlaceOrderVo.setPackageStr(res.getPackageVal()); - appPlaceOrderVo.setTradeType(res.getSignType()); - appPlaceOrderVo.setPaySign(res.getPaySign());*/ + try { + // 创建支付订单 + Long shopId = appPlaceOrderDto.getShopId(); + R<String> resultMch = remoteShopService.getShopSubMchId(shopId); + String subMchId = resultMch.getData(); + if(StringUtils.isEmpty(subMchId)){ + throw new ServiceException("获取微信商户号失败"); + } + + WxPayConfig config = wxService.getConfig(); + config.setSubMchId(subMchId); + + WxPayUnifiedOrderRequest request = new WxPayUnifiedOrderRequest(); + request.setTradeType(WxPayConstants.TradeType.JSAPI); + request.setSubMchId(subMchId); + // 商户订单号 + request.setOutTradeNo(orderNo); + // 订单总金额 + Integer totalFee = order.getPayMoney().multiply(new BigDecimal(100)).intValue(); + request.setTotalFee(totalFee); + request.setProductId(orderNo); + request.setNotifyUrl(config.getNotifyUrl()); + request.setProfitSharing("Y"); + request.setOpenid(appPlaceOrderDto.getOpenid()); + request.setSpbillCreateIp(appPlaceOrderDto.getSpbillCreateIp()); + // 商品描述 body + String body = "商品购买"; + if(null != goods){ + body = goods.getGoodsName() + "-" + body; + } + request.setBody(body); + + request.checkAndSign(config); + + // 请求参数 + Gson gson = new Gson(); + String payRequestJson = gson.toJson(request); + + WxPayMpOrderResult result = wxService.createOrder(request); + + String payResponseJson = gson.toJson(request); + + // 支付相关信息返回 + appPlaceOrderVo.setAppId(result.getAppId()); + appPlaceOrderVo.setMchId(config.getMchId()); + appPlaceOrderVo.setTimeStamp(result.getTimeStamp()); + appPlaceOrderVo.setNonceStr(result.getNonceStr()); + appPlaceOrderVo.setPackageStr(result.getPackageValue()); + appPlaceOrderVo.setSignType(result.getSignType()); + appPlaceOrderVo.setPaySign(result.getPaySign()); + appPlaceOrderVo.setPrepayId(result.getPackageValue()); + + //减去优惠券 + if(StringUtils.isNotBlank(memberCouponSJ.toString())){ + remoteCouponService.useMemberCoupon(memberCouponSJ.toString()); + } + //生成自动取消订单延时任务 + Integer delayTime = 30; + if(redisService.hasKey(SecurityConstant.AUTO_CANCEL_ORDER_TIME)){ + delayTime = redisService.getCacheObject(SecurityConstant.AUTO_CANCEL_ORDER_TIME); + } + redisService.setCacheObject(DelayTaskEnum.ORDER_AUTOMATIC_CANCEL.getCode() + "-" + orderId, orderId, delayTime.longValue(), TimeUnit.MINUTES); + DelayTask delayTask = new DelayTask(); + delayTask.setDelFlag(0); + delayTask.setCreateTime(new Date()); + delayTask.setEndTime(DateUtils.addMinutes(new Date(),delayTime)); + delayTask.setRedisKey(DelayTaskEnum.ORDER_AUTOMATIC_CANCEL.getCode() + "-" + orderId); + remoteConfigService.addDelayTask(delayTask); + appPlaceOrderVo.setEndTime(DateUtils.addMinutes(order.getCreateTime(),delayTime)); - //减去优惠券 - if(memberCouponSJ!=null&&StringUtils.isNotBlank(memberCouponSJ.toString())){ - remoteCouponService.useMemberCoupon(memberCouponSJ.toString()); + // 保存支付订单统一下单日志 + paymentMessageService.savePaymentMessage("1", 0L, payRequestJson, payResponseJson); + + // 保存支付订单统一下单支付记录 + orderPaymentService.saveOrderPayment(userId, shopId, orderId, order.getPayMoney(), + appPlaceOrderVo.getEndTime(), "Y", appPlaceOrderDto.getOpenid(), + Joiner.on(";").join(goodsNameList),result.getPackageValue()); + + return appPlaceOrderVo; + } catch (WxPayException e){ + throw new ServiceException(e.getMessage()); } - //生成自动取消订单延时任务 - Integer delayTime = 30; - if(redisService.hasKey(SecurityConstant.AUTO_CANCEL_ORDER_TIME)){ - delayTime = redisService.getCacheObject(SecurityConstant.AUTO_CANCEL_ORDER_TIME); - } - redisService.setCacheObject(DelayTaskEnum.ORDER_AUTOMATIC_CANCEL.getCode() + "-" + orderId, orderId, delayTime.longValue(), TimeUnit.MINUTES); - DelayTask delayTask = new DelayTask(); - delayTask.setDelFlag(0); - delayTask.setCreateTime(new Date()); - delayTask.setEndTime(DateUtils.addMinutes(new Date(),delayTime)); - delayTask.setRedisKey(DelayTaskEnum.ORDER_AUTOMATIC_CANCEL.getCode() + "-" + orderId); - remoteConfigService.addDelayTask(delayTask); - appPlaceOrderVo.setEndTime(DateUtils.addMinutes(order.getCreateTime(),delayTime)); - return appPlaceOrderVo; } @@ -1358,9 +1404,8 @@ merVerifyOrderVo.setUserMobile(member.getMobile()); merVerifyOrderVo.setCloseFlag(order.getCloseFlag()); // - if(order.getOrderFrom()==2){ - - //profitsSharingService.applyProfitSharing(); + if(order.getOrderFrom() == 2){ + // profitsSharingService.applyProfitSharing(); } //创建支付记录 @@ -1371,8 +1416,39 @@ payRecord.setPayTime(new Date()); payRecord.setPayType(2); payRecordService.save(payRecord); - return merVerifyOrderVo; + // TODO 核销完成 开始分账(平台收取服务费) + OrderPayment payment = orderPaymentService.getByOrderId(orderId); + String transactionId = payment.getTransactionId(); + + String platformTyMacId = MyWxPayConfig.getPlatformTyMacId(); + + R<String> resultMch = remoteShopService.getShopSubMchId(order.getShopId()); + String subMchId = resultMch.getData(); + if(StringUtils.isEmpty(subMchId)){ + throw new ServiceException("获取微信商户号失败"); + } + + R<ShopProportionVo> resultShopProportion = remoteShopService.getShopProportion(order.getShopId()); + ShopProportionVo shopProportion = resultShopProportion.getData(); + if(null == shopProportion){ + throw new ServiceException("获取商户分成失败"); + } + + ProfitSharingRequest request = new ProfitSharingRequest(); + request.setSubMchId(subMchId); + request.setTransactionId(transactionId); + request.setOutOrderNo(order.getOrderNo()); + List<ProfitSharingReceiver> receiverList = new ArrayList<>(); + ProfitSharingReceiver receiver = new ProfitSharingReceiver(); + // TODO 分账 + // receiver.set + // request.setReceivers(); + + // platformTyMacId + // wxService.getProfitSharingV3Service().profitSharing() + + return merVerifyOrderVo; } /** diff --git a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/controller/console/ShopController.java b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/controller/console/ShopController.java index cd42728..4b5e9e0 100644 --- a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/controller/console/ShopController.java +++ b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/controller/console/ShopController.java @@ -2,6 +2,9 @@ import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.exception.ServiceException; +import com.ruoyi.common.core.utils.bean.BeanUtils; +import com.ruoyi.shop.domain.pojo.shop.ShopAuthentication; +import com.ruoyi.shop.domain.pojo.shop.ShopProportion; import com.ruoyi.shop.domain.pojo.shop.ShopRelUser; import com.ruoyi.shop.domain.pojo.shop.ShopStaff; import com.ruoyi.shop.service.shop.*; @@ -10,6 +13,7 @@ import com.ruoyi.system.api.constant.AppErrorConstant; import com.ruoyi.system.api.domain.dto.*; import com.ruoyi.system.api.domain.poji.shop.Shop; +import com.ruoyi.system.api.domain.poji.shop.ShopProportionVo; import com.ruoyi.system.api.domain.poji.sys.SysUser; import com.ruoyi.system.api.domain.vo.*; import com.ruoyi.system.api.model.QwH5LoginVo; @@ -59,6 +63,12 @@ @Resource private MemberTaskService memberTaskService; + @Resource + private ShopAuthenticationService shopAuthenticationService; + + @Resource + private ShopProportionService shopProportionService; + /** * 企业微信H5登录 * @param qwUserDetail @@ -90,6 +100,30 @@ return R.ok(shop); } + @PostMapping("/getShopSubMchId") + public R<String> getShopSubMchId(@RequestBody Long shopId){ + String subMchid = ""; + ShopAuthentication authentication = shopAuthenticationService.getByShopId(shopId); + if(null != authentication){ + subMchid = authentication.getSubMchid(); + } + return R.ok(subMchid, ""); + } + + + /** + * 获取商户分成 + * @param shopId + * @return + */ + @PostMapping("/getShopProportion") + public R<ShopProportionVo> getShopProportion(@RequestBody Long shopId){ + ShopProportion shopProportion = shopProportionService.getByShopId(shopId); + + ShopProportionVo shopProportionVo = new ShopProportionVo(); + BeanUtils.copyBeanProp(shopProportionVo, shopProportion); + return R.ok(shopProportionVo); + } @PostMapping("/getShopByUserId") public R<ShopRelUserVo> getShopByUserId(@RequestBody Long userId) diff --git a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/enums/WxApplyMentSignStateEnum.java b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/enums/WxApplyMentSignStateEnum.java new file mode 100644 index 0000000..3bc5552 --- /dev/null +++ b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/enums/WxApplyMentSignStateEnum.java @@ -0,0 +1,20 @@ +package com.ruoyi.shop.enums; + +import com.ruoyi.shop.enums.dict.IDict; + +public enum WxApplyMentSignStateEnum implements IDict<Integer> { + /** + * 签约状态 + 1、UNSIGNED:未签约。该状态下,电商平台可查询获取签约链接,引导二级商户的超级管理员完成签约; + 2、SIGNED :已签约。指二级商户的超级管理员已完成签约。注意:若申请单被驳回,商户修改了商户主体名称、法人名称、超级管理员信息、主体类型等信息,则需重新签约。 + 3、NOT_SIGNABLE:不可签约。该状态下,暂不支持超级管理员签约。一般为申请单处于已驳回、已冻结、机器校验中状态,无法签约。 + */ + UNSIGNED(1, "UNSIGNED"), + SIGNED(2, "SIGNED"), + NOT_SIGNABLE(3, "NOT_SIGNABLE"); + + WxApplyMentSignStateEnum(Integer code, String text){ + init(code, text); + } + +} diff --git a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/enums/WxApplyMentStateEnum.java b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/enums/WxApplyMentStateEnum.java new file mode 100644 index 0000000..709e72d --- /dev/null +++ b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/enums/WxApplyMentStateEnum.java @@ -0,0 +1,30 @@ +package com.ruoyi.shop.enums; + +import com.ruoyi.shop.enums.dict.IDict; + +public enum WxApplyMentStateEnum implements IDict<Integer> { + /** + * 审核状态 + 1:CHECKING:资料校验中 + 2:ACCOUNT_NEED_VERIFY:待账户验证 + 3:AUDITING:审核中 + 4:REJECTED:已驳回 + 5:NEED_SIGN:待签约 + 6:FINISH:完成 + 7:FROZEN:已冻结 + 8:CANCELED:已作废 + */ + CHECKING(1, "CHECKING"), + ACCOUNT_NEED_VERIFY(2, "ACCOUNT_NEED_VERIFY"), + AUDITING(3, "AUDITING"), + REJECTED(4, "REJECTED"), + NEED_SIGN(5, "NEED_SIGN"), + FINISH(6, "FINISH"), + FROZEN(7, "FROZEN"), + CANCELED(8, "CANCELED"); + + WxApplyMentStateEnum(Integer code, String text){ + init(code, text); + } + +} diff --git a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/enums/dict/DictBean.java b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/enums/dict/DictBean.java new file mode 100644 index 0000000..c8c2424 --- /dev/null +++ b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/enums/dict/DictBean.java @@ -0,0 +1,15 @@ +package com.ruoyi.shop.enums.dict; + +import lombok.Data; + +/** + * 字典bean + * 只有code和text,可用于展示下拉框 + * + * @author luozhan + */ +@Data +public class DictBean<T> implements IDict<T> { + private final T code; + private final String text; +} diff --git a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/enums/dict/IDict.java b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/enums/dict/IDict.java new file mode 100644 index 0000000..04e77ec --- /dev/null +++ b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/enums/dict/IDict.java @@ -0,0 +1,170 @@ +package com.ruoyi.shop.enums.dict; + +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + + +/** + * 字典接口 + * <p> + * 自定义的字典枚举类实现本接口后可省略属性code和text,以及对应的get方法 + * 在构造方法中只需调用init方法即可初始化 + * + * @author luozhan + * @date 2021-12 + */ +public interface IDict<T> { + /** + * 通过code获取value + * + * @param clazz 枚举class + * @param code code + * @return text + */ + static <T> String getTextByCode(Class<? extends IDict<T>> clazz, T code) { + return Stream.of(clazz.getEnumConstants()) + .filter((IDict<T> e) -> e.getCode().equals(code)) + .map(IDict::getText) + .findAny().orElse(""); + } + + /** + * 通过text获取code + * + * @param clazz 枚举class + * @param text text + * @return code + */ + static <T> T getCodeByText(Class<? extends IDict<T>> clazz, String text) { + return Stream.of(clazz.getEnumConstants()) + .filter((IDict<T> e) -> e.getText().equals(text)) + .map(IDict::getCode) + .findAny().orElse(null); + } + + /** + * 通过code获取字典枚举实例 + * + * @param clazz 枚举class + * @param code code + * @param <T> 字典code类型 + * @param <R> 枚举类型 + * @return 字典枚举实例 + */ + @SuppressWarnings("unchecked") + static <T, R extends IDict<T>> R getByCode(Class<? extends IDict<T>> clazz, T code) { + return Stream.of(clazz.getEnumConstants()) + .filter((IDict<T> e) -> (e.getCode().equals(code))) + .map(v -> (R) v) + .findAny() + .orElse(null); + } + + /** + * 获取给定的字典枚举项(常用下拉框数据请求) + * + * @param enums 可指定需要哪些项 + * @return List + */ + @SafeVarargs + static <T, E extends IDict<T>> List<IDict<T>> getItems(E... enums) { + return Stream.of(enums) + .map(DictPool::getDict) + .collect(Collectors.toList()); + } + + /** + * 获取所有字典枚举项,除开指定的枚举 + * + * @param exclude 指定排除的枚举 + * @return List + */ + @SafeVarargs + @SuppressWarnings("unchecked") + static <T, E extends IDict<T>> List<IDict<T>> getItemsExclude(E... exclude) { + Class<IDict<T>> clazz = (Class<IDict<T>>) exclude.getClass().getComponentType(); + IDict<T>[] allEnum = clazz.getEnumConstants(); + List<IDict<T>> excludeList = Arrays.asList(exclude); + return Stream.of(allEnum) + .filter(e -> !excludeList.contains(e)) + .map(DictPool::getDict) + .collect(Collectors.toList()); + } + + /** + * 获取所有字典枚举项(常用下拉框数据请求) + * 枚举值上标记@Deprecated的不会返回 + * + * @param clazz 字典枚举类 + * @return List + */ + static <T> List<IDict<T>> getAll(Class<? extends IDict<T>> clazz) { + Map<String, Field> fieldCache = Arrays.stream(clazz.getDeclaredFields()). + filter(Field::isEnumConstant). + collect(Collectors.toMap(Field::getName, Function.identity())); + IDict<T>[] allEnum = clazz.getEnumConstants(); + return Stream.of(allEnum) + .filter(e -> !fieldCache.get(((Enum<?>) e).name()).isAnnotationPresent(Deprecated.class)) + .map(DictPool::getDict) + .collect(Collectors.toList()); + } + + /** + * 初始化 + * + * @param code 字典编码 + * @param text 字典文本 + */ + default void init(T code, String text) { + DictPool.putDict(this, code, text); + } + + /** + * 获取编码 + * + * @return 编码 + */ + default T getCode() { + return DictPool.getDict(this).getCode(); + } + + /** + * 获取文本 + * + * @return 文本 + */ + default String getText() { + return DictPool.getDict(this).getText(); + } + + + @SuppressWarnings("all") + class DictPool { + private static final Map<IDict, DictBean> DICT_MAP = new ConcurrentHashMap<>(); + + private static final Map<String, Class<? extends IDict>> DICT_NAME_CLASS_MAP = new ConcurrentHashMap<>(); + + static <T> void putDict(IDict<T> dict, T code, String text) { + DICT_NAME_CLASS_MAP.put(dict.getClass().getName(), dict.getClass()); + DICT_MAP.put(dict, new DictBean<>(code, text)); + } + + public static List<IDict<Object>> getDict(String dictName) { + Class<? extends IDict> aClass = DICT_NAME_CLASS_MAP.get(dictName); + return IDict.getAll((Class<? extends IDict<Object>>) aClass); + } + + static <K extends IDict<T>, T> DictBean<T> getDict(K dict) { + return DICT_MAP.get(dict); + } + + + } + +} diff --git a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/scheduler/ShopScheduler.java b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/scheduler/ShopScheduler.java index b239586..be7a4fa 100644 --- a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/scheduler/ShopScheduler.java +++ b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/scheduler/ShopScheduler.java @@ -1,7 +1,12 @@ package com.ruoyi.shop.scheduler; +import com.ruoyi.common.core.utils.bean.BeanUtils; +import com.ruoyi.common.core.utils.uuid.IdUtils; +import com.ruoyi.shop.domain.pojo.shop.ShopAuthentication; +import com.ruoyi.shop.service.shop.ShopService; import com.ruoyi.shop.service.task.ShopTaskService; +import com.ruoyi.system.api.domain.poji.shop.Shop; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; @@ -21,6 +26,9 @@ @Resource private ShopTaskService shopTaskService; + @Resource + private ShopService shopService; + /** * 定时检查跟进任务状态 @@ -33,4 +41,16 @@ } } + /** + * 0 0/1 * * * ? + * 定时检查 每分钟检查一次 微信二级商户进件状态 + */ + @Scheduled(cron="0 0/1 * * * ?") + private void queryEcommerceApplyMentsStatus(){ + if(schedulerUtils.getSchedulerRun()) { + log.info("--------------------定时检查微信二级商户进件状态任务开始执行--------------------"); + shopService.queryEcommerceApplyMentsStatus(); + log.info("--------------------定时检查微信二级商户进件状态任务结束执行--------------------"); + } + } } diff --git a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/impl/shop/ShopAuthenticationServiceImpl.java b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/impl/shop/ShopAuthenticationServiceImpl.java index f94da46..0061371 100644 --- a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/impl/shop/ShopAuthenticationServiceImpl.java +++ b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/impl/shop/ShopAuthenticationServiceImpl.java @@ -1,10 +1,23 @@ package com.ruoyi.shop.service.impl.shop; +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.github.binarywang.wxpay.bean.ecommerce.ApplymentsStatusResult; +import com.google.common.base.Joiner; import com.ruoyi.shop.domain.pojo.shop.ShopAuthentication; +import com.ruoyi.shop.enums.WxApplyMentSignStateEnum; +import com.ruoyi.shop.enums.WxApplyMentStateEnum; +import com.ruoyi.shop.enums.dict.IDict; import com.ruoyi.shop.mapper.shop.ShopAuthenticationMapper; import com.ruoyi.shop.service.shop.ShopAuthenticationService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; /** * <p> @@ -17,4 +30,72 @@ @Service public class ShopAuthenticationServiceImpl extends ServiceImpl<ShopAuthenticationMapper, ShopAuthentication> implements ShopAuthenticationService { + @Override + public List<ShopAuthentication> getShopAuthNeedUpdateStatus() { + List<Integer> auditStatusList = Arrays.asList(1, 2, 3, 5); + + LambdaQueryWrapper<ShopAuthentication> queryWrapper = Wrappers.lambdaQuery(); + queryWrapper.in(ShopAuthentication::getAuditStatus, auditStatusList); + queryWrapper.isNotNull(ShopAuthentication::getApplymentId); + return this.list(queryWrapper); + } + + @Override + public void updateAuditStatusByApplymentId(String applymentId, ApplymentsStatusResult result) { + // WxApplyMentStateEnum + String applymentState = result.getApplymentState(); + Integer auditStatus = IDict.getCodeByText(WxApplyMentStateEnum.class, applymentState); + + Integer signState = IDict.getCodeByText(WxApplyMentSignStateEnum.class, result.getSignState()); + + LambdaUpdateWrapper<ShopAuthentication> updateWrapper = Wrappers.lambdaUpdate(); + updateWrapper.eq(ShopAuthentication::getApplymentId, applymentId) + .set(ShopAuthentication::getAuditStatus, auditStatus) + .set(ShopAuthentication::getSignState, signState); + + if(WxApplyMentStateEnum.ACCOUNT_NEED_VERIFY.getCode().equals(auditStatus)){ + // ACCOUNT_NEED_VERIFY 待账户验证 + updateWrapper.set(ShopAuthentication::getLegalValidationUrl, result.getLegalValidationUrl()); + ApplymentsStatusResult.AccountValidation accountValidation = result.getAccountValidation(); + if(null != accountValidation) { + updateWrapper.set(ShopAuthentication::getAvAccountName, accountValidation.getAccountName()) + .set(ShopAuthentication::getAvAccountNo, accountValidation.getAccountNo()) + .set(ShopAuthentication::getAvPayAmount, accountValidation.getPayAmount()) + .set(ShopAuthentication::getDaNumber, accountValidation.getDestinationAccountNumber()) + .set(ShopAuthentication::getDaName, accountValidation.getDestinationAccountName()) + .set(ShopAuthentication::getDaBank, accountValidation.getDestinationAccountBank()) + .set(ShopAuthentication::getDaCity, accountValidation.getCity()) + .set(ShopAuthentication::getDaRemark, accountValidation.getRemark()) + .set(ShopAuthentication::getDaDeadline, accountValidation.getDeadline()); + } + } else if(WxApplyMentStateEnum.NEED_SIGN.getCode().equals(auditStatus)){ + // NEED_SIGN 待签约 + updateWrapper.set(ShopAuthentication::getSignUrl, result.getSignUrl()); + updateWrapper.set(ShopAuthentication::getSubMchid, result.getSubMchid()); + + } else if(WxApplyMentStateEnum.FINISH.getCode().equals(auditStatus)){ + // FINISH 完成 + updateWrapper.set(ShopAuthentication::getSubMchid, result.getSubMchid()); + + } else if(WxApplyMentStateEnum.REJECTED.getCode().equals(auditStatus) + || WxApplyMentStateEnum.FROZEN.getCode().equals(auditStatus)){ + List<ApplymentsStatusResult.AuditDetail> auditDetail = result.getAuditDetail(); + if(null != auditDetail && !auditDetail.isEmpty()){ + List<String> paramNameList = auditDetail.stream().map(ApplymentsStatusResult.AuditDetail::getParamName).collect(Collectors.toList()); + List<String> rejectReason = auditDetail.stream().map(ApplymentsStatusResult.AuditDetail::getRejectReason).collect(Collectors.toList()); + updateWrapper.set(ShopAuthentication::getAdParamName, Joiner.on(";").join(paramNameList)) + .set(ShopAuthentication::getAdRejectReason, Joiner.on(";").join(rejectReason)); + } + + } + this.update(updateWrapper); + } + + @Override + public ShopAuthentication getByShopId(Long shopId) { + LambdaQueryWrapper<ShopAuthentication> queryWrapper = Wrappers.lambdaQuery(); + queryWrapper.eq(ShopAuthentication::getShopId, shopId) + .last(" limit 1 "); + return this.getOne(queryWrapper); + } } diff --git a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/impl/shop/ShopProportionServiceImpl.java b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/impl/shop/ShopProportionServiceImpl.java index f6d96b3..2596193 100644 --- a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/impl/shop/ShopProportionServiceImpl.java +++ b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/impl/shop/ShopProportionServiceImpl.java @@ -1,7 +1,10 @@ package com.ruoyi.shop.service.impl.shop; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.shop.domain.dto.MgtShopProportionEditDto; +import com.ruoyi.shop.domain.pojo.shop.ShopAuthentication; import com.ruoyi.shop.domain.pojo.shop.ShopProportion; import com.ruoyi.shop.mapper.shop.ShopProportionMapper; import com.ruoyi.shop.service.shop.ShopProportionService; @@ -48,4 +51,13 @@ shopProportionNew.setUpdateUserId(mgtShopProportionEditDto.getUserId()); this.saveOrUpdate(shopProportionNew); } + + @Override + public ShopProportion getByShopId(Long shopId) { + LambdaQueryWrapper<ShopProportion> queryWrapper = Wrappers.lambdaQuery(); + queryWrapper.eq(ShopProportion::getShopId, shopId) + .eq(ShopProportion::getDelFlag, 0) + .last(" limit 1 "); + return this.getOne(queryWrapper); + } } diff --git a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/impl/shop/ShopServiceImpl.java b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/impl/shop/ShopServiceImpl.java index 6df823e..5427a4c 100644 --- a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/impl/shop/ShopServiceImpl.java +++ b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/impl/shop/ShopServiceImpl.java @@ -2,9 +2,12 @@ import com.alibaba.fastjson2.JSON; 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.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.github.binarywang.wxpay.bean.ecommerce.ApplymentsResult; +import com.github.binarywang.wxpay.bean.ecommerce.ApplymentsStatusResult; import com.github.binarywang.wxpay.exception.WxPayException; import com.ruoyi.common.core.constant.CacheConstants; import com.ruoyi.common.core.exception.ServiceException; @@ -18,6 +21,7 @@ import com.ruoyi.shop.domain.pojo.shop.*; import com.ruoyi.shop.domain.pojo.task.ShopFile; import com.ruoyi.shop.domain.vo.*; +import com.ruoyi.shop.enums.WxApplyMentStateEnum; import com.ruoyi.shop.mapper.shop.ShopMapper; import com.ruoyi.shop.service.shop.*; import com.ruoyi.shop.service.task.MemberTaskService; @@ -124,25 +128,26 @@ /** * 获取商户详情 + * * @param shopId * @return */ @Override - public AppShopInfoVo getAppShopInfo(Long shopId){ + public AppShopInfoVo getAppShopInfo(Long shopId) { AppShopInfoVo appShopInfoVo = new AppShopInfoVo(); Shop shop = this.getById(shopId); - BeanUtils.copyProperties(shop,appShopInfoVo); + BeanUtils.copyProperties(shop, appShopInfoVo); //商户地址 - appShopInfoVo.setShopAddress(shop.getShopAreaName()+shop.getShopAddress()); + appShopInfoVo.setShopAddress(shop.getShopAreaName() + shop.getShopAddress()); //商品图片 List<ShopFile> shopFileList = shopFileService.listShopFileByShopId(shopId); String shopPicture = null; StringJoiner shopBanners = new StringJoiner(","); - if(shopFileList!=null&&!shopFileList.isEmpty()){ - for(ShopFile shopFile : shopFileList){ - if(shopFile.getFileType()==1){ + if (shopFileList != null && !shopFileList.isEmpty()) { + for (ShopFile shopFile : shopFileList) { + if (shopFile.getFileType() == 1) { shopPicture = shopFile.getFileUrl(); - }else{ + } else { shopBanners.add(shopFile.getFileUrl()); } } @@ -151,7 +156,7 @@ appShopInfoVo.setShopBanners(shopBanners.toString()); //商户证书 List<ShopCertificate> shopCertificateList = shopCertificateService.listShopCertificateByShopId(shopId); - if(shopCertificateList!=null&&!shopCertificateList.isEmpty()){ + if (shopCertificateList != null && !shopCertificateList.isEmpty()) { appShopInfoVo.setShopCertificateList(shopCertificateList); } return appShopInfoVo; @@ -159,32 +164,33 @@ /** * 创建商户 + * * @param mgtEditShopDto */ @Override - public void createShop(MgtEditShopDto mgtEditShopDto){ + public void createShop(MgtEditShopDto mgtEditShopDto) { Shop shop = new Shop(); Boolean newShop = false; BigDecimal zeroBig = BigDecimal.ZERO; //验证关联账号唯一 String relUserIds = mgtEditShopDto.getRelUserIds(); - if(StringUtils.isNotBlank(relUserIds)) { + if (StringUtils.isNotBlank(relUserIds)) { String[] relUserIdArray = relUserIds.split(","); ShopRelUser shopRelUser; Long userId; - if(mgtEditShopDto.getShopId()!=null){ + if (mgtEditShopDto.getShopId() != null) { for (String str : relUserIdArray) { userId = Long.valueOf(str); shopRelUser = shopRelUserService.getByUserId(userId); - if(shopRelUser!=null&&!shopRelUser.getShopId().equals(mgtEditShopDto.getShopId())){ + if (shopRelUser != null && !shopRelUser.getShopId().equals(mgtEditShopDto.getShopId())) { throw new ServiceException(AppErrorConstant.SHOP_USER_DOUBLE); } } - }else { + } else { for (String str : relUserIdArray) { userId = Long.valueOf(str); shopRelUser = shopRelUserService.getByUserId(userId); - if(shopRelUser!=null){ + if (shopRelUser != null) { throw new ServiceException(AppErrorConstant.SHOP_USER_DOUBLE); } } @@ -192,9 +198,9 @@ } //验证商户名唯一 - Shop shopSame = this.getOne(new LambdaQueryWrapper<Shop>().eq(Shop::getDelFlag,0).eq(Shop::getShopName,mgtEditShopDto.getShopName())); - if(mgtEditShopDto.getShopId()!=null){ - if(shopSame!=null&&!Objects.equals(shopSame.getShopId(),mgtEditShopDto.getShopId())){ + Shop shopSame = this.getOne(new LambdaQueryWrapper<Shop>().eq(Shop::getDelFlag, 0).eq(Shop::getShopName, mgtEditShopDto.getShopName())); + if (mgtEditShopDto.getShopId() != null) { + if (shopSame != null && !Objects.equals(shopSame.getShopId(), mgtEditShopDto.getShopId())) { throw new ServiceException(AppErrorConstant.SHOP_DOUBLE); } shop = this.getById(mgtEditShopDto.getShopId()); @@ -208,14 +214,14 @@ //清空归属 shopRelUserService.deleteByShopId(shop.getShopId()); shopStaffService.clearShopStaffRelation(shop.getShopId()); - if(!shop.getShopName().equals(mgtEditShopDto.getShopName())){ + if (!shop.getShopName().equals(mgtEditShopDto.getShopName())) { MgtMemberShopNameDto mgtMemberShopNameDto = new MgtMemberShopNameDto(); mgtMemberShopNameDto.setShopId(mgtEditShopDto.getShopId()); mgtMemberShopNameDto.setShopName(mgtEditShopDto.getShopName()); remoteMemberService.updateMemberShopName(mgtMemberShopNameDto); } - }else{ - if(shopSame!=null){ + } else { + if (shopSame != null) { throw new ServiceException(AppErrorConstant.SHOP_DOUBLE); } shop.setDelFlag(0); @@ -227,9 +233,9 @@ shop.setAuthFlag(0); newShop = true; } - BeanUtils.copyProperties(mgtEditShopDto,shop); + BeanUtils.copyProperties(mgtEditShopDto, shop); String shopDetail = shop.getShopDetail(); - if(StringUtils.isNotBlank(shopDetail)){ + if (StringUtils.isNotBlank(shopDetail)) { byte[] decodedBytes = Base64.getDecoder().decode(shopDetail); shopDetail = new String(decodedBytes, StandardCharsets.UTF_8); shop.setShopDetail(shopDetail); @@ -242,13 +248,13 @@ this.saveOrUpdate(shop); //商户标签 String shopTagIds = mgtEditShopDto.getShopTagIds(); - if(StringUtils.isNotBlank(shopTagIds)){ + if (StringUtils.isNotBlank(shopTagIds)) { String[] shopTagIdArray = shopTagIds.split(","); ShopRelTag shopRelTag; Long tagid; StringJoiner shopTagSj = new StringJoiner(","); SysTag sysTag; - for(String str : shopTagIdArray){ + for (String str : shopTagIdArray) { shopRelTag = new ShopRelTag(); tagid = Long.valueOf(str); sysTag = configService.getSysTag(tagid).getData(); @@ -267,13 +273,13 @@ handleShopStaff(shop.getShopId(),belongSysUser); }*/ //商户关联人员 - if(StringUtils.isNotBlank(relUserIds)){ + if (StringUtils.isNotBlank(relUserIds)) { shopStaffService.clearShopStaffRelation(shop.getShopId()); String[] relUserIdArray = relUserIds.split(","); ShopRelUser shopRelUser; Long userId; SysUser sysUser; - for(String str : relUserIdArray){ + for (String str : relUserIdArray) { shopRelUser = new ShopRelUser(); userId = Long.valueOf(str); sysUser = sysUserService.getSysUser(userId).getData(); @@ -284,7 +290,7 @@ shopRelUser.setUserMobile(sysUser.getPhonenumber()); shopRelUser.setUserDeptId(sysUser.getDeptId()); shopRelUserService.save(shopRelUser); - handleShopStaff(shop.getShopId(),sysUser); + handleShopStaff(shop.getShopId(), sysUser); } } //商户封面 @@ -295,10 +301,10 @@ shopFile.setShopId(shop.getShopId()); shopFileService.save(shopFile); //商户banner - if(StringUtils.isNotBlank(mgtEditShopDto.getShopBanners())){ - String shopBanners= mgtEditShopDto.getShopBanners(); + if (StringUtils.isNotBlank(mgtEditShopDto.getShopBanners())) { + String shopBanners = mgtEditShopDto.getShopBanners(); String[] shopBannerArray = shopBanners.split(","); - for(String str : shopBannerArray){ + for (String str : shopBannerArray) { shopFile = new ShopFile(); shopFile.setDelFlag(0); shopFile.setFileType(2); @@ -307,13 +313,13 @@ shopFileService.save(shopFile); } } - if(newShop){ + if (newShop) { //生成商户关联记录 - initNewShop(shop,mgtEditShopDto.getUserId()); + initNewShop(shop, mgtEditShopDto.getUserId()); CodeGetDto codeGetDto = new CodeGetDto(); - String url = "https://wxapp.hhhrt.cn/mini/activity?activityId="+shop.getShopId(); + String url = "https://wxapp.hhhrt.cn/mini/activity?activityId=" + shop.getShopId(); codeGetDto.setUrl(url); - codeGetDto.setFileName("shop-"+shop.getShopId()); + codeGetDto.setFileName("shop-" + shop.getShopId()); String codeUrl = remoteFileService.getAppOrderTotal(codeGetDto).getData(); shop.setShopCode(codeUrl); this.saveOrUpdate(shop); @@ -321,14 +327,14 @@ } /** - * @description 商户关联类初始化 - * @author jqs - * @date 2023/7/7 11:25 * @param shop * @param userId - * @return void + * @return void + * @description 商户关联类初始化 + * @author jqs + * @date 2023/7/7 11:25 */ - private void initNewShop(Shop shop,Long userId){ + private void initNewShop(Shop shop, Long userId) { BigDecimal zeroBig = new BigDecimal("0.00"); //商户账户信息初始化 ShopAccount shopAccount = new ShopAccount(); @@ -394,16 +400,16 @@ } /** - * @description 终止合作 - * @author jqs - * @date 2023/6/20 12:01 * @param mgtTerminateCooperationDto - * @return void + * @return void + * @description 终止合作 + * @author jqs + * @date 2023/6/20 12:01 */ @Override - public void terminateMgtCooperation(MgtTerminateCooperationDto mgtTerminateCooperationDto){ + public void terminateMgtCooperation(MgtTerminateCooperationDto mgtTerminateCooperationDto) { Shop shop = this.getById(mgtTerminateCooperationDto.getShopId()); - if(mgtTerminateCooperationDto.getCooperativeFlag()==1){ + if (mgtTerminateCooperationDto.getCooperativeFlag() == 1) { /*Date coopStartDate = shop.getCooperationStartTime(); Date coopEndDate = shop.getCooperationEndTime(); Date nowTime = new Date(); @@ -412,52 +418,52 @@ throw new ServiceException(AppErrorConstant.COOPERATION_TIME_ERROR); }*/ shop.setCooperativeFlag(1); - }else{ + } else { shop.setCooperativeFlag(0); } - shop.setShopStatus(handelShopStatus(shop.getFrozenFlag(),shop.getCooperativeFlag(),shop.getAuthFlag())); + shop.setShopStatus(handelShopStatus(shop.getFrozenFlag(), shop.getCooperativeFlag(), shop.getAuthFlag())); shop.setUpdateTime(new Date()); shop.setUpdateUserId(mgtTerminateCooperationDto.getUserId()); this.saveOrUpdate(shop); } /** - * @description 冻结商户 - * @author jqs - * @date 2023/7/15 13:56 * @param mgtFrozenShopDto - * @return void + * @return void + * @description 冻结商户 + * @author jqs + * @date 2023/7/15 13:56 */ @Override - public void frozenMgtShop(MgtFrozenShopDto mgtFrozenShopDto){ + public void frozenMgtShop(MgtFrozenShopDto mgtFrozenShopDto) { Shop shop = this.getById(mgtFrozenShopDto.getShopId()); - if(mgtFrozenShopDto.getFrozenFlag()==1){ + if (mgtFrozenShopDto.getFrozenFlag() == 1) { shop.setFrozenFlag(1); - }else{ + } else { shop.setFrozenFlag(0); } - shop.setShopStatus(handelShopStatus(shop.getFrozenFlag(),shop.getCooperativeFlag(),shop.getAuthFlag())); + shop.setShopStatus(handelShopStatus(shop.getFrozenFlag(), shop.getCooperativeFlag(), shop.getAuthFlag())); this.saveOrUpdate(shop); } /** - * @description 处理商户状态 - * @author jqs - * @date 2023/7/15 14:09 * @param - * @return Integer + * @return Integer + * @description 处理商户状态 + * @author jqs + * @date 2023/7/15 14:09 */ - private Integer handelShopStatus(Integer frozenFlag, Integer cooperativeFlag, Integer authFlag){ + private Integer handelShopStatus(Integer frozenFlag, Integer cooperativeFlag, Integer authFlag) { Integer shopStatus = 1; - if(frozenFlag == 1){ + if (frozenFlag == 1) { shopStatus = 0; return shopStatus; } - if(authFlag == 0){ + if (authFlag == 0) { shopStatus = 3; return shopStatus; } - if(cooperativeFlag == 0){ + if (cooperativeFlag == 0) { shopStatus = 2; return shopStatus; } @@ -467,16 +473,17 @@ /** * 修改合作时间 + * * @param mgtChangeCoopDto */ @Override - public void changeCooperationTime(MgtChangeCoopDto mgtChangeCoopDto){ + public void changeCooperationTime(MgtChangeCoopDto mgtChangeCoopDto) { Shop shop = this.getById(mgtChangeCoopDto.getShopId()); Date coopStartDate = null; Date coopEndDate = null; try { - coopStartDate = DateUtils.parseDate(mgtChangeCoopDto.getCoopStartTime(),"yyyy-MM-dd"); - coopEndDate = DateUtils.parseDate(mgtChangeCoopDto.getCoopEndTime(),"yyyy-MM-dd"); + coopStartDate = DateUtils.parseDate(mgtChangeCoopDto.getCoopStartTime(), "yyyy-MM-dd"); + coopEndDate = DateUtils.parseDate(mgtChangeCoopDto.getCoopEndTime(), "yyyy-MM-dd"); } catch (ParseException e) { throw new RuntimeException(e); } @@ -484,13 +491,13 @@ shop.setCooperationStartTime(coopStartDate); shop.setCooperationEndTime(coopEndDate); Boolean inTime = false; - if(coopStartDate.compareTo(nowTime)<=0&&coopEndDate.compareTo(nowTime)>=0){ + if (coopStartDate.compareTo(nowTime) <= 0 && coopEndDate.compareTo(nowTime) >= 0) { inTime = true; shop.setCooperativeFlag(1); - }else{ + } else { shop.setCooperativeFlag(0); } - if(shop.getShopStatus()==2&&inTime){ + if (shop.getShopStatus() == 2 && inTime) { shop.setShopStatus(1); } shop.setUpdateTime(nowTime); @@ -500,12 +507,13 @@ /** * 分页获取商户 + * * @param page * @param mgtShopPageDto * @return */ @Override - public List<MgtShopPageVo> pageMgtShop(Page page, MgtShopPageDto mgtShopPageDto){ + public List<MgtShopPageVo> pageMgtShop(Page page, MgtShopPageDto mgtShopPageDto) { if (StringUtils.isNotBlank(mgtShopPageDto.getShopTags())) { mgtShopPageDto.setShopTags(mgtShopPageDto.getShopTags().replace(",", "|")); } @@ -528,7 +536,7 @@ MgtBaseBathDto mgtBaseBathDto; Map<Long, MgtSysSimpleUserVo> signUserMap = null; Map<Long, MgtSysSimpleUserVo> belongUserMap = null; - if(signUserIdSet!=null&&!signUserIdSet.isEmpty()){ + if (signUserIdSet != null && !signUserIdSet.isEmpty()) { String signUserString = String.join(",", signUserIdSet.stream().map(Object::toString).collect(Collectors.toList())); mgtBaseBathDto = new MgtBaseBathDto(); mgtBaseBathDto.setIds(signUserString); @@ -536,7 +544,7 @@ signUserMap = signUserVoList.stream() .collect(Collectors.toMap(MgtSysSimpleUserVo::getUserId, Function.identity())); } - if(belongUserIdSet!=null&&!belongUserIdSet.isEmpty()){ + if (belongUserIdSet != null && !belongUserIdSet.isEmpty()) { // 将签约用户ID集合和所属用户ID集合转为字符串 String belongUserString = String.join(",", belongUserIdSet.stream().map(Object::toString).collect(Collectors.toList())); // 查询签约用户和所属用户的详细信息 @@ -548,10 +556,10 @@ } // 遍历查询结果,将签约用户和所属用户的详细信息添加到商铺信息中 for (MgtShopPageVo shopPageVo : mgtShopPageVoList) { - if (signUserMap!=null&&!signUserMap.isEmpty()&&shopPageVo.getSignUserId() != null) { + if (signUserMap != null && !signUserMap.isEmpty() && shopPageVo.getSignUserId() != null) { shopPageVo.setSignUser(signUserMap.get(shopPageVo.getSignUserId()).getNickName()); } - if (belongUserMap!=null&&!belongUserMap.isEmpty()&&shopPageVo.getBelongUserId() != null) { + if (belongUserMap != null && !belongUserMap.isEmpty() && shopPageVo.getBelongUserId() != null) { shopPageVo.setBelongUser(belongUserMap.get(shopPageVo.getBelongUserId()).getNickName()); shopPageVo.setBelongDept(belongUserMap.get(shopPageVo.getBelongUserId()).getDeptName()); } @@ -563,44 +571,45 @@ /** * 获取商户详情 + * * @param shopId * @return */ @Override - public MgtShopInfoVo getMgtShopInfo(Long shopId){ + public MgtShopInfoVo getMgtShopInfo(Long shopId) { MgtShopInfoVo mgtShopInfoVo = new MgtShopInfoVo(); Shop shop = this.getById(shopId); //基本信息拷贝 - BeanUtils.copyProperties(shop,mgtShopInfoVo); + BeanUtils.copyProperties(shop, mgtShopInfoVo); String shopDetail = mgtShopInfoVo.getShopDetail(); - if(StringUtils.isNotBlank(shopDetail)){ + if (StringUtils.isNotBlank(shopDetail)) { byte[] encodedBytes = Base64.getEncoder().encode(shopDetail.getBytes(StandardCharsets.UTF_8)); shopDetail = new String(encodedBytes, StandardCharsets.UTF_8); mgtShopInfoVo.setShopDetail(shopDetail); } //商户标签 List<ShopRelTag> shopRelTagList = shopRelTagService.listShopRelTagByShopId(shopId); - if(shopRelTagList!=null&&!shopRelTagList.isEmpty()){ + if (shopRelTagList != null && !shopRelTagList.isEmpty()) { StringJoiner shopTagJs = new StringJoiner(","); - for(ShopRelTag shopRelTag : shopRelTagList){ + for (ShopRelTag shopRelTag : shopRelTagList) { shopTagJs.add(shopRelTag.getTagId().toString()); } mgtShopInfoVo.setShopTagIds(shopTagJs.toString()); } - if(mgtShopInfoVo.getBelongUserId()!=null){ + if (mgtShopInfoVo.getBelongUserId() != null) { SysUser sysUser = sysUserService.getSysUser(mgtShopInfoVo.getBelongUserId()).getData(); mgtShopInfoVo.setBelongUserName(sysUser.getNickName()); } - if(mgtShopInfoVo.getBelongShopId()!=null){ + if (mgtShopInfoVo.getBelongShopId() != null) { Shop belongShop = this.getByShopId(mgtShopInfoVo.getBelongShopId()); mgtShopInfoVo.setBelongShopName(belongShop.getShopName()); } //商户关联用户 List<ShopRelUser> shopRelUserList = shopRelUserService.listByShopId(shopId); - if(shopRelUserList!=null&&!shopRelUserList.isEmpty()){ + if (shopRelUserList != null && !shopRelUserList.isEmpty()) { StringJoiner shopUserJs = new StringJoiner(","); StringJoiner shopUserNameJs = new StringJoiner(","); - for(ShopRelUser shopRelUser : shopRelUserList){ + for (ShopRelUser shopRelUser : shopRelUserList) { shopUserJs.add(shopRelUser.getUserId().toString()); shopUserNameJs.add(shopRelUser.getUserName()); } @@ -609,12 +618,12 @@ } //商户图片 List<ShopFile> shopFileList = shopFileService.listShopFileByShopId(shopId); - if(shopFileList!=null&&!shopFileList.isEmpty()){ + if (shopFileList != null && !shopFileList.isEmpty()) { StringJoiner shopBannerJs = new StringJoiner(","); - for(ShopFile shopFile : shopFileList){ - if(shopFile.getFileType()==1){ + for (ShopFile shopFile : shopFileList) { + if (shopFile.getFileType() == 1) { mgtShopInfoVo.setShopPicture(shopFile.getFileUrl()); - }else{ + } else { shopBannerJs.add(shopFile.getFileUrl()); } } @@ -628,22 +637,23 @@ /** * 修改商户标签 + * * @param mgtEditShopTagDto */ @Override - public void editShopTag(MgtEditShopTagDto mgtEditShopTagDto){ + public void editShopTag(MgtEditShopTagDto mgtEditShopTagDto) { Long shopId = Long.valueOf(mgtEditShopTagDto.getId()); String shopTagIds = mgtEditShopTagDto.getShopTagIds(); String shopTags = null; //删除以前的标签 shopRelTagService.deleteByShopId(shopId); - if(StringUtils.isNotBlank(shopTagIds)){ + if (StringUtils.isNotBlank(shopTagIds)) { ShopRelTag shopRelTag; SysTag sysTag; Long tagId; String[] shopTagIdArray = shopTagIds.split(","); StringJoiner shopTagSj = new StringJoiner(","); - for(String str : shopTagIdArray){ + for (String str : shopTagIdArray) { tagId = Long.valueOf(str); sysTag = configService.getSysTag(tagId).getData(); shopRelTag = new ShopRelTag(); @@ -662,17 +672,17 @@ /** - * @description 转移客户 - * @author jqs - * @date 2023/6/28 16:36 * @param mgtTransferShopDto - * @return void + * @return void + * @description 转移客户 + * @author jqs + * @date 2023/6/28 16:36 */ @Override - public void transferMgtShop(MgtTransferShopDto mgtTransferShopDto){ + public void transferMgtShop(MgtTransferShopDto mgtTransferShopDto) { Shop shop = this.getByShopId(mgtTransferShopDto.getShopId()); - if(shop.getBelongUserId()!=null){ - if(shop.getBelongUserId().equals(mgtTransferShopDto.getUserId())){ + if (shop.getBelongUserId() != null) { + if (shop.getBelongUserId().equals(mgtTransferShopDto.getUserId())) { throw new ServiceException(AppErrorConstant.TRANS_NOT_MYSELF); } ShopTransferRecord shopTransferRecord = new ShopTransferRecord(); @@ -699,24 +709,25 @@ /** * 获取附近门店 + * * @param appNearbyShopDto * @return */ @Override - public AppNearbyShopVo getNearbyShop(AppNearbyShopDto appNearbyShopDto,Member member){ + public AppNearbyShopVo getNearbyShop(AppNearbyShopDto appNearbyShopDto, Member member) { AppNearbyShopVo appNearbyShopVo = new AppNearbyShopVo(); Shop shop = null; //获取附近商户 - if(member!=null&&member.getRelationShopId()!=null&&member.getBindingFlag()==1){ + if (member != null && member.getRelationShopId() != null && member.getBindingFlag() == 1) { //获取绑定商户 shop = this.getById(member.getRelationShopId()); - }else if(StringUtils.isNotBlank(appNearbyShopDto.getLatitude())&&StringUtils.isNotBlank(appNearbyShopDto.getLongitude())){ + } else if (StringUtils.isNotBlank(appNearbyShopDto.getLatitude()) && StringUtils.isNotBlank(appNearbyShopDto.getLongitude())) { AppNearShopVo appNearShopVo = shopMapper.getNearbyShop(appNearbyShopDto); shop = this.getById(appNearShopVo.getShopId()); - }else{ + } else { return appNearbyShopVo; } - if(member!=null&&member.getBindingFlag()!=1){ + if (member != null && member.getBindingFlag() != 1) { AppMemberBindingDto appMemberBindingDto = new AppMemberBindingDto(); appMemberBindingDto.setShopId(shop.getShopId()); appMemberBindingDto.setShopName(shop.getShopName()); @@ -726,36 +737,36 @@ } appNearbyShopVo.setShopId(shop.getShopId()); appNearbyShopVo.setShopName(shop.getShopName()); - appNearbyShopVo.setShopAddress(shop.getShopAreaName()+shop.getShopAddress()); + appNearbyShopVo.setShopAddress(shop.getShopAreaName() + shop.getShopAddress()); appNearbyShopVo.setShopLatitude(shop.getShopLatitude()); appNearbyShopVo.setShopLongitude(shop.getShopLongitude()); return appNearbyShopVo; } /** - * * @param shopId * @return */ @Override - public Shop getByShopId(Long shopId){ + public Shop getByShopId(Long shopId) { LambdaQueryWrapper<Shop> queryWrapper = Wrappers.lambdaQuery(); queryWrapper.eq(Shop::getDelFlag, 0).eq(Shop::getShopId, shopId); - Shop shop = this.getOne(queryWrapper,false); + Shop shop = this.getOne(queryWrapper, false); return shop; } /** * 获取获取员工端首页统计 + * * @param userId * @return */ @Override - public StaffHomeShopTotalVo getStaffHomeTotal(Long userId){ + public StaffHomeShopTotalVo getStaffHomeTotal(Long userId) { List<Long> userIds = null; List<Long> shopIds = null; //如果是leader 查询leader下面所有的员工下的所有shopId - if(remoteSysStaffService.isLeader()){ + if (remoteSysStaffService.isLeader()) { userIds = sysUserService.getUserIdsByDept(userId).getData(); //根据用户所有id查询关联的商户id MgtBasePlatformDto mgtBasePlatformDto = new MgtBasePlatformDto(); @@ -763,7 +774,7 @@ shopIds = shopMapper.listShopIdByTotal(mgtBasePlatformDto); Shop shop = this.getShopByBelongUserId(userId); shopIds.add(shop.getShopId()); - }else { + } else { //普通员工查询商户归属的shopId Shop shop = this.getShopByBelongUserId(userId); shopIds.add(shop.getShopId()); @@ -776,22 +787,24 @@ staffHomeShopTotalVo.setShopTask(shopTaskCount); return staffHomeShopTotalVo; } + /** * 获取商户端 + * * @param merBaseDto * @return */ @Override - public MerHomeShopTotalVo getMerHomeTotal(MerBaseDto merBaseDto){ + public MerHomeShopTotalVo getMerHomeTotal(MerBaseDto merBaseDto) { Long userId = merBaseDto.getUserId(); MerHomeShopTotalVo merHomeShopTotalVo = new MerHomeShopTotalVo(); ShopRelUser shopRelUser = shopRelUserService.getByUserId(userId); Long shopId = shopRelUser.getShopId(); //如果商户变动刷新token - if(!shopId.equals(merBaseDto.getShopId())){ + if (!shopId.equals(merBaseDto.getShopId())) { String userKey = SecurityUtils.getUserKey(); - redisService.deleteObject(CacheConstants.LOGIN_TOKEN_KEY+userKey); - throw new ServiceException("登录状态已过期",401); + redisService.deleteObject(CacheConstants.LOGIN_TOKEN_KEY + userKey); + throw new ServiceException("登录状态已过期", 401); } merHomeShopTotalVo.setShopId(shopId); Shop shop = this.getById(shopId); @@ -812,26 +825,28 @@ /** * 获取商户绑定代理商 + * * @param page * @param merAgencyPageDto * @return */ @Override - public List<MerAgencyPageVo> pageMerAgencyVo(Page page, MerAgencyPageDto merAgencyPageDto){ + public List<MerAgencyPageVo> pageMerAgencyVo(Page page, MerAgencyPageDto merAgencyPageDto) { List<MerAgencyPageVo> merAgencyPageVoList = shopMapper.pageMerAgencyVo(page, merAgencyPageDto); return merAgencyPageVoList; } /** * 处理商户员工 + * * @param shopId * @param sysUser */ - private void handleShopStaff(Long shopId,SysUser sysUser){ + private void handleShopStaff(Long shopId, SysUser sysUser) { ShopStaff shopStaff = shopStaffService.getByUserId(sysUser.getUserId()); - if(shopStaff!=null){ + if (shopStaff != null) { shopStaff.setShopId(shopId); - }else{ + } else { String staffId = IdUtils.simpleUUID(); shopStaff = new ShopStaff(); shopStaff.setStaffId(staffId); @@ -847,42 +862,42 @@ } /** - * @description 平台获取商户分成列表 - * @author jqs - * @date 2023/6/8 9:25 * @param page * @param mgtShopProportionPageDto - * @return List<MgtShopProportionPageVo> + * @return List<MgtShopProportionPageVo> + * @description 平台获取商户分成列表 + * @author jqs + * @date 2023/6/8 9:25 */ @Override - public List<MgtShopProportionPageVo> pageMgtShopProportion(Page page, MgtShopProportionPageDto mgtShopProportionPageDto){ - return shopMapper.pageMgtShopProportion(page,mgtShopProportionPageDto); + public List<MgtShopProportionPageVo> pageMgtShopProportion(Page page, MgtShopProportionPageDto mgtShopProportionPageDto) { + return shopMapper.pageMgtShopProportion(page, mgtShopProportionPageDto); } /** - * @description 删除商户标签 - * @author jqs - * @date 2023/6/8 15:53 * @param shopTag - * @return void + * @return void + * @description 删除商户标签 + * @author jqs + * @date 2023/6/8 15:53 */ @Override - public void deleteShopTag(String shopTag){ + public void deleteShopTag(String shopTag) { shopMapper.deleteShopTag(shopTag); } /** - * @description 通过code获取shopId - * @author jqs - * @date 2023/6/9 16:40 * @param mgtShopIdByCodeDto - * @return MgtShopIdByCodeVo + * @return MgtShopIdByCodeVo + * @description 通过code获取shopId + * @author jqs + * @date 2023/6/9 16:40 */ @Override - public MgtShopIdByCodeVo getShopIdByCode(MgtShopIdByCodeDto mgtShopIdByCodeDto){ + public MgtShopIdByCodeVo getShopIdByCode(MgtShopIdByCodeDto mgtShopIdByCodeDto) { MgtShopIdByCodeVo mgtShopIdByCodeVo = new MgtShopIdByCodeVo(); List<Long> shopIdList = shopMapper.getShopIdByCode(mgtShopIdByCodeDto); - if(shopIdList!=null&&!shopIdList.isEmpty()){ + if (shopIdList != null && !shopIdList.isEmpty()) { String shopIdStr = shopIdList.stream() .map(Object::toString) .collect(Collectors.joining(",")); @@ -892,93 +907,97 @@ } /** - * @description 获取商户list - * @author jqs - * @date 2023/6/12 14:37 * @param mgtShopListDto - * @return List<MgtShopListSimpleVo> + * @return List<MgtShopListSimpleVo> + * @description 获取商户list + * @author jqs + * @date 2023/6/12 14:37 */ @Override - public List<MgtShopListSimpleVo> listMgtShopSimpleVo(MgtShopListDto mgtShopListDto){ + public List<MgtShopListSimpleVo> listMgtShopSimpleVo(MgtShopListDto mgtShopListDto) { return shopMapper.listMgtShopSimpleVo(mgtShopListDto); } /** - * @description 通过id获取商户列表 - * @author jqs - * @date 2023/6/14 17:53 * @param shopIds - * @return List<MgtShopListSimpleVo> + * @return List<MgtShopListSimpleVo> + * @description 通过id获取商户列表 + * @author jqs + * @date 2023/6/14 17:53 */ @Override - public List<MgtSimpleShopVo> listShopSimpleVoByIds(String shopIds){ + public List<MgtSimpleShopVo> listShopSimpleVoByIds(String shopIds) { return shopMapper.listShopSimpleVoByIds(shopIds); } /** - * @description pageMgtShopByCityCode * @param page * @param mgtShopByCodePageDto * @return List<MgtSimpleShopVo> + * @description pageMgtShopByCityCode * @author jqs34 * @date 2023/6/14 20:56 */ @Override - public List<MgtSimpleShopVo> pageMgtShopByCityCode(Page page, MgtShopByCodePageDto mgtShopByCodePageDto){ + public List<MgtSimpleShopVo> pageMgtShopByCityCode(Page page, MgtShopByCodePageDto mgtShopByCodePageDto) { return shopMapper.pageMgtShopByCityCode(page, mgtShopByCodePageDto); } /** - * @description pageMgtShopAuth * @param page * @param mgtShopAuthPageDto * @return List<MgtShopAuthPageVo> + * @description pageMgtShopAuth * @author jqs34 * @date 2023/6/14 23:01 */ @Override - public List<MgtShopAuthPageVo> pageMgtShopAuth(Page page, MgtShopAuthPageDto mgtShopAuthPageDto){ + public List<MgtShopAuthPageVo> pageMgtShopAuth(Page page, MgtShopAuthPageDto mgtShopAuthPageDto) { return shopMapper.pageMgtShopAuth(page, mgtShopAuthPageDto); } /** - * @description boardShopTotal * @param * @return MgtBulletinBoardVo + * @description boardShopTotal * @author jqs34 * @date 2023/6/18 16:59 */ @Override - public MgtBulletinBoardVo boardShopTotal(){ + public MgtBulletinBoardVo boardShopTotal() { MgtBulletinBoardVo mgtBulletinBoardVoShop = shopMapper.shopTotal(); return mgtBulletinBoardVoShop; } /** - * @description 商户进件 - * @author jqs - * @date 2023/6/19 11:02 * @param mgtShopAuthDto - * @return void + * @return void + * @description 商户进件 + * @author jqs + * @date 2023/6/19 11:02 */ @Override public void mgtShopAuth(MgtShopAuthDto mgtShopAuthDto) throws WxPayException { ShopAuthentication shopAuthentication = shopAuthenticationService.getById(mgtShopAuthDto.getAuthId()); Shop shop = this.getByShopId(shopAuthentication.getShopId()); String applyNumber = IdUtils.simpleUUID(); - BeanUtils.copyProperties(mgtShopAuthDto , shopAuthentication); + BeanUtils.copyProperties(mgtShopAuthDto, shopAuthentication); shopAuthentication.setApplyNumber(applyNumber); - shopAuthentication.setAuditStatus(3); + // 提交申请 -> 资料校验中 + shopAuthentication.setAuditStatus(1); + + ApplymentsResult result = wechatPayUtils.ecommerceApply(shopAuthentication, applyNumber, shop); + // 微信支付申请单号 + shopAuthentication.setApplymentId(result.getApplymentId()); shopAuthenticationService.saveOrUpdate(shopAuthentication); - wechatPayUtils.ecommerceApply(shopAuthentication,applyNumber,shop); } /** - * @description 获取平台商户统计 - * @author jqs - * @date 2023/6/21 16:25 * @param mgtBasePlatformDto - * @return MgtPlTotalShopTotalVo + * @return MgtPlTotalShopTotalVo + * @description 获取平台商户统计 + * @author jqs + * @date 2023/6/21 16:25 */ @Override public MgtPlTotalShopTotalVo getPlTotalShopTotal(MgtBasePlatformDto mgtBasePlatformDto) { @@ -1049,15 +1068,15 @@ } /** - * @description 去除空字符串 - * @author jqs - * @date 2023/6/27 17:35 * @param MgtMapIntTotalVos - * @return List<MgtMapIntTotalVo> + * @return List<MgtMapIntTotalVo> + * @description 去除空字符串 + * @author jqs + * @date 2023/6/27 17:35 */ - private List<MgtMapIntTotalVo> listRemoveNull(List<MgtMapIntTotalVo> MgtMapIntTotalVos){ + private List<MgtMapIntTotalVo> listRemoveNull(List<MgtMapIntTotalVo> MgtMapIntTotalVos) { for (int i = 0; i < MgtMapIntTotalVos.size(); i++) { - if(StringUtils.isBlank(MgtMapIntTotalVos.get(i).getMapKey())){ + if (StringUtils.isBlank(MgtMapIntTotalVos.get(i).getMapKey())) { MgtMapIntTotalVos.remove(i); } } @@ -1065,28 +1084,28 @@ } /** - * @description 获取平台统计shopId * @param mgtBasePlatformDto * @return List<Long> + * @description 获取平台统计shopId * @author jqs34 * @date 2023/6/23 14:12 */ @Override - public List<Long> listShopIdByPlTotal(MgtBasePlatformDto mgtBasePlatformDto){ + public List<Long> listShopIdByPlTotal(MgtBasePlatformDto mgtBasePlatformDto) { List<Long> shopIdList = shopMapper.listShopIdByPlTotal(mgtBasePlatformDto); return shopIdList; } /** - * @description 获取商户审核资料 - * @author jqs - * @date 2023/6/25 10:37 * @param authId - * @return MgtShopAuthGetVo + * @return MgtShopAuthGetVo + * @description 获取商户审核资料 + * @author jqs + * @date 2023/6/25 10:37 */ @Override - public MgtShopAuthGetVo getMgtShopAuth(String authId){ + public MgtShopAuthGetVo getMgtShopAuth(String authId) { MgtShopAuthGetVo shopAuthGetVo = new MgtShopAuthGetVo(); ShopAuthentication shopAuthentication = shopAuthenticationService.getById(authId); BeanUtils.copyProperties(shopAuthentication, shopAuthGetVo); @@ -1094,14 +1113,14 @@ } /** - * @description 获取商户验证信息 - * @author jqs - * @date 2023/6/26 10:38 * @param authId - * @return MgtShopAuthCodeVo + * @return MgtShopAuthCodeVo + * @description 获取商户验证信息 + * @author jqs + * @date 2023/6/26 10:38 */ @Override - public MgtShopAuthCodeVo getMgtShopAuthCode(String authId){ + public MgtShopAuthCodeVo getMgtShopAuthCode(String authId) { MgtShopAuthCodeVo mgtShopAuthCodeVo = new MgtShopAuthCodeVo(); ShopAuthentication shopAuthentication = shopAuthenticationService.getById(authId); mgtShopAuthCodeVo.setSignUrl(shopAuthentication.getSignUrl()); @@ -1111,14 +1130,14 @@ /** - * @description 获取商户下属代理商 - * @author jqs - * @date 2023/7/3 17:27 * @param shopId - * @return List<Long> + * @return List<Long> + * @description 获取商户下属代理商 + * @author jqs + * @date 2023/7/3 17:27 */ @Override - public List<Long> listShopIdByShopId(Long shopId){ + public List<Long> listShopIdByShopId(Long shopId) { List<Long> shopIds = shopMapper.selectList( new LambdaQueryWrapper<Shop>().eq(Shop::getDelFlag, 0).eq(Shop::getBelongShopId, shopId) ).stream().map(Shop::getShopId).collect(Collectors.toList()); @@ -1126,17 +1145,17 @@ } /** - * @description 获取商户下属代理商 - * @author jqs - * @date 2023/7/3 18:18 * @param shopId - * @return List<MgtSimpleShopVo> + * @return List<MgtSimpleShopVo> + * @description 获取商户下属代理商 + * @author jqs + * @date 2023/7/3 18:18 */ @Override - public List<MgtSimpleShopVo> listShopByShop(Long shopId){ + public List<MgtSimpleShopVo> listShopByShop(Long shopId) { List<MgtSimpleShopVo> simpleShopVoList = shopMapper.selectList( - new LambdaQueryWrapper<Shop>().eq(Shop::getDelFlag, 0).eq(Shop::getBelongShopId, shopId)). - stream().map(shop->{ + new LambdaQueryWrapper<Shop>().eq(Shop::getDelFlag, 0).eq(Shop::getBelongShopId, shopId)). + stream().map(shop -> { MgtSimpleShopVo simpleShopVo = new MgtSimpleShopVo(); simpleShopVo.setShopId(shop.getShopId()); simpleShopVo.setShopName(shop.getShopName()); @@ -1146,59 +1165,59 @@ } /** - * @description 获取用户管理商户 - * @author jqs - * @date 2023/7/14 10:00 * @param userId - * @return Shop + * @return Shop + * @description 获取用户管理商户 + * @author jqs + * @date 2023/7/14 10:00 */ @Override - public Shop getShopByBelongUserId(Long userId){ + public Shop getShopByBelongUserId(Long userId) { LambdaQueryWrapper<Shop> queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(Shop::getDelFlag,0); - queryWrapper.eq(Shop::getBelongUserId,userId); - return this.getOne(queryWrapper,false); + queryWrapper.eq(Shop::getDelFlag, 0); + queryWrapper.eq(Shop::getBelongUserId, userId); + return this.getOne(queryWrapper, false); } /** - * @description 员工端获取商户列表 - * @author jqs - * @date 2023/7/14 15:26 * @param page * @param staffShopPageDto - * @return List<StaffShopPageVo> + * @return List<StaffShopPageVo> + * @description 员工端获取商户列表 + * @author jqs + * @date 2023/7/14 15:26 */ @Override - public List<StaffShopPageVo> pageStaffShop(Page page, StaffShopPageDto staffShopPageDto){ + public List<StaffShopPageVo> pageStaffShop(Page page, StaffShopPageDto staffShopPageDto) { List<StaffShopPageVo> staffShopPageVoList = shopMapper.pageStaffShop(page, staffShopPageDto); return staffShopPageVoList; } /** - * @description 获取员工端商户数量统计 - * @author jqs - * @date 2023/7/14 15:51 * @param userId - * @return StaffShopSimpleTotalVo + * @return StaffShopSimpleTotalVo + * @description 获取员工端商户数量统计 + * @author jqs + * @date 2023/7/14 15:51 */ @Override - public StaffShopSimpleTotalVo getStaffSimpleTotal(Long userId){ + public StaffShopSimpleTotalVo getStaffSimpleTotal(Long userId) { List<Long> userIdList = null; - if(remoteSysStaffService.isLeader()){ + if (remoteSysStaffService.isLeader()) { userIdList = sysUserService.getUserIdsByDept(userId).getData(); userIdList.add(userId); - }else { + } else { userIdList.add(userId); } return shopMapper.getStaffSimpleTotal(userIdList); } /** - * @description 员工端获取商户详情 - * @author jqs - * @date 2023/7/14 18:32 * @param shopId - * @return StaffShopInfoGetVo + * @return StaffShopInfoGetVo + * @description 员工端获取商户详情 + * @author jqs + * @date 2023/7/14 18:32 */ @Override public StaffShopInfoGetVo getStaffShopInfo(Long shopId) { @@ -1277,14 +1296,14 @@ } /** - * @description 修改商户评估 - * @author jqs - * @date 2023/7/15 10:18 * @param staffShopEstimateEditDto - * @return void + * @return void + * @description 修改商户评估 + * @author jqs + * @date 2023/7/15 10:18 */ @Override - public void editShopEstimate(StaffShopEstimateEditDto staffShopEstimateEditDto){ + public void editShopEstimate(StaffShopEstimateEditDto staffShopEstimateEditDto) { Shop shop = new Shop(); shop.setShopId(staffShopEstimateEditDto.getShopId()); shop.setSupportingCapacityFlag(staffShopEstimateEditDto.getSupportingCapacityFlag()); @@ -1301,18 +1320,18 @@ } /** - * @description 修改店铺扩展联系人 - * @author jqs - * @date 2023/7/15 11:06 * @param staffShopECEditDto - * @return void + * @return void + * @description 修改店铺扩展联系人 + * @author jqs + * @date 2023/7/15 11:06 */ @Override - public void editExtendContacts(StaffShopECEditDto staffShopECEditDto){ + public void editExtendContacts(StaffShopECEditDto staffShopECEditDto) { Shop shop = new Shop(); String extendContacts = null; List<ExtendContactsVo> extendContactsVoList = staffShopECEditDto.getExtendContactsVoList(); - if(extendContactsVoList!=null&&!extendContactsVoList.isEmpty()){ + if (extendContactsVoList != null && !extendContactsVoList.isEmpty()) { extendContacts = JSON.toJSONString(extendContactsVoList); } shop.setExtendContacts(extendContacts); @@ -1323,14 +1342,14 @@ } /** - * @description 修改店铺状态 - * @author jqs - * @date 2023/7/15 11:51 * @param staffShopCCEditDto - * @return void + * @return void + * @description 修改店铺状态 + * @author jqs + * @date 2023/7/15 11:51 */ @Override - public void editShopCustomStatus(StaffShopCCEditDto staffShopCCEditDto){ + public void editShopCustomStatus(StaffShopCCEditDto staffShopCCEditDto) { Shop shop = new Shop(); shop.setShopCustomStatus(staffShopCCEditDto.getShopCustomStatus()); shop.setShopId(staffShopCCEditDto.getShopId()); @@ -1338,4 +1357,44 @@ shop.setUpdateTime(new Date()); shopMapper.updateShop(shop); } + + @Override + public void queryEcommerceApplyMentsStatus() { + List<ShopAuthentication> list = shopAuthenticationService.getShopAuthNeedUpdateStatus(); + list.forEach(item -> queryApplyStatusByApplymentId(item.getApplymentId(), item.getShopId())); + } + + /** + * 调用微信接口查询申请审核状态 + * @param applymentId + */ + private void queryApplyStatusByApplymentId(String applymentId, Long shopId) { + try { + if (StringUtils.isNotBlank(applymentId)) { + ApplymentsStatusResult result = wechatPayUtils.queryApplyStatusByApplymentId(applymentId); + shopAuthenticationService.updateAuditStatusByApplymentId(applymentId, result); + String applymentState = result.getApplymentState(); + if(WxApplyMentStateEnum.FINISH.getText().equals(applymentState)){ + applySuccessUpdateShopStatus(shopId); + } + } + } catch (WxPayException e) { + e.printStackTrace(); + } + } + + /** + * 商户进件审核完成,更新商户状态 + * @param shopId + */ + private void applySuccessUpdateShopStatus(Long shopId){ + // 更新商户状态为正常 + Shop shop = this.getById(shopId); + Integer shopStatus = handelShopStatus(shop.getFrozenFlag(), shop.getCooperativeFlag(), 1); + LambdaUpdateWrapper<Shop> updateWrapper = Wrappers.lambdaUpdate(); + updateWrapper.eq(Shop::getShopId, shopId) + .set(Shop::getShopStatus, shopStatus) + .set(Shop::getAuthFlag, 1); + this.update(updateWrapper); + } } diff --git a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/shop/ShopAuthenticationService.java b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/shop/ShopAuthenticationService.java index 1aab902..1f10652 100644 --- a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/shop/ShopAuthenticationService.java +++ b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/shop/ShopAuthenticationService.java @@ -1,7 +1,10 @@ package com.ruoyi.shop.service.shop; +import com.github.binarywang.wxpay.bean.ecommerce.ApplymentsStatusResult; import com.ruoyi.shop.domain.pojo.shop.ShopAuthentication; import com.baomidou.mybatisplus.extension.service.IService; + +import java.util.List; /** * <p> @@ -13,4 +16,23 @@ */ public interface ShopAuthenticationService extends IService<ShopAuthentication> { + /** + * 获取需要更新状态的 微信二级商户认证审核 + * @return + */ + List<ShopAuthentication> getShopAuthNeedUpdateStatus(); + + /** + * 修改微信审核状态 + * @param applymentId + * @param result + */ + void updateAuditStatusByApplymentId(String applymentId, ApplymentsStatusResult result); + + /** + * 获取商户认证信息 + * @param shopId + * @return + */ + ShopAuthentication getByShopId(Long shopId); } diff --git a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/shop/ShopProportionService.java b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/shop/ShopProportionService.java index af99606..1f4b6c4 100644 --- a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/shop/ShopProportionService.java +++ b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/shop/ShopProportionService.java @@ -22,4 +22,11 @@ * @return void */ void editMgtShopProportion(MgtShopProportionEditDto mgtShopProportionEditDto); + + /** + * 获取商户分成比例 + * @param shopId + * @return + */ + ShopProportion getByShopId(Long shopId); } diff --git a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/shop/ShopService.java b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/shop/ShopService.java index 5a664f1..b84fce1 100644 --- a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/shop/ShopService.java +++ b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/shop/ShopService.java @@ -327,4 +327,9 @@ * @return void */ void editShopCustomStatus(StaffShopCCEditDto staffShopCCEditDto); + + /** + * 微信二级商户进件状态 定时任务检测 + */ + void queryEcommerceApplyMentsStatus(); } diff --git a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/util/WechatPayUtils.java b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/util/WechatPayUtils.java index 39a768f..14eae48 100644 --- a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/util/WechatPayUtils.java +++ b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/util/WechatPayUtils.java @@ -20,12 +20,13 @@ @Component @AllArgsConstructor public class WechatPayUtils { + private final WxPayService wxService; /** * 电商二级商户进件(提交申请单) */ - public void ecommerceApply(ShopAuthentication shopAuthentication, String applyNumber, Shop shop) throws WxPayException { + public ApplymentsResult ecommerceApply(ShopAuthentication shopAuthentication, String applyNumber, Shop shop) throws WxPayException { EcommerceService ecommerceService = wxService.getEcommerceService(); ApplymentsRequest request = new ApplymentsRequest(); //生成提交类 @@ -105,18 +106,18 @@ request.setBusinessAdditionPics(shopAuthentication.getBaPics()); request.setBusinessAdditionDesc(shopAuthentication.getBaDesc()); - ApplymentsResult result = ecommerceService.createApply(request); + return ecommerceService.createApply(request); } /** * 通过查询申请状态API查询二级商户入驻申请结果 - * @param applyNumber 业务申请编号 + * @param applymentId 微信支付申请单号 * @return 申请状态 * @throws WxPayException */ - public ApplymentsStatusResult queryApplyStatusByOutRequestNo(String applyNumber) throws WxPayException { - return wxService.getEcommerceService().queryApplyStatusByOutRequestNo(applyNumber); + public ApplymentsStatusResult queryApplyStatusByApplymentId(String applymentId) throws WxPayException { + return wxService.getEcommerceService().queryApplyStatusByApplymentId(applymentId); } } -- Gitblit v1.7.1