...
|
...
|
@@ -43,13 +43,17 @@ import com.yohoufo.order.utils.AddressHelper; |
|
|
import com.yohoufo.order.utils.LoggerUtils;
|
|
|
import com.yohoufo.order.utils.MathUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
|
|
|
import org.springframework.context.annotation.Primary;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@Primary
|
|
|
@Service
|
|
|
public class ShoppingServiceImpl implements IShoppingService {
|
|
|
|
...
|
...
|
@@ -119,7 +123,7 @@ public class ShoppingServiceImpl implements IShoppingService { |
|
|
|
|
|
PaymentResponse response = new PaymentResponse();
|
|
|
response.setPaymentWay(shoppingSupport.getPaymentWay());
|
|
|
response.setDeliveryWay(shoppingSupport.getDeliverWay(chargeContext.getChargeResult().getShippingAmount()));
|
|
|
response.setDeliveryWay(shoppingSupport.getDeliverWay(chargeContext.getChargeResult()));
|
|
|
response.setGood(shoppingSupport.getGoodsInfo(skupGood));
|
|
|
response.setPromotionFormulaList(shoppingSupport.getPromotionFormula(chargeResult));
|
|
|
response.setAmount(MathUtils.formatStr(chargeResult.getFinalAmount()));
|
...
|
...
|
@@ -149,8 +153,12 @@ public class ShoppingServiceImpl implements IShoppingService { |
|
|
}
|
|
|
|
|
|
private ChargeContext buildChargeContext(ShoppingRequest request, SellerOrderGoods skupInfo) {
|
|
|
ChargeParam chargeParam = ChargeParam.builder().uid(request.getUid())
|
|
|
.deliveryWay(buildDeliveryWay())
|
|
|
.couponCodes(request.getCouponCodes()).build();
|
|
|
|
|
|
return ChargeContext.builder()
|
|
|
.chargeParam(ChargeParam.builder().uid(request.getUid()).couponCodes(request.getCouponCodes()).build())
|
|
|
.chargeParam(chargeParam)
|
|
|
.chargeGoods(ChargeGoods.builder().goodsPrice(skupInfo.getGoodsPrice()).productId(skupInfo.getProductId()).skup(skupInfo.getId()).build()).build();
|
|
|
}
|
|
|
|
...
|
...
|
@@ -230,22 +238,11 @@ public class ShoppingServiceImpl implements IShoppingService { |
|
|
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
}
|
|
|
|
|
|
// 检查地址是否合法
|
|
|
int addressId = AddressUtil.getDecryptStr(shoppingRequest.getAddressId());
|
|
|
if (addressId < 0){
|
|
|
logger.warn("submit addressId invalidate, uid is {}, skup is {}, addressId is {}", shoppingRequest.getUid(),
|
|
|
shoppingRequest.getSkup(), shoppingRequest.getAddressId());
|
|
|
throw new ServiceException(ServiceError.ORDER_ADDRESSID_INVALIDATE);
|
|
|
}
|
|
|
//查询并校验用户地址
|
|
|
Pair<AddressInfo, AddressInfo> userAddressPair = getAndCheckAddressInfo(shoppingRequest);
|
|
|
|
|
|
// 检查skup是否可售
|
|
|
SellerOrderGoods skup = checkSkupSellOrNot(shoppingRequest.getSkup());
|
|
|
AddressInfo addressInfo = userProxyService.getAddressInfoNotHidden(shoppingRequest.getUid(), addressId);
|
|
|
if(AddressHelper.isNeedUpdate(addressInfo)){
|
|
|
logger.warn("submit addressId need update, uid is {}, skup is {}, addressId is {}", shoppingRequest.getUid(),
|
|
|
shoppingRequest.getSkup(), shoppingRequest.getAddressId());
|
|
|
throw new ServiceException(ServiceError.ORDER_ADDRESS_NEED_UPDATE);
|
|
|
}
|
|
|
|
|
|
//算费
|
|
|
ChargeContext chargeContext = buildChargeContext(shoppingRequest,skup);
|
...
|
...
|
@@ -258,8 +255,6 @@ public class ShoppingServiceImpl implements IShoppingService { |
|
|
|
|
|
logger.info("generate new orderCode:{}",orderCode);
|
|
|
|
|
|
AddressInfo hiddenAddress = userProxyService.getHiddenAddressInfo(shoppingRequest.getUid(), addressId);
|
|
|
|
|
|
// 减库存,skup更新成不可售,入库
|
|
|
//BigDecimal shipFee = new BigDecimal(delivery_way_sf_cost);
|
|
|
int uid;
|
...
|
...
|
@@ -269,7 +264,7 @@ public class ShoppingServiceImpl implements IShoppingService { |
|
|
.orderCode(orderCode)
|
|
|
.productId(skup.getProductId())
|
|
|
.paymentType(OrderConstant.PAYMENT_ONLINE)
|
|
|
.deliverWay(OrderConstant.DELIVERY_WAY_SF)
|
|
|
.deliverWay(buildDeliveryWay())
|
|
|
.channelNo(shoppingRequest.getChannelNo())
|
|
|
.amount(BigDecimal.valueOf(chargeResult.getFinalAmount()))
|
|
|
.shipFee(BigDecimal.valueOf(chargeResult.getShippingAmount()))
|
...
|
...
|
@@ -277,10 +272,10 @@ public class ShoppingServiceImpl implements IShoppingService { |
|
|
.couponAmount(BigDecimal.valueOf(chargeResult.getCouponPayResult().getCouponAmount()))
|
|
|
.build()
|
|
|
)
|
|
|
.hiddenAddressInfo(hiddenAddress)
|
|
|
.addressInfo(addressInfo)
|
|
|
.hiddenAddressInfo(userAddressPair.getRight())
|
|
|
.addressInfo(userAddressPair.getLeft())
|
|
|
.clientType(shoppingRequest.getClientType())
|
|
|
.attributes(OrderAttributes.COMMON_IN_STOCK.getCode())
|
|
|
.attributes(buildOrderArrtribute().getCode()) //1,普通;2,线下店;3,急速发货
|
|
|
.build();
|
|
|
|
|
|
BuyerOrderSubmitResult submitResult = ordeCreationService.doSumbitOrder(orderBuilder);
|
...
|
...
|
@@ -323,6 +318,43 @@ public class ShoppingServiceImpl implements IShoppingService { |
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 查询并校验用户地址(left: 用户地址; right: 脱敏的用户地址)
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
protected Pair<AddressInfo, AddressInfo> getAndCheckAddressInfo(ShoppingRequest shoppingRequest) {
|
|
|
// 检查地址是否合法
|
|
|
int addressId = AddressUtil.getDecryptStr(shoppingRequest.getAddressId());
|
|
|
if (addressId < 0){
|
|
|
logger.warn("submit addressId invalidate, uid is {}, skup is {}, addressId is {}", shoppingRequest.getUid(),
|
|
|
shoppingRequest.getSkup(), shoppingRequest.getAddressId());
|
|
|
throw new ServiceException(ServiceError.ORDER_ADDRESSID_INVALIDATE);
|
|
|
}
|
|
|
|
|
|
AddressInfo addressInfo = userProxyService.getAddressInfoNotHidden(shoppingRequest.getUid(), addressId);
|
|
|
if(AddressHelper.isNeedUpdate(addressInfo)){
|
|
|
logger.warn("submit addressId need update, uid is {}, skup is {}, addressId is {}", shoppingRequest.getUid(),
|
|
|
shoppingRequest.getSkup(), shoppingRequest.getAddressId());
|
|
|
throw new ServiceException(ServiceError.ORDER_ADDRESS_NEED_UPDATE);
|
|
|
}
|
|
|
|
|
|
//脱敏的用户地址
|
|
|
AddressInfo hiddenAddress = userProxyService.getHiddenAddressInfo(shoppingRequest.getUid(), addressId);
|
|
|
|
|
|
return Pair.of(addressInfo, hiddenAddress);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取订单attribute属性
|
|
|
* @return
|
|
|
*/
|
|
|
protected OrderAttributes buildOrderArrtribute() {
|
|
|
return OrderAttributes.COMMON_IN_STOCK;
|
|
|
}
|
|
|
|
|
|
protected int buildDeliveryWay() {
|
|
|
return OrderConstant.DELIVERY_WAY_SF;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|