...
|
...
|
@@ -25,6 +25,7 @@ import com.yohoufo.order.model.OrderBuilderFactory; |
|
|
import com.yohoufo.order.model.request.BuyerBidPublishRequest;
|
|
|
import com.yohoufo.order.model.request.ShoppingRequest;
|
|
|
import com.yohoufo.order.model.response.BidComputeResponse;
|
|
|
import com.yohoufo.order.model.response.BidPrePublishResponse;
|
|
|
import com.yohoufo.order.model.response.BidPublishResponse;
|
|
|
import com.yohoufo.order.service.BuyerOrderStateChangers;
|
|
|
import com.yohoufo.order.service.cache.CacheCleaner;
|
...
|
...
|
@@ -112,18 +113,14 @@ public class BuyerBidPublishService { |
|
|
//1.1 sku必须存在的
|
|
|
//1.2求购价格满足商品的最低和最高红线价,不满足提示价格过低,或者价格过高
|
|
|
//求购金额
|
|
|
BidPrice bidPrice = new BidPrice(request.getPrice(), productProxyService.getPrdPriceRange(request.getUid(), request.getStorageId()));
|
|
|
BuyerBidConfig buyerBidConfig = metaConfigService.getBuyerBidConfig();
|
|
|
BidAndSuggestPrice bidPrice = new BidAndSuggestPrice(request.getPrice(),
|
|
|
productProxyService.getPrdPriceRange(request.getUid(), request.getStorageId()),
|
|
|
buyerBidConfig.getBasConfig());
|
|
|
//2.计算定金
|
|
|
Deposit deposit = computeDeposit(bidPrice);
|
|
|
Deposit deposit = computeDeposit(bidPrice, buyerBidConfig.getDConfig());
|
|
|
logger.info("[{}] buyerBid compute deposit result:{}", uid, deposit);
|
|
|
|
|
|
//定金金额
|
|
|
BigDecimal earestMoney = BigDecimal.valueOf(deposit.getAmount());
|
|
|
//账户
|
|
|
Account account = accountFactory.get(uid);
|
|
|
//检测入驻用户账户金额
|
|
|
account.checkBalanceEnough(earestMoney);
|
|
|
|
|
|
//3.计算商品金额 + 运费
|
|
|
ChargeContext chargeContext = computeGoods(request, bidPrice);
|
|
|
|
...
|
...
|
@@ -132,12 +129,45 @@ public class BuyerBidPublishService { |
|
|
//返回结果
|
|
|
BidComputeResponse response = new BidComputeResponse();
|
|
|
response.setPromotionFormulaList(shoppingSupport.getPromotionFormula(chargeResult));
|
|
|
response.setDeposit(BidComputeResponse.Deposit.builder().amount(deposit.getAmount()).build());
|
|
|
response.setAmount(MathUtils.formatStr(deposit.getAmount()));
|
|
|
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 计算及提示
|
|
|
* 主要包括两部分
|
|
|
* 1.定金(出价 * 比例)
|
|
|
* 2.商品金额 + 运费
|
|
|
*/
|
|
|
public BidPrePublishResponse prePublish(BuyerBidPublishRequest request) {
|
|
|
int uid = request.getUid();
|
|
|
//1.校验如下规则
|
|
|
//1.1 sku必须存在的
|
|
|
//1.2求购价格满足商品的最低和最高红线价,不满足提示价格过低,或者价格过高
|
|
|
//比例配置
|
|
|
BuyerBidConfig buyerBidConfig = metaConfigService.getBuyerBidConfig();
|
|
|
//求购金额
|
|
|
BidAndSuggestPrice bidAndSuggestPrice = new BidAndSuggestPrice(request.getPrice(),
|
|
|
productProxyService.getPrdPriceRange(request.getUid(), request.getStorageId()), buyerBidConfig.getBasConfig());
|
|
|
//2.计算定金
|
|
|
Deposit deposit = computeDeposit(bidAndSuggestPrice, buyerBidConfig.getDConfig());
|
|
|
logger.info("[{}] buyerBid compute deposit result:{}", uid, deposit);
|
|
|
|
|
|
BidPrePublishResponse.Dialog dialog = null;
|
|
|
|
|
|
if (bidAndSuggestPrice.isSuggest()) {
|
|
|
logger.warn("[{}] Suggest,bidAndSuggestPrice:{}", uid, bidAndSuggestPrice);
|
|
|
//建议求购价
|
|
|
dialog = BidPrePublishResponse.Dialog.builder().type("suggest")
|
|
|
.title("建议求购价:" + OrderConstant.MONEY_SIGN + bidAndSuggestPrice.getSuggestPrice().toPlainString())
|
|
|
.content("高于建议求购价可以迅速提升求购速度成功率!").cancel("调整价格").confirm("继续求购").build();
|
|
|
}
|
|
|
return BidPrePublishResponse.builder().amount(MathUtils.formatStr(deposit.getAmount())).dialog(dialog).build();
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 预发布
|
|
|
*/
|
...
|
...
|
@@ -151,20 +181,21 @@ public class BuyerBidPublishService { |
|
|
|
|
|
// 返回结果
|
|
|
return BidPublishResponse.builder().skup(bidPublishResult.getSkup()).orderCode(bidPublishResult.getOrderCode())
|
|
|
.paymentStatus(bidPublishResult.isFinishedDepositPay() ? OrderConstant.Y_STR : OrderConstant.N_STR)
|
|
|
.paymentStatus(OrderConstant.N_STR)
|
|
|
.build();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 计算定金
|
|
|
*
|
|
|
* @param bidPrice 求购价
|
|
|
* @return
|
|
|
*/
|
|
|
private Deposit computeDeposit(BidPrice bidPrice) {
|
|
|
return new Deposit(bidPrice, metaConfigService.getBidDepositConfig());
|
|
|
private Deposit computeDeposit(BidAndSuggestPrice bidPrice, BuyerBidConfig.DepositConfig depositConfig) {
|
|
|
return new Deposit(bidPrice, depositConfig);
|
|
|
}
|
|
|
|
|
|
private ChargeContext computeGoods(BuyerBidPublishRequest request, BidPrice bidPrice) {
|
|
|
private ChargeContext computeGoods(BuyerBidPublishRequest request, BidAndSuggestPrice bidPrice) {
|
|
|
//构建算费上下文
|
|
|
ChargeContext chargeContext = chargeContextFactory.buildChargeContext(newShoppingRequest(request),
|
|
|
newSellerOrderGoods(0, 0, bidPrice.getPrice()),
|
...
|
...
|
@@ -207,6 +238,7 @@ public class BuyerBidPublishService { |
|
|
|
|
|
/**
|
|
|
* 发布
|
|
|
*
|
|
|
* @param request
|
|
|
* @return
|
|
|
*/
|
...
|
...
|
@@ -217,21 +249,15 @@ public class BuyerBidPublishService { |
|
|
//1.1 sku必须存在的
|
|
|
//1.2求购价格满足商品的最低和最高红线价,不满足提示价格过低,或者价格过高
|
|
|
//求购金额
|
|
|
BidPrice bidPrice = new BidPrice(request.getPrice(), productProxyService.getPrdPriceRange(uid, storageId));
|
|
|
BuyerBidConfig buyerBidConfig = metaConfigService.getBuyerBidConfig();
|
|
|
BidAndSuggestPrice bidPrice = new BidAndSuggestPrice(request.getPrice(), productProxyService.getPrdPriceRange(uid, storageId),
|
|
|
buyerBidConfig.getBasConfig());
|
|
|
//2.计算定金
|
|
|
Deposit deposit = computeDeposit(bidPrice);
|
|
|
Deposit deposit = computeDeposit(bidPrice, buyerBidConfig.getDConfig());
|
|
|
logger.info("[{}] bid compute deposit result:{}", uid, deposit);
|
|
|
//3.计算商品金额 + 运费
|
|
|
ChargeContext chargeContext = computeGoods(request, bidPrice);
|
|
|
|
|
|
//定金金额
|
|
|
BigDecimal earestMoney = BigDecimal.valueOf(deposit.getAmount());
|
|
|
|
|
|
//账户
|
|
|
Account account = accountFactory.get(uid);
|
|
|
//检测入驻用户账户金额
|
|
|
account.checkBalanceEnough(earestMoney);
|
|
|
|
|
|
//获取商品信息
|
|
|
GoodsInfo goodsInfo = skupService.getProductDetail(uid, storageId, bidPrice.getPrice(), SkupType.getSkupType(request.getSkupType()));
|
|
|
|
...
|
...
|
@@ -239,9 +265,6 @@ public class BuyerBidPublishService { |
|
|
final int skup = createCannotSellSellerSkup(uid, goodsInfo);
|
|
|
logger.info("[{}] generate new skup:{}", uid, skup);
|
|
|
|
|
|
//支付定金
|
|
|
AccountPayResult accountPayResult = account.tryPay(earestMoney,OrderConstant.PAY_LEVEL_DEPOSIT, () -> skup);
|
|
|
|
|
|
// 生成订单号
|
|
|
long orderCode = orderCodeGenerator.generate(OrderCodeType.BUYER_TYPE);
|
|
|
logger.info("[{}] generate new orderCode:{}", uid, orderCode);
|
...
|
...
|
@@ -255,19 +278,12 @@ public class BuyerBidPublishService { |
|
|
chargeContext);
|
|
|
//求购 定金
|
|
|
BidOrderMetaBo bidOrderMetaBo = BidOrderMetaBo.builder().depositAmount(deposit.getAmount()).days(request.getDays()).build();
|
|
|
if (accountPayResult.isFinishPay()) {
|
|
|
//钱包
|
|
|
bidOrderMetaBo.setPayment(Payment.WALLET.getCode());
|
|
|
}
|
|
|
|
|
|
// 创建买家订单
|
|
|
BuyerOrderSubmitResult submitResult = buyerBidOrderSubmitService.submitOrder(orderBuilder, bidOrderMetaBo);
|
|
|
|
|
|
//记录支付明细
|
|
|
account.recordPayDetail(orderCode, accountPayResult);
|
|
|
|
|
|
BidPublishResult publishResult = BidPublishResult.builder().skup(skup).orderCode(orderCode)
|
|
|
.publishTime(submitResult.getSubmitTime())
|
|
|
.finishedDepositPay(accountPayResult.isFinishPay())
|
|
|
.orderAmount(orderBuilder.getAmount())
|
|
|
.build();
|
|
|
|
...
|
...
|
@@ -305,10 +321,6 @@ public class BuyerBidPublishService { |
|
|
* @param bidPublishResult
|
|
|
*/
|
|
|
public void processAfterBidPublish(int uid, BidPublishResult bidPublishResult) {
|
|
|
//已完成定金支付,直接变更订单状态为求购中
|
|
|
if (bidPublishResult.isFinishedDepositPay()) {
|
|
|
buyerOrderStateChangers.selectOneToChange(uid, bidPublishResult.getOrderCode(), OrderStatus.WAITING_PAY_DEPOSIT, OrderStatus.BIDING);
|
|
|
}
|
|
|
//触发事件
|
|
|
fireCreateAsyncEvent(uid, bidPublishResult);
|
|
|
//clean cache
|
...
|
...
|
|