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

[停车发券/核销发券][新增]:功能调试通过

release_toaliyun_real
Stormeye.Wu 7 лет назад
Родитель
Сommit
4c4b3a5537
8 измененных файлов: 221 добавлений и 58 удалений
  1. +1
    -1
      mallinkAdmin/src/main/java/com/simple/controller/WxCarCallBackController.java
  2. +40
    -0
      mallinkService/src/main/java/com/simple/enums/EnumCouponActionChannelType.java
  3. +38
    -0
      mallinkService/src/main/java/com/simple/enums/EnumEnableType.java
  4. +4
    -3
      mallinkService/src/main/java/com/simple/service/WxCouponSendService.java
  5. +10
    -1
      mallinkService/src/main/java/com/simple/service/WxOrderService.java
  6. +1
    -1
      mallinkService/src/main/java/com/simple/service/impl/WxCouponOrderServiceImpl.java
  7. +40
    -48
      mallinkService/src/main/java/com/simple/service/impl/WxCouponSendServiceImpl.java
  8. +87
    -4
      mallinkService/src/main/java/com/simple/service/impl/WxOrderServiceImpl.java

+ 1
- 1
mallinkAdmin/src/main/java/com/simple/controller/WxCarCallBackController.java Просмотреть файл

@@ -109,7 +109,7 @@ public class WxCarCallBackController extends BaseController {
// TODO 可能多用户关联同一张车牌
List<WxCUserCar> userCarList = wxCUserCarService.getList(userCarQ);
for (WxCUserCar userCar : userCarList) {
wxCouponSendService.sendCouponToUser(tenantId, userCar.getCUserId(), EnumCouponSendType.CAR_STOP.getCode());
wxCouponSendService.sendCouponToUser(tenantId, userCar.getCUserId(), EnumCouponSendType.CAR_STOP);
}
}



+ 40
- 0
mallinkService/src/main/java/com/simple/enums/EnumCouponActionChannelType.java Просмотреть файл

@@ -0,0 +1,40 @@
package com.simple.enums;

/**
* Created by Stormeye on 2018/08/09.
*/
public enum EnumCouponActionChannelType {

// 0:精准 1:主动领取 2:用户购买 3:停车 4:核销
PRECISE(0, "精准"),
RECEIVE(1, "主动领取"),
BUY(2, "用户购买"),
CAR(3, "停车"),
VERIFY(4, "核销")
;

public static EnumCouponActionChannelType getEnum(Integer code) {
for (EnumCouponActionChannelType value : values()) {
if (value.getCode().equals(code)) {
return value;
}
}
return null;
}

private Integer code;
private String message;

EnumCouponActionChannelType(Integer code, String message) {
this.code = code;
this.message = message;
}

public Integer getCode() {
return code;
}

public String getMessage() {
return message;
}
}

+ 38
- 0
mallinkService/src/main/java/com/simple/enums/EnumEnableType.java Просмотреть файл

@@ -0,0 +1,38 @@
package com.simple.enums;

/**
* Created by Stormeye on 2018/08/09.
*/
public enum EnumEnableType {

// 0:启用 1:停用

Enable(0, "启用"),
Disable(1, "停用")
;

public static EnumEnableType getEnum(Integer code) {
for (EnumEnableType value : values()) {
if (value.getCode().equals(code)) {
return value;
}
}
return null;
}

private Integer code;
private String message;

EnumEnableType(Integer code, String message) {
this.code = code;
this.message = message;
}

public Integer getCode() {
return code;
}

public String getMessage() {
return message;
}
}

+ 4
- 3
mallinkService/src/main/java/com/simple/service/WxCouponSendService.java Просмотреть файл

@@ -3,6 +3,7 @@ package com.simple.service;
import java.util.*;
import com.github.pagehelper.PageInfo;
import com.simple.domain.po.WxCouponSend;
import com.simple.enums.EnumCouponSendType;

public interface WxCouponSendService {

@@ -10,8 +11,8 @@ public interface WxCouponSendService {
* 根据实体查询分页列表
*
* @param record
* @param offset
* @param limit
* @param pageIndex
* @param pageSize
* @return
*/
PageInfo<WxCouponSend> listAsPage(WxCouponSend record, Integer pageIndex, Integer pageSize);
@@ -44,7 +45,7 @@ public interface WxCouponSendService {
* @param cUserId
* @param type 2:停车发券 3:核销发券
*/
void sendCouponToUser(String tenantId,Long cUserId,int type);
void sendCouponToUser(String tenantId, Long cUserId, EnumCouponSendType type);

void updateStatusByCouponId(Long couponId,String tenantId,int status);


+ 10
- 1
mallinkService/src/main/java/com/simple/service/WxOrderService.java Просмотреть файл

@@ -5,6 +5,7 @@ import java.util.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.simple.domain.po.WxCUser;
import com.simple.domain.po.WxCouponOrder;
import com.simple.domain.po.WxOrder;
import com.simple.domain.vo.WxOrderCVo;
import com.simple.enums.EnumOrderStatus;
@@ -34,10 +35,18 @@ public interface WxOrderService {
* 免费券订单接口
* @param userId
* @param couponId
* @return 订单id
* @return WxOrder
*/
WxOrder sendUserFreeCoupon(Long userId, Long couponId);

/**
* 免费券订单接口
* @param userId
* @param couponId
* @return WxCouponOrder
*/
WxCouponOrder sendFreeCouponToUser(Long userId, Long couponId);

/**
* orderSuccess 订单已支付
* @param updateOrder


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

@@ -366,7 +366,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
WxOrder wxOrder = wxOrderMapper.selectByPrimaryKey(couponOrder.getOrderId());
if (wxOrder != null) {
try {
wxCouponSendService.sendCouponToUser(bUser.getTenantId(), wxOrder.getCUserId(), EnumCouponSendType.COUPON_VERIFY.getCode());
wxCouponSendService.sendCouponToUser(bUser.getTenantId(), wxOrder.getCUserId(), EnumCouponSendType.COUPON_VERIFY);
} catch (Exception e) {
logger.error("核销发券: " + e.getMessage());
}


+ 40
- 48
mallinkService/src/main/java/com/simple/service/impl/WxCouponSendServiceImpl.java Просмотреть файл

@@ -1,34 +1,41 @@
package com.simple.service.impl;

import java.util.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.simple.domain.po.WxCoupon;
import com.simple.domain.po.WxCouponOrder;
import com.simple.domain.po.WxCouponSend;
import com.simple.domain.po.WxMallConfig;
import com.simple.common.IdWorker;
import com.simple.domain.po.*;
import com.simple.enums.*;
import com.simple.mapper.WxCouponOrderMapper;
import com.simple.mapper.WxCouponSendMapper;
import com.simple.service.*;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.simple.common.IdWorker;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class WxCouponSendServiceImpl implements WxCouponSendService {
@Autowired
@Autowired
WxCouponSendMapper wxCouponSendMapper;
@Autowired
@Autowired
WxCouponOrderService wxCouponOrderService;
@Autowired
@Autowired
WxCouponService wxCouponService;
@Autowired
@Autowired
WxCouponActionLogService wxCouponActionLogService;
@Autowired
@Autowired
WxMallConfigService wxMallConfigService;

@Autowired
WxOrderService wxOrderService;

@Autowired
WxCouponOrderMapper wxCouponOrderMapper;


@Override
public PageInfo<WxCouponSend> listAsPage(WxCouponSend record, Integer pageIndex, Integer pageSize) {
@@ -45,7 +52,7 @@ public class WxCouponSendServiceImpl implements WxCouponSendService {
if (record.getId() == null) {
//record.setId(UUID.randomUUID().toString().replaceAll("-", ""));
final IdWorker idWorker = IdWorker.get();
record.setId(idWorker.nextId());
record.setId(idWorker.nextId());
wxCouponSendMapper.insertSelective(record);
} else {
wxCouponSendMapper.updateByPrimaryKeySelective(record);
@@ -59,61 +66,46 @@ public class WxCouponSendServiceImpl implements WxCouponSendService {

@Override
@Transactional
public void sendCouponToUser(String tenantId, Long cUserId, int type) {
public void sendCouponToUser(String tenantId, Long cUserId, EnumCouponSendType type) {
//查询开关是否打开
//查询停车或者核销的券 stopCarCouponSwitch verifyConponSwitch
WxCouponSend wxCouponSendQuery = new WxCouponSend();
wxCouponSendQuery.setTenantId(tenantId);
int actionLogType=0;
String configKey="";
if(type==2){
int actionLogType = 0;
String configKey = "";
if (type == EnumCouponSendType.CAR_STOP) {
//停车
wxCouponSendQuery.setSendType(2);
actionLogType=3;
configKey="stopCarCouponSwitch";
wxCouponSendQuery.setSendType(EnumCouponSendType.CAR_STOP.getCode());
actionLogType = EnumCouponActionChannelType.CAR.getCode();
configKey = "stopCarCouponSwitch";
}
if(type==3){
if (type == EnumCouponSendType.COUPON_VERIFY) {
//核销
wxCouponSendQuery.setSendType(3);
actionLogType=4;
configKey="verifyConponSwitch";
}else{
wxCouponSendQuery.setSendType(EnumCouponSendType.COUPON_VERIFY.getCode());
actionLogType = EnumCouponActionChannelType.VERIFY.getCode();
configKey = "verifyConponSwitch";
} else {
return;
}
WxMallConfig wxMallConfigQuery = new WxMallConfig();
wxMallConfigQuery.setKey(configKey);
wxMallConfigQuery.setTenantId(tenantId);
PageInfo<WxMallConfig> page = wxMallConfigService.listAsPage(wxMallConfigQuery, 1, 1);
if(page.getSize()>0) {
if (page.getSize() > 0) {
WxMallConfig config = page.getList().get(0);
if(config.getValue()==1){
if (config.getValue() == EnumEnableType.Disable.getCode()) {
return;
}
}


List<WxCouponSend> wxCouponSends = wxCouponSendMapper.findList(wxCouponSendQuery);
for (WxCouponSend send:wxCouponSends) {
WxCoupon wxCoupon= wxCouponService.getById(send.getCouponId());
WxCouponOrder wxCouponOrder = new WxCouponOrder();
wxCouponOrder.setCouponId(wxCoupon.getId());
wxCouponOrder.setCouponOrderStatus(0);
wxCouponOrder.setCUserId(cUserId);
wxCouponOrder.setCouponPrice(0);
wxCouponOrder.setCreateDate(new Date());
if (wxCoupon.getValidType() == 1) { //时间范围区间
if(new Date().after(wxCoupon.getValidEndDate())){
continue;
}
wxCouponOrder.setExpiredTime(wxCoupon.getValidEndDate());
} else {
Date date = DateUtils.addDays(new Date(), wxCoupon.getValidDays());
wxCouponOrder.setExpiredTime(date);
for (WxCouponSend send : wxCouponSends) {
// 发放免费券
WxCouponOrder couponOrder = wxOrderService.sendFreeCouponToUser(cUserId, send.getCouponId());
if (couponOrder != null) {
wxCouponActionLogService.addOne(tenantId, send.getCouponId(), couponOrder.getId(), actionLogType, send.getId());
}
wxCouponOrder.setTenantId(wxCoupon.getTenantId());
Long couponOrderId = wxCouponOrderService.insertOne(wxCouponOrder);
wxCouponActionLogService.addOne(tenantId, wxCoupon.getId(), couponOrderId, actionLogType, send.getId());
wxCouponService.reduceInventory(wxCoupon.getId(),1);
wxCouponService.reduceInventory(send.getCouponId(), 1);
}
}



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

@@ -259,7 +259,7 @@ public class WxOrderServiceImpl implements WxOrderService {
* @param order
* @param coupon
*/
private void createCouponOrder(WxCUser user, WxOrder order, WxCoupon coupon) {
private WxCouponOrder createCouponOrder(WxCUser user, WxOrder order, WxCoupon coupon) {
Date curr = new Date();
Date valid_date = null;
if (coupon.getValidType() == EnumValidStatus.VALID_RANGE.getCode())
@@ -299,9 +299,11 @@ public class WxOrderServiceImpl implements WxOrderService {
couponOrder.setCouponPrice(order.getPayment());

wxCouponOrderMapper.insertSelective(couponOrder);
return couponOrder;
}

@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class})
public WxOrder sendUserFreeCoupon(Long userId, Long couponId) {
// check 用户状态
WxCUser user = null;
@@ -346,6 +348,7 @@ public class WxOrderServiceImpl implements WxOrderService {
record.setId(orderNumber);
record.setTenantId(user.getTenantId());
record.setOrderNumber(orderNumber);
record.setCouponId(couponId);
record.setCUserId(user.getId());
record.setMerchantId(coupon.getMerchantId());
record.setPaymentType(EnumPayType.PAY_PAYMENT.getCode());
@@ -359,25 +362,105 @@ public class WxOrderServiceImpl implements WxOrderService {
try {
wxOrderMapper.insertSelective(record);
} catch (Exception e) {
logger.error("保存订单:" + e.getMessage());
// 库存恢复
stockBack(record);
logger.error("保存订单:" + e.getMessage());
throw new MallinkException(ErrorCode.ORDER_SAVE_ERR);
}

// 创建couponOrder
try {
createCouponOrder(user, record, coupon);
WxCouponOrder couponOrder = createCouponOrder(user, record, coupon);
} catch (Exception e) {
logger.error("保存订单:" + e.getMessage());
// 库存恢复
stockBack(record);
logger.error("保存订单:" + e.getMessage());
throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR);
}

return record;
}

@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class})
public WxCouponOrder sendFreeCouponToUser(Long userId, Long couponId) {
// check 用户状态
WxCUser user = null;
try {
user = wxCUserMapper.selectByPrimaryKey(userId);
} catch (Exception e) {
logger.error("userId : " + userId + ", e: " + e.getMessage());
}
if (user == null) {
logger.error("用户不存在, userId: " + userId);
throw new MallinkException(ErrorCode.USER_IS_EMPTY);
}

// 检查券状态
String couponIdStr = String.valueOf(couponId);
WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(couponId);
if (coupon == null) {
logger.error("券不存在, couponId: " + couponIdStr);
throw new MallinkException(ErrorCode.COUPON_IS_EMPTY);
}
if (coupon.getStatus() == EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode()) {
logger.error("券已下架, couponId: " + couponIdStr);
throw new MallinkException(ErrorCode.COUPON_IS_TAKE_OFF);
}
if (coupon.getSalePrice() != 0) {
logger.error("券不免费, couponId: " + couponIdStr);
throw new MallinkException(ErrorCode.COUPON_IS_NOT_FREE);
}

int payment = coupon.getSalePrice();

Date curr = new Date();

final IdWorker idWorker = IdWorker.get();
Long orderNumber = idWorker.nextId();

// body
// tenant_id + merchant_id + title + subtitle
String bodyStr = coupon.getTitle() + "/" + coupon.getSubTitle();

WxOrder record = new WxOrder();
record.setId(orderNumber);
record.setTenantId(user.getTenantId());
record.setOrderNumber(orderNumber);
record.setCouponId(couponId);
record.setCUserId(user.getId());
record.setMerchantId(coupon.getMerchantId());
record.setPaymentType(EnumPayType.PAY_PAYMENT.getCode());
record.setPayment(payment);
record.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode());
record.setDetail(bodyStr);
record.setCreateDate(curr);
record.setUpdateDate(curr);

// 保存订单
try {
wxOrderMapper.insertSelective(record);
} catch (Exception e) {
logger.error("保存订单:" + e.getMessage());
// 库存恢复
stockBack(record);
throw new MallinkException(ErrorCode.ORDER_SAVE_ERR);
}

// 创建couponOrder
WxCouponOrder couponOrder = null;
try {
couponOrder = createCouponOrder(user, record, coupon);
} catch (Exception e) {
logger.error("保存订单:" + e.getMessage());
// 库存恢复
stockBack(record);
throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR);
}

return couponOrder;
}

@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class})
public int orderSuccess(WxOrder updateOrder) {


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