Showing
16 changed files
with
229 additions
and
35 deletions
@@ -30,6 +30,8 @@ public interface SellerOrderMapper { | @@ -30,6 +30,8 @@ public interface SellerOrderMapper { | ||
30 | 30 | ||
31 | int updateByOrderCode(SellerOrder record); | 31 | int updateByOrderCode(SellerOrder record); |
32 | 32 | ||
33 | + int updateAmountByOrderCode(SellerOrder record); | ||
34 | + | ||
33 | int updateBySkups(@Param("condition") SellerOrder condition,@Param("skupList") Collection<Integer> skups); | 35 | int updateBySkups(@Param("condition") SellerOrder condition,@Param("skupList") Collection<Integer> skups); |
34 | 36 | ||
35 | List<SellerOrder> selectBySkups(@Param("skupList") Collection<Integer> skups); | 37 | List<SellerOrder> selectBySkups(@Param("skupList") Collection<Integer> skups); |
1 | package com.yohoufo.dal.order.model; | 1 | package com.yohoufo.dal.order.model; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
4 | +import lombok.Getter; | ||
5 | +import lombok.Setter; | ||
4 | 6 | ||
5 | import java.math.BigDecimal; | 7 | import java.math.BigDecimal; |
6 | 8 | ||
@@ -21,6 +23,8 @@ public class SellerOrder { | @@ -21,6 +23,8 @@ public class SellerOrder { | ||
21 | 23 | ||
22 | private BigDecimal earnestMoney; | 24 | private BigDecimal earnestMoney; |
23 | 25 | ||
26 | + @Getter@Setter | ||
27 | + private BigDecimal couponCutAmount; | ||
24 | 28 | ||
25 | private Integer isDel; | 29 | private Integer isDel; |
26 | 30 |
@@ -9,6 +9,7 @@ | @@ -9,6 +9,7 @@ | ||
9 | <result column="client_type" jdbcType="TINYINT" property="clientType" /> | 9 | <result column="client_type" jdbcType="TINYINT" property="clientType" /> |
10 | <result column="payment" jdbcType="TINYINT" property="payment" /> | 10 | <result column="payment" jdbcType="TINYINT" property="payment" /> |
11 | <result column="income" jdbcType="DECIMAL" property="income" /> | 11 | <result column="income" jdbcType="DECIMAL" property="income" /> |
12 | + <result column="coupon_cut_amount" property="couponCutAmount" jdbcType="DECIMAL"/> | ||
12 | <result column="earnest_money" jdbcType="DECIMAL" property="earnestMoney" /> | 13 | <result column="earnest_money" jdbcType="DECIMAL" property="earnestMoney" /> |
13 | <result column="is_del" jdbcType="TINYINT" property="isDel" /> | 14 | <result column="is_del" jdbcType="TINYINT" property="isDel" /> |
14 | <result column="status" jdbcType="TINYINT" property="status" /> | 15 | <result column="status" jdbcType="TINYINT" property="status" /> |
@@ -16,7 +17,7 @@ | @@ -16,7 +17,7 @@ | ||
16 | <result column="update_time" jdbcType="INTEGER" property="updateTime" /> | 17 | <result column="update_time" jdbcType="INTEGER" property="updateTime" /> |
17 | </resultMap> | 18 | </resultMap> |
18 | <sql id="Base_Column_List"> | 19 | <sql id="Base_Column_List"> |
19 | - id, order_code, skup, uid, client_type, payment, income, earnest_money, is_del, | 20 | + id, order_code, skup, uid, client_type, payment, income, earnest_money, coupon_cut_amount, is_del, |
20 | status, create_time, update_time | 21 | status, create_time, update_time |
21 | </sql> | 22 | </sql> |
22 | <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> | 23 | <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> |
@@ -271,6 +272,19 @@ | @@ -271,6 +272,19 @@ | ||
271 | </update> | 272 | </update> |
272 | 273 | ||
273 | 274 | ||
275 | + <update id="updateAmountByOrderCode" parameterType="com.yohoufo.dal.order.model.SellerOrder"> | ||
276 | + update seller_order | ||
277 | + <set> | ||
278 | + income = #{income,jdbcType=DECIMAL}, | ||
279 | + <if test="couponCutAmount != null"> | ||
280 | + coupon_cut_amount = #{couponCutAmount,jdbcType=DECIMAL}, | ||
281 | + </if> | ||
282 | + </set> | ||
283 | + where uid = #{uid,jdbcType=INTEGER} | ||
284 | + and order_code = #{orderCode,jdbcType=BIGINT} | ||
285 | + </update> | ||
286 | + | ||
287 | + | ||
274 | <select id="selectOrderNumByUid" resultType="java.lang.Integer"> | 288 | <select id="selectOrderNumByUid" resultType="java.lang.Integer"> |
275 | select count(*) from seller_order where uid = #{uid,jdbcType=INTEGER} and is_del = 1 | 289 | select count(*) from seller_order where uid = #{uid,jdbcType=INTEGER} and is_del = 1 |
276 | and status in | 290 | and status in |
@@ -125,6 +125,12 @@ public final class SellerOrderConvertor { | @@ -125,6 +125,12 @@ public final class SellerOrderConvertor { | ||
125 | String incomeStr = formatFee(income); | 125 | String incomeStr = formatFee(income); |
126 | String earnestMoneyStr = formatFee(earnestMoney); | 126 | String earnestMoneyStr = formatFee(earnestMoney); |
127 | String bankTransferFeeStr = formatFee(computeResult.getBankTransferfee()); | 127 | String bankTransferFeeStr = formatFee(computeResult.getBankTransferfee()); |
128 | + | ||
129 | + // | ||
130 | + BigDecimal couponCutAmount = computeResult.getCouponCutAmount(); | ||
131 | + CouponInfo couponInfo = Objects.isNull(couponCutAmount) ? null | ||
132 | + : CouponInfo.builder().couponAmountStr(formatFee(couponCutAmount)).build(); | ||
133 | + | ||
128 | // | 134 | // |
129 | SoldPrdComputeBo computeBo = SoldPrdComputeBo.builder() | 135 | SoldPrdComputeBo computeBo = SoldPrdComputeBo.builder() |
130 | .earnestMoney(earnestMoney.doubleValue()) | 136 | .earnestMoney(earnestMoney.doubleValue()) |
@@ -132,6 +138,7 @@ public final class SellerOrderConvertor { | @@ -132,6 +138,7 @@ public final class SellerOrderConvertor { | ||
132 | .platformFee(platformFeeWrapper) | 138 | .platformFee(platformFeeWrapper) |
133 | .bankTransferFee(buildSubtractFee(bankTransferFeeStr)) | 139 | .bankTransferFee(buildSubtractFee(bankTransferFeeStr)) |
134 | .income(incomeStr) | 140 | .income(incomeStr) |
141 | + .couponInfo(couponInfo) | ||
135 | .build(); | 142 | .build(); |
136 | return computeBo; | 143 | return computeBo; |
137 | 144 |
@@ -17,6 +17,7 @@ import com.yohoufo.order.model.bo.CouponBo; | @@ -17,6 +17,7 @@ import com.yohoufo.order.model.bo.CouponBo; | ||
17 | import com.yohoufo.order.model.bo.CouponBoList; | 17 | import com.yohoufo.order.model.bo.CouponBoList; |
18 | import com.yohoufo.order.model.dto.OrderBuilder; | 18 | import com.yohoufo.order.model.dto.OrderBuilder; |
19 | import com.yohoufo.order.service.impl.ShoppingServiceImpl; | 19 | import com.yohoufo.order.service.impl.ShoppingServiceImpl; |
20 | +import com.yohoufo.order.service.support.CouponSupport; | ||
20 | import com.yohoufo.order.utils.OrderAssist; | 21 | import com.yohoufo.order.utils.OrderAssist; |
21 | import org.apache.commons.lang3.StringUtils; | 22 | import org.apache.commons.lang3.StringUtils; |
22 | import org.apache.commons.lang3.tuple.Pair; | 23 | import org.apache.commons.lang3.tuple.Pair; |
@@ -51,7 +52,7 @@ public class OrderBuilderFactory { | @@ -51,7 +52,7 @@ public class OrderBuilderFactory { | ||
51 | .channelNo(channelNo) | 52 | .channelNo(channelNo) |
52 | .amount(BigDecimal.valueOf(chargeResult.getFinalAmount())) | 53 | .amount(BigDecimal.valueOf(chargeResult.getFinalAmount())) |
53 | .shipFee(BigDecimal.valueOf(chargeResult.getFinalShippingAmount())) | 54 | .shipFee(BigDecimal.valueOf(chargeResult.getFinalShippingAmount())) |
54 | - .couponBoList(buildOrderCouponBoList(chargeResult)) | 55 | + .couponBoList(CouponSupport.buildOrderCouponBoList(chargeResult.getCouponPayResultList())) |
55 | .hiddenAddressInfo(userAddressPair.getRight()) | 56 | .hiddenAddressInfo(userAddressPair.getRight()) |
56 | .addressInfo(userAddressPair.getLeft()) | 57 | .addressInfo(userAddressPair.getLeft()) |
57 | .clientType(clientType) | 58 | .clientType(clientType) |
@@ -95,23 +96,7 @@ public class OrderBuilderFactory { | @@ -95,23 +96,7 @@ public class OrderBuilderFactory { | ||
95 | .build(); | 96 | .build(); |
96 | } | 97 | } |
97 | 98 | ||
98 | - /** | ||
99 | - * 优惠券支付结果 | ||
100 | - * | ||
101 | - * @param chargeResult | ||
102 | - * @return | ||
103 | - */ | ||
104 | - protected CouponBoList buildOrderCouponBoList(ChargeResult chargeResult) { | ||
105 | - return CouponBoList.builder().couponBos(chargeResult.getCouponPayResultList().getCouponPayResults().stream() | ||
106 | - .map(couponPayResult -> CouponBo.builder() | ||
107 | - .couponCode(couponPayResult.getCouponCode()) | ||
108 | - .couponType(couponPayResult.getCouponType()) | ||
109 | - .couponAmount(BigDecimal.valueOf(couponPayResult.getCouponAmount())) | ||
110 | - .build() | ||
111 | - ) | ||
112 | - .collect(Collectors.toList()) | ||
113 | - ).build(); | ||
114 | - } | 99 | + |
115 | 100 | ||
116 | /** | 101 | /** |
117 | * 订单金额明细 | 102 | * 订单金额明细 |
@@ -2,9 +2,7 @@ package com.yohoufo.order.model.dto; | @@ -2,9 +2,7 @@ package com.yohoufo.order.model.dto; | ||
2 | 2 | ||
3 | import com.alibaba.fastjson.annotation.JSONField; | 3 | import com.alibaba.fastjson.annotation.JSONField; |
4 | import com.google.common.collect.Lists; | 4 | import com.google.common.collect.Lists; |
5 | -import com.yohobuy.ufo.model.order.bo.SellerCouponSimpleBo; | ||
6 | import com.yohobuy.ufo.model.order.dto.PlatformFeeDto; | 5 | import com.yohobuy.ufo.model.order.dto.PlatformFeeDto; |
7 | -import com.yohoufo.order.charge.model.ActivityCutResult; | ||
8 | import com.yohoufo.order.charge.model.CouponMatchResult; | 6 | import com.yohoufo.order.charge.model.CouponMatchResult; |
9 | import com.yohoufo.order.charge.model.CouponPayResultList; | 7 | import com.yohoufo.order.charge.model.CouponPayResultList; |
10 | import lombok.Data; | 8 | import lombok.Data; |
@@ -44,6 +42,8 @@ public class SellerOrderComputeResult { | @@ -44,6 +42,8 @@ public class SellerOrderComputeResult { | ||
44 | @JSONField(serialize = false, deserialize = false) | 42 | @JSONField(serialize = false, deserialize = false) |
45 | private transient CouponPayResultList couponPayResultList; | 43 | private transient CouponPayResultList couponPayResultList; |
46 | 44 | ||
45 | + @JSONField(serialize = false, deserialize = false) | ||
46 | + private transient boolean amountIsReset; | ||
47 | /** | 47 | /** |
48 | * 支付的券是否是自动推优 | 48 | * 支付的券是否是自动推优 |
49 | */ | 49 | */ |
1 | +package com.yohoufo.order.model.dto; | ||
2 | + | ||
3 | + | ||
4 | +import com.yohoufo.dal.order.model.SellerOrder; | ||
5 | +import com.yohoufo.order.model.bo.CouponBoList; | ||
6 | +import lombok.AllArgsConstructor; | ||
7 | +import lombok.Builder; | ||
8 | +import lombok.Data; | ||
9 | +import lombok.NoArgsConstructor; | ||
10 | + | ||
11 | +@Data | ||
12 | +@Builder | ||
13 | +@NoArgsConstructor@AllArgsConstructor | ||
14 | +public class SellerOrderSubmitDTO { | ||
15 | + | ||
16 | + | ||
17 | + private SellerOrder sellerOrder; | ||
18 | + | ||
19 | + | ||
20 | + /** | ||
21 | + * 使用的优惠券 | ||
22 | + */ | ||
23 | + private CouponBoList couponBoList; | ||
24 | + | ||
25 | + | ||
26 | + private SellerOrderComputeResult computeResult; | ||
27 | + | ||
28 | +} |
@@ -11,6 +11,7 @@ import com.yohobuy.ufo.model.order.constants.DepotType; | @@ -11,6 +11,7 @@ import com.yohobuy.ufo.model.order.constants.DepotType; | ||
11 | import com.yohobuy.ufo.model.order.constants.OrderConstant; | 11 | import com.yohobuy.ufo.model.order.constants.OrderConstant; |
12 | import com.yohobuy.ufo.model.order.constants.OrderDetailDesc; | 12 | import com.yohobuy.ufo.model.order.constants.OrderDetailDesc; |
13 | import com.yohobuy.ufo.model.order.constants.SkupType; | 13 | import com.yohobuy.ufo.model.order.constants.SkupType; |
14 | +import com.yohobuy.ufo.model.order.resp.CouponInfo; | ||
14 | import com.yohobuy.ufo.model.order.resp.ExpressInfoDetail; | 15 | import com.yohobuy.ufo.model.order.resp.ExpressInfoDetail; |
15 | import com.yohobuy.ufo.model.order.vo.AddressInfo; | 16 | import com.yohobuy.ufo.model.order.vo.AddressInfo; |
16 | import com.yohoufo.common.config.SpecialTimeConfigReader; | 17 | import com.yohoufo.common.config.SpecialTimeConfigReader; |
@@ -244,6 +245,8 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I | @@ -244,6 +245,8 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I | ||
244 | } | 245 | } |
245 | orderDetailInfo.setBankTransferFee(computeBo.getBankTransferFee()); | 246 | orderDetailInfo.setBankTransferFee(computeBo.getBankTransferFee()); |
246 | orderDetailInfo.setPlatformFee(computeBo.getPlatformFee()); | 247 | orderDetailInfo.setPlatformFee(computeBo.getPlatformFee()); |
248 | + CouponInfo couponInfo; | ||
249 | + orderDetailInfo.setCouponCutAmount(Objects.isNull(couponInfo = computeBo.getCouponInfo()) ? null : couponInfo.getCouponAmountStr()); | ||
247 | orderDetailInfo.setIncome(computeBo.getIncome()); | 250 | orderDetailInfo.setIncome(computeBo.getIncome()); |
248 | } | 251 | } |
249 | } | 252 | } |
@@ -26,6 +26,7 @@ import com.yohoufo.order.convert.SellerOrderConvertor; | @@ -26,6 +26,7 @@ import com.yohoufo.order.convert.SellerOrderConvertor; | ||
26 | import com.yohoufo.order.event.*; | 26 | import com.yohoufo.order.event.*; |
27 | import com.yohoufo.order.model.SellerOrderContext; | 27 | import com.yohoufo.order.model.SellerOrderContext; |
28 | import com.yohoufo.order.model.SellerOrderRelatedBuyerOrderContext; | 28 | import com.yohoufo.order.model.SellerOrderRelatedBuyerOrderContext; |
29 | +import com.yohoufo.order.model.bo.CouponBoList; | ||
29 | import com.yohoufo.order.model.dto.*; | 30 | import com.yohoufo.order.model.dto.*; |
30 | import com.yohoufo.order.model.request.OrderListRequest; | 31 | import com.yohoufo.order.model.request.OrderListRequest; |
31 | import com.yohoufo.order.model.request.OrderRequest; | 32 | import com.yohoufo.order.model.request.OrderRequest; |
@@ -53,6 +54,8 @@ import com.yohoufo.order.service.seller.orderMeta.SellerFeeService; | @@ -53,6 +54,8 @@ import com.yohoufo.order.service.seller.orderMeta.SellerFeeService; | ||
53 | import com.yohoufo.order.service.seller.processor.*; | 54 | import com.yohoufo.order.service.seller.processor.*; |
54 | import com.yohoufo.order.service.seller.setting.SellerService; | 55 | import com.yohoufo.order.service.seller.setting.SellerService; |
55 | import com.yohoufo.order.service.seller.setting.SellerWrapper; | 56 | import com.yohoufo.order.service.seller.setting.SellerWrapper; |
57 | +import com.yohoufo.order.service.seller.trade.SellerOrderSubmitService; | ||
58 | +import com.yohoufo.order.service.support.CouponSupport; | ||
56 | import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator; | 59 | import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator; |
57 | import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta; | 60 | import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta; |
58 | import com.yohoufo.order.utils.LoggerUtils; | 61 | import com.yohoufo.order.utils.LoggerUtils; |
@@ -177,6 +180,9 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic | @@ -177,6 +180,9 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic | ||
177 | @Autowired | 180 | @Autowired |
178 | private BuyerOrderAssistant buyerOrderAssistant; | 181 | private BuyerOrderAssistant buyerOrderAssistant; |
179 | 182 | ||
183 | + @Autowired | ||
184 | + private SellerOrderSubmitService sellerOrderSubmitService; | ||
185 | + | ||
180 | private static final int MAX_DEAL = 10; | 186 | private static final int MAX_DEAL = 10; |
181 | 187 | ||
182 | public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) { | 188 | public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) { |
@@ -988,12 +994,35 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic | @@ -988,12 +994,35 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServic | ||
988 | 994 | ||
989 | 995 | ||
990 | 996 | ||
991 | - public boolean submitWithCoupon(SellerOrderRelatedBuyerOrderContext sorboc){ | 997 | + public void submitWithCoupon(SellerOrderRelatedBuyerOrderContext sorboc){ |
992 | SellerOrderChargeParam chargeParam = sorboc.getChargeParam(); | 998 | SellerOrderChargeParam chargeParam = sorboc.getChargeParam(); |
993 | chargeParam.setChargeStage(SellerOrderChargeParam.SUBMIT); | 999 | chargeParam.setChargeStage(SellerOrderChargeParam.SUBMIT); |
994 | sellerOrderComputeService.compute(sorboc); | 1000 | sellerOrderComputeService.compute(sorboc); |
1001 | + //TODO how to keep atomic,rollback when fail | ||
1002 | + | ||
1003 | + | ||
1004 | + //after compute, may be reset | ||
1005 | + SellerOrderComputeResult computeResult = sorboc.getSellerOrderComputeResult(); | ||
1006 | + | ||
1007 | + CouponBoList couponBoList = CouponSupport.buildOrderCouponBoList(computeResult.getCouponPayResultList()); | ||
1008 | + | ||
1009 | + SellerOrderGoods psog = sorboc.getSkupInfo(); | ||
1010 | + | ||
1011 | + SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(psog.getId()); | ||
1012 | + | ||
1013 | + SellerOrderSubmitDTO submitDTO = SellerOrderSubmitDTO.builder() | ||
1014 | + .sellerOrder(sellerOrder) | ||
1015 | + .couponBoList(couponBoList) | ||
1016 | + .computeResult(computeResult) | ||
1017 | + .build(); | ||
1018 | + sellerOrderSubmitService.submitByOld(submitDTO); | ||
1019 | + } | ||
1020 | + | ||
1021 | + | ||
1022 | + | ||
1023 | + public void cancelWithCoupon(){ | ||
1024 | + | ||
995 | 1025 | ||
996 | - return false; | ||
997 | } | 1026 | } |
998 | 1027 | ||
999 | 1028 |
1 | +package com.yohoufo.order.service.seller; | ||
2 | + | ||
3 | +import com.yoho.core.dal.datasource.annotation.Database; | ||
4 | +import com.yohoufo.dal.order.SellerOrderMapper; | ||
5 | +import com.yohoufo.dal.order.model.SellerOrder; | ||
6 | +import com.yohoufo.order.model.dto.SellerOrderComputeResult; | ||
7 | +import com.yohoufo.order.model.dto.SellerOrderSubmitDTO; | ||
8 | +import com.yohoufo.order.service.seller.orderMeta.SellerOrderMetaService; | ||
9 | +import com.yohoufo.order.utils.LoggerUtils; | ||
10 | +import org.slf4j.Logger; | ||
11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
12 | +import org.springframework.stereotype.Service; | ||
13 | +import org.springframework.transaction.annotation.Propagation; | ||
14 | +import org.springframework.transaction.annotation.Transactional; | ||
15 | + | ||
16 | +@Service | ||
17 | +public class SellerOrderUpdateService { | ||
18 | + | ||
19 | + private Logger logger = LoggerUtils.getSellerOrderLogger(); | ||
20 | + @Autowired | ||
21 | + private SellerOrderMapper sellerOrderMapper; | ||
22 | + | ||
23 | + @Autowired | ||
24 | + private SellerOrderMetaService sellerOrderMetaService; | ||
25 | + | ||
26 | + @Transactional(propagation = Propagation.REQUIRED) | ||
27 | + @Database(ForceMaster=true, DataSource="ufo_order") | ||
28 | + public boolean updateAmount(SellerOrderSubmitDTO submitDTO){ | ||
29 | + SellerOrder sellerOrder = submitDTO.getSellerOrder(); | ||
30 | + | ||
31 | + if (submitDTO.getCouponBoList().isNotEmpty()){ | ||
32 | + sellerOrderMetaService.saveUsedCoupons(sellerOrder.getSkup(), sellerOrder.getUid(), submitDTO.getCouponBoList().getCouponBos()); | ||
33 | + } | ||
34 | + | ||
35 | + SellerOrderComputeResult computeResult = submitDTO.getComputeResult(); | ||
36 | + if (computeResult.isAmountIsReset()){ | ||
37 | + SellerOrder condition = new SellerOrder(); | ||
38 | + condition.setOrderCode(sellerOrder.getOrderCode()); | ||
39 | + condition.setUid(sellerOrder.getUid()); | ||
40 | + condition.setCouponCutAmount(computeResult.getCouponCutAmount()); | ||
41 | + condition.setIncome(computeResult.getIncome()); | ||
42 | + int updateOrderRusult = sellerOrderMapper.updateAmountByOrderCode(condition); | ||
43 | + logger.info("SellerOrderUpdateService.updateAmount sellerOrderMapper.updateAmountByOrderCode condition {} result {}", condition, updateOrderRusult); | ||
44 | + } | ||
45 | + | ||
46 | + return true; | ||
47 | + } | ||
48 | +} |
@@ -97,7 +97,7 @@ public class SellerFeeService { | @@ -97,7 +97,7 @@ public class SellerFeeService { | ||
97 | SellerOrderComputeResult computeResult = JSONObject.parseObject(meta.getMetaValue(), SellerOrderComputeResult.class); | 97 | SellerOrderComputeResult computeResult = JSONObject.parseObject(meta.getMetaValue(), SellerOrderComputeResult.class); |
98 | return computeResult; | 98 | return computeResult; |
99 | }catch (Exception ex){ | 99 | }catch (Exception ex){ |
100 | - logger.warn("in getSellerOrderComputeResult fail uid {}, skup {}", uid, skup); | 100 | + logger.warn("in getSellerOrderComputeResult fail uid {}, skup {}", uid, skup, ex); |
101 | return null; | 101 | return null; |
102 | } | 102 | } |
103 | } | 103 | } |
@@ -2,10 +2,10 @@ package com.yohoufo.order.service.seller.orderMeta; | @@ -2,10 +2,10 @@ package com.yohoufo.order.service.seller.orderMeta; | ||
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
4 | import com.yoho.core.dal.datasource.annotation.Database; | 4 | import com.yoho.core.dal.datasource.annotation.Database; |
5 | -import com.yohobuy.ufo.model.order.bo.SellerCouponSimpleBo; | ||
6 | import com.yohoufo.dal.order.SellerOrderMetaMapper; | 5 | import com.yohoufo.dal.order.SellerOrderMetaMapper; |
7 | import com.yohoufo.dal.order.model.SellerOrderMeta; | 6 | import com.yohoufo.dal.order.model.SellerOrderMeta; |
8 | import com.yohoufo.order.constants.MetaKey; | 7 | import com.yohoufo.order.constants.MetaKey; |
8 | +import com.yohoufo.order.model.bo.CouponBo; | ||
9 | import com.yohoufo.order.utils.LoggerUtils; | 9 | import com.yohoufo.order.utils.LoggerUtils; |
10 | import org.slf4j.Logger; | 10 | import org.slf4j.Logger; |
11 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -45,7 +45,7 @@ public class SellerOrderMetaService { | @@ -45,7 +45,7 @@ public class SellerOrderMetaService { | ||
45 | 45 | ||
46 | @Transactional(propagation = Propagation.REQUIRED) | 46 | @Transactional(propagation = Propagation.REQUIRED) |
47 | @Database(ForceMaster=true, DataSource="ufo_order") | 47 | @Database(ForceMaster=true, DataSource="ufo_order") |
48 | - public int saveUsedCoupons(int skup,int uid, List<SellerCouponSimpleBo> usedCoupons){ | 48 | + public int saveUsedCoupons(int skup,int uid, List<CouponBo> usedCoupons){ |
49 | String key = MetaKey.SELLER_USED_COUPON; | 49 | String key = MetaKey.SELLER_USED_COUPON; |
50 | SellerOrderMeta som = new SellerOrderMeta(); | 50 | SellerOrderMeta som = new SellerOrderMeta(); |
51 | som.setUid(uid); | 51 | som.setUid(uid); |
1 | package com.yohoufo.order.service.seller.trade; | 1 | package com.yohoufo.order.service.seller.trade; |
2 | 2 | ||
3 | import com.yohobuy.ufo.model.order.constants.SkupType; | 3 | import com.yohobuy.ufo.model.order.constants.SkupType; |
4 | -import com.yohoufo.order.service.seller.trade.OrderComputeHandler; | ||
5 | import com.yohoufo.order.utils.LoggerUtils; | 4 | import com.yohoufo.order.utils.LoggerUtils; |
6 | import org.apache.commons.collections.CollectionUtils; | 5 | import org.apache.commons.collections.CollectionUtils; |
7 | import org.slf4j.Logger; | 6 | import org.slf4j.Logger; |
@@ -185,35 +185,37 @@ public class SellerOrderComputeService { | @@ -185,35 +185,37 @@ public class SellerOrderComputeService { | ||
185 | * @return | 185 | * @return |
186 | */ | 186 | */ |
187 | private Optional<CouponPayResult> activityCouponUse(UserCouponsBo activityCouponsBo, SellerOrderRelatedBuyerOrderContext chargeContext) { | 187 | private Optional<CouponPayResult> activityCouponUse(UserCouponsBo activityCouponsBo, SellerOrderRelatedBuyerOrderContext chargeContext) { |
188 | - SellerOrderComputeResult chargeResult = chargeContext.getSellerOrderComputeResult(); | 188 | + SellerOrderComputeResult computeResult = chargeContext.getSellerOrderComputeResult(); |
189 | 189 | ||
190 | - PlatformFeeDto platformFeeDto = chargeResult.getPlatformFee(); | 190 | + PlatformFeeDto platformFeeDto = computeResult.getPlatformFee(); |
191 | 191 | ||
192 | BigDecimal oldServiceFee = platformFeeDto.getServiceFee(); | 192 | BigDecimal oldServiceFee = platformFeeDto.getServiceFee(); |
193 | //1. calculate coupon cut amount | 193 | //1. calculate coupon cut amount |
194 | BigDecimal couponPayAmount = BigDecimalHelper.min(oldServiceFee, activityCouponsBo.getCouponAmount()); | 194 | BigDecimal couponPayAmount = BigDecimalHelper.min(oldServiceFee, activityCouponsBo.getCouponAmount()); |
195 | - BigDecimal oldIncome = chargeResult.getIncome(); | 195 | + BigDecimal oldIncome = computeResult.getIncome(); |
196 | //2. calculate income and set | 196 | //2. calculate income and set |
197 | //2.1 | 197 | //2.1 |
198 | BigDecimal newIncome = BigDecimalHelper.add(oldIncome, couponPayAmount); | 198 | BigDecimal newIncome = BigDecimalHelper.add(oldIncome, couponPayAmount); |
199 | //2.2 set income | 199 | //2.2 set income |
200 | - chargeResult.setIncome(newIncome); | 200 | + computeResult.setIncome(newIncome); |
201 | //3. calculate serviceFee and set | 201 | //3. calculate serviceFee and set |
202 | BigDecimal newServiceFee = BigDecimalHelper.sub(oldServiceFee, couponPayAmount); | 202 | BigDecimal newServiceFee = BigDecimalHelper.sub(oldServiceFee, couponPayAmount); |
203 | - platformFeeDto.setServiceFee(newServiceFee); | 203 | + //platformFeeDto.setServiceFee(newServiceFee); |
204 | 204 | ||
205 | - BigDecimal oldFinalAmountOfCutCoupons = chargeResult.getCouponCutAmount(); | 205 | + BigDecimal oldFinalAmountOfCutCoupons = computeResult.getCouponCutAmount(); |
206 | BigDecimal newFinalAmountOfCutCoupons; | 206 | BigDecimal newFinalAmountOfCutCoupons; |
207 | if (Objects.isNull(oldFinalAmountOfCutCoupons)){ | 207 | if (Objects.isNull(oldFinalAmountOfCutCoupons)){ |
208 | newFinalAmountOfCutCoupons = couponPayAmount; | 208 | newFinalAmountOfCutCoupons = couponPayAmount; |
209 | }else { | 209 | }else { |
210 | newFinalAmountOfCutCoupons = BigDecimalHelper.add(oldFinalAmountOfCutCoupons, couponPayAmount); | 210 | newFinalAmountOfCutCoupons = BigDecimalHelper.add(oldFinalAmountOfCutCoupons, couponPayAmount); |
211 | } | 211 | } |
212 | - chargeResult.setCouponCutAmount(newFinalAmountOfCutCoupons); | 212 | + computeResult.setCouponCutAmount(newFinalAmountOfCutCoupons); |
213 | CouponPayResult couponPayResult = CouponPayResult.builder().couponCode(activityCouponsBo.getCouponCode()) | 213 | CouponPayResult couponPayResult = CouponPayResult.builder().couponCode(activityCouponsBo.getCouponCode()) |
214 | .couponAmount(couponPayAmount.doubleValue()).couponType(activityCouponsBo.getCouponType()).build(); | 214 | .couponAmount(couponPayAmount.doubleValue()).couponType(activityCouponsBo.getCouponType()).build(); |
215 | logger.info("seller order [{}] step activity coupon charge,oldIncome:{},newIncome of cut coupons:{}", | 215 | logger.info("seller order [{}] step activity coupon charge,oldIncome:{},newIncome of cut coupons:{}", |
216 | - chargeContext.getUid(), oldIncome, newIncome); | 216 | + chargeContext.getUid(), oldIncome, newIncome, newFinalAmountOfCutCoupons); |
217 | + // | ||
218 | + computeResult.setAmountIsReset(true); | ||
217 | return Optional.of(couponPayResult); | 219 | return Optional.of(couponPayResult); |
218 | } | 220 | } |
219 | 221 |
1 | +package com.yohoufo.order.service.seller.trade; | ||
2 | + | ||
3 | +import com.yoho.core.transaction.YHTxCoordinator; | ||
4 | +import com.yoho.core.transaction.annoation.YHTransaction; | ||
5 | +import com.yohoufo.dal.order.model.SellerOrder; | ||
6 | +import com.yohoufo.order.model.dto.SellerOrderSubmitDTO; | ||
7 | +import com.yohoufo.order.service.proxy.CouponProxyService; | ||
8 | +import com.yohoufo.order.service.seller.SellerOrderUpdateService; | ||
9 | +import com.yohoufo.order.utils.LoggerUtils; | ||
10 | +import org.slf4j.Logger; | ||
11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
12 | +import org.springframework.stereotype.Service; | ||
13 | + | ||
14 | +@Service | ||
15 | +public class SellerOrderSubmitService { | ||
16 | + | ||
17 | + private final Logger logger = LoggerUtils.getSellerOrderLogger(); | ||
18 | + | ||
19 | + @Autowired | ||
20 | + private YHTxCoordinator tx; | ||
21 | + | ||
22 | + @Autowired | ||
23 | + private CouponProxyService couponProxyService; | ||
24 | + | ||
25 | + @Autowired | ||
26 | + private SellerOrderUpdateService sellerOrderUpdateService; | ||
27 | + | ||
28 | + /** | ||
29 | + * 提交已有的订单 | ||
30 | + * 目前场景 发货用券时重新结算 | ||
31 | + * @param submitDTO | ||
32 | + */ | ||
33 | + @YHTransaction | ||
34 | + public void submitByOld(SellerOrderSubmitDTO submitDTO){ | ||
35 | + SellerOrder sellerOrder = submitDTO.getSellerOrder(); | ||
36 | + logger.info("in SellerOrderSubmitService.submitByOld, {}", sellerOrder); | ||
37 | + //修改卖家订单 | ||
38 | + sellerOrderUpdateService.updateAmount(submitDTO); | ||
39 | + // | ||
40 | + try { | ||
41 | + //使用优惠券 | ||
42 | + if (submitDTO.getCouponBoList().isNotEmpty()) { | ||
43 | + couponProxyService.orderUseCoupon(sellerOrder.getUid(), sellerOrder.getOrderCode(), submitDTO.getCouponBoList().getCouponCodes()); | ||
44 | + } | ||
45 | + | ||
46 | + }catch (Exception ex){ | ||
47 | + tx.rollback(); | ||
48 | + throw ex; | ||
49 | + } | ||
50 | + } | ||
51 | +} |
@@ -10,11 +10,14 @@ import com.yohoufo.order.constants.CouponConstants; | @@ -10,11 +10,14 @@ import com.yohoufo.order.constants.CouponConstants; | ||
10 | import com.yohobuy.ufo.model.order.resp.CouponInfo; | 10 | import com.yohobuy.ufo.model.order.resp.CouponInfo; |
11 | import com.yohobuy.ufo.model.order.resp.RecommendedCouponInfo; | 11 | import com.yohobuy.ufo.model.order.resp.RecommendedCouponInfo; |
12 | import com.yohobuy.ufo.model.order.resp.ShoppingCoupon; | 12 | import com.yohobuy.ufo.model.order.resp.ShoppingCoupon; |
13 | +import com.yohoufo.order.model.bo.CouponBo; | ||
14 | +import com.yohoufo.order.model.bo.CouponBoList; | ||
13 | import com.yohoufo.order.utils.CouponCodeUtils; | 15 | import com.yohoufo.order.utils.CouponCodeUtils; |
14 | import com.yohoufo.order.utils.MathUtils; | 16 | import com.yohoufo.order.utils.MathUtils; |
15 | import org.apache.commons.collections.CollectionUtils; | 17 | import org.apache.commons.collections.CollectionUtils; |
16 | import org.springframework.stereotype.Component; | 18 | import org.springframework.stereotype.Component; |
17 | 19 | ||
20 | +import java.math.BigDecimal; | ||
18 | import java.text.MessageFormat; | 21 | import java.text.MessageFormat; |
19 | import java.util.ArrayList; | 22 | import java.util.ArrayList; |
20 | import java.util.List; | 23 | import java.util.List; |
@@ -231,4 +234,23 @@ public class CouponSupport { | @@ -231,4 +234,23 @@ public class CouponSupport { | ||
231 | 234 | ||
232 | return result; | 235 | return result; |
233 | } | 236 | } |
237 | + | ||
238 | + | ||
239 | + /** | ||
240 | + * 优惠券支付结果 | ||
241 | + * | ||
242 | + * @param couponPayResultList | ||
243 | + * @return | ||
244 | + */ | ||
245 | + public static CouponBoList buildOrderCouponBoList(CouponPayResultList couponPayResultList) { | ||
246 | + return CouponBoList.builder().couponBos(couponPayResultList.getCouponPayResults().stream() | ||
247 | + .map(couponPayResult -> CouponBo.builder() | ||
248 | + .couponCode(couponPayResult.getCouponCode()) | ||
249 | + .couponType(couponPayResult.getCouponType()) | ||
250 | + .couponAmount(BigDecimal.valueOf(couponPayResult.getCouponAmount())) | ||
251 | + .build() | ||
252 | + ) | ||
253 | + .collect(Collectors.toList()) | ||
254 | + ).build(); | ||
255 | + } | ||
234 | } | 256 | } |
-
Please register or login to post a comment