|
|
@@ -41,6 +41,7 @@ import com.fs.company.mapper.CompanyMoneyLogsMapper;
|
|
|
import com.fs.company.service.ICompanyDeptService;
|
|
|
import com.fs.company.service.ICompanyService;
|
|
|
import com.fs.company.service.ICompanyUserService;
|
|
|
+import com.fs.core.utils.OrderCodeUtils;
|
|
|
import com.fs.erp.domain.*;
|
|
|
import com.fs.erp.dto.*;
|
|
|
import com.fs.erp.mapper.FsErpFinishPushMapper;
|
|
|
@@ -65,10 +66,12 @@ import com.fs.hisStore.enums.OrderInfoEnum;
|
|
|
import com.fs.hisStore.enums.OrderLogEnum;
|
|
|
import com.fs.hisStore.enums.ShipperCodeEnum;
|
|
|
import com.fs.hisStore.enums.SysConfigEnum;
|
|
|
+import com.fs.hisStore.mapper.FsStoreProductAttrValueScrmMapper;
|
|
|
import com.fs.hisStore.param.FsStoreOrderAddTuiMoneyParam;
|
|
|
import com.fs.hisStore.param.FsStoreOrderParam;
|
|
|
import com.fs.hisStore.param.FsStoreOrderScrmSetErpPhoneParam;
|
|
|
import com.fs.hisStore.service.IFsExpressScrmService;
|
|
|
+import com.fs.hisStore.service.IFsStoreProductScrmService;
|
|
|
import com.fs.hisStore.vo.FsMyStoreOrderListQueryVO;
|
|
|
import com.fs.hisStore.vo.FsStoreOrderItemVO;
|
|
|
import com.fs.hisStore.vo.FsStoreOrderVO;
|
|
|
@@ -127,7 +130,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
private LiveOrderItemMapper liveOrderItemMapper;
|
|
|
|
|
|
@Autowired
|
|
|
- private IFsStoreProductService fsStoreProductService;
|
|
|
+ private IFsStoreProductScrmService fsStoreProductService;
|
|
|
|
|
|
@Autowired
|
|
|
FsUserMapper userMapper;
|
|
|
@@ -141,7 +144,10 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
private ICompanyService companyService;
|
|
|
|
|
|
@Autowired
|
|
|
- private FsStoreProductAttrValueMapper fsStoreProductAttrValueMapper;
|
|
|
+ private FsStoreProductAttrValueScrmMapper fsStoreProductAttrValueMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LiveUserLotteryRecordMapper liveUserLotteryRecordMapper;
|
|
|
|
|
|
@Autowired
|
|
|
ICompanyUserService companyUserService;
|
|
|
@@ -197,6 +203,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
@Autowired
|
|
|
private LiveOrderPaymentErrorMapper liveOrderPaymentErrorMapper;
|
|
|
|
|
|
@@ -761,60 +768,41 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
|
|
|
@Override
|
|
|
public List<LiveOrderListVo> selectLiveOrderListVo(LiveOrder liveOrder) {
|
|
|
-// List<LiveOrderListVo> liveOrders = baseMapper.selectLiveOrderListVo(liveOrder.getUserId(),liveOrder.getStatus());
|
|
|
-// List<Long> allOrderIds = liveOrders.stream().map(LiveOrderListVo::getOrderId)
|
|
|
-// .filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
-//
|
|
|
-// if(CollectionUtils.isEmpty(allOrderIds)) {
|
|
|
-// return Collections.emptyList();
|
|
|
-// }
|
|
|
-//
|
|
|
-// Map<Long, FsStoreDelivers> byOrderIdWithTypeBatch = fsStoreDeliversMapper
|
|
|
-// .findByOrderIdWithTypeBatch(allOrderIds, 1);
|
|
|
-//
|
|
|
-// Map<Long,LiveAfterSales> liveAfterSalesMap = liveAfterSalesMapper.findByOrderIds(allOrderIds);
|
|
|
-//
|
|
|
-// List<LiveOrderItemVo> liveOrderItemVosList = liveOrderItemMapper.selectLiveOrderItemByOrderIds(allOrderIds);
|
|
|
-// Map<Long, List<LiveOrderItemVo>> orderItemsMap = liveOrderItemVosList.stream()
|
|
|
-// .collect(Collectors.groupingBy(
|
|
|
-// LiveOrderItemVo::getOrderId,
|
|
|
-// LinkedHashMap::new,
|
|
|
-// Collectors.toList()
|
|
|
-// ));
|
|
|
-//
|
|
|
-// for (LiveOrderListVo order : liveOrders) {
|
|
|
-// FsStoreDelivers delivers = byOrderIdWithTypeBatch.get(order.getOrderId());
|
|
|
-//
|
|
|
-// if(ObjectUtil.isNotNull(delivers)) {
|
|
|
-// order.setDeliveryCode(delivers.getDeliverSn());
|
|
|
-// order.setDeliveryName(delivers.getDeliverName());
|
|
|
-// order.setDeliverySn(delivers.getDeliverId());
|
|
|
-// order.setDeliveryStatus(delivers.getStatus());
|
|
|
-// order.setDeliveryType(String.valueOf(delivers.getStateEx()));
|
|
|
-// }else {
|
|
|
-// order.setDeliveryCode(null);
|
|
|
-// order.setDeliveryName(null);
|
|
|
-// order.setDeliverySn(null);
|
|
|
-// order.setDeliveryStatus(null);
|
|
|
-// order.setDeliveryType(null);
|
|
|
-// }
|
|
|
-// if(ObjectUtil.isNotNull(liveAfterSalesMap)){
|
|
|
-// LiveAfterSales liveAfterSales = liveAfterSalesMap.get(order.getOrderId());
|
|
|
-// if(ObjectUtil.isNotNull(liveAfterSales)) {
|
|
|
-// order.setAfterSaleId(liveAfterSales.getId());
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// if(ObjectUtil.isNotNull(orderItemsMap)){
|
|
|
-// Long orderId = order.getOrderId();
|
|
|
-// List<LiveOrderItemVo> liveOrderItemVos = orderItemsMap.get(orderId);
|
|
|
-// if(CollectionUtils.isNotEmpty(liveOrderItemVos)) {
|
|
|
-// order.setOrderItemList(liveOrderItemVos);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return liveOrders;
|
|
|
- return null;
|
|
|
+ List<LiveOrderListVo> liveOrders = baseMapper.selectLiveOrderListVo(liveOrder.getUserId(),liveOrder.getStatus());
|
|
|
+ List<Long> allOrderIds = liveOrders.stream().map(LiveOrderListVo::getOrderId)
|
|
|
+ .filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if(CollectionUtils.isEmpty(allOrderIds)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<Long,LiveAfterSales> liveAfterSalesMap = liveAfterSalesMapper.findByOrderIds(allOrderIds);
|
|
|
+
|
|
|
+ List<LiveOrderItemVo> liveOrderItemVosList = liveOrderItemMapper.selectLiveOrderItemByOrderIds(allOrderIds);
|
|
|
+ Map<Long, List<LiveOrderItemVo>> orderItemsMap = liveOrderItemVosList.stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ LiveOrderItemVo::getOrderId,
|
|
|
+ LinkedHashMap::new,
|
|
|
+ Collectors.toList()
|
|
|
+ ));
|
|
|
+
|
|
|
+ for (LiveOrderListVo order : liveOrders) {
|
|
|
+ if(ObjectUtil.isNotNull(liveAfterSalesMap)){
|
|
|
+ LiveAfterSales liveAfterSales = liveAfterSalesMap.get(order.getOrderId());
|
|
|
+ if(ObjectUtil.isNotNull(liveAfterSales)) {
|
|
|
+ order.setAfterSaleId(liveAfterSales.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ObjectUtil.isNotNull(orderItemsMap)){
|
|
|
+ Long orderId = order.getOrderId();
|
|
|
+ List<LiveOrderItemVo> liveOrderItemVos = orderItemsMap.get(orderId);
|
|
|
+ if(CollectionUtils.isNotEmpty(liveOrderItemVos)) {
|
|
|
+ order.setOrderItemList(liveOrderItemVos);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return liveOrders;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -1014,6 +1002,8 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
// order.setStatus(-2);
|
|
|
// order.setRefundMoney(order.getPayMoney());
|
|
|
// order.setRefundStatus(String.valueOf(OrderInfoEnum.REFUND_STATUS_2.getValue()));
|
|
|
+// liveUserLotteryRecordMapper.updateOrderStatusByOrderId(order.getOrderId(), -2);
|
|
|
+
|
|
|
// baseMapper.updateLiveOrder(order);
|
|
|
//
|
|
|
// //退库存
|
|
|
@@ -1070,6 +1060,8 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
// order.setStatus(-2);
|
|
|
// order.setRefundMoney(order.getPayMoney());
|
|
|
// order.setRefundStatus(String.valueOf(OrderInfoEnum.REFUND_STATUS_2.getValue()));
|
|
|
+// liveUserLotteryRecordMapper.updateOrderStatusByOrderId(order.getOrderId(), -2);
|
|
|
+
|
|
|
// baseMapper.updateLiveOrder(order);
|
|
|
//
|
|
|
// //退库存
|
|
|
@@ -1374,7 +1366,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
// order.setDeliveryName(deliverName);
|
|
|
// order.setDeliverySn(deliveryId);
|
|
|
// order.setDeliveryCode(express.getCode());
|
|
|
-//
|
|
|
+// liveUserLotteryRecordMapper.updateOrderStatusByOrderId(order.getOrderId(), 3);
|
|
|
// baseMapper.updateLiveOrder(order);
|
|
|
// if(ObjectUtil.isNotNull(express)) {
|
|
|
// FsStoreDelivers fsStoreDeliver = new FsStoreDelivers();
|
|
|
@@ -1428,6 +1420,140 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public LiveOrderComputeDTO computedReward(long l, LiveOrderComputedParam param) {
|
|
|
+ String orderKey= redisCache.getCacheObject("orderKey:"+param.getOrderKey());
|
|
|
+ if (StringUtils.isEmpty(orderKey)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ FsStoreProductScrm fsStoreProduct = fsStoreProductService.selectFsStoreProductById(param.getProductId());
|
|
|
+ if(fsStoreProduct == null) return null;
|
|
|
+ BigDecimal payPrice = BigDecimal.ZERO;
|
|
|
+ BigDecimal payDelivery = BigDecimal.ZERO;
|
|
|
+ BigDecimal totalPrice = fsStoreProduct.getPrice().multiply(new BigDecimal(param.getTotalNum()));
|
|
|
+ if (param.getCityId() != null) {
|
|
|
+ payDelivery = handleDeliveryMoney(param.getCityId(), fsStoreProduct, param.getTotalNum());
|
|
|
+ totalPrice = totalPrice.add(payDelivery);
|
|
|
+ }
|
|
|
+ return LiveOrderComputeDTO.builder().payPrice(payPrice)
|
|
|
+ .payDelivery(payDelivery)
|
|
|
+ .deductionPrice(totalPrice)
|
|
|
+ .totalPrice(totalPrice)
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R createRewardLiveOrder(LiveOrder liveOrder) {
|
|
|
+ String orderKey= redisCache.getCacheObject("orderKey:"+liveOrder.getOrderKey());
|
|
|
+ if (StringUtils.isEmpty(orderKey)) {
|
|
|
+ return R.error("订单已过期");
|
|
|
+ }
|
|
|
+ LiveUserLotteryRecord liveUserLotteryRecord = liveUserLotteryRecordMapper.selectLiveUserLotteryRecordById(liveOrder.getRecordId());
|
|
|
+ if(liveUserLotteryRecord == null) return R.error("未查询到中奖记录,请联系管理员处理!");
|
|
|
+ if(liveOrder.getLiveId() == null) return R.error("直播ID不能为空");
|
|
|
+ if(liveOrder.getProductId() == null) return R.error("购物商品ID不能为空");
|
|
|
+ if(liveOrder.getUserName() == null) return R.error("用户名不能为空");
|
|
|
+ if(liveOrder.getUserPhone() == null) return R.error("用户手机号不能为空");
|
|
|
+ if(liveOrder.getUserAddress() == null) return R.error("用户地址不能为空");
|
|
|
+ if(liveOrder.getTotalNum() == null) return R.error("商品数量不能为空");
|
|
|
+
|
|
|
+ Live live = liveMapper.selectLiveByLiveId(liveOrder.getLiveId());
|
|
|
+ if(live == null) return R.error("当前直播不存在");
|
|
|
+ FsStoreProductScrm fsStoreProduct = fsStoreProductService.selectFsStoreProductById(liveOrder.getProductId());
|
|
|
+ LiveGoods goods = liveGoodsMapper.selectLiveGoodsByProductId(liveOrder.getLiveId(), liveOrder.getProductId());
|
|
|
+ if(goods == null) return R.error("当前商品不存在");
|
|
|
+
|
|
|
+ // 更改店铺库存
|
|
|
+ fsStoreProduct.setStock(fsStoreProduct.getStock()-Integer.parseInt(liveOrder.getTotalNum()));
|
|
|
+ fsStoreProductService.updateFsStoreProduct(fsStoreProduct);
|
|
|
+ // 更新直播间库存
|
|
|
+ goods.setStock(goods.getStock()-Integer.parseInt(liveOrder.getTotalNum()));
|
|
|
+ liveGoodsMapper.updateLiveGoods(goods);
|
|
|
+
|
|
|
+ //判断是否是三种特定产品
|
|
|
+ if (fsStoreProduct.getProductId() != null && (fsStoreProduct.getProductId().equals(3168L)
|
|
|
+ || fsStoreProduct.getProductId().equals(3184L)
|
|
|
+ || fsStoreProduct.getProductId().equals(3185L))) {
|
|
|
+ liveOrder.setStoreHouseCode("YDSP001");
|
|
|
+ } else {
|
|
|
+ liveOrder.setStoreHouseCode("CQDS001");
|
|
|
+ }
|
|
|
+
|
|
|
+ LiveUserFirstEntry liveUserFirstEntry = liveUserFirstEntryService.selectEntityByLiveIdUserId(liveOrder.getLiveId(), Long.parseLong(liveOrder.getUserId()));
|
|
|
+ liveOrder.setCompanyId(liveUserFirstEntry.getCompanyId());
|
|
|
+ liveOrder.setCompanyUserId(liveUserFirstEntry.getCompanyUserId());
|
|
|
+ liveOrder.setTuiUserId(liveUserFirstEntry.getCompanyUserId());
|
|
|
+
|
|
|
+ String orderSn = OrderCodeUtils.getOrderSn();
|
|
|
+ log.info("订单生成:"+orderSn);
|
|
|
+ liveOrder.setOrderCode(orderSn);
|
|
|
+ BigDecimal totalPrice = fsStoreProduct.getPrice().multiply(new BigDecimal(liveOrder.getTotalNum()));
|
|
|
+ // 直播不需要服务费 0915 1735 左
|
|
|
+// String config=configService.selectConfigByKey("store.config");
|
|
|
+// StoreConfig storeConfig= JSONUtil.toBean(config,StoreConfig.class);
|
|
|
+// BigDecimal serviceFee=new BigDecimal(0);
|
|
|
+// if(storeConfig.getServiceFee()!=null){
|
|
|
+// if(liveOrder.getCompanyUserId()==null||liveOrder.getCompanyUserId()==0){
|
|
|
+// serviceFee=storeConfig.getServiceFee();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// payPrice = payPrice.add(serviceFee);
|
|
|
+ // 生成
|
|
|
+ BigDecimal deliveryMoney = handleDeliveryMoney(liveOrder);
|
|
|
+ totalPrice = totalPrice.add(deliveryMoney);
|
|
|
+ liveOrder.setDiscountMoney(totalPrice);
|
|
|
+
|
|
|
+
|
|
|
+ liveOrder.setItemJson(JSON.toJSONString(fsStoreProduct));
|
|
|
+ liveOrder.setCreateTime(new Date());
|
|
|
+ liveOrder.setUpdateTime(new Date());
|
|
|
+ liveOrder.setPayDelivery(deliveryMoney);
|
|
|
+ liveOrder.setProductId(fsStoreProduct.getProductId());
|
|
|
+ liveOrder.setStatus(OrderInfoEnum.STATUS_1.getValue());
|
|
|
+ liveOrder.setPayType("1");
|
|
|
+ liveOrder.setTotalPrice(totalPrice);
|
|
|
+ liveOrder.setPayMoney(BigDecimal.ZERO);
|
|
|
+ try {
|
|
|
+ if (baseMapper.insertLiveOrder(liveOrder) > 0) {
|
|
|
+ liveUserLotteryRecord.setOrderId(liveOrder.getOrderId());
|
|
|
+ liveUserLotteryRecord.setOrderStatus(liveOrder.getStatus());
|
|
|
+ liveUserLotteryRecordMapper.updateLiveUserLotteryRecord(liveUserLotteryRecord);
|
|
|
+ LiveOrderItemDTO dto=new LiveOrderItemDTO();
|
|
|
+ dto.setImage(fsStoreProduct.getImgUrl());
|
|
|
+ dto.setSku(String.valueOf(fsStoreProduct.getStock()));
|
|
|
+ if (StringUtils.isEmpty(fsStoreProduct.getBarCode())) {
|
|
|
+ FsStoreProductAttrValueScrm fsStoreProductAttrValue = fsStoreProductAttrValueMapper.selectFsStoreProductAttrValueByProductId(fsStoreProduct.getProductId()).stream().filter(attrValue -> StringUtils.isNotEmpty(attrValue.getBarCode())).findFirst().orElse(null);
|
|
|
+ if (fsStoreProductAttrValue != null) {
|
|
|
+ dto.setBarCode(fsStoreProductAttrValue.getBarCode());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ dto.setBarCode(fsStoreProduct.getBarCode());
|
|
|
+ }
|
|
|
+ dto.setPrice(fsStoreProduct.getPrice());
|
|
|
+ dto.setProductName(fsStoreProduct.getProductName());
|
|
|
+ dto.setNum(Long.valueOf(liveOrder.getTotalNum()));
|
|
|
+
|
|
|
+ LiveOrderItem liveOrderItem = new LiveOrderItem();
|
|
|
+ liveOrderItem.setOrderCode(liveOrder.getOrderCode());
|
|
|
+ liveOrderItem.setOrderId(liveOrder.getOrderId());
|
|
|
+ liveOrderItem.setProductId(liveOrder.getProductId());
|
|
|
+ liveOrderItem.setNum(Long.valueOf(liveOrder.getTotalNum()));
|
|
|
+ liveOrderItem.setJsonInfo(JSON.toJSONString(dto));
|
|
|
+ liveOrderItemMapper.insertLiveOrderItem(liveOrderItem);
|
|
|
+ redisCache.deleteObject("orderKey:" + liveOrder.getOrderKey());
|
|
|
+ return R.ok("下单成功").put("order",liveOrder);
|
|
|
+ } else {
|
|
|
+ return R.error("订单创建失败");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 异常处理
|
|
|
+ return R.error("订单创建失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public LiveOrderComputeDTO computedOrder(long userId, LiveOrderComputedParam param) {
|
|
|
@@ -1435,7 +1561,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
if (StringUtils.isEmpty(orderKey)) {
|
|
|
return null;
|
|
|
}
|
|
|
- FsStoreProduct fsStoreProduct = fsStoreProductService.selectFsStoreProductById(param.getProductId());
|
|
|
+ FsStoreProductScrm fsStoreProduct = fsStoreProductService.selectFsStoreProductById(param.getProductId());
|
|
|
BigDecimal totalPrice = BigDecimal.ZERO;
|
|
|
BigDecimal payPrice = fsStoreProduct.getPrice().multiply(new BigDecimal(param.getTotalNum()));
|
|
|
totalPrice = totalPrice.add(payPrice);
|
|
|
@@ -1449,7 +1575,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
if(param.getCouponUserId()!=null){
|
|
|
LiveCouponUser couponUser=liveCouponUserService.selectLiveCouponUserById(param.getCouponUserId());
|
|
|
if(couponUser!=null&&couponUser.getStatus()==0){
|
|
|
- if(couponUser.getUseMinPrice().compareTo(payPrice)==-1){
|
|
|
+ if(couponUser.getUseMinPrice().compareTo(payPrice)< 1){
|
|
|
payPrice=payPrice.subtract(couponUser.getCouponPrice());
|
|
|
deductionPrice = couponUser.getCouponPrice();
|
|
|
}
|
|
|
@@ -1537,6 +1663,8 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
// map.setStatus(OrderInfoEnum.STATUS_2.getValue());
|
|
|
// map.setOrderId(order.getOrderId());
|
|
|
// map.setDeliverySn(response.getOrders().get(0).getDeliverys().get(0).getMail_no());
|
|
|
+// liveUserLotteryRecordMapper.updateOrderStatusByOrderId(order.getOrderId(), 2);
|
|
|
+
|
|
|
// liveOrderMapper.updateLiveOrder(map);
|
|
|
// liveOrderLogsService.create(order.getOrderId(), OrderLogEnum.DELIVERY_GOODS.getValue(),
|
|
|
// OrderLogEnum.DELIVERY_GOODS.getDesc());
|
|
|
@@ -1882,7 +2010,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
return liveOrderMapper.selectLiveOrderCount(userId, status);
|
|
|
}
|
|
|
|
|
|
- private BigDecimal handleDeliveryMoney(Long cityId, FsStoreProduct fsStoreProduct, String totalNumSize) {
|
|
|
+ private BigDecimal handleDeliveryMoney(Long cityId, FsStoreProductScrm fsStoreProduct, String totalNumSize) {
|
|
|
BigDecimal storePostage = BigDecimal.ZERO;
|
|
|
// List<Long> citys = new ArrayList<>();
|
|
|
// citys.add(cityId);
|
|
|
@@ -1982,6 +2110,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
if(order.getStatus()==OrderInfoEnum.STATUS_3.getValue()){
|
|
|
order.setFinishTime(new Date());
|
|
|
order.setStatus(4);
|
|
|
+ liveUserLotteryRecordMapper.updateOrderStatusByOrderId(order.getOrderId(), 4);
|
|
|
baseMapper.updateLiveOrder(order);
|
|
|
liveOrderLogsService.create(order.getOrderId(), OrderLogEnum.FINISH_ORDER.getValue(),
|
|
|
OrderLogEnum.FINISH_ORDER.getDesc());
|
|
|
@@ -2042,6 +2171,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
public int updateLiveOrder(LiveOrder liveOrder)
|
|
|
{
|
|
|
liveOrder.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ liveUserLotteryRecordMapper.updateOrderStatusByOrderId(liveOrder.getOrderId(), liveOrder.getStatus());
|
|
|
return baseMapper.updateLiveOrder(liveOrder);
|
|
|
}
|
|
|
|
|
|
@@ -2199,6 +2329,7 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
// OrderLogEnum.FINISH_ORDER.getDesc());
|
|
|
|
|
|
int i = baseMapper.updateLiveOrder(updateEntity);
|
|
|
+ liveUserLotteryRecordMapper.updateOrderStatusByOrderId(order.getOrderId(), OrderInfoEnum.STATUS_3.getValue());
|
|
|
|
|
|
return i;
|
|
|
}
|
|
|
@@ -2265,6 +2396,84 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Throwable.class,propagation = Propagation.REQUIRED)
|
|
|
+ public R payConfirmReward(LiveOrder liveOrder) {
|
|
|
+ Long orderId = liveOrder.getOrderId();
|
|
|
+ if(orderId==null) return R.error("订单ID不存在");
|
|
|
+ Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
|
|
|
+ try {
|
|
|
+ liveOrder = baseMapper.selectLiveOrderByOrderId(String.valueOf(orderId));
|
|
|
+ if(liveOrder==null || !liveOrder.getStatus().equals(1)){
|
|
|
+ throw new CustomException("当前订单未找到或者订单状态不为待支付! orderId:" + orderId);
|
|
|
+ }
|
|
|
+ FsUser user = userMapper.selectFsUserByUserId(Long.valueOf(liveOrder.getUserId()));
|
|
|
+ if(user == null) return R.error("用户不存在");
|
|
|
+ String json = configService.selectConfigByKey("store.pay");
|
|
|
+ FsPayConfig fsPayConfig = JSON.parseObject(json, FsPayConfig.class);
|
|
|
+ String payCode = OrderCodeUtils.getOrderSn();
|
|
|
+ if(StringUtils.isEmpty(payCode)){
|
|
|
+ return R.error("订单生成失败,请重试");
|
|
|
+ }
|
|
|
+ LiveOrderPayment storePayment = liveOrderPaymentMapper.selectByBuissnessId(liveOrder.getOrderId());
|
|
|
+ if (storePayment != null) {
|
|
|
+ storePayment.setStatus(1);
|
|
|
+ liveOrderPaymentMapper.updateLiveOrderPayment(storePayment);
|
|
|
+ } else {
|
|
|
+ storePayment = new LiveOrderPayment();
|
|
|
+ storePayment.setStatus(1);
|
|
|
+ storePayment.setPayMode(fsPayConfig.getType());
|
|
|
+ storePayment.setBusinessCode(liveOrder.getOrderCode());
|
|
|
+ storePayment.setPayCode(payCode);
|
|
|
+ storePayment.setPayMoney(liveOrder.getPayMoney());
|
|
|
+// storePayment.setPayMoney(new BigDecimal("0.01"));
|
|
|
+ storePayment.setCreateTime(new Date());
|
|
|
+ storePayment.setPayTypeCode("weixin");
|
|
|
+ storePayment.setBusinessType(5);
|
|
|
+ storePayment.setRemark("直播商品订单支付");
|
|
|
+ storePayment.setOpenId(user.getMaOpenId());
|
|
|
+ storePayment.setUserId(user.getUserId());
|
|
|
+ storePayment.setBusinessId(liveOrder.getOrderId().toString());
|
|
|
+ liveOrderPaymentMapper.insertLiveOrderPayment(storePayment);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (storePayment!=null){
|
|
|
+ if(storePayment.getStatus().equals(0)){
|
|
|
+ LiveOrderPayment paymentMap=new LiveOrderPayment();
|
|
|
+ paymentMap.setPaymentId(storePayment.getPaymentId());
|
|
|
+ paymentMap.setStatus(1);
|
|
|
+ paymentMap.setPayTime(new Date());
|
|
|
+ liveOrderPaymentMapper.updateLiveOrderPayment(paymentMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ log.info("支付单号不存在:"+payCode);
|
|
|
+ throw new CustomException("当前支付记录未找到!");
|
|
|
+ }
|
|
|
+ if(liveOrder.getStatus()!=1){
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return R.error("当前订单未找到或者订单状态不为待支付!");
|
|
|
+ }
|
|
|
+ //增加用户购买次数
|
|
|
+ userMapper.incPayCount(Long.valueOf(liveOrder.getUserId()));
|
|
|
+
|
|
|
+ liveOrder.setStatus(2);
|
|
|
+ liveOrder.setPayTime(LocalDateTime.now());
|
|
|
+ liveUserLotteryRecordMapper.updateOrderStatusByOrderId(liveOrder.getOrderId(), 2);
|
|
|
+ baseMapper.updateLiveOrder(liveOrder);
|
|
|
+ return R.ok("支付成功");
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("抽奖订单支付错误:"+e.getMessage());
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);
|
|
|
+ LiveOrderPaymentError err = new LiveOrderPaymentError();
|
|
|
+ err.setOrderNo(String.valueOf(orderId));
|
|
|
+ err.setStatus(0);
|
|
|
+ err.setMsg("抽奖订单支付错误:"+e.getMessage());
|
|
|
+ err.setCreateTime(DateUtils.getNowDate());
|
|
|
+ liveOrderPaymentErrorMapper.insertLiveOrderPaymentError(err);
|
|
|
+ return R.error("支付失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
@Override
|
|
|
@@ -2287,8 +2496,9 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
|
|
|
Live live = liveMapper.selectLiveByLiveId(liveOrder.getLiveId());
|
|
|
if(live == null) return R.error("当前直播不存在");
|
|
|
- FsStoreProduct fsStoreProduct = fsStoreProductService.selectFsStoreProductById(liveOrder.getProductId());
|
|
|
+ FsStoreProductScrm fsStoreProduct = fsStoreProductService.selectFsStoreProductById(liveOrder.getProductId());
|
|
|
LiveGoods goods = liveGoodsMapper.selectLiveGoodsByProductId(liveOrder.getLiveId(), liveOrder.getProductId());
|
|
|
+ if(goods == null) return R.error("当前商品不存在");
|
|
|
if(fsStoreProduct == null) return R.error("店铺已下架商品,购买失败");
|
|
|
if(fsStoreProduct.getIsShow() == 0 || goods.getStatus() == 0) return R.error("商品已下架,购买失败");
|
|
|
if(fsStoreProduct.getStock() < Integer.parseInt(liveOrder.getTotalNum()) || goods.getStock() < Integer.parseInt(liveOrder.getTotalNum())) return R.error("抱歉,这款商品已被抢光,暂时无库存~");
|
|
|
@@ -2339,12 +2549,14 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
if (!couponUser.getUserId().toString().equals(liveOrder.getUserId())){
|
|
|
return R.error("非法操作");
|
|
|
}
|
|
|
- liveOrder.setUserCouponId(couponUser.getId());
|
|
|
- liveOrder.setDiscountMoney(couponUser.getCouponPrice());
|
|
|
- //更新优惠券状态
|
|
|
- couponUser.setStatus(1);
|
|
|
- couponUser.setUseTime(new Date());
|
|
|
- liveCouponUserService.updateLiveCouponUser(couponUser);
|
|
|
+ if(couponUser.getUseMinPrice().compareTo(payPrice) < 1){
|
|
|
+ liveOrder.setUserCouponId(couponUser.getId());
|
|
|
+ liveOrder.setDiscountMoney(couponUser.getCouponPrice());
|
|
|
+ //更新优惠券状态
|
|
|
+ couponUser.setStatus(1);
|
|
|
+ couponUser.setUseTime(new Date());
|
|
|
+ liveCouponUserService.updateLiveCouponUser(couponUser);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -2362,13 +2574,10 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
LiveOrderItemDTO dto=new LiveOrderItemDTO();
|
|
|
dto.setImage(fsStoreProduct.getImgUrl());
|
|
|
dto.setSku(String.valueOf(fsStoreProduct.getStock()));
|
|
|
- if (StringUtils.isEmpty(fsStoreProduct.getBarCode())) {
|
|
|
- FsStoreProductAttrValue fsStoreProductAttrValue = fsStoreProductAttrValueMapper.selectFsStoreProductAttrValueByProductId(fsStoreProduct.getProductId()).stream().filter(attrValue -> StringUtils.isNotEmpty(attrValue.getBarCode())).findFirst().orElse(null);
|
|
|
- if (fsStoreProductAttrValue != null) {
|
|
|
- dto.setBarCode(fsStoreProductAttrValue.getBarCode());
|
|
|
- }
|
|
|
- } else {
|
|
|
- dto.setBarCode(fsStoreProduct.getBarCode());
|
|
|
+ FsStoreProductAttrValueScrm fsStoreProductAttrValue = fsStoreProductAttrValueMapper.selectFsStoreProductAttrValueByProductId(fsStoreProduct.getProductId()).stream().filter(attrValue -> StringUtils.isNotEmpty(attrValue.getBarCode())).findFirst().orElse(null);
|
|
|
+ if (fsStoreProductAttrValue != null) {
|
|
|
+ dto.setBarCode(fsStoreProductAttrValue.getBarCode());
|
|
|
+ dto.setGroupBarCode(fsStoreProductAttrValue.getGroupBarCode());
|
|
|
}
|
|
|
dto.setPrice(fsStoreProduct.getPrice());
|
|
|
dto.setProductName(fsStoreProduct.getProductName());
|
|
|
@@ -2504,11 +2713,12 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
if(order.getStatus() == 1){
|
|
|
LiveOrder liveOrder = baseMapper.selectLiveOrderByOrderId(String.valueOf(order.getOrderId()));
|
|
|
if(liveOrder == null) return R.error("订单不存在");
|
|
|
+ liveUserLotteryRecordMapper.updateOrderStatusByOrderId(order.getOrderId(), -3);
|
|
|
baseMapper.cancelOrder(order.getOrderId());
|
|
|
liveOrderLogsService.create(order.getOrderId(), OrderLogEnum.CANCEL_ORDER.getValue(),
|
|
|
OrderLogEnum.CANCEL_ORDER.getDesc());
|
|
|
// 恢复库存
|
|
|
- FsStoreProduct fsStoreProduct = fsStoreProductService.selectFsStoreProductById(liveOrder.getProductId());
|
|
|
+ FsStoreProductScrm fsStoreProduct = fsStoreProductService.selectFsStoreProductById(liveOrder.getProductId());
|
|
|
LiveGoods goods = liveGoodsMapper.selectLiveGoodsByProductId(liveOrder.getLiveId(), liveOrder.getProductId());
|
|
|
fsStoreProduct.setStock(fsStoreProduct.getStock()+Integer.parseInt(liveOrder.getTotalNum()));
|
|
|
fsStoreProductService.updateFsStoreProduct(fsStoreProduct);
|