|
@@ -1,11 +1,21 @@
|
|
package com.zhentao.service.impl;
|
|
package com.zhentao.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.zhentao.controller.order.dto.OrderDto;
|
|
|
|
+import com.zhentao.domain.Coupon;
|
|
|
|
+import com.zhentao.domain.OrderShopping;
|
|
import com.zhentao.domain.UserOrder;
|
|
import com.zhentao.domain.UserOrder;
|
|
-import com.zhentao.service.UserOrderService;
|
|
|
|
|
|
+import com.zhentao.dto.Result;
|
|
import com.zhentao.mapper.UserOrderMapper;
|
|
import com.zhentao.mapper.UserOrderMapper;
|
|
|
|
+import com.zhentao.service.CouponService;
|
|
|
|
+import com.zhentao.service.UserOrderService;
|
|
|
|
+import org.checkerframework.checker.units.qual.A;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @author 86183
|
|
* @author 86183
|
|
* @description 针对表【user_order(订单表)】的数据库操作Service实现
|
|
* @description 针对表【user_order(订单表)】的数据库操作Service实现
|
|
@@ -14,7 +24,35 @@ import org.springframework.stereotype.Service;
|
|
@Service
|
|
@Service
|
|
public class UserOrderServiceImpl extends ServiceImpl<UserOrderMapper, UserOrder>
|
|
public class UserOrderServiceImpl extends ServiceImpl<UserOrderMapper, UserOrder>
|
|
implements UserOrderService{
|
|
implements UserOrderService{
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserOrderService service;
|
|
|
|
+ @Autowired
|
|
|
|
+ private CouponService couponService;
|
|
|
|
+ @Override
|
|
|
|
+ public Result add(OrderDto orderDto) {
|
|
|
|
+// 创建一个对象
|
|
|
|
+ UserOrder userOrder = new UserOrder();
|
|
|
|
+ long l = IdUtil.getSnowflake(1, 1).nextId();
|
|
|
|
+ userOrder.setId(l);
|
|
|
|
+// 设置用户ID
|
|
|
|
+ userOrder.setUserId(orderDto.getUserId());
|
|
|
|
+// 设置总价格
|
|
|
|
+ BigDecimal bigDecimal = new BigDecimal("0");
|
|
|
|
+ for (OrderShopping s:orderDto.getList()) {
|
|
|
|
+ bigDecimal = bigDecimal.add(s.getPrice());
|
|
|
|
+ }
|
|
|
|
+ userOrder.setTotalAmount(bigDecimal);
|
|
|
|
+// 设置优惠金额
|
|
|
|
+ Coupon byId = couponService.getById(orderDto.getCouponId());
|
|
|
|
+ if (byId.getCouponType()==1){
|
|
|
|
+
|
|
|
|
+ }else if (byId.getCouponType()==2){
|
|
|
|
+
|
|
|
|
+ }else if (byId.getCouponType()==3){
|
|
|
|
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|