This commit is contained in:
parent
52564191ca
commit
deac8fc77b
|
|
@ -4,10 +4,7 @@ import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import com.bonus.canteen.core.order.domain.OrderInfo;
|
import com.bonus.canteen.core.order.domain.OrderInfo;
|
||||||
import com.bonus.canteen.core.order.domain.param.OrderAddParam;
|
import com.bonus.canteen.core.order.domain.param.*;
|
||||||
import com.bonus.canteen.core.order.domain.param.OrderInfoAddParam;
|
|
||||||
import com.bonus.canteen.core.order.domain.param.OrderQueryParam;
|
|
||||||
import com.bonus.canteen.core.order.domain.param.ShopOrderAddParam;
|
|
||||||
import com.bonus.canteen.core.order.service.IOrderInfoService;
|
import com.bonus.canteen.core.order.service.IOrderInfoService;
|
||||||
import com.bonus.common.core.exception.ServiceException;
|
import com.bonus.common.core.exception.ServiceException;
|
||||||
import com.bonus.common.core.utils.poi.ExcelUtil;
|
import com.bonus.common.core.utils.poi.ExcelUtil;
|
||||||
|
|
@ -112,10 +109,18 @@ public class OrderInfoController extends BaseController
|
||||||
return toAjax(orderInfoService.insertCanteenOrderInfo(orderAddParam));
|
return toAjax(orderInfoService.insertCanteenOrderInfo(orderAddParam));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SysLog(title = "下单", module = "订单", businessType = OperaType.INSERT)
|
||||||
|
@PostMapping("/device/add")
|
||||||
|
@ResponseBody
|
||||||
|
public AjaxResult deviceAddSave(DeviceOrderAddParam orderAddParam)
|
||||||
|
{
|
||||||
|
return toAjax(orderInfoService.insertDeviceOrderInfo(orderAddParam));
|
||||||
|
}
|
||||||
|
|
||||||
@SysLog(title = "下单", module = "订单", businessType = OperaType.INSERT)
|
@SysLog(title = "下单", module = "订单", businessType = OperaType.INSERT)
|
||||||
@PostMapping("/shop/add")
|
@PostMapping("/shop/add")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public AjaxResult deviceAddSave(ShopOrderAddParam orderAddParam)
|
public AjaxResult shopAddSave(ShopOrderAddParam orderAddParam)
|
||||||
{
|
{
|
||||||
return toAjax(orderInfoService.insertShopOrderInfo(orderAddParam));
|
return toAjax(orderInfoService.insertShopOrderInfo(orderAddParam));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,7 @@ import java.util.Objects;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.NumberUtil;
|
import cn.hutool.core.util.NumberUtil;
|
||||||
import com.bonus.canteen.core.order.constants.*;
|
import com.bonus.canteen.core.order.constants.*;
|
||||||
import com.bonus.canteen.core.order.domain.param.OrderAddParam;
|
import com.bonus.canteen.core.order.domain.param.*;
|
||||||
import com.bonus.canteen.core.order.domain.param.OrderDetailInfoAddParam;
|
|
||||||
import com.bonus.canteen.core.order.domain.param.OrderInfoAddParam;
|
|
||||||
import com.bonus.canteen.core.pay.constants.PayChannelEnum;
|
import com.bonus.canteen.core.pay.constants.PayChannelEnum;
|
||||||
import com.bonus.canteen.core.pay.constants.PayStateEnum;
|
import com.bonus.canteen.core.pay.constants.PayStateEnum;
|
||||||
import com.bonus.common.core.annotation.Excel;
|
import com.bonus.common.core.annotation.Excel;
|
||||||
|
|
@ -265,4 +263,98 @@ public class OrderInfo extends BaseEntity
|
||||||
orderDetail.setUpdateTime(DateUtils.getNowDate());
|
orderDetail.setUpdateTime(DateUtils.getNowDate());
|
||||||
return orderDetail;
|
return orderDetail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<OrderInfo> of(DeviceOrderAddParam param) {
|
||||||
|
List<OrderInfo> orderInfoList = new ArrayList<>();
|
||||||
|
List<DeviceOrderInfoAddParam> orderList = param.getOrderList();
|
||||||
|
if(CollUtil.isNotEmpty(orderList)) {
|
||||||
|
for(DeviceOrderInfoAddParam orderInfoAddParam : orderList) {
|
||||||
|
OrderInfo orderInfo = new OrderInfo();
|
||||||
|
orderInfo.setOrderId(Id.next());
|
||||||
|
orderInfo.setDeviceOrderId(StringUtils.defaultString(orderInfoAddParam.getDeviceOrderId(), StringUtils.EMPTY));
|
||||||
|
orderInfo.setDeviceSn(StringUtils.defaultString(orderInfoAddParam.getDeviceSn(), StringUtils.EMPTY));
|
||||||
|
orderInfo.setDeviceNum(StringUtils.defaultString(orderInfoAddParam.getDeviceNum(), StringUtils.EMPTY));
|
||||||
|
orderInfo.setUserId(param.getUserId());
|
||||||
|
orderInfo.setPayableAmount(param.getPayableAmount());
|
||||||
|
orderInfo.setRealAmount(param.getRealAmount());
|
||||||
|
orderInfo.setSourceType(param.getSourceType());
|
||||||
|
orderInfo.setCreateBy(SecurityUtils.getUsername());
|
||||||
|
orderInfo.setCreateTime(DateUtils.getNowDate());
|
||||||
|
orderInfo.setUpdateBy(SecurityUtils.getUsername());
|
||||||
|
orderInfo.setUpdateTime(DateUtils.getNowDate());
|
||||||
|
orderInfo.setPayType(param.getPayType());
|
||||||
|
Long canteenId = orderInfoAddParam.getCanteenId();
|
||||||
|
orderInfo.setCanteenId(Objects.isNull(canteenId) ? -1 : canteenId);
|
||||||
|
Long stallId = orderInfoAddParam.getStallId();
|
||||||
|
orderInfo.setStallId(Objects.isNull(stallId) ? -1 : stallId);
|
||||||
|
orderInfo.setOrderDate(orderInfoAddParam.getOrderDate());
|
||||||
|
orderInfo.setOrderType(orderInfoAddParam.getOrderType());
|
||||||
|
Integer mealtimeType = orderInfoAddParam.getMealtimeType();
|
||||||
|
orderInfo.setMealtimeType(Objects.isNull(mealtimeType) ? -1 : mealtimeType);
|
||||||
|
orderInfo.setMealtimeName(orderInfoAddParam.getMealtimeName());
|
||||||
|
orderInfo.setIsOnline(Objects.isNull(param.getIsOnline()) ? 1 : param.getIsOnline());
|
||||||
|
orderInfo.setOrderState(OrderStateEnum.PLACE.getKey());
|
||||||
|
orderInfo.setOrderRefundState(OrderRefundStateEnum.UN_REFUND.getKey());
|
||||||
|
orderInfo.setDeductionType(DeductionTypeEnum.PAY_PLACE.getKey());
|
||||||
|
orderInfo.setPayType(param.getPayType());
|
||||||
|
orderInfo.setPayChannel(PayChannelEnum.ACC.getKey());
|
||||||
|
orderInfo.setPayState(PayStateEnum.PAY_INPROCESS.getKey());
|
||||||
|
orderInfo.setDeliveryAmount(BigDecimal.ZERO);
|
||||||
|
orderInfo.setPackingAmount(BigDecimal.ZERO);
|
||||||
|
orderInfo.setDeliveryType(DeliveryTypeEnum.SELF_TAKE.getKey());
|
||||||
|
orderInfo.setCommentState(CommentStateEnum.UN_COMMENT.getKey());
|
||||||
|
orderInfo.setOrderTime(DateUtils.getNowDate());
|
||||||
|
orderInfo.setPayableAmount(BigDecimal.ZERO);
|
||||||
|
orderInfo.setDiscountsAmount(BigDecimal.ZERO);
|
||||||
|
orderInfo.setRealAmount(BigDecimal.ZERO);
|
||||||
|
orderInfo.setExternalPayAmount(BigDecimal.ZERO);
|
||||||
|
orderInfo.setRefundAmount(BigDecimal.ZERO);
|
||||||
|
List<DeviceOrderDetailInfoAddParam> orderDetailInfoAddParams =orderInfoAddParam.getOrderDetailList();
|
||||||
|
if(CollUtil.isNotEmpty(orderDetailInfoAddParams)) {
|
||||||
|
List<OrderDetail> orderDetailList = CollUtil.newArrayList();
|
||||||
|
for(DeviceOrderDetailInfoAddParam orderDetailInfoAddParam : orderDetailInfoAddParams) {
|
||||||
|
OrderDetail orderDetail = getOrderDetail(orderDetailInfoAddParam, orderInfo);
|
||||||
|
orderDetailList.add(orderDetail);
|
||||||
|
BigDecimal saleTotalAmount = orderDetail.getSalePrice().multiply(new BigDecimal(orderDetail.getQuantity()));
|
||||||
|
BigDecimal discountTotalAmount = orderDetail.getDiscountPrice().multiply(new BigDecimal(orderDetail.getQuantity()));
|
||||||
|
orderInfo.setPayableAmount(orderInfo.getPayableAmount().add(saleTotalAmount));
|
||||||
|
orderInfo.setDiscountsAmount(orderInfo.getDiscountsAmount().add(discountTotalAmount));
|
||||||
|
orderInfo.setRealAmount(orderInfo.getRealAmount().add(orderDetail.getTotalAmount()));
|
||||||
|
orderInfo.setAccountPayAmount(orderInfo.getRealAmount().add(orderDetail.getTotalAmount()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return orderInfoList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private OrderDetail getOrderDetail(DeviceOrderDetailInfoAddParam orderDetailInfoAddParam, OrderInfo orderInfo) {
|
||||||
|
OrderDetail orderDetail = new OrderDetail();
|
||||||
|
orderDetail.setOrderId(orderInfo.getOrderId());
|
||||||
|
orderDetail.setOrderDate(orderInfo.getOrderDate());
|
||||||
|
orderDetail.setGoodsId(orderDetailInfoAddParam.getGoodsId());
|
||||||
|
orderDetail.setGoodsName(orderDetailInfoAddParam.getGoodsName());
|
||||||
|
orderDetail.setGoodsImgUrl(orderDetailInfoAddParam.getGoodsImgUrl());
|
||||||
|
orderDetail.setMenuDetailId(orderDetailInfoAddParam.getMenuDetailId());
|
||||||
|
orderDetail.setSalePrice(orderDetailInfoAddParam.getSalePrice());
|
||||||
|
orderDetail.setDiscountPrice(orderDetailInfoAddParam.getDiscountPrice());
|
||||||
|
orderDetail.setFinalPrice(orderDetailInfoAddParam.getFinalPrice());
|
||||||
|
orderDetail.setQuantity(orderDetailInfoAddParam.getQuantity());
|
||||||
|
orderDetail.setSalesMode(orderDetailInfoAddParam.getSalesMode());
|
||||||
|
orderDetail.setDetailType(orderDetailInfoAddParam.getDetailType());
|
||||||
|
BigDecimal totalAmount = orderDetail.getFinalPrice().multiply(new BigDecimal(orderDetail.getQuantity()));
|
||||||
|
orderDetail.setTotalAmount(totalAmount);
|
||||||
|
orderDetail.setCalcTotalAmount(totalAmount);
|
||||||
|
orderDetail.setRealAmount(totalAmount);
|
||||||
|
orderDetail.setDetailState(OrderDetailStateEnum.NORMAL.getKey());
|
||||||
|
orderDetail.setRefundAmount(BigDecimal.ZERO);
|
||||||
|
orderDetail.setRefundNum(0);
|
||||||
|
orderDetail.setDeviceSn(StringUtils.defaultString(orderInfo.getDeviceSn(), StringUtils.EMPTY));
|
||||||
|
orderDetail.setSerialNum(StringUtils.EMPTY);
|
||||||
|
orderDetail.setCreateBy(SecurityUtils.getUsername());
|
||||||
|
orderDetail.setCreateTime(DateUtils.getNowDate());
|
||||||
|
orderDetail.setUpdateBy(SecurityUtils.getUsername());
|
||||||
|
orderDetail.setUpdateTime(DateUtils.getNowDate());
|
||||||
|
return orderDetail;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.bonus.canteen.core.order.domain.param;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.DecimalMin;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DeviceOrderAddParam {
|
||||||
|
private @NotNull(
|
||||||
|
message = "订单实付金额不能为空"
|
||||||
|
) @DecimalMin(
|
||||||
|
value = "0",
|
||||||
|
message = "订单实付金额不能小于0"
|
||||||
|
) BigDecimal realAmount;
|
||||||
|
private @NotNull(
|
||||||
|
message = "订单应付金额不能为空"
|
||||||
|
) @DecimalMin(
|
||||||
|
value = "0",
|
||||||
|
message = "订单应付金额不能小于0"
|
||||||
|
) BigDecimal payableAmount;
|
||||||
|
@NotNull(message = "用户ID不能为空")
|
||||||
|
private Long userId;
|
||||||
|
@NotNull(message = "下单日期不能为空")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
||||||
|
private Date placeDate;
|
||||||
|
@NotNull(message = "支付类型不能为空")
|
||||||
|
private Integer payType;
|
||||||
|
@NotNull(message = "订单来源不能为空")
|
||||||
|
private Integer sourceType;
|
||||||
|
private Integer isOnline;
|
||||||
|
List<DeviceOrderInfoAddParam> orderList;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.bonus.canteen.core.order.domain.param;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.DecimalMin;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DeviceOrderDetailInfoAddParam {
|
||||||
|
|
||||||
|
@NotNull(message = "订单详情类型不能为空")
|
||||||
|
private Integer detailType;
|
||||||
|
@NotNull(message = "下单菜品ID不能为空")
|
||||||
|
private Long goodsId;
|
||||||
|
private String goodsImgUrl;
|
||||||
|
private String goodsName;
|
||||||
|
@NotNull(message = "菜谱详情ID不能为空")
|
||||||
|
private Long menuDetailId;
|
||||||
|
@NotNull(message = "菜谱ID不能为空")
|
||||||
|
private Long menuId;
|
||||||
|
@NotNull(message = "菜谱下单数量不能为空")
|
||||||
|
private Integer quantity;
|
||||||
|
private Integer restrictNum;
|
||||||
|
private @NotNull(
|
||||||
|
message = "售卖价格不能为空"
|
||||||
|
) @DecimalMin(
|
||||||
|
value = "0",
|
||||||
|
message = "售卖价格不能小于0"
|
||||||
|
) BigDecimal salePrice;
|
||||||
|
private @NotNull(
|
||||||
|
message = "优惠价格不能为空"
|
||||||
|
) @DecimalMin(
|
||||||
|
value = "0",
|
||||||
|
message = "优惠价格不能小于0"
|
||||||
|
) BigDecimal discountPrice;
|
||||||
|
private @NotNull(
|
||||||
|
message = "计算价格不能为空"
|
||||||
|
) @DecimalMin(
|
||||||
|
value = "0",
|
||||||
|
message = "计算价格不能小于0"
|
||||||
|
) BigDecimal finalPrice;
|
||||||
|
private Integer salesMode;
|
||||||
|
private String shoppingCartId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.bonus.canteen.core.order.domain.param;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DeviceOrderInfoAddParam {
|
||||||
|
@NotNull(message = "食堂ID不能为空")
|
||||||
|
private Long canteenId;
|
||||||
|
private String canteenName;
|
||||||
|
@NotNull(message = "档口ID不能为空")
|
||||||
|
private Long stallId;
|
||||||
|
@NotNull(message = "用户ID不能为空")
|
||||||
|
@NotNull(message = "餐次类型不能为空")
|
||||||
|
private Integer mealtimeType;
|
||||||
|
private String mealtimeName;
|
||||||
|
@NotNull(message = "订单日期不能为空")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
||||||
|
private Date orderDate;
|
||||||
|
@NotNull(message = "订单类型不能为空")
|
||||||
|
private Integer orderType;
|
||||||
|
@NotNull(message = "设备订单ID不能为空")
|
||||||
|
private String deviceOrderId;
|
||||||
|
@NotNull(message = "设备SN不能为空")
|
||||||
|
private String deviceSn;
|
||||||
|
@NotNull(message = "设备编号不能为空")
|
||||||
|
private String deviceNum;
|
||||||
|
List<DeviceOrderDetailInfoAddParam> orderDetailList;
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.bonus.canteen.core.order.service;
|
package com.bonus.canteen.core.order.service;
|
||||||
|
|
||||||
import com.bonus.canteen.core.order.domain.OrderInfo;
|
import com.bonus.canteen.core.order.domain.OrderInfo;
|
||||||
|
import com.bonus.canteen.core.order.domain.param.DeviceOrderAddParam;
|
||||||
import com.bonus.canteen.core.order.domain.param.OrderAddParam;
|
import com.bonus.canteen.core.order.domain.param.OrderAddParam;
|
||||||
import com.bonus.canteen.core.order.domain.param.OrderInfoAddParam;
|
import com.bonus.canteen.core.order.domain.param.OrderInfoAddParam;
|
||||||
import com.bonus.canteen.core.order.domain.param.ShopOrderAddParam;
|
import com.bonus.canteen.core.order.domain.param.ShopOrderAddParam;
|
||||||
|
|
@ -40,6 +41,7 @@ public interface IOrderInfoService
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int insertCanteenOrderInfo(OrderAddParam orderAddParam);
|
public int insertCanteenOrderInfo(OrderAddParam orderAddParam);
|
||||||
|
public int insertDeviceOrderInfo(DeviceOrderAddParam orderAddParam);
|
||||||
|
|
||||||
public int insertShopOrderInfo(ShopOrderAddParam orderAddParam);
|
public int insertShopOrderInfo(ShopOrderAddParam orderAddParam);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import com.bonus.canteen.core.order.domain.OrderDetail;
|
||||||
import com.bonus.canteen.core.order.domain.OrderInfo;
|
import com.bonus.canteen.core.order.domain.OrderInfo;
|
||||||
import com.bonus.canteen.core.order.domain.OrderPayDTO;
|
import com.bonus.canteen.core.order.domain.OrderPayDTO;
|
||||||
import com.bonus.canteen.core.order.domain.OrderPayResultDTO;
|
import com.bonus.canteen.core.order.domain.OrderPayResultDTO;
|
||||||
|
import com.bonus.canteen.core.order.domain.param.DeviceOrderAddParam;
|
||||||
import com.bonus.canteen.core.order.domain.param.OrderAddParam;
|
import com.bonus.canteen.core.order.domain.param.OrderAddParam;
|
||||||
import com.bonus.canteen.core.order.domain.param.ShopOrderAddParam;
|
import com.bonus.canteen.core.order.domain.param.ShopOrderAddParam;
|
||||||
import com.bonus.canteen.core.order.mapper.OrderInfoMapper;
|
import com.bonus.canteen.core.order.mapper.OrderInfoMapper;
|
||||||
|
|
@ -102,10 +103,25 @@ public class OrderInfoServiceImpl implements IOrderInfoService
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int insertCanteenOrderInfo(OrderAddParam orderAddParam) {
|
public int insertCanteenOrderInfo(OrderAddParam orderAddParam) {
|
||||||
log.info("[食堂下单]入参:{}", JacksonUtil.writeValueAsString(orderAddParam));
|
log.info("[食堂h5下单]入参:{}", JacksonUtil.writeValueAsString(orderAddParam));
|
||||||
String paramMd5 = "sc:canteen_order_"+DigestUtil.md5Hex(JacksonUtil.writeValueAsString(orderAddParam));
|
String paramMd5 = "sc:h5_order_"+DigestUtil.md5Hex(JacksonUtil.writeValueAsString(orderAddParam));
|
||||||
if (!RedisUtil.setNx(paramMd5, 1, 2)) {
|
if (!RedisUtil.setNx(paramMd5, 1, 2)) {
|
||||||
log.info("[食堂下单]重复提交:{}", paramMd5);
|
log.info("[食堂h5下单]重复提交:{}", paramMd5);
|
||||||
|
throw new ServiceException("请勿重复提交订单");
|
||||||
|
}
|
||||||
|
AccInfoDetailsVO accInfoVO = this.accInfoService.queryAccInfoByUserId(orderAddParam.getUserId());
|
||||||
|
accInfoService.checkAccStatus(accInfoVO);
|
||||||
|
List<OrderInfo> canteenOrderInfoList = new OrderInfo().of(orderAddParam);
|
||||||
|
List<OrderInfo> orderInfoList = orderBusiness.orderPlaceHandler(canteenOrderInfoList);
|
||||||
|
orderPay(orderInfoList);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public int insertDeviceOrderInfo(DeviceOrderAddParam orderAddParam) {
|
||||||
|
log.info("[食堂设备下单]入参:{}", JacksonUtil.writeValueAsString(orderAddParam));
|
||||||
|
String paramMd5 = "sc:device_order_"+DigestUtil.md5Hex(JacksonUtil.writeValueAsString(orderAddParam));
|
||||||
|
if (!RedisUtil.setNx(paramMd5, 1, 2)) {
|
||||||
|
log.info("[食堂设备下单]重复提交:{}", paramMd5);
|
||||||
throw new ServiceException("请勿重复提交订单");
|
throw new ServiceException("请勿重复提交订单");
|
||||||
}
|
}
|
||||||
AccInfoDetailsVO accInfoVO = this.accInfoService.queryAccInfoByUserId(orderAddParam.getUserId());
|
AccInfoDetailsVO accInfoVO = this.accInfoService.queryAccInfoByUserId(orderAddParam.getUserId());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue