dev-discount
袁野 4 years ago
commit ff5a448fcf
  1. 4
      hai-bweb/src/main/java/com/bweb/controller/HighDiscountAgentRelController.java
  2. 63
      hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java
  3. 2
      hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java
  4. 2
      hai-schedule/src/main/java/com/hai/schedule/HighDiscountSchedule.java
  5. 2
      hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java
  6. 2
      hai-schedule/src/main/java/com/hai/schedule/SynchronizeCNPC.java
  7. 10
      hai-service/src/main/java/com/hai/entity/HighOrder.java
  8. 13
      hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java
  9. 6
      hai-service/src/main/java/com/hai/service/impl/HighCouponServiceImpl.java
  10. 3
      hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java
  11. 16
      hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java

@ -97,7 +97,7 @@ public class HighDiscountAgentRelController {
// 是否已分配 // 是否已分配
if (highDiscountAgentRelService.getRelByDiscountAgent(highDiscountAgentRel.getDiscountId(), highDiscountAgentRel.getAgentId()) != null) { if (highDiscountAgentRelService.getRelByDiscountAgent(highDiscountAgentRel.getDiscountId(), highDiscountAgentRel.getAgentId()) != null) {
log.error("HighDiscountAgentRelController -> insertDiscountAgent() error!", discount.getDiscountName() + "重复分配给" + agent.getAgentName()); log.error("HighDiscountAgentRelController -> insertDiscountAgent() error!", discount.getDiscountName() + "重复分配给" + agent.getAgentName());
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, discount.getDiscountName() + "重复分配给" + agent.getAgentName()); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, discount.getDiscountName() + "重复分配给" + agent.getAgentName());
} }
highDiscountAgentRel.setCreateTime(new Date()); highDiscountAgentRel.setCreateTime(new Date());
highDiscountAgentRel.setStatus(1); highDiscountAgentRel.setStatus(1);
@ -110,7 +110,7 @@ public class HighDiscountAgentRelController {
//参数 //参数
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("type", QrCodeType.AGENT_QR_CODE); map.put("type", QrCodeType.AGENT_QR_CODE);
map.put("code", AESEncodeUtil.aesEncrypt(Base64Util.encode(highDiscountAgentRel.getId().toString()))); map.put("code", Base64Util.encode(AESEncodeUtil.aesEncrypt(highDiscountAgentRel.getId().toString())));
QRCodeGenerator.generateQRCodeImage(JSON.toJSONString(map), 350, 350, qrCodeUrl); QRCodeGenerator.generateQRCodeImage(JSON.toJSONString(map), 350, 350, qrCodeUrl);
highDiscountAgentRel.setQrCode(qrCodeImg); highDiscountAgentRel.setQrCode(qrCodeImg);
highDiscountAgentRelService.updateDiscountAgentRel(highDiscountAgentRel); highDiscountAgentRelService.updateDiscountAgentRel(highDiscountAgentRel);

@ -79,6 +79,16 @@ public class HighOrderController {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
} }
HighDiscountUserRel highDiscountUserRel = null;
if (highOrder.getMemDiscountId() != null) {
// 卡优惠券信息
highDiscountUserRel = highDiscountUserRelService.getRelById(highOrder.getMemDiscountId());
if (highDiscountUserRel == null || highDiscountUserRel.getStatus() != 1) {
log.error("HighOrderController --> addOrder() error!", "优惠券状态错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券状态错误");
}
}
BigDecimal totalPrice = new BigDecimal("0"); BigDecimal totalPrice = new BigDecimal("0");
for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) { for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) {
if (childOrder.getGoodsType() == null || childOrder.getGoodsId() == null || childOrder.getSaleCount() == null) { if (childOrder.getGoodsType() == null || childOrder.getGoodsId() == null || childOrder.getSaleCount() == null) {
@ -98,25 +108,27 @@ public class HighOrderController {
log.error("HighOrderController --> addOrder() error!", "未找到卡卷信息"); log.error("HighOrderController --> addOrder() error!", "未找到卡卷信息");
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, "");
} }
// 是否达到限购数量
// 校验优惠券是否可用 if (highCouponService.userBuyLimitNumber(userInfoModel.getHighUser().getId(), coupon.getId()) == true) {
if (highOrder.getMemDiscountId() != null) { log.error("HighOrderController --> addOrder() error!", "已达到限购数量");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, coupon.getCouponName() + ",已达到限购数量");
}
// 校验优惠券是否可用 如果使用优惠券就只能使用卡券的原价
if (highDiscountUserRel != null) {
List<HighDiscountCouponRel> discountCouponRelList = highDiscountCouponRelService.getRelByCoupon(coupon.getId()); List<HighDiscountCouponRel> discountCouponRelList = highDiscountCouponRelService.getRelByCoupon(coupon.getId());
if (discountCouponRelList.size() > 0) { if (discountCouponRelList.size() > 0) {
List<HighDiscountCouponRel> collect = discountCouponRelList.stream().filter(o -> o.getDiscountId().equals(highOrder.getMemDiscountId())).collect(Collectors.toList()); HighDiscountUserRel finalHighDiscountUserRel = highDiscountUserRel;
List<HighDiscountCouponRel> collect = discountCouponRelList.stream().filter(o -> o.getDiscountId().equals(finalHighDiscountUserRel.getDiscountId())).collect(Collectors.toList());
if (collect == null || collect.size() == 0) { if (collect == null || collect.size() == 0) {
log.error("HighOrderController --> addOrder() error!", "无法使用优惠券"); log.error("HighOrderController --> addOrder() error!", "无法使用优惠券");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法使用优惠券"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法使用优惠券");
} }
} }
childOrder.setGoodsPrice(coupon.getSalesPrice());
} else {
childOrder.setGoodsPrice(coupon.getDiscountPrice());
} }
// 是否到底限购数量
if (highCouponService.userBuyLimitNumber(userInfoModel.getHighUser().getId(), coupon.getId()) == true) {
log.error("HighOrderController --> addOrder() error!", "已达到限购数量");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, coupon.getCouponName() + ",已达到限购数量");
}
if (highCouponCodeService.getStockCountByCoupon(coupon.getId()) <= 0) { if (highCouponCodeService.getStockCountByCoupon(coupon.getId()) <= 0) {
log.error("HighOrderController --> addOrder() error!", "卡卷库存数量不足"); log.error("HighOrderController --> addOrder() error!", "卡卷库存数量不足");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COUPON_STOCK_INSUFFICIENT, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.COUPON_STOCK_INSUFFICIENT, "");
@ -124,7 +136,6 @@ public class HighOrderController {
childOrder.setGoodsName(coupon.getCouponName()); childOrder.setGoodsName(coupon.getCouponName());
childOrder.setGoodsImg(coupon.getCouponImg()); childOrder.setGoodsImg(coupon.getCouponImg());
childOrder.setGoodsSpecName("默认"); childOrder.setGoodsSpecName("默认");
childOrder.setGoodsPrice(coupon.getDiscountPrice());
} }
if (childOrder.getGoodsType() == 2) { if (childOrder.getGoodsType() == 2) {
@ -152,25 +163,21 @@ public class HighOrderController {
// 累计订单价格 // 累计订单价格
totalPrice = totalPrice.add(childOrder.getTotalPrice()); totalPrice = totalPrice.add(childOrder.getTotalPrice());
} }
highOrder.setTotalPrice(totalPrice);
// 是否使用了优惠券 // 是否使用了优惠券
if (highOrder.getMemDiscountId() != null) { if (highOrder.getMemDiscountId() != null) {
// 卡优惠券信息
HighDiscountUserRel rel = highDiscountUserRelService.getRelById(highOrder.getMemDiscountId()); highOrder.setMemDiscountName(highDiscountUserRel.getHighDiscount().getDiscountName());
if (rel == null || rel.getStatus() != 1) {
log.error("HighOrderController --> addOrder() error!", "优惠券状态错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券状态错误");
}
highOrder.setMemDiscountName(rel.getHighDiscount().getDiscountName());
// 卡卷类型 1:满减 2:抵扣 3:折扣 // 卡卷类型 1:满减 2:抵扣 3:折扣
if (rel.getHighDiscount().getDiscountType() == 1) { if (highDiscountUserRel.getHighDiscount().getDiscountType() == 1) {
// 如果订单总额 小于 满减价格 // 如果订单总额 小于 满减价格
if (highOrder.getTotalPrice().compareTo(rel.getHighDiscount().getDiscountCondition()) > 1) { if (highOrder.getTotalPrice().compareTo(highDiscountUserRel.getHighDiscount().getDiscountCondition()) > 1) {
log.error("HighOrderController --> addOrder() error!", "订单未达到满减额度"); log.error("HighOrderController --> addOrder() error!", "订单未达到满减额度");
throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "订单未达到"+rel.getHighDiscount().getDiscountCondition()+"元,无法使用此优惠券"); throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "订单未达到"+highDiscountUserRel.getHighDiscount().getDiscountCondition()+"元,无法使用此优惠券");
} }
// 订单总额 - 满减额度 // 订单总额 - 满减额度
BigDecimal total = highOrder.getTotalPrice().subtract(rel.getHighDiscount().getDiscountPrice()); BigDecimal total = highOrder.getTotalPrice().subtract(highDiscountUserRel.getHighDiscount().getDiscountPrice());
// 如果总额小于0 // 如果总额小于0
if (total.compareTo(new BigDecimal("0")) == -1) { if (total.compareTo(new BigDecimal("0")) == -1) {
highOrder.setTotalPrice(new BigDecimal("0")); highOrder.setTotalPrice(new BigDecimal("0"));
@ -180,9 +187,9 @@ public class HighOrderController {
} }
// 卡卷类型 1:满减 2:抵扣 3:折扣 // 卡卷类型 1:满减 2:抵扣 3:折扣
if (rel.getHighDiscount().getDiscountType() == 2) { if (highDiscountUserRel.getHighDiscount().getDiscountType() == 2) {
// 订单总额 - 满减额度 // 订单总额 - 满减额度
BigDecimal total = highOrder.getTotalPrice().subtract(rel.getHighDiscount().getDiscountPrice()); BigDecimal total = highOrder.getTotalPrice().subtract(highDiscountUserRel.getHighDiscount().getDiscountPrice());
// 如果总额小于0 // 如果总额小于0
if (total.compareTo(new BigDecimal("0")) == -1) { if (total.compareTo(new BigDecimal("0")) == -1) {
highOrder.setTotalPrice(new BigDecimal("0")); highOrder.setTotalPrice(new BigDecimal("0"));
@ -192,9 +199,9 @@ public class HighOrderController {
} }
// 卡卷类型 1:满减 2:抵扣 3:折扣 // 卡卷类型 1:满减 2:抵扣 3:折扣
if (rel.getHighDiscount().getDiscountType() == 3) { if (highDiscountUserRel.getHighDiscount().getDiscountType() == 3) {
// 折扣除100 // 折扣除100
BigDecimal discountPrice = rel.getHighDiscount().getDiscountPrice().divide(new BigDecimal("100")); BigDecimal discountPrice = highDiscountUserRel.getHighDiscount().getDiscountPrice().divide(new BigDecimal("10"));
// 订单总额 * 折扣 // 订单总额 * 折扣
BigDecimal total = highOrder.getTotalPrice().multiply(discountPrice); BigDecimal total = highOrder.getTotalPrice().multiply(discountPrice);
highOrder.setTotalPrice(total); highOrder.setTotalPrice(total);
@ -205,13 +212,13 @@ public class HighOrderController {
highOrder.setMemId(userInfoModel.getHighUser().getId()); highOrder.setMemId(userInfoModel.getHighUser().getId());
highOrder.setMemName(userInfoModel.getHighUser().getName()); highOrder.setMemName(userInfoModel.getHighUser().getName());
highOrder.setMemPhone(userInfoModel.getHighUser().getPhone()); highOrder.setMemPhone(userInfoModel.getHighUser().getPhone());
highOrder.setPayPrice(totalPrice); highOrder.setPayPrice(highOrder.getTotalPrice());
highOrder.setCreateTime(new Date()); highOrder.setCreateTime(new Date());
highOrder.setOrderStatus(1); highOrder.setOrderStatus(1);
highOrderService.insertOrder(highOrder); highOrderService.insertOrder(highOrder);
return ResponseMsgUtil.success(highOrder); return ResponseMsgUtil.success(getOrderById(highOrder.getId()));
} catch (Exception e) { } catch (Exception e) {
log.error("HighOrderController -> addOrder() error!",e); log.error("HighOrderController -> addOrder() error!",e);

@ -30,7 +30,7 @@ public class HighCouponSchedule {
* @Date 2021/4/4 22:44 * @Date 2021/4/4 22:44
**/ **/
// @Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次 // @Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次
//@Scheduled(cron = "0 0 0 * * ?") //每天 凌晨0点执行 @Scheduled(cron = "0 0 0 * * ?") //每天 凌晨0点执行
public void expiredCoupon() { public void expiredCoupon() {
// 查询过期的卡券 // 查询过期的卡券
List<HighUserCoupon> userCoupons = highUserCouponService.getOverdueCoupon(); List<HighUserCoupon> userCoupons = highUserCouponService.getOverdueCoupon();

@ -29,7 +29,7 @@ public class HighDiscountSchedule {
* @Description 处理过期的优惠券 * @Description 处理过期的优惠券
* @Date 2021/4/4 22:44 * @Date 2021/4/4 22:44
**/ **/
//@Scheduled(cron = "0 0 0 * * ?") //每1分钟执行一次 @Scheduled(cron = "0 0 0 * * ?") //每1分钟执行一次
public void expiredDiscount() { public void expiredDiscount() {
List<HighDiscountUserRel> expiredDiscount = highDiscountUserRelService.getExpiredDiscount(); List<HighDiscountUserRel> expiredDiscount = highDiscountUserRelService.getExpiredDiscount();
for (HighDiscountUserRel rel : expiredDiscount) { for (HighDiscountUserRel rel : expiredDiscount) {

@ -33,7 +33,7 @@ public class HighOrderSchedule {
* @Description 取消订单 15分钟 * @Description 取消订单 15分钟
* @Date 2021/4/4 22:45 * @Date 2021/4/4 22:45
**/ **/
//@Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次 @Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次
public void cancelOrder() { public void cancelOrder() {
List<HighOrder> orderList = highOrderService.getCloseOrder(); List<HighOrder> orderList = highOrderService.getCloseOrder();
if (orderList != null && orderList.size() > 0) { if (orderList != null && orderList.size() > 0) {

@ -29,7 +29,7 @@ public class SynchronizeCNPC {
private static final String[] HEX_DIGITS = {"0" ,"1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"}; private static final String[] HEX_DIGITS = {"0" ,"1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"};
@Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次 //@Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次
public void certification() { public void certification() {
Map<String, Object> tokenMap = new HashMap<>(); Map<String, Object> tokenMap = new HashMap<>();
tokenMap.put("appId", "jsVpwDoHZfR2rrpjhA"); tokenMap.put("appId", "jsVpwDoHZfR2rrpjhA");

@ -125,6 +125,16 @@ public class HighOrder implements Serializable {
private List<HighChildOrder> highChildOrderList; private List<HighChildOrder> highChildOrderList;
private HighDiscount highDiscount;
public HighDiscount getHighDiscount() {
return highDiscount;
}
public void setHighDiscount(HighDiscount highDiscount) {
this.highDiscount = highDiscount;
}
public List<HighChildOrder> getHighChildOrderList() { public List<HighChildOrder> getHighChildOrderList() {
return highChildOrderList; return highChildOrderList;
} }

@ -11,6 +11,7 @@ import com.hai.dao.HighCouponCodeMapperExt;
import com.hai.entity.*; import com.hai.entity.*;
import com.hai.model.UserInfoModel; import com.hai.model.UserInfoModel;
import com.hai.service.HighCouponCodeService; import com.hai.service.HighCouponCodeService;
import com.hai.service.HighCouponService;
import com.hai.service.HighOrderService; import com.hai.service.HighOrderService;
import com.hai.service.HighUserCouponService; import com.hai.service.HighUserCouponService;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
@ -42,6 +43,9 @@ public class HighCouponCodeServiceImpl implements HighCouponCodeService {
@Resource @Resource
private HighOrderService highOrderService; private HighOrderService highOrderService;
@Resource
private HighCouponService highCouponService;
@Resource @Resource
private HighUserCouponService highUserCouponService; private HighUserCouponService highUserCouponService;
@ -87,6 +91,15 @@ public class HighCouponCodeServiceImpl implements HighCouponCodeService {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COUPON_CODE_OVERDUE, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.COUPON_CODE_OVERDUE, "");
} }
// 卡券信息
HighCoupon coupon = highCouponService.getCouponById(salesCode.getCouponId());
if (coupon == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_DISCOUNT, "");
}
// 卡券来源:1.中石化
if (coupon.getCouponSource() == 1) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "此卡券无法消核");
}
salesCode.setStoreId(userInfoModel.getMerchantStore().getId()); salesCode.setStoreId(userInfoModel.getMerchantStore().getId());
salesCode.setConsumeTime(new Date()); salesCode.setConsumeTime(new Date());
salesCode.setStatus(3); salesCode.setStatus(3);

@ -353,6 +353,12 @@ public class HighCouponServiceImpl implements HighCouponService {
criteria.andStatusEqualTo(MapUtils.getInteger(map, "status")); criteria.andStatusEqualTo(MapUtils.getInteger(map, "status"));
} }
if (MapUtils.getInteger(map, "couponSource") != null) {
criteria.andCouponSourceEqualTo(MapUtils.getInteger(map, "status"));
} else {
criteria.andCouponSourceNotEqualTo(2);
}
example.setOrderByClause("create_time desc"); example.setOrderByClause("create_time desc");
List<HighCoupon> coupons = highCouponMapper.selectByExample(example); List<HighCoupon> coupons = highCouponMapper.selectByExample(example);
if (coupons != null && coupons.size() > 0) { if (coupons != null && coupons.size() > 0) {

@ -52,6 +52,9 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic
if (rel == null || rel.getHighDiscount() == null || rel.getAgentId() == null){ if (rel == null || rel.getHighDiscount() == null || rel.getAgentId() == null){
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_DISCOUNT, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_DISCOUNT, "");
} }
rel.setStockCount(rel.getStockCount() - 1);
highDiscountAgentRelService.updateDiscountAgentRel(rel);
// 校验卡卷状态 // 校验卡卷状态
if (rel.getHighDiscount().getStatus() != 2) { if (rel.getHighDiscount().getStatus() != 2) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "卡券已下架"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "卡券已下架");

@ -264,6 +264,9 @@ public class HighOrderServiceImpl implements HighOrderService {
return null; return null;
} }
order.setHighChildOrderList(getChildOrderByOrder(order.getId())); order.setHighChildOrderList(getChildOrderByOrder(order.getId()));
if (order.getMemDiscountId() != null) {
order.setHighDiscount(highDiscountUserRelService.getRelById(order.getMemDiscountId()).getHighDiscount());
}
return order; return order;
} }
@ -367,7 +370,7 @@ public class HighOrderServiceImpl implements HighOrderService {
HighDiscountUserRel rel = highDiscountUserRelService.getRelById(order.getMemDiscountId()); HighDiscountUserRel rel = highDiscountUserRelService.getRelById(order.getMemDiscountId());
if (rel != null) { if (rel != null) {
rel.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 rel.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用
rel.setUseTime(new Date()); rel.setUseTime(null);
highDiscountUserRelService.updateDiscountUserRel(rel); highDiscountUserRelService.updateDiscountUserRel(rel);
} }
} }
@ -383,8 +386,6 @@ public class HighOrderServiceImpl implements HighOrderService {
criteria.andMemIdEqualTo(memId); criteria.andMemIdEqualTo(memId);
criteria.andOrderStatusEqualTo(status); criteria.andOrderStatusEqualTo(status);
return highOrderMapper.selectByExample(example).size(); return highOrderMapper.selectByExample(example).size();
} }
@ -394,6 +395,15 @@ public class HighOrderServiceImpl implements HighOrderService {
HighDiscountUserRelExample example = new HighDiscountUserRelExample(); HighDiscountUserRelExample example = new HighDiscountUserRelExample();
HighDiscountUserRelExample.Criteria criteria = example.createCriteria(); HighDiscountUserRelExample.Criteria criteria = example.createCriteria();
if (userId != null) {
criteria.andUserIdEqualTo(userId);
}
if (status != null) {
criteria.andStatusEqualTo(status);
}
example.setOrderByClause("create_time desc");
return highDiscountUserRelMapper.selectByExample(example).size(); return highDiscountUserRelMapper.selectByExample(example).size();
} }
} }

Loading…
Cancel
Save