Просмотр исходного кода

[系统发卡][修改][发放]

release_toaliyun_real
gongbiao 6 лет назад
Родитель
Сommit
a3cb50e80c
2 измененных файлов: 36 добавлений и 33 удалений
  1. +31
    -3
      mallinkAdmin/src/main/java/com/iformall/controller/market/WxCouponPresentController.java
  2. +5
    -30
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponPresentServiceImpl.java

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

@@ -7,8 +7,14 @@ import com.iformall.common.ResultData;
import com.iformall.controller.base.BaseController; import com.iformall.controller.base.BaseController;
import com.iformall.domain.po.BaseEntity; import com.iformall.domain.po.BaseEntity;
import com.iformall.domain.po.MallUserInfo; import com.iformall.domain.po.MallUserInfo;
import com.iformall.domain.po.WxCoupon;
import com.iformall.domain.po.WxCouponPresent; import com.iformall.domain.po.WxCouponPresent;
import com.iformall.enums.EnumCouponStatus;
import com.iformall.enums.EnumCouponValidType;
import com.iformall.exception.MallinkException;
import com.iformall.service.PushLimitService;
import com.iformall.service.WxCouponPresentService; import com.iformall.service.WxCouponPresentService;
import com.iformall.service.WxCouponService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
@@ -18,6 +24,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;


import java.util.Date;

/** /**
* @author gongbiao * @author gongbiao
*/ */
@@ -30,6 +38,12 @@ public class WxCouponPresentController extends BaseController {
@Autowired @Autowired
private WxCouponPresentService wxCouponPresentService; private WxCouponPresentService wxCouponPresentService;


@Autowired
PushLimitService pushLimitService;

@Autowired
WxCouponService wxCouponService;

@ApiOperation("分页列表接口") @ApiOperation("分页列表接口")
@GetMapping("/list") @GetMapping("/list")
@ApiImplicitParams({ @ApiImplicitParams({
@@ -67,11 +81,25 @@ public class WxCouponPresentController extends BaseController {
if (wxCouponPresent.getPhones().isEmpty()) { if (wxCouponPresent.getPhones().isEmpty()) {
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请填写手机号"); return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请填写手机号");
} }

MallUserInfo user = getUser(); MallUserInfo user = getUser();
wxCouponPresent.setTenantId(user.getTenantId());
wxCouponPresent.setUserId(user.getId()); wxCouponPresent.setUserId(user.getId());

wxCouponPresent.setTenantId(user.getTenantId());
try {
pushLimitService.checkSendTime(user.getTenantId());
} catch (MallinkException e) {
logger.error(e.getMessage());
return new ResultData(e.getErrorCode(), e.getMessage());
}
WxCoupon wxCoupon = wxCouponService.getById(wxCouponPresent.getCouponId());
if (wxCoupon.getValidType().equals(EnumCouponValidType.BETWEEN_TWO_TIME.getCode())) { //时间范围
if (new Date().after(wxCoupon.getValidEndDate())) {
return new ResultData(ErrorCode.COUPON_IS_EXPIRED);
}
}
if (!wxCoupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode())) {
return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF);
}
wxCouponPresent.setCouponName(wxCoupon.getTitle());
return wxCouponPresentService.add(wxCouponPresent); return wxCouponPresentService.add(wxCouponPresent);
} }




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

@@ -6,22 +6,19 @@ import com.iformall.common.ErrorCode;
import com.iformall.common.IdWorker; import com.iformall.common.IdWorker;
import com.iformall.common.ResultData; import com.iformall.common.ResultData;
import com.iformall.domain.po.WxAppinfo; import com.iformall.domain.po.WxAppinfo;
import com.iformall.domain.po.WxCoupon;
import com.iformall.domain.po.WxCouponPassword; import com.iformall.domain.po.WxCouponPassword;
import com.iformall.domain.po.WxCouponPresent; import com.iformall.domain.po.WxCouponPresent;
import com.iformall.domain.po.msg.WxMsgRecord; import com.iformall.domain.po.msg.WxMsgRecord;
import com.iformall.enums.*; import com.iformall.enums.*;
import com.iformall.exception.MallinkException;
import com.iformall.mapper.WxCouponPasswordMapper; import com.iformall.mapper.WxCouponPasswordMapper;
import com.iformall.mapper.WxCouponPresentMapper; import com.iformall.mapper.WxCouponPresentMapper;
import com.iformall.mq.MqBaseProducer; import com.iformall.mq.MqBaseProducer;
import com.iformall.service.PushLimitService;
import com.iformall.service.WxAppinfoService; import com.iformall.service.WxAppinfoService;
import com.iformall.service.WxCouponPresentService; import com.iformall.service.WxCouponPresentService;
import com.iformall.service.WxCouponService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;


import java.util.*; import java.util.*;
@@ -36,12 +33,6 @@ public class WxCouponPresentServiceImpl implements WxCouponPresentService {
@Autowired @Autowired
WxCouponPresentMapper wxCouponPresentMapper; WxCouponPresentMapper wxCouponPresentMapper;


@Autowired
PushLimitService pushLimitService;

@Autowired
WxCouponService wxCouponService;

@Autowired @Autowired
WxCouponPasswordMapper wxCouponPasswordMapper; WxCouponPasswordMapper wxCouponPasswordMapper;


@@ -61,26 +52,11 @@ public class WxCouponPresentServiceImpl implements WxCouponPresentService {
return wxCouponPresentMapper.selectByPrimaryKey(id); return wxCouponPresentMapper.selectByPrimaryKey(id);
} }


@Async
@Override @Override
public ResultData add(WxCouponPresent record) { public ResultData add(WxCouponPresent record) {
String tenantId = record.getTenantId(); String tenantId = record.getTenantId();
try {
pushLimitService.checkSendTime(tenantId);
} catch (MallinkException e) {
logger.error(e.getMessage());
return new ResultData(e.getErrorCode(), e.getMessage());
}
WxCoupon wxCoupon = wxCouponService.getById(record.getCouponId());
if (wxCoupon.getValidType().equals(EnumCouponValidType.BETWEEN_TWO_TIME.getCode())) { //时间范围
if (new Date().after(wxCoupon.getValidEndDate())) {
return new ResultData(ErrorCode.COUPON_IS_EXPIRED);
}
}
if (!wxCoupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode())) {
return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF);
}
//获取手机号 //获取手机号
record.setCouponName(wxCoupon.getTitle());
String phones = record.getPhones(); String phones = record.getPhones();
String[] phoneSplit = phones.split(","); String[] phoneSplit = phones.split(",");
Set<String> phoneSet = new HashSet<>(phoneSplit.length); Set<String> phoneSet = new HashSet<>(phoneSplit.length);
@@ -89,7 +65,6 @@ public class WxCouponPresentServiceImpl implements WxCouponPresentService {
phoneSet.add(phone); phoneSet.add(phone);
} }
} }

//查询有效券数量 //查询有效券数量
WxCouponPassword wxCouponPassword = new WxCouponPassword(); WxCouponPassword wxCouponPassword = new WxCouponPassword();
wxCouponPassword.setTenantId(tenantId); wxCouponPassword.setTenantId(tenantId);
@@ -97,20 +72,20 @@ public class WxCouponPresentServiceImpl implements WxCouponPresentService {
wxCouponPassword.setStatus(EnumCouponPasswordStatus.INIT.getCode()); wxCouponPassword.setStatus(EnumCouponPasswordStatus.INIT.getCode());
List<WxCouponPassword> list = wxCouponPasswordMapper.findList(wxCouponPassword); List<WxCouponPassword> list = wxCouponPasswordMapper.findList(wxCouponPassword);
if (phoneSet.size() > list.size()) { if (phoneSet.size() > list.size()) {
logger.info(ErrorCode.REMAIN_IS_EMPTY.getMessage());
return new ResultData(ErrorCode.REMAIN_IS_EMPTY); return new ResultData(ErrorCode.REMAIN_IS_EMPTY);
} }
//添加记录 //添加记录
final IdWorker idWorker = IdWorker.get(); final IdWorker idWorker = IdWorker.get();
long id = idWorker.nextId(); long id = idWorker.nextId();
record.setId(id); record.setId(id);
record.setCouponName(wxCoupon.getTitle());
record.setSendAmount(phoneSet.size()); record.setSendAmount(phoneSet.size());
wxCouponPresentMapper.insertSelective(record); wxCouponPresentMapper.insertSelective(record);
//小程序 //小程序
WxAppinfo appInfo = wxAppinfoService.getCAppInfo(tenantId); WxAppinfo appInfo = wxAppinfoService.getCAppInfo(tenantId);
String title = wxCoupon.getTitle();
String title = record.getCouponName();
String name = appInfo.getName(); String name = appInfo.getName();
List<WxCouponPassword> tempList = wxCouponPasswordMapper.findList(wxCouponPassword);
List<WxCouponPassword> tempList = new ArrayList<>();
//循环发送 //循环发送
int i = 0; int i = 0;
for (String phone : phoneSet) { for (String phone : phoneSet) {


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