diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/rent/WxBillAllController.java b/mallinkAdmin/src/main/java/com/iformall/controller/rent/WxBillAllController.java index 3381df541..c8cb55ca1 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/rent/WxBillAllController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/rent/WxBillAllController.java @@ -30,7 +30,6 @@ import com.iformall.enums.EnumYesOrNo; import com.iformall.service.ExcelService; import com.iformall.service.SysConfigService; import com.iformall.service.WxBillActionService; -import com.iformall.service.WxBillAllService; import com.iformall.service.WxMerchantService; import com.iformall.service.WxPayAccountBillService; import com.iformall.service.helper.WxBillAllHelper; @@ -60,8 +59,8 @@ import java.util.Map; @RestController @RequestMapping("wxBillAll") public class WxBillAllController extends BillBaseController { - @Autowired - private WxBillAllService wxBillAllService; + //@Autowired + //private WxBillAllService wxBillAllService; private Logger logger = LoggerFactory.getLogger(WxBillAllController.class); @@ -98,10 +97,10 @@ public class WxBillAllController extends BillBaseController { wxMerchant.setFloorForRule(dataRule.getFloorIds()); wxMerchant.setBusinessForRule(dataRule.getBussinessIds()); } - return new ResultData(getVoPage(wxMerchant, pageNum, pageSize)); + return new ResultData(getVoPage(wxMerchant, pageNum, pageSize,null)); } - private PageInfo getVoPage(WxMerchant wxMerchant,Integer pageNum, Integer pageSize) { + private PageInfo getVoPage(WxMerchant wxMerchant,Integer pageNum, Integer pageSize , Integer billStaus) { Date starttime = wxMerchant.getStarttime(); Date enttime = wxMerchant.getEndtime(); wxMerchant.setStarttime(null); @@ -129,6 +128,7 @@ public class WxBillAllController extends BillBaseController { vo.setShopNumber(billAllHelper.getMerchantShopNumber(m)); wxMerchant.setId(m.getId()); + wxMerchant.setBillStatus(billStaus); WxBillSum rentSum = billAllHelper.getBillRentSum(wxMerchant,starttime, enttime); WxBillSum rentManageSum = billAllHelper.getBillRentManageSum(wxMerchant, starttime, enttime,null); WxBillSum rentDepositSum = billAllHelper.getBillDepositSum(wxMerchant, starttime, enttime); @@ -150,6 +150,9 @@ public class WxBillAllController extends BillBaseController { vo.setMaxDate(billAllHelper.getMaxDate(rentSum.getMaxDate(),rentManageSum.getMaxDate(),rentDepositSum.getMaxDate(),propertySum.getMaxDate(), propertyDepositSum.getMaxDate(),dailySum.getMaxDate(),otherSum.getMaxDate(),otherDepositSum.getMaxDate())); + vo.setReturnPay(billAllHelper.calcuteSum(rentSum.getReturnPay(),rentManageSum.getReturnPay(),rentDepositSum.getReturnPay(),propertySum.getReturnPay(), + propertyDepositSum.getReturnPay(),dailySum.getReturnPay(),otherSum.getReturnPay(),otherDepositSum.getReturnPay())); + retList.add(vo); } @@ -178,7 +181,7 @@ public class WxBillAllController extends BillBaseController { wxMerchant.setFloorForRule(dataRule.getFloorIds()); wxMerchant.setBusinessForRule(dataRule.getBussinessIds()); } - PageInfo page = getVoPage(wxMerchant, 1, 10000); + PageInfo page = getVoPage(wxMerchant, 1, 10000,null); excelService.exportExcel(page.getList(), null, "商户账单总览数据", WxMerchantBillVo.class, "商户账单总览数据.xlsx", response, false); } @@ -305,7 +308,7 @@ public class WxBillAllController extends BillBaseController { return new ResultData(Result.ERROR,"分类非法"); } } - return new ResultData(getBillList(wxMerchant, btype, null, pageNum, pageSize)); + return new ResultData(getBillList(wxMerchant, btype, true,null, pageNum, pageSize)); } @GetMapping("nearBillList") @@ -325,17 +328,19 @@ public class WxBillAllController extends BillBaseController { return new ResultData(Result.ERROR,"分类非法"); } } - return new ResultData(getBillList(wxMerchant, btype, getNearBillBeforeDays(), pageNum, pageSize)); + return new ResultData(getBillList(wxMerchant, btype, true,getNearBillBeforeDays(), pageNum, pageSize)); } - private PageInfo getBillList(WxMerchant wxMerchant,EnumBillAllType btype,Integer nearBillBeforeDays, Integer pageNum, Integer pageSize) { + private PageInfo getBillList(WxMerchant wxMerchant,EnumBillAllType btype,boolean isOwe,Integer nearBillBeforeDays, Integer pageNum, Integer pageSize) { wxMerchant.updateTenantInfo(getTenantInfo()); WxUserDataRule dataRule = this.getCurrentDataFloors(); if (null != dataRule) { wxMerchant.setFloorForRule(dataRule.getFloorIds()); wxMerchant.setBusinessForRule(dataRule.getBussinessIds()); } - wxMerchant.setOweBillBeforeDays(getOweBillBeforeDays()); + if (isOwe) { + wxMerchant.setOweBillBeforeDays(getOweBillBeforeDays()); + } wxMerchant.setNearBillBeforeDays(nearBillBeforeDays); return billAllHelper.getBillList(btype, wxMerchant,pageNum,pageSize); @@ -362,7 +367,7 @@ public class WxBillAllController extends BillBaseController { return ; } } - PageInfo page = getBillList(wxMerchant, btype, null, 1, 10000); + PageInfo page = getBillList(wxMerchant, btype, true,null, 1, 10000); if (null == page) { return; } @@ -384,7 +389,7 @@ public class WxBillAllController extends BillBaseController { return ; } } - PageInfo page = getBillList(wxMerchant, btype, getNearBillBeforeDays(), 1, 10000); + PageInfo page = getBillList(wxMerchant, btype, true,getNearBillBeforeDays(), 1, 10000); if (null == page) { return; } @@ -655,6 +660,40 @@ public class WxBillAllController extends BillBaseController { return new ResultData(retMap); } + //退租列表 + @GetMapping("tuizujs") + @ApiImplicitParams({ + @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), + @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) + public ResultData tuizujs(@ModelAttribute WxMerchant wxMerchant, Integer pageNum, Integer pageSize) { + wxMerchant.updateTenantInfo(getTenantInfo()); + WxUserDataRule dataRule = this.getCurrentDataFloors(); + if (null != dataRule) { + wxMerchant.setFloorForRule(dataRule.getFloorIds()); + wxMerchant.setBusinessForRule(dataRule.getBussinessIds()); + } + return new ResultData(getVoPage(wxMerchant, pageNum, pageSize,EnumBillStatus.STOP_TO_SETTLE.getCode())); + } + + //商户待结算账单 + @GetMapping("settleList") + public ResultData settleList(@ModelAttribute WxMerchant wxMerchant,Integer billType) { + if (null == billType || null == wxMerchant.getId()) { + return new ResultData(Result.ERROR,"参数错误"); + } + EnumBillAllType btype; + if (billType.intValue() == Constant.bill_all_type_manage_fee) { + btype = EnumBillAllType.RENT_BUSSINESS_MANAGE; + }else { + btype = EnumBillAllType.getEnum(billType); + if (null == btype) { + return new ResultData(Result.ERROR,"分类非法"); + } + } + wxMerchant.setBillStatus(EnumBillStatus.STOP_TO_SETTLE.getCode()); + return new ResultData(getBillList(wxMerchant, btype, false,getNearBillBeforeDays(), 1, 100)); + } + //###################################### 老代码 ###################################### // diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxBillDaily.java b/mallinkService/src/main/java/com/iformall/domain/po/WxBillDaily.java index 58e051105..db45c3a90 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxBillDaily.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillDaily.java @@ -134,6 +134,11 @@ public class WxBillDaily extends WxBillBaseEntity { return remark; } + @Override + public String getReturnPay() { + return "0"; + } + @Override public String getBillLatePay() { return "0"; diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxBillDeposit.java b/mallinkService/src/main/java/com/iformall/domain/po/WxBillDeposit.java index 774d7beee..79dc9cfac 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxBillDeposit.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillDeposit.java @@ -106,6 +106,11 @@ public class WxBillDeposit extends WxBillBaseEntity { return ""; } + @Override + public String getReturnPay() { + return this.returnPrice; + } + @Override public String getBillLatePay() { return "0"; diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxBillOther.java b/mallinkService/src/main/java/com/iformall/domain/po/WxBillOther.java index 088c0c24d..d3578c463 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxBillOther.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillOther.java @@ -126,6 +126,11 @@ public class WxBillOther extends WxBillBaseEntity { return StringUtils.trimToEmpty(name)+StringUtils.trimToEmpty(comments); } + @Override + public String getReturnPay() { + return "0"; + } + @Override public String getBillLatePay() { return "0"; diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxBillOtherDeposit.java b/mallinkService/src/main/java/com/iformall/domain/po/WxBillOtherDeposit.java index a2878e22c..36d26cf79 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxBillOtherDeposit.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillOtherDeposit.java @@ -143,6 +143,11 @@ public class WxBillOtherDeposit extends WxBillBaseEntity { return StringUtils.trimToEmpty(name)+StringUtils.trimToEmpty(comments); } + @Override + public String getReturnPay() { + return this.returnPrice; + } + @Override public String getBillLatePay() { return "0"; diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxBillProperty.java b/mallinkService/src/main/java/com/iformall/domain/po/WxBillProperty.java index 42440e8c5..2dbf6a0d8 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxBillProperty.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillProperty.java @@ -160,6 +160,11 @@ public class WxBillProperty extends WxBillBaseEntity { return ""; } + @Override + public String getReturnPay() { + return "0"; + } + @Override public String getBillLatePay() { return latePayPrice; diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxBillPropertyDeposit.java b/mallinkService/src/main/java/com/iformall/domain/po/WxBillPropertyDeposit.java index 69104e806..59370ecd3 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxBillPropertyDeposit.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillPropertyDeposit.java @@ -119,6 +119,11 @@ public class WxBillPropertyDeposit extends WxBillBaseEntity { return ""; } + @Override + public String getReturnPay() { + return this.returnPrice; + } + @Override public String getBillLatePay() { return "0"; diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxBillRent.java b/mallinkService/src/main/java/com/iformall/domain/po/WxBillRent.java index 85c778765..c4de32332 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxBillRent.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillRent.java @@ -103,6 +103,11 @@ public class WxBillRent extends WxBillBaseEntity { return ""; } + @Override + public String getReturnPay() { + return "0"; + } + @Override public String getBillLatePay() { return latePayPrice; diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxBillRentManage.java b/mallinkService/src/main/java/com/iformall/domain/po/WxBillRentManage.java index c4e5844e3..5d4162ef8 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxBillRentManage.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillRentManage.java @@ -177,6 +177,11 @@ public class WxBillRentManage extends WxBillBaseEntity { return ""; } + @Override + public String getReturnPay() { + return "0"; + } + @Override public String getBillLatePay() { return latePayPrice; diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxMerchant.java b/mallinkService/src/main/java/com/iformall/domain/po/WxMerchant.java index c79a96c06..d11191e4e 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxMerchant.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxMerchant.java @@ -456,5 +456,9 @@ public class WxMerchant extends TenantEntity { @TableField(exist = false) private Integer nearBillBeforeDays; + //账单状态 + @TableField(exist = false) + private Integer billStatus; + } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/base/WxBillBaseEntity.java b/mallinkService/src/main/java/com/iformall/domain/po/base/WxBillBaseEntity.java index a41fcf5eb..0794de161 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/base/WxBillBaseEntity.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/base/WxBillBaseEntity.java @@ -88,6 +88,10 @@ public class WxBillBaseEntity extends TenantEntity { @TableField(exist = false) protected Integer billType; + //已退款金额 + @TableField(exist = false) + protected String returnPay; + @Excel(name = "备注", width = 20, orderNum = "9") @io.swagger.annotations.ApiModelProperty(value="备注",name="billRemark") @TableField(exist = false) diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/WxBillSum.java b/mallinkService/src/main/java/com/iformall/domain/vo/WxBillSum.java index 6a9caea85..f9a4ce315 100644 --- a/mallinkService/src/main/java/com/iformall/domain/vo/WxBillSum.java +++ b/mallinkService/src/main/java/com/iformall/domain/vo/WxBillSum.java @@ -30,6 +30,21 @@ public class WxBillSum implements Serializable { private Date minDate; private Date maxDate; + + //手续费 + private String servicePay = "0"; + @TableField(exist = false) + private BigDecimal servicePayNumber; + + //滞纳金 + private String latePay = "0"; + @TableField(exist = false) + private BigDecimal latePayNumber; + + //已退回金额 + private String returnPay = "0"; + @TableField(exist = false) + private BigDecimal returnPayNumber; public BigDecimal getNeedPayNumber() { if (StringUtils.isNotBlank(needPay)) { @@ -62,7 +77,36 @@ public class WxBillSum implements Serializable { return oweNumber; } + public BigDecimal getServicePayNumber() { + if (StringUtils.isNotBlank(servicePay)) { + this.servicePayNumber = new BigDecimal(servicePay); + }else { + this.servicePayNumber = new BigDecimal(0); + } + return servicePayNumber; + } + + public BigDecimal getLatePayNumber() { + if (StringUtils.isNotBlank(latePay)) { + this.latePayNumber = new BigDecimal(latePay); + }else { + this.latePayNumber = new BigDecimal(0); + } + return latePayNumber; + } + + public BigDecimal getNeedReturnNumber() { + if (StringUtils.isNotBlank(returnPay)) { + this.returnPayNumber = new BigDecimal(returnPay); + }else { + this.returnPayNumber = new BigDecimal(0); + } + return returnPayNumber; + } + @TableField(exist = false) private String billName; + @TableField(exist = false) + private Integer billType; } diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/WxMerchantBillVo.java b/mallinkService/src/main/java/com/iformall/domain/vo/WxMerchantBillVo.java index 2a4b3f125..7feee3152 100644 --- a/mallinkService/src/main/java/com/iformall/domain/vo/WxMerchantBillVo.java +++ b/mallinkService/src/main/java/com/iformall/domain/vo/WxMerchantBillVo.java @@ -50,6 +50,14 @@ public class WxMerchantBillVo implements Serializable { return StringUtils.isBlank(owe) ? "0" : new BigDecimal(owe).toPlainString(); } + private String returnPay; + @Excel(name = "已退款金额(元)", width = 20, orderNum = "7") + @TableField(exist = false) + private String returnPayNumber; + public String getReturnPayNumber() { + return StringUtils.isBlank(returnPay) ? "0" : new BigDecimal(returnPay).toPlainString(); + } + @Excel(name = "账单最小日期",format="yyyy-MM-dd", width = 20, orderNum = "7") private Date minDate; diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumBillStatus.java b/mallinkService/src/main/java/com/iformall/enums/EnumBillStatus.java index 12299a00e..3f3cb316f 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumBillStatus.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumBillStatus.java @@ -13,7 +13,7 @@ public enum EnumBillStatus { //RETURN(5, "已退还"), INVALID(6, "失效"), BAD(7, "坏账"), - STOP_TO_SETTLE(8,"商户停用待结算") + STOP_TO_SETTLE(8,"退租待结算") ; public static EnumBillStatus getEnum(Integer code) { diff --git a/mallinkService/src/main/java/com/iformall/service/helper/WxBillAllHelper.java b/mallinkService/src/main/java/com/iformall/service/helper/WxBillAllHelper.java index ab84563e2..864d2dc89 100644 --- a/mallinkService/src/main/java/com/iformall/service/helper/WxBillAllHelper.java +++ b/mallinkService/src/main/java/com/iformall/service/helper/WxBillAllHelper.java @@ -127,6 +127,7 @@ public class WxBillAllHelper { if (null != wxMerchant.getNearBillBeforeDays()) { bill.setNearBillLastTime(getDateBefore(wxMerchant.getNearBillBeforeDays())); } + bill.setStatus(wxMerchant.getBillStatus()); } public WxBillSum getBillRentSum(WxMerchant wxMerchant,Date starttime, Date enttime) { @@ -137,6 +138,7 @@ public class WxBillAllHelper { rentSum = new WxBillSum(); } rentSum.setBillName("租赁费用"); + rentSum.setBillType(EnumBillAllType.RENT.getCode()); return rentSum; } @@ -170,8 +172,16 @@ public class WxBillAllHelper { } if (null != manageFeeType) { rentManageSum.setBillName(manageFeeType.getMessage()); + if (manageFeeType == EnumRentContractManageFeeType.RENT_BUSSINESS_MANAGE_FEE) { + rentManageSum.setBillType(EnumBillAllType.RENT_BUSSINESS_MANAGE.getCode()); + }else if (manageFeeType == EnumRentContractManageFeeType.RENT_OPERATING_MANAGE_FEE) { + rentManageSum.setBillType(EnumBillAllType.RENT_OPERATION_MANAGE.getCode()); + }else { + rentManageSum.setBillType(EnumBillAllType.RENT_BUSSINESS_MANAGE.getCode()); + } }else { rentManageSum.setBillName("租赁营业&商业管理费费用"); + rentManageSum.setBillType(EnumBillAllType.RENT_BUSSINESS_MANAGE.getCode()); } return rentManageSum; } @@ -220,6 +230,7 @@ public class WxBillAllHelper { rentDepositSum = new WxBillSum(); } rentDepositSum.setBillName("租赁押金费用"); + rentDepositSum.setBillType(EnumBillAllType.RENT_DEPOSIT.getCode()); return rentDepositSum; } @@ -249,6 +260,7 @@ public class WxBillAllHelper { propertySum = new WxBillSum(); } propertySum.setBillName("物业费用"); + propertySum.setBillType(EnumBillAllType.PROPERTY.getCode()); return propertySum; } @@ -278,6 +290,7 @@ public class WxBillAllHelper { propertyDepositSum = new WxBillSum(); } propertyDepositSum.setBillName("物业押金费用"); + propertyDepositSum.setBillType(EnumBillAllType.PROPERTY_DEPOSIT.getCode()); return propertyDepositSum; } @@ -314,6 +327,7 @@ public class WxBillAllHelper { }else { dailySum.setBillName("日藏水电空调费用"); } + dailySum.setBillType(EnumBillAllType.DAILY.getCode()); return dailySum; } @@ -346,6 +360,7 @@ public class WxBillAllHelper { otherSum = new WxBillSum(); } otherSum.setBillName("其他费用"); + otherSum.setBillType(EnumBillAllType.OTHER.getCode()); return otherSum; } @@ -375,6 +390,7 @@ public class WxBillAllHelper { otherDepositSum = new WxBillSum(); } otherDepositSum.setBillName("其他押金费用"); + otherDepositSum.setBillType(EnumBillAllType.OTHER_DEPOSIT.getCode()); return otherDepositSum; } 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 730694164..4958398c1 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java @@ -1,2302 +1,2301 @@ -package com.iformall.service.impl; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.github.pagehelper.PageHelper; -import com.github.pagehelper.PageInfo; -import com.iformall.common.ErrorCode; -import com.iformall.common.IdWorker; -import com.iformall.common.Result; -import com.iformall.common.ResultData; -import com.iformall.domain.dto.WxCouponMerchantDto; -import com.iformall.domain.po.*; -import com.iformall.domain.po.base.BaseEntity; -import com.iformall.domain.po.base.TenantEntity; -import com.iformall.domain.po.msg.FmInsideProductPushMsg; -import com.iformall.domain.vo.*; -import com.iformall.domain.vo.excel.WxCardData; -import com.iformall.domain.vo.excel.WxCouponData; -import com.iformall.domain.vo.excel.WxPressData; -import com.iformall.douyin.pay.enums.MerchantImportStatus; -import com.iformall.douyin.pay.orderQuery.QueryMerchantResult; -import com.iformall.douyin.web.bean.GoodsTemplateGet; -import com.iformall.enums.*; -import com.iformall.exception.MallinkException; -import com.iformall.mapper.*; -import com.iformall.mq.MqBaseProducer; -import com.iformall.service.*; -import com.iformall.service.excel.WxCardDataExporter; -import com.iformall.service.excel.WxCouponDataExporter; -import com.iformall.service.excel.WxPressDataExporter; -import com.iformall.service.pay.PayServiceFactory; -import com.iformall.service.pay.service.share.PayShareAdapterService; -import com.iformall.utils.Constant; -import com.iformall.utils.DateUtils; -import org.apache.commons.beanutils.BeanUtils; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.annotation.Lazy; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Isolation; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.math.BigDecimal; -import java.util.*; -import java.util.stream.Collectors; - -import static java.util.stream.Collectors.toList; - - -@Service -public class WxCouponServiceImpl implements WxCouponService { - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - - @Autowired - WxCouponMapper wxCouponMapper; - - @Autowired - WxCouponMerchantMapper wxCouponMerchantMapper; - - @Autowired - WxMerchantMapper wxMerchantMapper; - - @Autowired - WxMerchantService wxMerchantService; - - @Lazy - @Autowired - WxCouponChannelService wxCouponChannelService; - - @Lazy - @Autowired - WxCouponSendService wxCouponSendService; - - @Lazy - @Autowired - WxOrderService wxOrderService; - - @Lazy - @Autowired - WxScreenAdService wxScreenAdService; - - @Autowired - WxCouponChannelMapper wxCouponChannelMapper; - - @Autowired - WxCardInfoMapper wxCardInfoMapper; - - @Autowired - WxCouponPasswordMapper couponPasswordMapper; - - @Autowired - WxCouponPasswordService couponPasswordService; - - @Autowired - WxPayAccountMapper payAccountMapper; - - @Autowired - WxPayAccountService payAccountService; - - @Autowired - WxCouponOrderMapper wxCouponOrderMapper; - - @Autowired - WxCardTransferInfoMapper wxCardTransferInfoMapper; - - @Autowired - ExcelService excelService; - - @Autowired - WxCardDataExporter cardDataExporter; - - @Autowired - WxCouponDataExporter couponDataExporter; - - @Autowired - WxPressDataExporter pressDataExporter; - - @Autowired - @Qualifier("couponChannelRedisTemplate") - RedisTemplate> cdRedisTemplate; - - @Autowired - WxProfitSharingReceiverMapper wxProfitSharingReceiverMapper; - - @Autowired - private TtGoodsCategoryService ttGoodsCategoryService; - - @Autowired - private TtMerchantPoiService ttMerchantPoiService; - - @Autowired - WxAppinfoService wxAppinfoService; - - @Autowired - private MqBaseProducer mqBaseProducer; - - @Autowired - PayServiceFactory payServiceFactory; - - @Autowired - TtCouponChannelPoiMapper ttCouponChannelPoiMapper; - - @Autowired - WxCouponMallMapper wxCouponMallMapper; - - @Autowired - WxMallMapper wxMallMapper; - - @Autowired - WxCardDailyLogService wxCardDailyLogService; - - @Override - public ResultData list(TenantEntity tenantEntity,WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { - if (null == wxCoupon) wxCoupon = new WxCoupon(); - wxCoupon.updateTenantInfo(tenantEntity); - handCouponList(wxCoupon); - - //除了a端列表 其他默认需要过滤 - if(!EnumFilterPut.NO.equals(wxCoupon.getFilterCanPut())) { - WxCoupon couponModel = wxCouponMapper.findCouponModel(wxCoupon); - if (couponModel != null) { - wxCoupon.setCouponModelId(couponModel.getCouponModelId()); - wxCoupon.setCardModelId(couponModel.getCardModelId()); - wxCoupon.setGroupModelId(couponModel.getGroupModelId()); - wxCoupon.setPressModelId(couponModel.getPressModelId()); - } - } - - PageInfo page = listAsPage(wxCoupon, pageNum, pageSize); - - List wxCouponList = page.getList(); - - if (wxCouponList.isEmpty() || wxCoupon.getTargetAd() != null) { - return new ResultData(page); - } - - List ids = wxCouponList.stream().map(p -> p.getId()).collect(toList()); - - //处理抖音草稿数据 - Map draftStatusMap = new HashMap<>(); - if(EnumAppPlat.TOUTIAO.getCode().equals(wxCoupon.getPlat())){ - List draftStatus = wxCouponMapper.findDraftStatus(tenantEntity.getTenantId(),ids); - for (TtCouponVo vo:draftStatus) { - draftStatusMap.put(vo.getCouponId(),vo); - } - } - - - - WxCouponChannel wxCouponChannel = new WxCouponChannel(); - wxCouponChannel.updateTenantInfo(wxCoupon); - wxCouponChannel.setCouponIds(ids); - wxCouponChannel.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode()); - //上架状态 - List list = wxCouponChannelMapper.findList(wxCouponChannel); - if (!list.isEmpty()) { - Map> groupBy = list.stream().collect(Collectors.groupingBy(WxCouponChannel::getCouponId)); - for (WxCoupon temp: wxCouponList) { - if(!draftStatusMap.isEmpty()){ - TtCouponVo draft = draftStatusMap.get(temp.getId()); - if(draft != null){ - temp.setDraftPoiStatus(draft.getPoiStatus()); - temp.setDraftStatusDesc(draft.getStatusDesc()); - } - } - - if (groupBy.get(temp.getId()) != null) { - List channels = new ArrayList<>(); - for (WxCouponChannel tempchannel : groupBy.get(temp.getId())) { - if (!channels.contains(tempchannel.getTargetAd())) { - channels.add(tempchannel.getTargetAd()); - } - } - String sss = JSON.toJSONString(channels); - temp.setChannels(sss); - } else { - temp.setChannels(""); - } - - } - } else { - for (WxCoupon temp : wxCouponList) { - temp.setChannels(""); - } - - } - return new ResultData(page); - } - - - private void handCouponList(WxCoupon wxCoupon){ - //默认排序 - if(StringUtils.isBlank(wxCoupon.getSortColumns())){ - wxCoupon.setSortColumns(BaseEntity.SortField.CCreateDate_DESC, BaseEntity.SortField.CId_DESC); - } - if (wxCoupon.getStatus() != null && wxCoupon.getStatus() == -1){ - wxCoupon.setStatus(null); - } - //门店处理 - if(wxCoupon.getMerchantId() != null){ - List merchantIds = new ArrayList(); - merchantIds.add(wxCoupon.getMerchantId()); - List mcids = wxCouponMerchantMapper.findMerchantProductIds(wxCoupon.getTenantId(), merchantIds,0); - if(mcids == null || mcids.isEmpty()){ - wxCoupon.setId(-999L); - return; - }else{ - wxCoupon.setIds(mcids); - } - } - - //券类型处理 - if(wxCoupon.getType() != null){ - if(wxCoupon.getPlat() == null){ - wxCoupon.setPlat(EnumCouponType.getAppPlat(wxCoupon.getType()).getCode()); - } - }else{ - List types = new ArrayList<>(); - if(wxCoupon.getTypes() != null && !wxCoupon.getTypes().isEmpty()){ - types.addAll(wxCoupon.getTypes()); - } - if(wxCoupon.getTargetAd() != null){ - if(wxCoupon.getPlat() == null){ - wxCoupon.setPlat(EnumCouponChannelType.getAppPlat(wxCoupon.getTargetAd()).getCode()); - } - if(EnumAppPlat.TOUTIAO.getCode().equals(wxCoupon.getPlat())){ - //渠道查询时只查询审核通过的 - wxCoupon.setPoiStatus(EnumSpuSyncStatus.sync_put_on.getCode()); - } - List couponTypes = EnumCouponChannelType.getCouponTypeBy(wxCoupon.getTargetAd()); - if(couponTypes.isEmpty()){ - wxCoupon.setId(-999L); - return; - }else{ - if(types == null || types.isEmpty()){ - types = couponTypes; - }else{ - types.retainAll(couponTypes); - if(types.isEmpty()){ - wxCoupon.setId(-999L); - return; - } - } - } - } - if(wxCoupon.getPlat() == null){ - //默认查微信平台 - wxCoupon.setPlat(EnumAppPlat.WX.getCode()); - } - - List typeCode = EnumCouponType.getTypeCode(wxCoupon.getPlat()); - if(types == null || types.isEmpty()){ - types = typeCode; - }else{ - types.retainAll(typeCode); - if(types.isEmpty()){ - wxCoupon.setId(-999L); - return; - } - } - wxCoupon.setTypes(types); - } - - } - - - @Override - public List list(WxCoupon wxCoupon){ - return wxCouponMapper.findList(wxCoupon); - } - - @Override - public PageInfo simplelistAsPage(WxCoupon record, Integer pageNum, Integer pageSize) { - return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> wxCouponMapper.findList(record)); - } - - @Override - public PageInfo listAsPage(WxCoupon record, Integer pageIndex, Integer pageSize) { - int total = wxCouponMapper.findCouponListCount(record); - int pages; - if(total % pageSize == 0){ - pages = total / pageSize; - }else{ - pages = total / pageSize +1; - } - record.setLimitStart((pageIndex -1) * pageSize); - record.setLimitEnd(pageSize); - List list = wxCouponMapper.findCouponList(record); - - PageHelper.startPage(pageIndex, pageSize); - PageInfo pageInfo = new PageInfo<>(list); - pageInfo.setPages(pages); - pageInfo.setTotal(total); - PageHelper.clearPage(); - return pageInfo; - } - - - @Override - public PageInfo findCountData(WxCoupon record, List tenantEntitys, Integer pageNum, Integer pageSize) { - return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> wxCouponMapper.findCountData(tenantEntitys,record)); - } - - @Override - public void exportCardData(WxCoupon record, List tenantEntitys, HttpServletRequest request, - HttpServletResponse response) { - Map map = new HashMap(); - map.put("record", record); - map.put("tenantEntitys", tenantEntitys); - excelService.exportBigExcel(cardDataExporter,map, null, "卡营销数据信息", WxCardData.class, "卡营销数据.xlsx", response, false); - } - - @Override - public WxCoupon getById(Long id,String tenantId) { - return wxCouponMapper.selectById(id,tenantId); - } - - @Override - public WxCoupon getPriceAndStock(Long id,String tenantId) { - return wxCouponMapper.getPriceAndStock(id,tenantId); - } - - @Override - public List getPriceAndStock(List ids,String tenantId) { - return wxCouponMapper.batchGetPriceAndStock(ids,tenantId); - } - - @Override - public WxCoupon getHtmlById(Long id,String tenantId) { - return wxCouponMapper.selectById(id,tenantId); - } - - @Override - public WxCouponCVo getVoById(Long id,String couponTenantId,TenantEntity mallTenantEntity) { - WxCouponCVo wxCouponCVo = wxCouponMapper.findVoDetail(id,couponTenantId); - - if(wxCouponCVo == null){ - return null; - } - - List merchantList = getMerchantVoList(wxCouponCVo, mallTenantEntity, wxCouponCVo.getId(), wxCouponCVo.getType()); - - wxCouponCVo.setMerchantVoList(merchantList); - if(EnumCouponType.COUPON_GIFT.getCode().equals(wxCouponCVo.getType())){ - WxCoupon coupon = new WxCoupon(); - coupon.updateTenantInfo(wxCouponCVo); - List longs = JSON.parseArray(wxCouponCVo.getGiftList(), Long.class); - if(longs != null && longs.size() > 0){ - coupon.setIds(longs); - wxCouponCVo.setGiftCouponList(wxCouponMapper.findList(coupon)); - } - } - - return wxCouponCVo; - } - - private List getMerchantVoList(TenantEntity couponTenant,TenantEntity mallTenant,Long couponId,Integer couponType){ - if (EnumCouponType.isParentCoupon(couponType)){ - //集团查券 查询所有门店 - if(couponTenant.getTenantId().equals(mallTenant.getTenantId())){ - WxCouponMall couponMall = new WxCouponMall(); - couponMall.updateTenantInfo(couponTenant); - couponMall.setProductId(couponId); - List couponMallList = wxCouponMallMapper.findList(couponMall); - List merchantVoList = new ArrayList<>(); - if (null != couponMallList && couponMallList.size()> 0 ) { - for (WxCouponMall cm:couponMallList) { - WxMall mall = wxMallMapper.getByTenantId(cm.getMallTenantId()); - List couponMerchantList = getCouponMerchantList(couponId,null, mall); - if(couponMerchantList != null && couponMerchantList.size() > 0){ - merchantVoList.addAll(couponMerchantList); - } - } - } - return merchantVoList; - //子广场查券 只查询自己广场的门店 - }else{ - return getCouponMerchantList(couponId,null,mallTenant); - } - }else{ - return getCouponMerchantList(couponId,null,couponTenant); - } - } - - @Override - public WxCouponCVo getVoStatusById(Long id,String tenantId) { - WxCouponCVo wxCouponCVo = wxCouponMapper.findVoStatusDetail(id,tenantId); - return wxCouponCVo; - } - - @Override - public WxCoupon getAttrsById(Long id, String tenantId) { - return wxCouponMapper.getAttrsById(id,tenantId); - } - - - private Long parseMerchantId(JSONObject merchantParam){ - if (!StringUtils.isBlank(merchantParam.getString("id"))){ - return Long.valueOf(merchantParam.getString("id")); - } - return null; - } - private String parseParameter(JSONObject merchantParam){ - return merchantParam.getString("parameter"); - } - private Integer parseBusiness(JSONObject merchantParam){ - String businessIdStr = merchantParam.getString("businessId"); - if ( !StringUtils.isBlank(businessIdStr)) { - return Integer.valueOf(businessIdStr); - } - return null; - } - private Integer parseSubBusiness(JSONObject merchantParam){ - String subBusinessIdStr = merchantParam.getString("subBusinessId"); - if (subBusinessIdStr != null) - return Integer.valueOf(subBusinessIdStr); - return null; - } - - private WxCouponMerchantDto parseMerchantParam(JSONObject merchantParam){ - WxCouponMerchantDto wxCouponMerchantDto = new WxCouponMerchantDto(); - try { - wxCouponMerchantDto.setMerchantId(parseMerchantId(merchantParam)); - wxCouponMerchantDto.setParameter(parseParameter(merchantParam)); - wxCouponMerchantDto.setBusiness(parseBusiness(merchantParam)); - wxCouponMerchantDto.setSubBusiness(parseSubBusiness(merchantParam)); - }catch (Exception e) { - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); - } - if (wxCouponMerchantDto.getMerchantId()==null) { - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); - } - return wxCouponMerchantDto; - } - - - @Override - @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) - public ResultData saveOrUpdate(WxCoupon record, MallUserInfo user) { - //金额处理 - if (StringUtils.isNotEmpty(record.getSalePriceStr())) { - record.setSalePrice(new BigDecimal(record.getSalePriceStr()).multiply(new BigDecimal(100)).intValue()); - } - if (StringUtils.isNotEmpty(record.getFreightPriceStr())) { - record.setFreightPrice(new BigDecimal(record.getFreightPriceStr()).multiply(new BigDecimal(100)).intValue()); - } - if (StringUtils.isNotEmpty(record.getUsePriceStr())) { - record.setUsePrice(new BigDecimal(record.getUsePriceStr()).multiply(new BigDecimal(100)).intValue()); - } - if (StringUtils.isNotEmpty(record.getPriceStr())) { - record.setPrice(new BigDecimal(record.getPriceStr()).multiply(new BigDecimal(100)).intValue()); - } - if (StringUtils.isNotEmpty(record.getTailPriceStr())) { - record.setTailPrice(new BigDecimal(record.getTailPriceStr()).multiply(new BigDecimal(100)).intValue()); - } - if (StringUtils.isNotEmpty(record.getOrigPriceStr())) { - record.setOrigPrice(new BigDecimal(record.getOrigPriceStr()).multiply(new BigDecimal(100)).intValue()); - } - if (StringUtils.isNotEmpty(record.getSubsidyNumStr())) { - record.setSubsidyNum(new BigDecimal(record.getSubsidyNumStr()).multiply(new BigDecimal(100)).intValue()); - } - //补贴处理 - if(record.getSubsidyType() == null){ - record.setSubsidyType(EnumCouponSubsidyType.NO_SUBSIDY.getCode()); - } - if(record.getSubsidyNum() == null || record.getSubsidyNum().intValue() == 0){ - record.setSubsidyType(EnumCouponSubsidyType.NO_SUBSIDY.getCode()); - record.setSubsidyNum(0); - } - if (EnumCouponSubsidyType.WECHAT_COUPON.getCode().equals(record.getSubsidyType())) { - if (EnumYesOrNo.YES.getCode() != record.getIsAfterSetPrice()) { - // 微信 立减 - if (record.getSubsidyNum() > record.getSalePrice()) { - return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "补贴额大于售价"); - } - } - } else if (EnumCouponSubsidyType.OFFLINE_SUBSIDY.getCode().equals(record.getSubsidyType())) { - if (EnumYesOrNo.YES.getCode() != record.getIsAfterSetPrice()) { - // 线下补贴 - int subsidy_num = record.getPrice() - record.getSalePrice(); - if (record.getSubsidyNum() > subsidy_num) { - return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "补贴额大于面额与售价的差值"); - } - } - } else if (EnumCouponSubsidyType.WECHAT_MCHPAY.getCode().equals(record.getSubsidyType())) { - // TODO 微信转账到银行卡 - - } - - if (EnumCouponContentType.HTML.getCode().equals(record.getContentType())) { - if (StringUtils.isEmpty(record.getHtml())) { - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请填写富文本内容"); - } - } - - if (StringUtils.isBlank(record.getCoverPicture())) { - List strList = new ArrayList(); - if (StringUtils.isNotBlank(record.getCoverImg())) { - strList.add(record.getCoverImg()); - } - if (strList.size() > 1) { - record.setCoverPicture(JSONArray.toJSONString(strList)); - } - } - //可配送商品永久有效 - if(EnumCouponType.COUPON_DISTRIBUTION.getCode().equals(record.getType())){ - record.setValidType(EnumCouponValidType.FOREVER.getCode()); - } - //券礼包有效期=售卖时间 - if(EnumCouponType.COUPON_GIFT.getCode().equals(record.getType())){ - record.setValidType(EnumCouponValidType.BETWEEN_TWO_TIME.getCode()); - record.setValidStartDate(record.getSoldStartTime()); - record.setValidEndDate(record.getSoldEndTime()); - } - - if (record.getValidType() != null) { - switch (EnumCouponValidType.getEnum(record.getValidType())) { - case FOREVER: - record.setValidStartDate(null); - record.setValidEndDate(null); - record.setValidDays(null); - break; - case DAYS_AFTER_RECEIVING: - record.setValidStartDate(null); - record.setValidEndDate(null); - break; - case BETWEEN_TWO_TIME: - record.setValidDays(null); - case TIME_AND_DAYS: - if (record.getSoldStartTime() != null && record.getSoldEndTime() != null) { - if (record.getValidStartDate().before(record.getSoldStartTime())) { - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "有效时间需在售卖期之后"); - } - if (record.getValidEndDate().before(record.getSoldEndTime())) { - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "有效时间需在售卖期之后"); - } - } - break; - default: - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请填写有效时间类型"); - } - - if(!this.validCouponDate(record)) { - return new ResultData(ResultData.ERROR,"券有效结束日期必须在售卖30天以内。"); - } - } - - ResultData giftResult = this.validGiftCouponDate(record); - if(Result.SUCCESS != giftResult.code){ - return giftResult; - } - - //判断直连检查收款帐号(必须),总分模式直接收款到小程序的收款帐号 - ResultData merchantResultData = checkCouponMakeMerchant(record); - if(Result.SUCCESS != merchantResultData.code){ - return merchantResultData; - } - - //平台券先不设置商户 - Map tenantMerchantMap = null; - if (EnumCouponType.checkCreateWithMerchants(record.getType())) { - try { - tenantMerchantMap = checkCouponMerchantReceiver(record, true); - }catch(MallinkException e){ - return new ResultData(e.getErrorCode(),e.getMessage()); - }catch(Exception e) { - return new ResultData(Result.ERROR,e.getMessage()); - } - } - if (EnumCouponType.checkCreateWithMalls(record.getType())) { - String[] mallTenantIds = record.getMallTenantIds(); - if (null == mallTenantIds || mallTenantIds.length <= 0 ) { - return new ResultData(Result.ERROR,"请选择商场"); - } - } - - final IdWorker idWorker = IdWorker.get(); - if (record.getId() == null) { - record.setId(idWorker.nextId()); - if(record.getCouponId() == null){ - record.setCouponId(record.getId()); - } - if (EnumCouponType.checkCreateWithMerchants(record.getType())) { - for (Iterator it = tenantMerchantMap.keySet().iterator();it.hasNext();) { - TenantEntity mallTenant = it.next(); - String merchantParamListString = tenantMerchantMap.get(mallTenant); - List merchantParamList = JSONArray.parseArray(merchantParamListString, JSONObject.class); - merchantParamList.forEach(merchantParam -> { - WxCouponMerchant cm = new WxCouponMerchant(); - WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam); - cm.setId(idWorker.nextId()); - cm.updateTenantInfo(mallTenant); - cm.setMerchantId(wxCouponMerchantDto.getMerchantId()); - cm.setParameter(wxCouponMerchantDto.getParameter()); - cm.setProductId(record.getId()); - cm.setCreateDate(new Date()); - cm.setUpdateDate(new Date()); - cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); - wxCouponMerchantMapper.insert(cm); - }); - } - } - - if (EnumCouponType.checkCreateWithMalls(record.getType())) { - for (String mt : record.getMallTenantIds()) { - WxCouponMall mall = new WxCouponMall(); - mall.updateTenantInfo(record); - mall.setMallTenantId(mt); - mall.setProductId(record.getId()); - mall.setCreateDate(new Date()); - mall.setUpdateDate(new Date()); - //如果是直接设置到商户的,直接变为已完成 - if (EnumCouponType.checkCreateWithMerchants(record.getType())) { - mall.setStatus(EnumCouponMallStatus.FINISED.getCode()); - }else { - mall.setStatus(EnumCouponMallStatus.UNFINISED.getCode()); - } - wxCouponMallMapper.insert(mall); - } - } - - if (record.getPasswordSupport() != null && record.getPasswordSupport().equals(EnumCouponPasswordSupport.SUPPORTED.getCode())) { - // todo 生成卡密无法修改, 调整 - couponPasswordService.mkPasswords(record,user); - } - - record.setCreateDate(new Date()); - record.setUpdateDate(new Date()); - if (null == record.getBusiness()) { - record.setBusiness(Constant.default_business); - } - wxCouponMapper.insert(record); - - String remark = (user != null ? user.getUsername() : "") + "创建了卡[" + record.getTitle() + "]," + record.getInventory() + "张卡密"; - insertWxCardDailyLogInfo(user, record, true, remark); - - } else { - if(EnumCouponType.getDouYinType().contains(record.getType())){ - TtCouponChannelPoi ttCouponChannelPoi = ttCouponChannelPoiMapper.selectById(record.getTenantId(),record.getId()); - if(ttCouponChannelPoi != null && - (EnumSpuSyncStatus.sync_auditing.getCode().equals(ttCouponChannelPoi.getStatus()) - || EnumSpuSyncStatus.sync_put_on.getCode().equals(ttCouponChannelPoi.getStatus()))){ - return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"该券状态不允许修改"); - } - } - record.setRemainInventory(null); - record.setInventory(null); - -// if(record.getInventory() != null && record.getRemainInventory() != null) { -// // 库存修改检查 -// WxCoupon oldCoupon = wxCouponMapper.selectById(record.getId(),record.getTenantId()); -// if (Objects.equals(oldCoupon.getRemainInventory(), record.getRemainInventory())) { -// // 库存未变, 不更新库存 -// record.setRemainInventory(null); -// record.setInventory(null); -// } else { -// // TODO bug记录 -// logger.info("设置库存:record.getRemainInventory {},oldCoupon.getRemainInventory {},oldCoupon.getInventory {}", -// record.getRemainInventory(), oldCoupon.getRemainInventory(), oldCoupon.getInventory()); -// // 库存增加,要同时增加, 库存减少,要同时减少 -// record.setInventory(oldCoupon.getInventory() + record.getRemainInventory() - oldCoupon.getRemainInventory()); -// } -// } - - if (EnumCouponType.checkCreateWithMerchants(record.getType())) { - try { - updateCouponMerchants(record,idWorker); - } catch (Exception e) { - logger.error("updateCouponMerchants error.",e); - return new ResultData(Result.ERROR,"更新商户出错。"+e.getMessage()); - } - } - - if (EnumCouponType.checkCreateWithMalls(record.getType())) { - WxCouponMall couponMall = new WxCouponMall(); - couponMall.updateTenantInfo(record); - couponMall.setProductId(record.getId()); - List couponMallList = wxCouponMallMapper.findList(couponMall); - Map alreadyMallTenant = new HashMap(); - if (null != couponMallList && couponMallList.size() > 0 ) { - for (int i = 0 ; i < couponMallList.size() ; i ++) { - WxCouponMall c = couponMallList.get(i); - alreadyMallTenant.put(c.getMallTenantId(),c.getStatus()); - } - } - wxCouponMallMapper.delteAllByProductId(couponMall); - for (String mt : record.getMallTenantIds()) { - WxCouponMall mall = new WxCouponMall(); - mall.updateTenantInfo(record); - mall.setMallTenantId(mt); - mall.setProductId(record.getId()); - mall.setCreateDate(new Date()); - mall.setUpdateDate(new Date()); - Integer status = alreadyMallTenant.get(mt); - if (null != status ) { - mall.setStatus(status); - }else { - if (EnumCouponType.checkCreateWithMerchants(record.getType())) { - mall.setStatus(EnumCouponMallStatus.FINISED.getCode()); - }else { - mall.setStatus(EnumCouponMallStatus.UNFINISED.getCode()); - } - } - wxCouponMallMapper.insert(mall); - } - } - - record.setUpdateDate(new Date()); - if (null == record.getBusiness()) { - record.setBusiness(Constant.default_business); - } - wxCouponMapper.updateById(record); - } - - //清空缓存 - clearCIndexCache(record); - return new ResultData(record.getId()); - } - - private void updateCouponMerchants(WxCoupon record,final IdWorker idWorker) throws Exception { - Map tenantMerchantParmMap = checkCouponMerchantReceiver(record,false); - for (Iterator it = tenantMerchantParmMap.keySet().iterator();it.hasNext();) { - TenantEntity mallTenantEntity = it.next(); - WxCouponMerchant cmParam = new WxCouponMerchant(); - cmParam.updateTenantInfo(mallTenantEntity); - cmParam.setProductId(record.getId()); - List oldList = wxCouponMerchantMapper.findList(cmParam); - List merchantParamList = JSONArray.parseArray(tenantMerchantParmMap.get(mallTenantEntity),JSONObject.class); - merchantParamList.stream().forEach(merchantParam -> { - WxCouponMerchant cm = new WxCouponMerchant(); - WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam); - cm.updateTenantInfo(mallTenantEntity); - cm.setMerchantId(wxCouponMerchantDto.getMerchantId()); - cm.setProductId(record.getId()); - WxCouponMerchant rcm = wxCouponMerchantMapper.selectOne(new QueryWrapper<>(cm)); - if (rcm != null) { - rcm.setParameter(wxCouponMerchantDto.getParameter()); - rcm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); - rcm.setUpdateDate(new Date()); - wxCouponMerchantMapper.updateById(rcm); - }else { - cm.setId(idWorker.nextId()); - cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); - cm.setParameter(wxCouponMerchantDto.getParameter()); - cm.setCreateDate(new Date()); - cm.setUpdateDate(new Date()); - wxCouponMerchantMapper.insert(cm); - } - oldList.removeIf( - old->old.getProductId().equals(record.getId()) && - old.getMerchantId().equals(wxCouponMerchantDto.getMerchantId())); - }); - - oldList.stream().forEach(old->{ - old.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_INVALID.getCode()); - old.setUpdateDate(new Date()); - wxCouponMerchantMapper.updateById(old); - }); - } - - } - - //返回商场商户,key:商场tenant value:merchantParams - private Map checkCouponMerchantReceiver(WxCoupon record,boolean check) throws Exception{ - /* - * 父券对应子商场商户 - */ - if (EnumCouponType.isParentCoupon(record.getType())) { - if(EnumCouponType.COUPON_DOUYIN_BRAND.getCode().equals(record.getType())){ - handCouponMerchantParams(record); - } - if (StringUtils.isBlank(record.getChildMerchantParams())){ - throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空"); - } - List tenantMerchantParamList = JSONObject.parseArray(record.getChildMerchantParams(), JSONObject.class); - if(tenantMerchantParamList == null || tenantMerchantParamList.isEmpty()){ - throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空"); - } - Map retMap = new HashMap(); - String[] mallTenantIds = new String[tenantMerchantParamList.size()]; - int i = 0; - for (JSONObject o:tenantMerchantParamList) { - String mallTenantId = o.getString("tenantId"); - mallTenantIds[i] = mallTenantId; - String mallParentTenantId = record.getTenantId(); - String mallMerchantParams = o.getString("mallMerchantParams"); - TenantEntity mallTenantEntity = new TenantEntity(); - mallTenantEntity.setTenantId(mallTenantId); - mallTenantEntity.setParentTenantId(mallParentTenantId); - if (check) { - List merchantList = checkCouponOneMallMerchantReceiver(mallTenantEntity,mallMerchantParams,record); - } - retMap.put(mallTenantEntity, mallMerchantParams); - i++; - } - record.setMallTenantIds(mallTenantIds); - record.setBusiness(Constant.default_business); - return retMap; - }else { - if (check) { - List merchantList = checkCouponOneMallMerchantReceiver(record,record.getMerchantParams(),record); - if(merchantList.size() > 1){ - record.setBusiness(Constant.default_business); - }else{ - record.setBusiness(merchantList.get(0).getBusinessId()); - record.setSubBusiness(merchantList.get(0).getSubBusinessId()); - } - } - Map retMap = new HashMap(); - TenantEntity tenantEntity = new TenantEntity(); - tenantEntity.updateTenantInfo(record); - retMap.put(tenantEntity, record.getMerchantParams()); - record.setMallTenantIds(new String[]{tenantEntity.getTenantId()}); - return retMap; - } - } - - private void handCouponMerchantParams(WxCoupon record){ - List merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); - if(merchantParamList == null || merchantParamList.isEmpty()){ - throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空"); - } - - Map> map = new HashMap<>(); - for (JSONObject o:merchantParamList) { - String tenantId = o.getString("tenantId"); - if(StringUtils.isBlank(tenantId)){ - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"参数传递异常"); - } - List merchantParams = map.get(tenantId); - if(merchantParams == null){ - merchantParams = new ArrayList<>(); - } - merchantParams.add(o); - map.put(tenantId,merchantParams); - } - - List childMerchantParams = new ArrayList<>(); - for (Iterator it = map.keySet().iterator();it.hasNext();) { - JSONObject object = new JSONObject(); - String tenantId = it.next(); - object.put("tenantId",tenantId); - object.put("mallMerchantParams",map.get(tenantId)); - childMerchantParams.add(object); - } - record.setChildMerchantParams(JSON.toJSONString(childMerchantParams)); - } - - private List checkCouponOneMallMerchantReceiver(TenantEntity mallTenantEntity,String merchantParams,WxCoupon record) throws Exception { - List merchantParamList = JSONObject.parseArray(merchantParams, JSONObject.class); - if(merchantParamList == null || merchantParamList.isEmpty()){ - throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空"); - } - - List merchantIds = new ArrayList<>(); - for (JSONObject o:merchantParamList) { - merchantIds.add(o.getLong("id")); - } - WxMerchant merchantQ = new WxMerchant(); - merchantQ.updateTenantInfo(mallTenantEntity); - merchantQ.setIds(merchantIds); - List merchantList = wxMerchantService.findList(merchantQ); - if(merchantList.size() != merchantParamList.size()){ - throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_EQUAL.getCode(),"所属商户信息异常"); - } - List badMerchant = merchantList.stream().filter(m -> !EnumMerchantStatus.VALID.getCode().equals(m.getStatus())).collect(toList()); - if(badMerchant != null && !badMerchant.isEmpty()){ - List badNames = badMerchant.stream().map(WxMerchant::getName).collect(toList()); - throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_VALID.getCode(),JSONArray.toJSONString(badNames)+"被停用"); - } - - if(record.getSalePrice() != null && record.getSalePrice() > 0) { - EnumAppPlat plat = EnumCouponType.getAppPlat(record.getType()); - EnumPayWay payWay = EnumAppPlat.getPayWay(plat); - WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(mallTenantEntity,plat); - if (cAppInfo == null) { - throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); - } - WxPayAccount payAccount = payAccountMapper.selectById(cAppInfo.getPayId()); - if (payAccount == null) { - throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); - } - - //判断商户是否匹配poi - if (EnumAppPlat.TOUTIAO.equals(plat)) { - List badPoiNames = new ArrayList(); - for (WxMerchant merchant:merchantList) { - TtMerchantPoi byId = ttMerchantPoiService.getById(merchant.getId()); - if(byId == null || !EnumSupplierMathStatus.match_success.getCode().equals(byId.getMatchStatus())){ - badPoiNames.add(merchant.getName()); - } - } - if(!badPoiNames.isEmpty()){ - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), JSONArray.toJSONString(badPoiNames)+"未匹配poi"); - } - } - - EnumPayMchType payMchType = EnumPayMchType.getEnum(payAccount.getMchType()); - EnumPayShare isShare = EnumPayShare.getEnum(payAccount.getShare()); - - PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion()); - - List badNames = new ArrayList(); - if (EnumPayMchType.DIRECT.equals(payMchType)) { - //多商户券,抖音 直连 门店只有进件支付宝才能参加活动 todo - if(EnumAppPlat.TOUTIAO.equals(plat) && EnumCouponMerchantType.MULTIPLE_MERCHANT.getCode().equals(record.getMerchantType())){ - for (WxMerchant merchant:merchantList) { - WxProfitPaymentReceiver receiver = payShareServie.getPaymantReceiver(mallTenantEntity, merchant.getId()); - if (receiver == null) { - badNames.add(merchant.getName()); - }else{ - if(!MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus())){ - badNames.add(merchant.getName()); - } - } - } - } - -// WxMerchant makeMerchant = getDirectPayAccountMerchant(merchantList,record); -// if (null == makeMerchant) { -// throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "没有收款商户"); -// } -// record.setMakeMerchantId(makeMerchant.getId()); -// WxProfitSharingReceiver receiver = payShareServie.getReceiver(makeMerchant, makeMerchant.getId(), null, payMchType.getCode()); -// -// if (receiver == null) { -// throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "[\""+makeMerchant.getName()+"\"]未配置收款账户"); -// } - //如果是直连,抖音,多商户券必须只配置支付宝 -// if (EnumAppPlat.TOUTIAO.equals(plat)) { -// if (merchantList.size() > 1 ) { -// if (MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus()) && -// !MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus()) ) { -// }else { -// throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "[\""+makeMerchant.getName()+"\"]配置收款账户错误,多商户券主收款账户不能配置微信."); -// } -// }else { -// if (!MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus()) -// && !MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus()) -// && !MerchantImportStatus.improt_success.getCode().equals(receiver.getHzImportStatus())) { -// throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "[\""+makeMerchant.getName()+"\"]未配置收款账户"); -// } -// } -// } - } else if (EnumPayShare.YES.equals(isShare)) { - for (WxMerchant merchant:merchantList) { - boolean isBad = toTalPayMchTypeMerchantIsBad(payShareServie,payAccount,merchant.getName(),merchant.getId(),payMchType,plat); - if (isBad) { - badNames.add(merchant.getName()); - } - } - } - if(!badNames.isEmpty()){ - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), JSONArray.toJSONString(badNames)+"未配置分账账户"); - } - } - return merchantList; - } - - //直联模式收款商户 - private WxMerchant getDirectPayAccountMerchant(List merchantList,WxCoupon coupon) throws Exception{ - WxMerchant makeMerchant = null; - //平台券,集团商管商户 - if (EnumCouponType.COUPON_DOUYIN_PLAT.getCode() == coupon.getType()) { - //查询集团商管商户 - makeMerchant = wxMerchantService.findAdmin(coupon); - //品牌券,查询集团品牌商户 - }else if (EnumCouponType.COUPON_DOUYIN_BRAND.getCode() == coupon.getType()) { - makeMerchant = wxMerchantService.findBrandAdmin(coupon,coupon.getBrand()); - //商场券 - }else { - if(coupon.getMerchantType() == EnumCouponMerchantType.ONE_MERCHANT.getCode()){ - if (merchantList.size() == 1) { - makeMerchant = merchantList.get(0); - }else { - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "单商户券只能有一个商户"); - } - }else { - List adminMerchant = merchantList.stream().filter(m -> EnumMerchantAdmin.PUBLIC_ADMIN.getCode().equals(m.getIsAdmin())).collect(toList()); - if(adminMerchant == null || adminMerchant.isEmpty()){ - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "多门店券需包含一个商管商户"); - }else if(adminMerchant.size() > 1){ - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "多门店券只能包含一个商管商户"); - } - makeMerchant = adminMerchant.get(0); - } - } - return makeMerchant; - } - - //总分模式下不能分账的商户 - private boolean toTalPayMchTypeMerchantIsBad(PayShareAdapterService payShareServie,WxPayAccount payAccount, - String merchantName,Long merchantId,EnumPayMchType payMchType,EnumAppPlat plat) throws Exception { - WxProfitSharingReceiver receiver = payShareServie.getSharingReceiver(payAccount, merchantId, null, payMchType.getCode()); - if (receiver == null) { - return true; - } - if (EnumAppPlat.TOUTIAO.equals(plat)) {//抖音只能开通支付宝 - QueryMerchantResult openPayResult = payAccount.getOpenPayResult(); - if(!EnumYesOrNo.YES.getCode().equals(openPayResult.getAlipay()) - || EnumYesOrNo.YES.getCode().equals(openPayResult.getWx()) -// || EnumYesOrNo.YES.getCode().equals(openPayResult.getHz()) - ){ - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "分账模式设置错误"); - } - if(!MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus())){ - return true; - } - -// if(!EnumYesOrNo.YES.getCode().equals(openPayResult.getAlipay()) -// && !EnumYesOrNo.YES.getCode().equals(openPayResult.getWx()) -// && !EnumYesOrNo.YES.getCode().equals(openPayResult.getHz())){ -// throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "分账模式未设置开通支付渠道"); -// } -// if(EnumYesOrNo.YES.getCode().equals(openPayResult.getAlipay()) -// && !MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus())){ -// return true; -// } -// if(EnumYesOrNo.YES.getCode().equals(openPayResult.getWx()) -// && !MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus())){ -// return true; -// } -// if(EnumYesOrNo.YES.getCode().equals(openPayResult.getHz()) -// && !MerchantImportStatus.improt_success.getCode().equals(receiver.getHzImportStatus())){ -// return true; -// } - } - return false; - } - -// @Override -// @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) -// public ResultData setPrice(WxCoupon record) { -// Integer count = wxCouponMapper.setPrice(record); -// if (null == count || count <= 0 ) { -// return new ResultData(Result.ERROR,"设置失败"); -// } -// //设置卡密price -// WxCouponPassword couponPassword = new WxCouponPassword(); -// couponPassword.updateTenantInfo(record); -// couponPassword.setCouponId(record.getId()); -// couponPassword.setPrice(record.getPrice()); -// couponPasswordMapper.setPrice(couponPassword); -// return new ResultData(); -// } - - @Override - public ResultData updateTtProduct(WxCoupon record) { - if(EnumCouponType.getDouYinType().contains(record.getType())){ - TtCouponChannelPoi ttCouponChannelPoi = ttCouponChannelPoiMapper.selectById(record.getTenantId(),record.getId()); - if(ttCouponChannelPoi != null && - (EnumSpuSyncStatus.sync_auditing.getCode().equals(ttCouponChannelPoi.getStatus()) - || EnumSpuSyncStatus.sync_put_on.getCode().equals(ttCouponChannelPoi.getStatus()) - || EnumSpuSyncStatus.sync_audit_disable.getCode().equals(ttCouponChannelPoi.getStatus()))){ - return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"该券状态不允许修改"); - } - } - - if(StringUtils.isBlank(record.getProductAttrs()) || StringUtils.isBlank(record.getSkuAttrs())){ - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); - } - try{ - List productAttrs = JSONObject.parseArray(record.getProductAttrs(), GoodsTemplateGet.ProductAttrs.class); - List skuAttrs = JSONObject.parseArray(record.getSkuAttrs(), GoodsTemplateGet.ProductAttrs.class); - ttGoodsCategoryService.handDefaultAttr(record,productAttrs,skuAttrs); - for (GoodsTemplateGet.ProductAttrs attr:productAttrs) { - attr.setIsShow(null); - if(attr.getIsRequired() && StringUtils.isBlank(attr.getData())){ - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"product属性" +attr.getName()+" 为空"); - } - } - record.setProductAttrs(JSONObject.toJSONString(productAttrs)); - for (GoodsTemplateGet.ProductAttrs attr:skuAttrs) { - attr.setIsShow(null); - if(attr.getIsRequired() && StringUtils.isBlank(attr.getData())){ - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"sku属性 "+attr.getName()+" 为空"); - } - } - record.setSkuAttrs(JSONObject.toJSONString(skuAttrs)); - }catch(Exception e){ - logger.error(e.getMessage(),e); - return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR); - } - WxCoupon coupon = new WxCoupon(); - coupon.setId(record.getId()); - coupon.updateTenantInfo(record); - coupon.setProductType(record.getProductType()); - coupon.setCategoryId(record.getCategoryId()); - coupon.setProductAttrs(record.getProductAttrs()); - coupon.setSkuAttrs(record.getSkuAttrs()); - coupon.setUpdateDate(new Date()); - wxCouponMapper.updateById(coupon); - //清空缓存 - clearCIndexCache(record); - return new ResultData(record.getId()); - } - - - /** - * 清除c端首页券列表缓存 - * @param tenantEntity - */ - @Override - public void clearCIndexCache(TenantEntity tenantEntity){ - for (int i = 1; i <=5 ; i++) { - String key = EnumCacheKey.C_INDEX_PAGE_LIST.getMessage() +tenantEntity.getTenantId()+"_" + i + ":"; - cdRedisTemplate.delete(key); - } - } - - @Override - public void deleteById(Long id,String tenantId) { - wxCouponMapper.deleteById(id,tenantId); - } - - @Override - public List findSaleMoneyByDate(List tenantEntitys, WxCoupon wxCoupon) { - return wxCouponMapper.findSaleMoneyByDate(tenantEntitys,wxCoupon); - } - - @Override - public List findPaymentByDate(List tenantEntitys, WxCoupon wxCoupon) { - return wxCouponMapper.findPaymentByDate(tenantEntitys,wxCoupon); - } - - @Override - public Long findSaleCardCount(List tenantEntitys, WxCoupon wxCoupon) { - long count = 0l; - for (TenantEntity tenantEntity:tenantEntitys) { - wxCoupon.updateTenantInfo(tenantEntity); - long saleCardCount = wxCouponMapper.findSaleCardCount(wxCoupon).longValue(); - count += saleCardCount; - } - return count; - } - - @Override - public Long findTranCardCount(List tenantEntitys, WxCoupon wxCoupon) { - long count = 0l; - for (TenantEntity tenantEntity:tenantEntitys) { - wxCoupon.updateTenantInfo(tenantEntity); - long saleCardCount = wxCouponMapper.findTranCardCount(wxCoupon).longValue(); - count += saleCardCount; - } - return count; - } - - @Override - public String findSubsidyMoney(List tenantEntitys, WxCoupon wxCoupon) { - BigDecimal a = new BigDecimal("0"); - for (TenantEntity tenantEntity:tenantEntitys) { - wxCoupon.updateTenantInfo(tenantEntity); - String subsidyMoney = wxCouponMapper.findSubsidyMoney(wxCoupon); - if(StringUtils.isNotBlank(subsidyMoney)){ - a = a.add(new BigDecimal(subsidyMoney)); - } - } - return a.toPlainString(); - } - - @Override - public PageInfo findCouponData(WxCoupon record, List tenantEntitys, Integer pageNum, Integer pageSize) { - return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> wxCouponMapper.findCouponData(tenantEntitys,record)); - } - - @Override - public void exportCouponData(WxCoupon record, List tenantEntitys, HttpServletRequest request, - HttpServletResponse response) { - Map map = new HashMap(); - map.put("record", record); - map.put("tenantEntitys", tenantEntitys); - excelService.exportBigExcel(couponDataExporter,map, null, "券营销数据信息", WxCouponData.class, "券营销数据.xlsx", response, false); - } - - @Override - public List findCouponOrderCount(List tenantEntitys, WxCoupon wxCoupon) { - return wxCouponMapper.findCouponOrderCount(tenantEntitys,wxCoupon); - } - - - @Override - public List findCouponPaymentCount(List tenantEntitys, WxCoupon wxCoupon) { - return wxCouponMapper.findCouponPaymentCount(tenantEntitys,wxCoupon); - } - - @Override - public List priceCouponSaleCount(List tenantEntitys, WxCoupon wxCoupon) { - return wxCouponMapper.priceCouponSaleCount(tenantEntitys,wxCoupon); - } - - @Override - public List priceCouponPaymentCount(List tenantEntitys, WxCoupon wxCoupon) { - return wxCouponMapper.priceCouponPaymentCount(tenantEntitys,wxCoupon); - } - - @Override - public String findSumPriceSaleMoney(List tenantEntitys, WxCoupon wxCoupon) { - - BigDecimal a = new BigDecimal("0"); - for (TenantEntity tenantEntity:tenantEntitys) { - wxCoupon.updateTenantInfo(tenantEntity); - String subsidyMoney = wxCouponMapper.findSumPriceSaleMoney(wxCoupon); - if(StringUtils.isNotBlank(subsidyMoney)){ - a = a.add(new BigDecimal(subsidyMoney)); - } - } - return a.toPlainString(); - - } - - @Override - public String findSumPricePayMent(List tenantEntitys, WxCoupon wxCoupon) { - BigDecimal a = new BigDecimal("0"); - for (TenantEntity tenantEntity:tenantEntitys) { - wxCoupon.updateTenantInfo(tenantEntity); - String subsidyMoney = wxCouponMapper.findSumPricePayMent(wxCoupon); - if(StringUtils.isNotBlank(subsidyMoney)){ - a = a.add(new BigDecimal(subsidyMoney)); - } - } - return a.toPlainString(); - } - - @Override - public String findSumSubsidyMoney(List tenantEntitys, WxCoupon wxCoupon) { - BigDecimal a = new BigDecimal("0"); - for (TenantEntity tenantEntity:tenantEntitys) { - wxCoupon.updateTenantInfo(tenantEntity); - String subsidyMoney = wxCouponMapper.findSumSubsidyMoney(wxCoupon); - if(StringUtils.isNotBlank(subsidyMoney)){ - a = a.add(new BigDecimal(subsidyMoney)); - } - } - return a.toPlainString(); - } - - @Override - public PageInfo findPressData(WxCoupon record, List tenantEntitys, Integer pageNum, Integer pageSize) { - return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> wxCouponMapper.findPressData(tenantEntitys,record)); - } - - @Override - public void exportPressData(WxCoupon record, List tenantEntitys, HttpServletRequest request, - HttpServletResponse response) { - Map map = new HashMap(); - map.put("record", record); - map.put("tenantEntitys", tenantEntitys); - excelService.exportBigExcel(pressDataExporter,map, null, "砍价营销数据信息", WxPressData.class, "砍价营销数据.xlsx", response, false); - } - - @Override - public List pressSendHistory(List tenantEntitys, WxCoupon wxCoupon) { - return wxCouponMapper.pressSendHistory(tenantEntitys,wxCoupon); - } - - @Override - public List pressSuccHistory(List tenantEntitys, WxCoupon wxCoupon) { - return wxCouponMapper.pressSuccHistory(tenantEntitys,wxCoupon); - } - - @Override - public List pressPaymentHistory(List tenantEntitys, WxCoupon wxCoupon) { - return wxCouponMapper.pressPaymentHistory(tenantEntitys,wxCoupon); - } - - @Override - public String pressSuccRate(List tenantEntitys, WxCoupon wxCoupon) { - String count = wxCouponMapper.pressSuccRate(tenantEntitys,wxCoupon); - if (StringUtils.isBlank(count) || "0.00".equals(count)) { - return "0%"; - } else { - return count + "%"; - } - } - - @Override - public Long sumJoin(List tenantEntitys, WxCoupon wxCoupon) { - Long count = wxCouponMapper.sumJoin(tenantEntitys,wxCoupon); - return (count==null)?0l:count; - } - - @Override - public Long priceCouponCancelCount(List tenantEntitys, WxCoupon wxCoupon) { - Long count = 0l; - for (TenantEntity tenantEntity:tenantEntitys) { - wxCoupon.updateTenantInfo(tenantEntity); - Long aLong = wxCouponMapper.priceCouponCancelCount(wxCoupon); - count += (aLong==null)?0l:aLong; - } - return count; - } - - @Override - public List findSaleCardCountHistory(List tenantEntitys, WxCoupon wxCoupon) { - return wxCouponMapper.findSaleCardCountHistory(tenantEntitys,wxCoupon); - } - - @Override - @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) - public ResultData updateCouponStockAndEndTime(WxCoupon wxCoupon) { - // 1. get old coupon info - // 2. check 库存是否合适 - // 3. check 新的有效期是否合适 - // 4. 更新库存及有效期 - boolean bChanged = false; - WxCoupon oldCoupon = wxCouponMapper.selectById(wxCoupon.getId(),wxCoupon.getTenantId()); - if(oldCoupon == null) { - logger.error(ErrorCode.COUPON_IS_EMPTY.getMessage()); - return new ResultData(ErrorCode.COUPON_IS_EMPTY); - } - if(wxCoupon.getInventory() < wxCoupon.getRemainInventory()) { - // 总库存数要大于等于可用库存数 - logger.error("总库存数要大于等于可用库存数"); - return new ResultData(ErrorCode.COUPON_STOCK_ERR.getCode(), "总库存数要大于等于可用库存数"); - } - if(wxCoupon.getInventory() <= oldCoupon.getInventory() - oldCoupon.getRemainInventory()) { - // 库存可增, 可减, 但是要保证,总库存数要大于已售卖数 - logger.error("总库存数要大于已售卖数"); - return new ResultData(ErrorCode.COUPON_STOCK_ERR.getCode(), "总库存数要大于已售卖数"); - } - - if((!wxCoupon.getInventory().equals(oldCoupon.getInventory())) || - (!wxCoupon.getRemainInventory().equals(oldCoupon.getRemainInventory()))) { - // 库存 是否改变 - bChanged = true; - } - Integer newSale = wxCoupon.getInventory()-wxCoupon.getRemainInventory(); - Integer oldSale = oldCoupon.getInventory() - oldCoupon.getRemainInventory(); - if (!newSale.equals(oldSale)) { - // 已售卖数不变 - logger.error("券库存要保证同增同减 " + newSale + ", " + oldSale); - return new ResultData(ErrorCode.COUPON_STOCK_ERR.getCode(), "券库存要保证同增同减"); - } - if (!wxCoupon.getValidType().equals(oldCoupon.getValidType())) { - // 券有效期类型不能改变 - logger.error("券有效期类型不能改变"); - return new ResultData(ErrorCode.COUPON_VALID_DATE_ERR.getCode(), "券有效期类型不能改变"); - } - if(oldCoupon.getValidType().equals(EnumCouponValidType.BETWEEN_TWO_TIME.getCode())) { - if(wxCoupon.getValidEndDate().before(oldCoupon.getValidEndDate())) { - // 券有效期只可增加 - logger.error("券有效期只可增加"); - return new ResultData(ErrorCode.COUPON_VALID_DATE_ERR.getCode(), "券有效期只可增加"); - } - if(!wxCoupon.getValidEndDate().equals(oldCoupon.getValidEndDate())) { - bChanged = true; - } - } else if(oldCoupon.getValidType().equals(EnumCouponValidType.DAYS_AFTER_RECEIVING.getCode())){ - if(wxCoupon.getValidDays() list = wxCouponMapper.findCouponList(query); - if(CollectionUtils.isNotEmpty(list)){ - return list.get(0); - } - return null; - } - - @Override - @Transactional(isolation= Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) - public void reduceRemainInventory(TenantEntity tenantEntity,Long id, Integer number) { - int num = wxCouponMapper.reduceInventory(id,tenantEntity.getTenantId(), number); - if (num == 0) { - throw new MallinkException(ErrorCode.ORDER_SAVE_ERR); - } -// try{ -// spuStockSync(tenantEntity,id); -// }catch(Exception e){ -// logger.error("send spuStockSync error: " + e.getMessage()); -// } - } - - @Override - @Transactional(isolation= Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) - public void backRemainInventory(TenantEntity tenantEntity,Long id, Integer number, Integer remainInventory) { - int num = wxCouponMapper.backInventory(id,tenantEntity.getTenantId(), number); - if (num == 0) { - throw new MallinkException(ErrorCode.REMAIN_BACK_FAIL); - } -// try{ -// spuStockSync(tenantEntity,id); -// }catch(Exception e){ -// logger.error("send spuStockSync error: " + e.getMessage()); -// } - } - - private void spuStockSync(TenantEntity tenantEntity,Long couponId){ - FmInsideProductPushMsg productPush = new FmInsideProductPushMsg(); - productPush.setDelayTimeLevel(3); - productPush.setMsgType(EnumMsgRecordType.INSIDE_PRODUCT_PUSH.getCode()); - productPush.updateTenantInfo(tenantEntity); - productPush.setCouponId(couponId); - productPush.setSyncType(EnumPushType.SPU_STOCK_SYNC); - logger.info(">>>>>>>>>>>send FmInsideProductPushMsg :"+productPush); - mqBaseProducer.sendMessage(productPush, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); - - - } - - private void spuFreeAuditSync(TenantEntity tenantEntity,Long couponId){ - FmInsideProductPushMsg productPush = new FmInsideProductPushMsg(); - productPush.setDelayTimeLevel(3); - productPush.setMsgType(EnumMsgRecordType.INSIDE_PRODUCT_PUSH.getCode()); - productPush.updateTenantInfo(tenantEntity); - productPush.setCouponId(couponId); - productPush.setSyncType(EnumPushType.SPU_FREE_AUDIT_SYNC); - logger.info(">>>>>>>>>>>send FmInsideProductPushMsg :"+productPush); - mqBaseProducer.sendMessage(productPush, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); - - } - - @Override - @Transactional(isolation= Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) - public ResultData cardDefer(Long id,String tenantId,Date validEndDate) { - WxCoupon coupon = wxCouponMapper.selectById(id,tenantId); - if (null == coupon) { - return new ResultData(Result.ERROR,id+"未查询到券信息."); - } - if (new Date().after(validEndDate)) { - return new ResultData(Result.ERROR,"有效期不能小于当前时间."); - } - //更新coupon信息 - coupon.setValidEndDate(validEndDate); - coupon.setUpdateDate(new Date()); - wxCouponMapper.updateValidEndDate(coupon); - - //更新coupon_channel - wxCouponChannelMapper.cardDefer(id,tenantId, validEndDate); - - //更新coupon_order的状态,已过期的变为使用中 5-->4 - List couponOrderIds = wxCouponOrderMapper.cardDeferCouponOrderId(id,tenantId); - wxCouponOrderMapper.cardDefer(id,tenantId,validEndDate); - - //更新coupon_passwd - couponPasswordMapper.updateExpiredTime(id, validEndDate); - - //更新wx_card_transfer_info - if (null != couponOrderIds && couponOrderIds.size() > 0 ) { - wxCardTransferInfoMapper.cardDefer(validEndDate, couponOrderIds); - } - - return new ResultData(); - } - - /** - * 1.有价券 - * 2.微信 - * 3.分账 (因微信支付线上分账30天限制) 需要限制有效期30天 - * @param wxCoupon - * @return boolean 有效期结束时间需要当前时间的30天限制 验证是否通过 - */ - @Override - public boolean validCouponDate(WxCoupon wxCoupon) { - if(wxCoupon.checkIsFree()){ - return true; - } - if(!EnumCouponType.getWeiXinType().contains(wxCoupon.getType())){ - return true; - } - if(EnumCouponType.getPlatType().contains(wxCoupon.getType())){ - return true; - } - if(EnumCouponValidType.FOREVER.getCode().equals(wxCoupon.getValidType())){ - return true; - } - - WxPayAccount payAccount = payAccountService.getPayAccount(wxCoupon, EnumAppPlat.WX); - if(payAccount == null){ - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "未找到支付配置"); - } - if(EnumPayShare.YES.getCode().equals(payAccount.getShare())){ - Date startDate = null; - if(wxCoupon.getSoldStartTime() != null && wxCoupon.getSoldEndTime() != null){ - startDate = wxCoupon.getSoldStartTime(); - }else{ - startDate = new Date(); - } - - Date realValidDate = wxCoupon.getOuterRealValidDate(startDate); - Date limit_date = DateUtils.getTimeAfterDays(Constant.WX_LIMIT_DAYS, startDate); - if (realValidDate.after(limit_date)) { - return false; - } - } - return true; - - } - - /** - * 礼包券判断子券有效期 - * @param wxCoupon - * @return - */ - @Override - public ResultData validGiftCouponDate(WxCoupon wxCoupon){ - if(!EnumCouponType.COUPON_GIFT.getCode().equals(wxCoupon.getType())){ - return new ResultData(); - } - //获取子券 - List giftIds = JSON.parseArray(wxCoupon.getGiftList(), Long.class); - if(giftIds == null || giftIds.isEmpty()){ - return new ResultData(ErrorCode.COUPON_IS_EMPTY_GIFT.getCode(),"未添加子券"); - } - WxCoupon couponQ = new WxCoupon(); - couponQ.updateTenantInfo(wxCoupon); - couponQ.setIds(giftIds); - List giftList = wxCouponMapper.findList(couponQ); - if(giftList == null || giftList.isEmpty()){ - return new ResultData(ErrorCode.COUPON_IS_EMPTY_GIFT.getCode(), "未找到相应子券"); - } - for (WxCoupon gift:giftList) { - if(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode().equals(gift.getStatus())){ - return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF_GIFT.getCode(),"存在已作废的子券"); - } - if(EnumCouponValidType.BETWEEN_TWO_TIME.getCode().equals(wxCoupon.getValidType()) - && EnumCouponValidType.BETWEEN_TWO_TIME.getCode().equals(gift.getValidType()) - && gift.getValidEndDate().before(wxCoupon.getValidEndDate())){ - return new ResultData(ErrorCode.COUPON_VALID_DATE_ERR_GIFT); - } - } - return new ResultData(); - - } - - /** - * 直连判断收款商户 - * @param wxCoupon - * @return - */ - private ResultData checkCouponMakeMerchant(WxCoupon wxCoupon){ - EnumAppPlat plat = EnumCouponType.getAppPlat(wxCoupon.getType()); - EnumPayWay payWay = EnumAppPlat.getPayWay(plat); - WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(wxCoupon.getTenantId(),plat); - if (cAppInfo == null) { - return new ResultData(ErrorCode.APP_ID_NOT_FOUND); - } - WxPayAccount payAccount = payAccountService.getByIdFromRedis(cAppInfo.getPayId()); - if (payAccount == null) { - return new ResultData(ErrorCode.API_KEY_NOT_FOUND); - } - EnumPayMchType payMchType = EnumPayMchType.getEnum(payAccount.getMchType()); - if(EnumPayMchType.DIRECT.equals(payMchType)){ - WxMerchant makeMerchant = null; - //平台券,查询集团商管商户 - if (EnumCouponType.COUPON_DOUYIN_PLAT.getCode().equals(wxCoupon.getType())) { - wxCoupon.setMerchantType(EnumCouponMerchantType.MULTIPLE_MERCHANT.getCode()); - makeMerchant = wxMerchantService.findAdmin(wxCoupon); - //品牌券,查询集团品牌商户 - }else if (EnumCouponType.COUPON_DOUYIN_BRAND.getCode().equals(wxCoupon.getType())) { - if(wxCoupon.getBrand() == null){ - return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"未选择品牌"); - } - wxCoupon.setMerchantType(EnumCouponMerchantType.MULTIPLE_MERCHANT.getCode()); - makeMerchant = wxMerchantService.findBrandAdmin(wxCoupon,wxCoupon.getBrand()); - //其他商场券 - }else { - List merchantParamList = JSONObject.parseArray(wxCoupon.getMerchantParams(), JSONObject.class); - if(merchantParamList == null || merchantParamList.isEmpty()){ - return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空"); - } - //多门店券 - if(merchantParamList.size() > 1 || EnumCouponMerchantType.MULTIPLE_MERCHANT.getCode().equals(wxCoupon.getMerchantType())){ - wxCoupon.setMerchantType(EnumCouponMerchantType.MULTIPLE_MERCHANT.getCode()); - makeMerchant = wxMerchantService.findAdmin(wxCoupon); - }else{ - wxCoupon.setMerchantType(EnumCouponMerchantType.ONE_MERCHANT.getCode()); - Long merchantId = merchantParamList.get(0).getLong("id"); - makeMerchant = wxMerchantService.selectById(merchantId); - } - } - if (makeMerchant == null) { - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "未找到所属商户"); - } - wxCoupon.setMakeMerchantId(makeMerchant.getId()); - - if(wxCoupon.getSalePrice() != null && wxCoupon.getSalePrice() > 0) { - PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion()); - WxProfitPaymentReceiver receiver = payShareServie.getPaymantReceiver(makeMerchant, makeMerchant.getId()); - if (receiver == null) { - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "所属商户[\""+makeMerchant.getName()+"\"]未配置收款账户"); - } - - //如果是直连,抖音,多商户券必须只配置支付宝 - if (EnumAppPlat.TOUTIAO.equals(plat)) { - if (!MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus()) - && !MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus()) - && !MerchantImportStatus.improt_success.getCode().equals(receiver.getHzImportStatus())) { - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "所属商户[\""+makeMerchant.getName()+"\"]未配置收款账户"); - } - if(EnumCouponMerchantType.MULTIPLE_MERCHANT.getCode().equals(wxCoupon.getMerchantType())){ - if (MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus()) - && !MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus()) -// && !MerchantImportStatus.improt_success.getCode().equals(receiver.getHzImportStatus()) - ) { - }else { - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "所属商户[\""+makeMerchant.getName()+"\"]配置收款账户错误,只能配置支付宝."); - } - } - } - } - - }else{ - wxCoupon.setMakeMerchantId(0l); - } - - return new ResultData(); - } - - @Override - public Map getCouponMerchantMap(List couponIds, TenantEntity tenantEntity,boolean onlyOneMerchantCoupons) { - Map couponMerchantMap = new HashMap(); - if(null != couponIds && couponIds.size() > 0){ - List merchantIds = null; - if (onlyOneMerchantCoupons) { - merchantIds = wxCouponMerchantMapper.findOnlyMerchantByProductIds(tenantEntity.getTenantId(),couponIds); - }else { - merchantIds = wxCouponMerchantMapper.findMerchantByProductIds(tenantEntity.getTenantId(),couponIds); - } - if (null == merchantIds || merchantIds.size() <= 0) { - return couponMerchantMap; - } - WxMerchant merchantQ = new WxMerchant(); - merchantQ.updateTenantInfo(tenantEntity); - merchantQ.setIds(merchantIds); - List merchantList = wxMerchantMapper.findIdNameList(merchantQ); - Map merchantNameMap = new HashMap(); - if (null != merchantList) { - for (int i = 0 ; i < merchantList.size() ; i ++) { - WxMerchant m = merchantList.get(i); - merchantNameMap.put(m.getId(), m.getName()); - } - } - - List merchantProductVos = null; - if (onlyOneMerchantCoupons) { - merchantProductVos = wxCouponMerchantMapper.findOnlyMerchantProduct(tenantEntity.getTenantId(), merchantIds); - }else { - merchantProductVos = wxCouponMerchantMapper.findMerchantProduct(tenantEntity.getTenantId(), couponIds); - } - if (null != merchantProductVos && merchantProductVos.size() > 0 ) { - for (int i = 0 ; i < merchantProductVos.size(); i ++) { - WxMerchantProductVo mp = merchantProductVos.get(i); - if(couponIds.contains(mp.getProductId())){ - if (mp.getMc() > 1) { - couponMerchantMap.put(mp.getProductId(), "多商户通用"); - }else { - couponMerchantMap.put(mp.getProductId(), merchantNameMap.get(mp.getMerchantId())); - } - } - } - } - } - return couponMerchantMap; - } - - @Override - public Map getCouponMap(List couponIds, TenantEntity tenantEntity) { - Map couponMap = new HashMap(); - if(null != couponIds && couponIds.size() > 0){ - WxCoupon couponQ = new WxCoupon(); - couponQ.updateTenantInfo(tenantEntity); - couponQ.setIds(couponIds); - List couponList = wxCouponMapper.newfindCList(couponQ); - for (WxCoupon c:couponList) { - couponMap.put(c.getId(),c); - } - } - return couponMap; - } - - @Override - public Map> getCouponMerchantList(TenantEntity tenantInfo, Long couponId,String city) { - WxCoupon wxCoupon = wxCouponMapper.selectById(couponId,tenantInfo.getTenantId()); - if (EnumCouponType.isParentCoupon(wxCoupon.getType())){ - WxCouponMall couponMall = new WxCouponMall(); - couponMall.updateTenantInfo(tenantInfo); - couponMall.setProductId(couponId); - couponMall.setStatus(EnumCouponMallStatus.FINISED.getCode()); - List couponMallList = wxCouponMallMapper.findList(couponMall); - if (null != couponMallList && couponMallList.size()> 0 ) { - Map> mallMerchantMap = new HashMap>(); - for (int i = 0 ; i < couponMallList.size();i++) { - WxCouponMall cm = couponMallList.get(i); - WxMall mall = wxMallMapper.getByTenantId(cm.getMallTenantId()); - if (StringUtils.isBlank(city)) { - mallMerchantMap.put(mall.getTenantId()+"|"+mall.getName(), getCouponMerchantList(couponId,null,mall)); - }else { - mallMerchantMap.put(mall.getTenantId()+"|"+mall.getName() + "|" +city, getCouponMerchantList(couponId,city,mall)); - } - } - return mallMerchantMap; - } - return null; - }else { - Map> mallMerchantMap = new HashMap>(); - WxMall mall = wxMallMapper.getByTenantId(tenantInfo.getTenantId()); - if (StringUtils.isBlank(city)) { - mallMerchantMap.put(mall.getTenantId()+"|"+mall.getName(), getCouponMerchantList(couponId,null,mall)); - }else { - mallMerchantMap.put(mall.getTenantId()+"|"+mall.getName()+ "|" + city, getCouponMerchantList(couponId,city,mall)); - } - return mallMerchantMap; - } - } - - private List getCouponMerchantList(Long couponId,String city,TenantEntity mallTenantEntity) { - List merchantList = wxMerchantService.findMerchantVoList(couponId,city, mallTenantEntity,true); - - if (merchantList != null) { - - merchantList = merchantList.stream().sorted(Comparator.comparing(m -> m.getTtPoi(), Comparator.nullsLast(String::compareTo))).collect(toList()); - - merchantList = merchantList.stream().filter( - m->m.getMerchantStatus().equals(EnumMerchantStatus.VALID.getCode())) - .collect(toList()); - } - return merchantList; - } - - @Override - @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) - public ResultData disable(TenantEntity tenantInfo, Long couponId, MallUserInfo user) { - TtCouponChannelPoi onlineStatus = ttCouponChannelPoiMapper.selectById(tenantInfo.getTenantId(), couponId); - if(onlineStatus != null){ - if(EnumSpuSyncStatus.sync_auditing.getCode().equals(onlineStatus.getStatus())){ - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"此券审核中"); - } - Long draftId = wxCouponMapper.selectDraftId(couponId,tenantInfo.getTenantId()); - if(draftId != null){ - TtCouponChannelPoi draftStatus = ttCouponChannelPoiMapper.selectById(tenantInfo.getTenantId(), draftId); - if(draftStatus != null && EnumSpuSyncStatus.sync_auditing.getCode().equals(draftStatus.getStatus())){ - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"此券草稿审核中"); - } - } - } - - WxCoupon couponUpd = new WxCoupon(); - couponUpd.updateTenantInfo(tenantInfo); - couponUpd.setId(couponId); - couponUpd.setStatus(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode()); - couponUpd.setUpdateDate(new Date()); - int upd = wxCouponMapper.updateById(couponUpd); - if(upd == 1){ - //下架所有投放频道 - wxCouponChannelService.updateStatusByCouponId(couponId, tenantInfo, EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()); - //下架所有场景投放 - wxCouponSendService.updateStatusByCouponId(couponId, tenantInfo, EnumCouponSendStatus.INVALID.getCode()); - //下架所有已砍价券 todo 已生成的订单不做处理 -// wxOrderService.updateStatusByPressCouponId(couponId, tenantInfo, EnumOrderStatus.ORDER_STATUS_PRESS_CANCEL.getCode()); - //下架所有相关广告 - wxScreenAdService.updateStatusByCouponId(couponId, tenantInfo, EnumScreenAdStatus.INVALID.getCode()); - //下架拼团券 todo 已生成的订单不做处理 -// wxOrderService.updateOrderGroupStatusByCouponId(couponId, tenantInfo, EnumOrderStatus.ORDER_STATUS_COOPERATING_CANCEL.getCode()); - // 卡下架后,转赠找不到卡相关信息,所以修改卡转赠状态为不可转赠 - //wxCardInfoMapper.updateTransferStatusByCouponId(couponId); - // 卡券下架,未使用的卡密要下架 - couponPasswordMapper.disableByCouponId(couponId); - - //同步抖音状态 - wxCouponChannelService.spuStatusSyncByCoupon(tenantInfo,couponId); - - WxCoupon record = wxCouponMapper.selectById(couponId, tenantInfo.getTenantId()); - String remark = (user != null ? user.getUsername() : "") + "作废卡[" + record.getTitle() + "], 库存:"; - insertWxCardDailyLogInfo(user, record, false, remark); - } - return new ResultData(); - } - - public void insertWxCardDailyLogInfo(MallUserInfo user, WxCoupon record, Boolean flag, String remark) { - if (EnumCouponType.CARD_MULTIMCH.getCode().equals(record.getType())) { - try { - WxCardDailyLog cardSetPrice = new WxCardDailyLog(); - cardSetPrice.updateTenantInfo(record); - cardSetPrice.setPrice(flag ? record.getPrice() : record.getRemainInventory()); - cardSetPrice.setCouponId(record.getId()); - cardSetPrice.setType(flag ? EnumOperateLogType.CREATE.getCode() : EnumOperateLogType.DISABLE.getCode()); - cardSetPrice.setCount(record.getInventory()); - cardSetPrice.setOperatorType(user != null ? EnumUserType.MALLUSER.getCode() : 0); - cardSetPrice.setOperatorId(user != null ? user.getId() : 0); - cardSetPrice.setOperatorUser(user != null ? user.getUsername() : ""); - cardSetPrice.setRemark(flag ? remark : remark + cardSetPrice.getPrice()); - wxCardDailyLogService.saveOrUpdate(cardSetPrice); - } catch (Exception e) { - logger.error("insertWxCardDailyLogInfo insert error"); - throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "insertWxCardDailyLogInfo 插入出错!"); - } - } - } - - @Override - public void setParentCouponMallMerchants(TenantEntity mallTenantEntity,WxCoupon wxCoupon) throws Exception { - try { - WxCoupon coupon = wxCouponMapper.selectById(wxCoupon.getId(), mallTenantEntity.getParentTenantId()); - if (null == coupon) { - throw new MallinkException(Result.ERROR,"券未查询到"); - } - if (null == wxCoupon.getMerchantIds()) { - throw new MallinkException(Result.ERROR,"请选择商户"); - } -// Long makeMerchantId = coupon.getMakeMerchantId(); - // - StringBuffer merchantParams = new StringBuffer("[{\"tenantId\":").append(mallTenantEntity.getTenantId()).append(",\"mallMerchantParams\":").append("["); - Long[] mids = wxCoupon.getMerchantIds(); - for (int i = 0 ;i < mids.length; i++ ){ - merchantParams.append("{\"id\":").append(mids[i]).append(",\"businessId\":").append(Constant.default_business).append("}"); - if (i < mids.length-1 ) { - merchantParams.append(","); - } - } - merchantParams.append("]}]"); - coupon.setChildMerchantParams(merchantParams.toString()); - checkCouponMerchantReceiver(coupon,true); - final IdWorker idWorker = IdWorker.get(); - updateCouponMerchants(coupon,idWorker); - //平台券设置商管商户 -// if (null != coupon.getMakeMerchantId()) { -// wxCouponMapper.setMakeMerchantId(coupon); -// } - }catch(Exception e) { - throw e; - } - } - - private Map generateMerchantAutoShareAll(Long[] merchantIds,boolean auto) { - Map merchantAutoShareMap = new HashMap(); - for (Long mid:merchantIds) { - merchantAutoShareMap.put(mid, auto); - } - return merchantAutoShareMap; - } - - @Override - public Map couponMerchantAutoShare(TenantEntity tenantEntity,WxCoupon wxCoupon) throws Exception { - if (null == wxCoupon.getMerchantIds()) { - throw new MallinkException(Result.ERROR,"缺少参数"); - } - - Integer couponType = wxCoupon.getType(); - Integer couponMerchantType = wxCoupon.getMerchantType(); - //新增 - if (null == wxCoupon.getId()) { - if (null == wxCoupon.getType() || null == wxCoupon.getMerchantType()) { - throw new MallinkException(Result.ERROR,"缺少参数"); - } - //更新 - }else { - WxCoupon coupon = wxCouponMapper.selectById(wxCoupon.getId(), wxCoupon.getTenantId()); - if (null == coupon) { - throw new MallinkException(Result.ERROR,"未查询到券"); - } - couponType = coupon.getType(); - couponMerchantType = coupon.getMerchantType(); - } - EnumAppPlat plat = EnumCouponType.getAppPlat(couponType); - EnumPayWay payWay = EnumAppPlat.getPayWay(plat); - WxAppinfo cAppInfo = null; - if (EnumCouponType.isParentCoupon(couponType)) { - cAppInfo = wxAppinfoService.getCAppInfo(wxCoupon,plat); - }else { - cAppInfo = wxAppinfoService.getCAppInfo(tenantEntity,plat); - } - if (cAppInfo == null) { - throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); - } - WxPayAccount payAccount = payAccountMapper.selectById(cAppInfo.getPayId()); - if (payAccount == null) { - throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); - } - EnumPayMchType payMchType = EnumPayMchType.getEnum(payAccount.getMchType()); - EnumPayShare isShare = EnumPayShare.getEnum(payAccount.getShare()); - PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion()); - //直连模式,如果是单商户券,则都可以;如果是多商户券,抖音则只要开通了支付宝就可以,微信则不行。 - if (payMchType == EnumPayMchType.DIRECT) { - if (EnumCouponMerchantType.ONE_MERCHANT.getCode() == couponMerchantType) { - return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),true); - }else { - if (plat == EnumAppPlat.TOUTIAO) { - Map merchantAutoShareMap = new HashMap(); - for (Long mid:wxCoupon.getMerchantIds()) { - //开通了支付宝就可以 - WxProfitSharingReceiver receiver = payShareServie.getSharingReceiver(payAccount, mid, null, payMchType.getCode()); - if (null == receiver) { - merchantAutoShareMap.put(mid, false); - }else { - if (MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus())) { - merchantAutoShareMap.put(mid, true); - }else { - merchantAutoShareMap.put(mid, false); - } - } - } - return merchantAutoShareMap; - }else if (plat == EnumAppPlat.WX){ - return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),false); - }else { - return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),false); - } - } - }else { - //总分模式,分账开启,微信平台则认为是100%分账,抖音则只要开通了支付宝就可以。 - if (isShare == EnumPayShare.YES) { - if (plat == EnumAppPlat.WX) { - return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),true); - }else if (plat == EnumAppPlat.TOUTIAO) { - Map merchantAutoShareMap = new HashMap(); - for (Long mid:wxCoupon.getMerchantIds()) { - boolean isBad = toTalPayMchTypeMerchantIsBad(payShareServie,payAccount,String.valueOf(mid),mid,payMchType,plat); - if (isBad) { - merchantAutoShareMap.put(mid, false); - }else { - merchantAutoShareMap.put(mid, true); - } - } - return merchantAutoShareMap; - }else { - return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),true); - } - }else { - return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),false); - } - } - } - - @Override - public boolean isCouponMerchantValid(Long couponId, Integer couponType, TenantEntity couponTenantEntity) { - if (EnumCouponType.isParentCoupon(couponType)) { - WxCouponMall couponMall = new WxCouponMall(); - couponMall.updateTenantInfo(couponTenantEntity); - couponMall.setProductId(couponId); - couponMall.setStatus(EnumCouponMallStatus.FINISED.getCode()) ; - List couponMallList = wxCouponMallMapper.findList(couponMall); - if (null == couponMallList ) { - return false; - } - for (int i = 0 ; i < couponMallList.size(); i++) { - WxCouponMall wcm = couponMallList.get(i); - TenantEntity mallTenantEntity = new TenantEntity(); - mallTenantEntity.setTenantId(wcm.getMallTenantId()); - mallTenantEntity.setParentTenantId(couponTenantEntity.getTenantId()); - List merchantVoList = wxMerchantService.findMerchantListByProduct(mallTenantEntity,couponId,false); - if (null != merchantVoList && merchantVoList.size() > 0 ) { - if (merchantVoList.stream().anyMatch((cm->cm.getMerchantStatus().equals(EnumMerchantStatus.VALID.getCode())))){ - return true; - } - } - } - return false; - - }else { - List merchantVoList = wxMerchantService.findMerchantListByProduct(couponTenantEntity,couponId,false); - if (null == merchantVoList || merchantVoList.size() <=0 ) { - return false; - } - if (merchantVoList.stream().anyMatch((cm->cm.getMerchantStatus().equals(EnumMerchantStatus.VALID.getCode())))){ - return true; - } - } - return false; - } - - @Override - public Integer getCategoryId(TenantEntity tenantEntity, Long couponId) { - return wxCouponMapper.findCategoryIdById(couponId,tenantEntity.getTenantId()); - } - - @Override - public ResultData setCouponMerchants(TenantEntity tenantInfo, WxCoupon wxCoupon) { - WxCoupon record = wxCouponMapper.selectById(wxCoupon.getId(), tenantInfo.getTenantId()); - if (null == record) { - throw new MallinkException(Result.ERROR,"未查询到券"); - } - record.setMerchantParams(wxCoupon.getMerchantParams()); - - //判断直连检查收款帐号(必须),总分模式直接收款到小程序的收款帐号 - ResultData merchantResultData = checkCouponMakeMerchant(record); - if(Result.SUCCESS != merchantResultData.code){ - return merchantResultData; - } - try { - Map tenantMerchantMap = checkCouponMerchantReceiver(record, true); - }catch(MallinkException e){ - return new ResultData(e.getErrorCode(),e.getMessage()); - }catch(Exception e) { - return new ResultData(Result.ERROR,e.getMessage()); - } - - try { - final IdWorker idWorker = IdWorker.get(); - updateCouponMerchants(record,idWorker); - } catch (Exception e) { - logger.error("updateCouponMerchants error.",e); - return new ResultData(Result.ERROR,"更新商户出错。"+e.getMessage()); - } - - return new ResultData(); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void addManyCouponMerchants(TenantEntity tenantInfo, List couponIds, List merchantIds) { - List add = new ArrayList<>(); - final IdWorker idWorker = IdWorker.get(); - Date now = new Date(); - for (Long couponId:couponIds) { - wxCouponMerchantMapper.updateStatus(tenantInfo.getTenantId(),couponId,merchantIds,EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); - - List couponOldMerchants = wxCouponMerchantMapper.findMerchantIdListByProduct(couponId, tenantInfo.getTenantId()); - List couponAddMerchants = new ArrayList<>(); - couponAddMerchants.addAll(merchantIds); - couponAddMerchants.removeAll(couponOldMerchants); - if(!couponAddMerchants.isEmpty()){ - for (Long addMerchant:couponAddMerchants) { - WxCouponMerchant couponMerchant = new WxCouponMerchant(); - couponMerchant.setId(idWorker.nextId()); - couponMerchant.updateTenantInfo(tenantInfo); - couponMerchant.setProductId(couponId); - couponMerchant.setMerchantId(addMerchant); - couponMerchant.setCreateDate(now); - couponMerchant.setUpdateDate(now); - couponMerchant.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); - add.add(couponMerchant); - } - } - } - if(!add.isEmpty()){ - wxCouponMerchantMapper.insertList(add); - } - - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void delManyCouponMerchants(TenantEntity tenantInfo, List couponIds, List merchantIds) { - for (Long couponId:couponIds) { - wxCouponMerchantMapper.updateStatus(tenantInfo.getTenantId(),couponId,merchantIds,EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_INVALID.getCode()); - } - } - - @Override - public List getByIdListOrTitle(List couponIds, String tenantId, String title) { - WxCoupon coupon = new WxCoupon(); - coupon.setTenantId(tenantId); - if (CollectionUtils.isNotEmpty(couponIds)) { - coupon.setCouponIds(couponIds); - } - if (StringUtils.isNotBlank(title)) { - coupon.setTitle(title); - } - return wxCouponMapper.findList(coupon); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void handleDraftCoupon(WxCoupon wxCoupon) { - WxCoupon coupon = wxCouponMapper.selectOnlineCoupon(wxCoupon.getId(),wxCoupon.getTenantId()); - if(coupon == null){ - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未查询到券数据"); - } - if(EnumCouponVersion.draft.getCode().equals(coupon.getVersion())){ - TtCouponChannelPoi draftCouponChannelPoi = ttCouponChannelPoiMapper.selectById(coupon.getTenantId(), coupon.getId()); - if(draftCouponChannelPoi != null && EnumSpuSyncStatus.sync_auditing.getCode().equals(draftCouponChannelPoi.getStatus())){ - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"商品数据流程中"); - } - return; - } - TtCouponChannelPoi onlineCouponChannelPoi = ttCouponChannelPoiMapper.selectById(coupon.getTenantId(), coupon.getId()); - if(onlineCouponChannelPoi != null){ - if(EnumSpuSyncStatus.sync_auditing.getCode().equals(onlineCouponChannelPoi.getStatus())){ - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"商品数据流程中"); - } - if(EnumSpuSyncStatus.sync_put_on.getCode().equals(onlineCouponChannelPoi.getStatus()) - || EnumSpuSyncStatus.sync_pull_off.getCode().equals(onlineCouponChannelPoi.getStatus()) - || EnumSpuSyncStatus.sync_audit_pass.getCode().equals(onlineCouponChannelPoi.getStatus()) - || EnumSpuSyncStatus.sync_audit_disable.getCode().equals(onlineCouponChannelPoi.getStatus())){ - //复制草稿数据 - WxCoupon draftCoupon = wxCouponMapper.selectDraftCoupon(coupon.getId(),coupon.getTenantId()); - if(draftCoupon == null){ - try{ - final IdWorker idWorker = IdWorker.get(); - draftCoupon = new WxCoupon(); - BeanUtils.copyProperties(draftCoupon,coupon); - draftCoupon.setId(idWorker.nextId()); - draftCoupon.setVersion(EnumCouponVersion.draft.getCode()); - draftCoupon.setCreateDate(new Date()); - draftCoupon.setUpdateDate(new Date()); - wxCouponMapper.insert(draftCoupon); - - if (EnumCouponType.isParentCoupon(draftCoupon.getType())) { - WxCouponMall couponMall = new WxCouponMall(); - couponMall.updateTenantInfo(draftCoupon); - couponMall.setProductId(draftCoupon.getId()); - List couponMallList = wxCouponMallMapper.findList(couponMall); - - for (WxCouponMall cm : couponMallList) { - cm.setId(idWorker.nextId()); - cm.setProductId(draftCoupon.getCouponId()); - wxCouponMallMapper.insert(cm); - - WxCouponMerchant couponMerchant = new WxCouponMerchant(); - couponMerchant.setTenantId(cm.getMallTenantId()); - couponMerchant.setParentTenantId(cm.getTenantId()); - couponMerchant.setProductId(draftCoupon.getId()); - List couponMerchantList = wxCouponMerchantMapper.findList(couponMerchant); - - for (WxCouponMerchant cmt: couponMerchantList) { - cmt.setId(idWorker.nextId()); - cmt.setProductId(draftCoupon.getCouponId()); - wxCouponMerchantMapper.insert(cmt); - } - } - }else{ - WxCouponMerchant couponMerchant = new WxCouponMerchant(); - couponMerchant.updateTenantInfo(draftCoupon); - couponMerchant.setProductId(draftCoupon.getId()); - List couponMerchantList = wxCouponMerchantMapper.findList(couponMerchant); - for (WxCouponMerchant cmt: couponMerchantList) { - cmt.setId(idWorker.nextId()); - cmt.setProductId(draftCoupon.getCouponId()); - wxCouponMerchantMapper.insert(cmt); - } - } - }catch(Exception e){ - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"商品数据处理异常"); - } - - }else{ - TtCouponChannelPoi draftCouponChannelPoi = ttCouponChannelPoiMapper.selectById(draftCoupon.getTenantId(), draftCoupon.getId()); - if(draftCouponChannelPoi != null && EnumSpuSyncStatus.sync_auditing.getCode().equals(draftCouponChannelPoi.getStatus())){ - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"商品数据流程中"); - } - - } - wxCoupon.setId(draftCoupon.getId()); - wxCoupon.setVersion(null); - } - } - - } - - @Override - public WxCouponCVo getDraftCoupon(Long couponId, String tenantId, TenantEntity mallTenantEntity) { - Long id = wxCouponMapper.selectDraftId(couponId,tenantId); - if(id != null){ - return getVoById(id,tenantId,mallTenantEntity); - }else{ - return getVoById(couponId,tenantId,mallTenantEntity); - } - } - - @Override - public Map findCouponDetail(TenantEntity tenantInfo, Long id) { - Map couponDetail = new HashMap<>(); - couponDetail.put("id",id); - couponDetail.put("tenantId",tenantInfo.getTenantId()); - couponDetail.put("parentTenantId",tenantInfo.getParentTenantId()); - WxCoupon onlineCoupon = wxCouponMapper.selectOnlineCoupon(id, tenantInfo.getTenantId()); - if(onlineCoupon == null){ - throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL); - } - couponDetail.put("onlineCoupon",onlineCoupon); - couponDetail.put("supId",onlineCoupon.getGoodsId()); - TtCouponChannelPoi onlineCouponChannelPoi = ttCouponChannelPoiMapper.selectById(onlineCoupon.getTenantId(), onlineCoupon.getId()); - if(onlineCouponChannelPoi != null){ - couponDetail.put("onlineTTStatus",onlineCouponChannelPoi); - } - WxCoupon draftCoupon = wxCouponMapper.selectDraftCoupon(id, tenantInfo.getTenantId()); - if(draftCoupon != null){ - couponDetail.put("draftCoupon",draftCoupon); - TtCouponChannelPoi draftCouponChannelPoi = ttCouponChannelPoiMapper.selectById(draftCoupon.getTenantId(), draftCoupon.getId()); - if(draftCouponChannelPoi != null){ - couponDetail.put("draftTTStatus",draftCouponChannelPoi); - } - } - - return couponDetail; - } - - -} +package com.iformall.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.iformall.common.ErrorCode; +import com.iformall.common.IdWorker; +import com.iformall.common.Result; +import com.iformall.common.ResultData; +import com.iformall.domain.dto.WxCouponMerchantDto; +import com.iformall.domain.po.*; +import com.iformall.domain.po.base.BaseEntity; +import com.iformall.domain.po.base.TenantEntity; +import com.iformall.domain.po.msg.FmInsideProductPushMsg; +import com.iformall.domain.vo.*; +import com.iformall.domain.vo.excel.WxCardData; +import com.iformall.domain.vo.excel.WxCouponData; +import com.iformall.domain.vo.excel.WxPressData; +import com.iformall.douyin.pay.enums.MerchantImportStatus; +import com.iformall.douyin.pay.orderQuery.QueryMerchantResult; +import com.iformall.douyin.web.bean.GoodsTemplateGet; +import com.iformall.enums.*; +import com.iformall.exception.MallinkException; +import com.iformall.mapper.*; +import com.iformall.mq.MqBaseProducer; +import com.iformall.service.*; +import com.iformall.service.excel.WxCardDataExporter; +import com.iformall.service.excel.WxCouponDataExporter; +import com.iformall.service.excel.WxPressDataExporter; +import com.iformall.service.pay.PayServiceFactory; +import com.iformall.service.pay.service.share.PayShareAdapterService; +import com.iformall.utils.Constant; +import com.iformall.utils.DateUtils; +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Lazy; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.math.BigDecimal; +import java.util.*; +import java.util.stream.Collectors; + +import static java.util.stream.Collectors.toList; + + +@Service +public class WxCouponServiceImpl implements WxCouponService { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + WxCouponMapper wxCouponMapper; + + @Autowired + WxCouponMerchantMapper wxCouponMerchantMapper; + + @Autowired + WxMerchantMapper wxMerchantMapper; + + @Autowired + WxMerchantService wxMerchantService; + + @Lazy + @Autowired + WxCouponChannelService wxCouponChannelService; + + @Lazy + @Autowired + WxCouponSendService wxCouponSendService; + + @Lazy + @Autowired + WxOrderService wxOrderService; + + @Lazy + @Autowired + WxScreenAdService wxScreenAdService; + + @Autowired + WxCouponChannelMapper wxCouponChannelMapper; + + @Autowired + WxCardInfoMapper wxCardInfoMapper; + + @Autowired + WxCouponPasswordMapper couponPasswordMapper; + + @Autowired + WxCouponPasswordService couponPasswordService; + + @Autowired + WxPayAccountMapper payAccountMapper; + + @Autowired + WxPayAccountService payAccountService; + + @Autowired + WxCouponOrderMapper wxCouponOrderMapper; + + @Autowired + WxCardTransferInfoMapper wxCardTransferInfoMapper; + + @Autowired + ExcelService excelService; + + @Autowired + WxCardDataExporter cardDataExporter; + + @Autowired + WxCouponDataExporter couponDataExporter; + + @Autowired + WxPressDataExporter pressDataExporter; + + @Autowired + @Qualifier("couponChannelRedisTemplate") + RedisTemplate> cdRedisTemplate; + + @Autowired + WxProfitSharingReceiverMapper wxProfitSharingReceiverMapper; + + @Autowired + private TtGoodsCategoryService ttGoodsCategoryService; + + @Autowired + private TtMerchantPoiService ttMerchantPoiService; + + @Autowired + WxAppinfoService wxAppinfoService; + + @Autowired + private MqBaseProducer mqBaseProducer; + + @Autowired + PayServiceFactory payServiceFactory; + + @Autowired + TtCouponChannelPoiMapper ttCouponChannelPoiMapper; + + @Autowired + WxCouponMallMapper wxCouponMallMapper; + + @Autowired + WxMallMapper wxMallMapper; + + @Autowired + WxCardDailyLogService wxCardDailyLogService; + + @Override + public ResultData list(TenantEntity tenantEntity,WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { + if (null == wxCoupon) wxCoupon = new WxCoupon(); + wxCoupon.updateTenantInfo(tenantEntity); + handCouponList(wxCoupon); + + //除了a端列表 其他默认需要过滤 + if(!EnumFilterPut.NO.equals(wxCoupon.getFilterCanPut())) { + WxCoupon couponModel = wxCouponMapper.findCouponModel(wxCoupon); + if (couponModel != null) { + wxCoupon.setCouponModelId(couponModel.getCouponModelId()); + wxCoupon.setCardModelId(couponModel.getCardModelId()); + wxCoupon.setGroupModelId(couponModel.getGroupModelId()); + wxCoupon.setPressModelId(couponModel.getPressModelId()); + } + } + + PageInfo page = listAsPage(wxCoupon, pageNum, pageSize); + + List wxCouponList = page.getList(); + + if (wxCouponList.isEmpty() || wxCoupon.getTargetAd() != null) { + return new ResultData(page); + } + + List ids = wxCouponList.stream().map(p -> p.getId()).collect(toList()); + + //处理抖音草稿数据 + Map draftStatusMap = new HashMap<>(); + if(EnumAppPlat.TOUTIAO.getCode().equals(wxCoupon.getPlat())){ + List draftStatus = wxCouponMapper.findDraftStatus(tenantEntity.getTenantId(),ids); + for (TtCouponVo vo:draftStatus) { + draftStatusMap.put(vo.getCouponId(),vo); + } + } + + + + WxCouponChannel wxCouponChannel = new WxCouponChannel(); + wxCouponChannel.updateTenantInfo(wxCoupon); + wxCouponChannel.setCouponIds(ids); + wxCouponChannel.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode()); + //上架状态 + List list = wxCouponChannelMapper.findList(wxCouponChannel); + if (!list.isEmpty()) { + Map> groupBy = list.stream().collect(Collectors.groupingBy(WxCouponChannel::getCouponId)); + for (WxCoupon temp: wxCouponList) { + if(!draftStatusMap.isEmpty()){ + TtCouponVo draft = draftStatusMap.get(temp.getId()); + if(draft != null){ + temp.setDraftPoiStatus(draft.getPoiStatus()); + temp.setDraftStatusDesc(draft.getStatusDesc()); + } + } + + if (groupBy.get(temp.getId()) != null) { + List channels = new ArrayList<>(); + for (WxCouponChannel tempchannel : groupBy.get(temp.getId())) { + if (!channels.contains(tempchannel.getTargetAd())) { + channels.add(tempchannel.getTargetAd()); + } + } + String sss = JSON.toJSONString(channels); + temp.setChannels(sss); + } else { + temp.setChannels(""); + } + + } + } else { + for (WxCoupon temp : wxCouponList) { + temp.setChannels(""); + } + + } + return new ResultData(page); + } + + + private void handCouponList(WxCoupon wxCoupon){ + //默认排序 + if(StringUtils.isBlank(wxCoupon.getSortColumns())){ + wxCoupon.setSortColumns(BaseEntity.SortField.CCreateDate_DESC, BaseEntity.SortField.CId_DESC); + } + if (wxCoupon.getStatus() != null && wxCoupon.getStatus() == -1){ + wxCoupon.setStatus(null); + } + //门店处理 + if(wxCoupon.getMerchantId() != null){ + List merchantIds = new ArrayList(); + merchantIds.add(wxCoupon.getMerchantId()); + List mcids = wxCouponMerchantMapper.findMerchantProductIds(wxCoupon.getTenantId(), merchantIds,0); + if(mcids == null || mcids.isEmpty()){ + wxCoupon.setId(-999L); + return; + }else{ + wxCoupon.setIds(mcids); + } + } + + //券类型处理 + if(wxCoupon.getType() != null){ + if(wxCoupon.getPlat() == null){ + wxCoupon.setPlat(EnumCouponType.getAppPlat(wxCoupon.getType()).getCode()); + } + }else{ + List types = new ArrayList<>(); + if(wxCoupon.getTypes() != null && !wxCoupon.getTypes().isEmpty()){ + types.addAll(wxCoupon.getTypes()); + } + if(wxCoupon.getTargetAd() != null){ + if(wxCoupon.getPlat() == null){ + wxCoupon.setPlat(EnumCouponChannelType.getAppPlat(wxCoupon.getTargetAd()).getCode()); + } + if(EnumAppPlat.TOUTIAO.getCode().equals(wxCoupon.getPlat())){ + //渠道查询时只查询审核通过的 + wxCoupon.setPoiStatus(EnumSpuSyncStatus.sync_put_on.getCode()); + } + List couponTypes = EnumCouponChannelType.getCouponTypeBy(wxCoupon.getTargetAd()); + if(couponTypes.isEmpty()){ + wxCoupon.setId(-999L); + return; + }else{ + if(types == null || types.isEmpty()){ + types = couponTypes; + }else{ + types.retainAll(couponTypes); + if(types.isEmpty()){ + wxCoupon.setId(-999L); + return; + } + } + } + } + if(wxCoupon.getPlat() == null){ + //默认查微信平台 + wxCoupon.setPlat(EnumAppPlat.WX.getCode()); + } + + List typeCode = EnumCouponType.getTypeCode(wxCoupon.getPlat()); + if(types == null || types.isEmpty()){ + types = typeCode; + }else{ + types.retainAll(typeCode); + if(types.isEmpty()){ + wxCoupon.setId(-999L); + return; + } + } + wxCoupon.setTypes(types); + } + + } + + + @Override + public List list(WxCoupon wxCoupon){ + return wxCouponMapper.findList(wxCoupon); + } + + @Override + public PageInfo simplelistAsPage(WxCoupon record, Integer pageNum, Integer pageSize) { + return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> wxCouponMapper.findList(record)); + } + + @Override + public PageInfo listAsPage(WxCoupon record, Integer pageIndex, Integer pageSize) { + int total = wxCouponMapper.findCouponListCount(record); + int pages; + if(total % pageSize == 0){ + pages = total / pageSize; + }else{ + pages = total / pageSize +1; + } + record.setLimitStart((pageIndex -1) * pageSize); + record.setLimitEnd(pageSize); + List list = wxCouponMapper.findCouponList(record); + + PageHelper.startPage(pageIndex, pageSize); + PageInfo pageInfo = new PageInfo<>(list); + pageInfo.setPages(pages); + pageInfo.setTotal(total); + PageHelper.clearPage(); + return pageInfo; + } + + + @Override + public PageInfo findCountData(WxCoupon record, List tenantEntitys, Integer pageNum, Integer pageSize) { + return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> wxCouponMapper.findCountData(tenantEntitys,record)); + } + + @Override + public void exportCardData(WxCoupon record, List tenantEntitys, HttpServletRequest request, + HttpServletResponse response) { + Map map = new HashMap(); + map.put("record", record); + map.put("tenantEntitys", tenantEntitys); + excelService.exportBigExcel(cardDataExporter,map, null, "卡营销数据信息", WxCardData.class, "卡营销数据.xlsx", response, false); + } + + @Override + public WxCoupon getById(Long id,String tenantId) { + return wxCouponMapper.selectById(id,tenantId); + } + + @Override + public WxCoupon getPriceAndStock(Long id,String tenantId) { + return wxCouponMapper.getPriceAndStock(id,tenantId); + } + + @Override + public List getPriceAndStock(List ids,String tenantId) { + return wxCouponMapper.batchGetPriceAndStock(ids,tenantId); + } + + @Override + public WxCoupon getHtmlById(Long id,String tenantId) { + return wxCouponMapper.selectById(id,tenantId); + } + + @Override + public WxCouponCVo getVoById(Long id,String couponTenantId,TenantEntity mallTenantEntity) { + WxCouponCVo wxCouponCVo = wxCouponMapper.findVoDetail(id,couponTenantId); + + if(wxCouponCVo == null){ + return null; + } + + List merchantList = getMerchantVoList(wxCouponCVo, mallTenantEntity, wxCouponCVo.getId(), wxCouponCVo.getType()); + + wxCouponCVo.setMerchantVoList(merchantList); + if(EnumCouponType.COUPON_GIFT.getCode().equals(wxCouponCVo.getType())){ + WxCoupon coupon = new WxCoupon(); + coupon.updateTenantInfo(wxCouponCVo); + List longs = JSON.parseArray(wxCouponCVo.getGiftList(), Long.class); + if(longs != null && longs.size() > 0){ + coupon.setIds(longs); + wxCouponCVo.setGiftCouponList(wxCouponMapper.findList(coupon)); + } + } + + return wxCouponCVo; + } + + private List getMerchantVoList(TenantEntity couponTenant,TenantEntity mallTenant,Long couponId,Integer couponType){ + if (EnumCouponType.isParentCoupon(couponType)){ + //集团查券 查询所有门店 + if(couponTenant.getTenantId().equals(mallTenant.getTenantId())){ + WxCouponMall couponMall = new WxCouponMall(); + couponMall.updateTenantInfo(couponTenant); + couponMall.setProductId(couponId); + List couponMallList = wxCouponMallMapper.findList(couponMall); + List merchantVoList = new ArrayList<>(); + if (null != couponMallList && couponMallList.size()> 0 ) { + for (WxCouponMall cm:couponMallList) { + WxMall mall = wxMallMapper.getByTenantId(cm.getMallTenantId()); + List couponMerchantList = getCouponMerchantList(couponId,null, mall); + if(couponMerchantList != null && couponMerchantList.size() > 0){ + merchantVoList.addAll(couponMerchantList); + } + } + } + return merchantVoList; + //子广场查券 只查询自己广场的门店 + }else{ + return getCouponMerchantList(couponId,null,mallTenant); + } + }else{ + return getCouponMerchantList(couponId,null,couponTenant); + } + } + + @Override + public WxCouponCVo getVoStatusById(Long id,String tenantId) { + WxCouponCVo wxCouponCVo = wxCouponMapper.findVoStatusDetail(id,tenantId); + return wxCouponCVo; + } + + @Override + public WxCoupon getAttrsById(Long id, String tenantId) { + return wxCouponMapper.getAttrsById(id,tenantId); + } + + + private Long parseMerchantId(JSONObject merchantParam){ + if (!StringUtils.isBlank(merchantParam.getString("id"))){ + return Long.valueOf(merchantParam.getString("id")); + } + return null; + } + private String parseParameter(JSONObject merchantParam){ + return merchantParam.getString("parameter"); + } + private Integer parseBusiness(JSONObject merchantParam){ + String businessIdStr = merchantParam.getString("businessId"); + if ( !StringUtils.isBlank(businessIdStr)) { + return Integer.valueOf(businessIdStr); + } + return null; + } + private Integer parseSubBusiness(JSONObject merchantParam){ + String subBusinessIdStr = merchantParam.getString("subBusinessId"); + if (subBusinessIdStr != null) + return Integer.valueOf(subBusinessIdStr); + return null; + } + + private WxCouponMerchantDto parseMerchantParam(JSONObject merchantParam){ + WxCouponMerchantDto wxCouponMerchantDto = new WxCouponMerchantDto(); + try { + wxCouponMerchantDto.setMerchantId(parseMerchantId(merchantParam)); + wxCouponMerchantDto.setParameter(parseParameter(merchantParam)); + wxCouponMerchantDto.setBusiness(parseBusiness(merchantParam)); + wxCouponMerchantDto.setSubBusiness(parseSubBusiness(merchantParam)); + }catch (Exception e) { + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); + } + if (wxCouponMerchantDto.getMerchantId()==null) { + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); + } + return wxCouponMerchantDto; + } + + + @Override + @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) + public ResultData saveOrUpdate(WxCoupon record, MallUserInfo user) { + //金额处理 + if (StringUtils.isNotEmpty(record.getSalePriceStr())) { + record.setSalePrice(new BigDecimal(record.getSalePriceStr()).multiply(new BigDecimal(100)).intValue()); + } + if (StringUtils.isNotEmpty(record.getFreightPriceStr())) { + record.setFreightPrice(new BigDecimal(record.getFreightPriceStr()).multiply(new BigDecimal(100)).intValue()); + } + if (StringUtils.isNotEmpty(record.getUsePriceStr())) { + record.setUsePrice(new BigDecimal(record.getUsePriceStr()).multiply(new BigDecimal(100)).intValue()); + } + if (StringUtils.isNotEmpty(record.getPriceStr())) { + record.setPrice(new BigDecimal(record.getPriceStr()).multiply(new BigDecimal(100)).intValue()); + } + if (StringUtils.isNotEmpty(record.getTailPriceStr())) { + record.setTailPrice(new BigDecimal(record.getTailPriceStr()).multiply(new BigDecimal(100)).intValue()); + } + if (StringUtils.isNotEmpty(record.getOrigPriceStr())) { + record.setOrigPrice(new BigDecimal(record.getOrigPriceStr()).multiply(new BigDecimal(100)).intValue()); + } + if (StringUtils.isNotEmpty(record.getSubsidyNumStr())) { + record.setSubsidyNum(new BigDecimal(record.getSubsidyNumStr()).multiply(new BigDecimal(100)).intValue()); + } + //补贴处理 + if(record.getSubsidyType() == null){ + record.setSubsidyType(EnumCouponSubsidyType.NO_SUBSIDY.getCode()); + } + if(record.getSubsidyNum() == null || record.getSubsidyNum().intValue() == 0){ + record.setSubsidyType(EnumCouponSubsidyType.NO_SUBSIDY.getCode()); + record.setSubsidyNum(0); + } + if (EnumCouponSubsidyType.WECHAT_COUPON.getCode().equals(record.getSubsidyType())) { + if (EnumYesOrNo.YES.getCode() != record.getIsAfterSetPrice()) { + // 微信 立减 + if (record.getSubsidyNum() > record.getSalePrice()) { + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "补贴额大于售价"); + } + } + } else if (EnumCouponSubsidyType.OFFLINE_SUBSIDY.getCode().equals(record.getSubsidyType())) { + if (EnumYesOrNo.YES.getCode() != record.getIsAfterSetPrice()) { + // 线下补贴 + int subsidy_num = record.getPrice() - record.getSalePrice(); + if (record.getSubsidyNum() > subsidy_num) { + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "补贴额大于面额与售价的差值"); + } + } + } else if (EnumCouponSubsidyType.WECHAT_MCHPAY.getCode().equals(record.getSubsidyType())) { + // TODO 微信转账到银行卡 + + } + + if (EnumCouponContentType.HTML.getCode().equals(record.getContentType())) { + if (StringUtils.isEmpty(record.getHtml())) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请填写富文本内容"); + } + } + + if (StringUtils.isBlank(record.getCoverPicture())) { + List strList = new ArrayList(); + if (StringUtils.isNotBlank(record.getCoverImg())) { + strList.add(record.getCoverImg()); + } + if (strList.size() > 1) { + record.setCoverPicture(JSONArray.toJSONString(strList)); + } + } + //可配送商品永久有效 + if(EnumCouponType.COUPON_DISTRIBUTION.getCode().equals(record.getType())){ + record.setValidType(EnumCouponValidType.FOREVER.getCode()); + } + //券礼包有效期=售卖时间 + if(EnumCouponType.COUPON_GIFT.getCode().equals(record.getType())){ + record.setValidType(EnumCouponValidType.BETWEEN_TWO_TIME.getCode()); + record.setValidStartDate(record.getSoldStartTime()); + record.setValidEndDate(record.getSoldEndTime()); + } + + if (record.getValidType() != null) { + switch (EnumCouponValidType.getEnum(record.getValidType())) { + case FOREVER: + record.setValidStartDate(null); + record.setValidEndDate(null); + record.setValidDays(null); + break; + case DAYS_AFTER_RECEIVING: + record.setValidStartDate(null); + record.setValidEndDate(null); + break; + case BETWEEN_TWO_TIME: + record.setValidDays(null); + case TIME_AND_DAYS: + if (record.getSoldStartTime() != null && record.getSoldEndTime() != null) { + if (record.getValidStartDate().before(record.getSoldStartTime())) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "有效时间需在售卖期之后"); + } + if (record.getValidEndDate().before(record.getSoldEndTime())) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "有效时间需在售卖期之后"); + } + } + break; + default: + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请填写有效时间类型"); + } + + if(!this.validCouponDate(record)) { + return new ResultData(ResultData.ERROR,"券有效结束日期必须在售卖30天以内。"); + } + } + + ResultData giftResult = this.validGiftCouponDate(record); + if(Result.SUCCESS != giftResult.code){ + return giftResult; + } + + //判断直连检查收款帐号(必须),总分模式直接收款到小程序的收款帐号 + ResultData merchantResultData = checkCouponMakeMerchant(record); + if(Result.SUCCESS != merchantResultData.code){ + return merchantResultData; + } + + //平台券先不设置商户 + Map tenantMerchantMap = null; + if (EnumCouponType.checkCreateWithMerchants(record.getType())) { + try { + tenantMerchantMap = checkCouponMerchantReceiver(record, true); + }catch(MallinkException e){ + return new ResultData(e.getErrorCode(),e.getMessage()); + }catch(Exception e) { + return new ResultData(Result.ERROR,e.getMessage()); + } + } + if (EnumCouponType.checkCreateWithMalls(record.getType())) { + String[] mallTenantIds = record.getMallTenantIds(); + if (null == mallTenantIds || mallTenantIds.length <= 0 ) { + return new ResultData(Result.ERROR,"请选择商场"); + } + } + + final IdWorker idWorker = IdWorker.get(); + if (record.getId() == null) { + record.setId(idWorker.nextId()); + if(record.getCouponId() == null){ + record.setCouponId(record.getId()); + } + if (EnumCouponType.checkCreateWithMerchants(record.getType())) { + for (Iterator it = tenantMerchantMap.keySet().iterator();it.hasNext();) { + TenantEntity mallTenant = it.next(); + String merchantParamListString = tenantMerchantMap.get(mallTenant); + List merchantParamList = JSONArray.parseArray(merchantParamListString, JSONObject.class); + merchantParamList.forEach(merchantParam -> { + WxCouponMerchant cm = new WxCouponMerchant(); + WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam); + cm.setId(idWorker.nextId()); + cm.updateTenantInfo(mallTenant); + cm.setMerchantId(wxCouponMerchantDto.getMerchantId()); + cm.setParameter(wxCouponMerchantDto.getParameter()); + cm.setProductId(record.getId()); + cm.setCreateDate(new Date()); + cm.setUpdateDate(new Date()); + cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); + wxCouponMerchantMapper.insert(cm); + }); + } + } + + if (EnumCouponType.checkCreateWithMalls(record.getType())) { + for (String mt : record.getMallTenantIds()) { + WxCouponMall mall = new WxCouponMall(); + mall.updateTenantInfo(record); + mall.setMallTenantId(mt); + mall.setProductId(record.getId()); + mall.setCreateDate(new Date()); + mall.setUpdateDate(new Date()); + //如果是直接设置到商户的,直接变为已完成 + if (EnumCouponType.checkCreateWithMerchants(record.getType())) { + mall.setStatus(EnumCouponMallStatus.FINISED.getCode()); + }else { + mall.setStatus(EnumCouponMallStatus.UNFINISED.getCode()); + } + wxCouponMallMapper.insert(mall); + } + } + + if (record.getPasswordSupport() != null && record.getPasswordSupport().equals(EnumCouponPasswordSupport.SUPPORTED.getCode())) { + // todo 生成卡密无法修改, 调整 + couponPasswordService.mkPasswords(record,user); + } + + record.setCreateDate(new Date()); + record.setUpdateDate(new Date()); + if (null == record.getBusiness()) { + record.setBusiness(Constant.default_business); + } + wxCouponMapper.insert(record); + + String remark = (user != null ? user.getUsername() : "") + "创建了卡[" + record.getTitle() + "]," + record.getInventory() + "张卡密"; + insertWxCardDailyLogInfo(user, record, true, remark); + + } else { + if(EnumCouponType.getDouYinType().contains(record.getType())){ + TtCouponChannelPoi ttCouponChannelPoi = ttCouponChannelPoiMapper.selectById(record.getTenantId(),record.getId()); + if(ttCouponChannelPoi != null && + (EnumSpuSyncStatus.sync_auditing.getCode().equals(ttCouponChannelPoi.getStatus()) + || EnumSpuSyncStatus.sync_put_on.getCode().equals(ttCouponChannelPoi.getStatus()))){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"该券状态不允许修改"); + } + } + record.setRemainInventory(null); + record.setInventory(null); + +// if(record.getInventory() != null && record.getRemainInventory() != null) { +// // 库存修改检查 +// WxCoupon oldCoupon = wxCouponMapper.selectById(record.getId(),record.getTenantId()); +// if (Objects.equals(oldCoupon.getRemainInventory(), record.getRemainInventory())) { +// // 库存未变, 不更新库存 +// record.setRemainInventory(null); +// record.setInventory(null); +// } else { +// // TODO bug记录 +// logger.info("设置库存:record.getRemainInventory {},oldCoupon.getRemainInventory {},oldCoupon.getInventory {}", +// record.getRemainInventory(), oldCoupon.getRemainInventory(), oldCoupon.getInventory()); +// // 库存增加,要同时增加, 库存减少,要同时减少 +// record.setInventory(oldCoupon.getInventory() + record.getRemainInventory() - oldCoupon.getRemainInventory()); +// } +// } + + if (EnumCouponType.checkCreateWithMerchants(record.getType())) { + try { + updateCouponMerchants(record,idWorker); + } catch (Exception e) { + logger.error("updateCouponMerchants error.",e); + return new ResultData(Result.ERROR,"更新商户出错。"+e.getMessage()); + } + } + + if (EnumCouponType.checkCreateWithMalls(record.getType())) { + WxCouponMall couponMall = new WxCouponMall(); + couponMall.updateTenantInfo(record); + couponMall.setProductId(record.getId()); + List couponMallList = wxCouponMallMapper.findList(couponMall); + Map alreadyMallTenant = new HashMap(); + if (null != couponMallList && couponMallList.size() > 0 ) { + for (int i = 0 ; i < couponMallList.size() ; i ++) { + WxCouponMall c = couponMallList.get(i); + alreadyMallTenant.put(c.getMallTenantId(),c.getStatus()); + } + } + wxCouponMallMapper.delteAllByProductId(couponMall); + for (String mt : record.getMallTenantIds()) { + WxCouponMall mall = new WxCouponMall(); + mall.updateTenantInfo(record); + mall.setMallTenantId(mt); + mall.setProductId(record.getId()); + mall.setCreateDate(new Date()); + mall.setUpdateDate(new Date()); + Integer status = alreadyMallTenant.get(mt); + if (null != status ) { + mall.setStatus(status); + }else { + if (EnumCouponType.checkCreateWithMerchants(record.getType())) { + mall.setStatus(EnumCouponMallStatus.FINISED.getCode()); + }else { + mall.setStatus(EnumCouponMallStatus.UNFINISED.getCode()); + } + } + wxCouponMallMapper.insert(mall); + } + } + + record.setUpdateDate(new Date()); + if (null == record.getBusiness()) { + record.setBusiness(Constant.default_business); + } + wxCouponMapper.updateById(record); + } + + //清空缓存 + clearCIndexCache(record); + return new ResultData(record.getId()); + } + + private void updateCouponMerchants(WxCoupon record,final IdWorker idWorker) throws Exception { + Map tenantMerchantParmMap = checkCouponMerchantReceiver(record,false); + for (Iterator it = tenantMerchantParmMap.keySet().iterator();it.hasNext();) { + TenantEntity mallTenantEntity = it.next(); + WxCouponMerchant cmParam = new WxCouponMerchant(); + cmParam.updateTenantInfo(mallTenantEntity); + cmParam.setProductId(record.getId()); + List oldList = wxCouponMerchantMapper.findList(cmParam); + List merchantParamList = JSONArray.parseArray(tenantMerchantParmMap.get(mallTenantEntity),JSONObject.class); + merchantParamList.stream().forEach(merchantParam -> { + WxCouponMerchant cm = new WxCouponMerchant(); + WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam); + cm.updateTenantInfo(mallTenantEntity); + cm.setMerchantId(wxCouponMerchantDto.getMerchantId()); + cm.setProductId(record.getId()); + WxCouponMerchant rcm = wxCouponMerchantMapper.selectOne(new QueryWrapper<>(cm)); + if (rcm != null) { + rcm.setParameter(wxCouponMerchantDto.getParameter()); + rcm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); + rcm.setUpdateDate(new Date()); + wxCouponMerchantMapper.updateById(rcm); + }else { + cm.setId(idWorker.nextId()); + cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); + cm.setParameter(wxCouponMerchantDto.getParameter()); + cm.setCreateDate(new Date()); + cm.setUpdateDate(new Date()); + wxCouponMerchantMapper.insert(cm); + } + oldList.removeIf( + old->old.getProductId().equals(record.getId()) && + old.getMerchantId().equals(wxCouponMerchantDto.getMerchantId())); + }); + + oldList.stream().forEach(old->{ + old.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_INVALID.getCode()); + old.setUpdateDate(new Date()); + wxCouponMerchantMapper.updateById(old); + }); + } + + } + + //返回商场商户,key:商场tenant value:merchantParams + private Map checkCouponMerchantReceiver(WxCoupon record,boolean check) throws Exception{ + /* + * 父券对应子商场商户 + */ + if (EnumCouponType.isParentCoupon(record.getType())) { + if(EnumCouponType.COUPON_DOUYIN_BRAND.getCode().equals(record.getType())){ + handCouponMerchantParams(record); + } + if (StringUtils.isBlank(record.getChildMerchantParams())){ + throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空"); + } + List tenantMerchantParamList = JSONObject.parseArray(record.getChildMerchantParams(), JSONObject.class); + if(tenantMerchantParamList == null || tenantMerchantParamList.isEmpty()){ + throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空"); + } + Map retMap = new HashMap(); + String[] mallTenantIds = new String[tenantMerchantParamList.size()]; + int i = 0; + for (JSONObject o:tenantMerchantParamList) { + String mallTenantId = o.getString("tenantId"); + mallTenantIds[i] = mallTenantId; + String mallParentTenantId = record.getTenantId(); + String mallMerchantParams = o.getString("mallMerchantParams"); + TenantEntity mallTenantEntity = new TenantEntity(); + mallTenantEntity.setTenantId(mallTenantId); + mallTenantEntity.setParentTenantId(mallParentTenantId); + if (check) { + List merchantList = checkCouponOneMallMerchantReceiver(mallTenantEntity,mallMerchantParams,record); + } + retMap.put(mallTenantEntity, mallMerchantParams); + i++; + } + record.setMallTenantIds(mallTenantIds); + record.setBusiness(Constant.default_business); + return retMap; + }else { + if (check) { + List merchantList = checkCouponOneMallMerchantReceiver(record,record.getMerchantParams(),record); + if(merchantList.size() > 1){ + record.setBusiness(Constant.default_business); + }else{ + record.setBusiness(merchantList.get(0).getBusinessId()); + record.setSubBusiness(merchantList.get(0).getSubBusinessId()); + } + } + Map retMap = new HashMap(); + TenantEntity tenantEntity = new TenantEntity(); + tenantEntity.updateTenantInfo(record); + retMap.put(tenantEntity, record.getMerchantParams()); + record.setMallTenantIds(new String[]{tenantEntity.getTenantId()}); + return retMap; + } + } + + private void handCouponMerchantParams(WxCoupon record){ + List merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); + if(merchantParamList == null || merchantParamList.isEmpty()){ + throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空"); + } + + Map> map = new HashMap<>(); + for (JSONObject o:merchantParamList) { + String tenantId = o.getString("tenantId"); + if(StringUtils.isBlank(tenantId)){ + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"参数传递异常"); + } + List merchantParams = map.get(tenantId); + if(merchantParams == null){ + merchantParams = new ArrayList<>(); + } + merchantParams.add(o); + map.put(tenantId,merchantParams); + } + + List childMerchantParams = new ArrayList<>(); + for (Iterator it = map.keySet().iterator();it.hasNext();) { + JSONObject object = new JSONObject(); + String tenantId = it.next(); + object.put("tenantId",tenantId); + object.put("mallMerchantParams",map.get(tenantId)); + childMerchantParams.add(object); + } + record.setChildMerchantParams(JSON.toJSONString(childMerchantParams)); + } + + private List checkCouponOneMallMerchantReceiver(TenantEntity mallTenantEntity,String merchantParams,WxCoupon record) throws Exception { + List merchantParamList = JSONObject.parseArray(merchantParams, JSONObject.class); + if(merchantParamList == null || merchantParamList.isEmpty()){ + throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空"); + } + + List merchantIds = new ArrayList<>(); + for (JSONObject o:merchantParamList) { + merchantIds.add(o.getLong("id")); + } + WxMerchant merchantQ = new WxMerchant(); + merchantQ.updateTenantInfo(mallTenantEntity); + merchantQ.setIds(merchantIds); + List merchantList = wxMerchantService.findList(merchantQ); + if(merchantList.size() != merchantParamList.size()){ + throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_EQUAL.getCode(),"所属商户信息异常"); + } + List badMerchant = merchantList.stream().filter(m -> !EnumMerchantStatus.VALID.getCode().equals(m.getStatus())).collect(toList()); + if(badMerchant != null && !badMerchant.isEmpty()){ + List badNames = badMerchant.stream().map(WxMerchant::getName).collect(toList()); + throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_VALID.getCode(),JSONArray.toJSONString(badNames)+"被停用"); + } + + if(record.getSalePrice() != null && record.getSalePrice() > 0) { + EnumAppPlat plat = EnumCouponType.getAppPlat(record.getType()); + EnumPayWay payWay = EnumAppPlat.getPayWay(plat); + WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(mallTenantEntity,plat); + if (cAppInfo == null) { + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + WxPayAccount payAccount = payAccountMapper.selectById(cAppInfo.getPayId()); + if (payAccount == null) { + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + + //判断商户是否匹配poi + if (EnumAppPlat.TOUTIAO.equals(plat)) { + List badPoiNames = new ArrayList(); + for (WxMerchant merchant:merchantList) { + TtMerchantPoi byId = ttMerchantPoiService.getById(merchant.getId()); + if(byId == null || !EnumSupplierMathStatus.match_success.getCode().equals(byId.getMatchStatus())){ + badPoiNames.add(merchant.getName()); + } + } + if(!badPoiNames.isEmpty()){ + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), JSONArray.toJSONString(badPoiNames)+"未匹配poi"); + } + } + + EnumPayMchType payMchType = EnumPayMchType.getEnum(payAccount.getMchType()); + EnumPayShare isShare = EnumPayShare.getEnum(payAccount.getShare()); + + PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion()); + + List badNames = new ArrayList(); + if (EnumPayMchType.DIRECT.equals(payMchType)) { + //多商户券,抖音 直连 门店只有进件支付宝才能参加活动 todo + if(EnumAppPlat.TOUTIAO.equals(plat) && EnumCouponMerchantType.MULTIPLE_MERCHANT.getCode().equals(record.getMerchantType())){ + for (WxMerchant merchant:merchantList) { + WxProfitPaymentReceiver receiver = payShareServie.getPaymantReceiver(mallTenantEntity, merchant.getId()); + if (receiver == null) { + badNames.add(merchant.getName()); + }else{ + if(!MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus())){ + badNames.add(merchant.getName()); + } + } + } + } + +// WxMerchant makeMerchant = getDirectPayAccountMerchant(merchantList,record); +// if (null == makeMerchant) { +// throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "没有收款商户"); +// } +// record.setMakeMerchantId(makeMerchant.getId()); +// WxProfitSharingReceiver receiver = payShareServie.getReceiver(makeMerchant, makeMerchant.getId(), null, payMchType.getCode()); +// +// if (receiver == null) { +// throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "[\""+makeMerchant.getName()+"\"]未配置收款账户"); +// } + //如果是直连,抖音,多商户券必须只配置支付宝 +// if (EnumAppPlat.TOUTIAO.equals(plat)) { +// if (merchantList.size() > 1 ) { +// if (MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus()) && +// !MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus()) ) { +// }else { +// throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "[\""+makeMerchant.getName()+"\"]配置收款账户错误,多商户券主收款账户不能配置微信."); +// } +// }else { +// if (!MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus()) +// && !MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus()) +// && !MerchantImportStatus.improt_success.getCode().equals(receiver.getHzImportStatus())) { +// throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "[\""+makeMerchant.getName()+"\"]未配置收款账户"); +// } +// } +// } + } else if (EnumPayShare.YES.equals(isShare)) { + for (WxMerchant merchant:merchantList) { + boolean isBad = toTalPayMchTypeMerchantIsBad(payShareServie,payAccount,merchant.getName(),merchant.getId(),payMchType,plat); + if (isBad) { + badNames.add(merchant.getName()); + } + } + } + if(!badNames.isEmpty()){ + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), JSONArray.toJSONString(badNames)+"未配置分账账户"); + } + } + return merchantList; + } + + //直联模式收款商户 + private WxMerchant getDirectPayAccountMerchant(List merchantList,WxCoupon coupon) throws Exception{ + WxMerchant makeMerchant = null; + //平台券,集团商管商户 + if (EnumCouponType.COUPON_DOUYIN_PLAT.getCode() == coupon.getType()) { + //查询集团商管商户 + makeMerchant = wxMerchantService.findAdmin(coupon); + //品牌券,查询集团品牌商户 + }else if (EnumCouponType.COUPON_DOUYIN_BRAND.getCode() == coupon.getType()) { + makeMerchant = wxMerchantService.findBrandAdmin(coupon,coupon.getBrand()); + //商场券 + }else { + if(coupon.getMerchantType() == EnumCouponMerchantType.ONE_MERCHANT.getCode()){ + if (merchantList.size() == 1) { + makeMerchant = merchantList.get(0); + }else { + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "单商户券只能有一个商户"); + } + }else { + List adminMerchant = merchantList.stream().filter(m -> EnumMerchantAdmin.PUBLIC_ADMIN.getCode().equals(m.getIsAdmin())).collect(toList()); + if(adminMerchant == null || adminMerchant.isEmpty()){ + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "多门店券需包含一个商管商户"); + }else if(adminMerchant.size() > 1){ + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "多门店券只能包含一个商管商户"); + } + makeMerchant = adminMerchant.get(0); + } + } + return makeMerchant; + } + + //总分模式下不能分账的商户 + private boolean toTalPayMchTypeMerchantIsBad(PayShareAdapterService payShareServie,WxPayAccount payAccount, + String merchantName,Long merchantId,EnumPayMchType payMchType,EnumAppPlat plat) throws Exception { + WxProfitSharingReceiver receiver = payShareServie.getSharingReceiver(payAccount, merchantId, null, payMchType.getCode()); + if (receiver == null) { + return true; + } + if (EnumAppPlat.TOUTIAO.equals(plat)) {//抖音只能开通支付宝 + QueryMerchantResult openPayResult = payAccount.getOpenPayResult(); + if(!EnumYesOrNo.YES.getCode().equals(openPayResult.getAlipay()) + || EnumYesOrNo.YES.getCode().equals(openPayResult.getWx()) +// || EnumYesOrNo.YES.getCode().equals(openPayResult.getHz()) + ){ + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "分账模式设置错误"); + } + if(!MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus())){ + return true; + } + +// if(!EnumYesOrNo.YES.getCode().equals(openPayResult.getAlipay()) +// && !EnumYesOrNo.YES.getCode().equals(openPayResult.getWx()) +// && !EnumYesOrNo.YES.getCode().equals(openPayResult.getHz())){ +// throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "分账模式未设置开通支付渠道"); +// } +// if(EnumYesOrNo.YES.getCode().equals(openPayResult.getAlipay()) +// && !MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus())){ +// return true; +// } +// if(EnumYesOrNo.YES.getCode().equals(openPayResult.getWx()) +// && !MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus())){ +// return true; +// } +// if(EnumYesOrNo.YES.getCode().equals(openPayResult.getHz()) +// && !MerchantImportStatus.improt_success.getCode().equals(receiver.getHzImportStatus())){ +// return true; +// } + } + return false; + } + +// @Override +// @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) +// public ResultData setPrice(WxCoupon record) { +// Integer count = wxCouponMapper.setPrice(record); +// if (null == count || count <= 0 ) { +// return new ResultData(Result.ERROR,"设置失败"); +// } +// //设置卡密price +// WxCouponPassword couponPassword = new WxCouponPassword(); +// couponPassword.updateTenantInfo(record); +// couponPassword.setCouponId(record.getId()); +// couponPassword.setPrice(record.getPrice()); +// couponPasswordMapper.setPrice(couponPassword); +// return new ResultData(); +// } + + @Override + public ResultData updateTtProduct(WxCoupon record) { + if(EnumCouponType.getDouYinType().contains(record.getType())){ + TtCouponChannelPoi ttCouponChannelPoi = ttCouponChannelPoiMapper.selectById(record.getTenantId(),record.getId()); + if(ttCouponChannelPoi != null && + (EnumSpuSyncStatus.sync_auditing.getCode().equals(ttCouponChannelPoi.getStatus()) + || EnumSpuSyncStatus.sync_put_on.getCode().equals(ttCouponChannelPoi.getStatus()) + || EnumSpuSyncStatus.sync_audit_disable.getCode().equals(ttCouponChannelPoi.getStatus()))){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"该券状态不允许修改"); + } + } + + if(StringUtils.isBlank(record.getProductAttrs()) || StringUtils.isBlank(record.getSkuAttrs())){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); + } + try{ + List productAttrs = JSONObject.parseArray(record.getProductAttrs(), GoodsTemplateGet.ProductAttrs.class); + List skuAttrs = JSONObject.parseArray(record.getSkuAttrs(), GoodsTemplateGet.ProductAttrs.class); + ttGoodsCategoryService.handDefaultAttr(record,productAttrs,skuAttrs); + for (GoodsTemplateGet.ProductAttrs attr:productAttrs) { + attr.setIsShow(null); + if(attr.getIsRequired() && StringUtils.isBlank(attr.getData())){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"product属性" +attr.getName()+" 为空"); + } + } + record.setProductAttrs(JSONObject.toJSONString(productAttrs)); + for (GoodsTemplateGet.ProductAttrs attr:skuAttrs) { + attr.setIsShow(null); + if(attr.getIsRequired() && StringUtils.isBlank(attr.getData())){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"sku属性 "+attr.getName()+" 为空"); + } + } + record.setSkuAttrs(JSONObject.toJSONString(skuAttrs)); + }catch(Exception e){ + logger.error(e.getMessage(),e); + return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR); + } + WxCoupon coupon = new WxCoupon(); + coupon.setId(record.getId()); + coupon.updateTenantInfo(record); + coupon.setProductType(record.getProductType()); + coupon.setCategoryId(record.getCategoryId()); + coupon.setProductAttrs(record.getProductAttrs()); + coupon.setSkuAttrs(record.getSkuAttrs()); + coupon.setUpdateDate(new Date()); + wxCouponMapper.updateById(coupon); + //清空缓存 + clearCIndexCache(record); + return new ResultData(record.getId()); + } + + + /** + * 清除c端首页券列表缓存 + * @param tenantEntity + */ + @Override + public void clearCIndexCache(TenantEntity tenantEntity){ + for (int i = 1; i <=5 ; i++) { + String key = EnumCacheKey.C_INDEX_PAGE_LIST.getMessage() +tenantEntity.getTenantId()+"_" + i + ":"; + cdRedisTemplate.delete(key); + } + } + + @Override + public void deleteById(Long id,String tenantId) { + wxCouponMapper.deleteById(id,tenantId); + } + + @Override + public List findSaleMoneyByDate(List tenantEntitys, WxCoupon wxCoupon) { + return wxCouponMapper.findSaleMoneyByDate(tenantEntitys,wxCoupon); + } + + @Override + public List findPaymentByDate(List tenantEntitys, WxCoupon wxCoupon) { + return wxCouponMapper.findPaymentByDate(tenantEntitys,wxCoupon); + } + + @Override + public Long findSaleCardCount(List tenantEntitys, WxCoupon wxCoupon) { + long count = 0l; + for (TenantEntity tenantEntity:tenantEntitys) { + wxCoupon.updateTenantInfo(tenantEntity); + long saleCardCount = wxCouponMapper.findSaleCardCount(wxCoupon).longValue(); + count += saleCardCount; + } + return count; + } + + @Override + public Long findTranCardCount(List tenantEntitys, WxCoupon wxCoupon) { + long count = 0l; + for (TenantEntity tenantEntity:tenantEntitys) { + wxCoupon.updateTenantInfo(tenantEntity); + long saleCardCount = wxCouponMapper.findTranCardCount(wxCoupon).longValue(); + count += saleCardCount; + } + return count; + } + + @Override + public String findSubsidyMoney(List tenantEntitys, WxCoupon wxCoupon) { + BigDecimal a = new BigDecimal("0"); + for (TenantEntity tenantEntity:tenantEntitys) { + wxCoupon.updateTenantInfo(tenantEntity); + String subsidyMoney = wxCouponMapper.findSubsidyMoney(wxCoupon); + if(StringUtils.isNotBlank(subsidyMoney)){ + a = a.add(new BigDecimal(subsidyMoney)); + } + } + return a.toPlainString(); + } + + @Override + public PageInfo findCouponData(WxCoupon record, List tenantEntitys, Integer pageNum, Integer pageSize) { + return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> wxCouponMapper.findCouponData(tenantEntitys,record)); + } + + @Override + public void exportCouponData(WxCoupon record, List tenantEntitys, HttpServletRequest request, + HttpServletResponse response) { + Map map = new HashMap(); + map.put("record", record); + map.put("tenantEntitys", tenantEntitys); + excelService.exportBigExcel(couponDataExporter,map, null, "券营销数据信息", WxCouponData.class, "券营销数据.xlsx", response, false); + } + + @Override + public List findCouponOrderCount(List tenantEntitys, WxCoupon wxCoupon) { + return wxCouponMapper.findCouponOrderCount(tenantEntitys,wxCoupon); + } + + + @Override + public List findCouponPaymentCount(List tenantEntitys, WxCoupon wxCoupon) { + return wxCouponMapper.findCouponPaymentCount(tenantEntitys,wxCoupon); + } + + @Override + public List priceCouponSaleCount(List tenantEntitys, WxCoupon wxCoupon) { + return wxCouponMapper.priceCouponSaleCount(tenantEntitys,wxCoupon); + } + + @Override + public List priceCouponPaymentCount(List tenantEntitys, WxCoupon wxCoupon) { + return wxCouponMapper.priceCouponPaymentCount(tenantEntitys,wxCoupon); + } + + @Override + public String findSumPriceSaleMoney(List tenantEntitys, WxCoupon wxCoupon) { + + BigDecimal a = new BigDecimal("0"); + for (TenantEntity tenantEntity:tenantEntitys) { + wxCoupon.updateTenantInfo(tenantEntity); + String subsidyMoney = wxCouponMapper.findSumPriceSaleMoney(wxCoupon); + if(StringUtils.isNotBlank(subsidyMoney)){ + a = a.add(new BigDecimal(subsidyMoney)); + } + } + return a.toPlainString(); + + } + + @Override + public String findSumPricePayMent(List tenantEntitys, WxCoupon wxCoupon) { + BigDecimal a = new BigDecimal("0"); + for (TenantEntity tenantEntity:tenantEntitys) { + wxCoupon.updateTenantInfo(tenantEntity); + String subsidyMoney = wxCouponMapper.findSumPricePayMent(wxCoupon); + if(StringUtils.isNotBlank(subsidyMoney)){ + a = a.add(new BigDecimal(subsidyMoney)); + } + } + return a.toPlainString(); + } + + @Override + public String findSumSubsidyMoney(List tenantEntitys, WxCoupon wxCoupon) { + BigDecimal a = new BigDecimal("0"); + for (TenantEntity tenantEntity:tenantEntitys) { + wxCoupon.updateTenantInfo(tenantEntity); + String subsidyMoney = wxCouponMapper.findSumSubsidyMoney(wxCoupon); + if(StringUtils.isNotBlank(subsidyMoney)){ + a = a.add(new BigDecimal(subsidyMoney)); + } + } + return a.toPlainString(); + } + + @Override + public PageInfo findPressData(WxCoupon record, List tenantEntitys, Integer pageNum, Integer pageSize) { + return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> wxCouponMapper.findPressData(tenantEntitys,record)); + } + + @Override + public void exportPressData(WxCoupon record, List tenantEntitys, HttpServletRequest request, + HttpServletResponse response) { + Map map = new HashMap(); + map.put("record", record); + map.put("tenantEntitys", tenantEntitys); + excelService.exportBigExcel(pressDataExporter,map, null, "砍价营销数据信息", WxPressData.class, "砍价营销数据.xlsx", response, false); + } + + @Override + public List pressSendHistory(List tenantEntitys, WxCoupon wxCoupon) { + return wxCouponMapper.pressSendHistory(tenantEntitys,wxCoupon); + } + + @Override + public List pressSuccHistory(List tenantEntitys, WxCoupon wxCoupon) { + return wxCouponMapper.pressSuccHistory(tenantEntitys,wxCoupon); + } + + @Override + public List pressPaymentHistory(List tenantEntitys, WxCoupon wxCoupon) { + return wxCouponMapper.pressPaymentHistory(tenantEntitys,wxCoupon); + } + + @Override + public String pressSuccRate(List tenantEntitys, WxCoupon wxCoupon) { + String count = wxCouponMapper.pressSuccRate(tenantEntitys,wxCoupon); + if (StringUtils.isBlank(count) || "0.00".equals(count)) { + return "0%"; + } else { + return count + "%"; + } + } + + @Override + public Long sumJoin(List tenantEntitys, WxCoupon wxCoupon) { + Long count = wxCouponMapper.sumJoin(tenantEntitys,wxCoupon); + return (count==null)?0l:count; + } + + @Override + public Long priceCouponCancelCount(List tenantEntitys, WxCoupon wxCoupon) { + Long count = 0l; + for (TenantEntity tenantEntity:tenantEntitys) { + wxCoupon.updateTenantInfo(tenantEntity); + Long aLong = wxCouponMapper.priceCouponCancelCount(wxCoupon); + count += (aLong==null)?0l:aLong; + } + return count; + } + + @Override + public List findSaleCardCountHistory(List tenantEntitys, WxCoupon wxCoupon) { + return wxCouponMapper.findSaleCardCountHistory(tenantEntitys,wxCoupon); + } + + @Override + @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) + public ResultData updateCouponStockAndEndTime(WxCoupon wxCoupon) { + // 1. get old coupon info + // 2. check 库存是否合适 + // 3. check 新的有效期是否合适 + // 4. 更新库存及有效期 + boolean bChanged = false; + WxCoupon oldCoupon = wxCouponMapper.selectById(wxCoupon.getId(),wxCoupon.getTenantId()); + if(oldCoupon == null) { + logger.error(ErrorCode.COUPON_IS_EMPTY.getMessage()); + return new ResultData(ErrorCode.COUPON_IS_EMPTY); + } + if(wxCoupon.getInventory() < wxCoupon.getRemainInventory()) { + // 总库存数要大于等于可用库存数 + logger.error("总库存数要大于等于可用库存数"); + return new ResultData(ErrorCode.COUPON_STOCK_ERR.getCode(), "总库存数要大于等于可用库存数"); + } + if(wxCoupon.getInventory() <= oldCoupon.getInventory() - oldCoupon.getRemainInventory()) { + // 库存可增, 可减, 但是要保证,总库存数要大于已售卖数 + logger.error("总库存数要大于已售卖数"); + return new ResultData(ErrorCode.COUPON_STOCK_ERR.getCode(), "总库存数要大于已售卖数"); + } + + if((!wxCoupon.getInventory().equals(oldCoupon.getInventory())) || + (!wxCoupon.getRemainInventory().equals(oldCoupon.getRemainInventory()))) { + // 库存 是否改变 + bChanged = true; + } + Integer newSale = wxCoupon.getInventory()-wxCoupon.getRemainInventory(); + Integer oldSale = oldCoupon.getInventory() - oldCoupon.getRemainInventory(); + if (!newSale.equals(oldSale)) { + // 已售卖数不变 + logger.error("券库存要保证同增同减 " + newSale + ", " + oldSale); + return new ResultData(ErrorCode.COUPON_STOCK_ERR.getCode(), "券库存要保证同增同减"); + } + if (!wxCoupon.getValidType().equals(oldCoupon.getValidType())) { + // 券有效期类型不能改变 + logger.error("券有效期类型不能改变"); + return new ResultData(ErrorCode.COUPON_VALID_DATE_ERR.getCode(), "券有效期类型不能改变"); + } + if(oldCoupon.getValidType().equals(EnumCouponValidType.BETWEEN_TWO_TIME.getCode())) { + if(wxCoupon.getValidEndDate().before(oldCoupon.getValidEndDate())) { + // 券有效期只可增加 + logger.error("券有效期只可增加"); + return new ResultData(ErrorCode.COUPON_VALID_DATE_ERR.getCode(), "券有效期只可增加"); + } + if(!wxCoupon.getValidEndDate().equals(oldCoupon.getValidEndDate())) { + bChanged = true; + } + } else if(oldCoupon.getValidType().equals(EnumCouponValidType.DAYS_AFTER_RECEIVING.getCode())){ + if(wxCoupon.getValidDays() list = wxCouponMapper.findCouponList(query); + if(CollectionUtils.isNotEmpty(list)){ + return list.get(0); + } + return null; + } + + @Override + @Transactional(isolation= Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) + public void reduceRemainInventory(TenantEntity tenantEntity,Long id, Integer number) { + int num = wxCouponMapper.reduceInventory(id,tenantEntity.getTenantId(), number); + if (num == 0) { + throw new MallinkException(ErrorCode.ORDER_SAVE_ERR); + } +// try{ +// spuStockSync(tenantEntity,id); +// }catch(Exception e){ +// logger.error("send spuStockSync error: " + e.getMessage()); +// } + } + + @Override + @Transactional(isolation= Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) + public void backRemainInventory(TenantEntity tenantEntity,Long id, Integer number, Integer remainInventory) { + int num = wxCouponMapper.backInventory(id,tenantEntity.getTenantId(), number); + if (num == 0) { + throw new MallinkException(ErrorCode.REMAIN_BACK_FAIL); + } +// try{ +// spuStockSync(tenantEntity,id); +// }catch(Exception e){ +// logger.error("send spuStockSync error: " + e.getMessage()); +// } + } + + private void spuStockSync(TenantEntity tenantEntity,Long couponId){ + FmInsideProductPushMsg productPush = new FmInsideProductPushMsg(); + productPush.setDelayTimeLevel(3); + productPush.setMsgType(EnumMsgRecordType.INSIDE_PRODUCT_PUSH.getCode()); + productPush.updateTenantInfo(tenantEntity); + productPush.setCouponId(couponId); + productPush.setSyncType(EnumPushType.SPU_STOCK_SYNC); + logger.info(">>>>>>>>>>>send FmInsideProductPushMsg :"+productPush); + mqBaseProducer.sendMessage(productPush, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); + + + } + + private void spuFreeAuditSync(TenantEntity tenantEntity,Long couponId){ + FmInsideProductPushMsg productPush = new FmInsideProductPushMsg(); + productPush.setDelayTimeLevel(3); + productPush.setMsgType(EnumMsgRecordType.INSIDE_PRODUCT_PUSH.getCode()); + productPush.updateTenantInfo(tenantEntity); + productPush.setCouponId(couponId); + productPush.setSyncType(EnumPushType.SPU_FREE_AUDIT_SYNC); + logger.info(">>>>>>>>>>>send FmInsideProductPushMsg :"+productPush); + mqBaseProducer.sendMessage(productPush, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); + + } + + @Override + @Transactional(isolation= Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) + public ResultData cardDefer(Long id,String tenantId,Date validEndDate) { + WxCoupon coupon = wxCouponMapper.selectById(id,tenantId); + if (null == coupon) { + return new ResultData(Result.ERROR,id+"未查询到券信息."); + } + if (new Date().after(validEndDate)) { + return new ResultData(Result.ERROR,"有效期不能小于当前时间."); + } + //更新coupon信息 + coupon.setValidEndDate(validEndDate); + coupon.setUpdateDate(new Date()); + wxCouponMapper.updateValidEndDate(coupon); + + //更新coupon_channel + wxCouponChannelMapper.cardDefer(id,tenantId, validEndDate); + + //更新coupon_order的状态,已过期的变为使用中 5-->4 + List couponOrderIds = wxCouponOrderMapper.cardDeferCouponOrderId(id,tenantId); + wxCouponOrderMapper.cardDefer(id,tenantId,validEndDate); + + //更新coupon_passwd + couponPasswordMapper.updateExpiredTime(id, validEndDate); + + //更新wx_card_transfer_info + if (null != couponOrderIds && couponOrderIds.size() > 0 ) { + wxCardTransferInfoMapper.cardDefer(validEndDate, couponOrderIds); + } + + return new ResultData(); + } + + /** + * 1.有价券 + * 2.微信 + * 3.分账 (因微信支付线上分账30天限制) 需要限制有效期30天 + * @param wxCoupon + * @return boolean 有效期结束时间需要当前时间的30天限制 验证是否通过 + */ + @Override + public boolean validCouponDate(WxCoupon wxCoupon) { + if(wxCoupon.checkIsFree()){ + return true; + } + if(!EnumCouponType.getWeiXinType().contains(wxCoupon.getType())){ + return true; + } + if(EnumCouponType.getPlatType().contains(wxCoupon.getType())){ + return true; + } + if(EnumCouponValidType.FOREVER.getCode().equals(wxCoupon.getValidType())){ + return true; + } + + WxPayAccount payAccount = payAccountService.getPayAccount(wxCoupon, EnumAppPlat.WX); + if(payAccount == null){ + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "未找到支付配置"); + } + if(EnumPayShare.YES.getCode().equals(payAccount.getShare())){ + Date startDate = null; + if(wxCoupon.getSoldStartTime() != null && wxCoupon.getSoldEndTime() != null){ + startDate = wxCoupon.getSoldStartTime(); + }else{ + startDate = new Date(); + } + + Date realValidDate = wxCoupon.getOuterRealValidDate(startDate); + Date limit_date = DateUtils.getTimeAfterDays(Constant.WX_LIMIT_DAYS, startDate); + if (realValidDate.after(limit_date)) { + return false; + } + } + return true; + + } + + /** + * 礼包券判断子券有效期 + * @param wxCoupon + * @return + */ + @Override + public ResultData validGiftCouponDate(WxCoupon wxCoupon){ + if(!EnumCouponType.COUPON_GIFT.getCode().equals(wxCoupon.getType())){ + return new ResultData(); + } + //获取子券 + List giftIds = JSON.parseArray(wxCoupon.getGiftList(), Long.class); + if(giftIds == null || giftIds.isEmpty()){ + return new ResultData(ErrorCode.COUPON_IS_EMPTY_GIFT.getCode(),"未添加子券"); + } + WxCoupon couponQ = new WxCoupon(); + couponQ.updateTenantInfo(wxCoupon); + couponQ.setIds(giftIds); + List giftList = wxCouponMapper.findList(couponQ); + if(giftList == null || giftList.isEmpty()){ + return new ResultData(ErrorCode.COUPON_IS_EMPTY_GIFT.getCode(), "未找到相应子券"); + } + for (WxCoupon gift:giftList) { + if(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode().equals(gift.getStatus())){ + return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF_GIFT.getCode(),"存在已作废的子券"); + } + if(EnumCouponValidType.BETWEEN_TWO_TIME.getCode().equals(wxCoupon.getValidType()) + && EnumCouponValidType.BETWEEN_TWO_TIME.getCode().equals(gift.getValidType()) + && gift.getValidEndDate().before(wxCoupon.getValidEndDate())){ + return new ResultData(ErrorCode.COUPON_VALID_DATE_ERR_GIFT); + } + } + return new ResultData(); + + } + + /** + * 直连判断收款商户 + * @param wxCoupon + * @return + */ + private ResultData checkCouponMakeMerchant(WxCoupon wxCoupon){ + EnumAppPlat plat = EnumCouponType.getAppPlat(wxCoupon.getType()); + EnumPayWay payWay = EnumAppPlat.getPayWay(plat); + WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(wxCoupon.getTenantId(),plat); + if (cAppInfo == null) { + return new ResultData(ErrorCode.APP_ID_NOT_FOUND); + } + WxPayAccount payAccount = payAccountService.getByIdFromRedis(cAppInfo.getPayId()); + if (payAccount == null) { + return new ResultData(ErrorCode.API_KEY_NOT_FOUND); + } + EnumPayMchType payMchType = EnumPayMchType.getEnum(payAccount.getMchType()); + if(EnumPayMchType.DIRECT.equals(payMchType)){ + WxMerchant makeMerchant = null; + //平台券,查询集团商管商户 + if (EnumCouponType.COUPON_DOUYIN_PLAT.getCode().equals(wxCoupon.getType())) { + wxCoupon.setMerchantType(EnumCouponMerchantType.MULTIPLE_MERCHANT.getCode()); + makeMerchant = wxMerchantService.findAdmin(wxCoupon); + //品牌券,查询集团品牌商户 + }else if (EnumCouponType.COUPON_DOUYIN_BRAND.getCode().equals(wxCoupon.getType())) { + if(wxCoupon.getBrand() == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"未选择品牌"); + } + wxCoupon.setMerchantType(EnumCouponMerchantType.MULTIPLE_MERCHANT.getCode()); + makeMerchant = wxMerchantService.findBrandAdmin(wxCoupon,wxCoupon.getBrand()); + //其他商场券 + }else { + List merchantParamList = JSONObject.parseArray(wxCoupon.getMerchantParams(), JSONObject.class); + if(merchantParamList == null || merchantParamList.isEmpty()){ + return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空"); + } + //多门店券 + if(merchantParamList.size() > 1 || EnumCouponMerchantType.MULTIPLE_MERCHANT.getCode().equals(wxCoupon.getMerchantType())){ + wxCoupon.setMerchantType(EnumCouponMerchantType.MULTIPLE_MERCHANT.getCode()); + makeMerchant = wxMerchantService.findAdmin(wxCoupon); + }else{ + wxCoupon.setMerchantType(EnumCouponMerchantType.ONE_MERCHANT.getCode()); + Long merchantId = merchantParamList.get(0).getLong("id"); + makeMerchant = wxMerchantService.selectById(merchantId); + } + } + if (makeMerchant == null) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "未找到所属商户"); + } + wxCoupon.setMakeMerchantId(makeMerchant.getId()); + + if(wxCoupon.getSalePrice() != null && wxCoupon.getSalePrice() > 0) { + PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion()); + WxProfitPaymentReceiver receiver = payShareServie.getPaymantReceiver(makeMerchant, makeMerchant.getId()); + if (receiver == null) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "所属商户[\""+makeMerchant.getName()+"\"]未配置收款账户"); + } + + //如果是直连,抖音,多商户券必须只配置支付宝 + if (EnumAppPlat.TOUTIAO.equals(plat)) { + if (!MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus()) + && !MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus()) + && !MerchantImportStatus.improt_success.getCode().equals(receiver.getHzImportStatus())) { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "所属商户[\""+makeMerchant.getName()+"\"]未配置收款账户"); + } + if(EnumCouponMerchantType.MULTIPLE_MERCHANT.getCode().equals(wxCoupon.getMerchantType())){ + if (MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus()) + && !MerchantImportStatus.improt_success.getCode().equals(receiver.getWxImportStatus()) +// && !MerchantImportStatus.improt_success.getCode().equals(receiver.getHzImportStatus()) + ) { + }else { + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "所属商户[\""+makeMerchant.getName()+"\"]配置收款账户错误,只能配置支付宝."); + } + } + } + } + + }else{ + wxCoupon.setMakeMerchantId(0l); + } + + return new ResultData(); + } + + @Override + public Map getCouponMerchantMap(List couponIds, TenantEntity tenantEntity,boolean onlyOneMerchantCoupons) { + Map couponMerchantMap = new HashMap(); + if(null != couponIds && couponIds.size() > 0){ + List merchantIds = null; + if (onlyOneMerchantCoupons) { + merchantIds = wxCouponMerchantMapper.findOnlyMerchantByProductIds(tenantEntity.getTenantId(),couponIds); + }else { + merchantIds = wxCouponMerchantMapper.findMerchantByProductIds(tenantEntity.getTenantId(),couponIds); + } + if (null == merchantIds || merchantIds.size() <= 0) { + return couponMerchantMap; + } + WxMerchant merchantQ = new WxMerchant(); + merchantQ.updateTenantInfo(tenantEntity); + merchantQ.setIds(merchantIds); List merchantList = wxMerchantMapper.findIdNameList(merchantQ); + Map merchantNameMap = new HashMap(); + if (null != merchantList) { + for (int i = 0 ; i < merchantList.size() ; i ++) { + WxMerchant m = merchantList.get(i); + merchantNameMap.put(m.getId(), m.getName()); + } + } + + List merchantProductVos = null; + if (onlyOneMerchantCoupons) { + merchantProductVos = wxCouponMerchantMapper.findOnlyMerchantProduct(tenantEntity.getTenantId(), merchantIds); + }else { + merchantProductVos = wxCouponMerchantMapper.findMerchantProduct(tenantEntity.getTenantId(), couponIds); + } + if (null != merchantProductVos && merchantProductVos.size() > 0 ) { + for (int i = 0 ; i < merchantProductVos.size(); i ++) { + WxMerchantProductVo mp = merchantProductVos.get(i); + if(couponIds.contains(mp.getProductId())){ + if (mp.getMc() > 1) { + couponMerchantMap.put(mp.getProductId(), "多商户通用"); + }else { + couponMerchantMap.put(mp.getProductId(), merchantNameMap.get(mp.getMerchantId())); + } + } + } + } + } + return couponMerchantMap; + } + + @Override + public Map getCouponMap(List couponIds, TenantEntity tenantEntity) { + Map couponMap = new HashMap(); + if(null != couponIds && couponIds.size() > 0){ + WxCoupon couponQ = new WxCoupon(); + couponQ.updateTenantInfo(tenantEntity); + couponQ.setIds(couponIds); + List couponList = wxCouponMapper.newfindCList(couponQ); + for (WxCoupon c:couponList) { + couponMap.put(c.getId(),c); + } + } + return couponMap; + } + + @Override + public Map> getCouponMerchantList(TenantEntity tenantInfo, Long couponId,String city) { + WxCoupon wxCoupon = wxCouponMapper.selectById(couponId,tenantInfo.getTenantId()); + if (EnumCouponType.isParentCoupon(wxCoupon.getType())){ + WxCouponMall couponMall = new WxCouponMall(); + couponMall.updateTenantInfo(tenantInfo); + couponMall.setProductId(couponId); + couponMall.setStatus(EnumCouponMallStatus.FINISED.getCode()); + List couponMallList = wxCouponMallMapper.findList(couponMall); + if (null != couponMallList && couponMallList.size()> 0 ) { + Map> mallMerchantMap = new HashMap>(); + for (int i = 0 ; i < couponMallList.size();i++) { + WxCouponMall cm = couponMallList.get(i); + WxMall mall = wxMallMapper.getByTenantId(cm.getMallTenantId()); + if (StringUtils.isBlank(city)) { + mallMerchantMap.put(mall.getTenantId()+"|"+mall.getName(), getCouponMerchantList(couponId,null,mall)); + }else { + mallMerchantMap.put(mall.getTenantId()+"|"+mall.getName() + "|" +city, getCouponMerchantList(couponId,city,mall)); + } + } + return mallMerchantMap; + } + return null; + }else { + Map> mallMerchantMap = new HashMap>(); + WxMall mall = wxMallMapper.getByTenantId(tenantInfo.getTenantId()); + if (StringUtils.isBlank(city)) { + mallMerchantMap.put(mall.getTenantId()+"|"+mall.getName(), getCouponMerchantList(couponId,null,mall)); + }else { + mallMerchantMap.put(mall.getTenantId()+"|"+mall.getName()+ "|" + city, getCouponMerchantList(couponId,city,mall)); + } + return mallMerchantMap; + } + } + + private List getCouponMerchantList(Long couponId,String city,TenantEntity mallTenantEntity) { + List merchantList = wxMerchantService.findMerchantVoList(couponId,city, mallTenantEntity,true); + + if (merchantList != null) { + + merchantList = merchantList.stream().sorted(Comparator.comparing(m -> m.getTtPoi(), Comparator.nullsLast(String::compareTo))).collect(toList()); + + merchantList = merchantList.stream().filter( + m->m.getMerchantStatus().equals(EnumMerchantStatus.VALID.getCode())) + .collect(toList()); + } + return merchantList; + } + + @Override + @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) + public ResultData disable(TenantEntity tenantInfo, Long couponId, MallUserInfo user) { + TtCouponChannelPoi onlineStatus = ttCouponChannelPoiMapper.selectById(tenantInfo.getTenantId(), couponId); + if(onlineStatus != null){ + if(EnumSpuSyncStatus.sync_auditing.getCode().equals(onlineStatus.getStatus())){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"此券审核中"); + } + Long draftId = wxCouponMapper.selectDraftId(couponId,tenantInfo.getTenantId()); + if(draftId != null){ + TtCouponChannelPoi draftStatus = ttCouponChannelPoiMapper.selectById(tenantInfo.getTenantId(), draftId); + if(draftStatus != null && EnumSpuSyncStatus.sync_auditing.getCode().equals(draftStatus.getStatus())){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"此券草稿审核中"); + } + } + } + + WxCoupon couponUpd = new WxCoupon(); + couponUpd.updateTenantInfo(tenantInfo); + couponUpd.setId(couponId); + couponUpd.setStatus(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode()); + couponUpd.setUpdateDate(new Date()); + int upd = wxCouponMapper.updateById(couponUpd); + if(upd == 1){ + //下架所有投放频道 + wxCouponChannelService.updateStatusByCouponId(couponId, tenantInfo, EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()); + //下架所有场景投放 + wxCouponSendService.updateStatusByCouponId(couponId, tenantInfo, EnumCouponSendStatus.INVALID.getCode()); + //下架所有已砍价券 todo 已生成的订单不做处理 +// wxOrderService.updateStatusByPressCouponId(couponId, tenantInfo, EnumOrderStatus.ORDER_STATUS_PRESS_CANCEL.getCode()); + //下架所有相关广告 + wxScreenAdService.updateStatusByCouponId(couponId, tenantInfo, EnumScreenAdStatus.INVALID.getCode()); + //下架拼团券 todo 已生成的订单不做处理 +// wxOrderService.updateOrderGroupStatusByCouponId(couponId, tenantInfo, EnumOrderStatus.ORDER_STATUS_COOPERATING_CANCEL.getCode()); + // 卡下架后,转赠找不到卡相关信息,所以修改卡转赠状态为不可转赠 + //wxCardInfoMapper.updateTransferStatusByCouponId(couponId); + // 卡券下架,未使用的卡密要下架 + couponPasswordMapper.disableByCouponId(couponId); + + //同步抖音状态 + wxCouponChannelService.spuStatusSyncByCoupon(tenantInfo,couponId); + + WxCoupon record = wxCouponMapper.selectById(couponId, tenantInfo.getTenantId()); + String remark = (user != null ? user.getUsername() : "") + "作废卡[" + record.getTitle() + "], 库存:"; + insertWxCardDailyLogInfo(user, record, false, remark); + } + return new ResultData(); + } + + public void insertWxCardDailyLogInfo(MallUserInfo user, WxCoupon record, Boolean flag, String remark) { + if (EnumCouponType.CARD_MULTIMCH.getCode().equals(record.getType())) { + try { + WxCardDailyLog cardSetPrice = new WxCardDailyLog(); + cardSetPrice.updateTenantInfo(record); + cardSetPrice.setPrice(flag ? record.getPrice() : record.getRemainInventory()); + cardSetPrice.setCouponId(record.getId()); + cardSetPrice.setType(flag ? EnumOperateLogType.CREATE.getCode() : EnumOperateLogType.DISABLE.getCode()); + cardSetPrice.setCount(record.getInventory()); + cardSetPrice.setOperatorType(user != null ? EnumUserType.MALLUSER.getCode() : 0); + cardSetPrice.setOperatorId(user != null ? user.getId() : 0); + cardSetPrice.setOperatorUser(user != null ? user.getUsername() : ""); + cardSetPrice.setRemark(flag ? remark : remark + cardSetPrice.getPrice()); + wxCardDailyLogService.saveOrUpdate(cardSetPrice); + } catch (Exception e) { + logger.error("insertWxCardDailyLogInfo insert error"); + throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "insertWxCardDailyLogInfo 插入出错!"); + } + } + } + + @Override + public void setParentCouponMallMerchants(TenantEntity mallTenantEntity,WxCoupon wxCoupon) throws Exception { + try { + WxCoupon coupon = wxCouponMapper.selectById(wxCoupon.getId(), mallTenantEntity.getParentTenantId()); + if (null == coupon) { + throw new MallinkException(Result.ERROR,"券未查询到"); + } + if (null == wxCoupon.getMerchantIds()) { + throw new MallinkException(Result.ERROR,"请选择商户"); + } +// Long makeMerchantId = coupon.getMakeMerchantId(); + // + StringBuffer merchantParams = new StringBuffer("[{\"tenantId\":").append(mallTenantEntity.getTenantId()).append(",\"mallMerchantParams\":").append("["); + Long[] mids = wxCoupon.getMerchantIds(); + for (int i = 0 ;i < mids.length; i++ ){ + merchantParams.append("{\"id\":").append(mids[i]).append(",\"businessId\":").append(Constant.default_business).append("}"); + if (i < mids.length-1 ) { + merchantParams.append(","); + } + } + merchantParams.append("]}]"); + coupon.setChildMerchantParams(merchantParams.toString()); + checkCouponMerchantReceiver(coupon,true); + final IdWorker idWorker = IdWorker.get(); + updateCouponMerchants(coupon,idWorker); + //平台券设置商管商户 +// if (null != coupon.getMakeMerchantId()) { +// wxCouponMapper.setMakeMerchantId(coupon); +// } + }catch(Exception e) { + throw e; + } + } + + private Map generateMerchantAutoShareAll(Long[] merchantIds,boolean auto) { + Map merchantAutoShareMap = new HashMap(); + for (Long mid:merchantIds) { + merchantAutoShareMap.put(mid, auto); + } + return merchantAutoShareMap; + } + + @Override + public Map couponMerchantAutoShare(TenantEntity tenantEntity,WxCoupon wxCoupon) throws Exception { + if (null == wxCoupon.getMerchantIds()) { + throw new MallinkException(Result.ERROR,"缺少参数"); + } + + Integer couponType = wxCoupon.getType(); + Integer couponMerchantType = wxCoupon.getMerchantType(); + //新增 + if (null == wxCoupon.getId()) { + if (null == wxCoupon.getType() || null == wxCoupon.getMerchantType()) { + throw new MallinkException(Result.ERROR,"缺少参数"); + } + //更新 + }else { + WxCoupon coupon = wxCouponMapper.selectById(wxCoupon.getId(), wxCoupon.getTenantId()); + if (null == coupon) { + throw new MallinkException(Result.ERROR,"未查询到券"); + } + couponType = coupon.getType(); + couponMerchantType = coupon.getMerchantType(); + } + EnumAppPlat plat = EnumCouponType.getAppPlat(couponType); + EnumPayWay payWay = EnumAppPlat.getPayWay(plat); + WxAppinfo cAppInfo = null; + if (EnumCouponType.isParentCoupon(couponType)) { + cAppInfo = wxAppinfoService.getCAppInfo(wxCoupon,plat); + }else { + cAppInfo = wxAppinfoService.getCAppInfo(tenantEntity,plat); + } + if (cAppInfo == null) { + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + WxPayAccount payAccount = payAccountMapper.selectById(cAppInfo.getPayId()); + if (payAccount == null) { + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + EnumPayMchType payMchType = EnumPayMchType.getEnum(payAccount.getMchType()); + EnumPayShare isShare = EnumPayShare.getEnum(payAccount.getShare()); + PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion()); + //直连模式,如果是单商户券,则都可以;如果是多商户券,抖音则只要开通了支付宝就可以,微信则不行。 + if (payMchType == EnumPayMchType.DIRECT) { + if (EnumCouponMerchantType.ONE_MERCHANT.getCode() == couponMerchantType) { + return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),true); + }else { + if (plat == EnumAppPlat.TOUTIAO) { + Map merchantAutoShareMap = new HashMap(); + for (Long mid:wxCoupon.getMerchantIds()) { + //开通了支付宝就可以 + WxProfitSharingReceiver receiver = payShareServie.getSharingReceiver(payAccount, mid, null, payMchType.getCode()); + if (null == receiver) { + merchantAutoShareMap.put(mid, false); + }else { + if (MerchantImportStatus.improt_success.getCode().equals(receiver.getAlipayImportStatus())) { + merchantAutoShareMap.put(mid, true); + }else { + merchantAutoShareMap.put(mid, false); + } + } + } + return merchantAutoShareMap; + }else if (plat == EnumAppPlat.WX){ + return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),false); + }else { + return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),false); + } + } + }else { + //总分模式,分账开启,微信平台则认为是100%分账,抖音则只要开通了支付宝就可以。 + if (isShare == EnumPayShare.YES) { + if (plat == EnumAppPlat.WX) { + return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),true); + }else if (plat == EnumAppPlat.TOUTIAO) { + Map merchantAutoShareMap = new HashMap(); + for (Long mid:wxCoupon.getMerchantIds()) { + boolean isBad = toTalPayMchTypeMerchantIsBad(payShareServie,payAccount,String.valueOf(mid),mid,payMchType,plat); + if (isBad) { + merchantAutoShareMap.put(mid, false); + }else { + merchantAutoShareMap.put(mid, true); + } + } + return merchantAutoShareMap; + }else { + return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),true); + } + }else { + return generateMerchantAutoShareAll(wxCoupon.getMerchantIds(),false); + } + } + } + + @Override + public boolean isCouponMerchantValid(Long couponId, Integer couponType, TenantEntity couponTenantEntity) { + if (EnumCouponType.isParentCoupon(couponType)) { + WxCouponMall couponMall = new WxCouponMall(); + couponMall.updateTenantInfo(couponTenantEntity); + couponMall.setProductId(couponId); + couponMall.setStatus(EnumCouponMallStatus.FINISED.getCode()) ; + List couponMallList = wxCouponMallMapper.findList(couponMall); + if (null == couponMallList ) { + return false; + } + for (int i = 0 ; i < couponMallList.size(); i++) { + WxCouponMall wcm = couponMallList.get(i); + TenantEntity mallTenantEntity = new TenantEntity(); + mallTenantEntity.setTenantId(wcm.getMallTenantId()); + mallTenantEntity.setParentTenantId(couponTenantEntity.getTenantId()); + List merchantVoList = wxMerchantService.findMerchantListByProduct(mallTenantEntity,couponId,false); + if (null != merchantVoList && merchantVoList.size() > 0 ) { + if (merchantVoList.stream().anyMatch((cm->cm.getMerchantStatus().equals(EnumMerchantStatus.VALID.getCode())))){ + return true; + } + } + } + return false; + + }else { + List merchantVoList = wxMerchantService.findMerchantListByProduct(couponTenantEntity,couponId,false); + if (null == merchantVoList || merchantVoList.size() <=0 ) { + return false; + } + if (merchantVoList.stream().anyMatch((cm->cm.getMerchantStatus().equals(EnumMerchantStatus.VALID.getCode())))){ + return true; + } + } + return false; + } + + @Override + public Integer getCategoryId(TenantEntity tenantEntity, Long couponId) { + return wxCouponMapper.findCategoryIdById(couponId,tenantEntity.getTenantId()); + } + + @Override + public ResultData setCouponMerchants(TenantEntity tenantInfo, WxCoupon wxCoupon) { + WxCoupon record = wxCouponMapper.selectById(wxCoupon.getId(), tenantInfo.getTenantId()); + if (null == record) { + throw new MallinkException(Result.ERROR,"未查询到券"); + } + record.setMerchantParams(wxCoupon.getMerchantParams()); + + //判断直连检查收款帐号(必须),总分模式直接收款到小程序的收款帐号 + ResultData merchantResultData = checkCouponMakeMerchant(record); + if(Result.SUCCESS != merchantResultData.code){ + return merchantResultData; + } + try { + Map tenantMerchantMap = checkCouponMerchantReceiver(record, true); + }catch(MallinkException e){ + return new ResultData(e.getErrorCode(),e.getMessage()); + }catch(Exception e) { + return new ResultData(Result.ERROR,e.getMessage()); + } + + try { + final IdWorker idWorker = IdWorker.get(); + updateCouponMerchants(record,idWorker); + } catch (Exception e) { + logger.error("updateCouponMerchants error.",e); + return new ResultData(Result.ERROR,"更新商户出错。"+e.getMessage()); + } + + return new ResultData(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void addManyCouponMerchants(TenantEntity tenantInfo, List couponIds, List merchantIds) { + List add = new ArrayList<>(); + final IdWorker idWorker = IdWorker.get(); + Date now = new Date(); + for (Long couponId:couponIds) { + wxCouponMerchantMapper.updateStatus(tenantInfo.getTenantId(),couponId,merchantIds,EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); + + List couponOldMerchants = wxCouponMerchantMapper.findMerchantIdListByProduct(couponId, tenantInfo.getTenantId()); + List couponAddMerchants = new ArrayList<>(); + couponAddMerchants.addAll(merchantIds); + couponAddMerchants.removeAll(couponOldMerchants); + if(!couponAddMerchants.isEmpty()){ + for (Long addMerchant:couponAddMerchants) { + WxCouponMerchant couponMerchant = new WxCouponMerchant(); + couponMerchant.setId(idWorker.nextId()); + couponMerchant.updateTenantInfo(tenantInfo); + couponMerchant.setProductId(couponId); + couponMerchant.setMerchantId(addMerchant); + couponMerchant.setCreateDate(now); + couponMerchant.setUpdateDate(now); + couponMerchant.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); + add.add(couponMerchant); + } + } + } + if(!add.isEmpty()){ + wxCouponMerchantMapper.insertList(add); + } + + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delManyCouponMerchants(TenantEntity tenantInfo, List couponIds, List merchantIds) { + for (Long couponId:couponIds) { + wxCouponMerchantMapper.updateStatus(tenantInfo.getTenantId(),couponId,merchantIds,EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_INVALID.getCode()); + } + } + + @Override + public List getByIdListOrTitle(List couponIds, String tenantId, String title) { + WxCoupon coupon = new WxCoupon(); + coupon.setTenantId(tenantId); + if (CollectionUtils.isNotEmpty(couponIds)) { + coupon.setCouponIds(couponIds); + } + if (StringUtils.isNotBlank(title)) { + coupon.setTitle(title); + } + return wxCouponMapper.findList(coupon); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void handleDraftCoupon(WxCoupon wxCoupon) { + WxCoupon coupon = wxCouponMapper.selectOnlineCoupon(wxCoupon.getId(),wxCoupon.getTenantId()); + if(coupon == null){ + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未查询到券数据"); + } + if(EnumCouponVersion.draft.getCode().equals(coupon.getVersion())){ + TtCouponChannelPoi draftCouponChannelPoi = ttCouponChannelPoiMapper.selectById(coupon.getTenantId(), coupon.getId()); + if(draftCouponChannelPoi != null && EnumSpuSyncStatus.sync_auditing.getCode().equals(draftCouponChannelPoi.getStatus())){ + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"商品数据流程中"); + } + return; + } + TtCouponChannelPoi onlineCouponChannelPoi = ttCouponChannelPoiMapper.selectById(coupon.getTenantId(), coupon.getId()); + if(onlineCouponChannelPoi != null){ + if(EnumSpuSyncStatus.sync_auditing.getCode().equals(onlineCouponChannelPoi.getStatus())){ + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"商品数据流程中"); + } + if(EnumSpuSyncStatus.sync_put_on.getCode().equals(onlineCouponChannelPoi.getStatus()) + || EnumSpuSyncStatus.sync_pull_off.getCode().equals(onlineCouponChannelPoi.getStatus()) + || EnumSpuSyncStatus.sync_audit_pass.getCode().equals(onlineCouponChannelPoi.getStatus()) + || EnumSpuSyncStatus.sync_audit_disable.getCode().equals(onlineCouponChannelPoi.getStatus())){ + //复制草稿数据 + WxCoupon draftCoupon = wxCouponMapper.selectDraftCoupon(coupon.getId(),coupon.getTenantId()); + if(draftCoupon == null){ + try{ + final IdWorker idWorker = IdWorker.get(); + draftCoupon = new WxCoupon(); + BeanUtils.copyProperties(draftCoupon,coupon); + draftCoupon.setId(idWorker.nextId()); + draftCoupon.setVersion(EnumCouponVersion.draft.getCode()); + draftCoupon.setCreateDate(new Date()); + draftCoupon.setUpdateDate(new Date()); + wxCouponMapper.insert(draftCoupon); + + if (EnumCouponType.isParentCoupon(draftCoupon.getType())) { + WxCouponMall couponMall = new WxCouponMall(); + couponMall.updateTenantInfo(draftCoupon); + couponMall.setProductId(draftCoupon.getId()); + List couponMallList = wxCouponMallMapper.findList(couponMall); + + for (WxCouponMall cm : couponMallList) { + cm.setId(idWorker.nextId()); + cm.setProductId(draftCoupon.getCouponId()); + wxCouponMallMapper.insert(cm); + + WxCouponMerchant couponMerchant = new WxCouponMerchant(); + couponMerchant.setTenantId(cm.getMallTenantId()); + couponMerchant.setParentTenantId(cm.getTenantId()); + couponMerchant.setProductId(draftCoupon.getId()); + List couponMerchantList = wxCouponMerchantMapper.findList(couponMerchant); + + for (WxCouponMerchant cmt: couponMerchantList) { + cmt.setId(idWorker.nextId()); + cmt.setProductId(draftCoupon.getCouponId()); + wxCouponMerchantMapper.insert(cmt); + } + } + }else{ + WxCouponMerchant couponMerchant = new WxCouponMerchant(); + couponMerchant.updateTenantInfo(draftCoupon); + couponMerchant.setProductId(draftCoupon.getId()); + List couponMerchantList = wxCouponMerchantMapper.findList(couponMerchant); + for (WxCouponMerchant cmt: couponMerchantList) { + cmt.setId(idWorker.nextId()); + cmt.setProductId(draftCoupon.getCouponId()); + wxCouponMerchantMapper.insert(cmt); + } + } + }catch(Exception e){ + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"商品数据处理异常"); + } + + }else{ + TtCouponChannelPoi draftCouponChannelPoi = ttCouponChannelPoiMapper.selectById(draftCoupon.getTenantId(), draftCoupon.getId()); + if(draftCouponChannelPoi != null && EnumSpuSyncStatus.sync_auditing.getCode().equals(draftCouponChannelPoi.getStatus())){ + throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"商品数据流程中"); + } + + } + wxCoupon.setId(draftCoupon.getId()); + wxCoupon.setVersion(null); + } + } + + } + + @Override + public WxCouponCVo getDraftCoupon(Long couponId, String tenantId, TenantEntity mallTenantEntity) { + Long id = wxCouponMapper.selectDraftId(couponId,tenantId); + if(id != null){ + return getVoById(id,tenantId,mallTenantEntity); + }else{ + return getVoById(couponId,tenantId,mallTenantEntity); + } + } + + @Override + public Map findCouponDetail(TenantEntity tenantInfo, Long id) { + Map couponDetail = new HashMap<>(); + couponDetail.put("id",id); + couponDetail.put("tenantId",tenantInfo.getTenantId()); + couponDetail.put("parentTenantId",tenantInfo.getParentTenantId()); + WxCoupon onlineCoupon = wxCouponMapper.selectOnlineCoupon(id, tenantInfo.getTenantId()); + if(onlineCoupon == null){ + throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL); + } + couponDetail.put("onlineCoupon",onlineCoupon); + couponDetail.put("supId",onlineCoupon.getGoodsId()); + TtCouponChannelPoi onlineCouponChannelPoi = ttCouponChannelPoiMapper.selectById(onlineCoupon.getTenantId(), onlineCoupon.getId()); + if(onlineCouponChannelPoi != null){ + couponDetail.put("onlineTTStatus",onlineCouponChannelPoi); + } + WxCoupon draftCoupon = wxCouponMapper.selectDraftCoupon(id, tenantInfo.getTenantId()); + if(draftCoupon != null){ + couponDetail.put("draftCoupon",draftCoupon); + TtCouponChannelPoi draftCouponChannelPoi = ttCouponChannelPoiMapper.selectById(draftCoupon.getTenantId(), draftCoupon.getId()); + if(draftCouponChannelPoi != null){ + couponDetail.put("draftTTStatus",draftCouponChannelPoi); + } + } + + return couponDetail; + } + + +} diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantServiceImpl.java index f0bff1cfa..ba786e36e 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantServiceImpl.java @@ -500,6 +500,7 @@ public class WxMerchantServiceImpl implements WxMerchantService { //解绑商铺-没有租赁合同或物业合同才可以 if (countRentContract == 0 || countPropertyContract == 0) { wxMerchant.setStatus(EnumMerchantStatus.NOT_VALID.getCode()); + wxMerchant.setUpdateDate(new Date()); wxMerchantMapper.updateById(wxMerchant); WxMerchantShop wxMerchantShopQuery = new WxMerchantShop(); wxMerchantShopQuery.updateTenantInfo(wxMerchant); @@ -508,12 +509,14 @@ public class WxMerchantServiceImpl implements WxMerchantService { List wxMerchantShopList = wxMerchantShopMapper.findList(wxMerchantShopQuery); for (WxMerchantShop wxMerchantShop : wxMerchantShopList) { wxMerchantShop.setIsDel(EnumDelStatus.DEL.getCode()); + wxMerchantShop.setUpdateDate(new Date()); wxMerchantShopMapper.updateById(wxMerchantShop); //更新商铺状态 WxShop wxShop = new WxShop(); wxShop.updateTenantInfo(wxMerchant); wxShop.setId(wxMerchantShop.getShopId()); wxShop.setStatus(EnumShopStatus.NOT_RENT.getCode()); + wxShop.setUpdateDate(new Date()); wxShopMapper.updateById(wxShop); } //解绑用户 @@ -522,6 +525,7 @@ public class WxMerchantServiceImpl implements WxMerchantService { List wxMerchantBUserMapperList = wxMerchantBUserMapper.findList(bUser); for (WxMerchantBUser wxMerchantBUser : wxMerchantBUserMapperList) { wxMerchantBUser.setStatus(EnumMerchantBUserStatus.INVALID.getCode()); + wxMerchantBUser.setUpdateDate(new Date()); wxMerchantBUserMapper.updateById(wxMerchantBUser); } //作废卡券 diff --git a/mallinkService/src/main/resources/mapper/WxBillDailyMapper.xml b/mallinkService/src/main/resources/mapper/WxBillDailyMapper.xml index c42cd9e8e..8afa0815b 100644 --- a/mallinkService/src/main/resources/mapper/WxBillDailyMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxBillDailyMapper.xml @@ -168,13 +168,19 @@ + + + diff --git a/mallinkService/src/main/resources/mapper/WxBillDepositMapper.xml b/mallinkService/src/main/resources/mapper/WxBillDepositMapper.xml index d5fafa126..53877dd91 100644 --- a/mallinkService/src/main/resources/mapper/WxBillDepositMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxBillDepositMapper.xml @@ -187,13 +187,19 @@ + + + diff --git a/mallinkService/src/main/resources/mapper/WxBillOtherDepositMapper.xml b/mallinkService/src/main/resources/mapper/WxBillOtherDepositMapper.xml index fc4814c3e..2c7917e66 100644 --- a/mallinkService/src/main/resources/mapper/WxBillOtherDepositMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxBillOtherDepositMapper.xml @@ -172,14 +172,20 @@ - + + + + diff --git a/mallinkService/src/main/resources/mapper/WxBillOtherMapper.xml b/mallinkService/src/main/resources/mapper/WxBillOtherMapper.xml index cffecf5e8..1a0ec8638 100644 --- a/mallinkService/src/main/resources/mapper/WxBillOtherMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxBillOtherMapper.xml @@ -165,14 +165,20 @@ - + + + + diff --git a/mallinkService/src/main/resources/mapper/WxBillPropertyDepositMapper.xml b/mallinkService/src/main/resources/mapper/WxBillPropertyDepositMapper.xml index 9d6e16598..797ea8e9b 100644 --- a/mallinkService/src/main/resources/mapper/WxBillPropertyDepositMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxBillPropertyDepositMapper.xml @@ -161,14 +161,20 @@ - + + + + diff --git a/mallinkService/src/main/resources/mapper/WxBillPropertyMapper.xml b/mallinkService/src/main/resources/mapper/WxBillPropertyMapper.xml index 5e60bb768..618d8084a 100644 --- a/mallinkService/src/main/resources/mapper/WxBillPropertyMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxBillPropertyMapper.xml @@ -202,14 +202,20 @@ - + + + + diff --git a/mallinkService/src/main/resources/mapper/WxBillRentManageMapper.xml b/mallinkService/src/main/resources/mapper/WxBillRentManageMapper.xml index 6b600975d..45cf02a5e 100644 --- a/mallinkService/src/main/resources/mapper/WxBillRentManageMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxBillRentManageMapper.xml @@ -178,13 +178,19 @@ + + + diff --git a/mallinkService/src/main/resources/mapper/WxBillRentMapper.xml b/mallinkService/src/main/resources/mapper/WxBillRentMapper.xml index 54e7d25d6..5aaf4e2d1 100644 --- a/mallinkService/src/main/resources/mapper/WxBillRentMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxBillRentMapper.xml @@ -203,13 +203,19 @@ + + +