'销售码使用'

dev-discount
199901012 4 years ago
parent fcfa0ab93f
commit e46499752b
  1. 40
      hai-bweb/src/main/java/com/bweb/controller/HighCouponCodeController.java
  2. 3
      hai-service/src/main/java/com/hai/common/exception/ErrorCode.java
  3. 15
      hai-service/src/main/java/com/hai/service/HighCouponCodeService.java
  4. 14
      hai-service/src/main/java/com/hai/service/HighOrderService.java
  5. 51
      hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java
  6. 32
      hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java
  7. 4
      hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java

@ -1,11 +1,13 @@
package com.bweb.controller; package com.bweb.controller;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode; import com.hai.common.exception.SysCode;
import com.hai.common.security.SessionObject; import com.hai.common.security.SessionObject;
import com.hai.common.security.UserCenter;
import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.HighCouponCode; import com.hai.entity.HighCouponCode;
import com.hai.model.ResponseData; import com.hai.model.ResponseData;
@ -13,16 +15,15 @@ import com.hai.model.UserInfoModel;
import com.hai.service.HighCouponCodeService; import com.hai.service.HighCouponCodeService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -41,6 +42,9 @@ public class HighCouponCodeController {
@Resource @Resource
private HighCouponCodeService highCouponCodeService; private HighCouponCodeService highCouponCodeService;
@Resource
private UserCenter userCenter;
@RequestMapping(value="/getCouponCodeList",method = RequestMethod.GET) @RequestMapping(value="/getCouponCodeList",method = RequestMethod.GET)
@ResponseBody @ResponseBody
@ApiOperation(value = "销售码列表") @ApiOperation(value = "销售码列表")
@ -62,4 +66,32 @@ public class HighCouponCodeController {
return ResponseMsgUtil.exception(e); return ResponseMsgUtil.exception(e);
} }
} }
@RequestMapping(value="/useCouponCode",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "使用卡卷码")
public ResponseData useCouponCode(@RequestBody String reqBody, HttpServletRequest request) {
try {
SessionObject sessionObject = userCenter.getSessionObject(request);
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject();
if (userInfoModel.getMerchantStore() == null) {
log.error("HighMerchantController -> useCouponCode() error!","该主角色没有权限");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, "");
}
JSONObject jsonObject = JSONObject.parseObject(reqBody);
String code = jsonObject.getString("code");
if (StringUtils.isBlank(code)) {
log.error("HighMerchantStoreController -> useCouponCode() error!","参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
highCouponCodeService.useCouponCode(code, userInfoModel);
return ResponseMsgUtil.success("操作成功");
} catch (Exception e) {
log.error("HighCouponController -> useCouponCode() error!",e);
return ResponseMsgUtil.exception(e);
}
}
} }

@ -100,6 +100,9 @@ public enum ErrorCode {
COUPON_STOCK_INSUFFICIENT("2118","卡卷库存数量不足"), COUPON_STOCK_INSUFFICIENT("2118","卡卷库存数量不足"),
NOT_FOUND_ORDER("2119","未找到订单信息"), NOT_FOUND_ORDER("2119","未找到订单信息"),
ORDER_NO_STAY_PAY("2120","订单不处于待支付状态"), ORDER_NO_STAY_PAY("2120","订单不处于待支付状态"),
NOT_FOUND_COUPON_CODE("2121","销售码不存在"),
COUPON_CODE_STATUS("2122","卡券码状态错误"),
COUPON_CODE_OVERDUE("2122","卡券码已过期"),
STATUS_ERROR("3000","状态错误"), STATUS_ERROR("3000","状态错误"),
ADD_DATA_ERROR("3001","增加数据失败"), ADD_DATA_ERROR("3001","增加数据失败"),

@ -2,6 +2,7 @@ package com.hai.service;
import com.hai.entity.HighCouponCode; import com.hai.entity.HighCouponCode;
import com.hai.model.HighCouponCodeModel; import com.hai.model.HighCouponCodeModel;
import com.hai.model.UserInfoModel;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -35,6 +36,13 @@ public interface HighCouponCodeService {
**/ **/
void updateCouponCode(HighCouponCode highCouponCode); void updateCouponCode(HighCouponCode highCouponCode);
/**
* @Author 胡锐
* @Description 使用卡卷
* @Date 2021/3/27 13:21
**/
void useCouponCode(String code, UserInfoModel userInfoModel);
/** /**
* @Author 胡锐 * @Author 胡锐
* @Description 根据订单id查询 * @Description 根据订单id查询
@ -42,6 +50,13 @@ public interface HighCouponCodeService {
**/ **/
HighCouponCode getCouponCodeByOrderId(Long childOrderId); HighCouponCode getCouponCodeByOrderId(Long childOrderId);
/**
* @Author 胡锐
* @Description 根据销售码查询
* @Date 2021/3/27 12:39
**/
HighCouponCode getCouponCodeBySalesCode(String code);
/** /**
* *
* @Title: getStockCountByCoupon * @Title: getStockCountByCoupon

@ -33,6 +33,13 @@ public interface HighOrderService {
**/ **/
void updateOrder(HighOrder highOrder); void updateOrder(HighOrder highOrder);
/**
* @Author 胡锐
* @Description 获取未完成的子订单数量
* @Date 2021/3/27 13:35
**/
Integer getUndoneChildOrder(Long orderId);
/** /**
* @Author 胡锐 * @Author 胡锐
* @Description 根据id查询 * @Description 根据id查询
@ -54,4 +61,11 @@ public interface HighOrderService {
**/ **/
List<HighOrder> getOrderList(Map<String,Object> map); List<HighOrder> getOrderList(Map<String,Object> map);
/**
* @Author 胡锐
* @Description 子订单完成
* @Date 2021/3/27 13:28
**/
void childOrderComplete(Long childOrderId);
} }

@ -1,13 +1,22 @@
package com.hai.service.impl; package com.hai.service.impl;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.dao.HighCouponCodeMapper; import com.hai.dao.HighCouponCodeMapper;
import com.hai.dao.HighCouponCodeMapperExt; import com.hai.dao.HighCouponCodeMapperExt;
import com.hai.entity.HighChildOrder;
import com.hai.entity.HighCouponCode; import com.hai.entity.HighCouponCode;
import com.hai.entity.HighCouponCodeExample; import com.hai.entity.HighCouponCodeExample;
import com.hai.entity.HighOrder;
import com.hai.model.UserInfoModel;
import com.hai.service.HighCouponCodeService; import com.hai.service.HighCouponCodeService;
import com.hai.service.HighOrderService;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
@ -29,6 +38,9 @@ public class HighCouponCodeServiceImpl implements HighCouponCodeService {
@Resource @Resource
private HighCouponCodeMapperExt highCouponCodeMapperExt; private HighCouponCodeMapperExt highCouponCodeMapperExt;
@Resource
private HighOrderService highOrderService;
@Override @Override
public void insertCouponCode(HighCouponCode highCouponCode) { public void insertCouponCode(HighCouponCode highCouponCode) {
highCouponCodeMapper.insert(highCouponCode); highCouponCodeMapper.insert(highCouponCode);
@ -44,6 +56,34 @@ public class HighCouponCodeServiceImpl implements HighCouponCodeService {
highCouponCodeMapper.updateByPrimaryKey(highCouponCode); highCouponCodeMapper.updateByPrimaryKey(highCouponCode);
} }
@Override
@Transactional(propagation= Propagation.REQUIRES_NEW)
public void useCouponCode(String code, UserInfoModel userInfoModel) {
// 查询销售码
HighCouponCode salesCode = getCouponCodeBySalesCode(code);
if (salesCode == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON_CODE, "");
}
// 状态:1.待销售 2.未使用 3.已使用 99.预支付
if (salesCode.getStatus() != 2) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COUPON_CODE_STATUS, "");
}
// 使用时间已到期
if (salesCode.getUseEndTime().compareTo(new Date()) == -1) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COUPON_CODE_OVERDUE, "");
}
salesCode.setStoreId(userInfoModel.getMerchantStore().getId());
salesCode.setConsumeTime(new Date());
salesCode.setStatus(3);
updateCouponCode(salesCode);
highOrderService.childOrderComplete(salesCode.getChildOrderId());
}
@Override @Override
public HighCouponCode getCouponCodeByOrderId(Long childOrderId) { public HighCouponCode getCouponCodeByOrderId(Long childOrderId) {
HighCouponCodeExample example = new HighCouponCodeExample(); HighCouponCodeExample example = new HighCouponCodeExample();
@ -56,6 +96,17 @@ public class HighCouponCodeServiceImpl implements HighCouponCodeService {
return null; return null;
} }
@Override
public HighCouponCode getCouponCodeBySalesCode(String code) {
HighCouponCodeExample example = new HighCouponCodeExample();
example.createCriteria().andSalesCodeEqualTo(code);
List<HighCouponCode> codes = highCouponCodeMapper.selectByExample(example);
if (codes != null && codes.size() > 0) {
return codes.get(0);
}
return null;
}
@Override @Override
public Integer getStockCountByCoupon(Long couponId) { public Integer getStockCountByCoupon(Long couponId) {
HighCouponCodeExample example = new HighCouponCodeExample(); HighCouponCodeExample example = new HighCouponCodeExample();

@ -167,6 +167,18 @@ public class HighOrderServiceImpl implements HighOrderService {
} }
} }
@Override
public Integer getUndoneChildOrder(Long orderId) {
HighOrder order = getOrderById(orderId);
Integer count = 0;
for (HighChildOrder childOrder : order.getHighChildOrderList()) {
if (childOrder.getChildOrdeStatus() != 3) {
count++;
}
}
return count;
}
@Override @Override
public HighOrder getOrderById(Long id) { public HighOrder getOrderById(Long id) {
HighOrder order = highOrderMapper.selectByPrimaryKey(id); HighOrder order = highOrderMapper.selectByPrimaryKey(id);
@ -213,4 +225,24 @@ public class HighOrderServiceImpl implements HighOrderService {
example.setOrderByClause("create_time desc"); example.setOrderByClause("create_time desc");
return highOrderMapper.selectByExample(example); return highOrderMapper.selectByExample(example);
} }
@Override
@Transactional(propagation= Propagation.REQUIRES_NEW)
public void childOrderComplete(Long childOrderId) {
HighChildOrder childOrder = highChildOrderMapper.selectByPrimaryKey(childOrderId);
if (childOrder == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
childOrder.setChildOrdeStatus(3);
highChildOrderMapper.updateByPrimaryKey(childOrder);
// 查询未完成的子订单数量
Integer count = getUndoneChildOrder(childOrder.getOrderId());
if (count == 0) {
HighOrder order = getOrderById(childOrder.getOrderId());
order.setOrderStatus(3);
order.setFinishTime(new Date());
highOrderMapper.updateByPrimaryKey(order);
}
}
} }

@ -62,10 +62,9 @@ public class GoodsOrderServiceImpl implements PayService {
order.setOrderStatus(2); // 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 order.setOrderStatus(2); // 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消
for (HighChildOrder highChildOrder : order.getHighChildOrderList()) { for (HighChildOrder highChildOrder : order.getHighChildOrderList()) {
highChildOrder.setChildOrdeStatus(2); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消
// 商品类型 商品类型 1:卡卷 2:金币充值 // 商品类型 商品类型 1:卡卷 2:金币充值
if (highChildOrder.getGoodsType() == 1) { if (highChildOrder.getGoodsType() == 1) {
highChildOrder.setChildOrdeStatus(2); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消
HighCouponCode code = highCouponCodeService.getCouponCodeByOrderId(highChildOrder.getId()); HighCouponCode code = highCouponCodeService.getCouponCodeByOrderId(highChildOrder.getId());
code.setStatus(2); // 状态:1.待销售 2.未使用 3.已使用 99.预支付 code.setStatus(2); // 状态:1.待销售 2.未使用 3.已使用 99.预支付
highCouponCodeService.updateCouponCode(code); highCouponCodeService.updateCouponCode(code);
@ -82,6 +81,7 @@ public class GoodsOrderServiceImpl implements PayService {
} }
if (highChildOrder.getGoodsType() == 2) { if (highChildOrder.getGoodsType() == 2) {
highChildOrder.setChildOrdeStatus(3); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消
// 金币 1:100 // 金币 1:100
Integer goldNum = new BigDecimal(highChildOrder.getTotalPrice().toString()).multiply(new BigDecimal("100")).intValue(); Integer goldNum = new BigDecimal(highChildOrder.getTotalPrice().toString()).multiply(new BigDecimal("100")).intValue();
highUserService.goldHandle(highChildOrder.getGoodsId(), goldNum, 1, 1, highChildOrder.getId()); highUserService.goldHandle(highChildOrder.getGoodsId(), goldNum, 1, 1, highChildOrder.getId());

Loading…
Cancel
Save