...
|
...
|
@@ -4,6 +4,7 @@ import com.google.common.collect.Lists; |
|
|
import com.yoho.core.rest.client.ServiceCaller;
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yohobuy.ufo.model.promotion.UserCouponsBo;
|
|
|
import com.yohoufo.common.alarm.EventBusPublisher;
|
|
|
import com.yohoufo.common.utils.AddressUtil;
|
|
|
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
|
...
|
...
|
@@ -18,6 +19,7 @@ import com.yohoufo.order.charge.CouponRuleMatcher; |
|
|
import com.yohoufo.order.charge.model.ChargeGoods;
|
|
|
import com.yohoufo.order.charge.model.ChargeParam;
|
|
|
import com.yohoufo.order.charge.model.ChargeResult;
|
|
|
import com.yohoufo.order.charge.model.CouponMatchResult;
|
|
|
import com.yohoufo.order.event.BuyerCancelEvent;
|
|
|
import com.yohoufo.order.event.NotPaidNoticeEvent;
|
|
|
import com.yohoufo.order.model.AddressInfo;
|
...
|
...
|
@@ -31,16 +33,17 @@ import com.yohoufo.order.service.cache.CacheCleaner; |
|
|
import com.yohoufo.order.service.proxy.CouponProxyService;
|
|
|
import com.yohoufo.order.service.proxy.InBoxFacade;
|
|
|
import com.yohoufo.order.service.proxy.UserProxyService;
|
|
|
import com.yohoufo.order.service.support.CouponSupport;
|
|
|
import com.yohoufo.order.service.support.ShoppingSupport;
|
|
|
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
|
|
|
import com.yohoufo.order.utils.AddressHelper;
|
|
|
import com.yohoufo.order.utils.MathUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
...
|
...
|
@@ -89,6 +92,9 @@ public class ShoppingServiceImpl implements IShoppingService { |
|
|
@Autowired
|
|
|
private CouponRuleMatcher couponRuleMatcher;
|
|
|
|
|
|
@Autowired
|
|
|
private CouponSupport couponSupport;
|
|
|
|
|
|
/**
|
|
|
* 结算页数据
|
|
|
* @param request
|
...
|
...
|
@@ -151,99 +157,63 @@ public class ShoppingServiceImpl implements IShoppingService { |
|
|
|
|
|
@Override
|
|
|
public ShoppingCouponListResp selectCoupon(ShoppingRequest request) {
|
|
|
//todo
|
|
|
ShoppingCoupon coupon1 = new ShoppingCoupon();
|
|
|
coupon1.setCouponValueStr("100");
|
|
|
coupon1.setCouponCode("a123456");
|
|
|
coupon1.setCouponName("test");
|
|
|
coupon1.setCouponValidity("2018.1.1-2019.1.1");
|
|
|
coupon1.setSelected("N");
|
|
|
coupon1.setIsSelectedSupport("Y");
|
|
|
coupon1.setUseRuleStr("满499可用");
|
|
|
|
|
|
ShoppingCoupon coupon2 = new ShoppingCoupon();
|
|
|
coupon2.setCouponValueStr("50");
|
|
|
coupon2.setCouponCode("b987654");
|
|
|
coupon2.setCouponName("全场通用");
|
|
|
coupon2.setCouponValidity("2018.1.1-2019.1.1");
|
|
|
coupon2.setSelected("N");
|
|
|
coupon2.setIsSelectedSupport("Y");
|
|
|
coupon2.setUseRuleStr("满200可用");
|
|
|
ShoppingCouponListResp resp = new ShoppingCouponListResp();
|
|
|
resp.setCoupons(Lists.newArrayList(coupon1, coupon2));
|
|
|
return resp;
|
|
|
|
|
|
// if ((request.getSkup()) < 0 || request.getUid() < 0) {
|
|
|
// logger.warn("compute uid or skup is null");
|
|
|
// throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
// }
|
|
|
//
|
|
|
// // 检查 商品sku是否可售
|
|
|
// SellerOrderGoods skupGood = checkSkupSellOrNot(request.getSkup());
|
|
|
//
|
|
|
// //构建算费
|
|
|
// ChargeContext chargeContext = buildChargeContext(request, skupGood);
|
|
|
//
|
|
|
// List<UserCouponsBo> userCouponsBos = couponProxyService.getUserAvailableCoupons(chargeContext.getChargeParam().getUid());
|
|
|
// List<CouponMatchResult> couponMatchResults = couponRuleMatcher.match(userCouponsBos,chargeContext);
|
|
|
|
|
|
//todo
|
|
|
if ((request.getSkup()) < 0 || request.getUid() < 0) {
|
|
|
logger.warn("compute uid or skup is null");
|
|
|
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ComputeResponse compute(ShoppingRequest request) {
|
|
|
CouponInfo result = CouponInfo.builder().couponCode("a123456").couponAmountStr("¥50.00").couponTitle("test").couponCount(1).build();
|
|
|
// 检查 商品sku是否可售
|
|
|
SellerOrderGoods skupGood = checkSkupSellOrNot(request.getSkup());
|
|
|
|
|
|
//构建算费
|
|
|
ChargeContext chargeContext = buildChargeContext(request, skupGood);
|
|
|
|
|
|
PromotionFormula formula1 = new PromotionFormula();
|
|
|
formula1.setPromotion(OrderConstant.GOODS_PRICE);
|
|
|
formula1.setPromotionAmount(OrderConstant.MONEY_SIGN + "500");
|
|
|
//查询用户可用的优惠券
|
|
|
List<UserCouponsBo> userCouponsBos = couponProxyService.getUserAvailableCoupons(chargeContext.getChargeParam().getUid());
|
|
|
|
|
|
PromotionFormula formula2 = new PromotionFormula();
|
|
|
formula2.setPromotion(OrderConstant.DELIVERY_DESC);
|
|
|
formula2.setPromotionAmount(OrderConstant.PLUS_SIGN + OrderConstant.MONEY_SIGN + 25);
|
|
|
//进行券匹配
|
|
|
List<CouponMatchResult> couponMatchResults = couponRuleMatcher.match(userCouponsBos,chargeContext);
|
|
|
|
|
|
//满足当前商品的优惠券
|
|
|
List<ShoppingCoupon> usableCoupons = couponSupport.filterUsableCoupons(couponMatchResults);
|
|
|
|
|
|
PromotionFormula formula3 = new PromotionFormula();
|
|
|
formula3.setPromotion(OrderConstant.GOODS_REAL_PRICE);
|
|
|
formula3.setPromotionAmount(OrderConstant.MONEY_SIGN + "425");
|
|
|
//券选中
|
|
|
usableCoupons.forEach(shoppingCoupon -> {
|
|
|
if (request.getCouponCodes().contains(shoppingCoupon.getCouponCode())) {
|
|
|
shoppingCoupon.setSelected(OrderConstant.Y_STR);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
ShoppingCouponListResp resp = new ShoppingCouponListResp();
|
|
|
resp.setCoupons(usableCoupons);
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
PromotionFormula formula4 = new PromotionFormula();
|
|
|
formula4.setPromotion("优惠券");
|
|
|
formula4.setPromotionAmount("-"+ OrderConstant.MONEY_SIGN +"100");
|
|
|
@Override
|
|
|
public ComputeResponse compute(ShoppingRequest request) {
|
|
|
|
|
|
List<PromotionFormula> formulaList = Arrays.asList(formula1, formula2, formula4, formula3);
|
|
|
// 入口参数检查
|
|
|
if ((request.getSkup()) < 0 || request.getUid() < 0) {
|
|
|
logger.warn("compute uid or skup is null");
|
|
|
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
}
|
|
|
|
|
|
ComputeResponse response = new ComputeResponse();
|
|
|
// 检查 商品sku是否可售
|
|
|
SellerOrderGoods skupGood = checkSkupSellOrNot(request.getSkup());
|
|
|
//构建算费
|
|
|
ChargeContext chargeContext = buildChargeContext(request, skupGood);
|
|
|
//算费
|
|
|
chargeService.charge(chargeContext);
|
|
|
//算费结果
|
|
|
ChargeResult chargeResult = chargeContext.getChargeResult();
|
|
|
|
|
|
response.setCouponInfo(result);
|
|
|
response.setPromotionFormulaList(formulaList);
|
|
|
response.setAmount("425.00");
|
|
|
ComputeResponse response = new ComputeResponse();
|
|
|
response.setCouponInfo(shoppingSupport.getCouponInfo(chargeResult));
|
|
|
response.setPromotionFormulaList(shoppingSupport.getPromotionFormula(chargeResult));
|
|
|
response.setAmount(MathUtils.formatStr(chargeResult.getFinalAmount()));
|
|
|
|
|
|
return response;
|
|
|
|
|
|
// 入口参数检查
|
|
|
// if ((request.getSkup()) < 0 || request.getUid() < 0) {
|
|
|
// logger.warn("compute uid or skup is null");
|
|
|
// throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
// }
|
|
|
//
|
|
|
// // 检查 商品sku是否可售
|
|
|
// SellerOrderGoods skupGood = checkSkupSellOrNot(request.getSkup());
|
|
|
// //构建算费
|
|
|
// ChargeContext chargeContext = buildChargeContext(request, skupGood);
|
|
|
// //算费
|
|
|
// chargeService.charge(chargeContext);
|
|
|
// //算费结果
|
|
|
// ChargeResult chargeResult = chargeContext.getChargeResult();
|
|
|
//
|
|
|
// ComputeResponse response = new ComputeResponse();
|
|
|
// response.setCouponInfo(shoppingSupport.getCouponInfo(chargeResult));
|
|
|
// response.setPromotionFormulaList(shoppingSupport.getPromotionFormula(chargeResult));
|
|
|
// response.setAmount(MathUtils.formatStr(chargeResult.getFinalAmount()));
|
|
|
//
|
|
|
// return response;
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
|