|
|
@@ -1,10 +1,14 @@
|
|
|
package com.zhongzheng.modules.order.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.lang.Validator;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
|
import com.zhongzheng.common.utils.DateUtils;
|
|
|
+import com.zhongzheng.modules.activity.domain.ActivityConfiguration;
|
|
|
+import com.zhongzheng.modules.activity.service.IActivityConfigurationService;
|
|
|
+import com.zhongzheng.modules.activity.vo.ActivityConfigurationVo;
|
|
|
import com.zhongzheng.modules.bank.service.IQuestionBankService;
|
|
|
import com.zhongzheng.modules.bank.vo.QuestionBankVo;
|
|
|
import com.zhongzheng.modules.bank.vo.QuestionVo;
|
|
|
@@ -16,11 +20,9 @@ import com.zhongzheng.modules.exam.vo.ExamNoteVo;
|
|
|
import com.zhongzheng.modules.order.bo.*;
|
|
|
import com.zhongzheng.modules.order.domain.Coupon;
|
|
|
import com.zhongzheng.modules.order.domain.Order;
|
|
|
+import com.zhongzheng.modules.order.domain.OrderActivity;
|
|
|
import com.zhongzheng.modules.order.mapper.OrderMapper;
|
|
|
-import com.zhongzheng.modules.order.service.ICouponService;
|
|
|
-import com.zhongzheng.modules.order.service.IOrderCouponService;
|
|
|
-import com.zhongzheng.modules.order.service.IOrderGoodsService;
|
|
|
-import com.zhongzheng.modules.order.service.IOrderService;
|
|
|
+import com.zhongzheng.modules.order.service.*;
|
|
|
import com.zhongzheng.modules.order.vo.CouponVo;
|
|
|
import com.zhongzheng.modules.order.vo.OrderVo;
|
|
|
import com.zhongzheng.modules.user.domain.OrderPossessUser;
|
|
|
@@ -36,6 +38,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.github.pagehelper.Page;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Collection;
|
|
|
@@ -80,6 +83,12 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
@Autowired
|
|
|
private IOrderCouponService iOrderCouponService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IActivityConfigurationService activityConfigurationService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOrderActivityService oOrderActivityService;
|
|
|
+
|
|
|
@Override
|
|
|
public OrderVo queryById(Long orderId){
|
|
|
Order db = this.baseMapper.selectById(orderId);
|
|
|
@@ -140,6 +149,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Map<String, String> placeOrder(OrderAddBo bo) {
|
|
|
List<OrderGoodsAddBo> goodsList = bo.getGoodsList();
|
|
|
if(goodsList.size()<1){
|
|
|
@@ -149,7 +159,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
validEntityBeforeSave(add);
|
|
|
add.setCreateTime(DateUtils.getNowTime());
|
|
|
add.setUpdateTime(DateUtils.getNowTime());
|
|
|
- Map<String, String> result = dealOrder(add,goodsList,bo.getCouponId());
|
|
|
+ Map<String, String> result = dealOrder(add,goodsList,bo.getCouponId(),bo.getActivityId());
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
@@ -178,7 +188,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
return this.removeByIds(ids);
|
|
|
}
|
|
|
|
|
|
- private Map<String, String> dealOrder(Order add,List<OrderGoodsAddBo> goodsList,Long couponId){
|
|
|
+ private Map<String, String> dealOrder(Order add,List<OrderGoodsAddBo> goodsList,Long couponId,Long activity){
|
|
|
UserVo userVo = iUserService.queryById(add.getUserId());
|
|
|
String body = "中正云课堂消费";
|
|
|
String price = "1";
|
|
|
@@ -223,33 +233,63 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
if(!iOrderGoodsService.insertByAddBo(g)){
|
|
|
throw new CustomException("商品错误");
|
|
|
}
|
|
|
- totalPrice = totalPrice.add(g.getGoodsPrice());
|
|
|
|
|
|
- }
|
|
|
- if(couponId>0){
|
|
|
- //使用优惠券
|
|
|
- Coupon coupon= iCouponService.queryByIdAndUserId(couponId,add.getUserId());
|
|
|
- if(!Validator.isNotNull(coupon)){
|
|
|
- throw new CustomException("该优惠券不存在");
|
|
|
- }
|
|
|
- if(coupon.getUserStatus()!=0||coupon.getEndTime()<DateUtils.getNowTime()){
|
|
|
- throw new CustomException("该优惠券无法使用");
|
|
|
- }
|
|
|
- if(coupon.getCouponType()==0){
|
|
|
- //优惠券
|
|
|
- totalPrice = totalPrice.subtract(coupon.getPrice());
|
|
|
+ //查詢該券是否使用於此課程上
|
|
|
+ if(couponId>0 && g.getGoodsType()==1 && iCouponService.selectCount(g.getGoodsId(),couponId) > 0 ){
|
|
|
+ //使用优惠券
|
|
|
+ Coupon coupon= iCouponService.queryByIdAndUserId(couponId,add.getUserId());
|
|
|
+ if(!Validator.isNotNull(coupon)){
|
|
|
+ throw new CustomException("该优惠券不存在");
|
|
|
+ }
|
|
|
+ if(coupon.getUserStatus()!=0||coupon.getEndTime()<DateUtils.getNowTime()){
|
|
|
+ throw new CustomException("该优惠券无法使用");
|
|
|
+ }
|
|
|
+ if(coupon.getCouponType()==0){
|
|
|
+ //优惠券
|
|
|
+ g.setGoodsPrice(g.getGoodsPrice().subtract(coupon.getPrice()));
|
|
|
|
|
|
+ }
|
|
|
+ if(coupon.getCouponType()==1){
|
|
|
+ //折扣券
|
|
|
+ g.setGoodsPrice(g.getGoodsPrice().divide((new BigDecimal(10))).multiply(coupon.getPrice()));
|
|
|
+ }
|
|
|
+ OrderCouponAddBo orderCouponAddBo = new OrderCouponAddBo();
|
|
|
+ orderCouponAddBo.setCouponId(couponId);
|
|
|
+ orderCouponAddBo.setOrderSn(out_trade_no);
|
|
|
+ if(!iOrderCouponService.insertByAddBo(orderCouponAddBo)){
|
|
|
+ throw new CustomException("优惠券数据错误");
|
|
|
+ }
|
|
|
}
|
|
|
- if(coupon.getCouponType()==1){
|
|
|
- //折扣券
|
|
|
- totalPrice = totalPrice.divide((new BigDecimal(10))).multiply(coupon.getPrice());
|
|
|
- }
|
|
|
- OrderCouponAddBo orderCouponAddBo = new OrderCouponAddBo();
|
|
|
- orderCouponAddBo.setCouponId(couponId);
|
|
|
- orderCouponAddBo.setOrderSn(out_trade_no);
|
|
|
- if(!iOrderCouponService.insertByAddBo(orderCouponAddBo)){
|
|
|
- throw new CustomException("优惠券数据错误");
|
|
|
+
|
|
|
+ //查詢該活動是否使用於此課程上
|
|
|
+ if(activity >0 && g.getGoodsType()==1 && activityConfigurationService.selectCount(g.getGoodsId(),activity) > 0 ){
|
|
|
+ //使用活動
|
|
|
+ ActivityConfigurationVo activityConfigurationVo = activityConfigurationService.queryById(activity);
|
|
|
+ if(!Validator.isNotNull(activityConfigurationVo)){
|
|
|
+ throw new CustomException("该活動不存在");
|
|
|
+ }
|
|
|
+ if(Convert.toLong(activityConfigurationVo.getActivityType()) ==3){
|
|
|
+ //定價
|
|
|
+ g.setGoodsPrice(activityConfigurationVo.getPrice());
|
|
|
+ }
|
|
|
+ if(Convert.toLong(activityConfigurationVo.getActivityType()) ==4){
|
|
|
+ //優惠
|
|
|
+ g.setGoodsPrice(g.getGoodsPrice().subtract((activityConfigurationVo.getPrice())));
|
|
|
+ }
|
|
|
+ if(Convert.toLong(activityConfigurationVo.getActivityType()) ==5){
|
|
|
+ //折扣
|
|
|
+ g.setGoodsPrice(g.getGoodsPrice().divide((new BigDecimal(10))).multiply(activityConfigurationVo.getPrice()));
|
|
|
+ }
|
|
|
+ OrderActivityAddBo orderActivityAddBo = new OrderActivityAddBo();
|
|
|
+ orderActivityAddBo.setActivityId(couponId);
|
|
|
+ orderActivityAddBo.setOrderSn(out_trade_no);
|
|
|
+ if(!oOrderActivityService.insertByAddBo(orderActivityAddBo)){
|
|
|
+ throw new CustomException("活動錯誤");
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ totalPrice = totalPrice.add(g.getGoodsPrice());
|
|
|
+
|
|
|
}
|
|
|
BigDecimal zero = new BigDecimal(0.01);
|
|
|
if(totalPrice.compareTo(zero) == -1){
|