...
|
...
|
@@ -49,10 +49,7 @@ import java.math.BigDecimal; |
|
|
import java.text.CollationElementIterator;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneOffset;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
...
|
...
|
@@ -431,6 +428,51 @@ public class StoreSellerServiceImpl implements IStoredSellerService { |
|
|
|
|
|
|
|
|
|
|
|
public void orderPayBySkups(List<Integer> skups){
|
|
|
|
|
|
if (CollectionUtils.isEmpty(skups)){
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
scriptLogger.info("start orderPayBySkups {}", skups);
|
|
|
|
|
|
// 过滤出 支付方式是11的
|
|
|
List<SellerOrder> sellerOrders = sellerOrderMapper.selectBySkups(skups);
|
|
|
List<SellerOrder> walletSellerOrders = sellerOrders.stream().filter(x->Objects.nonNull(x.getPayment()) && x.getPayment()==11).collect(Collectors.toList());
|
|
|
|
|
|
if (CollectionUtils.isEmpty(walletSellerOrders)){
|
|
|
scriptLogger.info("no need orderPay....can sell goods not wallet");
|
|
|
}
|
|
|
|
|
|
int now = DateUtil.getCurrentTimeSecond();
|
|
|
|
|
|
for (SellerOrder sellerOrder : walletSellerOrders) {
|
|
|
|
|
|
scriptLogger.info("[{}] startorderPay [{}]", sellerOrder.getUid(), sellerOrder.getOrderCode());
|
|
|
|
|
|
OrdersPay ordersPaydb = ordersPayMapper.selectOrdersPay(sellerOrder.getOrderCode(), sellerOrder.getUid());
|
|
|
if (ordersPaydb != null) {
|
|
|
scriptLogger.info("[{}] no need orderPay [{}]", sellerOrder.getUid(), sellerOrder.getOrderCode());
|
|
|
continue;
|
|
|
}
|
|
|
OrdersPay ordersPay = new OrdersPay();
|
|
|
ordersPay.setPayOrderCode(String.valueOf(sellerOrder.getOrderCode()));
|
|
|
ordersPay.setAmount(sellerOrder.getEarnestMoney());
|
|
|
ordersPay.setOrderCode(sellerOrder.getOrderCode());
|
|
|
ordersPay.setUid(sellerOrder.getUid());
|
|
|
ordersPay.setPayment(11);
|
|
|
ordersPay.setCreateTime(now);
|
|
|
ordersPay.setSerialNo(String.valueOf(sellerOrder.getOrderCode()));
|
|
|
ordersPayMapper.insertSelective(ordersPay);
|
|
|
scriptLogger.info("[{}] do orderPay [{}]", sellerOrder.getUid(), sellerOrder.getOrderCode());
|
|
|
|
|
|
scriptLogger.info("==================================================");
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void compensate(List<Integer> uids){
|
|
|
|
...
|
...
|
@@ -501,44 +543,56 @@ public class StoreSellerServiceImpl implements IStoredSellerService { |
|
|
Map<Integer, SellerWallet> sellerWalletMap = sellerWalletList.stream().collect(Collectors.toMap(SellerWallet::getUid, Function.identity(), (key1, key2) -> key2));
|
|
|
|
|
|
// 2.需要执行商品下架的uid & skup
|
|
|
Map<Integer, List<Integer>> saleoutProcessingSkups = Maps.newHashMap();
|
|
|
|
|
|
// key=uid, value=需要下架的skup
|
|
|
Map<Integer, List<Integer>> downSelfSkupMap = Maps.newHashMap();
|
|
|
|
|
|
// key=uid, value=上架中的商品的价格,需占用
|
|
|
// key=uid, value=上架中的商品的价格+过程中的订单保证金,需占用
|
|
|
Map<Integer, Double> onshelfEarnest = Maps.newHashMap();
|
|
|
|
|
|
Map<Integer, List<Integer>> onselfSkupMap = Maps.newHashMap();
|
|
|
|
|
|
scriptLogger.info("========================== process degrade calculate ==========================");
|
|
|
|
|
|
for (Integer uid : filterUids){
|
|
|
scriptLogger.info("\n");
|
|
|
|
|
|
// 上架中 & 钱包 & 保证金 的skup
|
|
|
List<Integer> skupsOfuid = getOnshelfSkupOfUid(uid);
|
|
|
scriptLogger.info("[{}] process degrade, all skup {} ", uid, skupsOfuid);
|
|
|
Map<Integer, BigDecimal> onsaleSkupMap = getOnshelfSkupOfUid(uid);
|
|
|
|
|
|
// 上架中 and 已出售但是流程还没有走完的
|
|
|
Map<Integer, BigDecimal> saleoutProcessingSkupMap = getSaleOutProcessingSkup(uid);
|
|
|
|
|
|
if (CollectionUtils.isEmpty(skupsOfuid)){
|
|
|
scriptLogger.info("[{}] process degrade, onsale skups {}, saleoutprocessing skups {} ", uid, onsaleSkupMap.keySet(), saleoutProcessingSkupMap.keySet());
|
|
|
|
|
|
if (CollectionUtils.isEmpty(onsaleSkupMap.keySet()) && CollectionUtils.isEmpty(saleoutProcessingSkupMap.keySet())){
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
// 这些skup的实际保证金 key=skup, value=保证金
|
|
|
List<SellerOrderMeta> sellerOrderMetaList = sellerOrderMetaMapper.selectByUidSkupAndMetaKey(uid, skupsOfuid, Lists.newArrayList("fee"));
|
|
|
Map<Integer, SellerOrderMeta> skupEarnestMap = sellerOrderMetaList.stream().collect(Collectors.toMap(SellerOrderMeta::getSkup, Function.identity(), (key1, key2) -> key2));
|
|
|
double walletLeftMoney = sellerWalletMap.get(uid).getAmount().doubleValue();
|
|
|
|
|
|
double saleoutProcessingMoney = getSumEarnestSaleOutProcessiongSkups(saleoutProcessingSkupMap);
|
|
|
|
|
|
double leftMoney = sellerWalletMap.get(uid).getAmount().doubleValue();
|
|
|
// 实际真正可用金额
|
|
|
double availableLeftMoney = YHMath.sub(walletLeftMoney, saleoutProcessingMoney);
|
|
|
|
|
|
// 保持上架的skup & money
|
|
|
Pair<List<Integer>, Double> onshelfSkup = getOnselfSkupsAndEarnest(skupsOfuid, skupEarnestMap, leftMoney , uid);
|
|
|
scriptLogger.info("[{}] process degrade, leftMoney {}", uid, leftMoney);
|
|
|
Pair<List<Integer>, Double> onshelfSkup = getOnselfSkupsAndEarnest(onsaleSkupMap, availableLeftMoney);
|
|
|
scriptLogger.info("[{}] process degrade, walletLeftMoney {}, saleoutProcessingMoney {}, availableLeftMoney {}", uid, walletLeftMoney, saleoutProcessingMoney, availableLeftMoney);
|
|
|
scriptLogger.info("[{}] process degrade, onshelfSkup {}", uid, onshelfSkup.getLeft());
|
|
|
scriptLogger.info("[{}] process degrade, earnestMoneyTotal {} ", uid, onshelfSkup.getRight());
|
|
|
|
|
|
skupsOfuid.removeAll(onshelfSkup.getKey());
|
|
|
|
|
|
onselfSkupMap.put(uid, Lists.newArrayList(onshelfSkup.getKey()));
|
|
|
onsaleSkupMap.keySet().removeAll(onshelfSkup.getKey());
|
|
|
|
|
|
// 应该下架的skup
|
|
|
downSelfSkupMap.put(uid, skupsOfuid);
|
|
|
downSelfSkupMap.put(uid, Lists.newArrayList(onsaleSkupMap.keySet()));
|
|
|
|
|
|
onshelfEarnest.put(uid, onshelfSkup.getValue());
|
|
|
saleoutProcessingSkups.put(uid, Lists.newArrayList(saleoutProcessingSkupMap.keySet()));
|
|
|
|
|
|
onshelfEarnest.put(uid, YHMath.add(saleoutProcessingMoney, onshelfSkup.getValue()));
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
@@ -573,7 +627,7 @@ public class StoreSellerServiceImpl implements IStoredSellerService { |
|
|
// 3.2 下架商品
|
|
|
if (CollectionUtils.isNotEmpty(downSelfSkupMap.get(uid))){
|
|
|
|
|
|
boolean updateStatusFlag = productProxyService.sellerBatchUpdateStatus(downSelfSkupMap.get(uid), ProductProxyService.PrdShelvelStatus.off);
|
|
|
productProxyService.sellerBatchUpdateStatus(downSelfSkupMap.get(uid), ProductProxyService.PrdShelvelStatus.off);
|
|
|
|
|
|
sellerOrderGoodsMapper.updateStatusfBySkups(downSelfSkupMap.get(uid), SkupStatus.YOHO_CANCEL_SELL.getCode());
|
|
|
|
...
|
...
|
@@ -585,20 +639,51 @@ public class StoreSellerServiceImpl implements IStoredSellerService { |
|
|
scriptLogger.info("[{}] down shelf skup {} success", uid, downSelfSkupMap.get(uid));
|
|
|
}
|
|
|
|
|
|
// 给下架的商品和过程中的商品补充支付信息
|
|
|
orderPayBySkups(onselfSkupMap.get(uid));
|
|
|
scriptLogger.info("[{}] orerpay onsale skup {} success", uid, onselfSkupMap.get(uid));
|
|
|
|
|
|
orderPayBySkups(saleoutProcessingSkups.get(uid));
|
|
|
scriptLogger.info("[{}] orerpay processing skup {} success", uid, saleoutProcessingSkups.get(uid));
|
|
|
|
|
|
}
|
|
|
|
|
|
scriptLogger.info("========================== degrade end ==========================");
|
|
|
}
|
|
|
|
|
|
|
|
|
private List<Integer> getOnshelfSkupOfUid(Integer uid){
|
|
|
private double getSumEarnestSaleOutProcessiongSkups(Map<Integer, BigDecimal> saleoutProcessingSkupMap) {
|
|
|
double sum = 0.00d;
|
|
|
for (BigDecimal earnestMoney : saleoutProcessingSkupMap.values()) {
|
|
|
sum = YHMath.add(sum, earnestMoney.doubleValue());
|
|
|
}
|
|
|
|
|
|
return sum;
|
|
|
|
|
|
}
|
|
|
|
|
|
private Map<Integer, BigDecimal> getOnshelfSkupOfUid(Integer uid){
|
|
|
// 查询上架中 & 收取保证金的 skup
|
|
|
List<SellerOrderGoods> sellerOrderGoods = sellerOrderGoodsMapper.selectByUidAndAttributesDesc(uid,
|
|
|
List<SellerGoodSkup> sellerOrderGoods = sellerOrderGoodsMapper.selectOnsaleByUid(uid,
|
|
|
SkupStatus.CAN_SELL.getCode(), Lists.newArrayList(OrderAttributes.COMMON_IN_STOCK.getCode(),
|
|
|
OrderAttributes.FLAW.getCode(),OrderAttributes.SECOND_HAND.getCode(), OrderAttributes.ADVANCE_SALE.getCode()));
|
|
|
|
|
|
return sellerOrderGoods.stream().map(SellerOrderGoods::getId).collect(Collectors.toList());
|
|
|
if (CollectionUtils.isEmpty(sellerOrderGoods)){
|
|
|
return Maps.newHashMap();
|
|
|
}
|
|
|
|
|
|
return sellerOrderGoods.stream().collect(Collectors.toMap(SellerGoodSkup::getSkup, SellerGoodSkup::getEarnestMoney));
|
|
|
|
|
|
}
|
|
|
|
|
|
private Map<Integer, BigDecimal> getSaleOutProcessingSkup(Integer uid){
|
|
|
List<SellerGoodSkup> sellerOrderGoods = sellerOrderGoodsMapper.selectSaleOutProcessiongByUid(uid);
|
|
|
|
|
|
if (CollectionUtils.isEmpty(sellerOrderGoods)){
|
|
|
return Maps.newHashMap();
|
|
|
}
|
|
|
|
|
|
return sellerOrderGoods.stream().collect(Collectors.toMap(SellerGoodSkup::getSkup, SellerGoodSkup::getEarnestMoney));
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -631,7 +716,7 @@ public class StoreSellerServiceImpl implements IStoredSellerService { |
|
|
}
|
|
|
|
|
|
|
|
|
public Pair<List<Integer>, Double> getOnselfSkupsAndEarnest(List<Integer> skups, Map<Integer, SellerOrderMeta> sellerOrderMetaMap, double leftMoney, int uid){
|
|
|
public Pair<List<Integer>, Double> getOnselfSkupsAndEarnest(Map<Integer, BigDecimal> onsaleSkupMap, double leftMoney){
|
|
|
|
|
|
|
|
|
double earnestTotal = 0.00;
|
...
|
...
|
@@ -639,14 +724,11 @@ public class StoreSellerServiceImpl implements IStoredSellerService { |
|
|
List<Integer> onshelfSkups = Lists.newArrayList();
|
|
|
double onShelfSkupsEarnest = 0.00;
|
|
|
|
|
|
Map<Integer, Double> skupEarnest = Maps.newHashMap();
|
|
|
|
|
|
for (Integer skup : skups){
|
|
|
for (Integer skup : onsaleSkupMap.keySet()){
|
|
|
|
|
|
// 保证金
|
|
|
SellerOrderMeta sellerOrderMeta = sellerOrderMetaMap.get(skup);
|
|
|
JSONObject earnestJson = JSONObject.parseObject(sellerOrderMeta.getMetaValue()).getJSONObject("earnestMoney");
|
|
|
double earnestMoney = earnestJson.getDouble("earnestMoney");
|
|
|
double earnestMoney = onsaleSkupMap.get(skup).doubleValue();
|
|
|
|
|
|
earnestTotal=YHMath.add(earnestTotal, earnestMoney);
|
|
|
|
...
|
...
|
|