fix compute earnest money
add inbox msg facade use optimized lock 2 update seller order status
Showing
26 changed files
with
340 additions
and
103 deletions
@@ -27,4 +27,7 @@ public interface SellerOrderGoodsMapper { | @@ -27,4 +27,7 @@ public interface SellerOrderGoodsMapper { | ||
27 | @Param("statusList") List<Integer> statusList, | 27 | @Param("statusList") List<Integer> statusList, |
28 | @Param("offset")Integer offset, | 28 | @Param("offset")Integer offset, |
29 | @Param("limit")Integer limit); | 29 | @Param("limit")Integer limit); |
30 | + | ||
31 | + | ||
32 | + int updateStatusBySkpu(SellerOrderGoods record); | ||
30 | } | 33 | } |
@@ -23,6 +23,10 @@ public class SellerOrder { | @@ -23,6 +23,10 @@ public class SellerOrder { | ||
23 | private Integer isDel; | 23 | private Integer isDel; |
24 | 24 | ||
25 | private Integer status; | 25 | private Integer status; |
26 | + /** | ||
27 | + * 期望的原值,用来做乐观锁 | ||
28 | + */ | ||
29 | + private Integer exceptStatus; | ||
26 | 30 | ||
27 | private Integer createTime; | 31 | private Integer createTime; |
28 | 32 | ||
@@ -124,4 +128,13 @@ public class SellerOrder { | @@ -124,4 +128,13 @@ public class SellerOrder { | ||
124 | public void setIsDel(Integer isDel) { | 128 | public void setIsDel(Integer isDel) { |
125 | this.isDel = isDel; | 129 | this.isDel = isDel; |
126 | } | 130 | } |
131 | + | ||
132 | + | ||
133 | + public Integer getExceptStatus() { | ||
134 | + return exceptStatus; | ||
135 | + } | ||
136 | + | ||
137 | + public void setExceptStatus(Integer exceptStatus) { | ||
138 | + this.exceptStatus = exceptStatus; | ||
139 | + } | ||
127 | } | 140 | } |
@@ -27,6 +27,7 @@ public class SellerOrderGoods { | @@ -27,6 +27,7 @@ public class SellerOrderGoods { | ||
27 | 27 | ||
28 | private Integer status; | 28 | private Integer status; |
29 | 29 | ||
30 | + private Integer exceptStatus; | ||
30 | 31 | ||
31 | private String imageUrl; | 32 | private String imageUrl; |
32 | 33 | ||
@@ -136,4 +137,12 @@ public class SellerOrderGoods { | @@ -136,4 +137,12 @@ public class SellerOrderGoods { | ||
136 | public void setUid(Integer uid) { | 137 | public void setUid(Integer uid) { |
137 | this.uid = uid; | 138 | this.uid = uid; |
138 | } | 139 | } |
140 | + | ||
141 | + public Integer getExceptStatus() { | ||
142 | + return exceptStatus; | ||
143 | + } | ||
144 | + | ||
145 | + public void setExceptStatus(Integer exceptStatus) { | ||
146 | + this.exceptStatus = exceptStatus; | ||
147 | + } | ||
139 | } | 148 | } |
@@ -169,6 +169,21 @@ | @@ -169,6 +169,21 @@ | ||
169 | </if> | 169 | </if> |
170 | </trim> | 170 | </trim> |
171 | </insert> | 171 | </insert> |
172 | + | ||
173 | + | ||
174 | + | ||
175 | + <update id="updateStatusBySkpu" parameterType="com.yohoufo.dal.order.model.SellerOrderGoods"> | ||
176 | + update seller_order_goods | ||
177 | + <set> | ||
178 | + <if test="status != null"> | ||
179 | + status = #{status,jdbcType=TINYINT}, | ||
180 | + </if> | ||
181 | + </set> | ||
182 | + where id = #{id,jdbcType=INTEGER} | ||
183 | + and status = #{exceptStatus,jdbcType=TINYINT} | ||
184 | + </update> | ||
185 | + | ||
186 | + | ||
172 | <update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.SellerOrderGoods"> | 187 | <update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.SellerOrderGoods"> |
173 | update seller_order_goods | 188 | update seller_order_goods |
174 | <set> | 189 | <set> |
@@ -214,6 +214,8 @@ | @@ -214,6 +214,8 @@ | ||
214 | update_time = #{updateTime,jdbcType=INTEGER} | 214 | update_time = #{updateTime,jdbcType=INTEGER} |
215 | where uid = #{uid,jdbcType=INTEGER} | 215 | where uid = #{uid,jdbcType=INTEGER} |
216 | and order_code = #{orderCode,jdbcType=BIGINT} | 216 | and order_code = #{orderCode,jdbcType=BIGINT} |
217 | + and status = #{exceptStatus,jdbcType=INTEGER} | ||
218 | + | ||
217 | </update> | 219 | </update> |
218 | 220 | ||
219 | 221 |
@@ -54,5 +54,15 @@ | @@ -54,5 +54,15 @@ | ||
54 | <artifactId>javax.servlet-api</artifactId> | 54 | <artifactId>javax.servlet-api</artifactId> |
55 | <scope>compile</scope> | 55 | <scope>compile</scope> |
56 | </dependency> | 56 | </dependency> |
57 | + | ||
58 | + <dependency> | ||
59 | + <groupId>com.yohoufo.fore</groupId> | ||
60 | + <artifactId>yohoufo-fore-inboxclient</artifactId> | ||
61 | + </dependency> | ||
62 | + | ||
63 | + <dependency> | ||
64 | + <groupId>com.yoho.ufo.model</groupId> | ||
65 | + <artifactId>user-ufo-model</artifactId> | ||
66 | + </dependency> | ||
57 | </dependencies> | 67 | </dependencies> |
58 | </project> | 68 | </project> |
@@ -11,7 +11,7 @@ import java.util.List; | @@ -11,7 +11,7 @@ import java.util.List; | ||
11 | public class ActionStatusHold { | 11 | public class ActionStatusHold { |
12 | 12 | ||
13 | 13 | ||
14 | - public static List<Integer> getSellerCanCancelStatus(){ | 14 | + public static List<Integer> getSellerCanRefundStatus(){ |
15 | List<Integer> sellerCanCancelStatus; | 15 | List<Integer> sellerCanCancelStatus; |
16 | sellerCanCancelStatus = Arrays.asList(SellerOrderStatus.WAITING_PAY.getCode(), | 16 | sellerCanCancelStatus = Arrays.asList(SellerOrderStatus.WAITING_PAY.getCode(), |
17 | SellerOrderStatus.HAS_PAYED.getCode()); | 17 | SellerOrderStatus.HAS_PAYED.getCode()); |
@@ -19,15 +19,15 @@ public class ActionStatusHold { | @@ -19,15 +19,15 @@ public class ActionStatusHold { | ||
19 | return sellerCanCancelStatus; | 19 | return sellerCanCancelStatus; |
20 | } | 20 | } |
21 | 21 | ||
22 | - | ||
23 | - public static List<Integer> getSellerCanRefundEarnestMoneyStatus(){ | ||
24 | - List<Integer> sellerCanCancelStatus; | ||
25 | - sellerCanCancelStatus = Arrays.asList(SellerOrderStatus.SELf_CANCEL_PAY.getCode(), | ||
26 | - SellerOrderStatus.TIMEOUT_CANCEL.getCode(), | 22 | + static List<Integer> sellerCanRefundStatus; |
23 | + static { | ||
24 | + sellerCanRefundStatus = Arrays.asList( | ||
27 | SellerOrderStatus.YOHO_CANCEL_SELL.getCode(), | 25 | SellerOrderStatus.YOHO_CANCEL_SELL.getCode(), |
28 | SellerOrderStatus.FINISH.getCode()); | 26 | SellerOrderStatus.FINISH.getCode()); |
27 | + } | ||
29 | 28 | ||
30 | - return sellerCanCancelStatus; | 29 | + public static List<Integer> getSellerCanRefundEarnestMoneyStatus(){ |
30 | + return sellerCanRefundStatus; | ||
31 | } | 31 | } |
32 | 32 | ||
33 | 33 |
@@ -4,6 +4,7 @@ import com.yohobuy.ufo.model.order.bo.PlatformFee; | @@ -4,6 +4,7 @@ import com.yohobuy.ufo.model.order.bo.PlatformFee; | ||
4 | import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo; | 4 | import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo; |
5 | import com.yohoufo.common.utils.BigDecimalHelper; | 5 | import com.yohoufo.common.utils.BigDecimalHelper; |
6 | import com.yohoufo.common.utils.PriceFormater; | 6 | import com.yohoufo.common.utils.PriceFormater; |
7 | +import com.yohoufo.order.model.dto.EarnestMoney; | ||
7 | import com.yohoufo.order.model.dto.PlatformFeeDto; | 8 | import com.yohoufo.order.model.dto.PlatformFeeDto; |
8 | import com.yohoufo.order.model.dto.SellerOrderComputeResult; | 9 | import com.yohoufo.order.model.dto.SellerOrderComputeResult; |
9 | 10 | ||
@@ -16,9 +17,8 @@ public final class SellerOrderConvertor { | @@ -16,9 +17,8 @@ public final class SellerOrderConvertor { | ||
16 | 17 | ||
17 | public static SoldPrdComputeBo computeResult2SoldPrdComputeBo(SellerOrderComputeResult computeResult){ | 18 | public static SoldPrdComputeBo computeResult2SoldPrdComputeBo(SellerOrderComputeResult computeResult){ |
18 | //保证金(28-200(按照卖家发布商品的货款金额5%计算,最低28,封顶200)) | 19 | //保证金(28-200(按照卖家发布商品的货款金额5%计算,最低28,封顶200)) |
19 | - BigDecimal earnestMoney = computeResult.getEarnestMoney(); | ||
20 | - //银行转账费(0.65%+¥1.00) | ||
21 | - BigDecimal bankTransferfee = computeResult.getBankTransferfee(); | 20 | + EarnestMoney earnestMoneyDTO = computeResult.getEarnestMoney(); |
21 | + BigDecimal earnestMoney = earnestMoneyDTO.getEarnestMoney(); | ||
22 | PlatformFeeDto platformFeeDto = computeResult.getPlatformFee(); | 22 | PlatformFeeDto platformFeeDto = computeResult.getPlatformFee(); |
23 | BigDecimal income = computeResult.getIncome(); | 23 | BigDecimal income = computeResult.getIncome(); |
24 | 24 | ||
@@ -27,15 +27,13 @@ public final class SellerOrderConvertor { | @@ -27,15 +27,13 @@ public final class SellerOrderConvertor { | ||
27 | .amount(buildSubtractFee(formatFee(platformFeeDto.getTotal()))) | 27 | .amount(buildSubtractFee(formatFee(platformFeeDto.getTotal()))) |
28 | .appraiseFee(formatFee(platformFeeDto.getAppraiseFee())) | 28 | .appraiseFee(formatFee(platformFeeDto.getAppraiseFee())) |
29 | .packageFee(formatFee(platformFeeDto.getPackageFee())) | 29 | .packageFee(formatFee(platformFeeDto.getPackageFee())) |
30 | - .serviceFee(formatFee(platformFeeDto.getServiceFee())).build(); | 30 | + .build(); |
31 | // | 31 | // |
32 | String incomeStr = formatFee(income); | 32 | String incomeStr = formatFee(income); |
33 | String earnestMoneyStr = formatFee(earnestMoney); | 33 | String earnestMoneyStr = formatFee(earnestMoney); |
34 | - String bankTransferFeeStr = buildSubtractFee(formatFee(bankTransferfee)); | ||
35 | SoldPrdComputeBo computeBo = SoldPrdComputeBo.builder() | 34 | SoldPrdComputeBo computeBo = SoldPrdComputeBo.builder() |
36 | .earnestMoney(earnestMoney.doubleValue()) | 35 | .earnestMoney(earnestMoney.doubleValue()) |
37 | .earnestMoneyStr(earnestMoneyStr) | 36 | .earnestMoneyStr(earnestMoneyStr) |
38 | - .bankTransferFee(bankTransferFeeStr) | ||
39 | .platformFee(platformFeeWrapper) | 37 | .platformFee(platformFeeWrapper) |
40 | .income(incomeStr) | 38 | .income(incomeStr) |
41 | .build(); | 39 | .build(); |
@@ -27,6 +27,14 @@ public class OrderInfo { | @@ -27,6 +27,14 @@ public class OrderInfo { | ||
27 | private Integer payment; | 27 | private Integer payment; |
28 | 28 | ||
29 | private Integer status; | 29 | private Integer status; |
30 | + /** | ||
31 | + * 原来(数据库持久化)的状态 | ||
32 | + */ | ||
33 | + private Integer sourceStatus; | ||
34 | + /** | ||
35 | + * 目标状态 | ||
36 | + */ | ||
37 | + private Integer targetStatus; | ||
30 | 38 | ||
31 | private OrderCodeType orderCodeType; | 39 | private OrderCodeType orderCodeType; |
32 | 40 |
1 | +package com.yohoufo.order.model.dto; | ||
2 | + | ||
3 | +import com.yohoufo.common.utils.BigDecimalHelper; | ||
4 | +import lombok.Data; | ||
5 | + | ||
6 | +import java.math.BigDecimal; | ||
7 | + | ||
8 | +/** | ||
9 | + * 保证金(28-200(按照卖家发布商品的货款金额5%计算,最低28,封顶200)) | ||
10 | + * Created by chenchao on 2018/10/8. | ||
11 | + */ | ||
12 | +@Data | ||
13 | +public class EarnestMoney { | ||
14 | + | ||
15 | + private BigDecimal prdSalePrice; | ||
16 | + | ||
17 | + private BigDecimal min = new BigDecimal(28); | ||
18 | + | ||
19 | + private BigDecimal max = new BigDecimal(200); | ||
20 | + | ||
21 | + private BigDecimal rate = new BigDecimal(0.05D).setScale(2, BigDecimal.ROUND_HALF_UP); | ||
22 | + | ||
23 | + private BigDecimal earnestMoney; | ||
24 | +} |
@@ -11,7 +11,14 @@ import java.math.BigDecimal; | @@ -11,7 +11,14 @@ import java.math.BigDecimal; | ||
11 | public class PlatformFeeDto { | 11 | public class PlatformFeeDto { |
12 | 12 | ||
13 | BigDecimal total; | 13 | BigDecimal total; |
14 | - BigDecimal appraiseFee; | ||
15 | - BigDecimal packageFee; | ||
16 | - BigDecimal serviceFee; | 14 | + /** |
15 | + * 有货鉴定费(暂定5元) | ||
16 | + */ | ||
17 | + BigDecimal appraiseFee = new BigDecimal(5); | ||
18 | + /** | ||
19 | + * 有货包装费(暂定5元) | ||
20 | + */ | ||
21 | + BigDecimal packageFee = new BigDecimal(5); | ||
22 | + | ||
23 | + | ||
17 | } | 24 | } |
@@ -10,7 +10,7 @@ import java.math.BigDecimal; | @@ -10,7 +10,7 @@ import java.math.BigDecimal; | ||
10 | @Data | 10 | @Data |
11 | public class SellerOrderComputeResult { | 11 | public class SellerOrderComputeResult { |
12 | 12 | ||
13 | - BigDecimal earnestMoney; | 13 | + EarnestMoney earnestMoney; |
14 | // | 14 | // |
15 | PlatformFeeDto platformFee; | 15 | PlatformFeeDto platformFee; |
16 | BigDecimal bankTransferfee; | 16 | BigDecimal bankTransferfee; |
1 | package com.yohoufo.order.model.dto; | 1 | package com.yohoufo.order.model.dto; |
2 | 2 | ||
3 | +import com.yohoufo.common.utils.BigDecimalHelper; | ||
4 | +import lombok.Data; | ||
5 | + | ||
3 | import java.math.BigDecimal; | 6 | import java.math.BigDecimal; |
4 | 7 | ||
5 | /** | 8 | /** |
6 | * Created by chenchao on 2018/9/28. | 9 | * Created by chenchao on 2018/9/28. |
7 | */ | 10 | */ |
11 | +@Data | ||
8 | public class ServiceFeeRate { | 12 | public class ServiceFeeRate { |
9 | 13 | ||
10 | - BigDecimal goodsPaymentRate = new BigDecimal(0.05D); | ||
11 | - | ||
12 | - BigDecimal earnestMoneyRate = new BigDecimal(0.20D); | ||
13 | - | ||
14 | - BigDecimal payChannelRate = new BigDecimal(0.0006D); | 14 | + /** |
15 | + * 货款抽成 | ||
16 | + * ( | ||
17 | + * 暂定5%,后期可调整,上线初期为0, | ||
18 | + * 后期活动可根据活动进行减免,每个卖家可收费不一样 | ||
19 | + * ) | ||
20 | + */ | ||
21 | + BigDecimal goodsPaymentRate = new BigDecimal(0.05D).setScale(2, BigDecimal.ROUND_HALF_UP); | ||
22 | + | ||
23 | + /** | ||
24 | + * 保证金抽成(暂定20%,后期可调整) | ||
25 | + */ | ||
26 | + BigDecimal earnestMoneyRate = new BigDecimal(0.20D).setScale(2, BigDecimal.ROUND_HALF_UP); | ||
27 | + /** | ||
28 | + * 支付渠道费,调用银联支付接口时实时扣款 | ||
29 | + * (支付宝0.55%、微信均为0.6%,统一对用户收取0.6%,前期优惠策略可暂定0) | ||
30 | + */ | ||
31 | + BigDecimal payChannelRate = new BigDecimal(0.0006D).setScale(4, BigDecimal.ROUND_HALF_UP); | ||
15 | 32 | ||
16 | 33 | ||
17 | public static ServiceFeeRate getServiceFeeRate(){ | 34 | public static ServiceFeeRate getServiceFeeRate(){ |
@@ -76,6 +76,8 @@ public abstract class AbstractOrderPaymentService { | @@ -76,6 +76,8 @@ public abstract class AbstractOrderPaymentService { | ||
76 | public abstract boolean isOrderPaid(OrderInfo orderInfo); | 76 | public abstract boolean isOrderPaid(OrderInfo orderInfo); |
77 | 77 | ||
78 | 78 | ||
79 | + public abstract boolean canRefund(OrderInfo orderInfo); | ||
80 | + | ||
79 | /** | 81 | /** |
80 | * 更新订单状态 | 82 | * 更新订单状态 |
81 | * @param orderInfo | 83 | * @param orderInfo |
@@ -88,6 +88,13 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService { | @@ -88,6 +88,13 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService { | ||
88 | return false; | 88 | return false; |
89 | } | 89 | } |
90 | 90 | ||
91 | + @Override | ||
92 | + public boolean canRefund(OrderInfo orderInfo) { | ||
93 | + if (orderInfo.getStatus() != null && orderInfo.getStatus().intValue() == OrderStatus.HAS_PAYED.getCode()){ | ||
94 | + return true; | ||
95 | + } | ||
96 | + return false; | ||
97 | + } | ||
91 | 98 | ||
92 | 99 | ||
93 | /** | 100 | /** |
@@ -188,6 +195,7 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService { | @@ -188,6 +195,7 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService { | ||
188 | .amount(buyerOrder.getAmount()) | 195 | .amount(buyerOrder.getAmount()) |
189 | .createTime(buyerOrder.getCreateTime()) | 196 | .createTime(buyerOrder.getCreateTime()) |
190 | .orderCodeType(OrderCodeType.BUYER_TYPE) | 197 | .orderCodeType(OrderCodeType.BUYER_TYPE) |
198 | + .sourceStatus(buyerOrder.getStatus()) | ||
191 | .build(); | 199 | .build(); |
192 | 200 | ||
193 | 201 | ||
@@ -197,7 +205,7 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService { | @@ -197,7 +205,7 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService { | ||
197 | 205 | ||
198 | /** | 206 | /** |
199 | * 获取订单情报 | 207 | * 获取订单情报 |
200 | - * @param request | 208 | + * @param orderCode |
201 | * @return | 209 | * @return |
202 | */ | 210 | */ |
203 | public OrderInfo getOrderInfo(long orderCode) { | 211 | public OrderInfo getOrderInfo(long orderCode) { |
@@ -25,6 +25,8 @@ import org.slf4j.LoggerFactory; | @@ -25,6 +25,8 @@ import org.slf4j.LoggerFactory; | ||
25 | import org.springframework.beans.factory.annotation.Autowired; | 25 | import org.springframework.beans.factory.annotation.Autowired; |
26 | import org.springframework.stereotype.Service; | 26 | import org.springframework.stereotype.Service; |
27 | 27 | ||
28 | +import java.util.Objects; | ||
29 | + | ||
28 | 30 | ||
29 | @Service | 31 | @Service |
30 | public class SellerOrderPaymentService extends AbstractOrderPaymentService { | 32 | public class SellerOrderPaymentService extends AbstractOrderPaymentService { |
@@ -49,25 +51,29 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService { | @@ -49,25 +51,29 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService { | ||
49 | * @param orderInfo | 51 | * @param orderInfo |
50 | */ | 52 | */ |
51 | public void updateOrderStatusPaid(OrderInfo orderInfo){ | 53 | public void updateOrderStatusPaid(OrderInfo orderInfo){ |
52 | - //TODO | 54 | + // |
53 | logger.info("in update seller OrderStatus after Paid, orderInfo {}",orderInfo); | 55 | logger.info("in update seller OrderStatus after Paid, orderInfo {}",orderInfo); |
54 | SellerOrder sellerOrder = new SellerOrder(); | 56 | SellerOrder sellerOrder = new SellerOrder(); |
55 | sellerOrder.setOrderCode(orderInfo.getOrderCode()); | 57 | sellerOrder.setOrderCode(orderInfo.getOrderCode()); |
56 | sellerOrder.setUid(orderInfo.getUid()); | 58 | sellerOrder.setUid(orderInfo.getUid()); |
57 | - SellerOrderStatus sellerOrderStatus = SellerOrderStatus.HAS_PAYED; | ||
58 | - sellerOrder.setStatus(sellerOrderStatus.getCode()); | 59 | + SellerOrderStatus soTargetStatus = SellerOrderStatus.HAS_PAYED; |
60 | + sellerOrder.setStatus(soTargetStatus.getCode()); | ||
59 | 61 | ||
60 | - orderInfo.setStatus(sellerOrderStatus.getCode()); | 62 | + orderInfo.setStatus(soTargetStatus.getCode()); |
61 | sellerOrder.setUpdateTime(DateUtil.getCurrentTimeSecond()); | 63 | sellerOrder.setUpdateTime(DateUtil.getCurrentTimeSecond()); |
62 | - sellerOrderMapper.updateByOrderCode(sellerOrder); | ||
63 | - // | ||
64 | - SellerOrderGoods targetSog = new SellerOrderGoods(); | ||
65 | - targetSog.setId(orderInfo.getSkup()); | ||
66 | - targetSog.setStatus(sellerOrderStatus.getSkupStatus().getCode()); | ||
67 | - sellerOrderGoodsMapper.updateByPrimaryKeySelective(targetSog); | ||
68 | - SellerOrderGoods tsog = new SellerOrderGoods(); | ||
69 | - tsog.setId(orderInfo.getSkup()); | ||
70 | - productProxyService.syncSkup(tsog,sellerOrderStatus.getSkupStatus()); | 64 | + sellerOrder.setExceptStatus(SellerOrderStatus.WAITING_PAY.getCode()); |
65 | + int updateCnt = sellerOrderMapper.updateByOrderCode(sellerOrder); | ||
66 | + if (1 == updateCnt) { | ||
67 | + // | ||
68 | + SellerOrderGoods targetSog = new SellerOrderGoods(); | ||
69 | + targetSog.setId(orderInfo.getSkup()); | ||
70 | + targetSog.setStatus(soTargetStatus.getSkupStatus().getCode()); | ||
71 | + sellerOrderGoodsMapper.updateByPrimaryKeySelective(targetSog); | ||
72 | + //sync 2 product biz model | ||
73 | + SellerOrderGoods tsog = new SellerOrderGoods(); | ||
74 | + tsog.setId(orderInfo.getSkup()); | ||
75 | + productProxyService.syncSkup(tsog, soTargetStatus.getSkupStatus()); | ||
76 | + } | ||
71 | } | 77 | } |
72 | 78 | ||
73 | 79 | ||
@@ -94,7 +100,7 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService { | @@ -94,7 +100,7 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService { | ||
94 | public boolean isOrderPaid(OrderInfo orderInfo){ | 100 | public boolean isOrderPaid(OrderInfo orderInfo){ |
95 | 101 | ||
96 | if (orderInfo.getStatus() == null || | 102 | if (orderInfo.getStatus() == null || |
97 | - !ActionStatusHold.getSellerCanRefundEarnestMoneyStatus().contains(orderInfo.getStatus().intValue())){ | 103 | + !Objects.equals(SellerOrderStatus.HAS_PAYED.getCode(), orderInfo.getStatus().intValue())){ |
98 | return false; | 104 | return false; |
99 | } | 105 | } |
100 | 106 | ||
@@ -102,6 +108,17 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService { | @@ -102,6 +108,17 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService { | ||
102 | } | 108 | } |
103 | 109 | ||
104 | 110 | ||
111 | + public boolean canRefund(OrderInfo orderInfo){ | ||
112 | + Integer sourceStatus = orderInfo.getSourceStatus(); | ||
113 | + if (sourceStatus != null && | ||
114 | + ActionStatusHold.getSellerCanRefundEarnestMoneyStatus().contains(sourceStatus.intValue())){ | ||
115 | + return true; | ||
116 | + } | ||
117 | + | ||
118 | + return false; | ||
119 | + } | ||
120 | + | ||
121 | + | ||
105 | /** | 122 | /** |
106 | * 保存前回预支付结果 | 123 | * 保存前回预支付结果 |
107 | * @param orderInfo | 124 | * @param orderInfo |
@@ -225,6 +242,7 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService { | @@ -225,6 +242,7 @@ public class SellerOrderPaymentService extends AbstractOrderPaymentService { | ||
225 | .status(sellerOrder.getStatus()) | 242 | .status(sellerOrder.getStatus()) |
226 | .orderCodeType(OrderCodeType.BUYER_TYPE) | 243 | .orderCodeType(OrderCodeType.BUYER_TYPE) |
227 | .amount(sellerOrder.getEarnestMoney()) | 244 | .amount(sellerOrder.getEarnestMoney()) |
245 | + .sourceStatus(sellerOrder.getStatus()) | ||
228 | .build(); | 246 | .build(); |
229 | return orderInfo; | 247 | return orderInfo; |
230 | } | 248 | } |
1 | package com.yohoufo.order.service.handler; | 1 | package com.yohoufo.order.service.handler; |
2 | 2 | ||
3 | +import com.yohoufo.common.utils.BigDecimalHelper; | ||
4 | +import com.yohoufo.order.model.dto.EarnestMoney; | ||
3 | import com.yohoufo.order.model.dto.PlatformFeeDto; | 5 | import com.yohoufo.order.model.dto.PlatformFeeDto; |
4 | import com.yohoufo.order.model.dto.SellerOrderComputeResult; | 6 | import com.yohoufo.order.model.dto.SellerOrderComputeResult; |
5 | import com.yohoufo.order.model.dto.ServiceFeeRate; | 7 | import com.yohoufo.order.model.dto.ServiceFeeRate; |
@@ -16,9 +18,9 @@ import java.math.BigDecimal; | @@ -16,9 +18,9 @@ import java.math.BigDecimal; | ||
16 | public class SellerOrderComputeHandler { | 18 | public class SellerOrderComputeHandler { |
17 | 19 | ||
18 | @Value("${order.seller.earnestmoney.min:28}") | 20 | @Value("${order.seller.earnestmoney.min:28}") |
19 | - private double earnestmoney_min; | 21 | + private double earnestmoney_min = 28; |
20 | @Value("${order.seller.earnestmoney.max:200}") | 22 | @Value("${order.seller.earnestmoney.max:200}") |
21 | - private double earnestmoney_max; | 23 | + private double earnestmoney_max = 200; |
22 | private BigDecimal[] EARNESTMONEYRANGE = new BigDecimal[2]; | 24 | private BigDecimal[] EARNESTMONEYRANGE = new BigDecimal[2]; |
23 | 25 | ||
24 | 26 | ||
@@ -35,19 +37,19 @@ public class SellerOrderComputeHandler { | @@ -35,19 +37,19 @@ public class SellerOrderComputeHandler { | ||
35 | public SellerOrderComputeResult compute(BigDecimal prdPrice){ | 37 | public SellerOrderComputeResult compute(BigDecimal prdPrice){ |
36 | 38 | ||
37 | //保证金(28-200(按照卖家发布商品的货款金额5%计算,最低28,封顶200)) | 39 | //保证金(28-200(按照卖家发布商品的货款金额5%计算,最低28,封顶200)) |
38 | - BigDecimal earnestMoney = calEarnestMoney(prdPrice); | ||
39 | - //银行转账费(0.65%+¥1.00) | ||
40 | - BigDecimal bankTransferfee = calBankTransferFee(prdPrice); | 40 | + EarnestMoney earnestMoney = calEarnestMoney(prdPrice); |
41 | PlatformFeeDto platformFeeDto = calPlatformFee(); | 41 | PlatformFeeDto platformFeeDto = calPlatformFee(); |
42 | - BigDecimal income = calIncome(prdPrice, platformFeeDto.getTotal(), bankTransferfee); | 42 | + |
43 | + // | ||
44 | + ServiceFeeRate serviceFeeRate = ServiceFeeRate.getServiceFeeRate(); | ||
45 | + BigDecimal income = calIncome(prdPrice, platformFeeDto.getTotal(), serviceFeeRate); | ||
43 | //set | 46 | //set |
44 | SellerOrderComputeResult result = new SellerOrderComputeResult(); | 47 | SellerOrderComputeResult result = new SellerOrderComputeResult(); |
45 | result.setEarnestMoney(earnestMoney); | 48 | result.setEarnestMoney(earnestMoney); |
46 | - result.setBankTransferfee(bankTransferfee); | ||
47 | result.setPlatformFee(platformFeeDto); | 49 | result.setPlatformFee(platformFeeDto); |
48 | result.setIncome(income); | 50 | result.setIncome(income); |
49 | //TODO 根据配置文件 | 51 | //TODO 根据配置文件 |
50 | - result.setServiceFeeRate(ServiceFeeRate.getServiceFeeRate()); | 52 | + result.setServiceFeeRate(serviceFeeRate); |
51 | return result; | 53 | return result; |
52 | } | 54 | } |
53 | 55 | ||
@@ -56,8 +58,23 @@ public class SellerOrderComputeHandler { | @@ -56,8 +58,23 @@ public class SellerOrderComputeHandler { | ||
56 | return halfUp(prdPrice.multiply(new BigDecimal(0.0065)).add(new BigDecimal(1))); | 58 | return halfUp(prdPrice.multiply(new BigDecimal(0.0065)).add(new BigDecimal(1))); |
57 | } | 59 | } |
58 | 60 | ||
59 | - private BigDecimal calIncome(BigDecimal prdPrice,BigDecimal platformFee,BigDecimal bankTransferfee){ | ||
60 | - return halfUp(prdPrice.subtract(platformFee).subtract(bankTransferfee)); | 61 | + /** |
62 | + * (1-X-Z)*B-D-E * | ||
63 | + B:货款(卖家发布商品自行输入); | ||
64 | + D:有货鉴定费(暂定5元); | ||
65 | + E:有货包装费(暂定5元); | ||
66 | + X:货款抽成(暂定5%,后期可调整,上线初期为0,后期活动可根据活动进行减免,每个卖家可收费不一样); | ||
67 | + Z:支付渠道费,调用银联支付接口时实时扣款(支付宝0.55%、微信均为0.6%,统一对用户收取0.6%,前期优惠策略可暂定0) | ||
68 | + * @param prdPrice | ||
69 | + * @param platformFee | ||
70 | + * @return | ||
71 | + */ | ||
72 | + private BigDecimal calIncome(BigDecimal prdPrice,BigDecimal platformFee,ServiceFeeRate serviceFeeRate){ | ||
73 | + | ||
74 | + return halfUp(prdPrice.multiply( | ||
75 | + new BigDecimal(1D).subtract(serviceFeeRate.getEarnestMoneyRate()) | ||
76 | + .subtract(serviceFeeRate.getGoodsPaymentRate()) | ||
77 | + ).subtract(platformFee)); | ||
61 | } | 78 | } |
62 | 79 | ||
63 | /** | 80 | /** |
@@ -66,17 +83,11 @@ public class SellerOrderComputeHandler { | @@ -66,17 +83,11 @@ public class SellerOrderComputeHandler { | ||
66 | * @return | 83 | * @return |
67 | */ | 84 | */ |
68 | private PlatformFeeDto calPlatformFee(){ | 85 | private PlatformFeeDto calPlatformFee(){ |
69 | - | ||
70 | - BigDecimal appraiseFee = new BigDecimal(10);; | ||
71 | - BigDecimal packageFee = new BigDecimal(10); | ||
72 | - BigDecimal serviceFee = new BigDecimal(0); | ||
73 | - | ||
74 | - BigDecimal total = appraiseFee.add(packageFee).add(serviceFee); | ||
75 | PlatformFeeDto platformFee = new PlatformFeeDto(); | 86 | PlatformFeeDto platformFee = new PlatformFeeDto(); |
87 | + BigDecimal appraiseFee = platformFee.getAppraiseFee(); | ||
88 | + BigDecimal packageFee = platformFee.getPackageFee(); | ||
89 | + BigDecimal total = appraiseFee.add(packageFee); | ||
76 | platformFee.setTotal(total); | 90 | platformFee.setTotal(total); |
77 | - platformFee.setAppraiseFee(appraiseFee); | ||
78 | - platformFee.setPackageFee(packageFee); | ||
79 | - platformFee.setServiceFee(serviceFee); | ||
80 | return platformFee; | 91 | return platformFee; |
81 | } | 92 | } |
82 | 93 | ||
@@ -85,20 +96,25 @@ public class SellerOrderComputeHandler { | @@ -85,20 +96,25 @@ public class SellerOrderComputeHandler { | ||
85 | * @param prdPrice | 96 | * @param prdPrice |
86 | * @return | 97 | * @return |
87 | */ | 98 | */ |
88 | - private BigDecimal calEarnestMoney(BigDecimal prdPrice){ | ||
89 | - BigDecimal real = halfUp(prdPrice.multiply(new BigDecimal(0.05))); | ||
90 | - final BigDecimal min = EARNESTMONEYRANGE[0]; | ||
91 | - final BigDecimal max = EARNESTMONEYRANGE[1]; | 99 | + private EarnestMoney calEarnestMoney(BigDecimal prdPrice){ |
100 | + EarnestMoney earnestMoney = new EarnestMoney(); | ||
101 | + | ||
102 | + BigDecimal real = halfUp(prdPrice.multiply(earnestMoney.getRate())); | ||
103 | + final BigDecimal min = EARNESTMONEYRANGE[0] == null ? earnestMoney.getMin() : EARNESTMONEYRANGE[0]; | ||
104 | + final BigDecimal max = EARNESTMONEYRANGE[1] == null ? earnestMoney.getMax() : EARNESTMONEYRANGE[1]; | ||
92 | if(real.subtract(min).doubleValue() < 0D){ | 105 | if(real.subtract(min).doubleValue() < 0D){ |
93 | - return min; | 106 | + real = min; |
94 | } | 107 | } |
95 | if (real.subtract(max).doubleValue() > 0D){ | 108 | if (real.subtract(max).doubleValue() > 0D){ |
96 | - return max; | 109 | + real = max; |
97 | } | 110 | } |
98 | - return real; | 111 | + earnestMoney.setMin(min); |
112 | + earnestMoney.setMax(max); | ||
113 | + earnestMoney.setEarnestMoney(real); | ||
114 | + return earnestMoney; | ||
99 | } | 115 | } |
100 | 116 | ||
101 | private BigDecimal halfUp(BigDecimal fee){ | 117 | private BigDecimal halfUp(BigDecimal fee){ |
102 | - return fee.setScale(2, BigDecimal.ROUND_HALF_UP); | 118 | + return BigDecimalHelper.halfUp(fee); |
103 | } | 119 | } |
104 | } | 120 | } |
@@ -90,6 +90,7 @@ public class AppraiseService { | @@ -90,6 +90,7 @@ public class AppraiseService { | ||
90 | tso.setOrderCode(sellerOrderCode); | 90 | tso.setOrderCode(sellerOrderCode); |
91 | tso.setStatus(targetSoStatus.getCode()); | 91 | tso.setStatus(targetSoStatus.getCode()); |
92 | tso.setUpdateTime(DateUtil.getCurrentTimeSecond()); | 92 | tso.setUpdateTime(DateUtil.getCurrentTimeSecond()); |
93 | + tso.setExceptStatus(expectSOStatus.getCode()); | ||
93 | int soCnt = sellerOrderMapper.updateByOrderCode(tso); | 94 | int soCnt = sellerOrderMapper.updateByOrderCode(tso); |
94 | if (soCnt == 1){ | 95 | if (soCnt == 1){ |
95 | //refund earnestMoney | 96 | //refund earnestMoney |
@@ -281,7 +281,7 @@ public class PaymentServiceImpl implements IPaymentService { | @@ -281,7 +281,7 @@ public class PaymentServiceImpl implements IPaymentService { | ||
281 | AbstractOrderPaymentService orderPaymentService = getOrderPaymentService(codeMeta, request.getOrderCode()); | 281 | AbstractOrderPaymentService orderPaymentService = getOrderPaymentService(codeMeta, request.getOrderCode()); |
282 | OrderInfo orderInfo = orderPaymentService.getOrderInfo(request.getOrderCode()); | 282 | OrderInfo orderInfo = orderPaymentService.getOrderInfo(request.getOrderCode()); |
283 | 283 | ||
284 | - if (!orderPaymentService.isOrderPaid(orderInfo)){ | 284 | + if (!orderPaymentService.canRefund(orderInfo)){ |
285 | logger.warn("refund has not paid status, orderCode is {}", request.getOrderCode()); | 285 | logger.warn("refund has not paid status, orderCode is {}", request.getOrderCode()); |
286 | throw new ServiceException(ServiceError.ORDER_HAS_NOT_PAID); | 286 | throw new ServiceException(ServiceError.ORDER_HAS_NOT_PAID); |
287 | } | 287 | } |
@@ -11,10 +11,7 @@ import com.yohoufo.dal.order.model.BuyerOrder; | @@ -11,10 +11,7 @@ import com.yohoufo.dal.order.model.BuyerOrder; | ||
11 | import com.yohoufo.dal.order.model.BuyerOrderGoods; | 11 | import com.yohoufo.dal.order.model.BuyerOrderGoods; |
12 | import com.yohoufo.dal.order.model.SellerOrder; | 12 | import com.yohoufo.dal.order.model.SellerOrder; |
13 | import com.yohoufo.dal.order.model.SellerOrderGoods; | 13 | import com.yohoufo.dal.order.model.SellerOrderGoods; |
14 | -import com.yohoufo.order.common.ActionStatusHold; | ||
15 | -import com.yohoufo.order.common.OrderCodeType; | ||
16 | -import com.yohoufo.order.common.OrderStatus; | ||
17 | -import com.yohoufo.order.common.SellerOrderStatus; | 14 | +import com.yohoufo.order.common.*; |
18 | import com.yohoufo.order.event.ErpCancelSellerOrderEvent; | 15 | import com.yohoufo.order.event.ErpCancelSellerOrderEvent; |
19 | import com.yohoufo.order.event.OrderCancelEvent; | 16 | import com.yohoufo.order.event.OrderCancelEvent; |
20 | import com.yohoufo.order.model.request.PaymentRequest; | 17 | import com.yohoufo.order.model.request.PaymentRequest; |
@@ -27,16 +24,15 @@ import com.yohoufo.order.service.impl.visitor.UserCancelCase; | @@ -27,16 +24,15 @@ import com.yohoufo.order.service.impl.visitor.UserCancelCase; | ||
27 | import com.yohoufo.order.service.proxy.ProductProxyService; | 24 | import com.yohoufo.order.service.proxy.ProductProxyService; |
28 | import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator; | 25 | import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator; |
29 | import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta; | 26 | import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta; |
27 | +import lombok.experimental.Builder; | ||
30 | import org.slf4j.Logger; | 28 | import org.slf4j.Logger; |
31 | import org.slf4j.LoggerFactory; | 29 | import org.slf4j.LoggerFactory; |
32 | import org.springframework.beans.factory.annotation.Autowired; | 30 | import org.springframework.beans.factory.annotation.Autowired; |
33 | import org.springframework.stereotype.Service; | 31 | import org.springframework.stereotype.Service; |
34 | 32 | ||
35 | -import java.util.Arrays; | ||
36 | import java.util.List; | 33 | import java.util.List; |
37 | import java.util.Objects; | 34 | import java.util.Objects; |
38 | import java.util.Optional; | 35 | import java.util.Optional; |
39 | -import java.util.stream.Collectors; | ||
40 | 36 | ||
41 | /** | 37 | /** |
42 | * Created by chenchao on 2018/9/17. | 38 | * Created by chenchao on 2018/9/17. |
@@ -118,7 +114,7 @@ public class SellerOrderCancelService { | @@ -118,7 +114,7 @@ public class SellerOrderCancelService { | ||
118 | if (Objects.isNull(status)){ | 114 | if (Objects.isNull(status)){ |
119 | return result; | 115 | return result; |
120 | } | 116 | } |
121 | - List<Integer> sellerCanCancelStatus = ActionStatusHold.getSellerCanCancelStatus(); | 117 | + List<Integer> sellerCanCancelStatus = ActionStatusHold.getSellerCanRefundStatus(); |
122 | if (!sellerCanCancelStatus.contains(status)){ | 118 | if (!sellerCanCancelStatus.contains(status)){ |
123 | logger.warn("seller cancel can not execute in this status, uid {} orderCode {}, status {}", uid, orderCode, status); | 119 | logger.warn("seller cancel can not execute in this status, uid {} orderCode {}, status {}", uid, orderCode, status); |
124 | throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY); | 120 | throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY); |
@@ -130,7 +126,10 @@ public class SellerOrderCancelService { | @@ -130,7 +126,10 @@ public class SellerOrderCancelService { | ||
130 | //case 1: 未支付时 | 126 | //case 1: 未支付时 |
131 | if (SellerOrderStatus.WAITING_PAY.getCode() == status){ | 127 | if (SellerOrderStatus.WAITING_PAY.getCode() == status){ |
132 | targetSOStatus = SellerOrderStatus.SELf_CANCEL_PAY; | 128 | targetSOStatus = SellerOrderStatus.SELf_CANCEL_PAY; |
133 | - result = cancelBeforePayAction(uid, orderCode, sellerOrder.getSkup(), targetSOStatus); | 129 | + |
130 | + SellerOrderStatusNode statusNode = SellerOrderStatusNode.builder() | ||
131 | + .exceptStatus(SellerOrderStatus.WAITING_PAY).targetStatus(targetSOStatus).build(); | ||
132 | + result = cancelBeforePayAction(uid, orderCode, sellerOrder.getSkup(), statusNode); | ||
134 | } | 133 | } |
135 | 134 | ||
136 | //case 2: 支付完成,没有买家下单 | 135 | //case 2: 支付完成,没有买家下单 |
@@ -160,30 +159,26 @@ public class SellerOrderCancelService { | @@ -160,30 +159,26 @@ public class SellerOrderCancelService { | ||
160 | //case 1: 未支付时 | 159 | //case 1: 未支付时 |
161 | if (SellerOrderStatus.WAITING_PAY.getCode() == status){ | 160 | if (SellerOrderStatus.WAITING_PAY.getCode() == status){ |
162 | targetSOStatus = SellerOrderStatus.TIMEOUT_CANCEL; | 161 | targetSOStatus = SellerOrderStatus.TIMEOUT_CANCEL; |
163 | - result = cancelBeforePayAction(uid, orderCode, sellerOrder.getSkup(), targetSOStatus); | 162 | + SellerOrderStatusNode statusNode = SellerOrderStatusNode.builder() |
163 | + .exceptStatus(SellerOrderStatus.WAITING_PAY) | ||
164 | + .targetStatus(targetSOStatus).build(); | ||
165 | + result = cancelBeforePayAction(uid, orderCode, sellerOrder.getSkup(), statusNode); | ||
164 | } | 166 | } |
165 | 167 | ||
166 | return result; | 168 | return result; |
167 | } | 169 | } |
168 | 170 | ||
169 | - private int cancelBeforePayAction(int uid, long orderCode,Integer skup, SellerOrderStatus targetSOStatus){ | ||
170 | - logger.info("in seller cancel before Buy Action, uid {}, orderCode {}, targetSOStatus {}", | ||
171 | - uid, orderCode, targetSOStatus); | ||
172 | - SellerOrder target = new SellerOrder(); | ||
173 | - target.setOrderCode(orderCode); | ||
174 | - target.setUid(uid); | ||
175 | - target.setStatus(targetSOStatus.getCode()); | ||
176 | - target.setSkup(skup); | ||
177 | - return cancelBeforePayAction(target, targetSOStatus); | 171 | + @Builder |
172 | + static class SellerOrderStatusNode{ | ||
173 | + SellerOrderStatus targetStatus; | ||
174 | + SellerOrderStatus exceptStatus; | ||
178 | } | 175 | } |
179 | 176 | ||
180 | - /** | ||
181 | - * | ||
182 | - * @param target | ||
183 | - * @param targetSOStatus | ||
184 | - * @return | ||
185 | - */ | ||
186 | - private int cancelBeforePayAction(SellerOrder target, SellerOrderStatus targetSOStatus){ | 177 | + private int cancelBeforePayAction(int uid, long orderCode, Integer skup, SellerOrderStatusNode statusNode){ |
178 | + SellerOrderStatus targetSOStatus = statusNode.targetStatus; | ||
179 | + SellerOrderStatus exceptStatus = statusNode.exceptStatus; | ||
180 | + logger.info("in seller cancel before Buy Action, uid {}, orderCode {}, targetSOStatus {}, exceptStatus {}", | ||
181 | + uid, orderCode, targetSOStatus, exceptStatus); | ||
187 | /**case 1: 未支付时 | 182 | /**case 1: 未支付时 |
188 | * actions as blow: | 183 | * actions as blow: |
189 | * 1. sellerOrder | 184 | * 1. sellerOrder |
@@ -191,9 +186,15 @@ public class SellerOrderCancelService { | @@ -191,9 +186,15 @@ public class SellerOrderCancelService { | ||
191 | * 3. 同步product skup状态 | 186 | * 3. 同步product skup状态 |
192 | */ | 187 | */ |
193 | int result = 0; | 188 | int result = 0; |
194 | - | ||
195 | //update seller order | 189 | //update seller order |
196 | if (Objects.nonNull(targetSOStatus)){ | 190 | if (Objects.nonNull(targetSOStatus)){ |
191 | + SellerOrder target = new SellerOrder(); | ||
192 | + target.setOrderCode(orderCode); | ||
193 | + target.setUid(uid); | ||
194 | + target.setStatus(targetSOStatus.getCode()); | ||
195 | + target.setSkup(skup); | ||
196 | + target.setExceptStatus(exceptStatus.getCode()); | ||
197 | + target.setStatus(targetSOStatus.getCode()); | ||
197 | target.setUpdateTime(DateUtil.getCurrentTimeSecond()); | 198 | target.setUpdateTime(DateUtil.getCurrentTimeSecond()); |
198 | result += sellerOrderMapper.updateByOrderCode(target); | 199 | result += sellerOrderMapper.updateByOrderCode(target); |
199 | } | 200 | } |
@@ -202,17 +203,19 @@ public class SellerOrderCancelService { | @@ -202,17 +203,19 @@ public class SellerOrderCancelService { | ||
202 | //sync skup | 203 | //sync skup |
203 | if (result>0) { | 204 | if (result>0) { |
204 | SellerOrderGoods sogCondition = new SellerOrderGoods(); | 205 | SellerOrderGoods sogCondition = new SellerOrderGoods(); |
205 | - sogCondition.setId(target.getSkup()); | 206 | + sogCondition.setId(skup); |
206 | sogCondition.setStatus(targetSOStatus.getSkupStatus().getCode()); | 207 | sogCondition.setStatus(targetSOStatus.getSkupStatus().getCode()); |
207 | sellerOrderGoodsMapper.updateByPrimaryKeySelective(sogCondition); | 208 | sellerOrderGoodsMapper.updateByPrimaryKeySelective(sogCondition); |
208 | //sync skup | 209 | //sync skup |
209 | SellerOrderGoods tsog = new SellerOrderGoods(); | 210 | SellerOrderGoods tsog = new SellerOrderGoods(); |
210 | - tsog.setId(target.getSkup()); | 211 | + tsog.setId(skup); |
211 | productProxyService.syncSkup(tsog, targetSOStatus.getSkupStatus()); | 212 | productProxyService.syncSkup(tsog, targetSOStatus.getSkupStatus()); |
212 | } | 213 | } |
213 | return result; | 214 | return result; |
214 | } | 215 | } |
215 | 216 | ||
217 | + | ||
218 | + | ||
216 | private int cancelAfterPayButNotBuyAction(SellerOrder sellerOrder){ | 219 | private int cancelAfterPayButNotBuyAction(SellerOrder sellerOrder){ |
217 | /**case 2: 支付完成,没有买家下单 | 220 | /**case 2: 支付完成,没有买家下单 |
218 | * actions as blow: | 221 | * actions as blow: |
@@ -228,8 +231,11 @@ public class SellerOrderCancelService { | @@ -228,8 +231,11 @@ public class SellerOrderCancelService { | ||
228 | SellerOrderStatus targetSOStatus; | 231 | SellerOrderStatus targetSOStatus; |
229 | 232 | ||
230 | targetSOStatus = SellerOrderStatus.PLAY_SELF; | 233 | targetSOStatus = SellerOrderStatus.PLAY_SELF; |
234 | + SellerOrderStatus expectStatus = SellerOrderStatus.HAS_PAYED; | ||
231 | int skup = sellerOrder.getSkup(); | 235 | int skup = sellerOrder.getSkup(); |
232 | - result = cancelBeforePayAction(sellerUid, orderCode, skup, targetSOStatus); | 236 | + SellerOrderStatusNode statusNode = SellerOrderStatusNode.builder().targetStatus(targetSOStatus) |
237 | + .exceptStatus(expectStatus).build(); | ||
238 | + result = cancelBeforePayAction(sellerUid, orderCode, skup, statusNode); | ||
233 | //refund earnestMoney | 239 | //refund earnestMoney |
234 | if (result>0){ | 240 | if (result>0){ |
235 | double earnestMoney = sellerOrder.getEarnestMoney().doubleValue(); | 241 | double earnestMoney = sellerOrder.getEarnestMoney().doubleValue(); |
@@ -280,6 +286,7 @@ public class SellerOrderCancelService { | @@ -280,6 +286,7 @@ public class SellerOrderCancelService { | ||
280 | target.setUid(sellerUid); | 286 | target.setUid(sellerUid); |
281 | target.setStatus(targetSOStatus.getCode()); | 287 | target.setStatus(targetSOStatus.getCode()); |
282 | target.setUpdateTime(DateUtil.getCurrentTimeSecond()); | 288 | target.setUpdateTime(DateUtil.getCurrentTimeSecond()); |
289 | + target.setExceptStatus(SellerOrderStatus.HAS_PAYED.getCode()); | ||
283 | result += sellerOrderMapper.updateByOrderCode(target); | 290 | result += sellerOrderMapper.updateByOrderCode(target); |
284 | 291 | ||
285 | //TODO 分赃(分账) 有待考虑使用2比对 | 292 | //TODO 分赃(分账) 有待考虑使用2比对 |
@@ -354,6 +361,7 @@ public class SellerOrderCancelService { | @@ -354,6 +361,7 @@ public class SellerOrderCancelService { | ||
354 | 361 | ||
355 | 362 | ||
356 | /** | 363 | /** |
364 | + * 目前来看 只有支付过保证金的skup才有下架处理 | ||
357 | * TODO 如何控制好并发,必须控制不能重复转账 退款 | 365 | * TODO 如何控制好并发,必须控制不能重复转账 退款 |
358 | * 使用乐观锁,带着查询到的状态且符合条件时再去更新 | 366 | * 使用乐观锁,带着查询到的状态且符合条件时再去更新 |
359 | * @param offShelveCancelCase | 367 | * @param offShelveCancelCase |
@@ -362,15 +370,32 @@ public class SellerOrderCancelService { | @@ -362,15 +370,32 @@ public class SellerOrderCancelService { | ||
362 | logger.info("in cancel offShelveCancelCase {}", offShelveCancelCase); | 370 | logger.info("in cancel offShelveCancelCase {}", offShelveCancelCase); |
363 | ErpCancelSellerOrderEvent event = (ErpCancelSellerOrderEvent)offShelveCancelCase.getEvent(); | 371 | ErpCancelSellerOrderEvent event = (ErpCancelSellerOrderEvent)offShelveCancelCase.getEvent(); |
364 | final int skup = event.getSkup(); | 372 | final int skup = event.getSkup(); |
373 | + if (skup <= 0){ | ||
374 | + logger.warn("in offShelveCancelCase ,skup is illegal, skup {}", skup); | ||
375 | + return; | ||
376 | + } | ||
377 | + SellerOrderGoods psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup); | ||
378 | + Integer skupStatus; | ||
379 | + if (psog == null || (skupStatus = psog.getStatus() )== null){ | ||
380 | + logger.warn("in offShelveCancelCase, SellerOrderGoods or it's status illegal, skup {}", skup); | ||
381 | + return; | ||
382 | + } | ||
383 | + | ||
384 | + SkupStatus expectSkupStatus = SkupStatus.CAN_SELL; | ||
385 | + boolean isPayEarnestMoney = expectSkupStatus.getCode() == skupStatus; | ||
386 | + if (!isPayEarnestMoney){ | ||
387 | + logger.warn("in offShelveCancelCase, SellerOrderGoods status illegal, skup {}, status {}", skup, skupStatus); | ||
388 | + return; | ||
389 | + } | ||
365 | 390 | ||
366 | final SellerOrderStatus targetSellerOrderStatus = SellerOrderStatus.YOHO_CANCEL_SELL; | 391 | final SellerOrderStatus targetSellerOrderStatus = SellerOrderStatus.YOHO_CANCEL_SELL; |
367 | //TODO check skup is buy away | 392 | //TODO check skup is buy away |
368 | SellerOrderGoods targetGoods = new SellerOrderGoods(); | 393 | SellerOrderGoods targetGoods = new SellerOrderGoods(); |
369 | targetGoods.setId(skup); | 394 | targetGoods.setId(skup); |
370 | targetGoods.setStatus(targetSellerOrderStatus.getSkupStatus().getCode()); | 395 | targetGoods.setStatus(targetSellerOrderStatus.getSkupStatus().getCode()); |
371 | - | 396 | + targetGoods.setExceptStatus(skupStatus); |
372 | //利用数据库做并发控制 | 397 | //利用数据库做并发控制 |
373 | - int result = sellerOrderGoodsMapper.updateByPrimaryKeySelective(targetGoods); | 398 | + int result = sellerOrderGoodsMapper.updateStatusBySkpu(targetGoods); |
374 | if (result == 0) { | 399 | if (result == 0) { |
375 | return; | 400 | return; |
376 | } | 401 | } |
@@ -380,10 +405,13 @@ public class SellerOrderCancelService { | @@ -380,10 +405,13 @@ public class SellerOrderCancelService { | ||
380 | Long orderCode = sellerOrder.getOrderCode(); | 405 | Long orderCode = sellerOrder.getOrderCode(); |
381 | SellerOrder tso = new SellerOrder(); | 406 | SellerOrder tso = new SellerOrder(); |
382 | tso.setOrderCode(sellerOrder.getOrderCode()); | 407 | tso.setOrderCode(sellerOrder.getOrderCode()); |
408 | + tso.setExceptStatus(sellerOrder.getStatus()); | ||
383 | tso.setStatus(targetSellerOrderStatus.getCode()); | 409 | tso.setStatus(targetSellerOrderStatus.getCode()); |
410 | + tso.setUid(sellerUid); | ||
411 | + tso.setUpdateTime(DateUtil.getCurrentTimeSecond()); | ||
384 | result = sellerOrderMapper.updateByOrderCode(tso); | 412 | result = sellerOrderMapper.updateByOrderCode(tso); |
385 | - //refund earnestMoney | ||
386 | - if (result > 0) { | 413 | + //refund earnestMoney only has payed |
414 | + if (isPayEarnestMoney && result > 0) { | ||
387 | double earnestMoney = sellerOrder.getEarnestMoney().doubleValue(); | 415 | double earnestMoney = sellerOrder.getEarnestMoney().doubleValue(); |
388 | PaymentRequest refundReq = PaymentRequest.builder().uid(sellerOrder.getUid()) | 416 | PaymentRequest refundReq = PaymentRequest.builder().uid(sellerOrder.getUid()) |
389 | .orderCode(sellerOrder.getOrderCode()) | 417 | .orderCode(sellerOrder.getOrderCode()) |
@@ -33,7 +33,7 @@ public class SellerOrderCreateService { | @@ -33,7 +33,7 @@ public class SellerOrderCreateService { | ||
33 | condition.setIsDel(DelStatus.NOT_DEL.getCode()); | 33 | condition.setIsDel(DelStatus.NOT_DEL.getCode()); |
34 | condition.setCreateTime(currentTiem); | 34 | condition.setCreateTime(currentTiem); |
35 | condition.setStatus(SellerOrderStatus.WAITING_PAY.getCode()); | 35 | condition.setStatus(SellerOrderStatus.WAITING_PAY.getCode()); |
36 | - condition.setEarnestMoney(context.getSellerOrderComputeResult().getEarnestMoney()); | 36 | + condition.setEarnestMoney(context.getSellerOrderComputeResult().getEarnestMoney().getEarnestMoney()); |
37 | condition.setIncome(context.getSellerOrderComputeResult().getIncome()); | 37 | condition.setIncome(context.getSellerOrderComputeResult().getIncome()); |
38 | return sellerOrderMapper.insertSelective(condition); | 38 | return sellerOrderMapper.insertSelective(condition); |
39 | } | 39 | } |
1 | +package com.yohoufo.order.service.proxy; | ||
2 | + | ||
3 | +import com.yohobuy.ufo.model.enums.InboxBusinessTypeEnum; | ||
4 | +import com.yohoufo.inboxclient.model.InBoxResponse; | ||
5 | +import com.yohoufo.inboxclient.model.InboxReqVO; | ||
6 | +import com.yohoufo.inboxclient.sdk.InBoxSDK; | ||
7 | +import org.apache.commons.lang3.StringUtils; | ||
8 | +import org.slf4j.Logger; | ||
9 | +import org.slf4j.LoggerFactory; | ||
10 | +import org.springframework.beans.factory.annotation.Autowired; | ||
11 | +import org.springframework.stereotype.Service; | ||
12 | + | ||
13 | +/** | ||
14 | + * Created by chenchao on 2018/10/8. | ||
15 | + */ | ||
16 | +@Service | ||
17 | +public class InBoxFacade { | ||
18 | + | ||
19 | + private final Logger logger = LoggerFactory.getLogger(getClass()); | ||
20 | + | ||
21 | + @Autowired | ||
22 | + private InBoxSDK inBoxSDK; | ||
23 | + | ||
24 | + /** | ||
25 | + * 买家订单未付款 | ||
26 | + * @param buyerUid | ||
27 | + */ | ||
28 | + public void buyerOrderNotPayed(int buyerUid, long orderCode){ | ||
29 | + InboxReqVO req = new InboxReqVO(); | ||
30 | + req.setUid(buyerUid); | ||
31 | + String params = buildParams(orderCode); | ||
32 | + req.setParams(params); | ||
33 | + InboxBusinessTypeEnum ibt = InboxBusinessTypeEnum.PURCHASE_UNPAID; | ||
34 | + req.setType(ibt.getType()); | ||
35 | + req.setBusinessType(ibt.getBusinessType()); | ||
36 | + // | ||
37 | + InBoxResponse resp = inBoxSDK.addInbox(req); | ||
38 | + logger.info("record buyerOrderNotPayed inbox msg, buyerUid {}, orderCode {}, resp {}", | ||
39 | + buyerUid, orderCode, resp); | ||
40 | + } | ||
41 | + | ||
42 | + | ||
43 | + public static String buildParams(Object... objects){ | ||
44 | + String params = StringUtils.join(objects, ","); | ||
45 | + return params; | ||
46 | + } | ||
47 | +} |
@@ -2,6 +2,8 @@ package com.yohoufo.order.service; | @@ -2,6 +2,8 @@ package com.yohoufo.order.service; | ||
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
4 | import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo; | 4 | import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo; |
5 | +import com.yohoufo.order.model.dto.SellerOrderComputeResult; | ||
6 | +import com.yohoufo.order.service.handler.SellerOrderComputeHandler; | ||
5 | import com.yohoufo.order.service.impl.SellerOrderService; | 7 | import com.yohoufo.order.service.impl.SellerOrderService; |
6 | import org.junit.Test; | 8 | import org.junit.Test; |
7 | 9 | ||
@@ -14,9 +16,9 @@ public class SellerOrderServiceTest { | @@ -14,9 +16,9 @@ public class SellerOrderServiceTest { | ||
14 | 16 | ||
15 | @Test | 17 | @Test |
16 | public void testBuildSoldPrdComputeBo(){ | 18 | public void testBuildSoldPrdComputeBo(){ |
17 | - SellerOrderService sos = new SellerOrderService(); | ||
18 | - BigDecimal prdPrice = new BigDecimal(123.44); | ||
19 | - SoldPrdComputeBo bo = sos.buildSoldPrdComputeBo(prdPrice); | 19 | + SellerOrderComputeHandler sos = new SellerOrderComputeHandler(); |
20 | + BigDecimal prdPrice = new BigDecimal(123.44D); | ||
21 | + SellerOrderComputeResult bo = sos.compute(prdPrice); | ||
20 | System.out.println("in testBuildSoldPrdComputeBo :"+ JSONObject.toJSONString(bo)); | 22 | System.out.println("in testBuildSoldPrdComputeBo :"+ JSONObject.toJSONString(bo)); |
21 | } | 23 | } |
22 | } | 24 | } |
@@ -90,6 +90,12 @@ | @@ -90,6 +90,12 @@ | ||
90 | <artifactId>commons-pool2</artifactId> | 90 | <artifactId>commons-pool2</artifactId> |
91 | <version>2.2</version> | 91 | <version>2.2</version> |
92 | </dependency> | 92 | </dependency> |
93 | + | ||
94 | + | ||
95 | + <dependency> | ||
96 | + <groupId>com.yohoufo.fore</groupId> | ||
97 | + <artifactId>yohoufo-fore-inboxclient</artifactId> | ||
98 | + </dependency> | ||
93 | </dependencies> | 99 | </dependencies> |
94 | 100 | ||
95 | 101 |
@@ -19,7 +19,6 @@ | @@ -19,7 +19,6 @@ | ||
19 | 19 | ||
20 | <context:component-scan base-package="com.yohoufo" /> | 20 | <context:component-scan base-package="com.yohoufo" /> |
21 | 21 | ||
22 | - | ||
23 | <!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 --> | 22 | <!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 --> |
24 | <mvc:annotation-driven> | 23 | <mvc:annotation-driven> |
25 | <mvc:message-converters register-defaults="false"> | 24 | <mvc:message-converters register-defaults="false"> |
-
Please register or login to post a comment