|
@@ -30,7 +30,9 @@ import cn.newfeifan.mall.module.pay.enums.order.PayOrderStatusEnum;
|
|
|
import cn.newfeifan.mall.module.product.api.comment.ProductCommentApi;
|
|
|
import cn.newfeifan.mall.module.product.api.comment.dto.ProductCommentCreateReqDTO;
|
|
|
import cn.newfeifan.mall.module.product.dal.dataobject.sku.ProductSkuDO;
|
|
|
+import cn.newfeifan.mall.module.product.dal.dataobject.spu.ProductSpuDO;
|
|
|
import cn.newfeifan.mall.module.product.dal.mysql.sku.ProductSkuMapper;
|
|
|
+import cn.newfeifan.mall.module.product.dal.mysql.spu.ProductSpuMapper;
|
|
|
import cn.newfeifan.mall.module.sale.dal.dataobject.shop.ShopDO;
|
|
|
import cn.newfeifan.mall.module.sale.dal.mysql.shop.ShopMapper;
|
|
|
import cn.newfeifan.mall.module.system.service.user.AdminUserService;
|
|
@@ -38,6 +40,7 @@ import cn.newfeifan.mall.module.trade.controller.admin.order.vo.TradeOrderDelive
|
|
|
import cn.newfeifan.mall.module.trade.controller.admin.order.vo.TradeOrderRemarkReqVO;
|
|
|
import cn.newfeifan.mall.module.trade.controller.admin.order.vo.TradeOrderUpdateAddressReqVO;
|
|
|
import cn.newfeifan.mall.module.trade.controller.admin.order.vo.TradeOrderUpdatePriceReqVO;
|
|
|
+import cn.newfeifan.mall.module.trade.controller.app.base.property.AppProductPropertyValueDetailRespVO;
|
|
|
import cn.newfeifan.mall.module.trade.controller.app.order.vo.AppTradeOrderCreateReqVO;
|
|
|
import cn.newfeifan.mall.module.trade.controller.app.order.vo.AppTradeOrderSettlementReqVO;
|
|
|
import cn.newfeifan.mall.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO;
|
|
@@ -87,9 +90,10 @@ import static cn.newfeifan.mall.framework.common.exception.util.ServiceException
|
|
|
import static cn.newfeifan.mall.framework.common.util.collection.CollectionUtils.*;
|
|
|
import static cn.newfeifan.mall.framework.common.util.date.LocalDateTimeUtils.minusTime;
|
|
|
import static cn.newfeifan.mall.framework.common.util.servlet.ServletUtils.getClientIP;
|
|
|
+import static cn.newfeifan.mall.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
|
|
import static cn.newfeifan.mall.framework.web.core.util.WebFrameworkUtils.getTerminal;
|
|
|
import static cn.newfeifan.mall.module.trade.enums.ErrorCodeConstants.*;
|
|
|
-
|
|
|
+import static cn.newfeifan.mall.module.trade.enums.delivery.DeliveryTypeEnum.VIRTUAL_PRODUCT;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -102,11 +106,14 @@ import static cn.newfeifan.mall.module.trade.enums.ErrorCodeConstants.*;
|
|
|
@Slf4j
|
|
|
public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
|
|
|
+
|
|
|
@Resource
|
|
|
private IntegralMapper integralMapper;//add by ben 20240411
|
|
|
|
|
|
@Resource
|
|
|
private ProductSkuMapper productSkuMapper;//add by ben 20240314
|
|
|
+ @Resource
|
|
|
+ private ProductSpuMapper productSpuMapper;
|
|
|
|
|
|
@Resource
|
|
|
private ShopMapper shopMapper;//add by ben 20240314
|
|
@@ -163,12 +170,12 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
|
|
|
// =================== Order ===================
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* add by Ben
|
|
|
* 待支付订单,点支付时的新增方法
|
|
|
- * @param tradeOrderId
|
|
|
- * @return
|
|
|
+ *
|
|
|
+ * @param tradeOrderId 订单id
|
|
|
+ * @return 支付订单
|
|
|
*/
|
|
|
public PayOrderDO getPayOrder(Long tradeOrderId) {
|
|
|
|
|
@@ -177,29 +184,28 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
|
|
|
//页面传入的订单
|
|
|
TradeOrderDO orderDO = tradeOrderMapper.selectOne("id", tradeOrderId);
|
|
|
- Long parentPayOrderId = orderDO.getPayOrderId();
|
|
|
+ Long parentPayOrderId = orderDO.getPayOrderId();
|
|
|
|
|
|
//本订单对应的支付订单id,是否是多个订单支付的合并支付订单
|
|
|
List<TradeOrderDO> tradeOrderList = tradeOrderMapper.selectList("pay_order_id", parentPayOrderId);
|
|
|
- if(tradeOrderList.size()==1){//如果一个支付单只对应一个订单,证明不是合并支付订单
|
|
|
+ if (tradeOrderList.size() == 1) {//如果一个支付单只对应一个订单,证明不是合并支付订单
|
|
|
|
|
|
thisPayOrderDO = payOrderMapper.selectById(parentPayOrderId);
|
|
|
// rs = thisPayOrderDO;
|
|
|
- }else if(tradeOrderList.size()>1){//如果一个支付单对应多个订单,证明是合并支付订单,则生成其下级拆分支付的支付单
|
|
|
+ } else if (tradeOrderList.size() > 1) {//如果一个支付单对应多个订单,证明是合并支付订单,则生成其下级拆分支付的支付单
|
|
|
|
|
|
PayOrderDO parentPayOrderDO = payOrderMapper.selectById(parentPayOrderId);
|
|
|
LocalDateTime expireTime = parentPayOrderDO.getExpireTime();//原合并支付订单的过期时间
|
|
|
|
|
|
- for (int i = 0; i < tradeOrderList.size(); i++) {
|
|
|
- TradeOrderDO tradeOrderDO = tradeOrderList.get(i);
|
|
|
+ for (TradeOrderDO tradeOrderDO : tradeOrderList) {
|
|
|
Long tId = tradeOrderDO.getId();
|
|
|
List<TradeOrderItemDO> tradeOrderItemDOS = tradeOrderItemMapper.selectList("order_id", tId);
|
|
|
|
|
|
//创建子支付订单,并且让trade_order记录关联子支付订单
|
|
|
Long childPayOrderId = createChildPayOrder(tradeOrderDO, tradeOrderItemDOS,
|
|
|
- parentPayOrderId,expireTime);
|
|
|
+ parentPayOrderId, expireTime);
|
|
|
|
|
|
- if(tId==tradeOrderId){//如果当前为页面传入的订单
|
|
|
+ if (Objects.equals(tId, tradeOrderId)) {//如果当前为页面传入的订单
|
|
|
thisPayOrderDO = payOrderMapper.selectById(childPayOrderId);
|
|
|
}
|
|
|
}
|
|
@@ -220,68 +226,73 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
@Override
|
|
|
public AppTradeOrderSettlementRespVO settlementOrder(Long userId, AppTradeOrderSettlementReqVO settlementReqVO) {
|
|
|
// 1. 获得收货地址
|
|
|
- MemberAddressRespDTO address = getAddress(userId, settlementReqVO.getAddressId());
|
|
|
+ MemberAddressRespDTO address = getAddress(userId, settlementReqVO.getAddressId(), settlementReqVO.getAddressType());
|
|
|
if (address != null) {
|
|
|
settlementReqVO.setAddressId(address.getId());
|
|
|
}
|
|
|
|
|
|
+ //如果是虚拟商品,则用自己的编写的程序返回
|
|
|
+ if (Objects.equals(settlementReqVO.getDeliveryType(), VIRTUAL_PRODUCT.getType())) {
|
|
|
+ return getSettlement(address, settlementReqVO.getItems());
|
|
|
+ }
|
|
|
+
|
|
|
// add by Ben 20240314
|
|
|
// 4. 查询每个sku对应的店铺ID,并传回页面
|
|
|
List<AppTradeOrderSettlementReqVO.Item> productSkuList = settlementReqVO.getItems();
|
|
|
- List<Long> productSkuIdList = new ArrayList<Long>();
|
|
|
- Map<Long,AppTradeOrderSettlementReqVO.Item> itemMap = new HashMap<Long,AppTradeOrderSettlementReqVO.Item>();
|
|
|
- for(AppTradeOrderSettlementReqVO.Item skuItem : productSkuList){
|
|
|
+ List<Long> productSkuIdList = new ArrayList<>();
|
|
|
+ Map<Long, AppTradeOrderSettlementReqVO.Item> itemMap = new HashMap<>();
|
|
|
+ for (AppTradeOrderSettlementReqVO.Item skuItem : productSkuList) {
|
|
|
productSkuIdList.add(skuItem.getSkuId());
|
|
|
- itemMap.put(skuItem.getSkuId(),skuItem);
|
|
|
+ itemMap.put(skuItem.getSkuId(), skuItem);
|
|
|
}
|
|
|
// 查询每个skuid对应的sku对象
|
|
|
List<ProductSkuDO> productSkuDOList = productSkuMapper.selectListBySKuId(productSkuIdList);
|
|
|
|
|
|
//key为店铺ID,value为skuid的List
|
|
|
- Map<Long,List<Long>> shopSkuIds = new HashMap<Long, List<Long>>();
|
|
|
+ Map<Long, List<Long>> shopSkuIds = new HashMap<>();
|
|
|
//key为店铺ID,value为item的Map
|
|
|
- Map<Long,List<AppTradeOrderSettlementReqVO.Item>> shopSkuItemMap = new HashMap<Long,List<AppTradeOrderSettlementReqVO.Item>>();
|
|
|
+ Map<Long, List<AppTradeOrderSettlementReqVO.Item>> shopSkuItemMap = new HashMap<>();
|
|
|
|
|
|
- for(ProductSkuDO sku:productSkuDOList){//把sku根据店聚合放到map中
|
|
|
+ for (ProductSkuDO sku : productSkuDOList) {//把sku根据店聚合放到map中
|
|
|
Long skuId = sku.getId();
|
|
|
Long shopId = sku.getShopId();
|
|
|
|
|
|
List<AppTradeOrderSettlementReqVO.Item> itemList = shopSkuItemMap.get(shopId);
|
|
|
- if(itemList==null){
|
|
|
- itemList=new ArrayList<AppTradeOrderSettlementReqVO.Item>();
|
|
|
- shopSkuItemMap.put(shopId,itemList);
|
|
|
+ if (itemList == null) {
|
|
|
+ itemList = new ArrayList<>();
|
|
|
+ shopSkuItemMap.put(shopId, itemList);
|
|
|
}
|
|
|
// AppTradeOrderSettlementReqVO.Item item = new AppTradeOrderSettlementReqVO.Item();
|
|
|
itemList.add(itemMap.get(skuId));
|
|
|
|
|
|
List<Long> shopSkuList = shopSkuIds.get(shopId);
|
|
|
- if(shopSkuList==null) {
|
|
|
- shopSkuList = new ArrayList<Long>();
|
|
|
- shopSkuIds.put(shopId,shopSkuList);
|
|
|
+ if (shopSkuList == null) {
|
|
|
+ shopSkuList = new ArrayList<>();
|
|
|
+ shopSkuIds.put(shopId, shopSkuList);
|
|
|
}
|
|
|
shopSkuList.add(skuId);//把sku根据店聚合放到map中
|
|
|
}
|
|
|
|
|
|
|
|
|
//把店铺id和店铺名称查出来放到map中
|
|
|
- List<Long> shopIds = new ArrayList<Long>();
|
|
|
+ List<Long> shopIds = new ArrayList<>();
|
|
|
for (Long shopid : shopSkuIds.keySet()) {
|
|
|
shopIds.add(shopid);
|
|
|
}
|
|
|
List<ShopDO> shopDOList = shopMapper.selectListById(shopIds);
|
|
|
- Map<Long,String> shopNameMap = new HashMap<Long,String>();//key为店铺id,value为店铺名
|
|
|
+ Map<Long, String> shopNameMap = new HashMap<>();//key为店铺id,value为店铺名
|
|
|
for (ShopDO shopDO : shopDOList) {
|
|
|
- shopNameMap.put(shopDO.getId(),shopDO.getName());
|
|
|
+ shopNameMap.put(shopDO.getId(), shopDO.getName());
|
|
|
}
|
|
|
|
|
|
// 2. 计算价格
|
|
|
- /**
|
|
|
- * add by Ben 20240402
|
|
|
- * 原来下面的代码中是取settlementReqVO.getItems()的所有项计算的,其中Items含不同店铺的商品,现在要把不同店铺的商品分开计算
|
|
|
- *
|
|
|
+ /*
|
|
|
+ add by Ben 20240402
|
|
|
+ 原来下面的代码中是取settlementReqVO.getItems()的所有项计算的,其中Items含不同店铺的商品,现在要把不同店铺的商品分开计算
|
|
|
+
|
|
|
*/
|
|
|
//保存每个店铺返回页面的 订单信息汇总
|
|
|
- Map<Long,AppTradeOrderSettlementRespVO> shopRespVOMap = new HashMap<Long,AppTradeOrderSettlementRespVO>();
|
|
|
+ Map<Long, AppTradeOrderSettlementRespVO> shopRespVOMap = new HashMap<>();
|
|
|
//所有店铺支付总价
|
|
|
Integer allShopPayPrice = 0;
|
|
|
//所有店商品不算运费的商品总价
|
|
@@ -290,7 +301,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
Integer allShopDeliveryPrice = 0;
|
|
|
|
|
|
//循环计算各个店铺的价格
|
|
|
- for(Long shopId:shopSkuItemMap.keySet()){
|
|
|
+ for (Long shopId : shopSkuItemMap.keySet()) {
|
|
|
List<AppTradeOrderSettlementReqVO.Item> items = shopSkuItemMap.get(shopId);
|
|
|
AppTradeOrderSettlementReqVO shopSettlementReqVO = new AppTradeOrderSettlementReqVO();
|
|
|
BeanUtils.copyProperties(settlementReqVO, shopSettlementReqVO);
|
|
@@ -301,7 +312,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
TradePriceCalculateRespBO shopCalculateRespBO = calculatePrice(userId, shopSettlementReqVO);
|
|
|
// 3. 拼接返回
|
|
|
AppTradeOrderSettlementRespVO respVO = TradeOrderConvert.INSTANCE.convert(shopCalculateRespBO, address);
|
|
|
- shopRespVOMap.put(shopId,respVO);
|
|
|
+ shopRespVOMap.put(shopId, respVO);
|
|
|
|
|
|
//所有店铺支付总价
|
|
|
allShopPayPrice += shopCalculateRespBO.getPrice().getPayPrice();
|
|
@@ -330,7 +341,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
AppTradeOrderSettlementRespVO respVO = TradeOrderConvert.INSTANCE.convert(calculateRespBO, address);
|
|
|
|
|
|
//把重复的收货地址置为空
|
|
|
- for(Long shopId:shopRespVOMap.keySet()){
|
|
|
+ for (Long shopId : shopRespVOMap.keySet()) {
|
|
|
AppTradeOrderSettlementRespVO a = shopRespVOMap.get(shopId);
|
|
|
a.setAddress(null);
|
|
|
}
|
|
@@ -347,18 +358,129 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
return respVO;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 虚拟商品自走程序
|
|
|
+ *
|
|
|
+ * @param address
|
|
|
+ * @param items 商品项数组
|
|
|
+ * @return AppTradeOrderSettlementRespVO
|
|
|
+ */
|
|
|
+ private AppTradeOrderSettlementRespVO getSettlement(MemberAddressRespDTO address, List<AppTradeOrderSettlementReqVO.Item> items) {
|
|
|
+
|
|
|
+ // 4. 查询每个sku对应的店铺ID,并传回页面
|
|
|
+ List<AppTradeOrderSettlementReqVO.Item> productSkuList = items;
|
|
|
+ List<Long> productSkuIdList = new ArrayList<>();
|
|
|
+ Map<Long, AppTradeOrderSettlementReqVO.Item> itemMap = new HashMap<>();
|
|
|
+ for (AppTradeOrderSettlementReqVO.Item skuItem : productSkuList) {
|
|
|
+ productSkuIdList.add(skuItem.getSkuId());
|
|
|
+ itemMap.put(skuItem.getSkuId(), skuItem);
|
|
|
+ }
|
|
|
+ // 查询每个skuid对应的sku对象
|
|
|
+ List<ProductSkuDO> productSkuDOList = productSkuMapper.selectListBySKuId(productSkuIdList);
|
|
|
+
|
|
|
+ //key为店铺ID,value为skuid的List
|
|
|
+ Map<Long, List<Long>> shopSkuIds = new HashMap<>();
|
|
|
+ //key为店铺ID,value为item的Map
|
|
|
+ Map<Long, List<AppTradeOrderSettlementReqVO.Item>> shopSkuItemMap = new HashMap<>();
|
|
|
+
|
|
|
+ for (ProductSkuDO sku : productSkuDOList) {//把sku根据店聚合放到map中
|
|
|
+ Long skuId = sku.getId();
|
|
|
+ Long shopId = sku.getShopId();
|
|
|
+
|
|
|
+ List<AppTradeOrderSettlementReqVO.Item> itemList = shopSkuItemMap.get(shopId);
|
|
|
+ if (itemList == null) {
|
|
|
+ itemList = new ArrayList<>();
|
|
|
+ shopSkuItemMap.put(shopId, itemList);
|
|
|
+ }
|
|
|
+// AppTradeOrderSettlementReqVO.Item item = new AppTradeOrderSettlementReqVO.Item();
|
|
|
+ itemList.add(itemMap.get(skuId));
|
|
|
+
|
|
|
+ List<Long> shopSkuList = shopSkuIds.get(shopId);
|
|
|
+ if (shopSkuList == null) {
|
|
|
+ shopSkuList = new ArrayList<>();
|
|
|
+ shopSkuIds.put(shopId, shopSkuList);
|
|
|
+ }
|
|
|
+ shopSkuList.add(skuId);//把sku根据店聚合放到map中
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //把店铺id和店铺名称查出来放到map中
|
|
|
+ List<Long> shopIds = new ArrayList<>();
|
|
|
+ for (Long shopid : shopSkuIds.keySet()) {
|
|
|
+ shopIds.add(shopid);
|
|
|
+ }
|
|
|
+ List<ShopDO> shopDOList = shopMapper.selectListById(shopIds);
|
|
|
+ Map<Long, String> shopNameMap = new HashMap<>();//key为店铺id,value为店铺名
|
|
|
+ for (ShopDO shopDO : shopDOList) {
|
|
|
+ shopNameMap.put(shopDO.getId(), shopDO.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ AppTradeOrderSettlementRespVO respVO = new AppTradeOrderSettlementRespVO();
|
|
|
+ respVO.setShopNameMap(shopNameMap);
|
|
|
+ respVO.setShopSkuIds(shopSkuIds);
|
|
|
+ IntegralDO integralDO = integralMapper.selectOne("user_id", getLoginUserId());//查询出用户积分相关信息
|
|
|
+ Long currentQuota = integralDO.getCurrentQuota();//获取用户当前积分
|
|
|
+ respVO.setCurrentQuota(currentQuota);
|
|
|
+
|
|
|
+ //保存每个店铺返回页面的 订单信息汇总
|
|
|
+ Map<Long, AppTradeOrderSettlementRespVO> shopRespVOMap = new HashMap<>();
|
|
|
+ //所有店铺支付总价
|
|
|
+ AppTradeOrderSettlementRespVO.Price shopCalculateRespBO = new AppTradeOrderSettlementRespVO.Price();
|
|
|
+
|
|
|
+ //循环计算各个店铺的价格
|
|
|
+ for (Long shopId : shopSkuItemMap.keySet()) {
|
|
|
+ List<AppTradeOrderSettlementReqVO.Item> orderItems = shopSkuItemMap.get(shopId);
|
|
|
+
|
|
|
+ AppTradeOrderSettlementRespVO respVO2 = new AppTradeOrderSettlementRespVO();
|
|
|
+ respVO2.setPrice(shopCalculateRespBO);
|
|
|
+ AppTradeOrderSettlementRespVO.Item item = new AppTradeOrderSettlementRespVO.Item();
|
|
|
+ ProductSkuDO sku = productSkuMapper.selectById(orderItems.get(0).getSkuId());
|
|
|
+ ProductSpuDO spu = productSpuMapper.selectById(sku.getSpuId());
|
|
|
+ item.setPrice(sku.getPrice());
|
|
|
+ item.setHighPrecisionPrice(sku.getHighPrecisionPrice());
|
|
|
+ item.setCount(orderItems.get(0).getCount());
|
|
|
+ item.setPicUrl(sku.getPicUrl());
|
|
|
+ item.setSpuId(sku.getSpuId());
|
|
|
+ item.setSkuId(sku.getId().intValue());
|
|
|
+ item.setSpuName(spu.getName());
|
|
|
+ item.setCategoryId(spu.getCategoryId());
|
|
|
+ List<ProductSkuDO.Property> properties = sku.getProperties();
|
|
|
+ item.setProperties(cn.newfeifan.mall.framework.common.util.object.BeanUtils.toBean(properties, AppProductPropertyValueDetailRespVO.class));
|
|
|
+
|
|
|
+ respVO2.setItems(Arrays.asList(item));
|
|
|
+ //计算价格
|
|
|
+ shopRespVOMap.put(shopId, respVO2);
|
|
|
+ shopCalculateRespBO.setVirtualPayPrice(sku.getHighPrecisionPrice().doubleValue() * orderItems.get(0).getCount());
|
|
|
+ shopCalculateRespBO.setVirtualTotalPrice(sku.getHighPrecisionPrice().doubleValue() * orderItems.get(0).getCount());
|
|
|
+ shopCalculateRespBO.setPayPrice((int) sku.getHighPrecisionPrice().doubleValue() * orderItems.get(0).getCount());
|
|
|
+ shopCalculateRespBO.setTotalPrice((int) sku.getHighPrecisionPrice().doubleValue() * orderItems.get(0).getCount());
|
|
|
+ }
|
|
|
+
|
|
|
+ //把重复的收货地址置为空
|
|
|
+ for (Long shopId : shopRespVOMap.keySet()) {
|
|
|
+ AppTradeOrderSettlementRespVO a = shopRespVOMap.get(shopId);
|
|
|
+ a.setAddress(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ respVO.setShopRespVOMap(shopRespVOMap);
|
|
|
+ respVO.setPrice(shopCalculateRespBO);
|
|
|
+ respVO.setAddress(cn.newfeifan.mall.framework.common.util.object.BeanUtils.toBean(address, AppTradeOrderSettlementRespVO.Address.class));
|
|
|
+ return respVO;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获得用户地址
|
|
|
*
|
|
|
- * @param userId 用户编号
|
|
|
- * @param addressId 地址编号
|
|
|
+ * @param userId 用户编号
|
|
|
+ * @param addressId 地址编号
|
|
|
+ * @param addressType 地址类别
|
|
|
* @return 地址
|
|
|
*/
|
|
|
- private MemberAddressRespDTO getAddress(Long userId, Long addressId) {
|
|
|
+ private MemberAddressRespDTO getAddress(Long userId, Long addressId, Integer addressType) {
|
|
|
if (addressId != null) {
|
|
|
- return addressApi.getAddress(addressId, userId);
|
|
|
+ return addressApi.getAddress(addressId, userId, addressType);
|
|
|
}
|
|
|
- return addressApi.getDefaultAddress(userId);
|
|
|
+ return addressApi.getDefaultAddress(userId, addressType);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -383,7 +505,6 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* add by Ben
|
|
|
* 计算订单含积分的各项商品价格
|
|
@@ -407,18 +528,18 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
}
|
|
|
|
|
|
//把数据库的钱转换为数据库的积分
|
|
|
- public static BigDecimal money2Integral(BigDecimal money){
|
|
|
+ public static BigDecimal money2Integral(BigDecimal money) {
|
|
|
return money.multiply(DistriConstants.MONEY2INTEGRAL_BIG_DECIMAL);
|
|
|
}
|
|
|
|
|
|
//把数据库的钱转换为数据库的积分
|
|
|
- public static Long money2Integral(Integer money){
|
|
|
- return Long.valueOf(money*DistriConstants.MONEY2INTEGRAL);
|
|
|
+ public static Long money2Integral(Integer money) {
|
|
|
+ return Long.valueOf(money * DistriConstants.MONEY2INTEGRAL);
|
|
|
}
|
|
|
|
|
|
//把数据库的积分转换为数据库的钱
|
|
|
- public static Integer integral2Money(Long integral){
|
|
|
- Long l = (integral/DistriConstants.MONEY2INTEGRAL);
|
|
|
+ public static Integer integral2Money(Long integral) {
|
|
|
+ Long l = (integral / DistriConstants.MONEY2INTEGRAL);
|
|
|
return l.intValue();
|
|
|
}
|
|
|
|
|
@@ -431,23 +552,23 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
//查询订单提成比例
|
|
|
QueryWrapper<OrderPercentageDO> queryWrapper = new QueryWrapper<>();
|
|
|
OrderPercentageDO orderPercentageDO = orderPercentageMapper.selectOne(queryWrapper);//表中只有一条记录
|
|
|
- /**
|
|
|
+ /*
|
|
|
* 毛利 = 成本 * 0.38... (推广费用)
|
|
|
*/
|
|
|
String grossProfitPerc = orderPercentageDO.getGrossProfitPerc();
|
|
|
float grossProfitPercFloat = Float.parseFloat(grossProfitPerc);
|
|
|
- if(grossProfitPercFloat>1){
|
|
|
- throw new RuntimeException("商品毛利值,占利润比例异常,达到"+grossProfitPerc+"!!");
|
|
|
+ if (grossProfitPercFloat > 1) {
|
|
|
+ throw new RuntimeException("商品毛利值,占利润比例异常,达到" + grossProfitPerc + "!!");
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
+ /*
|
|
|
* 购物本人自得 百分比
|
|
|
*/
|
|
|
String grossProfitUserQuotaPerc = orderPercentageDO.getGrossProfitUserQuotaPerc();
|
|
|
float grossProfitUserQuotaPercFloat = Float.parseFloat(grossProfitUserQuotaPerc);
|
|
|
- if(grossProfitUserQuotaPercFloat>0.5){
|
|
|
- throw new RuntimeException("消费本人获得积分,占毛利比例异常,达到"+grossProfitUserQuotaPerc+"!!");
|
|
|
+ if (grossProfitUserQuotaPercFloat > 0.5) {
|
|
|
+ throw new RuntimeException("消费本人获得积分,占毛利比例异常,达到" + grossProfitUserQuotaPerc + "!!");
|
|
|
}
|
|
|
|
|
|
//校验最大值 end
|
|
@@ -457,43 +578,42 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
// 4. 查询每个sku对应的店铺ID,并传回页面
|
|
|
List<AppTradeOrderSettlementReqVO.Item> productSkuList = createReqVO.getItems();
|
|
|
// 把所有商品的id都取出来,为查询所有商品的店铺做准备
|
|
|
- List<Long> productSkuIdList = new ArrayList<Long>();
|
|
|
- Map<Long,AppTradeOrderSettlementReqVO.Item> itemMap = new HashMap<Long,AppTradeOrderSettlementReqVO.Item>();
|
|
|
- for(AppTradeOrderSettlementReqVO.Item skuItem : productSkuList){
|
|
|
+ List<Long> productSkuIdList = new ArrayList<>();
|
|
|
+ Map<Long, AppTradeOrderSettlementReqVO.Item> itemMap = new HashMap<>();
|
|
|
+ for (AppTradeOrderSettlementReqVO.Item skuItem : productSkuList) {
|
|
|
productSkuIdList.add(skuItem.getSkuId());
|
|
|
- itemMap.put(skuItem.getSkuId(),skuItem);
|
|
|
+ itemMap.put(skuItem.getSkuId(), skuItem);
|
|
|
}
|
|
|
// 查询每个skuid对应的sku对象
|
|
|
List<ProductSkuDO> productSkuDOList = productSkuMapper.selectListBySKuId(productSkuIdList);
|
|
|
|
|
|
- Map<Long,Long> shopMerchantMap = new HashMap<Long,Long>();//key是店铺ID,value是商户ID
|
|
|
- for(ProductSkuDO productSkuDO:productSkuDOList){
|
|
|
- shopMerchantMap.put(productSkuDO.getShopId(),productSkuDO.getMerchantId());
|
|
|
+ Map<Long, Long> shopMerchantMap = new HashMap<>();//key是店铺ID,value是商户ID
|
|
|
+ for (ProductSkuDO productSkuDO : productSkuDOList) {
|
|
|
+ shopMerchantMap.put(productSkuDO.getShopId(), productSkuDO.getMerchantId());
|
|
|
}
|
|
|
|
|
|
//key为店铺ID,value为skuid的List
|
|
|
- Map<Long,List<Long>> shopSkuIds = new HashMap<Long, List<Long>>();
|
|
|
+ Map<Long, List<Long>> shopSkuIds = new HashMap<>();
|
|
|
//key为店铺ID,value为item的Map
|
|
|
- Map<Long,List<AppTradeOrderSettlementReqVO.Item>> shopSkuItemMap = new HashMap<Long,List<AppTradeOrderSettlementReqVO.Item>>();
|
|
|
-
|
|
|
+ Map<Long, List<AppTradeOrderSettlementReqVO.Item>> shopSkuItemMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
- for(ProductSkuDO sku:productSkuDOList){//把sku根据店聚合放到map中
|
|
|
+ for (ProductSkuDO sku : productSkuDOList) {//把sku根据店聚合放到map中
|
|
|
Long skuId = sku.getId();
|
|
|
Long shopId = sku.getShopId();
|
|
|
|
|
|
List<AppTradeOrderSettlementReqVO.Item> itemList = shopSkuItemMap.get(shopId);
|
|
|
- if(itemList==null){
|
|
|
- itemList=new ArrayList<AppTradeOrderSettlementReqVO.Item>();
|
|
|
- shopSkuItemMap.put(shopId,itemList);
|
|
|
+ if (itemList == null) {
|
|
|
+ itemList = new ArrayList<>();
|
|
|
+ shopSkuItemMap.put(shopId, itemList);
|
|
|
}
|
|
|
// AppTradeOrderSettlementReqVO.Item item = new AppTradeOrderSettlementReqVO.Item();
|
|
|
itemList.add(itemMap.get(skuId));
|
|
|
|
|
|
List<Long> shopSkuList = shopSkuIds.get(shopId);
|
|
|
- if(shopSkuList==null) {
|
|
|
- shopSkuList = new ArrayList<Long>();
|
|
|
- shopSkuIds.put(shopId,shopSkuList);
|
|
|
+ if (shopSkuList == null) {
|
|
|
+ shopSkuList = new ArrayList<>();
|
|
|
+ shopSkuIds.put(shopId, shopSkuList);
|
|
|
}
|
|
|
shopSkuList.add(skuId);//把sku根据店聚合放到map中
|
|
|
}
|
|
@@ -501,18 +621,18 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
|
|
|
//add by Ben
|
|
|
//为键值对,键为店铺ID,值为备注文本
|
|
|
- Map<Long,String> shopRemarks = createReqVO.getShopRemarks();
|
|
|
- if(shopRemarks==null){
|
|
|
- shopRemarks = new HashMap<Long,String>();
|
|
|
+ Map<Long, String> shopRemarks = createReqVO.getShopRemarks();
|
|
|
+ if (shopRemarks == null) {
|
|
|
+ shopRemarks = new HashMap<>();
|
|
|
}
|
|
|
|
|
|
//消费者在页面录入的,要使用的积分
|
|
|
- Long payPoints = createReqVO.getPayIntegral();
|
|
|
+ Double payPoints = createReqVO.getPayIntegral();
|
|
|
|
|
|
- if(payPoints == null){
|
|
|
- payPoints = 0l;
|
|
|
- }else{//把页面传入的,1积分=1元钱的积分,转换为后台保存到数据库的积分值
|
|
|
- payPoints = payPoints* DistriConstants.INTEGRAL_PAGE2DB;
|
|
|
+ if (payPoints == null) {
|
|
|
+ payPoints = (double) 0;
|
|
|
+ } else {//把页面传入的,1积分=1元钱的积分,转换为后台保存到数据库的积分值
|
|
|
+ payPoints = payPoints * DistriConstants.INTEGRAL_PAGE2DB;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -521,9 +641,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
//计算订单含积分的各项商品价格
|
|
|
TradePriceCalculateRespBO tradePriceCalculateRespBO = calculatePriceWithPoints(userId, createReqVO);
|
|
|
//计算分摊的积分金额
|
|
|
- List<Integer> dividePoints = TradePriceCalculatorHelper.dividePrice(tradePriceCalculateRespBO.getItems(), integral2Money(payPoints));
|
|
|
+ List<Integer> dividePoints = TradePriceCalculatorHelper.dividePrice(tradePriceCalculateRespBO.getItems(), integral2Money(payPoints.longValue()));
|
|
|
//键为skuId,value为单个商品项信息
|
|
|
- Map<Long, TradePriceCalculateRespBO.OrderItem> itemPayPointsMap = new HashMap<Long, TradePriceCalculateRespBO.OrderItem>();
|
|
|
+ Map<Long, TradePriceCalculateRespBO.OrderItem> itemPayPointsMap = new HashMap<>();
|
|
|
|
|
|
//订单项数组
|
|
|
List<TradePriceCalculateRespBO.OrderItem> priceOrderItems = tradePriceCalculateRespBO.getItems();
|
|
@@ -531,16 +651,16 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
TradePriceCalculateRespBO.OrderItem orderItem = priceOrderItems.get(i);
|
|
|
Long itemPoint = money2Integral(dividePoints.get(i));//每项商品使用的积分
|
|
|
orderItem.setPayPoints(itemPoint);
|
|
|
- itemPayPointsMap.put(orderItem.getSkuId(),orderItem);
|
|
|
+ itemPayPointsMap.put(orderItem.getSkuId(), orderItem);
|
|
|
}
|
|
|
|
|
|
Integer allShopPayRMB = 0;//所有店铺订单实际支付的金额
|
|
|
|
|
|
- List<Map<String,Object>> orderMapList = new ArrayList<Map<String,Object>>();
|
|
|
+ List<Map<String, Object>> orderMapList = new ArrayList<>();
|
|
|
|
|
|
//循环调用原来的计算订单价格方法,计算价格
|
|
|
//循环一次生成一间店的订单
|
|
|
- for(Long shopId:shopSkuItemMap.keySet()){
|
|
|
+ for (Long shopId : shopSkuItemMap.keySet()) {
|
|
|
|
|
|
AppTradeOrderCreateReqVO shopCreateReqVO = new AppTradeOrderCreateReqVO();
|
|
|
|
|
@@ -558,6 +678,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
TradeOrderDO order = buildTradeOrder(userId, shopCreateReqVO, calculateRespBO);
|
|
|
List<TradeOrderItemDO> orderItems = buildTradeOrderItems(order, calculateRespBO);
|
|
|
|
|
|
+ for (TradeOrderItemDO orderItem : orderItems) {
|
|
|
+ ProductSkuDO productSkuDO = productSkuMapper.selectById(orderItem.getSkuId());
|
|
|
+ orderItem.setHighPrecisionPrice(productSkuDO.getHighPrecisionPrice());
|
|
|
+ }
|
|
|
+
|
|
|
// 2. 订单创建前的逻辑
|
|
|
//修改sku库存
|
|
|
tradeProductSkuOrderHandler.beforeOrderCreate(order, orderItems);
|
|
@@ -565,10 +690,10 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
// tradeOrderHandlers.forEach(handler -> handler.beforeOrderCreate(order, orderItems));
|
|
|
|
|
|
// 3. 保存一间店铺的订单
|
|
|
- Long shopPayPoints = 0l;//一间店铺订单总支付积分
|
|
|
+ Long shopPayPoints = 0L;//一间店铺订单总支付积分
|
|
|
Integer shopPayPrice = 0;//一间店铺订单总支付价格
|
|
|
|
|
|
- for(TradeOrderItemDO orderItem:orderItems){//一间店铺订单的所有商品项
|
|
|
+ for (TradeOrderItemDO orderItem : orderItems) {//一间店铺订单的所有商品项
|
|
|
// orderItem.setOrderId(order.getId());
|
|
|
|
|
|
//3.5 add by Ben
|
|
@@ -576,7 +701,20 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
Long skuId = orderItem.getSkuId();
|
|
|
TradePriceCalculateRespBO.OrderItem orderItemTmp = itemPayPointsMap.get(skuId);
|
|
|
orderItem.setPayIntegral(orderItemTmp.getPayPoints()); //本商品使用积分
|
|
|
- Integer payRmb = orderItem.getPrice()*orderItem.getCount()-integral2Money(orderItemTmp.getPayPoints());//本商品实付人民币
|
|
|
+ Integer payRmb;
|
|
|
+ if (orderItem.getHighPrecisionPrice() == null) {
|
|
|
+ payRmb = orderItem.getPrice() * orderItem.getCount() - integral2Money(orderItemTmp.getPayPoints());//本商品实付人民币
|
|
|
+ } else {
|
|
|
+ double rmb = (orderItem.getHighPrecisionPrice().doubleValue() * orderItem.getCount()) - integral2Money(orderItemTmp.getPayPoints());
|
|
|
+ if (rmb > 0 && rmb < 1) {
|
|
|
+ payRmb = 1;
|
|
|
+ }else{
|
|
|
+ double multiplied = rmb * 10;
|
|
|
+ // 对乘以10后的数使用 Math.ceil() 向上取整
|
|
|
+ double roundedUp = Math.ceil(multiplied);
|
|
|
+ payRmb = (int)(roundedUp/10.0);
|
|
|
+ }
|
|
|
+ }
|
|
|
orderItem.setPayRmb(payRmb);//本商品实付人民币
|
|
|
orderItem.setPayPrice(payRmb);//本商品实付人民币
|
|
|
|
|
@@ -584,9 +722,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
shopPayPrice += payRmb;//一间店铺订单总支付价格
|
|
|
}
|
|
|
|
|
|
- shopPayPrice+=order.getDeliveryPrice();//店铺支付总金额,加上运费
|
|
|
+ shopPayPrice += order.getDeliveryPrice();//店铺支付总金额,加上运费
|
|
|
|
|
|
- allShopPayRMB +=shopPayPrice;
|
|
|
+ allShopPayRMB += shopPayPrice;
|
|
|
|
|
|
Long merchantId = shopMerchantMap.get(shopId);//商户ID
|
|
|
|
|
@@ -594,7 +732,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
order.setShopId(shopId);
|
|
|
order.setPayPrice(shopPayPrice);
|
|
|
order.setPayRmb(shopPayPrice);
|
|
|
- order.setPayIntegral(shopPayPoints);
|
|
|
+ order.setPayIntegral(shopPayPoints.doubleValue());
|
|
|
|
|
|
tradeOrderMapper.insert(order);
|
|
|
|
|
@@ -605,46 +743,46 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
afterCreateTradeOrder(order, orderItems, shopCreateReqVO);
|
|
|
|
|
|
// Map<>
|
|
|
- Map<String,Object> orderMap = new HashMap<String,Object>();
|
|
|
- orderMap.put("order",order);
|
|
|
- orderMap.put("orderItems",orderItems);
|
|
|
+ Map<String, Object> orderMap = new HashMap<>();
|
|
|
+ orderMap.put("order", order);
|
|
|
+ orderMap.put("orderItems", orderItems);
|
|
|
orderMapList.add(orderMap);//把订单保存起来,为支付订单做准备
|
|
|
}
|
|
|
|
|
|
TradeOrderDO virtualOrder = new TradeOrderDO();//为了生成支付订单,创建的虚拟订单,本订单不会保存到数据库
|
|
|
- TradeOrderDO firstOrder = (TradeOrderDO)(orderMapList.get(0).get("order"));
|
|
|
- List<TradeOrderItemDO> firstOrderItems = (List<TradeOrderItemDO>)(orderMapList.get(0).get("orderItems"));
|
|
|
+ TradeOrderDO firstOrder = (TradeOrderDO) (orderMapList.get(0).get("order"));
|
|
|
+ List<TradeOrderItemDO> firstOrderItems = (List<TradeOrderItemDO>) (orderMapList.get(0).get("orderItems"));
|
|
|
|
|
|
BeanUtils.copyProperties(firstOrder, virtualOrder);
|
|
|
virtualOrder.setPayPrice(allShopPayRMB);
|
|
|
virtualOrder.setPayRmb(allShopPayRMB);
|
|
|
|
|
|
Integer shopCount = shopSkuIds.keySet().size();//订单对应的店铺数目
|
|
|
- if(shopCount>1) {//如果多店铺拆分订单,则支付订单的商户订单id为0
|
|
|
- virtualOrder.setId(0l);//为了让payOrder中的tradeOrderId为0;
|
|
|
- } else if (shopCount==1) {
|
|
|
+ if (shopCount > 1) {//如果多店铺拆分订单,则支付订单的商户订单id为0
|
|
|
+ virtualOrder.setId(0L);//为了让payOrder中的tradeOrderId为0;
|
|
|
+ } else if (shopCount == 1) {
|
|
|
virtualOrder.setId(firstOrder.getId());//为了指定payOrder中的tradeOrderId;
|
|
|
- }else{
|
|
|
- throw new RuntimeException("订单id"+firstOrder.getId()+",对应一间店铺都没");
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("订单id" + firstOrder.getId() + ",对应一间店铺都没");
|
|
|
}
|
|
|
|
|
|
// 3. 生成预支付:生成支付订单记录
|
|
|
Long payOrderId = createPayOrder(virtualOrder, firstOrderItems);
|
|
|
|
|
|
- for(Map<String,Object> m:orderMapList){
|
|
|
- TradeOrderDO order = (TradeOrderDO)(m.get("order"));
|
|
|
+ for (Map<String, Object> m : orderMapList) {
|
|
|
+ TradeOrderDO order = (TradeOrderDO) (m.get("order"));
|
|
|
// 更新到交易单上
|
|
|
tradeOrderMapper.updateById(new TradeOrderDO().setId(order.getId()).setPayOrderId(payOrderId));
|
|
|
}
|
|
|
|
|
|
//如果订单有使用积分,则抵扣用户的积分。add by Ben
|
|
|
- if(payPoints>0){
|
|
|
- for(Map<String,Object> m:orderMapList) {
|
|
|
+ if (payPoints > 0) {
|
|
|
+ for (Map<String, Object> m : orderMapList) {
|
|
|
TradeOrderDO order = (TradeOrderDO) (m.get("order"));
|
|
|
Long tradeOrderId = order.getId();
|
|
|
- String OrderNum =order.getNo();
|
|
|
- Long payIntegral = order.getPayIntegral();//每个订单使用的积分
|
|
|
- integralService.updateUserIntegral(userId, CaclEnum.ORDER_PAY_INTEGRAL, payIntegral * (-1), 0l, tradeOrderId, OrderNum);
|
|
|
+ String OrderNum = order.getNo();
|
|
|
+ Long payIntegral = order.getPayIntegral().longValue();//每个订单使用的积分
|
|
|
+ integralService.updateUserIntegral(userId, userId, CaclEnum.ORDER_PAY_INTEGRAL, payIntegral * (-1), 0L, tradeOrderId, OrderNum);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -716,22 +854,28 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
return virtualOrder;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * 把商品的推广费总额,转换为直推人获得的冻结积分
|
|
|
+ * 把商品的推广费总额,转换为消费者本人(直推人)、或消费者的推荐人 获得的冻结积分
|
|
|
+ *
|
|
|
* @param promotionExpenses 商品的推广费总额
|
|
|
+ * @param grossProfitPerc 推荐人/消费者本人额度 百分比
|
|
|
* @return 输入推广费,对应的直推人获得的冻结积分
|
|
|
*/
|
|
|
public static Long promotionExpenses2GrossProfitAncestorQuota(
|
|
|
+ /*
|
|
|
+ 商品的推广费总额
|
|
|
+ */
|
|
|
Integer promotionExpenses,
|
|
|
- /**
|
|
|
+ /*
|
|
|
* 毛利 = 成本 * 0.38... (推广费用)
|
|
|
*/
|
|
|
String grossProfitPerc,
|
|
|
- /**
|
|
|
- * 推广-推荐人额度 百分比
|
|
|
+ /*
|
|
|
+ * 推广-推荐人/消费者本人额度 百分比
|
|
|
*/
|
|
|
String grossProfitAncestorQuotaPerc
|
|
|
- ){
|
|
|
+ ) {
|
|
|
|
|
|
//转为BigDecimal
|
|
|
BigDecimal profit = new BigDecimal(String.valueOf(promotionExpenses));
|
|
@@ -766,13 +910,17 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
// 物流信息
|
|
|
order.setDeliveryType(createReqVO.getDeliveryType());
|
|
|
if (Objects.equals(createReqVO.getDeliveryType(), DeliveryTypeEnum.EXPRESS.getType())) {
|
|
|
- MemberAddressRespDTO address = addressApi.getAddress(createReqVO.getAddressId(), userId);
|
|
|
+ MemberAddressRespDTO address = addressApi.getAddress(createReqVO.getAddressId(), userId, 1);
|
|
|
Assert.notNull(address, "地址({}) 不能为空", createReqVO.getAddressId()); // 价格计算时,已经计算
|
|
|
order.setReceiverName(address.getName()).setReceiverMobile(address.getMobile())
|
|
|
.setReceiverAreaId(address.getAreaId()).setReceiverDetailAddress(address.getDetailAddress());
|
|
|
} else if (Objects.equals(createReqVO.getDeliveryType(), DeliveryTypeEnum.PICK_UP.getType())) {
|
|
|
order.setReceiverName(createReqVO.getReceiverName()).setReceiverMobile(createReqVO.getReceiverMobile());
|
|
|
order.setPickUpVerifyCode(RandomUtil.randomNumbers(8)); // 随机一个核销码,长度为 8 位
|
|
|
+ } else if (Objects.equals(createReqVO.getDeliveryType(), VIRTUAL_PRODUCT.getType())) {
|
|
|
+ MemberAddressRespDTO address = addressApi.getAddress(createReqVO.getAddressId(), userId, 2);
|
|
|
+ order.setReceiverName(address.getName()).setReceiverMobile(address.getMobile())
|
|
|
+ .setReceiverDetailAddress(address.getDetailAddress());
|
|
|
}
|
|
|
return order;
|
|
|
}
|
|
@@ -816,14 +964,15 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
|
|
|
/**
|
|
|
* 创建子支付订单
|
|
|
- * @param order
|
|
|
- * @param orderItems
|
|
|
- * @param parentPayOrderId 父级支付订单id
|
|
|
- * @param expireTime 支付过期时间
|
|
|
- * @return
|
|
|
+ *
|
|
|
+ * @param order 订单
|
|
|
+ * @param orderItems 订单详情
|
|
|
+ * @param parentPayOrderId 父级支付订单id
|
|
|
+ * @param expireTime 支付过期时间
|
|
|
+ * @return 支付订单ID
|
|
|
*/
|
|
|
private Long createChildPayOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems,
|
|
|
- Long parentPayOrderId,LocalDateTime expireTime) {
|
|
|
+ Long parentPayOrderId, LocalDateTime expireTime) {
|
|
|
// 创建支付单,用于后续的支付
|
|
|
PayOrderCreateReqDTO payOrderCreateReqDTO = TradeOrderConvert.INSTANCE.convert(
|
|
|
order, orderItems, tradeOrderProperties);
|
|
@@ -861,37 +1010,50 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
return payOrderId;//返回支付订单ID
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
@TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_PAY)
|
|
|
- //下面的参数中的id1为交易订单TradeOrder表的id,已经没用了,因为一个支付订单对应多个订单。
|
|
|
//只有支付订单id参数payOrderId是有用的。
|
|
|
- public void updateOrderPaid(Long id1, Long payOrderId) {
|
|
|
-
|
|
|
+ public List updateOrderPaid(Long payOrderId) {
|
|
|
|
|
|
// System.out.println("#########updateOrderPaid####payOrderId:"+payOrderId);
|
|
|
|
|
|
+ List rs = new ArrayList();
|
|
|
+
|
|
|
//查询订单提成比例
|
|
|
QueryWrapper<OrderPercentageDO> queryWrapper = new QueryWrapper<>();
|
|
|
OrderPercentageDO orderPercentageDO = orderPercentageMapper.selectOne(queryWrapper);//表中只有一条记录
|
|
|
- /**
|
|
|
+
|
|
|
+ /*
|
|
|
* 毛利 = 成本 * 0.38... (推广费用)
|
|
|
*/
|
|
|
String grossProfitPerc = orderPercentageDO.getGrossProfitPerc();
|
|
|
|
|
|
+ Integer allTradeOrderTotalPrice = 0;//所有订单的总金额
|
|
|
+ Long allTradeOrderTotalFreezeAmount = 0L;//所有订单用户总的冻结积分
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
+ /*
|
|
|
* 购物本人自得 百分比
|
|
|
*/
|
|
|
String grossProfitUserQuotaPerc = orderPercentageDO.getGrossProfitUserQuotaPerc();
|
|
|
|
|
|
+ /*
|
|
|
+ * 推荐人(上一级) 百分比
|
|
|
+ */
|
|
|
+ String grossProfitAncestorQuotaPerc = orderPercentageDO.getGrossProfitAncestorQuotaPerc();
|
|
|
+
|
|
|
//add by Ben 根据支付订单id,查询所有 支付订单 对应的 订单
|
|
|
List<TradeOrderDO> TradeOrderDOList = tradeOrderMapper.selectList("pay_order_id", payOrderId);
|
|
|
|
|
|
- for(TradeOrderDO tradeOrderDO:TradeOrderDOList) {
|
|
|
+ //购物者ID
|
|
|
+ Long memberUserIdOfTradeOrder = TradeOrderDOList.get(0).getUserId();
|
|
|
+ //20240604 推荐人(上级用户ID)
|
|
|
+ Long ancesterUserId = tradeOrderMapper.selectAncesterByMemberUserId(memberUserIdOfTradeOrder);
|
|
|
+
|
|
|
+ for (TradeOrderDO tradeOrderDO : TradeOrderDOList) {
|
|
|
|
|
|
Long tradeOrderId = tradeOrderDO.getId();
|
|
|
+ allTradeOrderTotalPrice += tradeOrderDO.getTotalPrice();
|
|
|
|
|
|
// System.out.println("#########updateOrderPaid####tradeOrderId:"+tradeOrderId);
|
|
|
|
|
@@ -936,17 +1098,20 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
}
|
|
|
|
|
|
List<ProductSkuDO> productSkuDOS = productSkuMapper.selectBatchIds(skuList);
|
|
|
- Map<Long,ProductSkuDO> skuDOMap = new HashMap<Long,ProductSkuDO>();
|
|
|
+ Map<Long, ProductSkuDO> skuDOMap = new HashMap<>();
|
|
|
for (ProductSkuDO productSkuDO : productSkuDOS) {
|
|
|
- skuDOMap.put(productSkuDO.getId(),productSkuDO);
|
|
|
+ skuDOMap.put(productSkuDO.getId(), productSkuDO);
|
|
|
}
|
|
|
|
|
|
- Long totalFreezeAmount = 0l;//用户总的冻结积分
|
|
|
+ Long totalFreezeAmount = 0L;//用户总的冻结积分
|
|
|
+
|
|
|
+ Long totalAncestorFreezeAmount = 0L;//推荐人总的冻结积分
|
|
|
+
|
|
|
for (TradeOrderItemDO tradeOrderItemDO : TradeOrderItemList) {
|
|
|
ProductSkuDO productSkuDO = skuDOMap.get(tradeOrderItemDO.getSkuId());
|
|
|
//这类商品的总推广费
|
|
|
- Integer promotionExpenses = (productSkuDO.getPrice()-productSkuDO.getCostPrice())
|
|
|
- *tradeOrderItemDO.getCount();
|
|
|
+ Integer promotionExpenses = (productSkuDO.getPrice() - productSkuDO.getCostPrice())
|
|
|
+ * tradeOrderItemDO.getCount();
|
|
|
|
|
|
//把商品项的推广费,转换为这项商品直推人获得的冻结积分
|
|
|
Long itemFreezeAmount =
|
|
@@ -955,30 +1120,70 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
grossProfitUserQuotaPerc//消费者自得额度 百分比
|
|
|
);
|
|
|
|
|
|
- totalFreezeAmount+=itemFreezeAmount;
|
|
|
+
|
|
|
+ //把商品项的推广费,转换为这项商品推荐人(上级)获得的冻结积分
|
|
|
+ Long ancestorItemFreezeAmount =
|
|
|
+ promotionExpenses2GrossProfitAncestorQuota(promotionExpenses,
|
|
|
+ grossProfitPerc,//毛利 = 成本 * 0.38... (推广费用)
|
|
|
+ grossProfitAncestorQuotaPerc//消费者自得额度 百分比
|
|
|
+ );
|
|
|
+
|
|
|
+ totalFreezeAmount += itemFreezeAmount;
|
|
|
+ totalAncestorFreezeAmount += ancestorItemFreezeAmount;
|
|
|
|
|
|
//记录用户在此订单项获得的冻结积分
|
|
|
TradeOrderItemDO toid = new TradeOrderItemDO();
|
|
|
toid.setId(tradeOrderItemDO.getId());
|
|
|
toid.setIncreaseIntegral(itemFreezeAmount);
|
|
|
+ toid.setAncestorIncreaseIntegral(ancestorItemFreezeAmount);//20240504 add by Ben
|
|
|
tradeOrderItemMapper.updateById(toid);
|
|
|
}
|
|
|
|
|
|
//把商品的推广费总额,转换为直推人获得的冻结积分
|
|
|
// Integer freezeAmount = promotionExpenses2GrossProfitAncestorQuota(orderPercentageMapper,totalPromotionExpenses);
|
|
|
|
|
|
- String OrderNum =order.getNo();
|
|
|
- integralService.updateUserIntegral(tradeOrderDO.getUserId(), CaclEnum.ORDER_GET_FREEZE_INTEGRAL, 0l,totalFreezeAmount,tradeOrderId,OrderNum);
|
|
|
+ String OrderNum = order.getNo();
|
|
|
+ //修改购物者本人获得的冻结积分
|
|
|
+ integralService.updateUserIntegral(tradeOrderDO.getUserId(), tradeOrderDO.getUserId(), CaclEnum.ORDER_PAY_INTEGRAL_CONSUMER, 0L, totalFreezeAmount, tradeOrderId, OrderNum);
|
|
|
+
|
|
|
+ //修改推荐人(上级)获得的冻结积分
|
|
|
+ integralService.updateUserIntegral(tradeOrderDO.getUserId(), ancesterUserId, CaclEnum.ORDER_PAY_INTEGRAL_ANCESTER, 0L, totalAncestorFreezeAmount, tradeOrderId, OrderNum);
|
|
|
+ log.warn("[TradeOrderUpdateServiceImpl.updateOrderPaid]$$$:[tradeOrderId({}),ancesterUserId({}),totalAncestorFreezeAmount({})]" + new Date(),
|
|
|
+ tradeOrderId, ancesterUserId, totalAncestorFreezeAmount);
|
|
|
|
|
|
+ allTradeOrderTotalFreezeAmount += totalFreezeAmount;//用户获得总的待确权冻结积分
|
|
|
|
|
|
// 发送给微信消息给系统用户待发货消息
|
|
|
sentWcChatMessage(order);
|
|
|
}
|
|
|
|
|
|
|
|
|
+ //自得身价计算
|
|
|
+ double orderUserSocialStatus = Double.parseDouble(orderPercentageDO.getOrderUserSocialStatus());//获得身价百分比
|
|
|
+ Double newSocialStatus = allTradeOrderTotalPrice * orderUserSocialStatus / 100;//用户获取的待确权身价值
|
|
|
+
|
|
|
+
|
|
|
+ rs.add(allTradeOrderTotalFreezeAmount);
|
|
|
+ rs.add(newSocialStatus);
|
|
|
+
|
|
|
+ return rs;
|
|
|
}
|
|
|
|
|
|
- private void sentWcChatMessage(TradeOrderDO order){
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.MEMBER_PAY)
|
|
|
+ //下面的参数中的id1为交易订单TradeOrder表的id,已经没用了,因为一个支付订单对应多个订单。
|
|
|
+ //只有支付订单id参数payOrderId是有用的。
|
|
|
+ public void updateOrderPaid(Long id1, Long payOrderId) {
|
|
|
+
|
|
|
+ log.error("[TradeOrderUpdateServiceImpl.updateOrderPaid]###微信回调(现在程序什么也没干):[payOrderId({}) ,TradeOrderId({})]" + new Date(),
|
|
|
+ payOrderId, id1);
|
|
|
+
|
|
|
+ //updateOrderPaid( payOrderId);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sentWcChatMessage(TradeOrderDO order) {
|
|
|
List<String> params = new ArrayList<>();
|
|
|
DecimalFormat df = new DecimalFormat("0.00");
|
|
|
String formattedPrice = df.format((double) order.getPayPrice() / 100);
|
|
@@ -1001,8 +1206,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
List<Long> adminUsers = adminUserService.getUserIdsByShop(order.getShopId());
|
|
|
for (Long aUserId : adminUsers) {
|
|
|
//发送信息
|
|
|
- wcChatMessageUtils.sendWcChatMessage(order.getUserId(), WcChatMessageTemplateIdEnum.ORDER_NO_DELIVERY2.getTemplateId(),
|
|
|
- params, aUserId, order.getUserId(), order.getId());
|
|
|
+ wcChatMessageUtils.sendWcChatMessage(WcChatMessageTemplateIdEnum.ORDER_NO_DELIVERY2.getTemplateId(),
|
|
|
+ params, aUserId, order.getId());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1216,6 +1421,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
|
|
|
/**
|
|
|
* 用户手动取消订单
|
|
|
+ *
|
|
|
* @param userId 用户编号
|
|
|
* @param id 订单编号
|
|
|
*/
|
|
@@ -1237,18 +1443,19 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
cancelOrder0(order, TradeOrderCancelTypeEnum.MEMBER_CANCEL);
|
|
|
|
|
|
//3.退回订单已支付的积分 add by Ben
|
|
|
- Long payIntegral = order.getPayIntegral();//每个订单使用的积分
|
|
|
+ Long payIntegral = order.getPayIntegral().longValue();//每个订单使用的积分
|
|
|
Long tradeOrderId = order.getId();
|
|
|
String orderNum = order.getNo();
|
|
|
//如果订单有使用积分,则退回积分
|
|
|
- if(payIntegral>0) {
|
|
|
- integralService.updateUserIntegral(userId, CaclEnum.ORDER_CANCEL_BY_USER_REFUND_INTEGRAL, payIntegral, 0l, tradeOrderId, orderNum);
|
|
|
+ if (payIntegral > 0) {
|
|
|
+ integralService.updateUserIntegral(userId, userId, CaclEnum.ORDER_CANCEL_BY_USER_REFUND_INTEGRAL, payIntegral, 0L, tradeOrderId, orderNum);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 订单超时未支付,自动取消
|
|
|
- * @return
|
|
|
+ *
|
|
|
+ * @return 数量
|
|
|
*/
|
|
|
@Override
|
|
|
public int cancelOrderBySystem() {
|
|
@@ -1267,13 +1474,13 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|
|
getSelf().cancelOrderBySystem(order);
|
|
|
|
|
|
//退回订单已支付的积分 add by Ben
|
|
|
- Long payIntegral = order.getPayIntegral();//每个订单使用的积分
|
|
|
+ Long payIntegral = order.getPayIntegral().longValue();//每个订单使用的积分
|
|
|
Long tradeOrderId = order.getId();
|
|
|
String orderNum = order.getNo();
|
|
|
Long userId = order.getUserId();
|
|
|
//如果订单有使用积分,则退回积分
|
|
|
- if(payIntegral>0) {
|
|
|
- integralService.updateUserIntegral(userId, CaclEnum.ORDER_CANCEL_BY_SYSTEM_REFUND_INTEGRAL, payIntegral, 0l, tradeOrderId, orderNum);
|
|
|
+ if (payIntegral > 0) {
|
|
|
+ integralService.updateUserIntegral(userId, userId, CaclEnum.ORDER_CANCEL_BY_SYSTEM_REFUND_INTEGRAL, payIntegral, 0L, tradeOrderId, orderNum);
|
|
|
}
|
|
|
|
|
|
count++;
|