Authored by sailing-PC\sailing

update

@@ -3,6 +3,7 @@ package com.yohoufo.dal.order; @@ -3,6 +3,7 @@ package com.yohoufo.dal.order;
3 import com.yohoufo.dal.order.model.BuyerOrder; 3 import com.yohoufo.dal.order.model.BuyerOrder;
4 import org.apache.ibatis.annotations.Param; 4 import org.apache.ibatis.annotations.Param;
5 5
  6 +import java.util.Collection;
6 import java.util.List; 7 import java.util.List;
7 8
8 9
@@ -36,4 +37,8 @@ public interface BuyerOrderMapper { @@ -36,4 +37,8 @@ public interface BuyerOrderMapper {
36 @Param("offset")Integer offset, @Param("limit")Integer limit); 37 @Param("offset")Integer offset, @Param("limit")Integer limit);
37 38
38 int updateByPrimaryKey(BuyerOrder record); 39 int updateByPrimaryKey(BuyerOrder record);
  40 +
  41 +
  42 + int updateBatchByOrderCodes(@Param("orderCodes")Collection<Long> orderCodes,@Param("status")Integer status,
  43 + @Param("updateTime")Integer updateTime);
39 } 44 }
@@ -19,7 +19,8 @@ public class SellerOrder { @@ -19,7 +19,8 @@ public class SellerOrder {
19 19
20 private BigDecimal earnestMoney; 20 private BigDecimal earnestMoney;
21 21
22 - private Integer isCancel; 22 +
  23 + private Integer isDel;
23 24
24 private Integer status; 25 private Integer status;
25 26
@@ -91,13 +92,6 @@ public class SellerOrder { @@ -91,13 +92,6 @@ public class SellerOrder {
91 this.earnestMoney = earnestMoney; 92 this.earnestMoney = earnestMoney;
92 } 93 }
93 94
94 - public Integer getIsCancel() {  
95 - return isCancel;  
96 - }  
97 -  
98 - public void setIsCancel(Integer isCancel) {  
99 - this.isCancel = isCancel;  
100 - }  
101 95
102 public Integer getStatus() { 96 public Integer getStatus() {
103 return status; 97 return status;
@@ -122,4 +116,12 @@ public class SellerOrder { @@ -122,4 +116,12 @@ public class SellerOrder {
122 public void setUpdateTime(Integer updateTime) { 116 public void setUpdateTime(Integer updateTime) {
123 this.updateTime = updateTime; 117 this.updateTime = updateTime;
124 } 118 }
  119 +
  120 + public Integer getIsDel() {
  121 + return isDel;
  122 + }
  123 +
  124 + public void setIsDel(Integer isDel) {
  125 + this.isDel = isDel;
  126 + }
125 } 127 }
@@ -289,6 +289,17 @@ @@ -289,6 +289,17 @@
289 </update> 289 </update>
290 290
291 291
  292 + <update id="updateBatchByOrderCodes" parameterType="com.yohoufo.dal.order.model.BuyerOrder">
  293 + update buyer_order
  294 + set
  295 + status = #{status,jdbcType=INTEGER},
  296 + update_time = #{updateTime,jdbcType=INTEGER}
  297 + where order_code IN
  298 + <foreach collection="orderCodes" item="orderCode" open="(" separator="," close=")">
  299 + #{orderCode,jdbcType=BIGINT}
  300 + </foreach>
  301 + </update>
  302 +
292 <sql id="sql_where_4_select_SellerUidStatus"> 303 <sql id="sql_where_4_select_SellerUidStatus">
293 seller_uid = #{sellerUid,jdbcType=INTEGER} 304 seller_uid = #{sellerUid,jdbcType=INTEGER}
294 and seller_order_status = 1 305 and seller_order_status = 1
@@ -10,13 +10,13 @@ @@ -10,13 +10,13 @@
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="earnest_money" jdbcType="DECIMAL" property="earnestMoney" /> 12 <result column="earnest_money" jdbcType="DECIMAL" property="earnestMoney" />
13 - <result column="is_cancel" jdbcType="TINYINT" property="isCancel" /> 13 + <result column="is_del" jdbcType="TINYINT" property="isDel" />
14 <result column="status" jdbcType="TINYINT" property="status" /> 14 <result column="status" jdbcType="TINYINT" property="status" />
15 <result column="create_time" jdbcType="INTEGER" property="createTime" /> 15 <result column="create_time" jdbcType="INTEGER" property="createTime" />
16 <result column="update_time" jdbcType="INTEGER" property="updateTime" /> 16 <result column="update_time" jdbcType="INTEGER" property="updateTime" />
17 </resultMap> 17 </resultMap>
18 <sql id="Base_Column_List"> 18 <sql id="Base_Column_List">
19 - id, order_code, skup, uid, client_type, payment, income, earnest_money, is_cancel, 19 + id, order_code, skup, uid, client_type, payment, income, earnest_money, is_del,
20 status, create_time, update_time 20 status, create_time, update_time
21 </sql> 21 </sql>
22 <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> 22 <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
@@ -72,11 +72,11 @@ @@ -72,11 +72,11 @@
72 <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.SellerOrder" useGeneratedKeys="true"> 72 <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.SellerOrder" useGeneratedKeys="true">
73 insert into seller_order (order_code, skup, uid, 73 insert into seller_order (order_code, skup, uid,
74 client_type, payment, income, 74 client_type, payment, income,
75 - earnest_money, is_cancel, status, 75 + earnest_money, is_del, status,
76 create_time, update_time) 76 create_time, update_time)
77 values (#{orderCode,jdbcType=BIGINT}, #{skup,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, 77 values (#{orderCode,jdbcType=BIGINT}, #{skup,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER},
78 #{clientType,jdbcType=TINYINT}, #{payment,jdbcType=TINYINT}, #{income,jdbcType=DECIMAL}, 78 #{clientType,jdbcType=TINYINT}, #{payment,jdbcType=TINYINT}, #{income,jdbcType=DECIMAL},
79 - #{earnestMoney,jdbcType=DECIMAL}, #{isCancel,jdbcType=TINYINT}, #{status,jdbcType=TINYINT}, 79 + #{earnestMoney,jdbcType=DECIMAL}, #{isDel,jdbcType=TINYINT}, #{status,jdbcType=TINYINT},
80 #{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER}) 80 #{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER})
81 </insert> 81 </insert>
82 <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.SellerOrder" useGeneratedKeys="true"> 82 <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.SellerOrder" useGeneratedKeys="true">
@@ -103,8 +103,8 @@ @@ -103,8 +103,8 @@
103 <if test="earnestMoney != null"> 103 <if test="earnestMoney != null">
104 earnest_money, 104 earnest_money,
105 </if> 105 </if>
106 - <if test="isCancel != null">  
107 - is_cancel, 106 + <if test="isDel != null">
  107 + is_del,
108 </if> 108 </if>
109 <if test="status != null"> 109 <if test="status != null">
110 status, 110 status,
@@ -138,8 +138,8 @@ @@ -138,8 +138,8 @@
138 <if test="earnestMoney != null"> 138 <if test="earnestMoney != null">
139 #{earnestMoney,jdbcType=DECIMAL}, 139 #{earnestMoney,jdbcType=DECIMAL},
140 </if> 140 </if>
141 - <if test="isCancel != null">  
142 - #{isCancel,jdbcType=TINYINT}, 141 + <if test="isDel != null">
  142 + #{isDel,jdbcType=TINYINT},
143 </if> 143 </if>
144 <if test="status != null"> 144 <if test="status != null">
145 #{status,jdbcType=TINYINT}, 145 #{status,jdbcType=TINYINT},
@@ -176,8 +176,8 @@ @@ -176,8 +176,8 @@
176 <if test="earnestMoney != null"> 176 <if test="earnestMoney != null">
177 earnest_money = #{earnestMoney,jdbcType=DECIMAL}, 177 earnest_money = #{earnestMoney,jdbcType=DECIMAL},
178 </if> 178 </if>
179 - <if test="isCancel != null">  
180 - is_cancel = #{isCancel,jdbcType=TINYINT}, 179 + <if test="isDel != null">
  180 + is_del = #{isDel,jdbcType=TINYINT},
181 </if> 181 </if>
182 <if test="status != null"> 182 <if test="status != null">
183 status = #{status,jdbcType=TINYINT}, 183 status = #{status,jdbcType=TINYINT},
@@ -200,7 +200,7 @@ @@ -200,7 +200,7 @@
200 payment = #{payment,jdbcType=TINYINT}, 200 payment = #{payment,jdbcType=TINYINT},
201 income = #{income,jdbcType=DECIMAL}, 201 income = #{income,jdbcType=DECIMAL},
202 earnest_money = #{earnestMoney,jdbcType=DECIMAL}, 202 earnest_money = #{earnestMoney,jdbcType=DECIMAL},
203 - is_cancel = #{isCancel,jdbcType=TINYINT}, 203 + is_del = #{isDel,jdbcType=TINYINT},
204 status = #{status,jdbcType=TINYINT}, 204 status = #{status,jdbcType=TINYINT},
205 create_time = #{createTime,jdbcType=INTEGER}, 205 create_time = #{createTime,jdbcType=INTEGER},
206 update_time = #{updateTime,jdbcType=INTEGER} 206 update_time = #{updateTime,jdbcType=INTEGER}
  1 +package com.yohoufo.order.common;
  2 +
  3 +/**
  4 + * Created by chenchao on 2018/9/25.
  5 + */
  6 +public enum DelStatus {
  7 +
  8 + NOT_DEL(0),
  9 +
  10 + IS_DEL(1);
  11 +
  12 + private int code;
  13 +
  14 + DelStatus(int code){
  15 + this.code = code;
  16 + }
  17 +
  18 +
  19 + public int getCode() {
  20 + return code;
  21 + }
  22 +}
@@ -75,8 +75,7 @@ public class SellerOrderController { @@ -75,8 +75,7 @@ public class SellerOrderController {
75 } 75 }
76 76
77 77
78 - @Autowired  
79 - private SellerOrderCancelService sellerOrderCancelService; 78 +
80 79
81 80
82 @RequestMapping(params = "method=ufo.sellerOrder.cancel") 81 @RequestMapping(params = "method=ufo.sellerOrder.cancel")
@@ -89,7 +88,25 @@ public class SellerOrderController { @@ -89,7 +88,25 @@ public class SellerOrderController {
89 .orderCode(orderCode) 88 .orderCode(orderCode)
90 .build(); 89 .build();
91 logger.info("in ufo.sellerOrder.cancel, req {}", req); 90 logger.info("in ufo.sellerOrder.cancel, req {}", req);
92 - boolean result = sellerOrderCancelService.cancel(req); 91 + boolean result = sellerOrderService.cancel(req);
  92 + String msg = "取消成功";
  93 + if(!result){
  94 + msg = "取消失败";
  95 + }
  96 + return new ApiResponse.ApiResponseBuilder().data(result).code(200).message(msg).build();
  97 + }
  98 +
  99 + @RequestMapping(params = "method=ufo.sellerOrder.delete")
  100 + @ResponseBody
  101 + public ApiResponse delete(@RequestParam(name = "uid", required = true)int uid,
  102 + @RequestParam(name = "order_code", required = true)long orderCode
  103 + ) throws GatewayException {
  104 + SellerOrderCancelReq req = SellerOrderCancelReq.builder()
  105 + .uid(uid)
  106 + .orderCode(orderCode)
  107 + .build();
  108 + logger.info("in ufo.sellerOrder.cancel, req {}", req);
  109 + boolean result = sellerOrderService.delete(req);
93 String msg = "取消成功"; 110 String msg = "取消成功";
94 if(!result){ 111 if(!result){
95 msg = "取消失败"; 112 msg = "取消失败";
@@ -6,13 +6,16 @@ import com.yohobuy.ufo.model.order.req.SellerOrderCancelReq; @@ -6,13 +6,16 @@ import com.yohobuy.ufo.model.order.req.SellerOrderCancelReq;
6 import com.yohoufo.common.utils.DateUtil; 6 import com.yohoufo.common.utils.DateUtil;
7 import com.yohoufo.dal.order.BuyerOrderMapper; 7 import com.yohoufo.dal.order.BuyerOrderMapper;
8 import com.yohoufo.dal.order.SellerOrderMapper; 8 import com.yohoufo.dal.order.SellerOrderMapper;
  9 +import com.yohoufo.dal.order.model.BuyerOrder;
9 import com.yohoufo.dal.order.model.SellerOrder; 10 import com.yohoufo.dal.order.model.SellerOrder;
10 import com.yohoufo.order.common.CancelType; 11 import com.yohoufo.order.common.CancelType;
11 import com.yohoufo.order.common.OrderStatus; 12 import com.yohoufo.order.common.OrderStatus;
12 import com.yohoufo.order.common.SellerOrderStatus; 13 import com.yohoufo.order.common.SellerOrderStatus;
13 import com.yohoufo.order.event.OrderCancelEvent; 14 import com.yohoufo.order.event.OrderCancelEvent;
  15 +import com.yohoufo.order.model.request.PaymentRequest;
14 import com.yohoufo.order.mq.TopicConstants; 16 import com.yohoufo.order.mq.TopicConstants;
15 import com.yohoufo.order.mq.producer.TradeMqSender; 17 import com.yohoufo.order.mq.producer.TradeMqSender;
  18 +import com.yohoufo.order.service.IPaymentService;
16 import com.yohoufo.order.service.impl.visitor.AutoCancelCase; 19 import com.yohoufo.order.service.impl.visitor.AutoCancelCase;
17 import com.yohoufo.order.service.impl.visitor.OffShelveCancelCase; 20 import com.yohoufo.order.service.impl.visitor.OffShelveCancelCase;
18 import com.yohoufo.order.service.impl.visitor.UserCancelCase; 21 import com.yohoufo.order.service.impl.visitor.UserCancelCase;
@@ -25,6 +28,7 @@ import java.util.Arrays; @@ -25,6 +28,7 @@ import java.util.Arrays;
25 import java.util.List; 28 import java.util.List;
26 import java.util.Objects; 29 import java.util.Objects;
27 import java.util.Optional; 30 import java.util.Optional;
  31 +import java.util.stream.Collectors;
28 32
29 /** 33 /**
30 * Created by chenchao on 2018/9/17. 34 * Created by chenchao on 2018/9/17.
@@ -43,18 +47,10 @@ public class SellerOrderCancelService { @@ -43,18 +47,10 @@ public class SellerOrderCancelService {
43 @Autowired 47 @Autowired
44 private TradeMqSender tradeMqSender; 48 private TradeMqSender tradeMqSender;
45 49
46 - public boolean cancel(SellerOrderCancelReq req){  
47 - logger.info("seller self cancel order,req {}", req);  
48 - int uid = req.getUid();  
49 - long orderCode = req.getOrderCode(); 50 + @Autowired
  51 + private IPaymentService paymentService;
50 52
51 - if (uid <= 0 || orderCode <= 0L){  
52 - throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);  
53 - }  
54 53
55 - int result = doCancel(uid, orderCode);  
56 - return result > 0;  
57 - }  
58 54
59 public void cancel(UserCancelCase cancelCase){ 55 public void cancel(UserCancelCase cancelCase){
60 logger.info("in cancel UserCancelCase {}", cancelCase); 56 logger.info("in cancel UserCancelCase {}", cancelCase);
@@ -64,10 +60,8 @@ public class SellerOrderCancelService { @@ -64,10 +60,8 @@ public class SellerOrderCancelService {
64 60
65 //未支付时 61 //未支付时
66 //支付完成,没有买家下单 62 //支付完成,没有买家下单
67 -  
68 -  
69 -  
70 //支付完成,有买家下单 63 //支付完成,有买家下单
  64 + doCancel(uid, orderCode);
71 } 65 }
72 66
73 67
@@ -80,32 +74,92 @@ public class SellerOrderCancelService { @@ -80,32 +74,92 @@ public class SellerOrderCancelService {
80 if (Objects.isNull(status)){ 74 if (Objects.isNull(status)){
81 return result; 75 return result;
82 } 76 }
83 - Integer targetStatus = null; 77 + //target seller Order Status
  78 + Integer targetSOStatus;
  79 + //未支付时
  80 +
84 if (SellerOrderStatus.WAITING_PAY.getCode() == status){ 81 if (SellerOrderStatus.WAITING_PAY.getCode() == status){
85 - targetStatus = SellerOrderStatus.SELf_CANCEL_PAY.getCode(); 82 + targetSOStatus = SellerOrderStatus.SELf_CANCEL_PAY.getCode();
  83 + doCancelBeforeBuyAction(uid, orderCode, targetSOStatus);
86 } 84 }
87 85
  86 +
88 if (SellerOrderStatus.HAS_PAYED.getCode() == status){ 87 if (SellerOrderStatus.HAS_PAYED.getCode() == status){
89 - List<Integer> sellerCanCancelStatus = Arrays.asList(OrderStatus.HAS_PAYED.getCode());  
90 - buyerOrderMapper.selectCntBySellerUidStatus(uid, sellerCanCancelStatus); 88 + doCancelAfterBuyAction(uid, orderCode);
  89 + }
91 90
92 - targetStatus = SellerOrderStatus.SELf_CANCEL_PAY.getCode(); 91 + return result;
93 } 92 }
94 93
95 - if (Objects.nonNull(targetStatus)){ 94 + private int doCancelBeforeBuyAction(int uid, long orderCode, Integer targetSOStatus){
96 SellerOrder target = new SellerOrder(); 95 SellerOrder target = new SellerOrder();
97 target.setOrderCode(orderCode); 96 target.setOrderCode(orderCode);
98 target.setUid(uid); 97 target.setUid(uid);
99 - target.setStatus(targetStatus);  
100 - target.setUpdateTime(DateUtil.getCurrentTimeSecond());  
101 - result = sellerOrderMapper.updateByOrderCode(target); 98 + target.setStatus(targetSOStatus);
  99 + return doCancelBeforeBuyAction(target);
102 } 100 }
103 101
104 102
  103 + private int doCancelBeforeBuyAction(SellerOrder target){
  104 + int result = 0;
  105 + int uid = target.getUid();
  106 + long orderCode = target.getOrderCode();
  107 + Integer targetSOStatus = target.getStatus();
  108 +
  109 + //update seller order
  110 + if (Objects.nonNull(targetSOStatus)){
105 111
  112 + target.setUpdateTime(DateUtil.getCurrentTimeSecond());
  113 + result += sellerOrderMapper.updateByOrderCode(target);
  114 + //refund earnestMoney
  115 + double earnestMoney = target.getEarnestMoney().doubleValue();
  116 + PaymentRequest refundReq = PaymentRequest.builder().uid(uid).orderCode(orderCode)
  117 + .refundAmount(earnestMoney).build();
  118 + paymentService.refund(refundReq);
  119 + }
  120 +
  121 + return result;
  122 + }
  123 +
  124 + private int doCancelAfterBuyAction(int sellerUid, long orderCode){
  125 + int result = 0;
  126 + List<Integer> sellerCanCancelStatus;
  127 + int canCancelCnt = 0;
  128 + //target Buyer Order Status
  129 + Integer targetBOStatus;
  130 +
  131 + //查询买家订单,状态是支付成功的
  132 + sellerCanCancelStatus = Arrays.asList(OrderStatus.HAS_PAYED.getCode());
  133 + canCancelCnt = buyerOrderMapper.selectCntBySellerUidStatus(sellerUid, sellerCanCancelStatus);
  134 + Integer targetSOStatus = SellerOrderStatus.SELF_CANCEL_COMPENSATE.getCode();
  135 + if (canCancelCnt == 0){
  136 + //支付完成,没有买家下单
  137 + result = doCancelBeforeBuyAction(sellerUid, orderCode, targetSOStatus);
106 return result; 138 return result;
107 } 139 }
  140 + targetBOStatus = OrderStatus.SELLER_CANCEL_AFTER_PAY.getCode();
108 141
  142 + List<BuyerOrder> buyerOrderList = buyerOrderMapper.selectListBySellerUidStatus(sellerUid, sellerCanCancelStatus, 0, canCancelCnt);
  143 + List<Long> orderCodes = buyerOrderList.parallelStream().map(BuyerOrder::getOrderCode).collect(Collectors.toList());
  144 +
  145 + if (orderCodes.size() > 1){
  146 + throw new ServiceException(ServiceError.ERP_ORDER_CANCEL_FAILED);
  147 + }
  148 + //actions of buyer order and related
  149 + //update buyer Order
  150 + result += buyerOrderMapper.updateBatchByOrderCodes(orderCodes, targetBOStatus, DateUtil.getCurrentTimeSecond());
  151 + //TODO 分赃(分账)
  152 +
  153 + SellerOrder target = new SellerOrder();
  154 + target.setOrderCode(orderCode);
  155 + target.setUid(sellerUid);
  156 + target.setStatus(targetSOStatus);
  157 + target.setUpdateTime(DateUtil.getCurrentTimeSecond());
  158 + result += sellerOrderMapper.updateByOrderCode(target);
  159 +
  160 + //TODO sync skup
  161 + return result;
  162 + }
109 163
110 164
111 public void cancel(AutoCancelCase autoCancelCase){ 165 public void cancel(AutoCancelCase autoCancelCase){
@@ -4,6 +4,7 @@ import com.yoho.core.dal.datasource.annotation.Database; @@ -4,6 +4,7 @@ import com.yoho.core.dal.datasource.annotation.Database;
4 import com.yohoufo.common.utils.DateUtil; 4 import com.yohoufo.common.utils.DateUtil;
5 import com.yohoufo.dal.order.SellerOrderMapper; 5 import com.yohoufo.dal.order.SellerOrderMapper;
6 import com.yohoufo.dal.order.model.SellerOrder; 6 import com.yohoufo.dal.order.model.SellerOrder;
  7 +import com.yohoufo.order.common.DelStatus;
7 import com.yohoufo.order.common.SellerOrderStatus; 8 import com.yohoufo.order.common.SellerOrderStatus;
8 import com.yohoufo.order.constants.SellerOrderCancelStatus; 9 import com.yohoufo.order.constants.SellerOrderCancelStatus;
9 import com.yohoufo.order.model.SellerOrderContext; 10 import com.yohoufo.order.model.SellerOrderContext;
@@ -29,7 +30,7 @@ public class SellerOrderCreateService { @@ -29,7 +30,7 @@ public class SellerOrderCreateService {
29 condition.setOrderCode(context.getOrderCode()); 30 condition.setOrderCode(context.getOrderCode());
30 condition.setUid(context.getUid()); 31 condition.setUid(context.getUid());
31 condition.setSkup(context.getSoldProduct().getSkup()); 32 condition.setSkup(context.getSoldProduct().getSkup());
32 - condition.setIsCancel(SellerOrderCancelStatus.NO.getCode()); 33 + condition.setIsDel(DelStatus.NOT_DEL.getCode());
33 condition.setCreateTime(currentTiem); 34 condition.setCreateTime(currentTiem);
34 condition.setStatus(SellerOrderStatus.WAITING_PAY.getCode()); 35 condition.setStatus(SellerOrderStatus.WAITING_PAY.getCode());
35 condition.setEarnestMoney(context.getSellerOrderComputeResult().getEarnestMoney()); 36 condition.setEarnestMoney(context.getSellerOrderComputeResult().getEarnestMoney());
1 package com.yohoufo.order.service.impl; 1 package com.yohoufo.order.service.impl;
2 2
  3 +import com.yoho.error.ServiceError;
  4 +import com.yoho.error.exception.ServiceException;
3 import com.yoho.service.model.response.UserAddressRspBO; 5 import com.yoho.service.model.response.UserAddressRspBO;
4 import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo; 6 import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo;
  7 +import com.yohobuy.ufo.model.order.req.SellerOrderCancelReq;
5 import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq; 8 import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq;
6 import com.yohobuy.ufo.model.order.req.SellerOrderSubmitReq; 9 import com.yohobuy.ufo.model.order.req.SellerOrderSubmitReq;
7 import com.yohobuy.ufo.model.order.resp.PageResp; 10 import com.yohobuy.ufo.model.order.resp.PageResp;
8 import com.yohoufo.common.exception.GatewayException; 11 import com.yohoufo.common.exception.GatewayException;
  12 +import com.yohoufo.common.utils.DateUtil;
  13 +import com.yohoufo.dal.order.BuyerOrderMapper;
9 import com.yohoufo.dal.order.SellerOrderMapper; 14 import com.yohoufo.dal.order.SellerOrderMapper;
10 -import com.yohoufo.order.common.CancelType;  
11 -import com.yohoufo.order.common.OrderCodeType;  
12 -import com.yohoufo.order.common.SkupStatus;  
13 -import com.yohoufo.order.common.TabType; 15 +import com.yohoufo.dal.order.model.BuyerOrder;
  16 +import com.yohoufo.dal.order.model.SellerOrder;
  17 +import com.yohoufo.order.common.*;
14 import com.yohoufo.order.convert.AddressInfoConvertor; 18 import com.yohoufo.order.convert.AddressInfoConvertor;
15 import com.yohoufo.order.convert.SellerOrderConvertor; 19 import com.yohoufo.order.convert.SellerOrderConvertor;
16 import com.yohoufo.order.event.EventHandlerContainer; 20 import com.yohoufo.order.event.EventHandlerContainer;
@@ -27,9 +31,11 @@ import com.yohoufo.order.service.IOrderDetailService; @@ -27,9 +31,11 @@ import com.yohoufo.order.service.IOrderDetailService;
27 import com.yohoufo.order.service.IOrderListService; 31 import com.yohoufo.order.service.IOrderListService;
28 import com.yohoufo.order.service.handler.SellerOrderComputeHandler; 32 import com.yohoufo.order.service.handler.SellerOrderComputeHandler;
29 import com.yohoufo.order.service.handler.SellerOrderSubmitHandler; 33 import com.yohoufo.order.service.handler.SellerOrderSubmitHandler;
  34 +import com.yohoufo.order.service.impl.visitor.UserCancelCase;
30 import com.yohoufo.order.service.proxy.ProductProxyService; 35 import com.yohoufo.order.service.proxy.ProductProxyService;
31 import com.yohoufo.order.service.proxy.UserProxyService; 36 import com.yohoufo.order.service.proxy.UserProxyService;
32 import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator; 37 import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
  38 +import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
33 import com.yohoufo.product.model.GoodsSize; 39 import com.yohoufo.product.model.GoodsSize;
34 import com.yohoufo.product.response.StorageDataResp; 40 import com.yohoufo.product.response.StorageDataResp;
35 import lombok.extern.slf4j.Slf4j; 41 import lombok.extern.slf4j.Slf4j;
@@ -51,7 +57,6 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -51,7 +57,6 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
51 private SellerOrderMapper sellerOrderMapper; 57 private SellerOrderMapper sellerOrderMapper;
52 58
53 59
54 -  
55 @Autowired 60 @Autowired
56 private SellerOrderComputeHandler computeHandler; 61 private SellerOrderComputeHandler computeHandler;
57 62
@@ -78,6 +83,14 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -78,6 +83,14 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
78 private EventHandlerContainer eventHandlerContainer; 83 private EventHandlerContainer eventHandlerContainer;
79 84
80 85
  86 + @Autowired
  87 + private SellerOrderCancelService sellerOrderCancelService;
  88 +
  89 +
  90 + @Autowired
  91 + private BuyerOrderMapper buyerOrderMapper;
  92 +
  93 +
81 public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) throws GatewayException { 94 public SoldPrdComputeBo computePublishPrd(SellerOrderComputeReq req) throws GatewayException {
82 log.info("in computePublishPrd, req {}", req); 95 log.info("in computePublishPrd, req {}", req);
83 96
@@ -175,6 +188,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -175,6 +188,7 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
175 } 188 }
176 189
177 190
  191 +
178 private GoodsInfo getProductDetail(SellerOrderContext context){ 192 private GoodsInfo getProductDetail(SellerOrderContext context){
179 int uid = context.getUid(); 193 int uid = context.getUid();
180 int storageId = context.getStorageId(); 194 int storageId = context.getStorageId();
@@ -259,6 +273,73 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi @@ -259,6 +273,73 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
259 273
260 } 274 }
261 275
  276 +
  277 +
  278 + public boolean cancel(SellerOrderCancelReq req){
  279 + log.info("seller self cancel order,req {}", req);
  280 + int uid = req.getUid();
  281 + long orderCode = req.getOrderCode();
  282 +
  283 + if (uid <= 0 || orderCode <= 0L){
  284 + throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
  285 + }
  286 +
  287 + OrderCancelEvent event = OrderCancelEvent.builder().uid(uid)
  288 + .orderCode(orderCode).actorType(TabType.SELL).build();
  289 + UserCancelCase userCancelCase = new UserCancelCase(event);
  290 + userCancelCase.accept(sellerOrderCancelService);
  291 + return true;
  292 + }
  293 +
  294 +
  295 +
  296 + public boolean delete(SellerOrderCancelReq req){
  297 + log.info("seller self cancel order,req {}", req);
  298 + int uid = req.getUid();
  299 + long orderCode = req.getOrderCode();
  300 +
  301 + if (uid <= 0 || orderCode <= 0L){
  302 + throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
  303 + }
  304 + //根据ordercode区分卖家 买家
  305 +
  306 + CodeMeta codeMeta = orderCodeGenerator.expId(orderCode);
  307 + if (Objects.isNull(codeMeta)){
  308 + log.warn("seller delete orderCode illegal, req {}", req);
  309 + throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
  310 + }
  311 +
  312 + if(OrderCodeType.SELLER_TYPE.getType() == codeMeta.getType()){
  313 + SellerOrder sellerOrder = sellerOrderMapper.selectByOrderCodeUid(orderCode, uid);
  314 +
  315 + //todo 判断状态后更新
  316 + SellerOrder target = new SellerOrder();
  317 + target.setId(sellerOrder.getId());
  318 + target.setIsDel(DelStatus.IS_DEL.getCode());
  319 + target.setUpdateTime(DateUtil.getCurrentTimeSecond());
  320 + int row = sellerOrderMapper.updateByPrimaryKeySelective(target);
  321 + return row > 0;
  322 + }
  323 +
  324 +
  325 + if(OrderCodeType.BUYER_TYPE.getType() == codeMeta.getType()){
  326 + BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
  327 + //todo 判断状态后更新
  328 +
  329 + BuyerOrder target = new BuyerOrder();
  330 + target.setId(buyerOrder.getId());
  331 + target.setSellerOrderStatus(DelStatus.IS_DEL.getCode());
  332 + target.setUpdateTime(DateUtil.getCurrentTimeSecond());
  333 + buyerOrderMapper.updateByPrimaryKeySelective(target);
  334 + }
  335 +
  336 +
  337 +
  338 +
  339 +
  340 + return true;
  341 + }
  342 +
262 /** 343 /**
263 * 查物流详情 344 * 查物流详情
264 * 只查卖家自己填的物流单 345 * 只查卖家自己填的物流单
@@ -8,10 +8,7 @@ import com.yohoufo.common.ApiResponse; @@ -8,10 +8,7 @@ import com.yohoufo.common.ApiResponse;
8 import com.yohoufo.common.caller.UfoServiceCaller; 8 import com.yohoufo.common.caller.UfoServiceCaller;
9 import com.yohoufo.dal.order.*; 9 import com.yohoufo.dal.order.*;
10 import com.yohoufo.dal.order.model.*; 10 import com.yohoufo.dal.order.model.*;
11 -import com.yohoufo.order.common.ClientType;  
12 -import com.yohoufo.order.common.OrderStatus;  
13 -import com.yohoufo.order.common.SellerOrderStatus;  
14 -import com.yohoufo.order.common.SkupStatus; 11 +import com.yohoufo.order.common.*;
15 import com.yohoufo.order.constants.MetaKey; 12 import com.yohoufo.order.constants.MetaKey;
16 import com.yohoufo.order.model.dto.OrderBuilder; 13 import com.yohoufo.order.model.dto.OrderBuilder;
17 import com.yohoufo.order.service.ISubmitOrderService; 14 import com.yohoufo.order.service.ISubmitOrderService;
@@ -165,6 +162,7 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService { @@ -165,6 +162,7 @@ public class SubmitOrderServiceImpl implements ISubmitOrderService {
165 buyerOrder.setCreateTime(now); 162 buyerOrder.setCreateTime(now);
166 buyerOrder.setUpdateTime(now); 163 buyerOrder.setUpdateTime(now);
167 buyerOrder.setStatus(OrderStatus.WAITING_PAY.getCode()); 164 buyerOrder.setStatus(OrderStatus.WAITING_PAY.getCode());
  165 + buyerOrder.setBuyerOrderStatus(DelStatus.NOT_DEL.getCode());
168 buyerOrderMapper.insert(buyerOrder); 166 buyerOrderMapper.insert(buyerOrder);
169 } 167 }
170 168
@@ -38,17 +38,17 @@ public class SellerOrderCancelHandler implements IEventHandler<OrderCancelEvent> @@ -38,17 +38,17 @@ public class SellerOrderCancelHandler implements IEventHandler<OrderCancelEvent>
38 switch (cancelType){ 38 switch (cancelType){
39 case SELF_BEFORE_PAY: 39 case SELF_BEFORE_PAY:
40 UserCancelCase ucCase = new UserCancelCase(event); 40 UserCancelCase ucCase = new UserCancelCase(event);
41 - sellerOrderCancelService.cancel(ucCase); 41 + ucCase.accept(sellerOrderCancelService);
42 break; 42 break;
43 43
44 case TIME_OUT: 44 case TIME_OUT:
45 AutoCancelCase autoCancelCase = new AutoCancelCase(event); 45 AutoCancelCase autoCancelCase = new AutoCancelCase(event);
46 - sellerOrderCancelService.cancel(autoCancelCase); 46 + autoCancelCase.accept(sellerOrderCancelService);
47 break; 47 break;
48 48
49 case ERP_OFFSHELVE: 49 case ERP_OFFSHELVE:
50 OffShelveCancelCase offShelveCancelCase = new OffShelveCancelCase(event); 50 OffShelveCancelCase offShelveCancelCase = new OffShelveCancelCase(event);
51 - sellerOrderCancelService.cancel(offShelveCancelCase); 51 + offShelveCancelCase.accept(sellerOrderCancelService);
52 break; 52 break;
53 } 53 }
54 54