| @@ -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; | |||
| @@ -181,10 +192,11 @@ public class AliPayController extends BaseController { | |||
| * @throws Exception 可能产生的任何异常 | |||
| */ | |||
| @RequestMapping(value = "/notify") | |||
| public void __Notify(@RequestParam Map<String, Object> paramMap) throws Exception { | |||
| public String __Notify(@RequestParam Map<String, Object> paramMap) throws Exception { | |||
| String msgMethod = (String) paramMap.get("msg_method"); | |||
| if (StringUtils.isBlank(msgMethod)) { | |||
| logger.error("alipay notify notify error. msg_method empity:"+paramMap); | |||
| return "fail"; | |||
| }else { | |||
| //支付成功 | |||
| if ("alipay.business.mall.trade.success".equals(msgMethod)) { | |||
| @@ -207,31 +219,83 @@ public class AliPayController extends BaseController { | |||
| }*/ | |||
| if (StringUtils.isBlank(bizContent)) { | |||
| logger.error("alipay notify notify error. bizContent empity:"+paramMap); | |||
| return "fail"; | |||
| }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){ | |||
| logger.error("alipay notify . 找不到门店:"+paramMap); | |||
| return "fail"; | |||
| } | |||
| 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); | |||
| return "success"; | |||
| } | |||
| //退款成功 | |||
| }else if ("alipay.business.mall.trade.refunded".equals(msgMethod)) { | |||
| String bizContent = (String) paramMap.get("biz_content"); | |||
| if (StringUtils.isBlank(bizContent)) { | |||
| logger.error("alipay notify notify error. bizContent empity:"+paramMap); | |||
| return "fail"; | |||
| }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){ | |||
| logger.error("alipay notify . 找不到门店:"+paramMap); | |||
| return "fail"; | |||
| } | |||
| 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); | |||
| return "success"; | |||
| } | |||
| } | |||
| }else{ | |||
| logger.error("alipay notify . 未知通知:"+paramMap); | |||
| return "fail"; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -81,7 +81,6 @@ public class WxBusinessOrderController extends BaseController { | |||
| WxBusinessCircleOrder wxBusinessCircleOrder = new WxBusinessCircleOrder(); | |||
| wxBusinessCircleOrder.updateTenantInfo(tenantEntity); | |||
| wxBusinessCircleOrder.setSourceType(EnumThirdPartyConfigType.WEIXIN.getCode()); | |||
| wxBusinessCircleOrder.setNoticeId(notifyData.getId()); | |||
| wxBusinessCircleOrder.setNoticeCreateTime(sdf.parse(notifyData.getCreateTime())); | |||
| wxBusinessCircleOrder.setNoticeEventType(notifyData.getEventType()); | |||
| @@ -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<String,Object> 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<String,Object> 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<String,Object> 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<String,Object> 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<String,Object> 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<String,Object> 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); | |||
| } | |||
| } | |||
| } | |||
| @@ -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"); | |||
| @@ -17,10 +17,6 @@ public class BusinessCircleBase extends TenantEntity { | |||
| protected Long id; | |||
| @TableField(exist = false) | |||
| @io.swagger.annotations.ApiModelProperty(value="来源类型(1:来自微信)",name="sourceType") | |||
| private Integer sourceType; | |||
| @io.swagger.annotations.ApiModelProperty(value="商圈支付结果通知Id",name="noticeId") | |||
| private String noticeId; | |||
| @@ -36,24 +32,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 +60,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 +81,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; | |||
| @@ -1,14 +1,10 @@ | |||
| package com.iformall.domain.po; | |||
| import com.baomidou.mybatisplus.annotation.TableField; | |||
| import com.baomidou.mybatisplus.annotation.TableName; | |||
| import com.iformall.domain.po.base.TenantEntity; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import lombok.ToString; | |||
| import java.math.BigDecimal; | |||
| import java.util.Date; | |||
| @TableName(value = "wx_third_party_orders") | |||
| @Data | |||
| @@ -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<AliBusinessCircleOrder, Long> { | |||
| List<AliBusinessCircleOrder> findList(AliBusinessCircleOrder record); | |||
| AliBusinessCircleOrder getById(AliBusinessCircleOrder record); | |||
| AliBusinessCircleOrder getOrderByTransactionId(AliBusinessCircleOrder record); | |||
| List<AliBusinessCircleOrder> getRefundOrderByTransactionId(AliBusinessCircleOrder record); | |||
| /** | |||
| * 成功通知新建 | |||
| * @param record | |||
| */ | |||
| void insertNoticeOrder(AliBusinessCircleOrder record); | |||
| /** | |||
| * 加积分 | |||
| * @param record | |||
| */ | |||
| void updatePoints(AliBusinessCircleOrder record); | |||
| /** | |||
| * 退款 | |||
| * @param record | |||
| */ | |||
| void insertRefundNoticeOrder(AliBusinessCircleOrder record); | |||
| } | |||
| @@ -13,7 +13,8 @@ public interface WxThirdPartyOrdersMapper extends CommonMapper<WxThirdPartyOrder | |||
| WxThirdPartyOrders getById(WxThirdPartyOrders record); | |||
| WxThirdPartyOrders getByTransactionId(WxThirdPartyOrders record); | |||
| WxThirdPartyOrders getOrderByTransactionId(WxThirdPartyOrders record); | |||
| List<WxThirdPartyOrders> getRefundOrderByTransactionId(WxThirdPartyOrders record); | |||
| /** | |||
| * 成功通知新建 | |||
| @@ -25,19 +26,12 @@ public interface WxThirdPartyOrdersMapper extends CommonMapper<WxThirdPartyOrder | |||
| * 加积分 | |||
| * @param record | |||
| */ | |||
| void updateAddPoints(WxThirdPartyOrders record); | |||
| void updatePoints(WxThirdPartyOrders record); | |||
| /** | |||
| * 退款 | |||
| * @param record | |||
| */ | |||
| void updateRefundNoticeOrder(WxThirdPartyOrders record); | |||
| /** | |||
| * 退积分 | |||
| * @param record | |||
| */ | |||
| void updateRefundPoints(WxThirdPartyOrders record); | |||
| void insertRefundNoticeOrder(WxThirdPartyOrders record); | |||
| } | |||
| @@ -0,0 +1,47 @@ | |||
| package com.iformall.service; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.domain.po.AliBusinessCircleOrder; | |||
| import java.util.List; | |||
| public interface AliBusinessCircleOrderService { | |||
| /** | |||
| * 根据实体查询分页列表 | |||
| * | |||
| * @param record | |||
| * @param pageIndex | |||
| * @param pageSize | |||
| * @return | |||
| */ | |||
| PageInfo<AliBusinessCircleOrder> 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<AliBusinessCircleOrder> getRefundOrderByTransactionId(String transactionId, String tenantId); | |||
| void createOrder(AliBusinessCircleOrder record); | |||
| void insertRefundNoticeOrder(AliBusinessCircleOrder record); | |||
| /** | |||
| * 积分 | |||
| * @param record | |||
| */ | |||
| void updatePoints(AliBusinessCircleOrder record); | |||
| } | |||
| @@ -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<WxThirdPartyOrders> 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); | |||
| /** | |||
| * 积分抵扣 | |||
| @@ -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<AliBusinessCircleOrder> 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<AliBusinessCircleOrder> 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<AliBusinessCircleOrder> 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); | |||
| } | |||
| } | |||
| @@ -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<WxBusinessCircleOrder> 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<WxBusinessCircleOrder> 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) { | |||
| @@ -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<WxCoupon> page = null; | |||
| if (wxCoupon.getStatus() != null && wxCoupon.getStatus() == -1) | |||
| wxCoupon.setStatus(null); | |||
| @@ -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<WxThirdPartyOrders> 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<WxThirdPartyOrders> 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<WxThirdPartyOrders> 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<WxThirdPartyOrders> 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); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,183 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
| <mapper namespace="com.iformall.mapper.AliBusinessCircleOrderMapper"> | |||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.AliBusinessCircleOrder"> | |||
| <id column="id" jdbcType="BIGINT" property="id"/> | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/> | |||
| <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" /> | |||
| <result column="notice_id" jdbcType="VARCHAR" property="noticeId" /> | |||
| <result column="notice_create_time" jdbcType="TIMESTAMP" property="noticeCreateTime"/> | |||
| <result column="notice_event_type" jdbcType="VARCHAR" property="noticeEventType" /> | |||
| <result column="notice_resource_type" jdbcType="VARCHAR" property="noticeResourceType" /> | |||
| <result column="summary" jdbcType="VARCHAR" property="summary" /> | |||
| <result column="mall_id" jdbcType="VARCHAR" property="mallId" /> | |||
| <result column="mall_name" jdbcType="VARCHAR" property="mallName" /> | |||
| <result column="mall_store_id" jdbcType="VARCHAR" property="mallStoreId" /> | |||
| <result column="buyer_id" jdbcType="VARCHAR" property="buyerId" /> | |||
| <result column="time_end" jdbcType="TIMESTAMP" property="timeEnd"/> | |||
| <result column="amount" jdbcType="INTEGER" property="amount"/> | |||
| <result column="pay_amount" jdbcType="INTEGER" property="payAmount"/> | |||
| <result column="transaction_id" jdbcType="VARCHAR" property="transactionId" /> | |||
| <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/> | |||
| <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/> | |||
| <result column="merchant_id" jdbcType="BIGINT" property="merchantId"/> | |||
| <result column="c_user_id" jdbcType="BIGINT" property="cUserId"/> | |||
| <result column="earn_points" jdbcType="TINYINT" property="earnPoints"/> | |||
| <result column="increased_points" jdbcType="INTEGER" property="increasedPoints"/> | |||
| <result column="points_update_time" jdbcType="TIMESTAMP" property="pointsUpdateTime"/> | |||
| <result column="is_refund" jdbcType="TINYINT" property="isRefund"/> | |||
| <result column="refund_id" jdbcType="VARCHAR" property="refundId" /> | |||
| <result column="refund_amount" jdbcType="INTEGER" property="refundAmount"/> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `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` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| where 1 = 1 | |||
| <if test=" null != id "> | |||
| and `id` = #{id} | |||
| </if> | |||
| <if test=" null != tenantId and '' != tenantId"> | |||
| and `tenant_id` = #{tenantId} | |||
| </if> | |||
| <if test=" null != parentTenantId and '' != parentTenantId"> | |||
| and `parent_tenant_id` = #{parentTenantId} | |||
| </if> | |||
| <if test=" null != mallStoreId and '' != mallStoreId"> | |||
| and `mall_store_id` = #{mallStoreId} | |||
| </if> | |||
| <if test=" null != buyerId and '' != buyerId"> | |||
| and `buyer_id` = #{buyerId} | |||
| </if> | |||
| <if test=" null != noticeId and '' != noticeId"> | |||
| and `notice_id` = #{noticeId} | |||
| </if> | |||
| <if test=" null != startTime "> | |||
| and `time_end` >= #{startTime} | |||
| </if> | |||
| <if test=" null != endTime"> | |||
| and `time_end` < #{endTime} | |||
| </if> | |||
| <if test=" null != transactionId and '' != transactionId"> | |||
| and `transaction_id` = #{transactionId} | |||
| </if> | |||
| <if test=" null != merchantId "> | |||
| and `merchant_id` = #{merchantId} | |||
| </if> | |||
| <if test=" null != cUserId "> | |||
| and `c_user_id` = #{cUserId} | |||
| </if> | |||
| <if test=" null != earnPoints "> | |||
| and `earn_points` = #{earnPoints} | |||
| </if> | |||
| <if test=" null != isRefund "> | |||
| and `is_refund` = #{isRefund} | |||
| </if> | |||
| <if test=" null != refundId and '' != refundId"> | |||
| and `refund_id` = #{refundId} | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and `id` in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
| #{idItem} | |||
| </foreach> | |||
| </if> | |||
| <if test=" null != sortColumns">order by ${sortColumns}</if> | |||
| </sql> | |||
| <select id="findList" parameterType="com.iformall.domain.po.WxThirdPartyOrders" resultMap="BaseResultMap"> | |||
| select | |||
| <include refid="allColumns"/> | |||
| from ali_business_circle_order | |||
| <include refid="dynamicWhereConditions"/> | |||
| </select> | |||
| <select id="getById" parameterType="com.iformall.domain.po.WxThirdPartyOrders" resultMap="BaseResultMap"> | |||
| select | |||
| <include refid="allColumns"/> | |||
| from ali_business_circle_order | |||
| where `id` = #{id} | |||
| and tenant_id=#{tenantId} | |||
| </select> | |||
| <select id="getOrderByTransactionId" parameterType="com.iformall.domain.po.WxThirdPartyOrders" resultMap="BaseResultMap"> | |||
| select | |||
| <include refid="allColumns"/> | |||
| from ali_business_circle_order | |||
| where `is_refund` = 0 | |||
| and tenant_id = #{tenantId} | |||
| and `transaction_id` = #{transactionId} | |||
| </select> | |||
| <select id="getRefundOrderByTransactionId" parameterType="com.iformall.domain.po.WxThirdPartyOrders" resultMap="BaseResultMap"> | |||
| select | |||
| <include refid="allColumns"/> | |||
| from ali_business_circle_order | |||
| where `is_refund` = 1 | |||
| and tenant_id = #{tenantId} | |||
| and `transaction_id` = #{transactionId} | |||
| </select> | |||
| <insert id="insertNoticeOrder" parameterType="com.iformall.domain.po.WxThirdPartyOrders" > | |||
| 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 | |||
| ); | |||
| </insert> | |||
| <update id="updatePoints" parameterType="com.iformall.domain.po.WxThirdPartyOrders"> | |||
| 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} | |||
| </update> | |||
| <insert id="insertRefundNoticeOrder" parameterType="com.iformall.domain.po.WxThirdPartyOrders" > | |||
| 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} | |||
| ); | |||
| </insert> | |||
| </mapper> | |||
| @@ -5,20 +5,30 @@ | |||
| <id column="id" jdbcType="BIGINT" property="id"/> | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/> | |||
| <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" /> | |||
| <result column="source_app_id" jdbcType="VARCHAR" property="sourceAppId"/> | |||
| <result column="source_type" jdbcType="INTEGER" property="sourceType"/> | |||
| <result column="notice_id" jdbcType="VARCHAR" property="noticeId" /> | |||
| <result column="notice_create_time" jdbcType="TIMESTAMP" property="noticeCreateTime"/> | |||
| <result column="notice_event_type" jdbcType="VARCHAR" property="noticeEventType" /> | |||
| <result column="notice_resource_type" jdbcType="VARCHAR" property="noticeResourceType" /> | |||
| <result column="summary" jdbcType="VARCHAR" property="summary" /> | |||
| <result column="shop_name" jdbcType="VARCHAR" property="shopName" /> | |||
| <result column="shop_number" jdbcType="VARCHAR" property="shopNumber" /> | |||
| <result column="user_phone" jdbcType="VARCHAR" property="userPhone" /> | |||
| <result column="user_number" jdbcType="VARCHAR" property="userNumber" /> | |||
| <result column="time_end" jdbcType="TIMESTAMP" property="timeEnd"/> | |||
| <result column="amount" jdbcType="INTEGER" property="amount"/> | |||
| <result column="pay_amount" jdbcType="INTEGER" property="payAmount"/> | |||
| <result column="transaction_id" jdbcType="VARCHAR" property="transactionId" /> | |||
| <result column="summary" jdbcType="VARCHAR" property="summary" /> | |||
| <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/> | |||
| <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/> | |||
| <result column="merchant_id" jdbcType="BIGINT" property="merchantId"/> | |||
| <result column="c_user_id" jdbcType="BIGINT" property="cUserId"/> | |||
| @@ -26,25 +36,20 @@ | |||
| <result column="increased_points" jdbcType="INTEGER" property="increasedPoints"/> | |||
| <result column="points_update_time" jdbcType="TIMESTAMP" property="pointsUpdateTime"/> | |||
| <result column="is_refund" jdbcType="TINYINT" property="isRefund"/> | |||
| <result column="refund_summary" jdbcType="VARCHAR" property="refundSummary" /> | |||
| <result column="refund_time" jdbcType="TIMESTAMP" property="refundTime"/> | |||
| <result column="refund_amount" jdbcType="INTEGER" property="refundAmount"/> | |||
| <result column="refund_id" jdbcType="VARCHAR" property="refundId" /> | |||
| <result column="is_refund_points" jdbcType="TINYINT" property="isRefundPoints"/> | |||
| <result column="refund_points_time" jdbcType="TIMESTAMP" property="refundPointsTime"/> | |||
| <result column="refund_amount" jdbcType="INTEGER" property="refundAmount"/> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `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` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -85,6 +90,10 @@ | |||
| and `user_number` = #{userNumber} | |||
| </if> | |||
| <if test=" null != noticeId and '' != noticeId"> | |||
| and `notice_id` = #{noticeId} | |||
| </if> | |||
| <if test=" null != startTime "> | |||
| and `time_end` >= #{startTime} | |||
| </if> | |||
| @@ -116,10 +125,6 @@ | |||
| and `refund_id` = #{refundId} | |||
| </if> | |||
| <if test=" null != isRefundPoints"> | |||
| and `is_refund_points` = #{isRefundPoints} | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and `id` in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
| @@ -144,46 +149,57 @@ | |||
| and tenant_id=#{tenantId} | |||
| </select> | |||
| <select id="getByTransactionId" parameterType="com.iformall.domain.po.WxThirdPartyOrders" resultMap="BaseResultMap"> | |||
| <select id="getOrderByTransactionId" parameterType="com.iformall.domain.po.WxThirdPartyOrders" resultMap="BaseResultMap"> | |||
| select | |||
| <include refid="allColumns"/> | |||
| 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} | |||
| </select> | |||
| <select id="getRefundOrderByTransactionId" parameterType="com.iformall.domain.po.WxThirdPartyOrders" resultMap="BaseResultMap"> | |||
| select | |||
| <include refid="allColumns"/> | |||
| from wx_third_party_orders | |||
| where `is_refund` = 1 | |||
| and `sourceType` = #{sourceType} | |||
| and `tenant_id` = #{tenantId} | |||
| and `transaction_id` = #{transactionId} | |||
| </select> | |||
| <insert id="insertNoticeOrder" parameterType="com.iformall.domain.po.WxThirdPartyOrders" > | |||
| 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 | |||
| ); | |||
| </insert> | |||
| <update id="updateAddPoints" parameterType="com.iformall.domain.po.WxThirdPartyOrders"> | |||
| update wx_business_circle_order set | |||
| <update id="updatePoints" parameterType="com.iformall.domain.po.WxThirdPartyOrders"> | |||
| 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> | |||
| <update id="updateRefundNoticeOrder" parameterType="com.iformall.domain.po.WxThirdPartyOrders"> | |||
| 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> | |||
| <update id="updateRefundPoints" parameterType="com.iformall.domain.po.WxThirdPartyOrders"> | |||
| update wx_business_circle_order set | |||
| `is_refund_points` = 1, `refund_points_time` = #{refundPointsTime}, `update_time` = #{updateTime} | |||
| where `id` = #{id} and `tenant_id` = #{tenantId} | |||
| </update> | |||
| <insert id="insertRefundNoticeOrder" parameterType="com.iformall.domain.po.WxThirdPartyOrders" > | |||
| 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} | |||
| ); | |||
| </insert> | |||
| </mapper> | |||