|
@@ -4,6 +4,7 @@ import com.google.common.collect.Lists; |
|
@@ -4,6 +4,7 @@ import com.google.common.collect.Lists; |
4
|
import com.yoho.core.rest.client.ServiceCaller;
|
4
|
import com.yoho.core.rest.client.ServiceCaller;
|
5
|
import com.yoho.error.ServiceError;
|
5
|
import com.yoho.error.ServiceError;
|
6
|
import com.yoho.error.exception.ServiceException;
|
6
|
import com.yoho.error.exception.ServiceException;
|
|
|
7
|
+import com.yohobuy.ufo.model.promotion.UserCouponsBo;
|
7
|
import com.yohoufo.common.alarm.EventBusPublisher;
|
8
|
import com.yohoufo.common.alarm.EventBusPublisher;
|
8
|
import com.yohoufo.common.utils.AddressUtil;
|
9
|
import com.yohoufo.common.utils.AddressUtil;
|
9
|
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
|
10
|
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
|
|
@@ -18,6 +19,7 @@ import com.yohoufo.order.charge.CouponRuleMatcher; |
|
@@ -18,6 +19,7 @@ import com.yohoufo.order.charge.CouponRuleMatcher; |
18
|
import com.yohoufo.order.charge.model.ChargeGoods;
|
19
|
import com.yohoufo.order.charge.model.ChargeGoods;
|
19
|
import com.yohoufo.order.charge.model.ChargeParam;
|
20
|
import com.yohoufo.order.charge.model.ChargeParam;
|
20
|
import com.yohoufo.order.charge.model.ChargeResult;
|
21
|
import com.yohoufo.order.charge.model.ChargeResult;
|
|
|
22
|
+import com.yohoufo.order.charge.model.CouponMatchResult;
|
21
|
import com.yohoufo.order.event.BuyerCancelEvent;
|
23
|
import com.yohoufo.order.event.BuyerCancelEvent;
|
22
|
import com.yohoufo.order.event.NotPaidNoticeEvent;
|
24
|
import com.yohoufo.order.event.NotPaidNoticeEvent;
|
23
|
import com.yohoufo.order.model.AddressInfo;
|
25
|
import com.yohoufo.order.model.AddressInfo;
|
|
@@ -31,16 +33,17 @@ import com.yohoufo.order.service.cache.CacheCleaner; |
|
@@ -31,16 +33,17 @@ import com.yohoufo.order.service.cache.CacheCleaner; |
31
|
import com.yohoufo.order.service.proxy.CouponProxyService;
|
33
|
import com.yohoufo.order.service.proxy.CouponProxyService;
|
32
|
import com.yohoufo.order.service.proxy.InBoxFacade;
|
34
|
import com.yohoufo.order.service.proxy.InBoxFacade;
|
33
|
import com.yohoufo.order.service.proxy.UserProxyService;
|
35
|
import com.yohoufo.order.service.proxy.UserProxyService;
|
|
|
36
|
+import com.yohoufo.order.service.support.CouponSupport;
|
34
|
import com.yohoufo.order.service.support.ShoppingSupport;
|
37
|
import com.yohoufo.order.service.support.ShoppingSupport;
|
35
|
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
|
38
|
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
|
36
|
import com.yohoufo.order.utils.AddressHelper;
|
39
|
import com.yohoufo.order.utils.AddressHelper;
|
37
|
import com.yohoufo.order.utils.MathUtils;
|
40
|
import com.yohoufo.order.utils.MathUtils;
|
38
|
import org.apache.commons.lang3.StringUtils;
|
41
|
import org.apache.commons.lang3.StringUtils;
|
|
|
42
|
+import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
|
39
|
import org.slf4j.Logger;
|
43
|
import org.slf4j.Logger;
|
40
|
import org.slf4j.LoggerFactory;
|
44
|
import org.slf4j.LoggerFactory;
|
41
|
import org.springframework.beans.factory.annotation.Autowired;
|
45
|
import org.springframework.beans.factory.annotation.Autowired;
|
42
|
import java.math.BigDecimal;
|
46
|
import java.math.BigDecimal;
|
43
|
-import java.util.Arrays;
|
|
|
44
|
import java.util.List;
|
47
|
import java.util.List;
|
45
|
import org.springframework.stereotype.Service;
|
48
|
import org.springframework.stereotype.Service;
|
46
|
|
49
|
|
|
@@ -89,6 +92,9 @@ public class ShoppingServiceImpl implements IShoppingService { |
|
@@ -89,6 +92,9 @@ public class ShoppingServiceImpl implements IShoppingService { |
89
|
@Autowired
|
92
|
@Autowired
|
90
|
private CouponRuleMatcher couponRuleMatcher;
|
93
|
private CouponRuleMatcher couponRuleMatcher;
|
91
|
|
94
|
|
|
|
95
|
+ @Autowired
|
|
|
96
|
+ private CouponSupport couponSupport;
|
|
|
97
|
+
|
92
|
/**
|
98
|
/**
|
93
|
* 结算页数据
|
99
|
* 结算页数据
|
94
|
* @param request
|
100
|
* @param request
|
|
@@ -151,99 +157,63 @@ public class ShoppingServiceImpl implements IShoppingService { |
|
@@ -151,99 +157,63 @@ public class ShoppingServiceImpl implements IShoppingService { |
151
|
|
157
|
|
152
|
@Override
|
158
|
@Override
|
153
|
public ShoppingCouponListResp selectCoupon(ShoppingRequest request) {
|
159
|
public ShoppingCouponListResp selectCoupon(ShoppingRequest request) {
|
154
|
- //todo
|
|
|
155
|
- ShoppingCoupon coupon1 = new ShoppingCoupon();
|
|
|
156
|
- coupon1.setCouponValueStr("100");
|
|
|
157
|
- coupon1.setCouponCode("a123456");
|
|
|
158
|
- coupon1.setCouponName("test");
|
|
|
159
|
- coupon1.setCouponValidity("2018.1.1-2019.1.1");
|
|
|
160
|
- coupon1.setSelected("N");
|
|
|
161
|
- coupon1.setIsSelectedSupport("Y");
|
|
|
162
|
- coupon1.setUseRuleStr("满499可用");
|
|
|
163
|
-
|
|
|
164
|
- ShoppingCoupon coupon2 = new ShoppingCoupon();
|
|
|
165
|
- coupon2.setCouponValueStr("50");
|
|
|
166
|
- coupon2.setCouponCode("b987654");
|
|
|
167
|
- coupon2.setCouponName("全场通用");
|
|
|
168
|
- coupon2.setCouponValidity("2018.1.1-2019.1.1");
|
|
|
169
|
- coupon2.setSelected("N");
|
|
|
170
|
- coupon2.setIsSelectedSupport("Y");
|
|
|
171
|
- coupon2.setUseRuleStr("满200可用");
|
|
|
172
|
- ShoppingCouponListResp resp = new ShoppingCouponListResp();
|
|
|
173
|
- resp.setCoupons(Lists.newArrayList(coupon1, coupon2));
|
|
|
174
|
- return resp;
|
|
|
175
|
|
160
|
|
176
|
-// if ((request.getSkup()) < 0 || request.getUid() < 0) {
|
|
|
177
|
-// logger.warn("compute uid or skup is null");
|
|
|
178
|
-// throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
179
|
-// }
|
|
|
180
|
-//
|
|
|
181
|
-// // 检查 商品sku是否可售
|
|
|
182
|
-// SellerOrderGoods skupGood = checkSkupSellOrNot(request.getSkup());
|
|
|
183
|
-//
|
|
|
184
|
-// //构建算费
|
|
|
185
|
-// ChargeContext chargeContext = buildChargeContext(request, skupGood);
|
|
|
186
|
-//
|
|
|
187
|
-// List<UserCouponsBo> userCouponsBos = couponProxyService.getUserAvailableCoupons(chargeContext.getChargeParam().getUid());
|
|
|
188
|
-// List<CouponMatchResult> couponMatchResults = couponRuleMatcher.match(userCouponsBos,chargeContext);
|
161
|
+ if ((request.getSkup()) < 0 || request.getUid() < 0) {
|
|
|
162
|
+ logger.warn("compute uid or skup is null");
|
|
|
163
|
+ throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
164
|
+ }
|
189
|
|
165
|
|
190
|
- //todo
|
|
|
191
|
- }
|
166
|
+ // 检查 商品sku是否可售
|
|
|
167
|
+ SellerOrderGoods skupGood = checkSkupSellOrNot(request.getSkup());
|
192
|
|
168
|
|
193
|
- @Override
|
|
|
194
|
- public ComputeResponse compute(ShoppingRequest request) {
|
|
|
195
|
- CouponInfo result = CouponInfo.builder().couponCode("a123456").couponAmountStr("¥50.00").couponTitle("test").couponCount(1).build();
|
169
|
+ //构建算费
|
|
|
170
|
+ ChargeContext chargeContext = buildChargeContext(request, skupGood);
|
196
|
|
171
|
|
|
|
172
|
+ //查询用户可用的优惠券
|
|
|
173
|
+ List<UserCouponsBo> userCouponsBos = couponProxyService.getUserAvailableCoupons(chargeContext.getChargeParam().getUid());
|
197
|
|
174
|
|
198
|
- PromotionFormula formula1 = new PromotionFormula();
|
|
|
199
|
- formula1.setPromotion(OrderConstant.GOODS_PRICE);
|
|
|
200
|
- formula1.setPromotionAmount(OrderConstant.MONEY_SIGN + "500");
|
175
|
+ //进行券匹配
|
|
|
176
|
+ List<CouponMatchResult> couponMatchResults = couponRuleMatcher.match(userCouponsBos,chargeContext);
|
201
|
|
177
|
|
202
|
- PromotionFormula formula2 = new PromotionFormula();
|
|
|
203
|
- formula2.setPromotion(OrderConstant.DELIVERY_DESC);
|
|
|
204
|
- formula2.setPromotionAmount(OrderConstant.PLUS_SIGN + OrderConstant.MONEY_SIGN + 25);
|
178
|
+ //满足当前商品的优惠券
|
|
|
179
|
+ List<ShoppingCoupon> usableCoupons = couponSupport.filterUsableCoupons(couponMatchResults);
|
205
|
|
180
|
|
|
|
181
|
+ //券选中
|
|
|
182
|
+ usableCoupons.forEach(shoppingCoupon -> {
|
|
|
183
|
+ if (request.getCouponCodes().contains(shoppingCoupon.getCouponCode())) {
|
|
|
184
|
+ shoppingCoupon.setSelected(OrderConstant.Y_STR);
|
|
|
185
|
+ }
|
|
|
186
|
+ });
|
206
|
|
187
|
|
207
|
- PromotionFormula formula3 = new PromotionFormula();
|
|
|
208
|
- formula3.setPromotion(OrderConstant.GOODS_REAL_PRICE);
|
|
|
209
|
- formula3.setPromotionAmount(OrderConstant.MONEY_SIGN + "425");
|
188
|
+ ShoppingCouponListResp resp = new ShoppingCouponListResp();
|
|
|
189
|
+ resp.setCoupons(usableCoupons);
|
|
|
190
|
+ return resp;
|
|
|
191
|
+ }
|
210
|
|
192
|
|
|
|
193
|
+ @Override
|
|
|
194
|
+ public ComputeResponse compute(ShoppingRequest request) {
|
211
|
|
195
|
|
212
|
- PromotionFormula formula4 = new PromotionFormula();
|
|
|
213
|
- formula4.setPromotion("优惠券");
|
|
|
214
|
- formula4.setPromotionAmount("-"+ OrderConstant.MONEY_SIGN +"100");
|
196
|
+ // 入口参数检查
|
|
|
197
|
+ if ((request.getSkup()) < 0 || request.getUid() < 0) {
|
|
|
198
|
+ logger.warn("compute uid or skup is null");
|
|
|
199
|
+ throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
200
|
+ }
|
215
|
|
201
|
|
216
|
- List<PromotionFormula> formulaList = Arrays.asList(formula1, formula2, formula4, formula3);
|
202
|
+ // 检查 商品sku是否可售
|
|
|
203
|
+ SellerOrderGoods skupGood = checkSkupSellOrNot(request.getSkup());
|
|
|
204
|
+ //构建算费
|
|
|
205
|
+ ChargeContext chargeContext = buildChargeContext(request, skupGood);
|
|
|
206
|
+ //算费
|
|
|
207
|
+ chargeService.charge(chargeContext);
|
|
|
208
|
+ //算费结果
|
|
|
209
|
+ ChargeResult chargeResult = chargeContext.getChargeResult();
|
217
|
|
210
|
|
218
|
ComputeResponse response = new ComputeResponse();
|
211
|
ComputeResponse response = new ComputeResponse();
|
219
|
-
|
|
|
220
|
- response.setCouponInfo(result);
|
|
|
221
|
- response.setPromotionFormulaList(formulaList);
|
|
|
222
|
- response.setAmount("425.00");
|
212
|
+ response.setCouponInfo(shoppingSupport.getCouponInfo(chargeResult));
|
|
|
213
|
+ response.setPromotionFormulaList(shoppingSupport.getPromotionFormula(chargeResult));
|
|
|
214
|
+ response.setAmount(MathUtils.formatStr(chargeResult.getFinalAmount()));
|
223
|
|
215
|
|
224
|
return response;
|
216
|
return response;
|
225
|
-
|
|
|
226
|
- // 入口参数检查
|
|
|
227
|
-// if ((request.getSkup()) < 0 || request.getUid() < 0) {
|
|
|
228
|
-// logger.warn("compute uid or skup is null");
|
|
|
229
|
-// throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
230
|
-// }
|
|
|
231
|
-//
|
|
|
232
|
-// // 检查 商品sku是否可售
|
|
|
233
|
-// SellerOrderGoods skupGood = checkSkupSellOrNot(request.getSkup());
|
|
|
234
|
-// //构建算费
|
|
|
235
|
-// ChargeContext chargeContext = buildChargeContext(request, skupGood);
|
|
|
236
|
-// //算费
|
|
|
237
|
-// chargeService.charge(chargeContext);
|
|
|
238
|
-// //算费结果
|
|
|
239
|
-// ChargeResult chargeResult = chargeContext.getChargeResult();
|
|
|
240
|
-//
|
|
|
241
|
-// ComputeResponse response = new ComputeResponse();
|
|
|
242
|
-// response.setCouponInfo(shoppingSupport.getCouponInfo(chargeResult));
|
|
|
243
|
-// response.setPromotionFormulaList(shoppingSupport.getPromotionFormula(chargeResult));
|
|
|
244
|
-// response.setAmount(MathUtils.formatStr(chargeResult.getFinalAmount()));
|
|
|
245
|
-//
|
|
|
246
|
-// return response;
|
|
|
247
|
}
|
217
|
}
|
248
|
|
218
|
|
249
|
/**
|
219
|
/**
|