|
@@ -45,6 +45,7 @@ import org.springframework.integration.redis.util.RedisLockRegistry;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
@@ -145,31 +146,52 @@ public class OrderLogic {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
GoodsCategoryService goodsCategoryService;
|
|
GoodsCategoryService goodsCategoryService;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ GoodsMaterialStorageService goodsMaterialStorageService;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ StorageService storageService;
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 立即购买
|
|
* 立即购买
|
|
|
*/
|
|
*/
|
|
|
@Transactional
|
|
@Transactional
|
|
|
- public PayDetail buy(OrderBuyBean orderBuyBean,HttpServletRequest request) throws Exception {
|
|
|
|
|
|
|
+ public PayDetail buy(OrderBuyBean orderBuyBean, HttpServletRequest request) throws Exception {
|
|
|
String ip = IpUtil.getIpAddr(request);
|
|
String ip = IpUtil.getIpAddr(request);
|
|
|
- if(StringUtils.isBlank(orderBuyBean.getUserAddressId())){
|
|
|
|
|
- throw new RemoteServiceException(1100,"请选择收货地址");
|
|
|
|
|
|
|
+ if (StringUtils.isBlank(orderBuyBean.getStorageId())) {
|
|
|
|
|
+ throw new RemoteServiceException(1100, "缺少仓库");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(orderBuyBean.getPayTypeId())) {
|
|
|
|
|
+ throw new RemoteServiceException(1100, "请选择支付方式");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(orderBuyBean.getUserAddressId())
|
|
|
|
|
+ && orderBuyBean.getPayTypeId().equals(PayTypeEnum.WECHAT.getKey())
|
|
|
|
|
+ && orderBuyBean.getTakeGoodsType().equals(TakeGoodsTypeEnum.Y.getKey())) {
|
|
|
|
|
+ throw new RemoteServiceException(1100, "请选择收货地址");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(orderBuyBean.getTakeGoodsType())) {
|
|
|
|
|
+ throw new RemoteServiceException(1100, "请选择提货方式");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (orderBuyBean.getTakeGoodsType().equals(TakeGoodsTypeEnum.Z.getKey())
|
|
|
|
|
+ && (Objects.isNull(orderBuyBean.getAppointmentPickStartTime())
|
|
|
|
|
+ || Objects.isNull(orderBuyBean.getAppointmentPickEndTime()))) {
|
|
|
|
|
+ throw new RemoteServiceException(1100, "请选择提货时间");
|
|
|
}
|
|
}
|
|
|
CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat(request);
|
|
CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat(request);
|
|
|
|
|
+
|
|
|
|
|
+ final Storage storage = storageService.getById(orderBuyBean.getStorageId());
|
|
|
//订单
|
|
//订单
|
|
|
OrderInfo orderInfo = new OrderInfo();
|
|
OrderInfo orderInfo = new OrderInfo();
|
|
|
String orderId = currentCompanyWechat.getOrderPrefix() + IdWorker.getIdStr();
|
|
String orderId = currentCompanyWechat.getOrderPrefix() + IdWorker.getIdStr();
|
|
|
orderInfo.setOrderId(orderId);
|
|
orderInfo.setOrderId(orderId);
|
|
|
|
|
+ orderInfo.setTakeGoodsType(orderBuyBean.getTakeGoodsType());
|
|
|
|
|
+ orderInfo.setPickStorageId(storage.getStorageId());
|
|
|
|
|
+ orderInfo.setPickStorageName(storage.getStorageName());
|
|
|
|
|
+ orderInfo.setAppointmentPickStartTime(orderBuyBean.getAppointmentPickStartTime());
|
|
|
|
|
+ orderInfo.setAppointmentPickEndTime(orderBuyBean.getAppointmentPickEndTime());
|
|
|
//购买人
|
|
//购买人
|
|
|
- String userId = currentCompanyWechat.getUserId();
|
|
|
|
|
User user = currentCompanyWechat.getUser();
|
|
User user = currentCompanyWechat.getUser();
|
|
|
- //分销员
|
|
|
|
|
- String serviceId = user.getServiceId();
|
|
|
|
|
- if(user.getType().equals(UserTypeEnum.SERVICE.toString())) {
|
|
|
|
|
- serviceId = user.getUserId();
|
|
|
|
|
- }
|
|
|
|
|
- User service = userService.getById(serviceId);
|
|
|
|
|
|
|
+
|
|
|
//商品总金额(不包含运费,优惠金额,非实际支付金额)
|
|
//商品总金额(不包含运费,优惠金额,非实际支付金额)
|
|
|
BigDecimal totalPrice = BigDecimal.valueOf(0);
|
|
BigDecimal totalPrice = BigDecimal.valueOf(0);
|
|
|
//商品实际支付总金额
|
|
//商品实际支付总金额
|
|
@@ -178,33 +200,25 @@ public class OrderLogic {
|
|
|
BigDecimal totalFreight = BigDecimal.valueOf(0);
|
|
BigDecimal totalFreight = BigDecimal.valueOf(0);
|
|
|
//订单标题
|
|
//订单标题
|
|
|
String orderTitle = "";
|
|
String orderTitle = "";
|
|
|
- //分账金额
|
|
|
|
|
- BigDecimal shareAmount = BigDecimal.valueOf(0);
|
|
|
|
|
- //非团购商品的分账金额
|
|
|
|
|
- BigDecimal notPromotionShareAmount = BigDecimal.valueOf(0);
|
|
|
|
|
//总数量
|
|
//总数量
|
|
|
Integer totalNum = 0;
|
|
Integer totalNum = 0;
|
|
|
- //兑换码
|
|
|
|
|
- String exchangeCode = orderBuyBean.getExchangeCode();
|
|
|
|
|
- //是否有使用了礼品码的商品
|
|
|
|
|
- Boolean hasGiftCode = false;
|
|
|
|
|
- //收获地址
|
|
|
|
|
- UserAddress userAddress = userAddressService.getById(orderBuyBean.getUserAddressId());
|
|
|
|
|
- //团长id
|
|
|
|
|
- String promotionGroupUserId = "";
|
|
|
|
|
- String orderPromotionGroupId = "";
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 收货地址
|
|
|
|
|
+ UserAddress userAddress = null;
|
|
|
|
|
+ if (StringUtils.isNotBlank(orderBuyBean.getUserAddressId())
|
|
|
|
|
+ && orderBuyBean.getPayTypeId().equals(PayTypeEnum.WECHAT.getKey())
|
|
|
|
|
+ && orderBuyBean.getTakeGoodsType().equals(TakeGoodsTypeEnum.Y.getKey())) {
|
|
|
|
|
+ userAddress = userAddressService.getById(orderBuyBean.getUserAddressId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
List<String> goodsIds = orderBuyBean.getBuyGoods().stream().map(BuyGood::getGoodsId).collect(Collectors.toList());
|
|
List<String> goodsIds = orderBuyBean.getBuyGoods().stream().map(BuyGood::getGoodsId).collect(Collectors.toList());
|
|
|
- //满件折扣活动
|
|
|
|
|
- Boolean promotionFullPiece = false;
|
|
|
|
|
- String promotionFullPieceId = "";
|
|
|
|
|
- String promotionFullPieceRemark = "";
|
|
|
|
|
- List<PromotionFullPieceItem> promotionFullPieceItems = promotionFullPieceLogic.getItems();
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
//购物车ids
|
|
//购物车ids
|
|
|
List<String> shoppingCartIds = orderBuyBean.getBuyGoods().stream().map(BuyGood::getShoppingCartId).collect(Collectors.toList());
|
|
List<String> shoppingCartIds = orderBuyBean.getBuyGoods().stream().map(BuyGood::getShoppingCartId).collect(Collectors.toList());
|
|
|
//如果用户存在,则判断是否为业务员,并更新相关信息
|
|
//如果用户存在,则判断是否为业务员,并更新相关信息
|
|
|
if (!user.getStatus()) {
|
|
if (!user.getStatus()) {
|
|
|
- throw new RemoteServiceException(1100,"用户已被冻结");
|
|
|
|
|
|
|
+ throw new RemoteServiceException(1100, "用户已被冻结");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//这里面会处理各个活动对单价以及佣金金额的处理
|
|
//这里面会处理各个活动对单价以及佣金金额的处理
|
|
@@ -213,16 +227,13 @@ public class OrderLogic {
|
|
|
//订单详情
|
|
//订单详情
|
|
|
List<OrderDetail> orderDetails = new ArrayList<>();
|
|
List<OrderDetail> orderDetails = new ArrayList<>();
|
|
|
for (BuyGood buyGood : buyGoods) {
|
|
for (BuyGood buyGood : buyGoods) {
|
|
|
- if(StringUtils.isBlank(orderPromotionGroupId)) {
|
|
|
|
|
- orderPromotionGroupId = buyGood.getPromotionGroupId();
|
|
|
|
|
- }
|
|
|
|
|
//商品
|
|
//商品
|
|
|
Goods goods = buyGood.getGoods();
|
|
Goods goods = buyGood.getGoods();
|
|
|
- if(!goods.getStatus()){
|
|
|
|
|
- throw new RemoteServiceException("存在已下架商品:"+goods.getGoodsName());
|
|
|
|
|
|
|
+ if (!goods.getStatus()) {
|
|
|
|
|
+ throw new RemoteServiceException("存在已下架商品:" + goods.getGoodsName());
|
|
|
}
|
|
}
|
|
|
//处理库存并返回商品规格
|
|
//处理库存并返回商品规格
|
|
|
- GoodsSpec goodsSpec = this.stock(buyGood.getGoodsSpecId(), goods.getGoodsName(), buyGood.getNum());
|
|
|
|
|
|
|
+ GoodsSpec goodsSpec = this.stock(buyGood.getGoodsSpecId(), goods.getGoodsName(), buyGood.getNum(), orderBuyBean.getStorageId());
|
|
|
|
|
|
|
|
String goodsId = goodsSpec.getGoodsId();
|
|
String goodsId = goodsSpec.getGoodsId();
|
|
|
String goodsSpecId = goodsSpec.getGoodsSpecId();
|
|
String goodsSpecId = goodsSpec.getGoodsSpecId();
|
|
@@ -232,7 +243,6 @@ public class OrderLogic {
|
|
|
BigDecimal goodsSecPrice = buyGood.getPrice();
|
|
BigDecimal goodsSecPrice = buyGood.getPrice();
|
|
|
String catagoryId = goods.getCategoryId();
|
|
String catagoryId = goods.getCategoryId();
|
|
|
String userCouponId = orderBuyBean.getUserCouponId();
|
|
String userCouponId = orderBuyBean.getUserCouponId();
|
|
|
- BigDecimal cutAmount = new BigDecimal("0");
|
|
|
|
|
|
|
|
|
|
GoodsMaterial gm = goodsMaterialService.getById(goodsSpec.getGoodsCode());
|
|
GoodsMaterial gm = goodsMaterialService.getById(goodsSpec.getGoodsCode());
|
|
|
|
|
|
|
@@ -254,7 +264,7 @@ public class OrderLogic {
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(catagoryId)) {
|
|
if (StringUtils.isNotBlank(catagoryId)) {
|
|
|
GoodsCategory goodsCategory = goodsCategoryLogic.queryById(catagoryId);
|
|
GoodsCategory goodsCategory = goodsCategoryLogic.queryById(catagoryId);
|
|
|
- if(goodsCategory != null) {
|
|
|
|
|
|
|
+ if (goodsCategory != null) {
|
|
|
orderDetail.setMainNumber(goodsCategory.getMainNumber());
|
|
orderDetail.setMainNumber(goodsCategory.getMainNumber());
|
|
|
orderDetail.setMainName(goodsCategory.getMainName());
|
|
orderDetail.setMainName(goodsCategory.getMainName());
|
|
|
orderDetail.setSmallNumber(goodsCategory.getSmallNumber());
|
|
orderDetail.setSmallNumber(goodsCategory.getSmallNumber());
|
|
@@ -276,7 +286,7 @@ public class OrderLogic {
|
|
|
orderDetail.setInsideNum(insideQty * orderDetail.getNum());
|
|
orderDetail.setInsideNum(insideQty * orderDetail.getNum());
|
|
|
orderDetail.setOutNum(outQty * orderDetail.getNum());
|
|
orderDetail.setOutNum(outQty * orderDetail.getNum());
|
|
|
orderDetail.setPartNum(partsQty * orderDetail.getNum());
|
|
orderDetail.setPartNum(partsQty * orderDetail.getNum());
|
|
|
- if(gm != null) {
|
|
|
|
|
|
|
+ if (gm != null) {
|
|
|
orderDetail.setGoodsMaterialId(gm.getId());
|
|
orderDetail.setGoodsMaterialId(gm.getId());
|
|
|
orderDetail.setGoodsMaterialName(gm.getGoodsName());
|
|
orderDetail.setGoodsMaterialName(gm.getGoodsName());
|
|
|
orderDetail.setGoodsSpecValue(gm.getSpecsName());
|
|
orderDetail.setGoodsSpecValue(gm.getSpecsName());
|
|
@@ -288,7 +298,7 @@ public class OrderLogic {
|
|
|
orderDetail.setSmallName(goodsSpec.getSmallName());
|
|
orderDetail.setSmallName(goodsSpec.getSmallName());
|
|
|
orderDetail.setFlag(1);
|
|
orderDetail.setFlag(1);
|
|
|
|
|
|
|
|
- BigDecimal freightAmountItem = this.getFreightAmountItem(userAddress.getProvince(), userAddress.getCity(), userAddress.getArea(), buyGood,currentCompanyWechat);
|
|
|
|
|
|
|
+ BigDecimal freightAmountItem = Objects.nonNull(userAddress) ? this.getFreightAmountItem(userAddress.getProvince(), userAddress.getCity(), userAddress.getArea(), buyGood, currentCompanyWechat) : BigDecimal.valueOf(0);
|
|
|
orderDetail.setFreight(freightAmountItem);
|
|
orderDetail.setFreight(freightAmountItem);
|
|
|
|
|
|
|
|
orderDetails.add(orderDetail);
|
|
orderDetails.add(orderDetail);
|
|
@@ -305,53 +315,40 @@ public class OrderLogic {
|
|
|
|
|
|
|
|
//生成订单
|
|
//生成订单
|
|
|
orderInfo.setIsAllVr(orderDetails.stream().filter(v -> !v.getIsVr()).count() == 0);
|
|
orderInfo.setIsAllVr(orderDetails.stream().filter(v -> !v.getIsVr()).count() == 0);
|
|
|
- //orderInfo.setIsAddCorp(yrzqw > 0);
|
|
|
|
|
|
|
+
|
|
|
orderInfo.setBuyerMsg(orderBuyBean.getBuyerMsg());
|
|
orderInfo.setBuyerMsg(orderBuyBean.getBuyerMsg());
|
|
|
|
|
+
|
|
|
orderInfo.setOrderStatus(OrderStatusEnum.NOPAY.toString());
|
|
orderInfo.setOrderStatus(OrderStatusEnum.NOPAY.toString());
|
|
|
|
|
+ // 如果是到店支付,订单改为待确认
|
|
|
|
|
+ if (orderBuyBean.getPayTypeId().equals(PayTypeEnum.STORE.getKey())) {
|
|
|
|
|
+ orderInfo.setOrderStatus(OrderStatusEnum.DQR.toString());
|
|
|
|
|
+ }
|
|
|
orderInfo.setUserId(user.getUserId());
|
|
orderInfo.setUserId(user.getUserId());
|
|
|
orderInfo.setUserName(user.getNickName());
|
|
orderInfo.setUserName(user.getNickName());
|
|
|
orderInfo.setPhone(user.getMobile());
|
|
orderInfo.setPhone(user.getMobile());
|
|
|
- orderInfo.setUserAddressId(userAddress.getUserAddressId());
|
|
|
|
|
- orderInfo.setReceUserName(userAddress.getName());
|
|
|
|
|
- orderInfo.setReceAddress(userAddress.getAddress());
|
|
|
|
|
- orderInfo.setRecePhone(userAddress.getPhone());
|
|
|
|
|
- orderInfo.setProvince(userAddress.getProvince());
|
|
|
|
|
- orderInfo.setCity(userAddress.getCity());
|
|
|
|
|
- orderInfo.setArea(userAddress.getArea());
|
|
|
|
|
- orderInfo.setStreet(userAddress.getStreet());
|
|
|
|
|
- orderInfo.setHouseNo(userAddress.getHouseNo());
|
|
|
|
|
|
|
+ if (Objects.nonNull(userAddress)) {
|
|
|
|
|
+ orderInfo.setUserAddressId(userAddress.getUserAddressId());
|
|
|
|
|
+ orderInfo.setReceUserName(userAddress.getName());
|
|
|
|
|
+ orderInfo.setReceAddress(userAddress.getAddress());
|
|
|
|
|
+ orderInfo.setRecePhone(userAddress.getPhone());
|
|
|
|
|
+ orderInfo.setProvince(userAddress.getProvince());
|
|
|
|
|
+ orderInfo.setCity(userAddress.getCity());
|
|
|
|
|
+ orderInfo.setArea(userAddress.getArea());
|
|
|
|
|
+ orderInfo.setStreet(userAddress.getStreet());
|
|
|
|
|
+ orderInfo.setHouseNo(userAddress.getHouseNo());
|
|
|
|
|
+ }
|
|
|
orderInfo.setCreateTime(new Date());
|
|
orderInfo.setCreateTime(new Date());
|
|
|
orderInfo.setFreight(totalFreight);
|
|
orderInfo.setFreight(totalFreight);
|
|
|
orderInfo.setTotalAmount(totalPrice);
|
|
orderInfo.setTotalAmount(totalPrice);
|
|
|
orderInfo.setPayAmount(payAmount);
|
|
orderInfo.setPayAmount(payAmount);
|
|
|
orderInfo.setPayTypeId(orderBuyBean.getPayTypeId());
|
|
orderInfo.setPayTypeId(orderBuyBean.getPayTypeId());
|
|
|
- orderInfo.setPayType(BaseEnum.keyToEnum(PayTypeEnum.class,orderBuyBean.getPayTypeId()).getRemark());
|
|
|
|
|
|
|
+ orderInfo.setPayType(BaseEnum.keyToEnum(PayTypeEnum.class, orderBuyBean.getPayTypeId()).getRemark());
|
|
|
//检查优惠券的使用合法性
|
|
//检查优惠券的使用合法性
|
|
|
- //if(!isPromotion && !hasGiftCode) {
|
|
|
|
|
- UserCouponBean userCoupon = couponLogic.check(orderBuyBean.getUserCouponId(), totalPrice, goodsIds,true);
|
|
|
|
|
-// if(userCoupon == null){
|
|
|
|
|
-// throw new RemoteServiceException("优惠券暂不可用,请联系相关人员");
|
|
|
|
|
-// }
|
|
|
|
|
- if (userCoupon != null && this.checkPackageUseCoupon(orderBuyBean.getGoodsPackageId(),userCoupon)) {
|
|
|
|
|
- orderInfo.setDiscountAmount(userCoupon.getCouponValue());
|
|
|
|
|
- orderInfo.setCouponId(userCoupon.getCouponId());
|
|
|
|
|
- orderInfo.setCouponName(userCoupon.getCouponName());
|
|
|
|
|
- orderInfo.setCouponValue(userCoupon.getCouponValue());
|
|
|
|
|
- orderInfo.setUserCouponId(userCoupon.getId());
|
|
|
|
|
-
|
|
|
|
|
- //检查是否优惠超过50%,如果超过,拒绝下单
|
|
|
|
|
- BigDecimal divide = totalPrice.divide(userCoupon.getCouponValue(), 3, RoundingMode.HALF_UP);
|
|
|
|
|
- if(divide.doubleValue() < 2){
|
|
|
|
|
- throw new RemoteServiceException("优惠券抵扣额度不可超订单价格50%");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ UserCouponBean userCoupon = couponLogic.check(orderBuyBean.getUserCouponId(), totalPrice, goodsIds, true);
|
|
|
|
|
|
|
|
- //扣减优惠券金额
|
|
|
|
|
- orderInfo.setPayAmount(orderInfo.getPayAmount().subtract(orderInfo.getDiscountAmount()));
|
|
|
|
|
- }
|
|
|
|
|
- //}
|
|
|
|
|
orderInfo.setTotalNum(totalNum);
|
|
orderInfo.setTotalNum(totalNum);
|
|
|
- if(StringUtils.isNotBlank(orderTitle) && orderTitle.length() > 0) {
|
|
|
|
|
- orderTitle = orderTitle.substring(0,orderTitle.length() - 1);
|
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(orderTitle) && orderTitle.length() > 0) {
|
|
|
|
|
+ orderTitle = orderTitle.substring(0, orderTitle.length() - 1);
|
|
|
orderInfo.setOrderTitle(orderTitle);
|
|
orderInfo.setOrderTitle(orderTitle);
|
|
|
}
|
|
}
|
|
|
orderInfo.setTotalProductAmount(totalPrice);
|
|
orderInfo.setTotalProductAmount(totalPrice);
|
|
@@ -360,14 +357,14 @@ public class OrderLogic {
|
|
|
orderInfo.setDispatchType(orderBuyBean.getDispatchType());
|
|
orderInfo.setDispatchType(orderBuyBean.getDispatchType());
|
|
|
|
|
|
|
|
//支付金额不可为负数
|
|
//支付金额不可为负数
|
|
|
- if(orderInfo.getPayAmount().doubleValue() < 0){
|
|
|
|
|
|
|
+ if (orderInfo.getPayAmount().doubleValue() < 0) {
|
|
|
throw new RemoteServiceException("优惠金额超出,请联系客服");
|
|
throw new RemoteServiceException("优惠金额超出,请联系客服");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//来源
|
|
//来源
|
|
|
- if(orderBuyBean.getMiniPay() != null && orderBuyBean.getMiniPay()){
|
|
|
|
|
|
|
+ if (orderBuyBean.getMiniPay() != null && orderBuyBean.getMiniPay()) {
|
|
|
orderInfo.setSource(OrderInfoSourceEnum.A.getRemark());
|
|
orderInfo.setSource(OrderInfoSourceEnum.A.getRemark());
|
|
|
- }else{
|
|
|
|
|
|
|
+ } else {
|
|
|
orderInfo.setSource(OrderInfoSourceEnum.B.getRemark());
|
|
orderInfo.setSource(OrderInfoSourceEnum.B.getRemark());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -378,36 +375,20 @@ public class OrderLogic {
|
|
|
if (!CollectionUtils.isEmpty(shoppingCartIds)) {
|
|
if (!CollectionUtils.isEmpty(shoppingCartIds)) {
|
|
|
shoppingCartService.lambdaUpdate().in(ShoppingCart::getShoppingCartId, shoppingCartIds).remove();
|
|
shoppingCartService.lambdaUpdate().in(ShoppingCart::getShoppingCartId, shoppingCartIds).remove();
|
|
|
}
|
|
}
|
|
|
- //代客下单
|
|
|
|
|
- if (orderBuyBean.getProxyUser()) {
|
|
|
|
|
- PayDetail payDetail = new PayDetail();
|
|
|
|
|
- payDetail.setIsPay(false);
|
|
|
|
|
- payDetail.setId(orderInfo.getOrderId());
|
|
|
|
|
- payDetail.setCodeUrl(wechatLogic.getQrcode(QrCodeEnum.ORDER.toString().toLowerCase(Locale.ROOT),
|
|
|
|
|
- orderInfo.getOrderId(), orderInfo.getUserId(),user.getCompanyWechatId()));
|
|
|
|
|
- return payDetail;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
//调起支付
|
|
//调起支付
|
|
|
String profitSharingFlag = "N";
|
|
String profitSharingFlag = "N";
|
|
|
BigDecimal zero = new BigDecimal("0.00");
|
|
BigDecimal zero = new BigDecimal("0.00");
|
|
|
- if (shareAmount.compareTo(zero) > 0) {
|
|
|
|
|
- profitSharingFlag = "Y";
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
PayDetail payDetail = new PayDetail();
|
|
PayDetail payDetail = new PayDetail();
|
|
|
payDetail.setId(orderInfo.getOrderId());
|
|
payDetail.setId(orderInfo.getOrderId());
|
|
|
|
|
|
|
|
- //if(orderBuyBean.getWechatPay()) {
|
|
|
|
|
- if(!StringUtils.equals(orderBuyBean.getPayTypeId(),PayTypeEnum.STORE.getKey())) {
|
|
|
|
|
- if (orderBuyBean.getH5Pay() != null && orderBuyBean.getH5Pay()) {
|
|
|
|
|
- payDetail = wechatLogic.paymentH5(orderInfo.getOrderId(), orderInfo.getPayAmount(), user.getOpenId(),
|
|
|
|
|
- profitSharingFlag, ip, user.getCompanyWechatId());
|
|
|
|
|
- } else {
|
|
|
|
|
- payDetail = wechatLogic.payment(orderInfo.getOrderId(), orderInfo.getPayAmount(),
|
|
|
|
|
- orderBuyBean.getMiniPay() != null && orderBuyBean.getMiniPay() ? orderBuyBean.getOpenId() : user.getOpenId(),
|
|
|
|
|
- profitSharingFlag, ip, user.getCompanyWechatId(), orderBuyBean.getMiniPay());
|
|
|
|
|
- }
|
|
|
|
|
- }else{
|
|
|
|
|
|
|
+ if (!StringUtils.equals(orderBuyBean.getPayTypeId(), PayTypeEnum.STORE.getKey())) {
|
|
|
|
|
+ payDetail = wechatLogic.payment(orderInfo.getOrderId(), orderInfo.getPayAmount(),
|
|
|
|
|
+ orderBuyBean.getMiniPay() != null && orderBuyBean.getMiniPay() ? orderBuyBean.getOpenId() : user.getOpenId(),
|
|
|
|
|
+ profitSharingFlag, ip, user.getCompanyWechatId(), orderBuyBean.getMiniPay());
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
payDetail.setIsPay(false);
|
|
payDetail.setIsPay(false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -415,68 +396,10 @@ public class OrderLogic {
|
|
|
if (!payDetail.getIsPay()) {
|
|
if (!payDetail.getIsPay()) {
|
|
|
payLogic.payCall(payDetail.getId(), "", orderInfo.getPayAmount());
|
|
payLogic.payCall(payDetail.getId(), "", orderInfo.getPayAmount());
|
|
|
}
|
|
}
|
|
|
- //}
|
|
|
|
|
- return payDetail;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 处理旧机
|
|
|
|
|
- * @param orderBuyBean
|
|
|
|
|
- * @param orderId
|
|
|
|
|
- * @param yjhxDkFlag
|
|
|
|
|
- * @return
|
|
|
|
|
- */
|
|
|
|
|
- private OrderOldProduct handleOldProduct(OrderBuyBean orderBuyBean,String orderId,Integer yjhxDkFlag){
|
|
|
|
|
- //以旧换新
|
|
|
|
|
- if (orderBuyBean.getOrderOldProductAdds() != null) {
|
|
|
|
|
-
|
|
|
|
|
- List<OrderOldProductItem> orderOldProductItems = new ArrayList<>();
|
|
|
|
|
-
|
|
|
|
|
- GoodsCategoryItem goodsCategoryItemDto = goodsCategoryItemService.getById(orderBuyBean.getOrderOldProductAdds().getId());
|
|
|
|
|
-
|
|
|
|
|
- GoodsCategory goodsCategory = goodsCategoryService.getById(goodsCategoryItemDto.getMainId());
|
|
|
|
|
- GoodsCategory goodsCategorySmall = goodsCategoryService.getById(goodsCategoryItemDto.getSmallId());
|
|
|
|
|
-
|
|
|
|
|
- OrderOldProduct orderOldProduct = new OrderOldProduct();
|
|
|
|
|
- this.productCategory(orderOldProduct, goodsCategoryItemDto);
|
|
|
|
|
- orderOldProduct.setId(null);
|
|
|
|
|
- orderOldProduct.setSaleType(1);
|
|
|
|
|
- orderOldProduct.setOrderId(orderId);
|
|
|
|
|
- orderOldProduct.setId(IdWorker.getIdStr());
|
|
|
|
|
- orderOldProduct.setNum(1);
|
|
|
|
|
- orderOldProduct.setYjhxDkFlag(yjhxDkFlag);
|
|
|
|
|
- orderOldProduct.setPrice(goodsCategoryItemDto.getPrice());
|
|
|
|
|
- orderOldProduct.setPayAmount(goodsCategoryItemDto.getPrice());
|
|
|
|
|
-
|
|
|
|
|
- orderOldProduct.setMainImg(goodsCategory.getImgUrl());
|
|
|
|
|
- orderOldProduct.setSmallImg(goodsCategorySmall.getImgUrl());
|
|
|
|
|
-
|
|
|
|
|
- for (String goodsCategoryItem : orderBuyBean.getOrderOldProductAdds().getItemIds()) {
|
|
|
|
|
- GoodsCategoryItem goodsCategoryItems = goodsCategoryItemService.getById(goodsCategoryItem);
|
|
|
|
|
- OrderOldProductItem orderOldProductItem = this.productCategoryItem(goodsCategoryItems);
|
|
|
|
|
- orderOldProductItem.setId(null);
|
|
|
|
|
- orderOldProductItem.setGoodsCategoryItemId(goodsCategoryItems.getId());
|
|
|
|
|
- orderOldProductItem.setOrderId(orderOldProduct.getOrderId());
|
|
|
|
|
- orderOldProductItem.setOrderOldProductId(orderOldProduct.getId());
|
|
|
|
|
- orderOldProduct.setPayAmount(orderOldProduct.getPayAmount().add(goodsCategoryItems.getPrice()));
|
|
|
|
|
- orderOldProductItems.add(orderOldProductItem);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- orderOldProductService.lambdaUpdate().eq(OrderOldProduct::getOrderId,orderId).remove();
|
|
|
|
|
- orderOldProductItemService.lambdaUpdate().eq(OrderOldProductItem::getOrderId,orderId).remove();
|
|
|
|
|
- orderOldProductService.save(orderOldProduct);
|
|
|
|
|
|
|
|
|
|
- if (!org.springframework.util.CollectionUtils.isEmpty(orderOldProductItems)){
|
|
|
|
|
- orderOldProductItemService.saveBatch(orderOldProductItems);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return orderOldProduct;
|
|
|
|
|
- }
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+ return payDetail;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
private OrderOldProductItem productCategoryItem(GoodsCategoryItem goodsCategoryItem) {
|
|
private OrderOldProductItem productCategoryItem(GoodsCategoryItem goodsCategoryItem) {
|
|
|
OrderOldProductItem orderOldProductItem = BeanUtil.toBean(goodsCategoryItem, OrderOldProductItem.class);
|
|
OrderOldProductItem orderOldProductItem = BeanUtil.toBean(goodsCategoryItem, OrderOldProductItem.class);
|
|
|
return orderOldProductItem;
|
|
return orderOldProductItem;
|
|
@@ -699,19 +622,6 @@ public class OrderLogic {
|
|
|
List<OrderOldProduct> listProduce = orderOldProductService.lambdaQuery()
|
|
List<OrderOldProduct> listProduce = orderOldProductService.lambdaQuery()
|
|
|
.eq(OrderOldProduct::getOrderId, orderId).list();
|
|
.eq(OrderOldProduct::getOrderId, orderId).list();
|
|
|
|
|
|
|
|
- List<OrderOldProductDTO> orderOldProductDTOS = new ArrayList<>();
|
|
|
|
|
-
|
|
|
|
|
- for (OrderOldProduct orderOldProduct : listProduce) {
|
|
|
|
|
- OrderOldProductDTO orderOldProductDTO = BeanUtil.toBean(orderOldProduct, OrderOldProductDTO.class);
|
|
|
|
|
- List<OrderOldProductItem> orderOldProductItemList = orderOldProductItemService.lambdaQuery()
|
|
|
|
|
- .eq(OrderOldProductItem::getOrderOldProductId, orderOldProduct.getId()).list();
|
|
|
|
|
- orderOldProductDTO.setItemList(orderOldProductItemList);
|
|
|
|
|
-
|
|
|
|
|
- orderOldProductDTOS.add(orderOldProductDTO);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- orderDetailBean.setOrderOldProductDTOList(orderOldProductDTOS);
|
|
|
|
|
-
|
|
|
|
|
return orderDetailBean;
|
|
return orderDetailBean;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -990,17 +900,24 @@ public class OrderLogic {
|
|
|
* @throws RemoteServiceException
|
|
* @throws RemoteServiceException
|
|
|
* @throws InterruptedException
|
|
* @throws InterruptedException
|
|
|
*/
|
|
*/
|
|
|
- private GoodsSpec stock(String goodsSpecId, String goodsName, Integer num) throws RemoteServiceException, InterruptedException {
|
|
|
|
|
|
|
+ private GoodsSpec stock(String goodsSpecId, String goodsName, Integer num, String storageId) throws RemoteServiceException, InterruptedException {
|
|
|
Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_ORDER_STOCK +":"+ goodsSpecId);
|
|
Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_ORDER_STOCK +":"+ goodsSpecId);
|
|
|
try {
|
|
try {
|
|
|
if (!obtain.tryLock(10, TimeUnit.SECONDS)) {
|
|
if (!obtain.tryLock(10, TimeUnit.SECONDS)) {
|
|
|
throw new RemoteServiceException("系统繁忙,请稍后再试");
|
|
throw new RemoteServiceException("系统繁忙,请稍后再试");
|
|
|
}
|
|
}
|
|
|
GoodsSpec goodsSpec = goodsLogic.getGoodsSpecById(goodsSpecId);
|
|
GoodsSpec goodsSpec = goodsLogic.getGoodsSpecById(goodsSpecId);
|
|
|
- if (goodsSpec.getStockNum() < num) {
|
|
|
|
|
- throw new RemoteServiceException(1100,goodsName+"库存不足");
|
|
|
|
|
|
|
+ final GoodsMaterialStorage storage = goodsMaterialStorageService.lambdaQuery()
|
|
|
|
|
+ .eq(GoodsMaterialStorage::getGoodsMaterialId, goodsSpec.getGoodsCode())
|
|
|
|
|
+ .eq(GoodsMaterialStorage::getStorageId, storageId)
|
|
|
|
|
+ .one();
|
|
|
|
|
+// if (goodsSpec.getStockNum() < num) {
|
|
|
|
|
+// throw new RemoteServiceException(1100,goodsName+"库存不足");
|
|
|
|
|
+// }
|
|
|
|
|
+ if (Objects.isNull(storage) || storage.getStockQty() < num) {
|
|
|
|
|
+ throw new RemoteServiceException(1100, goodsName+"库存不足");
|
|
|
}
|
|
}
|
|
|
- goodsSpec.setStockNum(goodsSpec.getStockNum() - num);
|
|
|
|
|
|
|
+// goodsSpec.setStockNum(goodsSpec.getStockNum() - num);
|
|
|
goodsSpec.setSoldNum(goodsSpec.getSoldNum() + num);
|
|
goodsSpec.setSoldNum(goodsSpec.getSoldNum() + num);
|
|
|
goodsSpec.updateById();
|
|
goodsSpec.updateById();
|
|
|
|
|
|
|
@@ -1091,8 +1008,6 @@ public class OrderLogic {
|
|
|
BigDecimal totalAmount = new BigDecimal(0);
|
|
BigDecimal totalAmount = new BigDecimal(0);
|
|
|
//总的商品数量
|
|
//总的商品数量
|
|
|
Integer totalNum = 0;
|
|
Integer totalNum = 0;
|
|
|
- //满件打折金额
|
|
|
|
|
- BigDecimal promotionFullPieceDiscountAmount = BigDecimal.valueOf(0);
|
|
|
|
|
|
|
|
|
|
OrderAckBean orderAckBean = new OrderAckBean();
|
|
OrderAckBean orderAckBean = new OrderAckBean();
|
|
|
orderAckBean.setDiscountAmount(BigDecimal.valueOf(0));
|
|
orderAckBean.setDiscountAmount(BigDecimal.valueOf(0));
|
|
@@ -1101,11 +1016,23 @@ public class OrderLogic {
|
|
|
//填充必要参数
|
|
//填充必要参数
|
|
|
List<BuyGood> buyGoods = this.supplyBuyBoods(orderBuyBean,user);
|
|
List<BuyGood> buyGoods = this.supplyBuyBoods(orderBuyBean,user);
|
|
|
|
|
|
|
|
|
|
+ final Map<String, Integer> storageMap = goodsMaterialStorageService.lambdaQuery()
|
|
|
|
|
+ .eq(GoodsMaterialStorage::getStorageId, orderBuyBean.getStorageId())
|
|
|
|
|
+ .in(GoodsMaterialStorage::getGoodsMaterialId, buyGoods.stream().map(v -> v.getGoodsSpec().getGoodsCode()).collect(Collectors.toList()))
|
|
|
|
|
+ .list()
|
|
|
|
|
+ .stream()
|
|
|
|
|
+ .collect(Collectors.toMap(GoodsMaterialStorage::getGoodsMaterialId, GoodsMaterialStorage::getStockQty));
|
|
|
|
|
+
|
|
|
for (BuyGood buyGood : buyGoods) {
|
|
for (BuyGood buyGood : buyGoods) {
|
|
|
|
|
|
|
|
Goods goods = buyGood.getGoods();
|
|
Goods goods = buyGood.getGoods();
|
|
|
GoodsSpec goodsSpec = buyGood.getGoodsSpec();
|
|
GoodsSpec goodsSpec = buyGood.getGoodsSpec();
|
|
|
|
|
|
|
|
|
|
+ final Integer stockQty = storageMap.get(goodsSpec.getGoodsCode());
|
|
|
|
|
+ if (Objects.isNull(stockQty) || stockQty <= 0) {
|
|
|
|
|
+ throw new RemoteServiceException(goods.getGoodsName() + "商品" + goodsSpec.getSpecValue() + "规格不存在,请重新添加");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
//总购买数量
|
|
//总购买数量
|
|
|
totalNum += buyGood.getNum();
|
|
totalNum += buyGood.getNum();
|
|
|
|
|
|
|
@@ -1126,9 +1053,6 @@ public class OrderLogic {
|
|
|
//检查优惠券的使用合法性(团购和礼品卡和兑换码不可使用)
|
|
//检查优惠券的使用合法性(团购和礼品卡和兑换码不可使用)
|
|
|
List<String> goodsIds = buyGoods.stream().map(BuyGood::getGoodsId).collect(Collectors.toList());
|
|
List<String> goodsIds = buyGoods.stream().map(BuyGood::getGoodsId).collect(Collectors.toList());
|
|
|
UserCouponBean userCoupon = couponLogic.check(orderBuyBean.getUserCouponId(), totalAmount, goodsIds,false);
|
|
UserCouponBean userCoupon = couponLogic.check(orderBuyBean.getUserCouponId(), totalAmount, goodsIds,false);
|
|
|
- if (userCoupon != null && this.checkPackageUseCoupon(orderBuyBean.getGoodsPackageId(),userCoupon)) {
|
|
|
|
|
- orderAckBean.setExchangeAmount(userCoupon.getCouponValue());
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
if(orderAckBean.getExchangeAmount() == null){
|
|
if(orderAckBean.getExchangeAmount() == null){
|
|
|
orderAckBean.setExchangeAmount(BigDecimal.valueOf(0));
|
|
orderAckBean.setExchangeAmount(BigDecimal.valueOf(0));
|