|
@@ -1,33 +1,43 @@
|
|
|
package com.gree.mall.contest.logic.order;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
import com.gree.mall.contest.bean.ExcelData;
|
|
|
import com.gree.mall.contest.bean.admin.AdminUserCom;
|
|
|
-import com.gree.mall.contest.bean.order.BatchRemarkBean;
|
|
|
-import com.gree.mall.contest.bean.order.DeliverGoodsBean;
|
|
|
-import com.gree.mall.contest.bean.order.OrderDetailBean;
|
|
|
-import com.gree.mall.contest.bean.order.OrderDetailListBean;
|
|
|
+import com.gree.mall.contest.bean.coupon.UserCouponBean;
|
|
|
+import com.gree.mall.contest.bean.goods.AckGoodsBean;
|
|
|
+import com.gree.mall.contest.bean.order.*;
|
|
|
+import com.gree.mall.contest.bean.pay.PayDetail;
|
|
|
+import com.gree.mall.contest.bean.user.CurrentCompanyWechat;
|
|
|
+import com.gree.mall.contest.commonmapper.AppMapper;
|
|
|
import com.gree.mall.contest.commonmapper.CoustomUserCouponMapper;
|
|
|
import com.gree.mall.contest.commonmapper.CustomWebsitMapper;
|
|
|
import com.gree.mall.contest.commonmapper.OrderMapper;
|
|
|
import com.gree.mall.contest.constant.Constant;
|
|
|
-import com.gree.mall.contest.enums.OrderShareStatusEnum;
|
|
|
-import com.gree.mall.contest.enums.OrderStatusEnum;
|
|
|
-import com.gree.mall.contest.enums.RefundFlagEnum;
|
|
|
+import com.gree.mall.contest.enums.*;
|
|
|
+import com.gree.mall.contest.enums.coupon.CouponTypeEnum;
|
|
|
import com.gree.mall.contest.exception.RemoteServiceException;
|
|
|
import com.gree.mall.contest.logic.ExpressLogic;
|
|
|
+import com.gree.mall.contest.logic.FreightLogic;
|
|
|
import com.gree.mall.contest.logic.StorageLogic;
|
|
|
+import com.gree.mall.contest.logic.activity.PromotionGroupLogic;
|
|
|
import com.gree.mall.contest.logic.common.CommonLogic;
|
|
|
import com.gree.mall.contest.logic.common.WechatLogic;
|
|
|
+import com.gree.mall.contest.logic.coupon.CouponLogic;
|
|
|
+import com.gree.mall.contest.logic.goods.GoodsLogic;
|
|
|
+import com.gree.mall.contest.logic.pay.PayLogic;
|
|
|
import com.gree.mall.contest.logic.user.MsgSubscriptLogic;
|
|
|
import com.gree.mall.contest.logic.user.UserLogic;
|
|
|
import com.gree.mall.contest.plus.entity.*;
|
|
|
import com.gree.mall.contest.plus.service.*;
|
|
|
import com.gree.mall.contest.utils.ArithUtils;
|
|
|
+import com.gree.mall.contest.utils.CommonUtils;
|
|
|
+import com.gree.mall.contest.utils.IpUtil;
|
|
|
import com.gree.mall.contest.utils.excel.ExcelUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -43,10 +53,12 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.locks.Lock;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@@ -78,6 +90,21 @@ public class OrderLogic {
|
|
|
private final OrderMapper orderMapper;
|
|
|
private final ExpressLogic expressLogic;
|
|
|
private final AdminCompanyWechatService adminCompanyWechatService;
|
|
|
+ private final FreightLogic freightLogic;
|
|
|
+ private final GoodsPackagePopService goodsPackagePopService;
|
|
|
+ private final CouponLogic couponLogic;
|
|
|
+ private final GoodsLogic goodsLogic;
|
|
|
+ private final PromotionDiscountService promotionDiscountService;
|
|
|
+ private final GoodsPackageUserRelaService goodsPackageUserRelaService;
|
|
|
+ private final GiftExchangeCodeService giftExchangeCodeService;
|
|
|
+ private final PromotionGroupSpecUserService promotionGroupSpecUserService;
|
|
|
+ private final PromotionGroupLogic promotionGroupLogic;
|
|
|
+ private final UserAddressService userAddressService;
|
|
|
+ private final GoodsCategoryService goodsCategoryService;
|
|
|
+ private final ShoppingCartService shoppingCartService;
|
|
|
+ private final PayLogic payLogic;
|
|
|
+ private final AppMapper appMapper;
|
|
|
+ private final AdminWebsitService adminWebsitService;
|
|
|
|
|
|
/**
|
|
|
* 订单列表
|
|
@@ -199,18 +226,57 @@ public class OrderLogic {
|
|
|
if (!orderInfo.getOrderStatus().equals(OrderStatusEnum.NOPAY.toString())) {
|
|
|
throw new RemoteServiceException("订单已支付,不可取消");
|
|
|
}
|
|
|
-// if(!orderInfo.getOrderStatus().equals(OrderStatusEnum.NOPAY.toString())) {
|
|
|
-//
|
|
|
-// log.info("【退款开始:】退款金额{}", orderInfo.getPayAmount().doubleValue());
|
|
|
-// wechatLogic.refund(orderInfo.getOrderId(), orderInfo.getOrderId()+"T", orderInfo.getPayAmount().doubleValue()
|
|
|
-// , orderInfo.getPayAmount().doubleValue());
|
|
|
-//
|
|
|
-// orderShareLogic.reloadAmount(orderId, null);
|
|
|
-// }
|
|
|
+
|
|
|
this.updateOrderStatus(orderId, OrderStatusEnum.CLOSE.toString());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 取消订单
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public void cancel(List<String> orderIds) throws RemoteServiceException {
|
|
|
+ List<OrderInfo> list = orderInfoService.lambdaQuery().in(OrderInfo::getOrderId, orderIds).list();
|
|
|
+ List<String> userCouponIds = list.stream().map(OrderInfo::getUserCouponId).collect(Collectors.toList());
|
|
|
+ //1.取消订单
|
|
|
+ orderInfoService.lambdaUpdate()
|
|
|
+ .set(OrderInfo::getOrderStatus, OrderStatusEnum.TIMEOUT.toString())
|
|
|
+ .in(OrderInfo::getOrderId, orderIds).update();
|
|
|
+
|
|
|
+ //2.恢复商品规格库存
|
|
|
+ List<OrderDetail> orderDetails = orderDetailService.lambdaQuery().in(OrderDetail::getOrderId, orderIds).list();
|
|
|
+ for (OrderDetail orderDetail : orderDetails) {
|
|
|
+ //非秒杀订单 还原库存
|
|
|
+ this.recoveryStock(orderDetail.getGoodsSpecId(), orderDetail.getNum());
|
|
|
+ }
|
|
|
+ //3.恢复优惠券的使用状态
|
|
|
+ if (CollectionUtil.isEmpty(userCouponIds)) {
|
|
|
+ couponLogic.updateStatus(userCouponIds);
|
|
|
+ }
|
|
|
+ //4.恢复礼品兑换码
|
|
|
+ for (OrderInfo orderInfo : list) {
|
|
|
+ String exchangeCode = orderInfo.getExchangeCode();
|
|
|
+ if (StringUtils.isNotEmpty(orderInfo.getExchangeCode())) {
|
|
|
+ Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_GIFT + ":" + orderInfo.getExchangeCode());
|
|
|
+ try {
|
|
|
+ if (!obtain.tryLock(5, TimeUnit.SECONDS)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ giftExchangeCodeService.lambdaUpdate()
|
|
|
+ .set(GiftExchangeCode::getStatus, 0)
|
|
|
+ .eq(GiftExchangeCode::getId, exchangeCode)
|
|
|
+ .update();
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ log.error("订单超时取消,恢复兑换码失败。orderId:{}", orderInfo.getOrderId());
|
|
|
+ } finally {
|
|
|
+ obtain.unlock();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 确定收款
|
|
|
*/
|
|
|
public void ackPay(String orderId) {
|
|
@@ -916,11 +982,11 @@ public class OrderLogic {
|
|
|
/**
|
|
|
* 修改物流单号
|
|
|
*/
|
|
|
- public void updateExpress(String orderId,String logisticsNo,String companyCode) throws RemoteServiceException {
|
|
|
+ public void updateExpress(String orderId, String logisticsNo, String companyCode) throws RemoteServiceException {
|
|
|
//查询物流公司
|
|
|
String company = expressLogic.expressCompanyName(companyCode);
|
|
|
OrderInfo orderInfo = orderInfoService.getById(orderId);
|
|
|
- if(!orderInfo.getOrderStatus().equals(OrderStatusEnum.YFH.toString())){
|
|
|
+ if (!orderInfo.getOrderStatus().equals(OrderStatusEnum.YFH.toString())) {
|
|
|
throw new RemoteServiceException("非已发货订单不可修改物流单号");
|
|
|
}
|
|
|
orderInfo.setCompanyCode(companyCode);
|
|
@@ -932,12 +998,1430 @@ public class OrderLogic {
|
|
|
/**
|
|
|
* 查看物流
|
|
|
*/
|
|
|
- public List<ExpressInfo> queryExpressInfo(String logisticsNo){
|
|
|
+ public List<ExpressInfo> queryExpressInfo(String logisticsNo) {
|
|
|
List<ExpressInfo> list = expressInfoService.lambdaQuery().eq(ExpressInfo::getLogisticsNo, logisticsNo).list();
|
|
|
- if (CollectionUtil.isNotEmpty(list)){
|
|
|
+ if (CollectionUtil.isNotEmpty(list)) {
|
|
|
return list;
|
|
|
}
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 确认订单内容
|
|
|
+ */
|
|
|
+ public OrderAckBean ackOrder(OrderBuyBean orderBuyBean, HttpServletRequest request) throws InterruptedException {
|
|
|
+ OrderAckBean orderAckBean = this.ackOrder2(orderBuyBean, request);
|
|
|
+
|
|
|
+ //运费
|
|
|
+ BigDecimal freightAmountV2 = freightLogic.getFreightAmountV2(orderBuyBean, request);
|
|
|
+
|
|
|
+ orderAckBean.setFreight(freightAmountV2);
|
|
|
+ orderAckBean.setTotalAmount(orderAckBean.getTotalAmount());
|
|
|
+ //实际支付金额
|
|
|
+ BigDecimal payAmount = orderAckBean.getTotalAmount()
|
|
|
+ .subtract(orderAckBean.getExchangeAmount())
|
|
|
+ .subtract(orderAckBean.getDiscountAmount())
|
|
|
+ .add(orderAckBean.getFreight());
|
|
|
+ if (payAmount.doubleValue() <= 0) {
|
|
|
+ payAmount = BigDecimal.valueOf(0);
|
|
|
+ }
|
|
|
+ orderAckBean.setPayAmount(payAmount);
|
|
|
+ return orderAckBean;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 确认订单内容
|
|
|
+ */
|
|
|
+ public OrderAckBean ackOrder2(OrderBuyBean orderBuyBean, HttpServletRequest request) throws RemoteServiceException, InterruptedException {
|
|
|
+
|
|
|
+ //是否有礼品卡兑换码
|
|
|
+ Boolean hasGiftCode = false;
|
|
|
+ //是否为团购活动
|
|
|
+ Boolean isPromotionGroup = false; //是否为套购商品
|
|
|
+ Boolean isGoodsPackage = StringUtils.isNotEmpty(orderBuyBean.getGoodsPackageId());
|
|
|
+
|
|
|
+ //购买人
|
|
|
+ String userId = CommonUtils.getUserId(request);
|
|
|
+ User user = userService.getById(userId);
|
|
|
+ //兑换码
|
|
|
+ String exchangeCode = orderBuyBean.getExchangeCode();
|
|
|
+ //非团购商品的分佣金额
|
|
|
+ BigDecimal notPromotionShareAmount = BigDecimal.valueOf(0);
|
|
|
+ //总的商品金额
|
|
|
+ BigDecimal totalAmount = new BigDecimal(0);
|
|
|
+ //总的商品数量
|
|
|
+ Integer totalNum = 0;
|
|
|
+
|
|
|
+ OrderAckBean orderAckBean = new OrderAckBean();
|
|
|
+ orderAckBean.setDiscountAmount(BigDecimal.valueOf(0));
|
|
|
+ orderAckBean.setOpenId(user.getOpenId());
|
|
|
+ List<AckGoodsBean> list = new ArrayList<>();
|
|
|
+ //业务员
|
|
|
+ User service = user.getType().equals(UserTypeEnum.SERVICE.toString()) ? user : null;
|
|
|
+ if (service == null) {
|
|
|
+ service = userService.getById(user.getServiceId());
|
|
|
+ }
|
|
|
+ //填充必要参数
|
|
|
+ List<BuyGood> buyGoods = this.supplyBuyBoods(orderBuyBean, user);
|
|
|
+ boolean isRecordBuyer = false;
|
|
|
+ for (BuyGood buyGood : buyGoods) {
|
|
|
+
|
|
|
+ Goods goods = buyGood.getGoods();
|
|
|
+ GoodsSpec goodsSpec = buyGood.getGoodsSpec();
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(goods.getUmsDiscountCode()) && StringUtils.isNotBlank(goodsSpec.getBarCode())) {
|
|
|
+ isRecordBuyer = true;
|
|
|
+ }
|
|
|
+ //礼品卡商品处理
|
|
|
+ Boolean isGift = this.giftGoods(user.getUserId(), orderBuyBean.getExchangeCode(), false, goods, goodsSpec, buyGood.getNum());
|
|
|
+
|
|
|
+ //总购买数量
|
|
|
+ totalNum += buyGood.getNum();
|
|
|
+
|
|
|
+ AckGoodsBean ackGoodsBean = new AckGoodsBean();
|
|
|
+ BeanUtils.copyProperties(goods, ackGoodsBean);
|
|
|
+ ackGoodsBean.setSpecImgUrl(goodsSpec.getImgUrl());
|
|
|
+ ackGoodsBean.setSpecValue(goodsSpec.getSpecValue());
|
|
|
+ ackGoodsBean.setNum(buyGood.getNum());
|
|
|
+ ackGoodsBean.setPrice(buyGood.getPrice());
|
|
|
+ ackGoodsBean.setOrgPrice(goods.getOrgGoodsPrice());
|
|
|
+ ackGoodsBean.setSecKillId(buyGood.getSecKillId());
|
|
|
+ ackGoodsBean.setPromotionGroupId(buyGood.getPromotionGroupId());
|
|
|
+ if (isGift) {
|
|
|
+ //ackGoodsBean.setPrice(goodsSpec.getPrice());
|
|
|
+ ackGoodsBean.setIsGift(true);
|
|
|
+ hasGiftCode = true;
|
|
|
+
|
|
|
+ //商品需要支付的金额(累加小计金额)
|
|
|
+ totalAmount = totalAmount.add(this.getChildTotalPrice(ackGoodsBean, goodsSpec.getPrice()));
|
|
|
+ } else {
|
|
|
+ //商品需要支付的金额(累加小计金额)
|
|
|
+ totalAmount = totalAmount.add(this.getChildTotalPrice(ackGoodsBean));
|
|
|
+ }
|
|
|
+
|
|
|
+ //普通商品佣金
|
|
|
+ BigDecimal shareAmount = buyGood.getShareAmount();
|
|
|
+ //内部人员佣金
|
|
|
+ if (service != null && service.getType().equals(UserTypeEnum.SERVICE.toString()) && service.getInnerr()) {
|
|
|
+ shareAmount = goodsSpec.getInnerShareAmount();
|
|
|
+ }
|
|
|
+ //非团购商品的分佣金额
|
|
|
+ if (!buyGood.getIsPromotionGroup()) {
|
|
|
+ notPromotionShareAmount = notPromotionShareAmount.add(shareAmount.multiply(BigDecimal.valueOf(ackGoodsBean.getNum())));
|
|
|
+ }
|
|
|
+ if (buyGood.getIsPromotionGroup() && !isGoodsPackage)
|
|
|
+ isPromotionGroup = true;
|
|
|
+
|
|
|
+ list.add(ackGoodsBean);
|
|
|
+ }
|
|
|
+ //检查优惠券的使用合法性(团购和礼品卡和兑换码不可使用)
|
|
|
+ if (!isPromotionGroup && !hasGiftCode) {
|
|
|
+ List<String> goodsIds = buyGoods.stream().map(BuyGood::getGoodsId).collect(Collectors.toList());
|
|
|
+ UserCouponBean userCoupon = couponLogic.check(orderBuyBean.getUserCouponId(), totalAmount, goodsIds, false);
|
|
|
+ if (userCoupon != null && this.checkPackageUseCoupon(orderBuyBean.getGoodsPackageId(), userCoupon)) {
|
|
|
+ orderAckBean.setExchangeAmount(userCoupon.getCouponValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //优惠码的金额
|
|
|
+ if (!hasGiftCode && !isGoodsPackage) {
|
|
|
+ //兑换码商品(此处会重置规格的价格)
|
|
|
+ BigDecimal subAmount = this.subGoods(userId, exchangeCode, false, notPromotionShareAmount, null);
|
|
|
+ if (subAmount != null && subAmount.doubleValue() > 0) {
|
|
|
+ orderAckBean.setExchangeAmount(subAmount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (orderAckBean.getExchangeAmount() == null) {
|
|
|
+ orderAckBean.setExchangeAmount(BigDecimal.valueOf(0));
|
|
|
+ }
|
|
|
+ //计算折扣活动的金额(任何活动商品都可以参与,允许与优惠券/兑换码同用)-------------start
|
|
|
+ //1.订单商品的实际支付金额
|
|
|
+ BigDecimal payAmount = totalAmount.subtract(orderAckBean.getExchangeAmount());
|
|
|
+ //2.折扣活动 需要扣减的金额
|
|
|
+ if (!isGoodsPackage) {
|
|
|
+ PromotionDiscountBean promotionDiscountBean = this.discountPromotion(buyGoods, payAmount);
|
|
|
+ if (promotionDiscountBean != null) {
|
|
|
+ orderAckBean.setDiscountAmount(promotionDiscountBean.getSubDiscountAmount());
|
|
|
+ orderAckBean.setPromotionDiscountRate(promotionDiscountBean.getDiscountRate());
|
|
|
+ } else {
|
|
|
+ if (orderAckBean.getDiscountAmount() == null) {
|
|
|
+ orderAckBean.setDiscountAmount(BigDecimal.valueOf(0));
|
|
|
+ }
|
|
|
+ orderAckBean.setPromotionDiscountRate(BigDecimal.valueOf(0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //计算折扣活动的金额(任何活动商品都可以参与,允许与优惠券/兑换码同用)-------------end
|
|
|
+ orderAckBean.setGoods(list);
|
|
|
+ orderAckBean.setTotalAmount(totalAmount);
|
|
|
+ orderAckBean.setTotalNum(totalNum);
|
|
|
+ orderAckBean.setIsRecordBuyer(isRecordBuyer);
|
|
|
+ return orderAckBean;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 折扣活动处理
|
|
|
+ *
|
|
|
+ * @param buyGoods 购买的商品
|
|
|
+ * @param payAmount 实际支付的金额
|
|
|
+ */
|
|
|
+ private PromotionDiscountBean discountPromotion(List<BuyGood> buyGoods, BigDecimal payAmount) {
|
|
|
+
|
|
|
+ List<String> promotionIds = buyGoods.stream().filter(v -> StringUtils.isNotEmpty(v.getPromotionGroupId()))
|
|
|
+ .map(BuyGood::getPromotionGroupId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ //全团购商品
|
|
|
+ Boolean allPromotionGroup = CollectionUtil.isNotEmpty(promotionIds) && promotionIds.size() == buyGoods.size();
|
|
|
+
|
|
|
+ BigDecimal discountAmount;
|
|
|
+ //1.判断是否达到折扣条件
|
|
|
+ List<PromotionDiscount> list = promotionDiscountService.lambdaQuery()
|
|
|
+ .ge(PromotionDiscount::getLimitUpperAmount, payAmount)
|
|
|
+ .le(PromotionDiscount::getLimitLowerAmount, payAmount)
|
|
|
+ .eq(PromotionDiscount::getStatus, true)
|
|
|
+ .in(allPromotionGroup, PromotionDiscount::getPromotionGroupId, promotionIds)
|
|
|
+ .eq(allPromotionGroup, PromotionDiscount::getType, 2)
|
|
|
+ .eq(!allPromotionGroup, PromotionDiscount::getType, 1)
|
|
|
+ .orderByAsc(PromotionDiscount::getDiscountRate)
|
|
|
+ .list();
|
|
|
+ if (CollectionUtil.isEmpty(list)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ PromotionDiscount promotionDiscount = list.get(0);
|
|
|
+ //2.判断是否有非该团购活动之外的商品
|
|
|
+ long count = buyGoods.stream().filter(v -> !StringUtils.equals(v.getPromotionGroupId(), promotionDiscount.getPromotionGroupId())).count();
|
|
|
+ if (count > 0) {
|
|
|
+ throw new RemoteServiceException("检测到有非折扣商品,请联系相关人员");
|
|
|
+ }
|
|
|
+ BigDecimal subRate = BigDecimal.valueOf(1).subtract(promotionDiscount.getDiscountRate());
|
|
|
+ //实际折扣扣减的金额
|
|
|
+ discountAmount = payAmount.multiply(subRate).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+
|
|
|
+ PromotionDiscountBean bean = new PromotionDiscountBean();
|
|
|
+ BeanUtils.copyProperties(promotionDiscount, bean);
|
|
|
+ bean.setSubDiscountAmount(discountAmount);
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 整理 购买商品 的必要参数
|
|
|
+ *
|
|
|
+ * @param orderBuyBean
|
|
|
+ * @param user
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<BuyGood> supplyBuyBoods(OrderBuyBean orderBuyBean, User user) throws InterruptedException {
|
|
|
+ String goodsPackageId = orderBuyBean.getGoodsPackageId();
|
|
|
+
|
|
|
+ List<BuyGood> buyGoods = orderBuyBean.getBuyGoods();
|
|
|
+ //套购商品
|
|
|
+ Boolean isGoodsPackage = false;
|
|
|
+ if (StringUtils.isNotEmpty(goodsPackageId)) {
|
|
|
+ Goods goodsPackage = goodsLogic.getGoodsById(goodsPackageId);
|
|
|
+ if (goodsPackage != null) {
|
|
|
+ //套购商品检查
|
|
|
+ this.checkPackageGoods(buyGoods, user, goodsPackage);
|
|
|
+ //是否为套购商品
|
|
|
+ isGoodsPackage = StringUtils.equals(goodsPackage.getGoodsType(), GoodsTypeEnum.PACKAGE.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (BuyGood buyGood : buyGoods) {
|
|
|
+ //String promotionGroupId = buyGood.getPromotionGroupId();
|
|
|
+ Goods goods = goodsLogic.getGoodsById(buyGood.getGoodsId());
|
|
|
+ GoodsSpec goodsSpec = goodsLogic.getGoodsSpecById(buyGood.getGoodsSpecId());
|
|
|
+ if (goods == null || goodsSpec == null) {
|
|
|
+ throw new RemoteServiceException("商品不存在,请重新添加");
|
|
|
+ }
|
|
|
+ buyGood.setGoods(goods);
|
|
|
+ buyGood.setGoodsSpec(goodsSpec);
|
|
|
+
|
|
|
+ //非套购商品
|
|
|
+ if (!isGoodsPackage) {
|
|
|
+
|
|
|
+ buyGood.setOrgPrice(goodsSpec.getOrgPrice());
|
|
|
+ buyGood.setPrice(goodsSpec.getPrice());
|
|
|
+ buyGood.setShareAmount(goodsSpec.getShareAmount());
|
|
|
+ //团购活动
|
|
|
+ this.groupPromotion(buyGood, goodsSpec, user);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ //套购商品
|
|
|
+ GoodsPackagePop goodsPackagePop = goodsPackagePopService.lambdaQuery()
|
|
|
+ .eq(GoodsPackagePop::getGoodsPackageId, goodsPackageId)
|
|
|
+ .eq(GoodsPackagePop::getGoodsSpecId, buyGood.getGoodsSpecId()).one();
|
|
|
+ buyGood.setOrgPrice(goodsSpec.getOrgPrice());
|
|
|
+ buyGood.setPrice(goodsPackagePop.getPrice());
|
|
|
+ buyGood.setShareAmount(goodsPackagePop.getShareRate().multiply(buyGood.getPrice()));
|
|
|
+ buyGood.setIsGoodsPackage(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return buyGoods;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 团购活动
|
|
|
+ *
|
|
|
+ * @param buyGood
|
|
|
+ * @param goodsSpec
|
|
|
+ */
|
|
|
+ private void groupPromotion(BuyGood buyGood, GoodsSpec goodsSpec, User user) {
|
|
|
+ String promotionGroupUserId = user.getPromotionGroupUserId();
|
|
|
+ if (user.getPromotionGroupLeader()) {
|
|
|
+ promotionGroupUserId = user.getUserId();
|
|
|
+ }
|
|
|
+
|
|
|
+ PromotionGroupSpecUser promotionGroupSpecUser = promotionGroupSpecUserService.lambdaQuery()
|
|
|
+ .eq(PromotionGroupSpecUser::getGoodsSpecId, goodsSpec.getGoodsSpecId())
|
|
|
+ .eq(PromotionGroupSpecUser::getUserId, promotionGroupUserId)
|
|
|
+ .ge(PromotionGroupSpecUser::getEndTime, new Date())
|
|
|
+ .le(PromotionGroupSpecUser::getStartTime, new Date())
|
|
|
+ .one();
|
|
|
+ if (promotionGroupSpecUser == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (promotionGroupLogic.checkPromotionGroup(promotionGroupSpecUser.getPromotionGroupId())) {
|
|
|
+ buyGood.setPrice(promotionGroupSpecUser.getGroupPrice());
|
|
|
+ buyGood.setShareAmount(promotionGroupSpecUser.getShareAmount());
|
|
|
+ buyGood.setOrgPrice(promotionGroupSpecUser.getOrgGoodsPrice());
|
|
|
+ buyGood.setPromotionImgUrl(promotionGroupSpecUser.getGoodsImgSrc());
|
|
|
+ buyGood.setIsPromotionGroup(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 礼品卡商品
|
|
|
+ */
|
|
|
+ private Boolean giftGoods(String userId, String exchangeCode, Boolean order, Goods goods, GoodsSpec goodsSpec, int num) throws RemoteServiceException, InterruptedException {
|
|
|
+ if (StringUtils.isEmpty(exchangeCode)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_GIFT + ":" + exchangeCode);
|
|
|
+ if (!obtain.tryLock(5, TimeUnit.SECONDS)) {
|
|
|
+ throw new RemoteServiceException("系统繁忙,请稍后再试");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ GiftExchangeCode giftExchangeCode = giftExchangeCodeService.getById(exchangeCode);
|
|
|
+ if (giftExchangeCode == null)
|
|
|
+ return false;
|
|
|
+ User user = userService.getById(userId);
|
|
|
+ if (user.getExchangeNum() > 10) {
|
|
|
+ throw new RemoteServiceException(1100, "该用户已被禁用兑换码");
|
|
|
+ }
|
|
|
+ if (giftExchangeCode.getType().equals(ExchangeCodeTypeEnum.GIFT.toString())) {
|
|
|
+ //礼品兑换码
|
|
|
+ if (goods == null || goodsSpec == null) {
|
|
|
+ throw new RemoteServiceException("商品不存在");
|
|
|
+ }
|
|
|
+ BigDecimal amount = this.giftExchangeCodeGoods(giftExchangeCode, goods.getGoodsId(), user, num, order);
|
|
|
+ goodsSpec.setPrice(amount);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ obtain.unlock();
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 抵扣兑换码商品
|
|
|
+ */
|
|
|
+ private BigDecimal subGoods(String userId, String exchangeCode, Boolean order, BigDecimal totalShareAmount, String orderId) throws RemoteServiceException, InterruptedException {
|
|
|
+ if (StringUtils.isEmpty(exchangeCode)) {
|
|
|
+ return BigDecimal.valueOf(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_GIFT + ":" + exchangeCode);
|
|
|
+ if (!obtain.tryLock(5, TimeUnit.SECONDS)) {
|
|
|
+ throw new RemoteServiceException("系统繁忙,请稍后再试");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ GiftExchangeCode giftExchangeCode = giftExchangeCodeService.getById(exchangeCode);
|
|
|
+ if (giftExchangeCode == null)
|
|
|
+ return BigDecimal.valueOf(0);
|
|
|
+ User user = userService.getById(userId);
|
|
|
+ if (user.getExchangeNum() > 10) {
|
|
|
+ throw new RemoteServiceException(1100, "该用户已被禁用兑换码");
|
|
|
+ }
|
|
|
+ if (giftExchangeCode.getType().equals(ExchangeCodeTypeEnum.SUB.toString()) && totalShareAmount != null) {
|
|
|
+ //金额抵扣码
|
|
|
+ return this.subExchangeCodeGoods(giftExchangeCode, user, order, totalShareAmount, orderId);
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ obtain.unlock();
|
|
|
+ }
|
|
|
+ return BigDecimal.valueOf(0);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 礼品卡兑换码
|
|
|
+ */
|
|
|
+ private BigDecimal giftExchangeCodeGoods(GiftExchangeCode giftExchangeCode, String goodsId, User user, Integer num, Boolean order) {
|
|
|
+ if (giftExchangeCode == null || giftExchangeCode.getStatus() == 1 || giftExchangeCode.getStartTime().getTime() > new Date().getTime()
|
|
|
+ || giftExchangeCode.getEndTime().getTime() < new Date().getTime() || !giftExchangeCode.getGoodsId().equals(goodsId)) {
|
|
|
+ user.setExchangeNum(user.getExchangeNum() + 1);
|
|
|
+ user.updateById();
|
|
|
+ throw new RemoteServiceException(1100, "兑换码无效");
|
|
|
+ }
|
|
|
+ if (num > 1)
|
|
|
+ throw new RemoteServiceException(1100, "该兑换码只支持购买1个商品");
|
|
|
+ //生成订单需要核销
|
|
|
+ if (order) {
|
|
|
+ //分享人id
|
|
|
+// String userId = giftExchangeCode.getUserId();
|
|
|
+// User service = userService.getById(userId);
|
|
|
+// if(service != null) {
|
|
|
+// giftExchangeCode.setNickName(service.getWorkName());
|
|
|
+// giftExchangeCode.setAvatar(service.getAvatar());
|
|
|
+// giftExchangeCode.setWebsitId()
|
|
|
+// }
|
|
|
+ //使用人
|
|
|
+ giftExchangeCode.setUseUserId(user.getUserId());
|
|
|
+ giftExchangeCode.setUseNickName(user.getNickName());
|
|
|
+ giftExchangeCode.setUseTime(new Date());
|
|
|
+ giftExchangeCode.setUseAvatar(user.getAvatar());
|
|
|
+ giftExchangeCode.setCompanyWechatId(user.getCompanyWechatId());
|
|
|
+ giftExchangeCode.setCompanyName(user.getCompanyName());
|
|
|
+
|
|
|
+ giftExchangeCode.setStatus(1);
|
|
|
+ giftExchangeCode.updateById();
|
|
|
+
|
|
|
+ user.setExchangeNum(0);
|
|
|
+ user.updateById();
|
|
|
+ }
|
|
|
+ return giftExchangeCode.getAmount();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 抵扣兑换码
|
|
|
+ *
|
|
|
+ * @return 可抵扣的金额
|
|
|
+ * @throws InterruptedException
|
|
|
+ */
|
|
|
+ private BigDecimal subExchangeCodeGoods(GiftExchangeCode giftExchangeCode, User user, Boolean order, BigDecimal totalShareAmount, String orderId) throws InterruptedException {
|
|
|
+ String serviceId = user.getServiceId();
|
|
|
+ if (user.getType().equals(UserTypeEnum.SERVICE.toString())) {
|
|
|
+ serviceId = user.getUserId();
|
|
|
+ }
|
|
|
+ if (giftExchangeCode == null || giftExchangeCode.getStatus() == 1 || giftExchangeCode.getStartTime().getTime() > new Date().getTime()
|
|
|
+ || giftExchangeCode.getEndTime().getTime() < new Date().getTime() || !giftExchangeCode.getUserId().equals(serviceId)) {
|
|
|
+ user.setExchangeNum(user.getExchangeNum() + 1);
|
|
|
+ user.updateById();
|
|
|
+ throw new RemoteServiceException(1100, "兑换码无效");
|
|
|
+ }
|
|
|
+ if (giftExchangeCode.getAmount().doubleValue() > totalShareAmount.doubleValue()) {
|
|
|
+ throw new RemoteServiceException(1100, "兑换码不适用目前所购买的商品");
|
|
|
+ }
|
|
|
+ //生成订单需要核销
|
|
|
+ if (order) {
|
|
|
+
|
|
|
+ //使用人
|
|
|
+ giftExchangeCode.setUseUserId(user.getUserId());
|
|
|
+ giftExchangeCode.setUseNickName(user.getNickName());
|
|
|
+ giftExchangeCode.setUseTime(new Date());
|
|
|
+ giftExchangeCode.setUseAvatar(user.getAvatar());
|
|
|
+
|
|
|
+ giftExchangeCode.setOrderId(orderId);
|
|
|
+ giftExchangeCode.setCompanyWechatId(user.getCompanyWechatId());
|
|
|
+ giftExchangeCode.setCompanyName(user.getCompanyName());
|
|
|
+ giftExchangeCode.setStatus(1);
|
|
|
+ giftExchangeCode.updateById();
|
|
|
+
|
|
|
+ user.setExchangeNum(0);
|
|
|
+ user.updateById();
|
|
|
+ }
|
|
|
+ return giftExchangeCode.getAmount();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 已开发票
|
|
|
+ */
|
|
|
+ public void tax(String orderId, String orderTaxId) {
|
|
|
+ orderInfoService.lambdaUpdate()
|
|
|
+ .set(OrderInfo::getTax, true)
|
|
|
+ .set(OrderInfo::getOrderTaxId, orderTaxId)
|
|
|
+ .eq(OrderInfo::getOrderId, orderId).update();
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取商品小计金额
|
|
|
+ private BigDecimal getChildTotalPrice(AckGoodsBean ackGoodsBean) {
|
|
|
+ return ackGoodsBean.getPrice().multiply(new BigDecimal(ackGoodsBean.getNum()));
|
|
|
+ }
|
|
|
+
|
|
|
+ private BigDecimal getChildTotalPrice(AckGoodsBean ackGoodsBean, BigDecimal price) {
|
|
|
+ return price.multiply(new BigDecimal(ackGoodsBean.getNum()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 套购--检查是否可使用优惠券
|
|
|
+ */
|
|
|
+ private Boolean checkPackageUseCoupon(String goodsPackageId, UserCoupon userCoupon) {
|
|
|
+ if (StringUtils.isEmpty(goodsPackageId)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ //使用优惠券 0=不可使用 1=所有优惠券 2=满减券 3=商品券
|
|
|
+ Goods goods = goodsLogic.getGoodsById(goodsPackageId);
|
|
|
+ if (!StringUtils.equals(goods.getGoodsType(), GoodsTypeEnum.PACKAGE.toString())) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ Integer useCoupon = goods.getUseCoupon();
|
|
|
+ if (useCoupon == 0) {
|
|
|
+ throw new RemoteServiceException("当前套购商品不可使用优惠券");
|
|
|
+ }
|
|
|
+ if (useCoupon == 2 && !userCoupon.getCouponType().equals(CouponTypeEnum.SATISFY.toString())) {
|
|
|
+ throw new RemoteServiceException("当前套购商品不可使用满减券");
|
|
|
+ }
|
|
|
+ if (useCoupon == 3 && !userCoupon.getCouponType().equals(CouponTypeEnum.GOODS.toString())) {
|
|
|
+ throw new RemoteServiceException("当前套购商品不可使用商品券");
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 套购商品
|
|
|
+ */
|
|
|
+ public void checkPackageGoods(List<BuyGood> buyGoods, User user, Goods goodsPackage) {
|
|
|
+ List<GoodsPackagePop> list = goodsPackagePopService.lambdaQuery()
|
|
|
+ .eq(GoodsPackagePop::getGoodsPackageId, goodsPackage.getGoodsId())
|
|
|
+ .orderByAsc(GoodsPackagePop::getType).list();
|
|
|
+ //判断是否都为套购内商品
|
|
|
+ Map<String, GoodsPackagePop> goodsSpecMap = list.stream().collect(Collectors.toMap(GoodsPackagePop::getGoodsSpecId, v -> v));
|
|
|
+ for (BuyGood buyGood : buyGoods) {
|
|
|
+ Goods goods = goodsLogic.getGoodsById(buyGood.getGoodsId());
|
|
|
+ GoodsSpec goodsSpec = goodsLogic.getGoodsSpecById(buyGood.getGoodsSpecId());
|
|
|
+ GoodsPackagePop goodsPackagePop = goodsSpecMap.get(buyGood.getGoodsSpecId());
|
|
|
+ if (goodsPackagePop == null) {
|
|
|
+ throw new RemoteServiceException("存在不包含当前套购的商品");
|
|
|
+ }
|
|
|
+ //检查是否超出了购买上限
|
|
|
+ if (buyGood.getNum() > goodsPackagePop.getLimitNum()) {
|
|
|
+ throw new RemoteServiceException(goods.getGoodsName() + "-" + goodsSpec.getSpecValue() + "最大支持购买" + goodsPackagePop.getLimitNum() + "个");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //检查配比是否正确
|
|
|
+ String[] splitPop = goodsPackage.getPackagePop().split(":");
|
|
|
+ this.checkPackagePop(buyGoods, splitPop);
|
|
|
+ //检查是否有权限购买
|
|
|
+ this.checkPackagePower(user, goodsPackage);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 套购--检查配比是否正确
|
|
|
+ *
|
|
|
+ * @param list
|
|
|
+ * @param splitPop 配比比例
|
|
|
+ */
|
|
|
+ private void checkPackagePop(List<BuyGood> list, String[] splitPop) {
|
|
|
+ //检查配提购买的机型是否大于等于限定机型购买的倍数,
|
|
|
+ //倍数 num = 购买的数量 / 所属比例
|
|
|
+ double num = -1;
|
|
|
+ for (int i = 1; i <= splitPop.length; i++) {
|
|
|
+ int a = i;
|
|
|
+ int rate = Integer.parseInt(splitPop[i - 1]);
|
|
|
+ int sum = list.stream().filter(v -> v.getPopType() == a).mapToInt(BuyGood::getNum).sum();
|
|
|
+ double div = sum / rate;
|
|
|
+ if (div == 0)
|
|
|
+ throw new RemoteServiceException("检查到配比不正确");
|
|
|
+
|
|
|
+ if (sum % rate != 0)
|
|
|
+ throw new RemoteServiceException("购买数量必须是套餐对应比例的整倍数");
|
|
|
+
|
|
|
+ if (num != -1 && num != div)
|
|
|
+ throw new RemoteServiceException("检查到配比不正确");
|
|
|
+
|
|
|
+ if (i == 1)
|
|
|
+ num = div;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 套购--检查是否有权限购买
|
|
|
+ */
|
|
|
+ private void checkPackagePower(User user, Goods goods) {
|
|
|
+ if (!StringUtils.equals(goods.getGoodsType(), GoodsTypeEnum.PACKAGE.toString())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 0=指定人员 1=所有人 2=普通用户 3=业务员
|
|
|
+ if (goods.getPackageUserType() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //指定人员
|
|
|
+ if (goods.getPackageUserType() == 0) {
|
|
|
+ Long count = goodsPackageUserRelaService.lambdaQuery()
|
|
|
+ .eq(GoodsPackageUserRela::getGoodsId, goods.getGoodsId()).eq(GoodsPackageUserRela::getUserId, user.getUserId()).count();
|
|
|
+ if (count > 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //所有人
|
|
|
+ if (goods.getPackageUserType() == 1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //普通用户
|
|
|
+ if (goods.getPackageUserType() == 2 && StringUtils.equals(user.getType(), UserTypeEnum.GENERAL.toString())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //业务员
|
|
|
+ if (goods.getPackageUserType() == 3 && StringUtils.equals(user.getType(), UserTypeEnum.SERVICE.toString())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ throw new RemoteServiceException("暂不可购买该商品");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 立即购买
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public PayDetail buy(OrderBuyBean orderBuyBean, HttpServletRequest request) throws Exception {
|
|
|
+ String ip = IpUtil.getIpAddr(request);
|
|
|
+ if (StringUtils.isEmpty(orderBuyBean.getUserAddressId())) {
|
|
|
+ throw new RemoteServiceException(1100, "请选择收货地址");
|
|
|
+ }
|
|
|
+ CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat(request);
|
|
|
+ //订单
|
|
|
+ OrderInfo orderInfo = new OrderInfo();
|
|
|
+ String orderId = currentCompanyWechat.getOrderPrefix() + IdWorker.getIdStr();
|
|
|
+ orderInfo.setOrderId(orderId);
|
|
|
+ orderInfo.setPayType("微信支付");
|
|
|
+ //购买人
|
|
|
+ String userId = currentCompanyWechat.getUserId();
|
|
|
+ User user = currentCompanyWechat.getUser();
|
|
|
+
|
|
|
+ //判断该手机号是否为业务员
|
|
|
+ user = userLogic.userToService(user, currentCompanyWechat);
|
|
|
+
|
|
|
+ //分销员
|
|
|
+ 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 totalFreight = BigDecimal.valueOf(0);
|
|
|
+ //订单标题
|
|
|
+ String orderTitle = "";
|
|
|
+ //分账金额
|
|
|
+ BigDecimal shareAmount = BigDecimal.valueOf(0);
|
|
|
+ //非团购商品的分账金额
|
|
|
+ BigDecimal notPromotionShareAmount = BigDecimal.valueOf(0);
|
|
|
+ //总数量
|
|
|
+ Integer totalNum = 0;
|
|
|
+ //兑换码
|
|
|
+ String exchangeCode = orderBuyBean.getExchangeCode();
|
|
|
+ //是否有使用了礼品码的商品
|
|
|
+ Boolean hasGiftCode = false;
|
|
|
+ //收获地址
|
|
|
+ UserAddress userAddress = userAddressService.getById(orderBuyBean.getUserAddressId());
|
|
|
+ //团长id
|
|
|
+ String promotionGroupUserId = "";
|
|
|
+ String orderPromotionGroupId = "";
|
|
|
+ //是否为套购商品
|
|
|
+ Boolean isGoodsPackage = StringUtils.isNotEmpty(orderBuyBean.getGoodsPackageId());
|
|
|
+ //是否有活动商品
|
|
|
+ Boolean isPromotion = false;
|
|
|
+ List<String> goodsIds = orderBuyBean.getBuyGoods().stream().map(BuyGood::getGoodsId).collect(Collectors.toList());
|
|
|
+ //购物车ids
|
|
|
+ List<String> shoppingCartIds = orderBuyBean.getBuyGoods().stream().map(BuyGood::getShoppingCartId).collect(Collectors.toList());
|
|
|
+ //如果用户存在,则判断是否为业务员,并更新相关信息
|
|
|
+ if (!user.getStatus()) {
|
|
|
+ throw new RemoteServiceException(1100, "用户已被冻结");
|
|
|
+ }
|
|
|
+
|
|
|
+ //这里面会处理各个活动对单价以及佣金金额的处理
|
|
|
+ List<BuyGood> buyGoods = this.supplyBuyBoods(orderBuyBean, user);
|
|
|
+
|
|
|
+ // 云闪付优惠码
|
|
|
+ boolean isExistCode = false;
|
|
|
+
|
|
|
+ //订单详情
|
|
|
+ List<OrderDetail> orderDetails = new ArrayList<>();
|
|
|
+ for (BuyGood buyGood : buyGoods) {
|
|
|
+ String promotionGroupId = buyGood.getPromotionGroupId();
|
|
|
+ if (StringUtils.isEmpty(orderPromotionGroupId)) {
|
|
|
+ orderPromotionGroupId = buyGood.getPromotionGroupId();
|
|
|
+ }
|
|
|
+ String secKillId = buyGood.getSecKillId();
|
|
|
+ //商品
|
|
|
+ Goods goods = buyGood.getGoods();
|
|
|
+ if (!goods.getStatus()) {
|
|
|
+ throw new RemoteServiceException("存在已下架商品:" + goods.getGoodsName());
|
|
|
+ }
|
|
|
+ //处理库存并返回商品规格
|
|
|
+ GoodsSpec goodsSpec = this.stock(buyGood.getGoodsSpecId(), goods.getGoodsName(), buyGood.getNum());
|
|
|
+ //礼品卡商品(此处会重置规格的价格)
|
|
|
+ Boolean isGift = this.giftGoods(userId, exchangeCode, true, goods, goodsSpec, buyGood.getNum());
|
|
|
+ if (!hasGiftCode)
|
|
|
+ hasGiftCode = isGift;
|
|
|
+
|
|
|
+ String goodsId = goodsSpec.getGoodsId();
|
|
|
+ String goodsSpecId = goodsSpec.getGoodsSpecId();
|
|
|
+ String goodsSpecName = goodsSpec.getName();
|
|
|
+ String goodsSpecValue = goodsSpec.getSpecValue();
|
|
|
+ String goodsName = goods.getGoodsName();
|
|
|
+ //BigDecimal goodsShareAmount = goodsSpec.getShareAmount();
|
|
|
+ //BigDecimal goodsSecPrice = goodsSpec.getPrice();
|
|
|
+ BigDecimal goodsShareAmount = buyGood.getShareAmount();
|
|
|
+ BigDecimal goodsSecPrice = buyGood.getPrice();
|
|
|
+ String catagoryId = goods.getCategoryId();
|
|
|
+ String userCouponId = orderBuyBean.getUserCouponId();
|
|
|
+ BigDecimal cutAmount = new BigDecimal("0");
|
|
|
+
|
|
|
+ //内部价格处理
|
|
|
+ if (service != null
|
|
|
+ && service.getType().equals(UserTypeEnum.SERVICE.toString())
|
|
|
+ && service.getInnerr()
|
|
|
+ && !buyGood.getIsPromotionGroup()
|
|
|
+ && !buyGood.getIsSecKill()
|
|
|
+ && !buyGood.getIsGoodsPackage()) {
|
|
|
+ goodsShareAmount = goodsSpec.getInnerShareAmount();
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("是否为礼品卡商品:{},金额:{}", isGift, goodsSecPrice);
|
|
|
+
|
|
|
+ //活动和优惠券不能一起使用
|
|
|
+ if (StringUtils.isNotEmpty(userCouponId)
|
|
|
+ // && (StringUtils.isNotEmpty(promotionGroupId) || StringUtils.isNotEmpty(secKillId) || isGift || StringUtils.isNotEmpty(exchangeCode))){
|
|
|
+ && (isGift || StringUtils.isNotEmpty(exchangeCode) || buyGood.getIsPromotionGroup())) {
|
|
|
+ throw new RemoteServiceException(1100, "活动商品不可使用优惠券");
|
|
|
+ }
|
|
|
+
|
|
|
+ OrderDetail orderDetail = new OrderDetail();
|
|
|
+ //默认的分佣人是分销员
|
|
|
+ orderDetail.setShareUserId(serviceId);
|
|
|
+ orderDetail.setUmsDiscountCode(goods.getUmsDiscountCode());
|
|
|
+ orderDetail.setBarCode(goodsSpec.getBarCode());
|
|
|
+ if (StringUtils.isNotBlank(goods.getUmsDiscountCode()) && StringUtils.isNotBlank(goodsSpec.getBarCode())) {
|
|
|
+ isExistCode = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ //团购活动
|
|
|
+ if (buyGood.getIsPromotionGroup()) {
|
|
|
+ PromotionGroupSpecUser promotionGroupSpecUser = promotionGroupLogic.getStock(user.getPromotionGroupUserId(), buyGood.getGoodsSpecId(), buyGood.getNum());
|
|
|
+ promotionGroupUserId = promotionGroupSpecUser.getUserId();
|
|
|
+ isPromotion = true;
|
|
|
+
|
|
|
+ orderDetail.setPromotionGroupId(promotionGroupId);
|
|
|
+ orderDetail.setShareUserId(promotionGroupUserId);
|
|
|
+ }
|
|
|
+
|
|
|
+ orderDetail.setOrderId(orderId);
|
|
|
+ orderDetail.setPromotionGroupId(promotionGroupId);
|
|
|
+ orderDetail.setGoodsId(goodsId);
|
|
|
+ orderDetail.setGoodsName(goodsName);
|
|
|
+ orderDetail.setGoodsSpecId(goodsSpecId);
|
|
|
+ orderDetail.setGoodsSpecName(goodsSpecName);
|
|
|
+ orderDetail.setGoodsSpecValue(goodsSpecValue);
|
|
|
+ orderDetail.setIsGift(isGift);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(catagoryId)) {
|
|
|
+ GoodsCategory goodsCategory = goodsCategoryService.getById(catagoryId);
|
|
|
+ if (goodsCategory != null) {
|
|
|
+ orderDetail.setGoodsCategoryId(goodsCategory.getCategoryId());
|
|
|
+ orderDetail.setGoodsCategoryName(goodsCategory.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ orderDetail.setPrice(goodsSecPrice);
|
|
|
+ orderDetail.setNeedPayAmount(goodsSecPrice);
|
|
|
+ orderDetail.setPayAmount(goodsSecPrice.multiply(new BigDecimal(buyGood.getNum())));
|
|
|
+ orderDetail.setNum(buyGood.getNum());
|
|
|
+ orderDetail.setTotalPrice(goodsSecPrice.multiply(new BigDecimal(buyGood.getNum())));
|
|
|
+ orderDetail.setShareAmount(goodsShareAmount.multiply(new BigDecimal(buyGood.getNum())));
|
|
|
+ orderDetail.setCutAmount(cutAmount);
|
|
|
+ orderDetail.setTotalCutAmount(cutAmount.multiply(new BigDecimal(buyGood.getNum())));
|
|
|
+ orderDetail.setProfitAmount(orderDetail.getTotalPrice().subtract(orderDetail.getShareAmount()));
|
|
|
+ orderDetail.setImgUrl(goodsSpec.getImgUrl());
|
|
|
+ orderDetail.setCreateTime(new Date());
|
|
|
+ orderDetail.setMarketingId(goods.getMarketingId());
|
|
|
+ orderDetail.setMarketingName(goods.getMarketingName());
|
|
|
+ BigDecimal freightAmountItem = this.getFreightAmountItem(userAddress.getProvince(), userAddress.getCity(), userAddress.getArea(), buyGood, currentCompanyWechat);
|
|
|
+ orderDetail.setFreight(freightAmountItem);
|
|
|
+
|
|
|
+ orderDetails.add(orderDetail);
|
|
|
+
|
|
|
+ if (!isGift) {
|
|
|
+ //非礼品卡商品
|
|
|
+ totalPrice = totalPrice.add(goodsSecPrice.multiply(new BigDecimal(buyGood.getNum())));
|
|
|
+ } else {
|
|
|
+ //礼品卡商品
|
|
|
+ totalPrice = totalPrice.add(goodsSpec.getPrice().multiply(new BigDecimal(buyGood.getNum())));
|
|
|
+ }
|
|
|
+
|
|
|
+ totalFreight = totalFreight.add(freightAmountItem);
|
|
|
+ orderTitle += goods.getGoodsName() + ",";
|
|
|
+ totalNum += buyGood.getNum();
|
|
|
+ orderTitle += goods.getGoodsName() + ",";
|
|
|
+ shareAmount = orderDetail.getShareAmount().add(shareAmount);
|
|
|
+ if (StringUtils.isEmpty(orderDetail.getPromotionGroupId())) {
|
|
|
+ notPromotionShareAmount = notPromotionShareAmount.add(orderDetail.getShareAmount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!orderBuyBean.getWechatPay() && isExistCode && orderDetails.size() > 1) {
|
|
|
+ // 云闪付支付的参加以旧换新商品只能单品下单
|
|
|
+ throw new RemoteServiceException("订单存在“以旧换新”活动商品,只能单品下单");
|
|
|
+ }
|
|
|
+ if (!orderBuyBean.getWechatPay() && isExistCode && orderDetails.size() == 1 && orderDetails.get(0).getNum() > 1) {
|
|
|
+ // 云闪付支付的参加以旧换新商品只能数量=1单品下单
|
|
|
+ throw new RemoteServiceException("订单存在“以旧换新”活动商品,只能数量“1”单品下单");
|
|
|
+ }
|
|
|
+ //补充网点师傅相关信息
|
|
|
+ this.supplyWorkUser(orderInfo, user);
|
|
|
+
|
|
|
+ //实际需要支付的金额(包含运费)
|
|
|
+ BigDecimal payAmount = totalPrice.add(totalFreight);
|
|
|
+
|
|
|
+ //抵扣的兑换码
|
|
|
+ BigDecimal subAmount = new BigDecimal("0");
|
|
|
+ if (StringUtils.isNotEmpty(exchangeCode) && !hasGiftCode) {
|
|
|
+ if (service == null || !service.getType().equals(UserTypeEnum.SERVICE.toString())) {
|
|
|
+ throw new RemoteServiceException(1100, "无效的兑换码");
|
|
|
+ }
|
|
|
+ //兑换码商品
|
|
|
+ subAmount = this.subGoods(userId, exchangeCode, true, notPromotionShareAmount, orderId);
|
|
|
+ payAmount = payAmount.subtract(subAmount);
|
|
|
+ shareAmount = shareAmount.subtract(subAmount);
|
|
|
+ hasGiftCode = true;
|
|
|
+
|
|
|
+ //处理订单详情的抵扣金额明细
|
|
|
+ this.supplyOrderDetail(orderDetails, subAmount, notPromotionShareAmount);
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成订单
|
|
|
+ orderInfo.setBuyerMsg(orderBuyBean.getBuyerMsg());
|
|
|
+ orderInfo.setOrderStatus(OrderStatusEnum.NOPAY.toString());
|
|
|
+ orderInfo.setUserId(user.getUserId());
|
|
|
+ orderInfo.setUserName(user.getNickName());
|
|
|
+ orderInfo.setPhone(user.getMobile());
|
|
|
+ orderInfo.setExchangeCode(exchangeCode);
|
|
|
+ orderInfo.setExchangeSubAmount(subAmount);
|
|
|
+ orderInfo.setPromotionGroupId(orderPromotionGroupId);
|
|
|
+ orderInfo.setPromotionGroupUserId(promotionGroupUserId);
|
|
|
+ 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.setFreight(totalFreight);
|
|
|
+ orderInfo.setTotalAmount(totalPrice);
|
|
|
+ orderInfo.setPayAmount(payAmount);
|
|
|
+ orderInfo.setPromotionPackageGoodsId(orderBuyBean.getGoodsPackageId());
|
|
|
+ orderInfo.setBuyerName(orderBuyBean.getBuyerName());
|
|
|
+ orderInfo.setBuyerIdCard(orderBuyBean.getBuyerIdCard());
|
|
|
+ orderInfo.setBuyerMobile(user.getMobile());
|
|
|
+ //检查优惠券的使用合法性
|
|
|
+
|
|
|
+ if (!isPromotion && !hasGiftCode) {
|
|
|
+ UserCouponBean userCoupon = couponLogic.check(orderBuyBean.getUserCouponId(), totalPrice, goodsIds, true);
|
|
|
+ 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%");
|
|
|
+ }
|
|
|
+
|
|
|
+ //扣减优惠券金额
|
|
|
+ orderInfo.setPayAmount(
|
|
|
+ orderInfo.getPayAmount().subtract(orderInfo.getDiscountAmount()).doubleValue()
|
|
|
+ < 0 ? BigDecimal.valueOf(0)
|
|
|
+ : orderInfo.getPayAmount().subtract(orderInfo.getDiscountAmount()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ orderInfo.setTotalNum(totalNum);
|
|
|
+ orderInfo.setTotalShareAmount(shareAmount);
|
|
|
+ orderInfo.setOrderTitle(orderTitle);
|
|
|
+ orderInfo.setTotalProductAmount(totalPrice);
|
|
|
+ orderInfo.setCompanyWechatId(currentCompanyWechat.getCompanyWechatId());
|
|
|
+ orderInfo.setCompanyWechatName(currentCompanyWechat.getCompanyName());
|
|
|
+ orderInfo.setDispatchType(orderBuyBean.getDispatchType());
|
|
|
+ orderInfo.setClientIp(ip);
|
|
|
+ //团购的折扣活动
|
|
|
+ if (!isGoodsPackage) {
|
|
|
+ PromotionDiscountBean promotionDiscountBean = this.discountPromotion(orderBuyBean.getBuyGoods(), orderInfo.getPayAmount());
|
|
|
+ //减掉折扣优惠金额
|
|
|
+ if (promotionDiscountBean != null) {
|
|
|
+ payAmount = orderInfo.getPayAmount().subtract(promotionDiscountBean.getSubDiscountAmount());
|
|
|
+ orderInfo.setPromotionDiscountId(promotionDiscountBean.getId());
|
|
|
+ orderInfo.setPromotionDiscountLimitAmount(promotionDiscountBean.getLimitUpperAmount());
|
|
|
+ orderInfo.setPromotionDiscountAmount(promotionDiscountBean.getSubDiscountAmount());
|
|
|
+ orderInfo.setPromotionDiscountRate(promotionDiscountBean.getDiscountRate());
|
|
|
+ orderInfo.setPayAmount(payAmount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ orderInfoService.save(orderInfo);
|
|
|
+ //新增订单详情
|
|
|
+ orderDetailService.saveBatch(orderDetails);
|
|
|
+ //检查清掉购物车
|
|
|
+ if (CollectionUtil.isNotEmpty(shoppingCartIds)) {
|
|
|
+ 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";
|
|
|
+ BigDecimal zero = new BigDecimal("0.00");
|
|
|
+ if (shareAmount.compareTo(zero) > 0) {
|
|
|
+ profitSharingFlag = "Y";
|
|
|
+ }
|
|
|
+
|
|
|
+ PayDetail payDetail = new PayDetail();
|
|
|
+ payDetail.setId(orderInfo.getOrderId());
|
|
|
+
|
|
|
+
|
|
|
+ payDetail = wechatLogic.payment(orderInfo.getOrderId(), orderInfo.getPayAmount(), user.getOpenId(),
|
|
|
+ profitSharingFlag, ip, user.getCompanyWechatId());
|
|
|
+ //不需要支付
|
|
|
+ if (!payDetail.getIsPay()) {
|
|
|
+ payLogic.payCall(payDetail.getId(), "", BigDecimal.valueOf(0));
|
|
|
+ }
|
|
|
+
|
|
|
+ return payDetail;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理商品规格库存
|
|
|
+ *
|
|
|
+ * @param goodsSpecId
|
|
|
+ * @param goodsName
|
|
|
+ * @param num
|
|
|
+ * @return
|
|
|
+ * @throws RemoteServiceException
|
|
|
+ * @throws InterruptedException
|
|
|
+ */
|
|
|
+ private GoodsSpec stock(String goodsSpecId, String goodsName, Integer num) throws RemoteServiceException, InterruptedException {
|
|
|
+ Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_ORDER_STOCK + ":" + goodsSpecId);
|
|
|
+ try {
|
|
|
+ if (!obtain.tryLock(10, TimeUnit.SECONDS)) {
|
|
|
+ throw new RemoteServiceException("系统繁忙,请稍后再试");
|
|
|
+ }
|
|
|
+ GoodsSpec goodsSpec = goodsLogic.getGoodsSpecById(goodsSpecId);
|
|
|
+ if (goodsSpec.getStockNum() < num) {
|
|
|
+ throw new RemoteServiceException(1100, goodsName + "库存不足");
|
|
|
+ }
|
|
|
+ goodsSpec.setStockNum(goodsSpec.getStockNum() - num);
|
|
|
+ goodsSpec.setSoldNum(goodsSpec.getSoldNum() + num);
|
|
|
+ goodsSpec.updateById();
|
|
|
+
|
|
|
+ return goodsSpec;
|
|
|
+ } finally {
|
|
|
+ obtain.unlock();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 还原库存
|
|
|
+ */
|
|
|
+ private void recoveryStock(String goodsSpecId, Integer num) {
|
|
|
+ Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_ORDER_STOCK + goodsSpecId);
|
|
|
+ try {
|
|
|
+ if (!obtain.tryLock(10, TimeUnit.SECONDS)) {
|
|
|
+ log.error("还原库存获取锁失败");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ GoodsSpec goodsSpec = goodsLogic.getGoodsSpecById(goodsSpecId);
|
|
|
+ goodsSpec.setStockNum(goodsSpec.getStockNum() + num);
|
|
|
+ goodsSpec.updateById();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("还原库存失败goodsSpecId:" + goodsSpecId, e);
|
|
|
+ } finally {
|
|
|
+ obtain.unlock();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 订单数量
|
|
|
+ */
|
|
|
+ public OrderStatusBean count(String orderId) {
|
|
|
+ OrderStatusBean orderStatusBean = appMapper.orderStatusCount(orderId);
|
|
|
+ return orderStatusBean;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 补充网点师傅信息
|
|
|
+ *
|
|
|
+ * @param orderInfo
|
|
|
+ * @param user
|
|
|
+ */
|
|
|
+ private void supplyWorkUser(OrderInfo orderInfo, User user) {
|
|
|
+ if (user.getType().equals(UserTypeEnum.SERVICE.toString())) {
|
|
|
+ final AdminWebsit adminWebsit = adminWebsitService.lambdaQuery()
|
|
|
+ .eq(AdminWebsit::getCompanyWechatId, user.getCompanyWechatId())
|
|
|
+ .eq(AdminWebsit::getWebsitId, user.getWebsitId())
|
|
|
+ .one();
|
|
|
+ orderInfo.setWorkerId(user.getWorkUserId());
|
|
|
+ orderInfo.setWorkerName(user.getWorkName());
|
|
|
+ orderInfo.setWorkerPhone(user.getWorkPhone());
|
|
|
+ orderInfo.setWebsitId(user.getWebsitId() + "");
|
|
|
+ orderInfo.setWebsitNumber(Objects.nonNull(adminWebsit) ? adminWebsit.getWebsitNumber() : null);
|
|
|
+ orderInfo.setWebsitName(user.getWebsitName());
|
|
|
+ orderInfo.setPosition(user.getPosition());
|
|
|
+
|
|
|
+ } else {
|
|
|
+ //非业务员那就找到业务员
|
|
|
+ if (StringUtils.isNotEmpty(user.getServiceId())) {
|
|
|
+ User workUser = userService.getById(user.getServiceId());
|
|
|
+ if (workUser != null) {
|
|
|
+ final AdminWebsit adminWebsit = adminWebsitService.lambdaQuery()
|
|
|
+ .eq(AdminWebsit::getCompanyWechatId, workUser.getCompanyWechatId())
|
|
|
+ .eq(AdminWebsit::getWebsitId, workUser.getWebsitId())
|
|
|
+ .one();
|
|
|
+
|
|
|
+ orderInfo.setWorkerId(workUser.getWorkUserId());
|
|
|
+ orderInfo.setWorkerName(workUser.getWorkName());
|
|
|
+ orderInfo.setWorkerPhone(workUser.getWorkPhone());
|
|
|
+ orderInfo.setPosition(workUser.getPosition());
|
|
|
+ orderInfo.setWebsitId(workUser.getWebsitId());
|
|
|
+ orderInfo.setWebsitName(workUser.getWebsitName());
|
|
|
+ orderInfo.setWebsitNumber(Objects.nonNull(adminWebsit) ? adminWebsit.getWebsitNumber() : null);
|
|
|
+
|
|
|
+ if (workUser.getCustomerServiceFlag() != null && workUser.getCustomerServiceFlag()) {
|
|
|
+ orderInfo.setSource("svip邀请");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 支付待支付订单
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public PayDetail waitPayOrder(String userId, String orderId, String ip, String payType, String buyerName,
|
|
|
+ String buyerIdCard, HttpServletRequest request) throws Exception {
|
|
|
+ OrderInfo orderInfo = orderInfoService.getById(orderId);
|
|
|
+ //订单
|
|
|
+ CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat(request);
|
|
|
+ String newOrderId = currentCompanyWechat.getOrderPrefix() + IdWorker.getIdStr();
|
|
|
+
|
|
|
+ if (orderInfo.getPromotionApplyStatus() != null && orderInfo.getPromotionApplyStatus() == 1) {
|
|
|
+ throw new RemoteServiceException("正在申请优惠中请耐心等待");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(userId) && !userId.equals(orderInfo.getUserId())) {
|
|
|
+ User user = userService.getById(userId);
|
|
|
+ if (user.getType().equals(UserTypeEnum.SERVICE.toString())) {
|
|
|
+ throw new RemoteServiceException("业务员不可替业务员下单");
|
|
|
+ }
|
|
|
+
|
|
|
+ //绑定客户关系
|
|
|
+ if (StringUtils.isEmpty(user.getServiceId())) {
|
|
|
+ user.setServiceId(orderInfo.getUserId());
|
|
|
+ user.setServiceTime(new Date());
|
|
|
+ user.updateById();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!orderInfo.getOrderStatus().equals(OrderStatusEnum.NOPAY.toString())) {
|
|
|
+ throw new RemoteServiceException("订单已超时取消或已支付成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ //将订单绑定给用户
|
|
|
+ orderInfo.setUserId(userId);
|
|
|
+ orderInfo.setUserName(user.getNickName());
|
|
|
+ orderInfo.setPhone(user.getMobile());
|
|
|
+
|
|
|
+ orderInfo.updateById();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ orderInfoService.lambdaUpdate()
|
|
|
+ .set(OrderInfo::getOrderId, newOrderId)
|
|
|
+ .set(StringUtils.isNotBlank(buyerName), OrderInfo::getBuyerName, buyerName)
|
|
|
+ .set(StringUtils.isNotBlank(buyerIdCard), OrderInfo::getBuyerIdCard, buyerIdCard)
|
|
|
+ .set(OrderInfo::getClientIp, ip)
|
|
|
+ .eq(OrderInfo::getOrderId, orderId)
|
|
|
+ .update();
|
|
|
+ orderDetailService.lambdaUpdate().set(OrderDetail::getOrderId, newOrderId).eq(OrderDetail::getOrderId, orderId).update();
|
|
|
+
|
|
|
+ User user = userService.getById(orderInfo.getUserId());
|
|
|
+ String profitSharingFlag = "N";
|
|
|
+ BigDecimal zero = new BigDecimal("0.00");
|
|
|
+ if (orderInfo.getTotalShareAmount().compareTo(zero) > 0) {
|
|
|
+ profitSharingFlag = "Y";
|
|
|
+ }
|
|
|
+
|
|
|
+ return wechatLogic.payment(newOrderId, orderInfo.getPayAmount(), user.getOpenId(),
|
|
|
+ profitSharingFlag, ip, user.getCompanyWechatId());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 订单列表
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<OrderDetailBean> list(String userId, String orderStatus, Integer promotionApplyStatus, Integer pageNum, Integer pageSize) {
|
|
|
+ User user = userService.getById(userId);
|
|
|
+ List<Integer> promotionApplyStatusList = new ArrayList<>();
|
|
|
+ if (promotionApplyStatus != null) {
|
|
|
+ if (promotionApplyStatus == 100) {
|
|
|
+ promotionApplyStatusList.add(0);
|
|
|
+ promotionApplyStatusList.add(1);
|
|
|
+ promotionApplyStatusList.add(2);
|
|
|
+ promotionApplyStatusList.add(3);
|
|
|
+ promotionApplyStatusList.add(4);
|
|
|
+ } else if (promotionApplyStatus == 2) {
|
|
|
+ promotionApplyStatusList.add(2);
|
|
|
+ promotionApplyStatusList.add(4);
|
|
|
+ } else {
|
|
|
+ promotionApplyStatusList.add(promotionApplyStatus);
|
|
|
+ }
|
|
|
+ if (user.getPromotionApplyExamineby()) {
|
|
|
+ user.setWorkUserId(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ userId = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ IPage page = orderInfoService.lambdaQuery()
|
|
|
+ .eq(StringUtils.isNotEmpty(orderStatus), OrderInfo::getOrderStatus, orderStatus)
|
|
|
+ .eq(StringUtils.isNotEmpty(userId), OrderInfo::getUserId, userId)
|
|
|
+ .in(CollectionUtil.isNotEmpty(promotionApplyStatusList), OrderInfo::getPromotionApplyStatus, promotionApplyStatusList)
|
|
|
+ .eq(CollectionUtil.isNotEmpty(promotionApplyStatusList) && user.getWorkUserId() != null, OrderInfo::getWorkerId, user.getWorkUserId())
|
|
|
+ .and(promotionApplyStatus != null && promotionApplyStatus == 100, v ->
|
|
|
+ v.eq(OrderInfo::getOrderStatus, OrderStatusEnum.NOPAY.toString())
|
|
|
+ .or().ne(OrderInfo::getOrderStatus, OrderStatusEnum.NOPAY.toString()).ne(OrderInfo::getPromotionApplyStatus, 0)
|
|
|
+ )
|
|
|
+ .orderByDesc(OrderInfo::getCreateTime)
|
|
|
+ .page(new Page<>(pageNum, pageSize));
|
|
|
+
|
|
|
+ List<OrderDetailBean> list = new ArrayList<>();
|
|
|
+ for (Object o : page.getRecords()) {
|
|
|
+ OrderInfo orderInfo = (OrderInfo) o;
|
|
|
+ OrderDetailBean orderDetailBean = new OrderDetailBean();
|
|
|
+ BeanUtils.copyProperties(orderInfo, orderDetailBean);
|
|
|
+ List<OrderShare> list1 = orderShareService
|
|
|
+ .lambdaQuery()
|
|
|
+ .eq(OrderShare::getOrderId, orderInfo.getOrderId())
|
|
|
+ .list();
|
|
|
+ if (list1 != null && list1.size() > 0) {
|
|
|
+ //此处list1目前最多2条
|
|
|
+ for (OrderShare orderShare : list1) {
|
|
|
+ orderDetailBean.setOrderShareStatus(orderShare.getStatus());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //查询订单详情
|
|
|
+ List<OrderDetail> orderDetails = orderDetailService.lambdaQuery().eq(OrderDetail::getOrderId, orderInfo.getOrderId()).list();
|
|
|
+
|
|
|
+ List<OrderDetailGoodsBean> orderDetailGoodsBeans = BeanUtil.copyToList(orderDetails, OrderDetailGoodsBean.class);
|
|
|
+
|
|
|
+ this.getGoodsByGoodsId(orderDetailGoodsBeans);
|
|
|
+
|
|
|
+ final OrderDetail detail = orderDetails.get(0);
|
|
|
+
|
|
|
+ orderDetailBean.setOrderDetailList(orderDetailGoodsBeans);
|
|
|
+ list.add(orderDetailBean);
|
|
|
+ }
|
|
|
+ page.setRecords(list);
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getGoodsByGoodsId(List<OrderDetailGoodsBean> orderDetailGoodsBeans) {
|
|
|
+ final List<String> goodsIds = orderDetailGoodsBeans.stream().map(OrderDetailGoodsBean::getGoodsId).collect(Collectors.toList());
|
|
|
+ final List<Goods> goodsList = goodsService.lambdaQuery()
|
|
|
+ .in(Goods::getGoodsId, goodsIds)
|
|
|
+ .list();
|
|
|
+ final Map<String, Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods::getGoodsId, Function.identity(), (key1, key2) -> key2));
|
|
|
+
|
|
|
+ for (OrderDetailGoodsBean detailGoodsBean : orderDetailGoodsBeans) {
|
|
|
+ final Goods goods = goodsMap.get(detailGoodsBean.getGoodsId());
|
|
|
+ detailGoodsBean.setGoods(goods);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据件数以及地区计算运费
|
|
|
+ */
|
|
|
+ private BigDecimal getFreightAmountItem(String province, String city, String area, BuyGood buyGood, AdminCompanyWechat adminCompanyWechat) throws RemoteServiceException {
|
|
|
+ return freightLogic.computeAmountItem(province, city, area, buyGood, adminCompanyWechat);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 维护兑换码抵扣金额对订单详情商品的影响
|
|
|
+ */
|
|
|
+ private void supplyOrderDetail(List<OrderDetail> orderDetails, BigDecimal exchangeAmount, BigDecimal notPromotionGroupAmount) {
|
|
|
+
|
|
|
+ List<OrderDetail> ods = orderDetails.stream().filter(v -> StringUtils.isEmpty(v.getPromotionGroupId())).collect(Collectors.toList());
|
|
|
+ if (ods.size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (exchangeAmount == null || exchangeAmount.doubleValue() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ BigDecimal totalSubAmount = BigDecimal.valueOf(0);
|
|
|
+ for (int i = 0; i < ods.size(); i++) {
|
|
|
+ OrderDetail orderDetail = ods.get(i);
|
|
|
+ if (i == ods.size() - 1) {
|
|
|
+ //最后一个,直接用总数减掉
|
|
|
+ BigDecimal subtract = exchangeAmount.subtract(totalSubAmount);
|
|
|
+ orderDetail.setShareAmount(orderDetail.getShareAmount().subtract(subtract));
|
|
|
+ orderDetail.setTotalExchangeAmount(subtract);
|
|
|
+
|
|
|
+ double div = ArithUtils.div(subtract.doubleValue(), orderDetail.getNum(), 2);
|
|
|
+ orderDetail.setExchangeAmount(BigDecimal.valueOf(div));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ //该商品的总抵扣金额
|
|
|
+ double div = ArithUtils.div(orderDetail.getShareAmount().doubleValue(), notPromotionGroupAmount.doubleValue(), 4);
|
|
|
+ double mul = ArithUtils.mul(div, exchangeAmount.doubleValue());
|
|
|
+ BigDecimal subAmount = BigDecimal.valueOf(mul);
|
|
|
+ //该商品数量1情况下的抵扣金额
|
|
|
+ double div1 = ArithUtils.div(subAmount.doubleValue(), orderDetail.getNum(), 2);
|
|
|
+
|
|
|
+ orderDetail.setShareAmount(orderDetail.getShareAmount().subtract(subAmount));
|
|
|
+ orderDetail.setTotalExchangeAmount(subAmount);
|
|
|
+ orderDetail.setExchangeAmount(BigDecimal.valueOf(div1));
|
|
|
+ //记录已经分配了多少抵扣金额
|
|
|
+ totalSubAmount = totalSubAmount.add(subAmount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 确认收货
|
|
|
+ */
|
|
|
+ //@Transactional
|
|
|
+ public void ack(String orderId) throws Exception {
|
|
|
+ Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_ORDER + ":" + orderId);
|
|
|
+ if (!obtain.tryLock(5, TimeUnit.SECONDS)) {
|
|
|
+ throw new RemoteServiceException("系统繁忙,请勿重复操作");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ OrderInfo orderInfo = orderInfoService.getById(orderId);
|
|
|
+ if (!orderInfo.getOrderStatus().equals(OrderStatusEnum.YFH.toString())) {
|
|
|
+ throw new RemoteServiceException("非已发货订单不可确认收货");
|
|
|
+ }
|
|
|
+ orderInfo.setOrderStatus(OrderStatusEnum.OVER.toString());
|
|
|
+ orderInfo.setOverTime(new Date());
|
|
|
+ orderInfo.updateById();
|
|
|
+
|
|
|
+ orderShareService.lambdaUpdate()
|
|
|
+ .set(OrderShare::getOrderStatus, orderInfo.getOrderStatus())
|
|
|
+ .eq(OrderShare::getOrderId, orderId)
|
|
|
+ .set(OrderShare::getOrderFinishTime, new Date())
|
|
|
+ .update();
|
|
|
+ } finally {
|
|
|
+ obtain.unlock();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 撤销申请
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public String cancelRefund(String refundOrderId) throws RemoteServiceException {
|
|
|
+ OrderRefund orderRefund = orderRefundService.getById(refundOrderId);
|
|
|
+ if (orderRefund == null || !orderRefund.getOrderStatus().equals(OrderStatusEnum.DSJCL.toString())) {
|
|
|
+ throw new RemoteServiceException("已非待商家处理状态不可撤销申请");
|
|
|
+ }
|
|
|
+ //还原订单为完成状态
|
|
|
+ String orderId = orderRefund.getOrderId();
|
|
|
+ orderRefund.deleteById();
|
|
|
+ return orderId;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 申请售后
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public String applyAfterSale(RefundGoodsBean refundGoodsBean) throws Exception {
|
|
|
+ String orderId = refundGoodsBean.getOrderId();
|
|
|
+ String refundReason = refundGoodsBean.getRefundReason();
|
|
|
+ String refundType = refundGoodsBean.getRefundType();
|
|
|
+ String refundExplain = refundGoodsBean.getRefundExplain();
|
|
|
+ List<String> imgIds = refundGoodsBean.getImgIds();
|
|
|
+ List<RefundGoods> refundGoods = refundGoodsBean.getRefundGoods();
|
|
|
+
|
|
|
+ OrderInfo orderInfo = orderInfoService.getById(orderId);
|
|
|
+
|
|
|
+ Long count = orderShareService.lambdaQuery()
|
|
|
+ .eq(OrderShare::getOrderId, orderId)
|
|
|
+ .and(o -> o.eq(OrderShare::getStatus, OrderShareStatusEnum.OVER.toString())
|
|
|
+ .or()
|
|
|
+ .eq(OrderShare::getStatus, OrderShareStatusEnum.CANCEL.toString()))
|
|
|
+ .count();
|
|
|
+
|
|
|
+ if (count > 0) {
|
|
|
+ throw new RemoteServiceException("已结算订单,不能申请售后");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (OrderStatusEnum.NOPAY.toString().equals(orderInfo.getOrderStatus())) {
|
|
|
+ throw new RemoteServiceException("未付款,不需要售后");
|
|
|
+ }
|
|
|
+// if (OrderStatusEnum.OVER.toString().equals(orderInfo.getOrderStatus())) {
|
|
|
+// throw new RemoteServiceException("订单已完成,不能售后");
|
|
|
+// }
|
|
|
+ Long refundCount = orderRefundService.lambdaQuery()
|
|
|
+ .eq(OrderRefund::getOrderId, orderId)
|
|
|
+ .in(OrderRefund::getOrderStatus, Arrays.asList(OrderStatusEnum.DSJCL.toString(),
|
|
|
+ OrderStatusEnum.DMJCL.toString(), OrderStatusEnum.DSJSH.toString(), OrderStatusEnum.REFUND.toString(), OrderStatusEnum.OVER.toString()))
|
|
|
+ .ne(OrderRefund::getExamineStatus, OrderExamineEnum.FAIL.toString())
|
|
|
+ .count();
|
|
|
+ if (refundCount > 0) {
|
|
|
+ throw new RemoteServiceException("请勿重新申请售后");
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal totalRefundAmount = new BigDecimal("0.00");
|
|
|
+ BigDecimal totalRefundShareAmount = new BigDecimal("0.00");
|
|
|
+ for (RefundGoods bean : refundGoods) {
|
|
|
+ OrderDetail orderDetail = orderDetailService.getById(bean.getOrderDetailId());
|
|
|
+ if (orderInfo.getPromotionPackageGoods() && orderDetail.getNum().intValue() != bean.getNum().intValue()) {
|
|
|
+ throw new RemoteServiceException("套购商品只支持全量退");
|
|
|
+ }
|
|
|
+ if (bean.getNum() > orderDetail.getNum()) {
|
|
|
+ throw new RemoteServiceException("申请售后的商品数量错误");
|
|
|
+ }
|
|
|
+ //商品需要退款的金额
|
|
|
+ BigDecimal refundAmount = BigDecimal.valueOf(ArithUtils.mul(ArithUtils.div(orderDetail.getPayAmount().doubleValue(), orderDetail.getNum(), 4), bean.getNum(), 2));
|
|
|
+ //计算退款的数量占比
|
|
|
+ double div = ArithUtils.div(bean.getNum(), orderDetail.getNum(), 4);
|
|
|
+ //按比例退运费(这里涉及到运费模板规则问题,暂不明确退款的规则运费怎么处理,目前以不退运费为准)
|
|
|
+// if (orderInfo.getOrderStatus().equals(OrderStatusEnum.DFH.toString()) ||
|
|
|
+// (orderInfo.getOrderStatus().equals(OrderStatusEnum.REFUND.toString()) &&
|
|
|
+// org.apache.commons.lang3.StringUtils.isEmpty(orderInfo.getLogisticsNo()))) {//待发货状态退运费
|
|
|
+// BigDecimal refundFreight = BigDecimal.valueOf(ArithUtils.mul(orderDetail.getFreight().doubleValue(), div, 2));
|
|
|
+// if (refundFreight == null) {
|
|
|
+// refundFreight = new BigDecimal("0.00");
|
|
|
+// }
|
|
|
+// refundAmount = refundAmount.add(refundFreight);
|
|
|
+// }
|
|
|
+ orderDetail.setRefundNum(bean.getNum());
|
|
|
+ orderDetail.setRefundAmount(refundAmount);
|
|
|
+ orderDetail.setRefundTime(new Date());
|
|
|
+ orderDetail.setRefund(true);
|
|
|
+ orderDetail.updateById();
|
|
|
+ //总退款金额
|
|
|
+ totalRefundAmount = totalRefundAmount.add(refundAmount);
|
|
|
+ totalRefundShareAmount = totalRefundShareAmount.add(orderDetail.getShareAmount());
|
|
|
+ }
|
|
|
+ //扣除运费后的金额
|
|
|
+ //totalRefundAmount=totalRefundAmount.subtract(orderInfo.getFreight());
|
|
|
+ //绑定附件
|
|
|
+ commonLogic.bindFile(orderId, Constant.Img.ORDER_REFUND_TKPZ, imgIds);
|
|
|
+ //新增售后申请信息
|
|
|
+ OrderRefund orderRefund = orderRefundService.lambdaQuery()
|
|
|
+ .eq(OrderRefund::getOrderId, orderId)
|
|
|
+ .one();
|
|
|
+ if (orderRefund == null) {
|
|
|
+ orderRefund = new OrderRefund();
|
|
|
+ orderRefund.setCreateTime(new Date());
|
|
|
+ BeanUtils.copyProperties(orderInfo, orderRefund);
|
|
|
+ }
|
|
|
+ orderRefund.setOrderStatus(OrderStatusEnum.DSJCL.toString());
|
|
|
+ orderRefund.setRefundType(refundType);
|
|
|
+ orderRefund.setRefundReason(refundReason);
|
|
|
+ orderRefund.setRefundExplain(refundExplain);
|
|
|
+ orderRefund.setRefundAmount(totalRefundAmount);
|
|
|
+ orderRefund.setRefundShareAmount(totalRefundShareAmount);
|
|
|
+ orderRefund.setWebsitName(orderInfo.getWebsitName());
|
|
|
+ orderRefund.setWebsitNumber(orderInfo.getWebsitNumber());
|
|
|
+ orderRefund.setCreateTime(new Date());
|
|
|
+ orderRefundService.saveOrUpdate(orderRefund);
|
|
|
+ orderInfo.setLastOrderStatus(orderInfo.getOrderStatus());
|
|
|
+ orderInfo.setOrderStatus(OrderStatusEnum.REFUND.toString());
|
|
|
+ orderInfo.setRefundFlag(RefundFlagEnum.ING.toString());
|
|
|
+ orderInfoService.updateById(orderInfo);
|
|
|
+
|
|
|
+ return orderRefund.getOrderRefundId();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 售后订单列表
|
|
|
+ */
|
|
|
+ public IPage<OrderRefundDetailBean> refundList(String userId, String orderStatus, Integer pageNo, Integer pageSize) {
|
|
|
+ IPage page = orderRefundService.lambdaQuery()
|
|
|
+ .eq(OrderRefund::getUserId, userId)
|
|
|
+ .eq(StringUtils.isNotEmpty(orderStatus), OrderRefund::getOrderStatus, orderStatus)
|
|
|
+ .orderByDesc(OrderRefund::getCreateTime)
|
|
|
+ .page(new Page<>(pageNo, pageSize));
|
|
|
+
|
|
|
+ List<OrderRefundDetailBean> list = new ArrayList<>();
|
|
|
+ for (Object o : page.getRecords()) {
|
|
|
+ OrderRefund orderRefund = (OrderRefund) o;
|
|
|
+ OrderRefundDetailBean orderRefundDetailBean = new OrderRefundDetailBean();
|
|
|
+ BeanUtils.copyProperties(orderRefund, orderRefundDetailBean);
|
|
|
+ orderRefundDetailBean.setOrderDetails(orderDetailService.lambdaQuery()
|
|
|
+ .eq(OrderDetail::getOrderId, orderRefund.getOrderId()).list());
|
|
|
+ list.add(orderRefundDetailBean);
|
|
|
+ }
|
|
|
+ page.setRecords(list);
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 售后订单详情
|
|
|
+ *
|
|
|
+ * @param orderRefundId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public OrderRefundDetailBean orderRefundDetail(String orderRefundId) {
|
|
|
+ OrderRefund orderRefund = orderRefundService.getById(orderRefundId);
|
|
|
+ List<OrderDetail> list = orderDetailService.lambdaQuery().eq(OrderDetail::getOrderId, orderRefund.getOrderId()).list();
|
|
|
+
|
|
|
+ OrderRefundDetailBean orderRefundDetailBean = new OrderRefundDetailBean();
|
|
|
+ BeanUtils.copyProperties(orderRefund, orderRefundDetailBean);
|
|
|
+ orderRefundDetailBean.setOrderDetails(list);
|
|
|
+ //售后凭证
|
|
|
+ List<CommonFile> commonFiles = commonLogic.queryFileByObjId(orderRefundId, Constant.Img.ORDER_REFUND_WLPZ);
|
|
|
+ orderRefundDetailBean.setFiles(commonFiles);
|
|
|
+
|
|
|
+ return orderRefundDetailBean;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 售后订单-补充退货资料
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public void supplyData(String orderRefundId, String logisticsNo, String expressCompany, List<String> imgIds) throws RemoteServiceException {
|
|
|
+ OrderRefund orderRefund = orderRefundService.getById(orderRefundId);
|
|
|
+ if (!orderRefund.getOrderStatus().equals(OrderStatusEnum.DMJCL.toString())) {
|
|
|
+ throw new RemoteServiceException("请耐心等待商家审核");
|
|
|
+ }
|
|
|
+ orderRefund.setLogisticsNo(logisticsNo);
|
|
|
+ orderRefund.setExpressCompanyCode(expressCompany);
|
|
|
+ orderRefund.setOrderStatus(OrderStatusEnum.DSJSH.toString());
|
|
|
+ orderRefund.updateById();
|
|
|
+
|
|
|
+ //凭证
|
|
|
+ commonLogic.bindFile(orderRefundId, Constant.Img.ORDER_REFUND_WLPZ, imgIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提醒发货
|
|
|
+ */
|
|
|
+ public void notice(String orderId) {
|
|
|
+ OrderInfo orderInfo = orderInfoService.getById(orderId);
|
|
|
+ Notice notice = new Notice();
|
|
|
+ notice.setObjId(orderId);
|
|
|
+ notice.setCreateTime(new Date());
|
|
|
+ notice.setContent("客户催促您发货了,订单号:" + orderId);
|
|
|
+ notice.setType(1);
|
|
|
+ notice.setTitle("订单发货");
|
|
|
+ notice.setWebsitName(orderInfo.getWebsitName());
|
|
|
+ notice.setWebsitNumber(orderInfo.getWebsitNumber());
|
|
|
+ notice.insert();
|
|
|
+ }
|
|
|
}
|