From f8faaaad55eda85939134778a0b48085b5dcd6c3 Mon Sep 17 00:00:00 2001 From: xhxu Date: Tue, 27 Apr 2021 18:41:18 +0800 Subject: [PATCH] businessCircle --- .../controller/callback/AliPayController.java | 71 ++- .../UserThirdCircleOrderController.java | 458 ++++++++-------- .../config/BaseMyBatisConfiguration.java | 16 +- .../domain/po/BusinessCircleBase.java | 29 +- .../mapper/AliBusinessCircleOrderMapper.java | 37 ++ .../mapper/WxThirdPartyOrdersMapper.java | 14 +- .../AliBusinessCircleOrderService.java | 47 ++ .../service/WxThirdPartyOrdersService.java | 20 +- .../AliBusinessCircleOrderServiceImpl.java | 218 ++++++++ .../WxBusinessCircleOrderServiceImpl.java | 28 +- .../service/impl/WxCouponServiceImpl.java | 4 +- .../impl/WxThirdPartyOrdersServiceImpl.java | 505 ++++++++++-------- .../mapper/AliBusinessCircleMapper.xml | 203 +++++++ .../mapper/AliBusinessCircleOrder.xml | 183 +++++++ .../mapper/WxThirdPartyOrdersMapper.xml | 100 ++-- 15 files changed, 1368 insertions(+), 565 deletions(-) create mode 100644 mallinkService/src/main/java/com/iformall/mapper/AliBusinessCircleOrderMapper.java create mode 100644 mallinkService/src/main/java/com/iformall/service/AliBusinessCircleOrderService.java create mode 100644 mallinkService/src/main/java/com/iformall/service/impl/AliBusinessCircleOrderServiceImpl.java create mode 100644 mallinkService/src/main/resources/mapper/AliBusinessCircleMapper.xml create mode 100644 mallinkService/src/main/resources/mapper/AliBusinessCircleOrder.xml diff --git a/mallinkCallback/src/main/java/com/iformall/controller/callback/AliPayController.java b/mallinkCallback/src/main/java/com/iformall/controller/callback/AliPayController.java index 6c361b452..acab89be2 100644 --- a/mallinkCallback/src/main/java/com/iformall/controller/callback/AliPayController.java +++ b/mallinkCallback/src/main/java/com/iformall/controller/callback/AliPayController.java @@ -3,10 +3,8 @@ package com.iformall.controller.callback; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.iformall.controller.base.BaseController; -import com.iformall.domain.po.AliPayCUser; -import com.iformall.domain.po.WxMall; -import com.iformall.service.AliPayCUserService; -import com.iformall.service.WxMallService; +import com.iformall.domain.po.*; +import com.iformall.service.*; import com.iformall.service.pay.alipay.AliPayUtil; import com.iformall.service.pay.alipay.api.enums.EnumMemberCardConfig; import com.iformall.service.pay.alipay.api.result.UserAuthData; @@ -26,6 +24,10 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; import java.util.Map; @RestController @@ -34,14 +36,23 @@ public class AliPayController extends BaseController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); + private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + @Autowired private AliPayUtil alipayUtil; + + @Autowired + private WxMerchantService wxMerchantService; @Autowired private WxMallService mallService; @Autowired private AliPayCUserService aliPayCUserService; + + @Autowired + AliBusinessCircleOrderService aliBusinessCircleOrderService; private void writeResponse(HttpServletResponse response,String msg) { PrintWriter out; @@ -209,13 +220,35 @@ public class AliPayController extends BaseController { logger.error("alipay notify notify error. bizContent empity:"+paramMap); }else { JSONObject jo = JSON.parseObject(bizContent); - String gmtPayment = jo.getString("gmt_payment"); - String totalAmount = jo.getString("total_amount");//交易总金额 + String gmtPayment = jo.getString("gmt_payment");//付款时间 + Date endTime = sdf.parse(gmtPayment); + String totalAmount = jo.getString("total_amount");//交易总金额 + int amount = new BigDecimal(totalAmount).multiply(new BigDecimal(100)).intValue(); String receiptAmount = jo.getString("receipt_amount");//商家实收金额 + int payAmount =new BigDecimal(receiptAmount).multiply(new BigDecimal(100)).intValue(); String mallStoreId = jo.getString("mall_store_id"); String buyerId = jo.getString("buyer_id"); - String tradeNo = jo.getString("trade_no"); - } + String tradeNo = jo.getString("trade_no"); + + String mallId = jo.getString("mall_id"); + String mallName = jo.getString("mall_name"); + + WxMerchant merchant = wxMerchantService.getById(Long.parseLong(mallStoreId)); + if(merchant == null){return;} + AliBusinessCircleOrder aliBusinessCircleOrder = new AliBusinessCircleOrder(); + aliBusinessCircleOrder.updateTenantInfo(merchant); + aliBusinessCircleOrder.setTransactionId(tradeNo); + aliBusinessCircleOrder.setAmount(amount); + aliBusinessCircleOrder.setPayAmount(payAmount); + aliBusinessCircleOrder.setTimeEnd(endTime); + aliBusinessCircleOrder.setBuyerId(buyerId); + + aliBusinessCircleOrder.setMallId(mallId); + aliBusinessCircleOrder.setMallName(mallName); + + aliBusinessCircleOrderService.createOrder(aliBusinessCircleOrder); + + } //退款成功 }else if ("alipay.business.mall.trade.refunded".equals(msgMethod)) { String bizContent = (String) paramMap.get("biz_content"); @@ -224,10 +257,30 @@ public class AliPayController extends BaseController { }else { JSONObject jo = JSON.parseObject(bizContent); String gmtRefundPay = jo.getString("gmt_refund_pay");//退款时间 + Date endTime = sdf.parse(gmtRefundPay); String refundFee = jo.getString("refund_fee");//本次退款金额 + int refundAmount = new BigDecimal(refundFee).multiply(new BigDecimal(100)).intValue(); String mallStoreId = jo.getString("mall_store_id"); String buyerId = jo.getString("buyer_id"); - String tradeNo = jo.getString("trade_no"); + String tradeNo = jo.getString("trade_no"); + + String mallId = jo.getString("mall_id"); + String mallName = jo.getString("mall_name"); + + WxMerchant merchant = wxMerchantService.getById(Long.parseLong(mallStoreId)); + if(merchant == null){return;} + AliBusinessCircleOrder aliBusinessCircleOrder = new AliBusinessCircleOrder(); + aliBusinessCircleOrder.updateTenantInfo(merchant); + aliBusinessCircleOrder.setTransactionId(tradeNo); + aliBusinessCircleOrder.setRefundAmount(refundAmount); + aliBusinessCircleOrder.setTimeEnd(endTime); + aliBusinessCircleOrder.setBuyerId(buyerId); + + aliBusinessCircleOrder.setMallId(mallId); + aliBusinessCircleOrder.setMallName(mallName); + + aliBusinessCircleOrderService.insertRefundNoticeOrder(aliBusinessCircleOrder); + } } } diff --git a/mallinkPublicApi/src/main/java/com/iformall/controller/UserThirdCircleOrderController.java b/mallinkPublicApi/src/main/java/com/iformall/controller/UserThirdCircleOrderController.java index 0210ddf5e..31a7eb6a1 100644 --- a/mallinkPublicApi/src/main/java/com/iformall/controller/UserThirdCircleOrderController.java +++ b/mallinkPublicApi/src/main/java/com/iformall/controller/UserThirdCircleOrderController.java @@ -1,229 +1,229 @@ -//package com.iformall.controller; -// -//import com.iformall.common.ErrorCode; -//import com.iformall.common.ResultData; -//import com.iformall.domain.po.WxThirdPartyOrders; -//import com.iformall.enums.EnumThirdOrderType; -//import com.iformall.exception.MallinkException; -//import com.iformall.service.WxThirdPartyOrdersService; -//import io.swagger.annotations.Api; -//import io.swagger.annotations.ApiOperation; -//import org.apache.commons.lang3.StringUtils; -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.web.bind.annotation.PostMapping; -//import org.springframework.web.bind.annotation.RequestBody; -//import org.springframework.web.bind.annotation.RequestMapping; -//import org.springframework.web.bind.annotation.RestController; -// -//import java.text.ParseException; -//import java.text.SimpleDateFormat; -//import java.util.Date; -//import java.util.Map; -// -//@RestController -//@RequestMapping("api/thirdCircle") -//@Api(description = "会员交易相关接口") -//public class UserThirdCircleOrderController extends BaseController { -// -// private final Logger logger = LoggerFactory.getLogger(this.getClass()); -// -// private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); -// -// -// @Autowired -// WxThirdPartyOrdersService thirdPartyOrdersService; -// -// /** -// * -// * @param -// * @return -// */ -// @PostMapping("/order") -// @ApiOperation(value = "订单", notes = "") -// public ResultData createOrder(@RequestBody Map map) { -// logger.info("UserThirdCircleOrderController >>>>>>>>>>>> createOrder >>>>>>>>>>>>>"+map.toString()); -// -// String transactionId = (String) map.get("transactionId");//***订单Id -// Long shopNumber = (Long) map.get("shopNumber");//***门店唯一标识 对应双方平台门店 -// String shopName = (String) map.get("shopName");//门店名称 -// Long userNumber = (Long) map.get("userNumber");//***会员Id -// String userPhone = (String) map.get("userPhone");//会员手机号 -// String timeEnd = (String) map.get("timeEnd");//***付款时间(yyyy-MM-dd HH:mm:ss) -// Integer amount = (Integer) map.get("amount");//***付款金额(分) -// String summary = (String) map.get("summary");//付款摘要 -// -// if(StringUtils.isBlank(transactionId)){ -// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"transactionId为空"); -// } -// if(shopNumber == null){ -// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"shopNumber为空"); -// } -// if(userNumber == null){ -// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"userNumber为空"); -// } -// if(StringUtils.isNotBlank(userPhone) && !userPhone.matches("^1[0-9]{10}$")){ -// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"userPhone格式不正确"); -// } -// if(timeEnd == null){ -// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"timeEnd为空"); -// } -// Date timeEndDate = null; -// try { -// timeEndDate = sdf.parse(timeEnd); -// } catch (ParseException e) { -// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"timeEnd格式不正确"); -// } -// if(amount == null){ -// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"amount为空"); -// } -// -// WxThirdPartyOrders thirdPartyOrders = new WxThirdPartyOrders(); -// thirdPartyOrders.updateTenantInfo(getTenantInfo()); -// thirdPartyOrders.setSourceAppId(getAppId()); -// -// thirdPartyOrders.setTransactionId(transactionId); -// thirdPartyOrders.setShopNumber(String.valueOf(shopNumber)); -// thirdPartyOrders.setShopName(shopName); -// thirdPartyOrders.setUserNumber(String.valueOf(userNumber)); -// thirdPartyOrders.setUserPhone(userPhone); -// thirdPartyOrders.setTimeEnd(timeEndDate); -// thirdPartyOrders.setAmount(amount); -// thirdPartyOrders.setSummary(summary); -// try{ -// thirdPartyOrdersService.createOrder(thirdPartyOrders); -// }catch(MallinkException e){ -// logger.error(e.getMessage()); -// return new ResultData(e.getErrorCode(), e.getMessage()); -// }catch(Exception e){ -// e.printStackTrace(); -// return new ResultData(ErrorCode.SYS_SERVER_ERROR); -// } -// -// return new ResultData(); -// } -// -// /** -// * -// * @param -// * @return -// */ -// @PostMapping("/orderRefund") -// @ApiOperation(value = "退款", notes = "") -// public ResultData orderRefund(@RequestBody Map map) { -// logger.info("UserThirdCircleOrderController >>>>>>>>>>>> orderRefund >>>>>>>>>>>>>"+map.toString()); -// -// String transactionId = (String) map.get("transactionId");//***订单Id -// String refundTime = (String) map.get("refundTime");//***退款时间(yyyy-MM-dd HH:mm:ss) -// String refundSummary = (String) map.get("refundSummary");//退款摘要 -// Integer refundAmount = (Integer) map.get("refundAmount");//退款金额(分) -// String refundId = (String) map.get("refundId");//退款Id -// -// if(StringUtils.isBlank(transactionId)){ -// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"transactionId为空"); -// } -// if(refundTime == null){ -// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"refundTime为空"); -// } -// Date refundTimeDate = null; -// try { -// refundTimeDate = sdf.parse(refundTime); -// } catch (ParseException e) { -// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"timeEnd格式不正确"); -// } -// -// WxThirdPartyOrders thirdPartyOrders = new WxThirdPartyOrders(); -// thirdPartyOrders.updateTenantInfo(getTenantInfo()); -// thirdPartyOrders.setSourceAppId(getAppId()); -// thirdPartyOrders.setSourceType(EnumThirdOrderType.RMB_PAY.getCode()); -// -// thirdPartyOrders.setTransactionId(transactionId); -// thirdPartyOrders.setRefundTime(refundTimeDate); -// thirdPartyOrders.setRefundSummary(refundSummary); -// thirdPartyOrders.setRefundAmount(refundAmount); -// thirdPartyOrders.setRefundId(refundId); -// -// try{ -// thirdPartyOrdersService.updateRefundOrder(thirdPartyOrders); -// }catch(MallinkException e){ -// logger.error(e.getMessage()); -// return new ResultData(e.getErrorCode(), e.getMessage()); -// }catch(Exception e){ -// e.printStackTrace(); -// return new ResultData(ErrorCode.SYS_SERVER_ERROR); -// } -// -// return new ResultData(); -// } -// -// -// /** -// * -// * @param -// * @return -// */ -// @PostMapping("/pointDeduction") -// @ApiOperation(value = "积分抵扣", notes = "") -// public ResultData pointDeduction(@RequestBody Map map) { -// logger.info("UserThirdCircleOrderController >>>>>>>>>>>> pointDeduction >>>>>>>>>>>>>"+map.toString()); -// -// String transactionId = (String) map.get("transactionId");//***订单Id -// Long shopNumber = (Long) map.get("shopNumber");//***门店唯一标识 对应双方平台门店 -// String shopName = (String) map.get("shopName");//门店名称 -// Long userNumber = (Long) map.get("userNumber");//***会员Id -// String userPhone = (String) map.get("userPhone");//会员手机号 -// String timeEnd = (String) map.get("timeEnd");//***抵扣时间 -// Integer amount = (Integer) map.get("amount");//***积分数量 -// String summary = (String) map.get("summary");//付款摘要 -// -// if(StringUtils.isBlank(transactionId)){ -// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"transactionId为空"); -// } -// if(shopNumber == null){ -// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"shopNumber为空"); -// } -// if(userNumber == null){ -// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"userNumber为空"); -// } -// if(StringUtils.isNotBlank(userPhone) && !userPhone.matches("^1[0-9]{10}$")){ -// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"userPhone格式不正确"); -// } -// if(timeEnd == null){ -// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"timeEnd为空"); -// } -// Date timeEndDate = null; -// try { -// timeEndDate = sdf.parse(timeEnd); -// } catch (ParseException e) { -// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"timeEnd格式不正确"); -// } -// if(amount == null){ -// return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"amount为空"); -// } -// -// WxThirdPartyOrders thirdPartyOrders = new WxThirdPartyOrders(); -// thirdPartyOrders.updateTenantInfo(getTenantInfo()); -// thirdPartyOrders.setSourceAppId(getAppId()); -// -// thirdPartyOrders.setTransactionId(transactionId); -// thirdPartyOrders.setShopNumber(String.valueOf(shopNumber)); -// thirdPartyOrders.setShopName(shopName); -// thirdPartyOrders.setUserNumber(String.valueOf(userNumber)); -// thirdPartyOrders.setUserPhone(userPhone); -// thirdPartyOrders.setTimeEnd(timeEndDate); -// thirdPartyOrders.setAmount(amount); -// thirdPartyOrders.setSummary(summary); -// try{ -// thirdPartyOrdersService.pointDeduction(thirdPartyOrders); -// return new ResultData(); -// }catch(MallinkException e){ -// logger.error(e.getMessage()); -// return new ResultData(e.getErrorCode(), e.getMessage()); -// }catch(Exception e){ -// e.printStackTrace(); -// return new ResultData(ErrorCode.SYS_SERVER_ERROR); -// } -// } -// -//} +package com.iformall.controller; + +import com.iformall.common.ErrorCode; +import com.iformall.common.ResultData; +import com.iformall.domain.po.WxThirdPartyOrders; +import com.iformall.enums.EnumThirdOrderType; +import com.iformall.exception.MallinkException; +import com.iformall.service.WxThirdPartyOrdersService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Map; + +@RestController +@RequestMapping("api/thirdCircle") +@Api(description = "会员交易相关接口") +public class UserThirdCircleOrderController extends BaseController { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + + @Autowired + WxThirdPartyOrdersService thirdPartyOrdersService; + + /** + * + * @param + * @return + */ + @PostMapping("/order") + @ApiOperation(value = "订单", notes = "") + public ResultData createOrder(@RequestBody Map map) { + logger.info("UserThirdCircleOrderController >>>>>>>>>>>> createOrder >>>>>>>>>>>>>"+map.toString()); + + String transactionId = (String) map.get("transactionId");//***订单Id + Long shopNumber = (Long) map.get("shopNumber");//***门店唯一标识 对应双方平台门店 + String shopName = (String) map.get("shopName");//门店名称 + Long userNumber = (Long) map.get("userNumber");//***会员Id + String userPhone = (String) map.get("userPhone");//会员手机号 + String timeEnd = (String) map.get("timeEnd");//***付款时间(yyyy-MM-dd HH:mm:ss) + Integer amount = (Integer) map.get("amount");//***付款金额(分) + String summary = (String) map.get("summary");//付款摘要 + + if(StringUtils.isBlank(transactionId)){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"transactionId为空"); + } + if(shopNumber == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"shopNumber为空"); + } + if(userNumber == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"userNumber为空"); + } + if(StringUtils.isNotBlank(userPhone) && !userPhone.matches("^1[0-9]{10}$")){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"userPhone格式不正确"); + } + if(timeEnd == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"timeEnd为空"); + } + Date timeEndDate = null; + try { + timeEndDate = sdf.parse(timeEnd); + } catch (ParseException e) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"timeEnd格式不正确"); + } + if(amount == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"amount为空"); + } + + WxThirdPartyOrders thirdPartyOrders = new WxThirdPartyOrders(); + thirdPartyOrders.updateTenantInfo(getTenantInfo()); + thirdPartyOrders.setSourceAppId(getAppId()); + + thirdPartyOrders.setTransactionId(transactionId); + thirdPartyOrders.setShopNumber(String.valueOf(shopNumber)); + thirdPartyOrders.setShopName(shopName); + thirdPartyOrders.setUserNumber(String.valueOf(userNumber)); + thirdPartyOrders.setUserPhone(userPhone); + thirdPartyOrders.setTimeEnd(timeEndDate); + thirdPartyOrders.setAmount(amount); + thirdPartyOrders.setSummary(summary); + try{ + thirdPartyOrdersService.createOrder(thirdPartyOrders); + }catch(MallinkException e){ + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + }catch(Exception e){ + e.printStackTrace(); + return new ResultData(ErrorCode.SYS_SERVER_ERROR); + } + + return new ResultData(); + } + + /** + * + * @param + * @return + */ + @PostMapping("/orderRefund") + @ApiOperation(value = "退款", notes = "") + public ResultData orderRefund(@RequestBody Map map) { + logger.info("UserThirdCircleOrderController >>>>>>>>>>>> orderRefund >>>>>>>>>>>>>"+map.toString()); + + String transactionId = (String) map.get("transactionId");//***订单Id + String refundTime = (String) map.get("refundTime");//***退款时间(yyyy-MM-dd HH:mm:ss) + String refundSummary = (String) map.get("refundSummary");//退款摘要 + Integer refundAmount = (Integer) map.get("refundAmount");//退款金额(分) + String refundId = (String) map.get("refundId");//退款Id + + if(StringUtils.isBlank(transactionId)){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"transactionId为空"); + } + if(refundTime == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"refundTime为空"); + } + Date refundTimeDate = null; + try { + refundTimeDate = sdf.parse(refundTime); + } catch (ParseException e) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"timeEnd格式不正确"); + } + + WxThirdPartyOrders thirdPartyOrders = new WxThirdPartyOrders(); + thirdPartyOrders.updateTenantInfo(getTenantInfo()); + thirdPartyOrders.setSourceAppId(getAppId()); + thirdPartyOrders.setSourceType(EnumThirdOrderType.RMB_PAY.getCode()); + + thirdPartyOrders.setTransactionId(transactionId); + thirdPartyOrders.setEndTime(refundTimeDate); + thirdPartyOrders.setSummary(refundSummary); + thirdPartyOrders.setRefundAmount(refundAmount); + thirdPartyOrders.setRefundId(refundId); + + try{ + thirdPartyOrdersService.insertRefundNoticeOrder(thirdPartyOrders); + }catch(MallinkException e){ + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + }catch(Exception e){ + e.printStackTrace(); + return new ResultData(ErrorCode.SYS_SERVER_ERROR); + } + + return new ResultData(); + } + + + /** + * + * @param + * @return + */ + @PostMapping("/pointDeduction") + @ApiOperation(value = "积分抵扣", notes = "") + public ResultData pointDeduction(@RequestBody Map map) { + logger.info("UserThirdCircleOrderController >>>>>>>>>>>> pointDeduction >>>>>>>>>>>>>"+map.toString()); + + String transactionId = (String) map.get("transactionId");//***订单Id + Long shopNumber = (Long) map.get("shopNumber");//***门店唯一标识 对应双方平台门店 + String shopName = (String) map.get("shopName");//门店名称 + Long userNumber = (Long) map.get("userNumber");//***会员Id + String userPhone = (String) map.get("userPhone");//会员手机号 + String timeEnd = (String) map.get("timeEnd");//***抵扣时间 + Integer amount = (Integer) map.get("amount");//***积分数量 + String summary = (String) map.get("summary");//付款摘要 + + if(StringUtils.isBlank(transactionId)){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"transactionId为空"); + } + if(shopNumber == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"shopNumber为空"); + } + if(userNumber == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"userNumber为空"); + } + if(StringUtils.isNotBlank(userPhone) && !userPhone.matches("^1[0-9]{10}$")){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"userPhone格式不正确"); + } + if(timeEnd == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"timeEnd为空"); + } + Date timeEndDate = null; + try { + timeEndDate = sdf.parse(timeEnd); + } catch (ParseException e) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"timeEnd格式不正确"); + } + if(amount == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"amount为空"); + } + + WxThirdPartyOrders thirdPartyOrders = new WxThirdPartyOrders(); + thirdPartyOrders.updateTenantInfo(getTenantInfo()); + thirdPartyOrders.setSourceAppId(getAppId()); + + thirdPartyOrders.setTransactionId(transactionId); + thirdPartyOrders.setShopNumber(String.valueOf(shopNumber)); + thirdPartyOrders.setShopName(shopName); + thirdPartyOrders.setUserNumber(String.valueOf(userNumber)); + thirdPartyOrders.setUserPhone(userPhone); + thirdPartyOrders.setTimeEnd(timeEndDate); + thirdPartyOrders.setAmount(amount); + thirdPartyOrders.setSummary(summary); + try{ + thirdPartyOrdersService.pointDeduction(thirdPartyOrders); + return new ResultData(); + }catch(MallinkException e){ + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + }catch(Exception e){ + e.printStackTrace(); + return new ResultData(ErrorCode.SYS_SERVER_ERROR); + } + } + +} diff --git a/mallinkService/src/main/java/com/iformall/config/BaseMyBatisConfiguration.java b/mallinkService/src/main/java/com/iformall/config/BaseMyBatisConfiguration.java index 9fa287d0e..a370754da 100644 --- a/mallinkService/src/main/java/com/iformall/config/BaseMyBatisConfiguration.java +++ b/mallinkService/src/main/java/com/iformall/config/BaseMyBatisConfiguration.java @@ -103,7 +103,21 @@ public class BaseMyBatisConfiguration { wxBusinessCircleOrderSharding.setCount(100); wxBusinessCircleOrderSharding.setRule(EnumShardingRule.HASH.getCode()); shardingList.add(wxBusinessCircleOrderSharding); - + + ShardingSphere aliBusinessCircleOrderSharding = new ShardingSphere(); + aliBusinessCircleOrderSharding.setColumn("tenant_id"); + aliBusinessCircleOrderSharding.setTableName("ali_business_circle_order"); + aliBusinessCircleOrderSharding.setCount(100); + aliBusinessCircleOrderSharding.setRule(EnumShardingRule.HASH.getCode()); + shardingList.add(aliBusinessCircleOrderSharding); + + ShardingSphere wxThirdPartyOrdersSharding = new ShardingSphere(); + wxThirdPartyOrdersSharding.setColumn("tenant_id"); + wxThirdPartyOrdersSharding.setTableName("wx_third_party_orders"); + wxThirdPartyOrdersSharding.setCount(100); + wxThirdPartyOrdersSharding.setRule(EnumShardingRule.HASH.getCode()); + shardingList.add(wxThirdPartyOrdersSharding); + ShardingSphere wxOrderSharding = new ShardingSphere(); wxOrderSharding.setColumn("tenant_id"); wxOrderSharding.setTableName("wx_order"); diff --git a/mallinkService/src/main/java/com/iformall/domain/po/BusinessCircleBase.java b/mallinkService/src/main/java/com/iformall/domain/po/BusinessCircleBase.java index 8159b4055..9374264fa 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/BusinessCircleBase.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/BusinessCircleBase.java @@ -36,24 +36,6 @@ public class BusinessCircleBase extends TenantEntity { @io.swagger.annotations.ApiModelProperty(value="商圈支付结果通知回调摘要",name="summary") private String summary; - @io.swagger.annotations.ApiModelProperty(value="微信支付分配的商户号",name="wxMchid") - private String wxMchid; - - @io.swagger.annotations.ApiModelProperty(value="商圈商户名称",name="wxMerchantName") - private String wxMerchantName; - - @io.swagger.annotations.ApiModelProperty(value="门店名称,商圈在商圈小程序上圈店时填写的门店名称",name="wxShopName") - private String wxShopName; - - @io.swagger.annotations.ApiModelProperty(value="门店编号,商圈在商圈小程序上圈店时填写的门店编号,用于跟商圈自身已有的商户识别码对齐",name="wxShopNumber") - private String wxShopNumber; - - @io.swagger.annotations.ApiModelProperty(value="小程序appid",name="appid") - private String appid; - - @io.swagger.annotations.ApiModelProperty(value="openid",name="openid") - private String openid; - @io.swagger.annotations.ApiModelProperty(value="交易完成时间",name="timeEnd") private Date timeEnd; @@ -82,19 +64,16 @@ public class BusinessCircleBase extends TenantEntity { @io.swagger.annotations.ApiModelProperty(value="支付订单号",name="transactionId") private String transactionId; - @io.swagger.annotations.ApiModelProperty(value="手动提交积分标记,自动提交时无该字段,用于区分用户手动申请后推送的积分",name="commitTag") - private String commitTag; - @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createTime") private Date createTime; @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateTime") private Date updateTime; - @io.swagger.annotations.ApiModelProperty(value="门店Id,与wx_shop_number对齐",name="merchantId") + @io.swagger.annotations.ApiModelProperty(value="门店Id,与第三方对齐",name="merchantId") private Long merchantId; - @io.swagger.annotations.ApiModelProperty(value="c端会员id,与openid对齐",name="cUserId") + @io.swagger.annotations.ApiModelProperty(value="c端会员id,与第三方对齐",name="cUserId") private Long cUserId; @io.swagger.annotations.ApiModelProperty(value="是否获得积分(1:是,0:否)",name="earnPoints") @@ -106,10 +85,6 @@ public class BusinessCircleBase extends TenantEntity { @io.swagger.annotations.ApiModelProperty(value="积分更新时间(新增)",name="increasedPoints") private Date pointsUpdateTime; - @io.swagger.annotations.ApiModelProperty(value="是否积分同步(1:是,0:否)",name="isPointsNotify") - private Integer isPointsNotify; - - @io.swagger.annotations.ApiModelProperty(value="是否退款(1:是,0:否)",name="isRefund") private Integer isRefund; diff --git a/mallinkService/src/main/java/com/iformall/mapper/AliBusinessCircleOrderMapper.java b/mallinkService/src/main/java/com/iformall/mapper/AliBusinessCircleOrderMapper.java new file mode 100644 index 000000000..a5959ef23 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/mapper/AliBusinessCircleOrderMapper.java @@ -0,0 +1,37 @@ +package com.iformall.mapper; + + +import com.iformall.common.CommonMapper; +import com.iformall.domain.po.AliBusinessCircleOrder; + +import java.util.List; + + +public interface AliBusinessCircleOrderMapper extends CommonMapper { + + List findList(AliBusinessCircleOrder record); + + AliBusinessCircleOrder getById(AliBusinessCircleOrder record); + + AliBusinessCircleOrder getOrderByTransactionId(AliBusinessCircleOrder record); + List getRefundOrderByTransactionId(AliBusinessCircleOrder record); + + /** + * 成功通知新建 + * @param record + */ + void insertNoticeOrder(AliBusinessCircleOrder record); + + /** + * 加积分 + * @param record + */ + void updatePoints(AliBusinessCircleOrder record); + + /** + * 退款 + * @param record + */ + void insertRefundNoticeOrder(AliBusinessCircleOrder record); + +} diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxThirdPartyOrdersMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxThirdPartyOrdersMapper.java index df97e0450..08aa80f92 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxThirdPartyOrdersMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxThirdPartyOrdersMapper.java @@ -13,7 +13,8 @@ public interface WxThirdPartyOrdersMapper extends CommonMapper getRefundOrderByTransactionId(WxThirdPartyOrders record); /** * 成功通知新建 @@ -25,19 +26,12 @@ public interface WxThirdPartyOrdersMapper extends CommonMapper listAsPage(AliBusinessCircleOrder record, Integer pageIndex, Integer pageSize); + + /** + * id+tenantId + * @param + * @return + */ + AliBusinessCircleOrder getById(Long id, String tenantId); + + /** + * transactionId+tenantId + * @param + * @return + */ + AliBusinessCircleOrder getOrderByTransactionId(String transactionId, String tenantId); + List getRefundOrderByTransactionId(String transactionId, String tenantId); + + + void createOrder(AliBusinessCircleOrder record); + + void insertRefundNoticeOrder(AliBusinessCircleOrder record); + + /** + * 积分 + * @param record + */ + void updatePoints(AliBusinessCircleOrder record); + +} diff --git a/mallinkService/src/main/java/com/iformall/service/WxThirdPartyOrdersService.java b/mallinkService/src/main/java/com/iformall/service/WxThirdPartyOrdersService.java index 8cced583d..fe480c02c 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxThirdPartyOrdersService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxThirdPartyOrdersService.java @@ -1,7 +1,11 @@ package com.iformall.service; import com.github.pagehelper.PageInfo; +import com.iformall.domain.po.WxBusinessCircleOrder; import com.iformall.domain.po.WxThirdPartyOrders; +import com.iformall.enums.EnumThirdOrderType; + +import java.util.List; public interface WxThirdPartyOrdersService { @@ -28,23 +32,19 @@ public interface WxThirdPartyOrdersService { * @param * @return */ - WxThirdPartyOrders getByTransactionId(String transactionId, String tenantId); + WxThirdPartyOrders getOrderByTransactionId(EnumThirdOrderType orderType, String transactionId, String tenantId); + List getRefundOrderByTransactionId(EnumThirdOrderType orderType, String transactionId, String tenantId); - void createOrder(WxThirdPartyOrders record); - void updateRefundOrder(WxThirdPartyOrders record); + void createOrder(WxThirdPartyOrders record); - /** - * 加积分 - * @param record - */ - void updateAddPoints(WxThirdPartyOrders record); + void insertRefundNoticeOrder(WxThirdPartyOrders record); /** - * 退积分 + * 积分 * @param record */ - void updateRefundPoints(WxThirdPartyOrders record); + void updatePoints(WxThirdPartyOrders record); /** * 积分抵扣 diff --git a/mallinkService/src/main/java/com/iformall/service/impl/AliBusinessCircleOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/AliBusinessCircleOrderServiceImpl.java new file mode 100644 index 000000000..7ed4114d9 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/impl/AliBusinessCircleOrderServiceImpl.java @@ -0,0 +1,218 @@ +package com.iformall.service.impl; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.iformall.common.IdWorker; +import com.iformall.domain.po.*; +import com.iformall.enums.EnumBusiness; +import com.iformall.enums.EnumScoreType; +import com.iformall.enums.EnumUserType; +import com.iformall.enums.EnumYesOrNo; +import com.iformall.mapper.AliBusinessCircleOrderMapper; +import com.iformall.service.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; + +@Service +public class AliBusinessCircleOrderServiceImpl implements AliBusinessCircleOrderService { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + AliBusinessCircleOrderMapper aliBusinessCircleOrderMapper; + + @Autowired + WxMerchantService wxMerchantService; + + @Autowired + AliPayCUserService aliPayCUserService; + + @Autowired + WxCUserBasicInfoService wxCUserBasicInfoService; + + @Autowired + WxCreditHistoryService creditHistoryService; + + + @Override + public PageInfo listAsPage(AliBusinessCircleOrder record, Integer pageIndex, Integer pageSize) { + return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> aliBusinessCircleOrderMapper.findList(record)); + } + + @Override + public AliBusinessCircleOrder getById(Long id, String tenantId) { + AliBusinessCircleOrder recordQ = new AliBusinessCircleOrder(); + recordQ.setId(id); + recordQ.setTenantId(tenantId); + return aliBusinessCircleOrderMapper.getById(recordQ); + } + + @Override + public AliBusinessCircleOrder getOrderByTransactionId(String transactionId, String tenantId) { + AliBusinessCircleOrder recordQ = new AliBusinessCircleOrder(); + recordQ.setTransactionId(transactionId); + recordQ.setTenantId(tenantId); + return aliBusinessCircleOrderMapper.getOrderByTransactionId(recordQ); + } + + @Override + public List getRefundOrderByTransactionId(String transactionId, String tenantId) { + AliBusinessCircleOrder recordQ = new AliBusinessCircleOrder(); + recordQ.setTransactionId(transactionId); + recordQ.setTenantId(tenantId); + return aliBusinessCircleOrderMapper.getRefundOrderByTransactionId(recordQ); + } + + @Override + public void createOrder(AliBusinessCircleOrder record) { + AliBusinessCircleOrder byTransactionId = this.getOrderByTransactionId(record.getTransactionId(),record.getTenantId()); + if(byTransactionId != null){ + logger.error("--Ali商圈付款--订单消息已存在---byTransactionId="+byTransactionId.getTransactionId()); + }else{ + Date now = new Date(); + final IdWorker idWorker = IdWorker.get(); + record.setId(idWorker.nextId()); + record.setCreateTime(now); + record.setUpdateTime(now); + + //TODO 第三方获取门店(标识可能发生变化) + WxMerchant wxMerchant = wxMerchantService.getById(Long.parseLong(record.getMallStoreId())); + if(wxMerchant != null){ + record.setMerchantId(wxMerchant.getId()); + }else{ + logger.error("--Ali商圈付款通知消息未找到门店--mallStoreId="+record.getMallStoreId()); + } + AliPayCUser userQ = new AliPayCUser(); + userQ.updateTenantInfo(record); + userQ.setId(Long.parseLong(record.getBuyerId())); + AliPayCUser aliUser = aliPayCUserService.getByAliPayUserId(userQ); + WxCUserBasicInfo infoByPhone = wxCUserBasicInfoService.findInfoByPhone(aliUser, aliUser.getPhone()); + + if(infoByPhone != null ){ + record.setCUserId(infoByPhone.getId()); + }else{ + logger.error("--Ali商圈付款通知消息未找到会员--aliUserId="+record.getBuyerId()); + } + aliBusinessCircleOrderMapper.insertNoticeOrder(record); + + if(record.getCUserId() == null){ + return; + } + Integer businessId = EnumBusiness.BUSINESS_ID6.getCode(); + if(wxMerchant != null){ + businessId = wxMerchant.getBusinessId(); + } + WxCreditHistory creditHistory = new WxCreditHistory(); + creditHistory.setTenantId(record.getFinalTenantId()); + creditHistory.setOperatorType(EnumUserType.ALI_CIRCLE.getCode()); + creditHistory.setOperatorId(record.getCUserId()); + creditHistory.setCUserId(record.getCUserId()); + creditHistory.setCreateDate(now); + creditHistory.setCouponId(record.getId()); + creditHistory.setBusinessId(businessId); + creditHistory.setMerchantId(record.getMerchantId()); + creditHistory.setCreditType(EnumScoreType.CONSUMPTION.getCode()); + creditHistory.setSpend(record.getPayAmount()); + creditHistory.setChangePurpose("Ali商圈消费:消费商户["+record.getMallName()+"] ("+record.getPayAmountStr()+"元) "); + creditHistory = creditHistoryService.saveOrUpdate(creditHistory,record.getTenantId()); + Integer creditNum = 0; + if (creditHistory.getCreditNum() != null) { + creditNum = creditHistory.getCreditNum(); + } + if(creditNum == 0){ + return; + } + record.setIncreasedPoints(creditNum); + record.setPointsUpdateTime(creditHistory.getCreateDate()); + this.updatePoints(record); + } + } + + @Override + public void insertRefundNoticeOrder(AliBusinessCircleOrder record) { + AliBusinessCircleOrder order = this.getOrderByTransactionId(record.getTransactionId(),record.getTenantId()); + if(order == null){ + logger.error("--Ali商圈退款--付款消息未找到--transactionId="+record.getTransactionId()); + }else{ + List refundOrders = this.getRefundOrderByTransactionId(record.getTransactionId(),record.getTenantId()); + Integer amount = order.getPayAmount(); + Integer increasedPoints = order.getIncreasedPoints(); + Integer refundAmount = 0; + Integer refundIncreasedPoints = 0; + + if(refundOrders != null && refundOrders.size()>0){ + for (AliBusinessCircleOrder ro:refundOrders) { + refundAmount += ro.getRefundAmount(); + refundIncreasedPoints += ro.getIncreasedPoints(); + } + } + if(refundAmount >= amount){ + logger.error("--Ali商圈退款--已经退款--transactionId="+record.getTransactionId()); + }else if((refundAmount + record.getRefundAmount()) > amount ){ + logger.error("--Ali商圈退款--退款金额超限--transactionId="+record.getTransactionId()); + }else{ + Date now = new Date(); + final IdWorker idWorker = IdWorker.get(); + record.setId(idWorker.nextId()); + record.setCreateTime(now); + record.setUpdateTime(now); + + record.setCUserId(order.getCUserId()); + record.setMerchantId(order.getMerchantId()); + aliBusinessCircleOrderMapper.insertRefundNoticeOrder(record); + + if(order.getEarnPoints().equals(EnumYesOrNo.YES.getCode())){ + WxCreditHistory creditHistory = new WxCreditHistory(); + creditHistory.setTenantId(record.getFinalTenantId()); + creditHistory.setOperatorType(EnumUserType.ALI_CIRCLE.getCode()); + creditHistory.setOperatorId(record.getCUserId()); + creditHistory.setCUserId(record.getCUserId()); + creditHistory.setCreateDate(new Date()); + creditHistory.setCouponId(record.getId()); + creditHistory.setMerchantId(record.getMerchantId()); + creditHistory.setCreditType(EnumScoreType.REFUND_CONSUMPTION.getCode()); + int points = 0; + if((refundAmount + record.getRefundAmount()) == amount){ + points = increasedPoints - refundIncreasedPoints; + }else{ + points = new BigDecimal(order.getIncreasedPoints()) + .divide(new BigDecimal(order.getPayAmount()),2,BigDecimal.ROUND_HALF_UP) + .multiply(new BigDecimal(record.getRefundAmount())) + .intValue(); + } + + creditHistory.setCreditNum(points); + creditHistory.setSpend(0-record.getRefundAmount()); + creditHistory.setChangePurpose("Ali商圈消费退款:商户["+record.getMallName()+"] ("+record.getRefundAmountStr()+"元) "); + creditHistory = creditHistoryService.saveOrUpdate(creditHistory,record.getTenantId()); + Integer creditNum = 0; + if (creditHistory.getCreditNum() != null) { + creditNum = creditHistory.getCreditNum(); + } + if(creditNum == 0){ + return; + } + + record.setIncreasedPoints(creditNum); + record.setPointsUpdateTime(creditHistory.getCreateDate()); + this.updatePoints(record); + } + } + } + } + + + @Override + public void updatePoints(AliBusinessCircleOrder record) { + record.setUpdateTime(new Date()); + aliBusinessCircleOrderMapper.updatePoints(record); + } + + +} diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBusinessCircleOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBusinessCircleOrderServiceImpl.java index 632f9eb14..f16e7a7a4 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBusinessCircleOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBusinessCircleOrderServiceImpl.java @@ -9,7 +9,6 @@ import com.iformall.domain.po.WxCreditHistory; import com.iformall.domain.po.WxMerchant; import com.iformall.enums.*; import com.iformall.mapper.WxBusinessCircleOrderMapper; -import com.iformall.mq.MqBaseProducer; import com.iformall.service.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,19 +16,14 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; -import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; -import java.util.Locale; @Service public class WxBusinessCircleOrderServiceImpl implements WxBusinessCircleOrderService { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'+'mm:ss", Locale.CHINA); - - @Autowired WxBusinessCircleOrderMapper wxBusinessCircleOrderMapper; @@ -42,15 +36,9 @@ public class WxBusinessCircleOrderServiceImpl implements WxBusinessCircleOrderSe @Autowired WxCreditHistoryService creditHistoryService; - @Autowired - WxPayAccountService wxPayAccountService; - @Autowired WxCallBackService wxCallBackService; - @Autowired - MqBaseProducer mqBaseProducer; - @Override public PageInfo listAsPage(WxBusinessCircleOrder record, Integer pageIndex, Integer pageSize) { @@ -85,7 +73,7 @@ public class WxBusinessCircleOrderServiceImpl implements WxBusinessCircleOrderSe public void createOrder(WxBusinessCircleOrder record) { WxBusinessCircleOrder byTransactionId = this.getOrderByTransactionId(record.getTransactionId(),record.getTenantId()); if(byTransactionId != null){ - logger.error("--商圈付款--订单消息已存在---byTransactionId="+byTransactionId.getTransactionId()); + logger.error("--Wx商圈付款--订单消息已存在---byTransactionId="+byTransactionId.getTransactionId()); }else{ Date now = new Date(); final IdWorker idWorker = IdWorker.get(); @@ -98,7 +86,7 @@ public class WxBusinessCircleOrderServiceImpl implements WxBusinessCircleOrderSe if(wxMerchant != null){ record.setMerchantId(wxMerchant.getId()); }else{ - logger.error("--商圈付款通知消息未找到门店--shopName="+record.getWxShopName()+"&shopNumber="+record.getWxShopNumber()); + logger.error("--Wx商圈付款通知消息未找到门店--shopName="+record.getWxShopName()+"&shopNumber="+record.getWxShopNumber()); } WxCUser userQ = new WxCUser(); userQ.updateTenantInfo(record); @@ -108,7 +96,7 @@ public class WxBusinessCircleOrderServiceImpl implements WxBusinessCircleOrderSe if(user != null && user.getUserId() != null){ record.setCUserId(user.getUserId()); }else{ - logger.error("--商圈付款通知消息未找到会员--openid="+record.getOpenid()); + logger.error("--Wx商圈付款通知消息未找到会员--openid="+record.getOpenid()); } wxBusinessCircleOrderMapper.insertNoticeOrder(record); @@ -130,7 +118,7 @@ public class WxBusinessCircleOrderServiceImpl implements WxBusinessCircleOrderSe creditHistory.setMerchantId(record.getMerchantId()); creditHistory.setCreditType(EnumScoreType.CONSUMPTION.getCode()); creditHistory.setSpend(record.getPayAmount()); - creditHistory.setChangePurpose("商圈消费:消费商户["+record.getWxShopName()+"] ("+record.getPayAmountStr()+"元) "); + creditHistory.setChangePurpose("Wx商圈消费:消费商户["+record.getWxShopName()+"] ("+record.getPayAmountStr()+"元) "); creditHistory = creditHistoryService.saveOrUpdate(creditHistory,record.getTenantId()); Integer creditNum = 0; if (creditHistory.getCreditNum() != null) { @@ -153,7 +141,7 @@ public class WxBusinessCircleOrderServiceImpl implements WxBusinessCircleOrderSe public void insertRefundNoticeOrder(WxBusinessCircleOrder record) { WxBusinessCircleOrder order = this.getOrderByTransactionId(record.getTransactionId(),record.getTenantId()); if(order == null){ - logger.error("--商圈退款--付款消息未找到--transactionId="+record.getTransactionId()); + logger.error("--Wx商圈退款--付款消息未找到--transactionId="+record.getTransactionId()); }else{ List refundOrders = this.getRefundOrderByTransactionId(record.getTransactionId(),record.getTenantId()); Integer amount = order.getPayAmount(); @@ -168,9 +156,9 @@ public class WxBusinessCircleOrderServiceImpl implements WxBusinessCircleOrderSe } } if(refundAmount >= amount){ - logger.error("--商圈退款--已经退款--transactionId="+record.getTransactionId()); + logger.error("--Wx商圈退款--已经退款--transactionId="+record.getTransactionId()); }else if((refundAmount + record.getRefundAmount()) > amount ){ - logger.error("--商圈退款--退款金额超限--transactionId="+record.getTransactionId()); + logger.error("--Wx商圈退款--退款金额超限--transactionId="+record.getTransactionId()); }else{ Date now = new Date(); final IdWorker idWorker = IdWorker.get(); @@ -204,7 +192,7 @@ public class WxBusinessCircleOrderServiceImpl implements WxBusinessCircleOrderSe creditHistory.setCreditNum(points); creditHistory.setSpend(0-record.getRefundAmount()); - creditHistory.setChangePurpose("商圈消费退款:商户["+record.getWxShopName()+"] ("+record.getRefundAmountStr()+"元) "); + creditHistory.setChangePurpose("Wx商圈消费退款:商户["+record.getWxShopName()+"] ("+record.getRefundAmountStr()+"元) "); creditHistory = creditHistoryService.saveOrUpdate(creditHistory,record.getTenantId()); Integer creditNum = 0; if (creditHistory.getCreditNum() != null) { diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java index a525b35a0..9bfaa047f 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java @@ -118,7 +118,9 @@ public class WxCouponServiceImpl implements WxCouponService { public ResultData list(TenantEntity tenantEntity,WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { if (null == wxCoupon) wxCoupon = new WxCoupon(); wxCoupon.updateTenantInfo(tenantEntity); - wxCoupon.setSortColumns(BaseEntity.SortField.CCreateDate_DESC, BaseEntity.SortField.CId_DESC); + if(StringUtils.isBlank(wxCoupon.getSortColumns())){ + wxCoupon.setSortColumns(BaseEntity.SortField.CCreateDate_DESC, BaseEntity.SortField.CId_DESC); + } PageInfo page = null; if (wxCoupon.getStatus() != null && wxCoupon.getStatus() == -1) wxCoupon.setStatus(null); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxThirdPartyOrdersServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxThirdPartyOrdersServiceImpl.java index 12f073d75..dd156f330 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxThirdPartyOrdersServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxThirdPartyOrdersServiceImpl.java @@ -1,216 +1,289 @@ -//package com.iformall.service.impl; -// -//import com.github.pagehelper.PageHelper; -//import com.github.pagehelper.PageInfo; -//import com.iformall.common.ErrorCode; -//import com.iformall.common.IdWorker; -//import com.iformall.domain.po.WxCUserBasicInfo; -//import com.iformall.domain.po.WxCreditHistory; -//import com.iformall.domain.po.WxMerchant; -//import com.iformall.domain.po.WxThirdPartyOrders; -//import com.iformall.domain.po.msg.FmInsideCircleOrderMsg; -//import com.iformall.enums.*; -//import com.iformall.exception.MallinkException; -//import com.iformall.mapper.WxThirdPartyOrdersMapper; -//import com.iformall.mq.MqBaseProducer; -//import com.iformall.service.*; -//import org.apache.commons.lang3.StringUtils; -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.stereotype.Service; -//import org.springframework.transaction.annotation.Transactional; -// -//import java.util.Date; -// -//import static org.springframework.transaction.annotation.Propagation.REQUIRED; -// -//@Service -//public class WxThirdPartyOrdersServiceImpl implements WxThirdPartyOrdersService { -// private final Logger logger = LoggerFactory.getLogger(this.getClass()); -// -// @Autowired -// WxThirdPartyOrdersMapper wxThirdPartyOrdersMapper; -// -// @Autowired -// WxMerchantService wxMerchantService; -// -// @Autowired -// WxCUserService wxCUserService; -// -// @Autowired -// WxCUserBasicInfoService wxCUserBasicInfoService; -// -// @Autowired -// MqBaseProducer mqBaseProducer; -// -// @Autowired -// WxCreditHistoryService wxCreditHistoryService; -// -// -// @Override -// public PageInfo listAsPage(WxThirdPartyOrders record, Integer pageIndex, Integer pageSize) { -// return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxThirdPartyOrdersMapper.findList(record)); -// } -// -// @Override -// public WxThirdPartyOrders getById(Long id, String tenantId) { -// WxThirdPartyOrders recordQ = new WxThirdPartyOrders(); -// recordQ.setId(id); -// recordQ.setTenantId(tenantId); -// return wxThirdPartyOrdersMapper.getById(recordQ); -// } -// -// @Override -// public WxThirdPartyOrders getByTransactionId(String transactionId, String tenantId) { -// WxThirdPartyOrders recordQ = new WxThirdPartyOrders(); -// recordQ.setTransactionId(transactionId); -// recordQ.setTenantId(tenantId); -// return wxThirdPartyOrdersMapper.getByTransactionId(recordQ); -// } -// -// @Override -// public void createOrder(WxThirdPartyOrders record) { -// WxThirdPartyOrders byTransactionId = wxThirdPartyOrdersMapper.getByTransactionId(record); -// if(byTransactionId != null){ -// logger.error("--第三方付款--通知消息已存在---byTransactionId="+byTransactionId.getTransactionId()); -// throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "订单数据已存在"); -// }else{ -// Date now = new Date(); -// final IdWorker idWorker = IdWorker.get(); -// record.setId(idWorker.nextId()); -// record.setCreateTime(now); -// record.setUpdateTime(now); -// -// record.setSourceType(EnumThirdOrderType.RMB_PAY.getCode()); -// -// //TODO 第三方获取门店(标识可能发生变化) -// WxMerchant wxMerchant = wxMerchantService.getById(Long.parseLong(record.getShopNumber())); -// if(wxMerchant != null){ -// record.setMerchantId(wxMerchant.getId()); -// }else{ -// logger.info("--第三方付款通知消息未找到门店--shopName="+record.getShopName()+"&shopNumber="+record.getShopNumber()); -// } -// -// WxCUserBasicInfo basicInfo = null; -// basicInfo = wxCUserBasicInfoService.getById(Long.parseLong(record.getUserNumber()), record.getFinalTenantId()); -// if(basicInfo == null){ -// basicInfo = wxCUserBasicInfoService.registerByPhone(record, record.getUserPhone()); -// } -// -// if(basicInfo != null){ -// record.setCUserId(basicInfo.getId()); -// }else{ -// logger.error("--第三方付款通知消息未找到会员--userPhone="+record.getUserPhone()+"$userNumer="+record.getId()); -// } -// wxThirdPartyOrdersMapper.insertNoticeOrder(record); -// -// this.sendMessage(record,EnumYesOrNo.NO.getCode()); -// -// } -// } -// -// /** -// * -// * @param record -// * @param isRefund 是否退款 -// */ -// private void sendMessage(WxThirdPartyOrders record,Integer isRefund){ -// FmInsideCircleOrderMsg msg = new FmInsideCircleOrderMsg(); -// msg.setMsgType(EnumMsgRecordType.THIRD_PARTY_NOTICE.getCode()); -// msg.updateTenantInfo(record); -// msg.setIsRefund(isRefund); -// msg.setCircleOrderId(record.getId()); -// msg.setMerchantId(record.getMerchantId()); -// msg.setCUserId(record.getCUserId()); -// msg.setShopName(record.getShopName()); -// msg.setUserPhone(record.getUserPhone()); -// msg.setAmount(record.getAmount()); -// mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); -// } -// -// @Override -// public void updateRefundOrder(WxThirdPartyOrders record) { -// WxThirdPartyOrders byTransactionId = this.getByTransactionId(record.getTransactionId(),record.getTenantId()); -// if(byTransactionId == null){ -// logger.error("--第三方退款--付款消息未找到--transactionId="+record.getTransactionId()); -// throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "付款消息未找到"); -// }else if(byTransactionId.getIsRefund().equals(EnumYesOrNo.YES.getCode())){ -// logger.error("--第三方退款--已是退款状态--transactionId="+record.getTransactionId()); -// throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "已是退款状态"); -// }else{ -// Date now = new Date(); -// record.setId(byTransactionId.getId()); -// record.setUpdateTime(now); -// wxThirdPartyOrdersMapper.updateRefundNoticeOrder(record); -// -// this.sendMessage(record,EnumYesOrNo.YES.getCode()); -// } -// } -// -// @Override -// public void updateAddPoints(WxThirdPartyOrders record) { -// record.setUpdateTime(new Date()); -// wxThirdPartyOrdersMapper.updateAddPoints(record); -// } -// -// @Override -// public void updateRefundPoints(WxThirdPartyOrders record) { -// record.setUpdateTime(new Date()); -// wxThirdPartyOrdersMapper.updateRefundPoints(record); -// } -// -// @Transactional(propagation = REQUIRED ,rollbackFor = Exception.class) -// @Override -// public void pointDeduction(WxThirdPartyOrders record) { -// -// WxCUserBasicInfo basicInfo = null; -// if(StringUtils.isNotBlank(record.getUserNumber())){ -// basicInfo = wxCUserBasicInfoService.getById(Long.parseLong(record.getUserNumber()), record.getFinalTenantId()); -// } -// if(basicInfo == null){ -// logger.error("--第三方积分订单--未找到用户---userId="+record.getUserNumber()); -// throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "未找到用户"); -// } -// -// record.setCUserId(basicInfo.getId()); -// -// WxThirdPartyOrders byTransactionId = wxThirdPartyOrdersMapper.getByTransactionId(record); -// if(byTransactionId != null){ -// logger.error("--第三方积分订单--数据已存在---byTransactionId="+byTransactionId.getTransactionId()); -// throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "订单数据已存在"); -// }else{ -// Date now = new Date(); -// final IdWorker idWorker = IdWorker.get(); -// record.setId(idWorker.nextId()); -// record.setCreateTime(now); -// record.setUpdateTime(now); -// -// record.setSourceType(EnumThirdOrderType.CREDIT_PAY.getCode()); -// -// //TODO 第三方获取门店(标识可能发生变化) -// WxMerchant wxMerchant = wxMerchantService.getById(Long.parseLong(record.getShopNumber())); -// if(wxMerchant != null){ -// record.setMerchantId(wxMerchant.getId()); -// }else{ -// logger.info("--第三方付款通知消息未找到门店--shopName="+record.getShopName()+"&shopNumber="+record.getShopNumber()); -// } -// -// WxCreditHistory wxCreditHistory = new WxCreditHistory(); -// wxCreditHistory.setTenantId(record.getFinalTenantId()); -// wxCreditHistory.setCUserId(basicInfo.getId()); -// wxCreditHistory.setOperatorId(basicInfo.getId()); -// wxCreditHistory.setOperatorType(EnumUserType.THIRD_CIRCLE.getCode()); -// wxCreditHistory.setCreditNum(record.getAmount()); -// wxCreditHistory.setCreditType(EnumScoreType.CHANGE_CREDIT.getCode()); -// wxCreditHistory.setChangePurpose("第三方消费抵扣{}"+record.getSummary()); -// wxCreditHistory.setCouponId(record.getId()); -// wxCreditHistoryService.saveOrUpdate(wxCreditHistory,record.getTenantId()); -// -// wxThirdPartyOrdersMapper.insertNoticeOrder(record); -// } -// -// } -// -// -//} +package com.iformall.service.impl; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.iformall.common.ErrorCode; +import com.iformall.common.IdWorker; +import com.iformall.domain.po.*; +import com.iformall.enums.*; +import com.iformall.exception.MallinkException; +import com.iformall.mapper.WxThirdPartyOrdersMapper; +import com.iformall.service.*; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; + +import static org.springframework.transaction.annotation.Propagation.REQUIRED; + +@Service +public class WxThirdPartyOrdersServiceImpl implements WxThirdPartyOrdersService { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + WxThirdPartyOrdersMapper wxThirdPartyOrdersMapper; + + @Autowired + WxMerchantService wxMerchantService; + + @Autowired + WxCUserService wxCUserService; + + @Autowired + WxCUserBasicInfoService wxCUserBasicInfoService; + + @Autowired + WxCreditHistoryService wxCreditHistoryService; + + + + @Override + public PageInfo listAsPage(WxThirdPartyOrders record, Integer pageIndex, Integer pageSize) { + return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxThirdPartyOrdersMapper.findList(record)); + } + + @Override + public WxThirdPartyOrders getById(Long id, String tenantId) { + WxThirdPartyOrders recordQ = new WxThirdPartyOrders(); + recordQ.setId(id); + recordQ.setTenantId(tenantId); + return wxThirdPartyOrdersMapper.getById(recordQ); + } + + @Override + public WxThirdPartyOrders getOrderByTransactionId(EnumThirdOrderType orderType, String transactionId, String tenantId) { + WxThirdPartyOrders recordQ = new WxThirdPartyOrders(); + recordQ.setSourceType(orderType.getCode()); + recordQ.setTransactionId(transactionId); + recordQ.setTenantId(tenantId); + return wxThirdPartyOrdersMapper.getOrderByTransactionId(recordQ); + } + + @Override + public List getRefundOrderByTransactionId(EnumThirdOrderType orderType, String transactionId, String tenantId) { + WxThirdPartyOrders recordQ = new WxThirdPartyOrders(); + recordQ.setSourceType(orderType.getCode()); + recordQ.setTransactionId(transactionId); + recordQ.setTenantId(tenantId); + return wxThirdPartyOrdersMapper.getRefundOrderByTransactionId(recordQ); + } + + @Override + public void createOrder(WxThirdPartyOrders record) { + WxThirdPartyOrders byTransactionId = this.getOrderByTransactionId(EnumThirdOrderType.RMB_PAY,record.getTransactionId(),record.getTenantId()); + if(byTransactionId != null){ + logger.error("--第三方付款--通知消息已存在---byTransactionId="+byTransactionId.getTransactionId()); + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "订单数据已存在"); + }else{ + Date now = new Date(); + final IdWorker idWorker = IdWorker.get(); + record.setId(idWorker.nextId()); + record.setCreateTime(now); + record.setUpdateTime(now); + + record.setSourceType(EnumThirdOrderType.RMB_PAY.getCode()); + + //TODO 第三方获取门店(标识可能发生变化) + WxMerchant wxMerchant = wxMerchantService.getById(Long.parseLong(record.getShopNumber())); + if(wxMerchant != null){ + record.setMerchantId(wxMerchant.getId()); + }else{ + logger.info("--第三方付款通知消息未找到门店--shopName="+record.getShopName()+"&shopNumber="+record.getShopNumber()); + } + + WxCUserBasicInfo basicInfo = null; + basicInfo = wxCUserBasicInfoService.getById(Long.parseLong(record.getUserNumber()), record.getFinalTenantId()); + if(basicInfo == null){ + basicInfo = wxCUserBasicInfoService.registerByPhone(record, record.getUserPhone()); + } + + if(basicInfo != null){ + record.setCUserId(basicInfo.getId()); + }else{ + logger.error("--第三方付款通知消息未找到会员--userPhone="+record.getUserPhone()+"$userNumer="+record.getId()); + } + wxThirdPartyOrdersMapper.insertNoticeOrder(record); + + if(record.getCUserId() == null){ + return; + } + Integer businessId = EnumBusiness.BUSINESS_ID6.getCode(); + if(wxMerchant != null){ + businessId = wxMerchant.getBusinessId(); + } + WxCreditHistory creditHistory = new WxCreditHistory(); + creditHistory.setTenantId(record.getFinalTenantId()); + creditHistory.setOperatorType(EnumUserType.THIRD_CIRCLE.getCode()); + creditHistory.setOperatorId(record.getCUserId()); + creditHistory.setCUserId(record.getCUserId()); + creditHistory.setCreateDate(now); + creditHistory.setCouponId(record.getId()); + creditHistory.setBusinessId(businessId); + creditHistory.setMerchantId(record.getMerchantId()); + creditHistory.setCreditType(EnumScoreType.CONSUMPTION.getCode()); + creditHistory.setSpend(record.getPayAmount()); + creditHistory.setChangePurpose("第三方消费:消费商户["+record.getShopName()+"] ("+record.getPayAmountStr()+"元) "); + creditHistory = wxCreditHistoryService.saveOrUpdate(creditHistory,record.getTenantId()); + Integer creditNum = 0; + if (creditHistory.getCreditNum() != null) { + creditNum = creditHistory.getCreditNum(); + } + if(creditNum == 0){ + return; + } + record.setIncreasedPoints(creditNum); + record.setPointsUpdateTime(creditHistory.getCreateDate()); + this.updatePoints(record); + + + } + } + + + @Override + public void insertRefundNoticeOrder(WxThirdPartyOrders record) { + WxThirdPartyOrders order = this.getOrderByTransactionId(EnumThirdOrderType.RMB_PAY,record.getTransactionId(),record.getTenantId()); + if(order == null){ + logger.error("--第三方退款--付款消息未找到--transactionId="+record.getTransactionId()); + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "付款消息未找到"); + }else if(order.getIsRefund().equals(EnumYesOrNo.YES.getCode())){ + logger.error("--第三方退款--已是退款状态--transactionId="+record.getTransactionId()); + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "已是退款状态"); + }else{ + List refundOrders = this.getRefundOrderByTransactionId(EnumThirdOrderType.RMB_PAY,record.getTransactionId(),record.getTenantId()); + Integer amount = order.getPayAmount(); + Integer increasedPoints = order.getIncreasedPoints(); + Integer refundAmount = 0; + Integer refundIncreasedPoints = 0; + + if(refundOrders != null && refundOrders.size()>0){ + for (WxThirdPartyOrders ro:refundOrders) { + refundAmount += ro.getRefundAmount(); + refundIncreasedPoints += ro.getIncreasedPoints(); + } + } + if(refundAmount >= amount){ + logger.error("--第三方退款--已经退款--transactionId="+record.getTransactionId()); + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "已经退款"); + }else if((refundAmount + record.getRefundAmount()) > amount ){ + logger.error("--第三方退款--退款金额超限--transactionId="+record.getTransactionId()); + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "退款金额超限"); + }else{ + + Date now = new Date(); + final IdWorker idWorker = IdWorker.get(); + record.setId(idWorker.nextId()); + record.setCreateTime(now); + record.setUpdateTime(now); + + record.setCUserId(order.getCUserId()); + record.setMerchantId(order.getMerchantId()); + wxThirdPartyOrdersMapper.insertRefundNoticeOrder(record); + + if(order.getEarnPoints().equals(EnumYesOrNo.YES.getCode())){ + WxCreditHistory creditHistory = new WxCreditHistory(); + creditHistory.setTenantId(record.getFinalTenantId()); + creditHistory.setOperatorType(EnumUserType.THIRD_CIRCLE.getCode()); + creditHistory.setOperatorId(record.getCUserId()); + creditHistory.setCUserId(record.getCUserId()); + creditHistory.setCreateDate(new Date()); + creditHistory.setCouponId(record.getId()); + creditHistory.setMerchantId(record.getMerchantId()); + creditHistory.setCreditType(EnumScoreType.REFUND_CONSUMPTION.getCode()); + int points = 0; + if((refundAmount + record.getRefundAmount()) == amount){ + points = increasedPoints - refundIncreasedPoints; + }else{ + points = new BigDecimal(order.getIncreasedPoints()) + .divide(new BigDecimal(order.getPayAmount()),2,BigDecimal.ROUND_HALF_UP) + .multiply(new BigDecimal(record.getRefundAmount())) + .intValue(); + } + + creditHistory.setCreditNum(points); + creditHistory.setSpend(0-record.getRefundAmount()); + creditHistory.setChangePurpose("第三方消费退款:商户["+record.getShopName()+"] ("+record.getRefundAmountStr()+"元) "); + creditHistory = wxCreditHistoryService.saveOrUpdate(creditHistory,record.getTenantId()); + Integer creditNum = 0; + if (creditHistory.getCreditNum() != null) { + creditNum = creditHistory.getCreditNum(); + } + if(creditNum == 0){ + return; + } + + record.setIncreasedPoints(creditNum); + record.setPointsUpdateTime(creditHistory.getCreateDate()); + this.updatePoints(record); + } + } + + } + } + + @Override + public void updatePoints(WxThirdPartyOrders record) { + record.setUpdateTime(new Date()); + wxThirdPartyOrdersMapper.updatePoints(record); + } + + @Transactional(propagation = REQUIRED ,rollbackFor = Exception.class) + @Override + public void pointDeduction(WxThirdPartyOrders record) { + + WxCUserBasicInfo basicInfo = null; + if(StringUtils.isNotBlank(record.getUserNumber())){ + basicInfo = wxCUserBasicInfoService.getById(Long.parseLong(record.getUserNumber()), record.getFinalTenantId()); + } + if(basicInfo == null){ + logger.error("--第三方积分订单--未找到用户---userId="+record.getUserNumber()); + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "未找到用户"); + } + + record.setCUserId(basicInfo.getId()); + + WxThirdPartyOrders byTransactionId = this.getOrderByTransactionId(EnumThirdOrderType.CREDIT_PAY,record.getTransactionId(),record.getTenantId()); + if(byTransactionId != null){ + logger.error("--第三方积分订单--数据已存在---byTransactionId="+byTransactionId.getTransactionId()); + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "订单数据已存在"); + }else{ + Date now = new Date(); + final IdWorker idWorker = IdWorker.get(); + record.setId(idWorker.nextId()); + record.setCreateTime(now); + record.setUpdateTime(now); + + record.setSourceType(EnumThirdOrderType.CREDIT_PAY.getCode()); + + //TODO 第三方获取门店(标识可能发生变化) + WxMerchant wxMerchant = wxMerchantService.getById(Long.parseLong(record.getShopNumber())); + if(wxMerchant != null){ + record.setMerchantId(wxMerchant.getId()); + }else{ + logger.info("--第三方付款通知消息未找到门店--shopName="+record.getShopName()+"&shopNumber="+record.getShopNumber()); + } + + WxCreditHistory wxCreditHistory = new WxCreditHistory(); + wxCreditHistory.setTenantId(record.getFinalTenantId()); + wxCreditHistory.setCUserId(basicInfo.getId()); + wxCreditHistory.setOperatorId(basicInfo.getId()); + wxCreditHistory.setOperatorType(EnumUserType.THIRD_CIRCLE.getCode()); + wxCreditHistory.setCreditNum(record.getAmount()); + wxCreditHistory.setCreditType(EnumScoreType.CHANGE_CREDIT.getCode()); + wxCreditHistory.setChangePurpose("第三方消费抵扣{}"+record.getSummary()); + wxCreditHistory.setCouponId(record.getId()); + wxCreditHistoryService.saveOrUpdate(wxCreditHistory,record.getTenantId()); + + wxThirdPartyOrdersMapper.insertNoticeOrder(record); + } + + } + + +} diff --git a/mallinkService/src/main/resources/mapper/AliBusinessCircleMapper.xml b/mallinkService/src/main/resources/mapper/AliBusinessCircleMapper.xml new file mode 100644 index 000000000..f1949b259 --- /dev/null +++ b/mallinkService/src/main/resources/mapper/AliBusinessCircleMapper.xml @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + `id`, `tenant_id`, `parent_tenant_id`, `source_app_id`, `source_type`,`notice_id`, `notice_create_time`, `notice_event_type`, + `notice_resource_type`, `summary`,`shop_name`, `shop_number`, `user_phone`, `user_number`, + `time_end`, `amount`, `pay_amount`, `transaction_id`, `create_time`, `update_time`, + `merchant_id`, `c_user_id`, `earn_points`, `increased_points`, `points_update_time`, + `is_refund`, `refund_id`, `refund_amount` + + + + where 1 = 1 + + + and `id` = #{id} + + + + and `tenant_id` = #{tenantId} + + + and `parent_tenant_id` = #{parentTenantId} + + + + and `source_app_id` = #{sourceAppId} + + + + and `source_type` = #{sourceType} + + + + and `shop_name` like concat('%', #{shopName},'%') + + + + and `shop_number` = #{shopNumber} + + + + and `user_phone` = #{userPhone} + + + + and `user_number` = #{userNumber} + + + + and `notice_id` = #{noticeId} + + + + and `time_end` >= #{startTime} + + + and `time_end` < #{endTime} + + + + and `transaction_id` = #{transactionId} + + + + and `merchant_id` = #{merchantId} + + + + and `c_user_id` = #{cUserId} + + + + and `earn_points` = #{earnPoints} + + + + and `is_refund` = #{isRefund} + + + + and `refund_id` = #{refundId} + + + + and `id` in + + #{idItem} + + + order by ${sortColumns} + + + + + + + + + + + + INSERT INTO wx_third_party_orders ( + `id`, `tenant_id`, `parent_tenant_id`,`source_app_id`, `source_type`, `notice_id`, `notice_create_time`, `notice_event_type`, + `notice_resource_type`, `summary`, `shop_name`, `shop_number`, `user_phone`, `user_number`,`time_end`, `amount`, `pay_amount`, `transaction_id`, `commit_tag`, `create_time`, `update_time`, + `merchant_id`, `c_user_id`, `earn_points`, `is_refund` + ) + VALUES( + #{id},#{tenantId},#{parentTenantId},#{sourceAppId},#{sourceType},#{noticeId},#{noticeCreateTime},#{noticeEventType}, + #{noticeResourceType},#{summary},#{shopName},#{shopNumber},#{userPhone},#{userNumber},#{timeEnd},#{amount},#{payAmount},#{transactionId},#{commitTag},#{createTime},#{updateTime}, + #{merchantId},#{cUserId},0,0 + ); + + + + update wx_third_party_orders set + `earn_points` = 1, `increased_points` = #{increasedPoints}, `points_update_time` = #{pointsUpdateTime}, + `is_refund_points` = 0, `update_time` = #{updateTime} + where `id` = #{id} and `tenant_id` = #{tenantId} + + + + INSERT INTO wx_third_party_orders ( + `id`, `tenant_id`, `parent_tenant_id`,`source_app_id`, `source_type`, `notice_id`, `notice_create_time`, `notice_event_type`, + `notice_resource_type`, `summary`,`shop_name`, `shop_number`, `user_phone`, `user_number`, `time_end`, `amount`,`pay_amount`, `transaction_id`, `commit_tag`, `create_time`, `update_time`, + `merchant_id`, `c_user_id`, `earn_points`, `is_refund`, `refund_id`, `refund_amount` + ) + VALUES( + #{id},#{tenantId},#{parentTenantId},#{sourceAppId},#{sourceType},#{noticeId},#{noticeCreateTime},#{noticeEventType}, + #{noticeResourceType},#{summary},#{shopName},#{shopNumber},#{userPhone},#{userNumber},#{timeEnd},#{amount},#{payAmount},#{transactionId},#{commitTag},#{createTime},#{updateTime}, + #{merchantId},#{cUserId},0,1,#{refundId},#{refundAmount} + ); + + + diff --git a/mallinkService/src/main/resources/mapper/AliBusinessCircleOrder.xml b/mallinkService/src/main/resources/mapper/AliBusinessCircleOrder.xml new file mode 100644 index 000000000..1c4d44c30 --- /dev/null +++ b/mallinkService/src/main/resources/mapper/AliBusinessCircleOrder.xml @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + `id`, `tenant_id`, `parent_tenant_id`, `notice_id`, `notice_create_time`, `notice_event_type`, + `notice_resource_type`, `summary`,`mall_id`, `mall_name`, `mall_store_id`, `buyer_id`, + `time_end`, `amount`, `pay_amount`, `transaction_id`, `create_time`, `update_time`, + `merchant_id`, `c_user_id`, `earn_points`, `increased_points`, `points_update_time`, + `is_refund`, `refund_id`, `refund_amount` + + + + where 1 = 1 + + + and `id` = #{id} + + + + and `tenant_id` = #{tenantId} + + + and `parent_tenant_id` = #{parentTenantId} + + + + and `mall_store_id` = #{mallStoreId} + + + + and `buyer_id` = #{buyerId} + + + + and `notice_id` = #{noticeId} + + + + and `time_end` >= #{startTime} + + + and `time_end` < #{endTime} + + + + and `transaction_id` = #{transactionId} + + + + and `merchant_id` = #{merchantId} + + + + and `c_user_id` = #{cUserId} + + + + and `earn_points` = #{earnPoints} + + + + and `is_refund` = #{isRefund} + + + + and `refund_id` = #{refundId} + + + + and `id` in + + #{idItem} + + + order by ${sortColumns} + + + + + + + + + + + + INSERT INTO ali_business_circle_order ( + `id`, `tenant_id`, `parent_tenant_id`, `notice_id`, `notice_create_time`, `notice_event_type`, + `notice_resource_type`, `summary`, `mall_id`, `mall_name`, `mall_store_id`, `buyer_id`,`time_end`, `amount`, `pay_amount`, `transaction_id`, `commit_tag`, `create_time`, `update_time`, + `merchant_id`, `c_user_id`, `earn_points`, `is_refund` + ) + VALUES( + #{id},#{tenantId},#{parentTenantId},#{noticeId},#{noticeCreateTime},#{noticeEventType}, + #{noticeResourceType},#{summary},#{mallId},#{mallName},#{mallStoreId},#{buyerId},#{timeEnd},#{amount},#{payAmount},#{transactionId},#{commitTag},#{createTime},#{updateTime}, + #{merchantId},#{cUserId},0,0 + ); + + + + update ali_business_circle_order set + `earn_points` = 1, `increased_points` = #{increasedPoints}, `points_update_time` = #{pointsUpdateTime}, + `is_refund_points` = 0, `update_time` = #{updateTime} + where `id` = #{id} and `tenant_id` = #{tenantId} + + + + INSERT INTO ali_business_circle_order ( + `id`, `tenant_id`, `parent_tenant_id`,`notice_id`, `notice_create_time`, `notice_event_type`, + `notice_resource_type`, `summary`,`mall_id`, `mall_name`, `mall_store_id`, `buyer_id`, `time_end`, `amount`,`pay_amount`, `transaction_id`, `commit_tag`, `create_time`, `update_time`, + `merchant_id`, `c_user_id`, `earn_points`, `is_refund`, `refund_id`, `refund_amount` + ) + VALUES( + #{id},#{tenantId},#{parentTenantId},#{noticeId},#{noticeCreateTime},#{noticeEventType}, + #{noticeResourceType},#{summary},#{mallId},#{mallName},#{mallStoreId},#{buyerId},#{timeEnd},#{amount},#{payAmount},#{transactionId},#{commitTag},#{createTime},#{updateTime}, + #{merchantId},#{cUserId},0,1,#{refundId},#{refundAmount} + ); + + + diff --git a/mallinkService/src/main/resources/mapper/WxThirdPartyOrdersMapper.xml b/mallinkService/src/main/resources/mapper/WxThirdPartyOrdersMapper.xml index a2d12ef39..d71df67d3 100644 --- a/mallinkService/src/main/resources/mapper/WxThirdPartyOrdersMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxThirdPartyOrdersMapper.xml @@ -5,20 +5,30 @@ + + + + + + + + + + - + @@ -26,25 +36,20 @@ + - - - - - - + - `id`, `tenant_id`, `parent_tenant_id`, `source_app_id`, `source_type`, `shop_name`, `shop_number`, - `user_phone`, `user_number`, `time_end`, `amount`, `transaction_id`, `summary`, - `create_time`, `update_time`, `merchant_id`, `c_user_id`, - `earn_points`, `increased_points`, `points_update_time`, - `is_refund`, `refund_summary`, `refund_time`, `refund_amount`, `refund_id`, - `is_refund_points`, `refund_points_time` + `id`, `tenant_id`, `parent_tenant_id`, `source_app_id`, `source_type`,`notice_id`, `notice_create_time`, `notice_event_type`, + `notice_resource_type`, `summary`,`shop_name`, `shop_number`, `user_phone`, `user_number`, + `time_end`, `amount`, `pay_amount`, `transaction_id`, `create_time`, `update_time`, + `merchant_id`, `c_user_id`, `earn_points`, `increased_points`, `points_update_time`, + `is_refund`, `refund_id`, `refund_amount` @@ -85,6 +90,10 @@ and `user_number` = #{userNumber} + + and `notice_id` = #{noticeId} + + and `time_end` >= #{startTime} @@ -116,10 +125,6 @@ and `refund_id` = #{refundId} - - and `is_refund_points` = #{isRefundPoints} - - and `id` in @@ -144,46 +149,57 @@ and tenant_id=#{tenantId} - select from wx_third_party_orders - where `transaction_id` = #{transactionId} - and tenant_id=#{tenantId} + where `is_refund` = 0 + and `sourceType` = #{sourceType} + and `tenant_id` = #{tenantId} + and `transaction_id` = #{transactionId} + + + - INSERT INTO wx_business_circle_order ( - `id`, `tenant_id`, `parent_tenant_id`, `source_app_id`,`source_type`,`shop_name`, `shop_number`, - `user_phone`, `user_number`, `time_end`, `amount`, `transaction_id`, `summary`, - `create_time`, `update_time`, `merchant_id`, `c_user_id`, `earn_points`, `is_refund` + INSERT INTO wx_third_party_orders ( + `id`, `tenant_id`, `parent_tenant_id`,`source_app_id`, `source_type`, `notice_id`, `notice_create_time`, `notice_event_type`, + `notice_resource_type`, `summary`, `shop_name`, `shop_number`, `user_phone`, `user_number`,`time_end`, `amount`, `pay_amount`, `transaction_id`, `commit_tag`, `create_time`, `update_time`, + `merchant_id`, `c_user_id`, `earn_points`, `is_refund` ) VALUES( - #{id},#{tenantId},#{parentTenantId},#{sourceAppId},#{sourceType},#{shopName},#{shopNumber}, - #{userPhone},#{userNumber},#{timeEnd},#{amount},#{transactionId},#{summary}, - #{createTime},#{updateTime}, #{merchantId},#{cUserId},0,0 + #{id},#{tenantId},#{parentTenantId},#{sourceAppId},#{sourceType},#{noticeId},#{noticeCreateTime},#{noticeEventType}, + #{noticeResourceType},#{summary},#{shopName},#{shopNumber},#{userPhone},#{userNumber},#{timeEnd},#{amount},#{payAmount},#{transactionId},#{commitTag},#{createTime},#{updateTime}, + #{merchantId},#{cUserId},0,0 ); - - update wx_business_circle_order set + + update wx_third_party_orders set `earn_points` = 1, `increased_points` = #{increasedPoints}, `points_update_time` = #{pointsUpdateTime}, `is_refund_points` = 0, `update_time` = #{updateTime} where `id` = #{id} and `tenant_id` = #{tenantId} - - update wx_business_circle_order set - `is_refund` = 1, `refund_summary` = #{refundSummary}, - `refund_time` = #{refundTime}, `refund_amount` = #{refundAmount}, `refund_id` = #{refundId}, - `update_time` = #{updateTime} - where `id` = #{id} and `tenant_id` = #{tenantId} - - - - update wx_business_circle_order set - `is_refund_points` = 1, `refund_points_time` = #{refundPointsTime}, `update_time` = #{updateTime} - where `id` = #{id} and `tenant_id` = #{tenantId} - + + INSERT INTO wx_third_party_orders ( + `id`, `tenant_id`, `parent_tenant_id`,`source_app_id`, `source_type`, `notice_id`, `notice_create_time`, `notice_event_type`, + `notice_resource_type`, `summary`,`shop_name`, `shop_number`, `user_phone`, `user_number`, `time_end`, `amount`,`pay_amount`, `transaction_id`, `commit_tag`, `create_time`, `update_time`, + `merchant_id`, `c_user_id`, `earn_points`, `is_refund`, `refund_id`, `refund_amount` + ) + VALUES( + #{id},#{tenantId},#{parentTenantId},#{sourceAppId},#{sourceType},#{noticeId},#{noticeCreateTime},#{noticeEventType}, + #{noticeResourceType},#{summary},#{shopName},#{shopNumber},#{userPhone},#{userNumber},#{timeEnd},#{amount},#{payAmount},#{transactionId},#{commitTag},#{createTime},#{updateTime}, + #{merchantId},#{cUserId},0,1,#{refundId},#{refundAmount} + ); +