Authored by chenchao

buyer order support skup type of hongkong

package com.yohoufo.order.charge;
import com.yoho.core.common.utils.YHMath;
import com.yohobuy.ufo.model.order.constants.DeliveryWayEnum;
import com.yohobuy.ufo.model.promotion.UserCouponsBo;
import com.yohobuy.ufo.model.promotion.constant.CouponTypeEnum;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.BigDecimalHelper;
import com.yohoufo.order.charge.coupon.CouponService;
import com.yohoufo.order.charge.model.*;
import com.yohoufo.order.service.support.DeliveryWayCostSupport;
... ... @@ -15,10 +17,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.*;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.yohoufo.order.charge.model.ChargeParam.*;
import static com.yohoufo.order.constants.ApiVersionConfig.*;
import static com.yohoufo.order.constants.ApiVersionConfig.ApiVersion;
import static com.yohoufo.order.constants.ApiVersionConfig.Payment;
/**
* Created by jiexiang.wu on 2018/11/19.
... ... @@ -75,14 +80,15 @@ public class ChargeService {
ChargeResult chargeResult = chargeContext.getChargeResult();
//算费商品
ChargeGoods chargeGoods = chargeContext.getChargeGoods();
chargeResult.setGoodsAmount(chargeGoods.getRealPrice().doubleValue());
chargeResult.setFinalAmount(chargeGoods.getRealPrice().doubleValue());
logger.info("[{}] step goods charge,goodsPrice:{},goodsAmount:{},amount:{}",
BigDecimal goodsRealPrice = chargeGoods.getRealPrice();
chargeResult.setGoodsAmount(goodsRealPrice.doubleValue());
chargeResult.setFinalAmount(goodsRealPrice.doubleValue());
BigDecimal tariffRate = chargeGoods.getTariffRate();
logger.info("[{}] step goods charge,goodsPrice:{},goodsAmount:{},amount:{} tariffRate {}",
chargeContext.getChargeParam().getUid(),
chargeGoods.getGoodsPrice(),
chargeResult.getGoodsAmount(),
chargeResult.getFinalAmount());
chargeResult.getFinalAmount(), tariffRate);
//活动优惠
ActivityPrice activityPrice = chargeContext.getActivityPrice();
... ... @@ -96,6 +102,17 @@ public class ChargeService {
double oldFinalAmount = chargeResult.getFinalAmount();
double newFinalAmount = Math.max(0, YHMath.sub(oldFinalAmount, realCutPrice.doubleValue()));
//加上税费
double tariffAmount = 0D;
if (tariffRate!=null && tariffRate.compareTo(BigDecimal.ZERO)>0){
tariffAmount = BigDecimalHelper.halfUp(goodsRealPrice.multiply(tariffRate)).doubleValue();
}
if (tariffAmount > 0D){
chargeResult.setTariffAmount(tariffAmount);
newFinalAmount = YHMath.add(tariffAmount, newFinalAmount);
}
chargeResult.setFinalAmount(newFinalAmount);
ActivityCutResult activityCutResult = ActivityCutResult.builder()
... ... @@ -105,10 +122,11 @@ public class ChargeService {
.build();
chargeResult.setActivityCutResult(activityCutResult);
logger.info("[{}] step activity charge,goodsPrice:{},realPrice:{},oldFinalAmount:{},newFinalAmount:{},activityPrice:{},activityCutResult:{}",
logger.info("[{}] step activity charge,goodsPrice:{},realPrice:{},tariffAmount {},oldFinalAmount:{},newFinalAmount:{},activityPrice:{},activityCutResult:{}",
chargeContext.getChargeParam().getUid(),
chargeGoods.getGoodsPrice(),
chargeGoods.getRealPrice(),
tariffAmount,
oldFinalAmount, chargeResult.getFinalAmount(),
activityPrice,
chargeResult.getActivityCutResult());
... ... @@ -123,7 +141,26 @@ public class ChargeService {
private void calculateShippingAmount(ChargeContext chargeContext) {
double deliveryWayCost = 0D;
//如果是门店自提,则免运费
if (shoppingSupport.isDeliveryWayByStore(chargeContext.getChargeParam().getDeliveryWay())){
DeliveryWayEnum deliveryWay = DeliveryWayEnum.getByCode(chargeContext.getChargeParam().getDeliveryWay());
if (deliveryWay == null){
deliveryWayCost = deliveryWayCostSupport.getCostOfSf();
}else{
switch (deliveryWay){
case SELF_FETCH:
deliveryWayCost = 0D;
break;
case OVERSEAS_HONGHONG:
deliveryWayCost = deliveryWayCostSupport.getCostFromHk();
break;
case SF:
default:
deliveryWayCost = deliveryWayCostSupport.getCostOfSf();
break;
}
}
/*
if (shoppingSupport.isDeliveryWayByStore()){
deliveryWayCost = 0D;
}else/* if(chargeContext.getUserAddressPair() != null){
String areaCode = chargeContext.getUserAddressPair().getLeft().getAreaCode();
... ... @@ -133,9 +170,11 @@ public class ChargeService {
if (chargeContext.isShipFeeRequird()){
deliveryWayCost = deliveryWayCostSupport.getCostOfSf();
}
}*/{
}*/
/*{
deliveryWayCost = deliveryWayCostSupport.getCostOfSf();
}
*/
//运费
chargeContext.getChargeResult().setDeliveryWay(chargeContext.getChargeParam().getDeliveryWay());
chargeContext.getChargeResult().setShippingAmount(deliveryWayCost);
... ...
package com.yohoufo.order.charge.model;
import com.yohobuy.ufo.model.order.constants.SkupType;
import lombok.Data;
import lombok.ToString;
import lombok.Builder;
... ... @@ -20,12 +21,16 @@ public class ChargeGoods {
private int attributes;
private SkupType skupType;
/**
* 商品金额
*/
private BigDecimal goodsPrice;
/**
* 关税费率
*/
private BigDecimal tariffRate;
/**
* 活动减免金额
*/
... ...
... ... @@ -29,6 +29,11 @@ public class ChargeResult {
private double finalShippingAmount;
/**
* 关税
*/
private double tariffAmount;
/**
* 发货方式
*/
private int deliveryWay;
... ...
package com.yohoufo.order.charge.model;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class FeeNRate {
BigDecimal shipFee;
BigDecimal tariffRate;
}
... ...
... ... @@ -176,7 +176,7 @@ public class SellerOrderController {
@ResponseBody
public ApiResponse delete(@RequestParam(name = "uid", required = true)int uid,
@RequestParam(name = "orderCode", required = true)long orderCode
) throws GatewayException {
) {
SellerOrderCancelReq req = SellerOrderCancelReq.builder()
.uid(uid)
.orderCode(orderCode)
... ...
... ... @@ -32,4 +32,9 @@ public class AmountDetailBo {
* 运费券减免金额
*/
private double shippingCouponCutAmount;
/**
* 海外购商品入关的税费
*/
private double tariffAmount;
}
... ...
... ... @@ -76,7 +76,8 @@ public class CacheKeyBuilder {
ORDER_CODE_RULE("ufo:order:code:rule", ""),
SELLER_GOODS_FEE_RATE("ufo:order:seller:goods:service:feeRate", ""),
SELLER_GOODS_PLATFORM_FEE("ufo:order:seller:goods:platform:fee", "")
SELLER_GOODS_PLATFORM_FEE("ufo:order:seller:goods:platform:fee", ""),
BUYER_ORDER_FEE("ufo:order:buyer:order:fee","")
;
private String fix;
... ...
... ... @@ -10,6 +10,7 @@ import com.yohobuy.ufo.model.order.resp.EntryThreshold;
import com.yohoufo.common.cache.CacheClient;
import com.yohoufo.dal.order.MetaConfigMapper;
import com.yohoufo.dal.order.model.MetaConfig;
import com.yohoufo.order.charge.model.FeeNRate;
import com.yohoufo.order.model.dto.*;
import com.yohoufo.order.service.cache.CacheKeyBuilder;
import com.yohoufo.order.service.cache.ExpiredTime;
... ... @@ -303,4 +304,19 @@ public class MetaConfigService {
return pfMap;
}
public Map<String,FeeNRate> getBuyerOrderFeeNRate(){
CacheKeyBuilder.KeyTemp kt = CacheKeyBuilder.KeyTemp.BUYER_ORDER_FEE;
RedisKeyBuilder rkb = kt.builderKeyOnlyFixed();
final String key = MetaConfigKey.BUYER_ORDER_FEE;
String configVal = new DataProcesser(rkb, key, ExpiredTime.ORDER_BASE_CONFIG).getConfigVal();
Map<String,FeeNRate> pfMap = new HashMap<String,FeeNRate>(10);
try{
pfMap = JSONObject.parseObject(configVal, new TypeReference<Map<String,FeeNRate>>(){});
}catch (Exception ex){
logger.warn("in getBuyerOrderFeeNRate parseObject fail, metaVal {}", configVal, ex);
}
return pfMap;
}
}
... ...
... ... @@ -2,6 +2,8 @@ package com.yohoufo.order.service.impl;
import java.util.List;
import com.yohobuy.ufo.model.order.constants.DeliveryWayEnum;
import com.yohobuy.ufo.model.order.constants.SkupType;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -122,7 +124,7 @@ public class OfflineShoppingServiceImpl extends ShoppingServiceImpl implements I
}
@Override
protected int buildDeliveryWay() {
return OrderConstant.DELIVERY_WAY_STORE;
protected int buildDeliveryWay(SkupType skupType) {
return DeliveryWayEnum.SELF_FETCH.getCode();
}
}
... ...
... ... @@ -6,8 +6,7 @@ import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.common.*;
import com.yohobuy.ufo.model.order.constants.ChangePriceStatus;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.order.constants.*;
import com.yohobuy.ufo.model.promotion.constant.CouponTypeEnum;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.exception.UfoServiceException;
... ... @@ -20,7 +19,6 @@ import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.SellerChangePriceRecord;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohoufo.order.charge.ChargeContext;
import com.yohoufo.order.charge.ChargeService;
import com.yohoufo.order.charge.model.*;
... ... @@ -46,6 +44,7 @@ import com.yohoufo.order.service.listener.OrderChangeListenerContainer;
import com.yohoufo.order.service.proxy.BargainProxyService;
import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.UserProxyService;
import com.yohoufo.order.service.seller.support.SkupTypeCodeSupport;
import com.yohoufo.order.service.support.CouponSupport;
import com.yohoufo.order.service.support.ShoppingSupport;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
... ... @@ -61,6 +60,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
... ... @@ -125,7 +125,10 @@ public class ShoppingServiceImpl implements IShoppingService {
private ConfigReader configReader;
@Autowired
AppraiseAddressService appraiseAddressService;
private AppraiseAddressService appraiseAddressService;
@Autowired
private MetaConfigService metaConfigService;
/**
... ... @@ -133,6 +136,7 @@ public class ShoppingServiceImpl implements IShoppingService {
* @param request
* @return
*/
@Override
public PaymentResponse payment(ShoppingRequest request){
int skup;
int uid;
... ... @@ -237,17 +241,34 @@ public class ShoppingServiceImpl implements IShoppingService {
.activityTypeEnum(activityTypeEnum).build();
}
private ChargeContext buildChargeContext(ShoppingRequest request, SellerOrderGoods skupInfo, ActivityPrice activityPrice,int chargeStage) {
private ChargeContext buildChargeContext(ShoppingRequest request,
SellerOrderGoods skupInfo,
ActivityPrice activityPrice,
int chargeStage) {
Integer skupAttr = skupInfo.getAttributes();
SkupType skupType = SkupType.getSkupType(skupAttr);
FeeNRate feeNRate = getFeeNRate(skupType);
BigDecimal tariffRate = null;
if (feeNRate != null){
tariffRate = feeNRate.getTariffRate();
}
ChargeParam chargeParam = ChargeParam.builder().uid(request.getUid())
.chargeStage(chargeStage)
.apiVersion(request.getApiVersion())
.deliveryWay(buildDeliveryWay())
.deliveryWay(buildDeliveryWay(skupType))
.couponCodes(request.getCouponCodes()).build();
ChargeGoods chargeGoods = ChargeGoods.builder()
.goodsPrice(skupInfo.getGoodsPrice())
.productId(skupInfo.getProductId())
.attributes(skupAttr)
.skup(skupInfo.getId())
.activityCutPrice(BigDecimal.ZERO)
.skupType(skupType)
.tariffRate(tariffRate)
.build();
return ChargeContext.builder()
.chargeParam(chargeParam)
.chargeGoods(ChargeGoods.builder().goodsPrice(skupInfo.getGoodsPrice()).productId(skupInfo.getProductId())
.attributes(skupInfo.getAttributes()).skup(skupInfo.getId()).activityCutPrice(BigDecimal.ZERO).build())
.chargeGoods(chargeGoods)
.activityPrice(activityPrice)
.build();
... ... @@ -325,6 +346,32 @@ public class ShoppingServiceImpl implements IShoppingService {
return response;
}
private FeeNRate buildDefaultFeeNRate(SkupType skupType){
FeeNRate feeNRate = null;
switch (skupType){
case HK_IN_STOCK:
feeNRate = new FeeNRate();
feeNRate.setShipFee(new BigDecimal(55));
feeNRate.setShipFee(new BigDecimal(0.091));
break;
}
return feeNRate;
}
private FeeNRate getFeeNRate(SkupType skupType){
if (skupType == null){
return null;
}
Map<String,FeeNRate> config = metaConfigService.getBuyerOrderFeeNRate();
if (config == null){
// set default
return buildDefaultFeeNRate(skupType);
}
return config.get(skupType.getLocalCacheKey());
}
/**
* 提交订单
* @param shoppingRequest
... ... @@ -366,6 +413,8 @@ public class ShoppingServiceImpl implements IShoppingService {
logger.info("generate new orderCode:{}",orderCode);
SkupType skupType = chargeContext.getChargeGoods().getSkupType();
// 减库存,skup更新成不可售,入库
//BigDecimal shipFee = new BigDecimal(delivery_way_sf_cost);
OrderBuilder orderBuilder = OrderBuilder.builder()
... ... @@ -374,7 +423,7 @@ public class ShoppingServiceImpl implements IShoppingService {
.orderCode(orderCode)
.productId(psog.getProductId())
.paymentType(OrderConstant.PAYMENT_ONLINE)
.deliverWay(buildDeliveryWay())
.deliverWay(buildDeliveryWay(skupType))
.channelNo(shoppingRequest.getChannelNo())
.amount(BigDecimal.valueOf(chargeResult.getFinalAmount()))
.shipFee(BigDecimal.valueOf(chargeResult.getFinalShippingAmount()))
... ... @@ -425,7 +474,7 @@ public class ShoppingServiceImpl implements IShoppingService {
//
inBoxFacade.sellerSkupCreateOrderByBuyer(sellerUid, psog);
}else{
logger.warn("buyer submit order ");
logger.warn("buyer submit order ordeCreationService.doSubmitOrder fail shoppingRequest {}", shoppingRequest);
}
// 返回结果
return OrderSubmitResponse.builder().orderCode(orderCode).productId(psog.getProductId())
... ... @@ -548,6 +597,8 @@ public class ShoppingServiceImpl implements IShoppingService {
//活动金额
amountDetailBo.setActivityCutAmount(chargeResult.getActivityCutResult().getActivityCutAmount());
//税费
amountDetailBo.setTariffAmount(chargeResult.getTariffAmount());
//活动券减免金额
chargeResult.getCouponPayResultList().getCouponPayResultByCouponType(CouponTypeEnum.ACTIVITY_COUPON.getCode()).
ifPresent(tempPayResult -> amountDetailBo.setCouponCutAmount(tempPayResult.getCouponAmount()));
... ... @@ -559,8 +610,33 @@ public class ShoppingServiceImpl implements IShoppingService {
return amountDetailBo;
}
protected int buildDeliveryWay() {
return OrderConstant.DELIVERY_WAY_SF;
protected int buildDeliveryWay(SkupType skupType) {
DeliveryWayEnum deliveryWay ;
if (skupType==null){
deliveryWay = DeliveryWayEnum.SF;
}else{
SkupTypeCodeSupport.CodeNode codeNode = SkupTypeCodeSupport.explain(skupType.getCode());
RegionEnum regionEnum = RegionEnum.getByCode(codeNode.getRegion());
if (regionEnum == null){
deliveryWay = DeliveryWayEnum.SF;
}else{
switch (regionEnum){
case HONGKONG:
deliveryWay = DeliveryWayEnum.OVERSEAS_HONGHONG;
break;
case MAINLAND:
default:
deliveryWay = DeliveryWayEnum.SF;
break;
}
}
}
return deliveryWay.getCode();
}
}
... ...
... ... @@ -18,6 +18,7 @@ import com.yohoufo.common.alarm.SmsAlarmEvent;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.convert.builder.AlarmEventBuilder;
import com.yohoufo.order.service.seller.support.SkupTypeCodeSupport;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
... ... @@ -329,16 +330,18 @@ public class ProductProxyService extends AbsProxyService{
skupReq.setStorageId(goods.getStorageId());
skupReq.setPrice(goods.getGoodsPrice());
skupReq.setSellerUid(goods.getUid());
Integer skupa = goods.getAttributes();
Integer skupa = goods.getAttributes() == null ? 0 : goods.getAttributes();
SkupTypeCodeSupport.CodeNode codeNode = SkupTypeCodeSupport.explain(skupa);
skupReq.setRegion(codeNode.getRegion());
if (Objects.nonNull(skupa) && SkupType.ADVANCE.getCode() == skupa){
skupReq.setPreSaleFlag(isAdvace);
}
skupBoList.add(skupReq);
skupList.add(goods.getId());
}
ApiResponse resp = ufoServiceCaller.call(batchCreateSkup, skupBoList);
logger.info("call {} resp {}", batchCreateSkup, resp);
final String serviceName = batchCreateSkup;
ApiResponse resp = ufoServiceCaller.call(serviceName, skupBoList);
logger.info("call {} resp {}", serviceName, resp);
return (null == resp || null == resp.getData())? false : (boolean)resp.getData();
}
... ...
... ... @@ -54,7 +54,7 @@ public class SkupTypeCodeSupport {
public static void main(String[] args) {
CodeNode cn = SkupTypeCodeSupport.explain(19);
CodeNode cn = SkupTypeCodeSupport.explain(0);
System.out.println("test SkupTypeCodeSupport.explain -->" + cn);
System.out.println("generate-->" +generate(cn));
}
... ...
... ... @@ -72,4 +72,8 @@ public class DeliveryWayCostSupport {
}
public double getCostFromHk(){
return 35D;
}
}
... ...
package com.yohoufo.order.service.support;
import com.google.common.collect.Lists;
import com.yohobuy.ufo.model.order.constants.DeliveryWayEnum;
import com.yohobuy.ufo.model.order.constants.OrderDetailDesc;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.promotion.constant.CouponTypeEnum;
... ... @@ -69,11 +70,11 @@ public class ShoppingSupport {
private String getDeliveryWayStr(int deliveryWay) {
return deliveryWay == OrderConstant.DELIVERY_WAY_STORE ? OrderConstant.DELIVERY_WAY_STORE_NAME : OrderConstant.DELIVERY_WAY_SF_NAME;
return deliveryWay == DeliveryWayEnum.SELF_FETCH.getCode() ? OrderConstant.DELIVERY_WAY_STORE_NAME : OrderConstant.DELIVERY_WAY_SF_NAME;
}
public boolean isDeliveryWayByStore(int deliveryWay) {
return deliveryWay == OrderConstant.DELIVERY_WAY_STORE;
return deliveryWay == DeliveryWayEnum.SELF_FETCH.getCode();
}
... ... @@ -111,19 +112,24 @@ public class ShoppingSupport {
goodsFormula.setPromotionAmount(MathUtils.formatCurrencyStr(chargeResult.getGoodsAmount()));
formulas.add(goodsFormula);
//运费
PromotionFormula expressFormula = new PromotionFormula();
expressFormula.setPromotion(OrderConstant.DELIVERY_DESC);
String shipFee = OrderConstant.PLUS_SIGN + MathUtils.formatCurrencyStr(chargeResult.getShippingAmount());
expressFormula.setPromotionAmount(shipFee);
formulas.add(expressFormula);
//税费
double tariffAmount;
if ((tariffAmount=chargeResult.getTariffAmount()) > 0D){
PromotionFormula tariffFormula = new PromotionFormula();
tariffFormula.setPromotion(OrderConstant.TAX_DESC);
String tariffAmountDesc = OrderConstant.PLUS_SIGN + MathUtils.formatCurrencyStr(tariffAmount);
tariffFormula.setPromotionAmount(tariffAmountDesc);
formulas.add(tariffFormula);
}
//活动优惠
ActivityCutResult activityCutResult = chargeResult.getActivityCutResult();
if (activityCutResult.getActivityCutAmount() > 0) {
if (activityCutResult.getActivityCutAmount() > 0D) {
PromotionFormula activityFormula = new PromotionFormula();
activityFormula.setPromotion(OrderConstant.ACTIVITY_DESC);
activityFormula.setPromotionAmount(OrderConstant.SUB_SIGN + MathUtils.formatCurrencyStr(activityCutResult.getActivityCutAmount()));
... ...