xhxu 3 лет назад
Родитель
Сommit
023e30265a
9 измененных файлов: 354 добавлений и 379 удалений
  1. +24
    -27
      mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponController.java
  2. +43
    -19
      mallinkBApi/src/main/java/com/iformall/controller/WxCouponController.java
  3. +0
    -88
      mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java
  4. +14
    -0
      mallinkService/src/main/java/com/iformall/enums/EnumAppPlat.java
  5. +50
    -2
      mallinkService/src/main/java/com/iformall/enums/EnumCouponType.java
  6. +9
    -0
      mallinkService/src/main/java/com/iformall/service/WxCouponService.java
  7. +212
    -237
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java
  8. +1
    -5
      mallinkService/src/main/java/com/iformall/service/impl/WxMerchantServiceImpl.java
  9. +1
    -1
      mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java

+ 24
- 27
mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponController.java Просмотреть файл

@@ -121,7 +121,7 @@ public class WxCouponController extends BaseController {
Integer[] typeArray = {
EnumCouponType.COUPON_MANJIAN.getCode(),
EnumCouponType.COUPON_DAIJIN.getCode(),
EnumCouponType.COUPON_TUANGOU.getCode(),
// EnumCouponType.COUPON_TUANGOU.getCode(),
EnumCouponType.COUPON_LIPIN.getCode(),
EnumCouponType.COUPON_TINGCHE.getCode(),
EnumCouponType.COUPON_MULTIMCH.getCode(),
@@ -184,30 +184,22 @@ public class WxCouponController extends BaseController {
if (wxCoupon.getId() == null) {
return new ResultData(ResultData.ERROR, "缺少id");
}
wxCoupon.updateTenantInfo(getTenantInfo());
if(EnumDelFlag.YES.getCode().equals(wxCoupon.getIsDel())){
WxCouponChannel query = new WxCouponChannel();
query.updateTenantInfo(wxCoupon);
query.setCouponId(wxCoupon.getId());
query.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode());
if (CollectionUtils.isNotEmpty(wxCouponChannelService.findList(query))) {
return new ResultData(ResultData.ERROR, "有活动正在上架,请先下架。");
}
// query.setStatus(EnumCouponChannelStatus.STATUS_BEFORE.getCode());
// if (CollectionUtils.isNotEmpty(wxCouponChannelService.findList(query))) {
// TtCouponChannelPoi ttCouponChannelPoi = wxCouponService.getCouponChannelPoi(getTenantInfo(),wxCoupon.getId());
// if(EnumSpuSyncStatus.sync_auditing.getCode().equals(ttCouponChannelPoi.getLastStatus())){
// return new ResultData(ResultData.ERROR, "有活动正在预审核.");
// }
// }
}
WxCoupon coupon = wxCouponService.getById(wxCoupon.getId(),wxCoupon.getTenantId());
if (null == coupon) {
return new ResultData(ResultData.ERROR, "券未查询到。"+wxCoupon.getId());
return new ResultData(ResultData.ERROR, "券未查询到。"+wxCoupon.getId());
}
redisLock.setCouponStock(wxCoupon.getId(), coupon.getRemainInventory());

if(EnumDelFlag.YES.getCode().equals(wxCoupon.getIsDel())){
if(!EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode().equals(coupon.getStatus())){
return new ResultData(ResultData.ERROR, "请先作废,再进行删除。");
}
wxCouponService.deleteById(wxCoupon.getId(),wxCoupon.getTenantId());
CouponCacheUtils.removeCouponCache(redisTemplate, wxCoupon.getId());
CouponCacheUtils.removeCouponMerchantCache(redisTemplate, wxCoupon.getId());
return new ResultData();
}

//启动审批流
if (wxCoupon.getFlowParams() != null && wxCoupon.getFlowParams().size() > 0) {
logger.info("------coupon.update().businessType:"+wxCoupon.getFlowParams().get("businessType"));
@@ -222,8 +214,15 @@ public class WxCouponController extends BaseController {
wxCoupon.setPutApplyStatus(EnumRentContractAppStatus.APPLYING.getCode());
}
}
ResultData result = wxCouponService.saveOrUpdate(wxCoupon);

ResultData result = null;
if(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode().equals(wxCoupon.getStatus())){
result = wxCouponService.disable(wxCoupon, wxCoupon.getId());
}else{
result = wxCouponService.saveOrUpdate(wxCoupon);
redisLock.setCouponStock(wxCoupon.getId(), wxCoupon.getRemainInventory());
}

CouponCacheUtils.removeCouponCache(redisTemplate, wxCoupon.getId());
CouponCacheUtils.removeCouponMerchantCache(redisTemplate, wxCoupon.getId());
return result;
@@ -339,10 +338,8 @@ public class WxCouponController extends BaseController {
return new ResultData(ErrorCode.COUPON_STOCK_ENDTIME_ERR);
}
wxCoupon.setSalePrice(coupon.getSalePrice());
if(!EnumCouponType.COUPON_DOUYIN.getCode().equals(wxCoupon.getType())
&& !wxCouponService.validCouponDate(wxCoupon)) {
// if(!wxCouponService.validCouponDate(wxCoupon)) {
return new ResultData(ResultData.ERROR,"券有效使用日期必须在30天以内。");
if(!wxCouponService.validCouponDate(wxCoupon)) {
return new ResultData(ResultData.ERROR,"券有效结束日期必须在30天以内。");
}
wxCoupon.setSalePrice(null);



+ 43
- 19
mallinkBApi/src/main/java/com/iformall/controller/WxCouponController.java Просмотреть файл

@@ -98,7 +98,7 @@ public class WxCouponController extends BaseController {
Integer[] typeArray = {
EnumCouponType.COUPON_MANJIAN.getCode(),
EnumCouponType.COUPON_DAIJIN.getCode(),
EnumCouponType.COUPON_TUANGOU.getCode(),
// EnumCouponType.COUPON_TUANGOU.getCode(),
EnumCouponType.COUPON_LIPIN.getCode(),
EnumCouponType.COUPON_TINGCHE.getCode(),
EnumCouponType.COUPON_MULTIMCH.getCode(),
@@ -230,36 +230,60 @@ public class WxCouponController extends BaseController {
@ApiOperation("根据id更新接口")
@PostMapping("update")
public ResultData update(@RequestBody WxCoupon wxCoupon) {
if (!hasMerchantCouponFlow()) {
return new ResultData(Result.ERROR,EnumFlowKey.B_COUPON_MERCHANT_CREATE.getMessage()+"未配置审批流程");
}

logger.debug("[" + getIpAddr() + "] WxCouponController::update");
if (wxCoupon.getId() == null) {
return new ResultData(ResultData.ERROR, "缺少id");
}
WxCoupon coupon = wxCouponService.getById(wxCoupon.getId(),wxCoupon.getTenantId());
if (null == coupon) {
return new ResultData(ResultData.ERROR, "券未查询到。"+wxCoupon.getId());
}
wxCoupon.updateTenantInfo(getTenantInfo());
if(EnumDelFlag.YES.getCode().equals(wxCoupon.getIsDel())){
WxCouponChannel query = new WxCouponChannel();
query.updateTenantInfo(wxCoupon);
query.setCouponId(wxCoupon.getId());
query.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode());
if (CollectionUtils.isNotEmpty(wxCouponChannelService.findList(query))) {
return new ResultData(ResultData.ERROR, "有活动正在上架,请先下架。");
if(!EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode().equals(coupon.getStatus())){
return new ResultData(ResultData.ERROR, "请先作废,再进行删除。");
}
wxCouponService.deleteById(wxCoupon.getId(),wxCoupon.getTenantId());
CouponCacheUtils.removeCouponCache(redisTemplate, wxCoupon.getId());
CouponCacheUtils.removeCouponMerchantCache(redisTemplate, wxCoupon.getId());
return new ResultData();
}

List<WxMerchant> merchantList = new ArrayList<>();
WxMerchant wxMerchant = wxMerchantService.getById(getLoginBUser().getMerchantId());
merchantList.add(wxMerchant);
if (!hasMerchantCouponFlow()) {
return new ResultData(Result.ERROR,EnumFlowKey.B_COUPON_MERCHANT_CREATE.getMessage()+"未配置审批流程");
}

wxCoupon.setMerchantParams(JSONObject.toJSONString(merchantList));
//启动审批流
WxMerchantBUser buser = getLoginBUser();
if (wxCoupon.getFlowParams() != null && wxCoupon.getFlowParams().size() > 0) {
logger.info("------coupon.update().businessType:"+wxCoupon.getFlowParams().get("businessType"));
wxCoupon.getFlowParams().put("businessId",wxCoupon.getId());
wxFlowService.start(wxCoupon.getFlowParams(), buser.getId(), buser.getName(), getTenantInfo());
//作废审批
if (EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode().equals(wxCoupon.getStatus())) {
wxCoupon.setCancleApplyStatus(EnumRentContractAppStatus.APPLYING.getCode());
return new ResultData(wxCoupon);
} else {
//投放审批
wxCoupon.setPutApplyStatus(EnumRentContractAppStatus.APPLYING.getCode());
}
}

WxCoupon coupon = wxCouponService.getById(wxCoupon.getId(),wxCoupon.getTenantId());
if (null == coupon) {
return new ResultData(ResultData.ERROR, "券未查询到。"+wxCoupon.getId());
ResultData result = null;
if(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode().equals(wxCoupon.getStatus())){
result = wxCouponService.disable(wxCoupon, wxCoupon.getId());
}else{
List<WxMerchant> merchantList = new ArrayList<>();
WxMerchant wxMerchant = wxMerchantService.selectById(getLoginBUser().getMerchantId());
merchantList.add(wxMerchant);

wxCoupon.setMerchantParams(JSONObject.toJSONString(merchantList));

result = wxCouponService.saveOrUpdate(wxCoupon);
redisLock.setCouponStock(wxCoupon.getId(), wxCoupon.getRemainInventory());
}
redisLock.setCouponStock(wxCoupon.getId(), coupon.getRemainInventory());
ResultData result = wxCouponService.saveOrUpdate(wxCoupon);

CouponCacheUtils.removeCouponCache(redisTemplate, wxCoupon.getId());
CouponCacheUtils.removeCouponMerchantCache(redisTemplate, wxCoupon.getId());
return result;


+ 0
- 88
mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java Просмотреть файл

@@ -448,94 +448,6 @@ public class WxCoupon extends TenantEntity {
return false;
}
public boolean validDate(boolean isShare,Date curr) {
if(this.getType().equals(EnumCouponType.COUPON_DOUYIN.getCode())){
return true;
}
if(isShare && this.getSalePrice() > 0 && !this.checkIsCard()){
Date valid_date = getOuterRealValidDate(curr);
Date limit_date = DateUtils.getTimeAfterDays(Constant.WX_LIMIT_DAYS, curr);

if (valid_date.after(limit_date)) {
return false;
}
}
return true;


// Map retMap = calcuteValidDate(isShare, hasShareAmount, curr);
// int success = (int) retMap.get("success");
// if (success > 0) {
// return true;
// }else {
// return false;
// }
}
public Date getRealValidDate(Date curr) {
//券都上架卖出去了还判断个什么有效期
// Map retMap = calcuteValidDate(isShare,hasShareAmount,curr);
// return (Date) retMap.get("realDate");
return getOuterRealValidDate(curr);
}
// private Map calcuteValidDate(boolean isShare,boolean hasShareAmount,Date curr) {
// if(this.getType().equals(EnumCouponType.COUPON_DOUYIN.getCode())){
// Map retMap = new HashMap();
// retMap.put("success", 1);
// retMap.put("realDate", getOuterRealValidDate(new Date()));
// return retMap;
// }
// int limit_days = Constant.WX_LIMIT_DAYS;
// int success = 1;
// Date valid_date = null;
// if (this.getValidType().equals(EnumValidStatus.VALID_RANGE.getCode()) ||
// this.getType().equals(EnumCouponType.COUPON_TINGCHE.getCode())) {
//
// if( this.getType().equals(EnumCouponType.COUPON_PREORDER.getCode())){
// valid_date = this.getPickEndDate();
// }else{
// valid_date = this.getValidEndDate();
// }
// if (this.getSalePrice() > 0 && !this.checkIsCard()) {
// if (hasShareAmount) {
// if (isShare) {
// // 分账有价券核销有效期不能大于分账过期时间
// Date limit_date = DateUtils.getTimeAfterDays(limit_days, curr);
// if (valid_date.after(limit_date)) {
// valid_date = limit_date;
// success = 0;
// }
// }
// }
// }
// } else {
// if (this.getSalePrice() > 0 && !this.checkIsCard()) {
// if (hasShareAmount) {
// // 分账有价券核销有效期不能大于分账过期时间
// if (isShare) {
// if (this.getValidDays() < Constant.WX_LIMIT_DAYS) {
// limit_days = this.getValidDays();
// }else {
// success = 0;
// }
// }else {
// limit_days = this.getValidDays();
// }
// }else{
// limit_days = this.getValidDays();
// }
// } else {
// limit_days = this.getValidDays();
// }
// valid_date = DateUtils.getTimeAfterDays(limit_days, curr);
// }
// Map retMap = new HashMap();
// retMap.put("success", success);
// retMap.put("realDate", valid_date);
// return retMap;
// }
public Date getOuterRealValidDate(Date curr) {
Date valid_date = null;


+ 14
- 0
mallinkService/src/main/java/com/iformall/enums/EnumAppPlat.java Просмотреть файл

@@ -1,5 +1,8 @@
package com.iformall.enums;

import com.iformall.common.ErrorCode;
import com.iformall.exception.MallinkException;

/**
* app平台
* @author alascor
@@ -35,4 +38,15 @@ public enum EnumAppPlat {
}
return null;
}

public static EnumPayWay getPayWay(EnumAppPlat plat){
if(WX.equals(plat)){
return EnumPayWay.PAY_WAY_WECHAT;
}else if(ALI.equals(plat)){
return EnumPayWay.PAY_WAY_ALIPAY;
}else if(TOUTIAO.equals(plat)){
return EnumPayWay.PAY_WAY_TT;
}
throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "未找到对应支付");
}
}

+ 50
- 2
mallinkService/src/main/java/com/iformall/enums/EnumCouponType.java Просмотреть файл

@@ -1,5 +1,8 @@
package com.iformall.enums;

import com.iformall.common.ErrorCode;
import com.iformall.exception.MallinkException;

import java.util.ArrayList;
import java.util.List;

@@ -12,13 +15,13 @@ public enum EnumCouponType {
// 100.消费卡
COUPON_MANJIAN(1, "满减券"),
COUPON_DAIJIN(2, "代金券"),
COUPON_TUANGOU(3, "团购券"),//没
// COUPON_TUANGOU(3, "团购券"),//弃
COUPON_LIPIN(4, "礼品券"),
COUPON_TINGCHE(5, "停车券"),
COUPON_MULTIMCH(6, "通用券"),
COUPON_DOUYIN(66, "抖音券"),
COUPON_PRESS(8, "砍价券"),
COUPON_GROUP(9, "团券"),
COUPON_GROUP(9, "团券"),
COUPON_PREORDER(10, "预购商品"),
COUPON_DISTRIBUTION(11, "可配送商品"),
COUPON_GIFT(12, "券礼包"),
@@ -64,6 +67,10 @@ public enum EnumCouponType {
return message;
}

/**
* 抖音平台的券
* @return
*/
public static List<Integer> getDouYinType(){
List<Integer> typeList = new ArrayList<>();
typeList.add(COUPON_DOUYIN.getCode());
@@ -71,4 +78,45 @@ public enum EnumCouponType {
return typeList;
}

/**
* 微信平台的券
*/
public static List<Integer> getWeiXinType(){
List<Integer> typeList = new ArrayList<>();
typeList.add(COUPON_MANJIAN.getCode());
typeList.add(COUPON_DAIJIN.getCode());
// typeList.add(COUPON_TUANGOU.getCode());
typeList.add(COUPON_LIPIN.getCode());
typeList.add(COUPON_TINGCHE.getCode());
typeList.add(COUPON_MULTIMCH.getCode());
typeList.add(COUPON_PRESS.getCode());
typeList.add(COUPON_GROUP.getCode());
typeList.add(COUPON_PREORDER.getCode());
typeList.add(COUPON_DISTRIBUTION.getCode());
typeList.add(COUPON_GIFT.getCode());
typeList.add(COUPON_CREDIT.getCode());
typeList.add(COUPON_CREDIT_PARK.getCode());
typeList.add(CARD_MULTIMCH.getCode());
return typeList;
}

/**
* 有价 并且永不分账的券类型
*/
public static List<Integer> getPlatType(){
List<Integer> typeList = new ArrayList<>();
typeList.add(COUPON_GIFT.getCode());
typeList.add(CARD_MULTIMCH.getCode());
return typeList;
}

public static EnumAppPlat getAppPlat(Integer couponType){
if(getWeiXinType().contains(couponType)){
return EnumAppPlat.WX;
}else if(getDouYinType().contains(couponType)){
return EnumAppPlat.TOUTIAO;
}
throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "券类型错误,未找到对应平台");
}

}

+ 9
- 0
mallinkService/src/main/java/com/iformall/service/WxCouponService.java Просмотреть файл

@@ -10,6 +10,7 @@ import com.iformall.common.ResultData;
import com.iformall.domain.po.TtCouponChannelPoi;
import com.iformall.domain.po.WxAppinfo;
import com.iformall.domain.po.WxCoupon;
import com.iformall.domain.po.WxMerchant;
import com.iformall.domain.po.base.TenantEntity;
import com.iformall.domain.vo.TtCouponVo;
import com.iformall.domain.vo.WxCouponCVo;
@@ -267,6 +268,7 @@ public interface WxCouponService {


boolean validCouponDate(WxCoupon wxCoupon);
ResultData validGiftCouponDate(WxCoupon wxCoupon);

/**
* 获取券商户map
@@ -278,4 +280,11 @@ public interface WxCouponService {

List<WxMerchantVo> getCouponMerchantList(TenantEntity tenantInfo, Long couponId);

/**
* 作废卷
* @param tenantInfo
* @param couponId
* @return
*/
ResultData disable(TenantEntity tenantInfo, Long couponId);
}

+ 212
- 237
mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java Просмотреть файл

@@ -33,6 +33,8 @@ 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.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@@ -102,6 +104,9 @@ public class WxCouponServiceImpl implements WxCouponService {

@Autowired
WxPayAccountMapper payAccountMapper;

@Autowired
WxPayAccountService payAccountService;
@Autowired
WxCouponOrderMapper wxCouponOrderMapper;
@@ -353,7 +358,7 @@ public class WxCouponServiceImpl implements WxCouponService {
@Override
@Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
public ResultData saveOrUpdate(WxCoupon record) {
//金额处理
if (StringUtils.isNotEmpty(record.getSalePriceStr())) {
record.setSalePrice(new BigDecimal(record.getSalePriceStr()).multiply(new BigDecimal(100)).intValue());
}
@@ -375,16 +380,36 @@ public class WxCouponServiceImpl implements WxCouponService {
if (StringUtils.isNotEmpty(record.getSubsidyNumStr())) {
record.setSubsidyNum(new BigDecimal(record.getSubsidyNumStr()).multiply(new BigDecimal(100)).intValue());
}
// if (EnumCouponType.COUPON_DOUYIN.getCode().equals(record.getType())){
// if(StringUtils.isBlank(record.getItemGroup())){
// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"团购详情不能为");
// }
// try{
// JSON.parseArray(record.getItemGroup());
// }catch(Exception e){
// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"团购详情格式不正确");
// }
// }
//补贴处理
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 (record.getSubsidyNum() > record.getSalePrice()) {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "补贴额大于售价");
}
} else if (EnumCouponSubsidyType.OFFLINE_SUBSIDY.getCode().equals(record.getSubsidyType())) {
// 线下补贴
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<String> strList = new ArrayList<String>();
if (StringUtils.isNotBlank(record.getCoverImg())) {
@@ -405,133 +430,62 @@ public class WxCouponServiceImpl implements WxCouponService {
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请填写有效时间类型");
}
if(!this.validCouponDate(record)) {
return new ResultData(ResultData.ERROR,"券有效使用日期必须在30天以内。");
}
}

if(EnumCouponType.COUPON_GIFT.getCode().equals(record.getType()) && EnumCouponValidType.BETWEEN_TWO_TIME.getCode().equals(record.getValidType())){
//券礼包时间判断
WxCoupon couponQ = new WxCoupon();
couponQ.updateTenantInfo(record);
List<Long> longs = JSON.parseArray(record.getGiftList(), Long.class);
if(longs != null && longs.size() > 0){
couponQ.setIds(longs);
List<WxCoupon> list = wxCouponMapper.findList(couponQ);
if(list != null && list.size() > 0){
for (WxCoupon wc:list) {
if(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode().equals(wc.getStatus())){
return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF_GIFT);
}
if(EnumCouponValidType.BETWEEN_TWO_TIME.getCode().equals(wc.getValidType()) && wc.getValidEndDate().before(record.getValidEndDate())){
return new ResultData(ErrorCode.COUPON_VALID_DATE_ERR_GIFT);
}
}
}else{
return new ResultData(ErrorCode.COUPON_IS_EMPTY_GIFT);
}
}else{
return new ResultData(ErrorCode.COUPON_IS_EMPTY_GIFT);
return new ResultData(ResultData.ERROR,"券有效结束日期必须在30天以内。");
}
}

if (EnumCouponContentType.HTML.getCode().equals(record.getContentType())) {
if (StringUtils.isEmpty(record.getHtml())) {
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请填写富文本内容");
}
ResultData giftResult = this.validGiftCouponDate(record);
if(Result.SUCCESS != giftResult.code){
return giftResult;
}

ResultData resultData = checkCouponMerchantReceiver(record);
if(resultData.code != 200){
return resultData;
ResultData receiverResult = checkCouponMerchantReceiver(record);
if(Result.SUCCESS != giftResult.code){
return receiverResult;
}
List<JSONObject> merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class);

final IdWorker idWorker = IdWorker.get();
if (record.getId() == null) {

// check 卡券补贴设置
Integer subsidyType = record.getSubsidyType();
Integer subsidyNum = record.getSubsidyNum();
if(subsidyType != null && subsidyNum != null) {
if (subsidyType.equals(EnumCouponSubsidyType.WECHAT_COUPON.getCode())) {
// 微信 立减
if (subsidyNum > record.getSalePrice()) {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "补贴额大于售价");
}
} else if (subsidyType.equals(EnumCouponSubsidyType.OFFLINE_SUBSIDY.getCode())) {
// 线下补贴
int subsidy_num = record.getPrice() - record.getSalePrice();
if (subsidyNum > subsidy_num) {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "补贴额大于面额与售价的差值");
}
} else if (subsidyType.equals(EnumCouponSubsidyType.WECHAT_MCHPAY.getCode())) {
// TODO 微信转账到银行卡

}
}

record.setId(idWorker.nextId());

if (merchantParamList != null && merchantParamList.size() > 0) {
List<WxCouponMerchantDto> wxCouponMerchantDtoList = new ArrayList<>();
merchantParamList.forEach(merchantParam -> {
WxCouponMerchant cm = new WxCouponMerchant();
WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam);
cm.setId(idWorker.nextId());
cm.updateTenantInfo(record);
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());
wxCouponMerchantDtoList.add(wxCouponMerchantDto);
wxCouponMerchantMapper.insert(cm);
});
if (wxCouponMerchantDtoList.stream()
.mapToInt(WxCouponMerchantDto::getBusiness).distinct().count() > 1) {
record.setBusiness(EnumBusiness.BUSINESS_ID6.getCode());
} else if (wxCouponMerchantDtoList.size() > 1){
record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness());
} else {
record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness());
record.setSubBusiness(wxCouponMerchantDtoList.get(0).getSubBusiness());
}

} else{
if (!EnumCouponType.COUPON_GIFT.getCode().equals(record.getType())){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL);
}
List<WxCouponMerchantDto> wxCouponMerchantDtoList = new ArrayList<>();
merchantParamList.forEach(merchantParam -> {
WxCouponMerchant cm = new WxCouponMerchant();
WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam);
cm.setId(idWorker.nextId());
cm.updateTenantInfo(record);
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());
wxCouponMerchantDtoList.add(wxCouponMerchantDto);
wxCouponMerchantMapper.insert(cm);
});
if (wxCouponMerchantDtoList.stream()
.mapToInt(WxCouponMerchantDto::getBusiness).distinct().count() > 1) {
record.setBusiness(EnumBusiness.BUSINESS_ID6.getCode());
} else if (wxCouponMerchantDtoList.size() > 1){
record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness());
} else {
record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness());
record.setSubBusiness(wxCouponMerchantDtoList.get(0).getSubBusiness());
}

if (record.getPasswordSupport() != null && record.getPasswordSupport().equals(EnumCouponPasswordSupport.SUPPORTED.getCode())) {
// 如果用户启用卡密,生成数据并保存
// todo 生成卡密无法修改, 调整
couponPasswordService.mkPasswords(record, record.getId(), record.getInventory());
}

record.setId(idWorker.nextId());
record.setCreateDate(new Date());
record.setUpdateDate(new Date());
wxCouponMapper.insert(record);

} else {
if(EnumCouponSendType.GIFT.getCode().equals(record.getSendType())){
//券礼包子券类型判断时间
WxCoupon couponQ = new WxCoupon();
couponQ.updateTenantInfo(record);
couponQ.setStatus(EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode());
couponQ.setGiftList(Long.toString(record.getId()));
List<WxCoupon> couponList = wxCouponMapper.findCouponList(couponQ);
if(couponList != null && couponList.size() > 0){
for (WxCoupon wc:couponList) {
if(EnumCouponType.COUPON_GIFT.getCode().equals(wc.getType())
&& EnumCouponValidType.BETWEEN_TWO_TIME.getCode().equals(record.getValidType())
&& record.getValidEndDate().before(wc.getValidEndDate())){
return new ResultData(ErrorCode.COUPON_VALID_DATE_ERR_GIFT);
}
}
}
}

if(record.getInventory() != null && record.getRemainInventory() != null) {
// 库存修改检查
WxCoupon oldCoupon = wxCouponMapper.selectById(record.getId(),record.getTenantId());
@@ -547,86 +501,56 @@ public class WxCouponServiceImpl implements WxCouponService {
record.setInventory(oldCoupon.getInventory() + record.getRemainInventory() - oldCoupon.getRemainInventory());
}
}
if (merchantParamList != null && merchantParamList.size() > 0) {
WxCouponMerchant cmParam = new WxCouponMerchant();
cmParam.updateTenantInfo(record);
cmParam.setProductId(record.getId());
List<WxCouponMerchant> oldList = wxCouponMerchantMapper.findList(cmParam);
List<WxCouponMerchantDto> wxCouponMerchantDtoList = new ArrayList<>();
merchantParamList.stream().forEach(merchantParam -> {
WxCouponMerchant cm = new WxCouponMerchant();
WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam);
cm.updateTenantInfo(record);
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);
}
wxCouponMerchantDtoList.add(wxCouponMerchantDto);
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);
});

if (wxCouponMerchantDtoList.stream()
.mapToInt(WxCouponMerchantDto::getBusiness).distinct().count() > 1) {
record.setBusiness(EnumBusiness.BUSINESS_ID6.getCode());
} else if (wxCouponMerchantDtoList.size() > 1){
record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness());
} else {
record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness());
record.setSubBusiness(wxCouponMerchantDtoList.get(0).getSubBusiness());

WxCouponMerchant cmParam = new WxCouponMerchant();
cmParam.updateTenantInfo(record);
cmParam.setProductId(record.getId());
List<WxCouponMerchant> oldList = wxCouponMerchantMapper.findList(cmParam);
List<WxCouponMerchantDto> wxCouponMerchantDtoList = new ArrayList<>();
merchantParamList.stream().forEach(merchantParam -> {
WxCouponMerchant cm = new WxCouponMerchant();
WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam);
cm.updateTenantInfo(record);
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);
}
wxCouponMerchantDtoList.add(wxCouponMerchantDto);
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);
});

if (wxCouponMerchantDtoList.stream()
.mapToInt(WxCouponMerchantDto::getBusiness).distinct().count() > 1) {
record.setBusiness(EnumBusiness.BUSINESS_ID6.getCode());
} else if (wxCouponMerchantDtoList.size() > 1){
record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness());
} else {
record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness());
record.setSubBusiness(wxCouponMerchantDtoList.get(0).getSubBusiness());
}

if (record.getStatus() != null &&
(record.getStatus().equals(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode()))) {

//下架所有投放频道
wxCouponChannelService.updateStatusByCouponId(record.getId(), record, EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode());
//下架所有场景投放
wxCouponSendService.updateStatusByCouponId(record.getId(), record, EnumCouponSendStatus.INVALID.getCode());
//下架所有已砍价券
wxOrderService.updateStatusByPressCouponId(record.getId(), record, EnumOrderStatus.ORDER_STATUS_PRESS_CANCEL.getCode());
//下架所有相关广告
wxScreenAdService.updateStatusByCouponId(record.getId(), record, EnumScreenAdStatus.INVALID.getCode());
//下架拼团券
wxOrderService.updateOrderGroupStatusByCouponId(record.getId(), record, EnumOrderStatus.ORDER_STATUS_COOPERATING_CANCEL.getCode());
// 卡下架后,转赠找不到卡相关信息,所以修改卡转赠状态为不可转赠
wxCardInfoMapper.updateTransferStatusByCouponId(record.getId());
// 卡券下架,未使用的卡密要下架
couponPasswordMapper.disableByCouponId(record.getId());


}
record.setUpdateDate(new Date());
wxCouponMapper.updateById(record);

try{
if(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode().equals(record.getStatus())){
//同步抖音状态
wxCouponChannelService.spuStatusSyncByCoupon(record,record.getId());
}
}catch(Exception e){
logger.error("send spuStatusSync error: " + e.getMessage());
}
}

//清空缓存
@@ -636,46 +560,24 @@ public class WxCouponServiceImpl implements WxCouponService {

private ResultData checkCouponMerchantReceiver(WxCoupon record){
List<JSONObject> merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class);
// if(EnumCouponType.COUPON_GIFT.getCode().equals(record.getType())){
// return new ResultData();
// }

if(merchantParamList == null || merchantParamList.isEmpty()){
return new ResultData();
return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND.getCode(),"所属商户为空");
}
if(record.getSalePrice() != null && record.getSalePrice() > 0) {
WxAppinfo cAppInfo = wxAppinfoService.getCouponAppInfo(record);
EnumAppPlat plat = EnumCouponType.getAppPlat(record.getType());
EnumPayWay payWay = EnumAppPlat.getPayWay(plat);
WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(record,plat);
if (cAppInfo == null) {
return new ResultData(ErrorCode.APP_ID_NOT_FOUND);
}
EnumAppPlat plat = EnumAppPlat.WX;
EnumAppPlat platEnum = EnumAppPlat.getByCode(cAppInfo.getPlat());
if (platEnum != null) {
plat = platEnum;
}
EnumPayWay payWay = EnumPayWay.PAY_WAY_WECHAT;
if(EnumAppPlat.TOUTIAO.equals(plat)){
payWay = EnumPayWay.PAY_WAY_TT;
}

WxPayAccount payAccount = payAccountMapper.selectById(cAppInfo.getPayId());
if (payAccount == null) {
return new ResultData(ErrorCode.APP_ID_NOT_FOUND);
}
EnumPayMchType payMchType = EnumPayMchType.TOTAL;
EnumPayShare isShare = EnumPayShare.NO;

EnumPayMchType payMchTypeEnum = EnumPayMchType.getEnum(payAccount.getMchType());
if (payMchTypeEnum != null) {
payMchType = payMchTypeEnum;
}
if (EnumPayMchType.DIRECT.equals(payMchType)) {
isShare = EnumPayShare.NO;
} else {
EnumPayShare paySHareEnum = EnumPayShare.getEnum(payAccount.getShare());
if (paySHareEnum != null) {
isShare = paySHareEnum;
}
}
EnumPayMchType payMchType = EnumPayMchType.getEnum(payAccount.getMchType());
EnumPayShare isShare = EnumPayShare.getEnum(payAccount.getShare());

PayShareAdapterService payShareServie = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion());
List<Long> merchantIds = new ArrayList<>();
@@ -708,7 +610,7 @@ public class WxCouponServiceImpl implements WxCouponService {
merchantId = merchantIds.get(0);
}
record.setMakeMerchantId(merchantId);
WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, merchantId, null, payMchTypeEnum.getCode());
WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, merchantId, null, payMchType.getCode());

if (receiver == null) {
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "["+idAndNamesMap.get(merchantId)+"]未配置收款账户");
@@ -723,7 +625,7 @@ public class WxCouponServiceImpl implements WxCouponService {
} else if (EnumPayShare.YES.equals(isShare)) {
List<String> merchantNames = new ArrayList();
for (Long merchantId:merchantIds) {
WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, merchantId, null, payMchTypeEnum.getCode());
WxProfitSharingReceiver receiver = payShareServie.getReceiver(payAccount, merchantId, null, payMchType.getCode());
if (receiver == null) {
merchantNames.add(idAndNamesMap.get(merchantId));
continue;
@@ -1232,33 +1134,75 @@ public class WxCouponServiceImpl implements WxCouponService {
return new ResultData();
}

//有价券开启了分账,必须在30天以内。,停车券,积分券,积分停车券,卡无次限制
/**
* 1.有价券
* 2.微信
* 3.分账 (因微信支付线上分账30天限制) 需要限制有效期30天
* @param wxCoupon
* @return boolean 有效期结束时间需要当前时间的30天限制 验证是否通过
*/
@Override
public boolean validCouponDate(WxCoupon wxCoupon) {
if(wxCoupon.getType().equals(EnumCouponType.COUPON_DOUYIN.getCode())){
if(wxCoupon.checkIsFree()){
return true;
}
if(wxCoupon.getSalePrice() == 0){
if(!EnumCouponType.getWeiXinType().contains(wxCoupon.getType())){
return true;
}
if(wxCoupon.checkIsCard()){
if(EnumCouponType.getPlatType().contains(wxCoupon.getType())){
return true;
}
EnumPayShare isShare = EnumPayShare.NO;
WxAppinfo appinfo = wxAppinfoService.getCouponAppInfo(wxCoupon);
if (null == appinfo) {
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(), "券未查询到appInfo");
WxPayAccount payAccount = payAccountService.getPayAccount(wxCoupon, EnumAppPlat.WX);
if(payAccount == null){
throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "未找到支付配置");
}
WxPayAccount payAccount = payAccountMapper.selectById(appinfo.getPayId());
EnumPayShare paySHareEnum = EnumPayShare.getEnum(payAccount.getShare());
if (paySHareEnum != null) {
isShare = paySHareEnum;
if(EnumPayShare.YES.getCode().equals(payAccount.getShare())){
Date now = new Date();
Date realValidDate = wxCoupon.getOuterRealValidDate(now);
Date limit_date = DateUtils.getTimeAfterDays(Constant.WX_LIMIT_DAYS, now);
if (realValidDate.after(limit_date)) {
return false;
}
}
if (EnumPayShare.YES.equals(isShare)) {
return wxCoupon.validDate(true,new Date());
}else{
return wxCoupon.validDate(false,new Date());
return true;

}

/**
* 礼包券判断子券有效期
* @param wxCoupon
* @return
*/
@Override
public ResultData validGiftCouponDate(WxCoupon wxCoupon){
if(!EnumCouponType.COUPON_GIFT.getCode().equals(wxCoupon.getType())){
return new ResultData();
}
//获取子券
List<Long> 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<WxCoupon> giftList = wxCouponMapper.findList(couponQ);
if(giftList == null || giftList.isEmpty()){
throw new MallinkException(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();

}

@Override
@@ -1341,4 +1285,35 @@ public class WxCouponServiceImpl implements WxCouponService {
return merchantList;
}

@Override
@Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
public ResultData disable(TenantEntity tenantInfo, Long couponId) {
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());
//下架所有已砍价券
wxOrderService.updateStatusByPressCouponId(couponId, tenantInfo, EnumOrderStatus.ORDER_STATUS_PRESS_CANCEL.getCode());
//下架所有相关广告
wxScreenAdService.updateStatusByCouponId(couponId, tenantInfo, EnumScreenAdStatus.INVALID.getCode());
//下架拼团券
wxOrderService.updateOrderGroupStatusByCouponId(couponId, tenantInfo, EnumOrderStatus.ORDER_STATUS_COOPERATING_CANCEL.getCode());
// 卡下架后,转赠找不到卡相关信息,所以修改卡转赠状态为不可转赠
wxCardInfoMapper.updateTransferStatusByCouponId(couponId);
// 卡券下架,未使用的卡密要下架
couponPasswordMapper.disableByCouponId(couponId);

//同步抖音状态
wxCouponChannelService.spuStatusSyncByCoupon(tenantInfo,couponId);
}
return new ResultData();
}

}

+ 1
- 5
mallinkService/src/main/java/com/iformall/service/impl/WxMerchantServiceImpl.java Просмотреть файл

@@ -482,11 +482,7 @@ public class WxMerchantServiceImpl implements WxMerchantService {
List<Long> couponIds = wxCouponMerchantList.stream().map(cm -> cm.getProductId()).collect(Collectors.toList());

couponIds.stream().filter(cid -> !isCouponMerchantValid(cid,wxCouponMerchant)).forEach(cid -> {
WxCoupon wxCoupon = new WxCoupon();
wxCoupon.setId(cid);
wxCoupon.updateTenantInfo(wxMerchant);
wxCoupon.setStatus(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode());
wxCouponService.saveOrUpdate(wxCoupon);
wxCouponService.disable(wxMerchant,cid);
CouponCacheUtils.removeCouponMerchantCache(redisTemplate, cid);
});
}


+ 1
- 1
mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java Просмотреть файл

@@ -1376,7 +1376,7 @@ public class WxOrderServiceImpl implements WxOrderService {
// if (null != payOrder && null != payOrder.getShare() && payOrder.getShare().intValue() > 0) {
// isShare = true;
// }
valid_date = coupon.getRealValidDate(curr);
valid_date = coupon.getOuterRealValidDate(curr);

boolean isCard = false;
// 检查是否是储值卡


Загрузка…
Отмена
Сохранить