提交 | 用户 | age
|
fd7281
|
1 |
package com.hx.phip.tool.refund; |
C |
2 |
|
160c33
|
3 |
import com.alibaba.fastjson.JSON; |
fd7281
|
4 |
import com.hx.common.service.CommonService; |
160c33
|
5 |
import com.hx.exception.TipsException; |
528195
|
6 |
import com.hx.mybatisTool.SqlSentence; |
160c33
|
7 |
import com.hx.phiappt.common.*; |
C |
8 |
import com.hx.phiappt.constants.enums.GroupTypeEnum; |
|
9 |
import com.hx.phiappt.constants.tool.RefundToolUtil; |
fd7281
|
10 |
import com.hx.phiappt.model.BaseEntity; |
C |
11 |
import com.hx.phiappt.model.activity.ActivityAction; |
|
12 |
import com.hx.phiappt.model.activity.ActivityRule; |
160c33
|
13 |
import com.hx.phiappt.model.cardItem.CardEquity; |
C |
14 |
import com.hx.phiappt.model.cardItem.CardItemInfo; |
|
15 |
import com.hx.phiappt.model.coupon.CouponNumber; |
|
16 |
import com.hx.phiappt.model.coupon.CouponOrderDiscountLog; |
|
17 |
import com.hx.phiappt.model.order.*; |
|
18 |
import com.hx.phiappt.model.refund.*; |
|
19 |
import com.hx.phiappt.model.user.UserCard; |
|
20 |
import com.hx.phiappt.model.user.UserCardUsed; |
|
21 |
import com.hx.phiappt.model.user.UserProjectItem; |
fd7281
|
22 |
import com.hx.phiappt.model.userMoney.UserMoneyUnclaimed; |
528195
|
23 |
import com.hx.phip.dao.mapper.*; |
160c33
|
24 |
import com.hx.phip.service.order.impl.OrderRefundServiceImpl; |
cfedbf
|
25 |
import com.hx.phip.tool.order.OrderTool; |
4ebb90
|
26 |
import com.hx.phip.tool.user.UserCardTool; |
160c33
|
27 |
import com.hx.phip.tool.user.UserProjectTool; |
fd7281
|
28 |
import com.hx.phip.util.api.UserMoneyUtil; |
e490fa
|
29 |
import com.hx.phip.vo.order.refund.RefundCarryVo; |
4ebb90
|
30 |
import com.hx.phip.vo.user.UserCardItemInfoVo; |
fd7281
|
31 |
import com.hx.util.StringUtils; |
C |
32 |
import com.platform.exception.PlatTipsException; |
|
33 |
import com.platform.resultTool.PlatformCode; |
160c33
|
34 |
import org.slf4j.Logger; |
C |
35 |
import org.slf4j.LoggerFactory; |
fd7281
|
36 |
|
C |
37 |
import java.math.BigDecimal; |
528195
|
38 |
import java.util.HashMap; |
fd7281
|
39 |
import java.util.List; |
528195
|
40 |
import java.util.Map; |
160c33
|
41 |
import java.util.stream.Collectors; |
fd7281
|
42 |
|
C |
43 |
/** |
|
44 |
* 订单退款单作废工具 |
160c33
|
45 |
* @author CJH |
fd7281
|
46 |
*/ |
C |
47 |
public class OrderRefundCancelTool { |
|
48 |
|
160c33
|
49 |
/**log4j日志*/ |
C |
50 |
private static final Logger logger = LoggerFactory.getLogger(OrderRefundServiceImpl.class.getName()); |
|
51 |
|
4ebb90
|
52 |
/**操作类型-0退款执行*/ |
C |
53 |
public static final int OPT_TYPE_EXECUTE = 0; |
|
54 |
/**操作类型—1作废退款*/ |
|
55 |
public static final int OPT_TYPE_CANCEL = 1; |
|
56 |
|
245f89
|
57 |
public static final String REFUND_REMARK = "订单退款"; |
C |
58 |
|
160c33
|
59 |
|
C |
60 |
/**处理总退款方式数据*/ |
b3fdea
|
61 |
public static List<RefundRecordMethod> refundRecordMotnedHandle(RefundRecord refundRecord,OrdersTotal ordersTotal,StringBuilder orderNodeBuilder,CommonService commonService){ |
160c33
|
62 |
SqlSentence sqlSentence = new SqlSentence(); |
C |
63 |
Map<String,Object> values = new HashMap<>(); |
|
64 |
|
|
65 |
//获取总退款方式 |
|
66 |
values.put("refundRecordId",refundRecord.getId()); |
|
67 |
sqlSentence.sqlSentence("SELECT * FROM refund_record_method WHERE isDel = 0 AND refundRecordId = #{m.refundRecordId}",values); |
|
68 |
List<RefundRecordMethod> refundRecordMethodList = commonService.selectList(RefundRecordMethodMapper.class,sqlSentence); |
a9c1ab
|
69 |
//退款的支付方式记录数据,总的 |
160c33
|
70 |
values.clear(); |
C |
71 |
values.put("refundRecordId",refundRecord.getId()); |
a9c1ab
|
72 |
sqlSentence.sqlSentence("SELECT * FROM refund_record_consume_pay WHERE isDel = 0 AND refundRecordId = #{m.refundRecordId} AND refundRecordItemId IS NULL",values); |
160c33
|
73 |
List<RefundRecordConsumePay> refundConsumePayList = commonService.selectList(RefundRecordConsumePayMapper.class,sqlSentence); |
C |
74 |
|
|
75 |
for(RefundRecordConsumePay refundRecordConsumePay:refundConsumePayList){ |
|
76 |
//更新支付记录退款信息 |
|
77 |
values.clear(); |
|
78 |
values.put("refundTotal",refundRecordConsumePay.getRefundTotal().negate()); |
|
79 |
values.put("id",refundRecordConsumePay.getConsumePayId()); |
4ebb90
|
80 |
sqlSentence.sqlUpdate("refundTotal = refundTotal + #{m.refundTotal} WHERE id = #{m.id} AND refundTotal + #{m.refundTotal} >= 0",values); |
160c33
|
81 |
if(commonService.updateWhere(ConsumePayMapper.class,sqlSentence) != 1){ |
C |
82 |
throw new TipsException("退款金额错误[33]!"); |
|
83 |
} |
|
84 |
|
|
85 |
//更新支付记录退款信息 |
|
86 |
values.clear(); |
|
87 |
values.put("status",RefundRecordConsumePay.NO); |
|
88 |
values.put("statusOld",RefundRecordConsumePay.YES); |
|
89 |
values.put("id",refundRecordConsumePay.getId()); |
01fbcb
|
90 |
sqlSentence.sqlUpdate("status = #{m.status} WHERE id = #{m.id} AND status = #{m.statusOld}",values); |
160c33
|
91 |
if(commonService.updateWhere(RefundRecordConsumePayMapper.class,sqlSentence) != 1){ |
C |
92 |
throw new TipsException("退款金额记录状态错误!"); |
|
93 |
} |
|
94 |
|
|
95 |
} |
|
96 |
|
b3fdea
|
97 |
//处理扣减账号资金 |
160c33
|
98 |
for(RefundRecordMethod refundRecordMethod:refundRecordMethodList){ |
C |
99 |
if(PayMethodTypeConstants.PAY_STORED.equals(refundRecordMethod.getRefundNumberNo())){ |
|
100 |
//储值金额 |
|
101 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
|
102 |
if(refundRecordMethod.getActualTotal().compareTo(BigDecimal.ZERO)>0){ |
|
103 |
UserMoneyUtil.setNewUserMoneyUnclaimed(ordersTotal.getPayUserId()==null?ordersTotal.getUserId():ordersTotal.getPayUserId(),refundRecord.getInvalidRemarks(),"作废退款:支付方式储值金额扣减",refundRecord.getInvalidId(),refundRecord.getOrderId(),refundRecord.getInvalidAppCode(),refundRecord.getId(),refundRecordMethod.getRealRefundTotal().negate(), UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.NO); |
|
104 |
OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord, refundRecord.getInvalidId(), refundRecord.getInvalidName(), refundRecordMethod.getName()+"作废退款金额:"+refundRecordMethod.getRealRefundTotal(), 1, OrderLogConstants.LOG_TYPE_REFUND_UNDO); |
|
105 |
commonService.insert(OrderLogMapper.class,orderLog); |
b3fdea
|
106 |
if(orderNodeBuilder != null){ |
C |
107 |
orderNodeBuilder.append("-[作废退款]扣减退款金额(储值金):").append(refundRecordMethod.getRealRefundTotal()); |
|
108 |
} |
160c33
|
109 |
} |
C |
110 |
}else if(PayMethodTypeConstants.PAY_ADD_FUND.equals(refundRecordMethod.getRefundNumberNo())){ |
|
111 |
//增值金 |
|
112 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
|
113 |
if(refundRecordMethod.getActualTotal().compareTo(BigDecimal.ZERO)!=0){ |
|
114 |
UserMoneyUtil.setNewUserMoneyUnclaimed(ordersTotal.getPayUserId()==null?ordersTotal.getUserId():ordersTotal.getPayUserId(),refundRecord.getRemarks(),"作废退款:支付方式增值金退回",refundRecord.getInvalidId(),refundRecord.getOrderId(),refundRecord.getInvalidAppCode(),refundRecord.getId(),refundRecordMethod.getRealRefundTotal().negate(), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.NO); |
|
115 |
OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,refundRecord.getInvalidId(),refundRecord.getInvalidName(),refundRecordMethod.getName(),1, OrderLogConstants.LOG_TYPE_REFUND_UNDO); |
|
116 |
commonService.insert(OrderLogMapper.class,orderLog); |
b3fdea
|
117 |
if(orderNodeBuilder != null){ |
C |
118 |
orderNodeBuilder.append("-[作废退款]扣减退款金额(增值金):").append(refundRecordMethod.getRealRefundTotal()); |
|
119 |
} |
160c33
|
120 |
} |
C |
121 |
}else if(PayMethodTypeConstants.PAY_INTEGRAL.equals(refundRecordMethod.getRefundNumberNo())){ |
|
122 |
//积分 |
|
123 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
|
124 |
if(refundRecordMethod.getActualTotal().compareTo(BigDecimal.ZERO)!=0){ |
|
125 |
UserMoneyUtil.setNewUserMoneyUnclaimed(ordersTotal.getPayUserId()==null?ordersTotal.getUserId():ordersTotal.getPayUserId(),refundRecord.getRemarks(),"作废退款:支付方式积分退回",refundRecord.getInvalidId(),refundRecord.getOrderId(),refundRecord.getInvalidAppCode(),refundRecord.getId(),refundRecordMethod.getRealRefundTotal().negate(), UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.NO); |
|
126 |
OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,refundRecord.getInvalidId(),refundRecord.getInvalidName(),refundRecordMethod.getName()+"作废退款金额:"+refundRecordMethod.getRealRefundTotal(),1, OrderLogConstants.LOG_TYPE_REFUND_UNDO); |
|
127 |
commonService.insert(OrderLogMapper.class,orderLog); |
b3fdea
|
128 |
if(orderNodeBuilder != null){ |
C |
129 |
orderNodeBuilder.append("-[作废退款]扣减退款金额(积分):").append(refundRecordMethod.getRealRefundTotal()); |
|
130 |
} |
160c33
|
131 |
} |
C |
132 |
}else { |
|
133 |
//现金支付 |
|
134 |
if(refundRecordMethod.getActualTotal().compareTo(BigDecimal.ZERO)<1){ |
|
135 |
continue; |
|
136 |
} |
|
137 |
OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,refundRecord.getInvalidId(),refundRecord.getInvalidName(),refundRecordMethod.getName()+"作废退款金额:"+refundRecordMethod.getRealRefundTotal(),1, OrderLogConstants.LOG_TYPE_REFUND_UNDO); |
|
138 |
orderLog.setOrderId(ordersTotal.getId()); |
|
139 |
commonService.insert(OrderLogMapper.class,orderLog); |
|
140 |
} |
|
141 |
} |
b3fdea
|
142 |
return refundRecordMethodList; |
160c33
|
143 |
} |
C |
144 |
|
|
145 |
/**充值单特需处理 |
|
146 |
* @param ordersTotal 订单 |
|
147 |
* @param refundRecord 退款单 |
|
148 |
* @param optType 操作类型:0退款执行,1作废退款 |
f5e288
|
149 |
* @param optName 操作名称,如:申请退款、作废退款、审核拒绝 |
160c33
|
150 |
* @param commonService 映射 |
C |
151 |
*/ |
b3fdea
|
152 |
public static void rechargeHandle(OrdersTotal ordersTotal, RefundRecord refundRecord,int optType,String optName,StringBuilder orderNodeBuilder, CommonService commonService){ |
755975
|
153 |
|
fd7281
|
154 |
if(!OrderTotalConstants.TYPE_RECHARGE.equals(ordersTotal.getType())){ |
C |
155 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"操作失败,不是充值单!"); |
|
156 |
} |
|
157 |
if(ordersTotal.getTotal().compareTo(BigDecimal.ZERO) < 1){ |
|
158 |
return; |
|
159 |
} |
4ebb90
|
160 |
OrderLog orderLog; |
C |
161 |
if(optType == OPT_TYPE_EXECUTE){ |
160c33
|
162 |
//充值金额扣减 |
bfdc6b
|
163 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),REFUND_REMARK+"["+ordersTotal.getOrderNo()+"]","退款单:"+refundRecord.getCode()+";"+optName+",扣减充值资金:"+ordersTotal.getTotal(),refundRecord.getOperatorId(),refundRecord.getOrderId(),refundRecord.getInvalidAppCode(),refundRecord.getId(),ordersTotal.getTotal().negate(), UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.NO); |
f5e288
|
164 |
orderLog = RefundToolUtil.setOrderLog(refundRecord, refundRecord.getOperatorId(), refundRecord.getOperatorName(), "充值单:"+ordersTotal.getOrderNo()+";"+optName+",预扣除金额:"+ordersTotal.getTotal(), 0, OrderLogConstants.LOG_TYPE_REFUND); |
b3fdea
|
165 |
|
4ebb90
|
166 |
}else if(optType == OPT_TYPE_CANCEL){ |
160c33
|
167 |
//充值金额回退 |
245f89
|
168 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),REFUND_REMARK+"["+ordersTotal.getOrderNo()+"]","退款单:"+refundRecord.getCode()+";"+optName+",退回充值资金:"+ordersTotal.getTotal(),refundRecord.getInvalidId(),refundRecord.getOrderId(),refundRecord.getInvalidAppCode(),refundRecord.getId(),ordersTotal.getTotal(), UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND, OperationReasonConstants.OP_REASON_REFUND_CANCEL,commonService,UserMoneyUnclaimed.NO); |
f5e288
|
169 |
orderLog = RefundToolUtil.setOrderLog(refundRecord, refundRecord.getOperatorId(), refundRecord.getOperatorName(), "充值单:"+ordersTotal.getOrderNo()+";"+optName+",退回预扣除金额:"+ordersTotal.getTotal(), 0, OrderLogConstants.LOG_TYPE_REFUND); |
160c33
|
170 |
}else{ |
C |
171 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"操作类型错误[1]["+optType+"]!"); |
b3fdea
|
172 |
} |
C |
173 |
if(orderNodeBuilder !=null){ |
|
174 |
orderNodeBuilder.append("-[").append(optName).append("]充值单充值金操作(储值金):").append(ordersTotal.getTotal()); |
160c33
|
175 |
} |
4ebb90
|
176 |
orderLog.setOrderId(ordersTotal.getId()); |
C |
177 |
commonService.insert(OrderLogMapper.class,orderLog); |
fd7281
|
178 |
} |
C |
179 |
|
160c33
|
180 |
/**活动规则处理 |
C |
181 |
* @param ordersTotal 订单 |
|
182 |
* @param refundRecord 退款单 |
|
183 |
* @param optType 操作类型:0退款执行,1作废退款 |
f5e288
|
184 |
* @param optName 操作名称,如:申请退款、作废退款、审核拒绝 |
160c33
|
185 |
* @param commonService 映射 |
C |
186 |
*/ |
b3fdea
|
187 |
public static void activityRuleHandle(OrdersTotal ordersTotal, RefundRecord refundRecord,int optType,String optName,StringBuilder orderNodeBuilder,CommonService commonService){ |
fd7281
|
188 |
|
528195
|
189 |
//先获取活动规则 |
C |
190 |
SqlSentence sqlSentence = new SqlSentence(); |
|
191 |
Map<String,Object> values = new HashMap<>(); |
|
192 |
|
|
193 |
values.put("orderId",ordersTotal.getId()); |
|
194 |
sqlSentence.sqlSentence("SELECT * FROM orders_activity_info WHERE isDel = 0 AND orderId = #{m.orderId}",values); |
|
195 |
List<OrdersActivityInfo> ordersActivityInfoList = commonService.selectList(OrdersActivityInfoMapper.class,sqlSentence); |
|
196 |
if(ordersActivityInfoList.size() > 0){ |
160c33
|
197 |
//订单活动信息处理 |
b3fdea
|
198 |
activityRulePollingHandle2(ordersActivityInfoList,optType,optName,ordersTotal,refundRecord,orderNodeBuilder,commonService); |
528195
|
199 |
}else{ |
160c33
|
200 |
//没有订单活动信息处理,就获取保存在订单里面的活动标识 |
C |
201 |
values.clear(); |
|
202 |
values.put("orderId",ordersTotal.getId()); |
528195
|
203 |
sqlSentence.sqlSentence("SELECT * FROM orders_info WHERE isDel = 0 AND orderId = #{m.orderId}",values); |
C |
204 |
OrderInfo orderInfo = commonService.selectOne(OrderInfoMapper.class,sqlSentence); |
160c33
|
205 |
if(orderInfo!=null && StringUtils.noNull(orderInfo.getActivityId())){ |
b3fdea
|
206 |
activityRulePollingHandle1(orderInfo.getActivityId(),optType,optName,ordersTotal,refundRecord,orderNodeBuilder,commonService); |
160c33
|
207 |
} |
C |
208 |
} |
|
209 |
} |
528195
|
210 |
|
160c33
|
211 |
/**处理活动标识保存在订单里面的 |
C |
212 |
* @param activityId 活动标识 |
|
213 |
* @param optType 操作类型:0退款执行,1退款作废 |
f5e288
|
214 |
* @param optName 操作名称,如:申请退款、作废退款、审核拒绝 |
160c33
|
215 |
* @param ordersTotal 订单 |
C |
216 |
* @param refundRecord 退款单 |
|
217 |
* @param commonService 映射 |
|
218 |
*/ |
b3fdea
|
219 |
public static void activityRulePollingHandle1(String activityId,int optType,String optName,OrdersTotal ordersTotal,RefundRecord refundRecord |
C |
220 |
,StringBuilder orderNodeBuilder,CommonService commonService){ |
160c33
|
221 |
SqlSentence sqlSentence = new SqlSentence(); |
C |
222 |
Map<String,Object> values = new HashMap<>(); |
|
223 |
|
|
224 |
//查找活动规则,没有找到就跳出循环 |
|
225 |
ActivityRule activityRule = commonService.selectOneByKeyBlob(ActivityRuleMapper.class,activityId); |
|
226 |
if(activityRule == null){ |
|
227 |
return; |
528195
|
228 |
} |
C |
229 |
|
160c33
|
230 |
values.put("activityRuleId",activityRule.getId()); |
C |
231 |
values.put("type", ActivityAction.TYPE_INTEGRAL); |
|
232 |
values.put("type1",ActivityAction.TYPE_VALUEADDEDFUND); |
|
233 |
values.put("type2",ActivityAction.TYPE_COUPON); |
|
234 |
sqlSentence.sqlSentence("select * from activity_action where activityRuleId=#{m.activityRuleId} and (type=#{m.type} or type=#{m.type1} or type=#{m.type2}) and isDel=0",values); |
|
235 |
List<ActivityAction> activityActions = commonService.selectList(ActivityActionMapper.class, sqlSentence); |
|
236 |
if(activityActions!=null && activityActions.size()>0){ |
|
237 |
for (ActivityAction activityAction : activityActions) { |
|
238 |
if(ActivityAction.TYPE_INTEGRAL.equals(activityAction.getType())){ |
|
239 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
|
240 |
if(new BigDecimal(activityAction.getWorth()).compareTo(BigDecimal.ZERO) == 0){ |
|
241 |
continue; |
|
242 |
} |
4ebb90
|
243 |
if(optType == OPT_TYPE_EXECUTE){ |
f5e288
|
244 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"订单:"+ordersTotal.getOrderNo()+";"+optName+",预扣除活动规则赠送储值金金额:"+activityAction.getWorth(),refundRecord.getOperatorId(),refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),new BigDecimal(activityAction.getWorth()).negate(), UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES); |
4ebb90
|
245 |
}else if(optType == OPT_TYPE_CANCEL){ |
bfdc6b
|
246 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"订单:"+ordersTotal.getOrderNo()+";"+optName+",返还赠送储值金预扣除金额:"+activityAction.getWorth(),refundRecord.getInvalidId(),refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),new BigDecimal(activityAction.getWorth()), UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_REFUND_CANCEL,commonService,UserMoneyUnclaimed.YES); |
160c33
|
247 |
}else{ |
C |
248 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"操作类型错误[2]["+optType+"]!"); |
|
249 |
} |
b3fdea
|
250 |
if(orderNodeBuilder !=null){ |
C |
251 |
orderNodeBuilder.append("-[").append(optName).append("]处理活动赠送(积分):").append(activityAction.getWorth()); |
|
252 |
} |
160c33
|
253 |
}else if(ActivityAction.TYPE_VALUEADDEDFUND.equals(activityAction.getType())){ |
C |
254 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
755975
|
255 |
if(new BigDecimal(activityAction.getWorth()).compareTo(BigDecimal.ZERO) == 0 ){ |
160c33
|
256 |
continue; |
C |
257 |
} |
4ebb90
|
258 |
if(optType == OPT_TYPE_EXECUTE){ |
f5e288
|
259 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"订单:"+ordersTotal.getOrderNo()+";"+optName+",预扣除活动规则赠送增值金金额:"+activityAction.getWorth(),refundRecord.getOperatorId(),refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),new BigDecimal(activityAction.getWorth()).negate(), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES); |
4ebb90
|
260 |
}else if(optType == OPT_TYPE_CANCEL){ |
bfdc6b
|
261 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"订单:"+ordersTotal.getOrderNo()+";"+optName+",返还赠送增值金预扣除金额:"+activityAction.getWorth(),refundRecord.getInvalidId(),refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),new BigDecimal(activityAction.getWorth()), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND,OperationReasonConstants.OP_REASON_REFUND_CANCEL,commonService,UserMoneyUnclaimed.YES); |
160c33
|
262 |
}else{ |
C |
263 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"操作类型错误[3]["+optType+"]!"); |
|
264 |
} |
b3fdea
|
265 |
if(orderNodeBuilder !=null){ |
C |
266 |
orderNodeBuilder.append("-[").append(optName).append("]处理活动赠送(增值金):").append(activityAction.getWorth()); |
|
267 |
} |
160c33
|
268 |
}else if(ActivityAction.TYPE_COUPON.equals(activityAction.getType())){ |
4ebb90
|
269 |
values.put("oldValidState",optType==OPT_TYPE_EXECUTE? BaseEntity.YES:BaseEntity.NO); |
C |
270 |
values.put("newValidState",optType==OPT_TYPE_EXECUTE?BaseEntity.NO:BaseEntity.YES); |
160c33
|
271 |
values.put("couponId",activityAction.getCrmCouponId()); |
C |
272 |
values.put("commonId",ordersTotal.getId()); |
|
273 |
sqlSentence.sqlSentence(" validState=#{m.newValidState} where couponId=#{m.couponId} and commonId=#{m.commonId} and validState=#{m.oldValidState} ",values); |
b3fdea
|
274 |
if(commonService.updateWhere(CouponNumberMapper.class,sqlSentence) != 0){ |
C |
275 |
if(orderNodeBuilder !=null){ |
|
276 |
orderNodeBuilder.append("-[").append(optName).append("]处理活动赠送(优惠券):").append(activityAction.getWorthName()); |
|
277 |
} |
|
278 |
} |
160c33
|
279 |
} |
C |
280 |
} |
|
281 |
} |
|
282 |
} |
fd7281
|
283 |
|
160c33
|
284 |
/**处理活动保存在订单活动信息里面的 |
C |
285 |
* @param ordersActivityInfoList 订单活动数据 |
|
286 |
* @param optType 操作类型:0退款退回,1作废退款 |
f5e288
|
287 |
* @param optName 操作名称,如:申请退款、作废退款、审核拒绝 |
160c33
|
288 |
* @param ordersTotal 订单 |
C |
289 |
* @param refundRecord 退款单 |
|
290 |
* @param commonService 映射 |
|
291 |
*/ |
f5e288
|
292 |
public static void activityRulePollingHandle2(List<OrdersActivityInfo> ordersActivityInfoList,int optType,String optName,OrdersTotal ordersTotal |
b3fdea
|
293 |
,RefundRecord refundRecord,StringBuilder orderNodeBuilder,CommonService commonService){ |
160c33
|
294 |
if(ordersActivityInfoList == null || ordersActivityInfoList.size()==0){ |
C |
295 |
return; |
|
296 |
} |
|
297 |
SqlSentence sqlSentence = new SqlSentence(); |
|
298 |
Map<String,Object> values = new HashMap<>(); |
|
299 |
|
b3fdea
|
300 |
//是否变更订单活动状态 |
C |
301 |
boolean changeStatus; |
160c33
|
302 |
//获取订单活动条目 |
C |
303 |
List<OrdersActivityInfoItem> ordersActivityInfoItemList; |
|
304 |
for(OrdersActivityInfo ordersActivityInfo:ordersActivityInfoList){ |
|
305 |
values.clear(); |
|
306 |
values.put("activityInfoId",ordersActivityInfo.getId()); |
|
307 |
values.put("performStatus",OrdersActivityInfoItem.STATUS_PERFORM_SEND_OUT); |
4ebb90
|
308 |
values.put("handleStatus",optType==OPT_TYPE_EXECUTE?OrdersActivityInfoItem.HANDLE_STATUS_SUCCESS:OrdersActivityInfoItem.HANDLE_STATUS_CANCEL); |
160c33
|
309 |
sqlSentence.sqlSentence("SELECT * FROM orders_activity_info_item WHERE isDel = 0 AND activityInfoId = #{m.activityInfoId} AND performStatus = #{m.performStatus} AND handleStatus = #{m.handleStatus}",values); |
C |
310 |
ordersActivityInfoItemList = commonService.selectList(OrdersActivityInfoItemMapper.class,sqlSentence); |
|
311 |
for(OrdersActivityInfoItem ordersActivityInfoItem:ordersActivityInfoItemList){ |
b3fdea
|
312 |
changeStatus = false; |
160c33
|
313 |
if(ActivityAction.TYPE_INTEGRAL.equals(ordersActivityInfoItem.getType())){ |
C |
314 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
|
315 |
if(new BigDecimal(ordersActivityInfoItem.getWorth()).compareTo(BigDecimal.ZERO) == 0){ |
|
316 |
continue; |
|
317 |
} |
4ebb90
|
318 |
if(optType == OPT_TYPE_EXECUTE){ |
f5e288
|
319 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"订单:"+ordersTotal.getOrderNo()+";"+optName+",预扣除活动规则赠送储值金金额:"+ordersActivityInfoItem.getWorth(),refundRecord.getOperatorId(),refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),new BigDecimal(ordersActivityInfoItem.getWorth()).negate(), UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES); |
4ebb90
|
320 |
}else if(optType == OPT_TYPE_CANCEL){ |
f5e288
|
321 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"订单:"+ordersTotal.getOrderNo()+";"+optName+",返还赠送储值金预扣除金额:"+ordersActivityInfoItem.getWorth(),refundRecord.getInvalidId(),refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),new BigDecimal(ordersActivityInfoItem.getWorth()), UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES); |
160c33
|
322 |
}else{ |
C |
323 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"操作类型错误[2]["+optType+"]!"); |
|
324 |
} |
b3fdea
|
325 |
if(orderNodeBuilder !=null){ |
C |
326 |
orderNodeBuilder.append("-[").append(optName).append("]处理活动赠送(积分):").append(ordersActivityInfoItem.getWorth()); |
|
327 |
} |
|
328 |
changeStatus = true; |
160c33
|
329 |
}else if(ActivityAction.TYPE_VALUEADDEDFUND.equals(ordersActivityInfoItem.getType())){ |
C |
330 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
755975
|
331 |
if(new BigDecimal(ordersActivityInfoItem.getWorth()).compareTo(BigDecimal.ZERO) == 0 ){ |
160c33
|
332 |
continue; |
C |
333 |
} |
4ebb90
|
334 |
if(optType == OPT_TYPE_EXECUTE){ |
f5e288
|
335 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"订单:"+ordersTotal.getOrderNo()+";"+optName+",预扣除活动规则赠送增值金金额:"+ordersActivityInfoItem.getWorth(),refundRecord.getOperatorId(),refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),new BigDecimal(ordersActivityInfoItem.getWorth()).negate(), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES); |
4ebb90
|
336 |
}else if(optType == OPT_TYPE_CANCEL){ |
f5e288
|
337 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"订单:"+ordersTotal.getOrderNo()+";"+optName+",返还赠送增值金预扣除金额:"+ordersActivityInfoItem.getWorth(),refundRecord.getInvalidId(),refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),new BigDecimal(ordersActivityInfoItem.getWorth()), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES); |
160c33
|
338 |
}else{ |
C |
339 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"操作类型错误[3]["+optType+"]!"); |
|
340 |
} |
b3fdea
|
341 |
if(orderNodeBuilder !=null){ |
C |
342 |
orderNodeBuilder.append("-[").append(optName).append("]处理活动赠送(增值金):").append(ordersActivityInfoItem.getWorth()); |
|
343 |
} |
|
344 |
changeStatus = true; |
160c33
|
345 |
}else if(ActivityAction.TYPE_COUPON.equals(ordersActivityInfoItem.getType())){ |
4ebb90
|
346 |
values.clear(); |
C |
347 |
values.put("oldValidState",optType==OPT_TYPE_EXECUTE? BaseEntity.YES:BaseEntity.NO); |
|
348 |
values.put("newValidState",optType==OPT_TYPE_EXECUTE?BaseEntity.NO:BaseEntity.YES); |
160c33
|
349 |
values.put("id",ordersActivityInfoItem.getCouponNumberId()); |
4ebb90
|
350 |
sqlSentence.sqlSentence(" validState=#{m.newValidState} where id=#{m.id} AND validState = #{m.oldValidState} ",values); |
160c33
|
351 |
//优惠券不判断回退 |
b3fdea
|
352 |
if(commonService.updateWhere(CouponNumberMapper.class,sqlSentence) != 0){ |
C |
353 |
if(orderNodeBuilder !=null){ |
|
354 |
orderNodeBuilder.append("-[").append(optName).append("]处理活动赠送(优惠券):").append(ordersActivityInfoItem.getWorthName()); |
|
355 |
} |
|
356 |
changeStatus = true; |
|
357 |
} |
160c33
|
358 |
} |
b3fdea
|
359 |
if(changeStatus){ |
C |
360 |
//更新订单活动信息状态 |
|
361 |
values.clear(); |
|
362 |
values.put("handleStatus",optType==OPT_TYPE_EXECUTE?OrdersActivityInfoItem.HANDLE_STATUS_CANCEL:OrdersActivityInfoItem.HANDLE_STATUS_SUCCESS); |
|
363 |
values.put("handleStatusOld",optType==OPT_TYPE_EXECUTE?OrdersActivityInfoItem.HANDLE_STATUS_SUCCESS:OrdersActivityInfoItem.HANDLE_STATUS_CANCEL); |
|
364 |
values.put("performStatusOld",OrdersActivityInfoItem.STATUS_PERFORM_SEND_OUT); |
|
365 |
values.put("id",ordersActivityInfoItem.getId()); |
|
366 |
sqlSentence.sqlSentence("handleStatus = #{m.handleStatus} WHERE id = #{m.id} AND handleStatus = #{m.handleStatusOld} AND performStatus = #{m.performStatusOld}",values); |
|
367 |
if(commonService.updateWhere(OrdersActivityInfoItemMapper.class,sqlSentence) != 1){ |
|
368 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"活动条目状态变化错误:"); |
|
369 |
} |
160c33
|
370 |
} |
C |
371 |
} |
|
372 |
} |
|
373 |
} |
|
374 |
|
|
375 |
/** |
|
376 |
* 退款作废-处理优惠券 |
|
377 |
* @param ordersTotal 订单 |
|
378 |
* @param refundRecord 退款总数据 |
|
379 |
* @param commonService 映射 |
|
380 |
*/ |
b3fdea
|
381 |
public static void handCoupon(OrdersTotal ordersTotal,RefundRecord refundRecord,StringBuilder orderNodeBuilder,CommonService commonService) { |
160c33
|
382 |
|
C |
383 |
//回退的优惠券变成使用状态 |
|
384 |
//如果该优惠券在别的订单使用了,那么就不再理会 |
|
385 |
|
|
386 |
SqlSentence sqlSentence = new SqlSentence(); |
|
387 |
Map<String, Object> values = new HashMap<>(); |
|
388 |
|
|
389 |
values.put("refundRecordId",refundRecord.getId()); |
4ebb90
|
390 |
sqlSentence.sqlSentence("select * from refund_record_coupon where refundRecordId = #{m.refundRecordId} and isDel=0 ",values); |
160c33
|
391 |
List<RefundRecordCoupon> refundRecordCouponList=commonService.selectList(RefundRecordCouponMapper.class,sqlSentence); |
C |
392 |
|
|
393 |
CouponOrderDiscountLog couponOrderDiscountLog; |
|
394 |
for (RefundRecordCoupon refundRecordCoupon : refundRecordCouponList) { |
|
395 |
|
|
396 |
couponOrderDiscountLog=commonService.selectOneByKey(CouponOrderDiscountLogMapper.class,refundRecordCoupon.getCouponOrderId()); |
|
397 |
if(couponOrderDiscountLog==null){ |
|
398 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"订单优惠卷标识不正确"); |
|
399 |
} |
|
400 |
|
|
401 |
//领建优惠券跳过回退 |
|
402 |
if(PartialRefundUtil.HIS_COUPON_CODE.equals(couponOrderDiscountLog.getCouponNumberId())){ |
|
403 |
//变更订单优惠券记录状态 |
|
404 |
values.clear(); |
|
405 |
values.put("status", BaseEntity.NO); |
|
406 |
values.put("oldStatus", BaseEntity.YES); |
|
407 |
values.put("id", couponOrderDiscountLog.getId()); |
|
408 |
sqlSentence.sqlSentence("status = #{m.status} WHERE id = #{m.id} AND status = #{m.oldStatus}",values); |
|
409 |
if(commonService.updateWhere(CouponOrderDiscountLogMapper.class,sqlSentence) != 1){ |
|
410 |
throw new TipsException("优惠券回退失败!"); |
|
411 |
} |
|
412 |
}else{ |
|
413 |
//优惠券状态变化 |
|
414 |
values.clear(); |
|
415 |
values.put("isUse", BaseEntity.YES); |
|
416 |
values.put("isUseOld", BaseEntity.NO); |
|
417 |
values.put("useTime", couponOrderDiscountLog.getCreateTime()); |
|
418 |
values.put("useType", CouponNumber.USE_TYPE_USER); |
|
419 |
values.put("id", couponOrderDiscountLog.getCouponNumberId()); |
|
420 |
sqlSentence.sqlSentence(" isUse=#{m.isUse},useTime=#{m.useTime},useType=#{m.useType},isUse=#{m.isUse} WHERE id = #{m.id} AND isUse = #{m.isUseOld}",values); |
b3fdea
|
421 |
if(commonService.updateWhere(CouponNumberMapper.class,sqlSentence) != 0){ |
C |
422 |
if(orderNodeBuilder != null){ |
|
423 |
orderNodeBuilder.append("-[作废退款]使用优惠券处理:"+couponOrderDiscountLog.getTitle()); |
|
424 |
} |
160c33
|
425 |
//变更订单优惠券记录状态 |
C |
426 |
values.clear(); |
|
427 |
values.put("status", BaseEntity.NO); |
|
428 |
values.put("oldStatus", BaseEntity.YES); |
|
429 |
values.put("id", couponOrderDiscountLog.getId()); |
|
430 |
sqlSentence.sqlSentence("status = #{m.status} WHERE id = #{m.id} AND status = #{m.oldStatus}",values); |
|
431 |
if(commonService.updateWhere(CouponOrderDiscountLogMapper.class,sqlSentence) != 1) { |
|
432 |
throw new TipsException("优惠券回退失败!"); |
fd7281
|
433 |
} |
C |
434 |
} |
|
435 |
} |
|
436 |
} |
|
437 |
} |
|
438 |
|
cfedbf
|
439 |
/**作废退款-爆款活动赠送处理*/ |
C |
440 |
public static void burstActivityHandle(StringBuilder orderNodeBuilder,OrdersTotal ordersTotal,RefundRecord refundRecord,CommonService commonService){ |
|
441 |
//不是爆款活动 |
|
442 |
if(ordersTotal.getActivityPageType() != OrderTotalConstants.ACTIVITY_TYPE_BURST){ |
|
443 |
return; |
|
444 |
} |
|
445 |
|
|
446 |
//查找是否处理了赠送的增值金 |
|
447 |
SqlSentence sqlSentence = new SqlSentence(); |
|
448 |
Map<String,Object> values = new HashMap<>(); |
|
449 |
values.put("isDel",102); |
|
450 |
values.put("orderId",refundRecord.getOrderId()); |
|
451 |
sqlSentence.sqlSentence("SELECT * FROM refund_user_assets rua WHERE rua.isDel = #{m.isDel} AND rua.status = 1 AND rua.amountStatus IN(1,3) AND rua.orderId = #{m.orderId}",values); |
|
452 |
List<RefundUserAssets> refundUserAssetsList = commonService.selectList(RefundUserAssetsMapper.class,sqlSentence); |
|
453 |
if(refundUserAssetsList.size() == 0){ |
|
454 |
return; |
|
455 |
} |
|
456 |
|
|
457 |
for(RefundUserAssets refundUserAssets:refundUserAssetsList){ |
|
458 |
//判断是否已经存在了别的赠送记录 |
|
459 |
if(OrderTool.getActivityGive(refundUserAssets.getUserId(),ordersTotal.getActivityPageCode(),commonService).size() == 0){ |
|
460 |
//是否有扣减用户资产 |
|
461 |
if(refundUserAssets.getAmountStatus() == RefundUserAssets.AMOUNT_STATUS_NORMAL){ |
|
462 |
orderNodeBuilder.append(",活动赠送增加成功"); |
|
463 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundUserAssets.getUserId(),refundRecord.getRemarks(),"退款作废:活动赠送资金回退作废",refundUserAssets.getOperatorId() |
|
464 |
,refundRecord.getOrderId(),refundRecord.getOperatorAppCode(),refundUserAssets.getId(),refundUserAssets.getAmount().negate(),refundUserAssets.getAmountType() |
|
465 |
,OperationReasonConstants.OP_REASON_BRING_NEW_USER_GIFT_RETRU_CANCEL,commonService,UserMoneyUnclaimed.YES); |
|
466 |
}else if(refundUserAssets.getAmountStatus() == RefundUserAssets.AMOUNT_STATUS_NOT_RECEIVE){ |
|
467 |
//用户未领取记录,还原 |
|
468 |
orderNodeBuilder.append(",活动赠送用户未领取,作废的领取记录还原"); |
|
469 |
values.clear(); |
|
470 |
values.put("id",refundUserAssets.getUserMoneyUnclaimedId()); |
|
471 |
values.put("status",UserMoneyUnclaimed.STATUS_WAI); |
|
472 |
sqlSentence.sqlUpdate("isDel = 0,isValid = 1 WHERE id = #{m.id} AND isDel = 1 AND isValid = 0 AND status = #{m.status}",values); |
|
473 |
if(commonService.updateWhere(UserMoneyUnclaimedMapper.class,sqlSentence) != 1){ |
|
474 |
throw new TipsException("活动赠送资产记录状态已变化[作废]!"); |
|
475 |
} |
|
476 |
} |
|
477 |
} |
|
478 |
|
|
479 |
//记录作废 |
|
480 |
values.clear(); |
|
481 |
values.put("id",refundUserAssets.getId()); |
|
482 |
values.put("status",RefundUserAssets.STATUS_CANCEL); |
|
483 |
values.put("oldStatus",RefundUserAssets.STATUS_NORMAL); |
|
484 |
sqlSentence.sqlSentence("status = #{m.status} WHERE id = #{m.id} AND status = #{m.oldStatus}",values); |
|
485 |
if(commonService.updateWhere(RefundUserAssetsMapper.class,sqlSentence) != 1){ |
|
486 |
throw new TipsException("活动赠送资产退款记录状态已变化[作废]!"); |
|
487 |
} |
|
488 |
} |
|
489 |
} |
|
490 |
|
160c33
|
491 |
/**退款子项处理*/ |
C |
492 |
public static void refundRecordItemHandle(OrdersTotal ordersTotal,RefundRecord refundRecord,CommonService commonService){ |
fd7281
|
493 |
|
160c33
|
494 |
SqlSentence sqlSentence = new SqlSentence(); |
C |
495 |
Map<String,Object> values = new HashMap<>(); |
|
496 |
|
|
497 |
//获取退款子单 |
|
498 |
values.put("refundRecordId",refundRecord.getId()); |
|
499 |
sqlSentence.sqlSentence("SELECT * FROM refund_record_item WHERE isDel = 0 AND refundRecordId = #{m.refundRecordId}",values); |
|
500 |
List<RefundRecordItem> refundRecordItems =commonService.selectList(RefundRecordItemMapper.class,sqlSentence); |
|
501 |
if(refundRecordItems == null || refundRecordItems.size() == 0){ |
|
502 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到退款子订单信息"); |
|
503 |
} |
|
504 |
|
|
505 |
for (RefundRecordItem refundRecordItem: refundRecordItems) { |
|
506 |
//商品类型判断 |
|
507 |
switch (refundRecordItem.getType()){ |
|
508 |
case OrderItemConstants.TYPE_RETAIL: |
755975
|
509 |
//商品/药品 |
160c33
|
510 |
rerailHandleOne(refundRecordItem,commonService); |
C |
511 |
break; |
|
512 |
case OrderItemConstants.TYPE_DRUG: |
755975
|
513 |
//处方单药品 |
160c33
|
514 |
rerailHandleOne(refundRecordItem,commonService); |
C |
515 |
break; |
|
516 |
case OrderItemConstants.TYPE_PROJECT: |
755975
|
517 |
//项目 |
160c33
|
518 |
projectHandleOne(refundRecordItem,refundRecord,commonService); |
C |
519 |
break; |
|
520 |
case OrderItemConstants.TYPE_PROMOTION: |
755975
|
521 |
//促销 |
160c33
|
522 |
handRefundPromotion( refundRecordItem, refundRecord, commonService); |
C |
523 |
break; |
|
524 |
case OrderItemConstants.TYPE_CARD: |
755975
|
525 |
//卡项 |
160c33
|
526 |
cardHandleOne( refundRecord, refundRecordItem, commonService); |
C |
527 |
break; |
|
528 |
case OrderItemConstants.CARD_BAG: |
755975
|
529 |
//卡包 |
160c33
|
530 |
handRefundPromotion( refundRecordItem, refundRecord, commonService); |
C |
531 |
break; |
e065e7
|
532 |
default: |
C |
533 |
//其他 |
|
534 |
rerailHandleOne(refundRecordItem,commonService); |
|
535 |
break; |
160c33
|
536 |
} |
C |
537 |
} |
|
538 |
} |
|
539 |
|
|
540 |
|
|
541 |
/**一级订单-商品/药品处理*/ |
|
542 |
public static void rerailHandleOne(RefundRecordItem refundRecordItem,CommonService commonService){ |
|
543 |
//判断操作完了去修改子订单状态 |
|
544 |
OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,refundRecordItem.getOrderItemId()); |
|
545 |
if (orderItem==null){ |
|
546 |
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息"); |
|
547 |
} |
|
548 |
|
|
549 |
//剩余可退款数量 |
|
550 |
if(refundRecordItem.getRefundNum() > orderItem.getHasReNum()){ |
755975
|
551 |
throw new TipsException(orderItem.getGoodsName()+"["+orderItem.getGoodsNo()+"]"+"作废退款数量不能大于已退款数量!"); |
160c33
|
552 |
} |
C |
553 |
|
|
554 |
//变更退款子项信息 |
|
555 |
int refundStatus; |
|
556 |
if (orderItem.getHasReNum().equals(refundRecordItem.getRefundNum())){ |
|
557 |
refundStatus = OrderTotalConstants.STATUS_REFUND_NONE; |
|
558 |
}else{ |
|
559 |
refundStatus = OrderTotalConstants.STATUS_REFUND_PART; |
|
560 |
} |
e490fa
|
561 |
RefundCarryVo refundCarryVo = new RefundCarryVo(); |
C |
562 |
refundCarryVo.setRefundTotal(refundRecordItem.getRealRefundTotal().negate()); |
|
563 |
refundCarryVo.setIntegralTotal(refundRecordItem.getRealRefundIntegral().negate()); |
|
564 |
refundCarryVo.setDeductionTotal(refundRecordItem.getDeductionTotal().negate()); |
|
565 |
refundCarryVo.setCashTotal(refundRecordItem.getCashTotal().negate()); |
|
566 |
refundCarryVo.setCashPurenessTotal(refundRecordItem.getCashPurenessTotal().negate()); |
|
567 |
refundCarryVo.setRechargeTotal(refundRecordItem.getRechargeTotal().negate()); |
|
568 |
refundCarryVo.setIncrementTotal(refundRecordItem.getIncrementTotal().negate()); |
160c33
|
569 |
|
C |
570 |
//更新子订单信息 |
e490fa
|
571 |
PartialRefundUtil.updateOrderItemOne(orderItem,refundStatus,refundCarryVo,-refundRecordItem.getRealRefundNum(), commonService); |
160c33
|
572 |
} |
C |
573 |
|
|
574 |
/**一级订单-项目处理*/ |
|
575 |
public static void projectHandleOne(RefundRecordItem refundRecordItem,RefundRecord refundRecord,CommonService commonService){ |
|
576 |
//找到子单 |
|
577 |
OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,refundRecordItem.getOrderItemId()); |
|
578 |
if (orderItem==null){ |
|
579 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到子订单信息"); |
|
580 |
} |
755975
|
581 |
//计算子单是否还有剩余的可扣疗程数 |
C |
582 |
if(refundRecordItem.getRefundNum() > orderItem.getHasReNum()){ |
|
583 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,orderItem.getGoodsName()+"["+orderItem.getGoodsNo()+"]"+"退款次数大于可退次数[54]!"); |
|
584 |
} |
160c33
|
585 |
|
C |
586 |
//找到用户项目 |
01fbcb
|
587 |
UserProjectItem userProjectItem = PartialRefundUtil.getUserProject(orderItem.getId(),commonService); |
160c33
|
588 |
if (userProjectItem == null) { |
755975
|
589 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,orderItem.getGoodsName()+"["+orderItem.getGoodsNo()+"]"+"未找到用户子项项目信息"); |
160c33
|
590 |
} |
C |
591 |
if(userProjectItem.getCancelNum() < refundRecordItem.getRefundNum()){ |
755975
|
592 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,orderItem.getGoodsName()+"["+orderItem.getGoodsNo()+"]"+"作废退款次数大于用户项目已退次数!"); |
160c33
|
593 |
} |
C |
594 |
|
|
595 |
//用户项目操作 |
755975
|
596 |
UserProjectTool.userProjectDeduction(userProjectItem, UserProjectUsedCon.USED_METHOD_ORDER_REFUND,UserProjectUsedCon.USED_TYPE_RETURN,refundRecordItem.getDeductionTotalUser() |
C |
597 |
,refundRecordItem.getId(),refundRecordItem.getRealRefundNum(),refundRecord.getInvalidAppId(),refundRecord.getInvalidAppName(),refundRecord.getRefundShopId(),refundRecord.getRefundShopName(),"员工备注:"+refundRecord.getInvalidRemarks(),commonService); |
160c33
|
598 |
|
C |
599 |
int refundStatus; |
|
600 |
if(refundRecordItem.getRefundNum().equals(orderItem.getHasReNum())){ |
|
601 |
refundStatus=OrderTotalConstants.STATUS_REFUND_NONE; |
|
602 |
}else{ |
|
603 |
refundStatus=OrderTotalConstants.STATUS_REFUND_PART; |
|
604 |
} |
|
605 |
|
e490fa
|
606 |
RefundCarryVo refundCarryVo = new RefundCarryVo(); |
C |
607 |
refundCarryVo.setRefundTotal(refundRecordItem.getRealRefundTotal().negate()); |
|
608 |
refundCarryVo.setIntegralTotal(refundRecordItem.getRealRefundIntegral().negate()); |
|
609 |
refundCarryVo.setDeductionTotal(refundRecordItem.getDeductionTotal().negate()); |
|
610 |
refundCarryVo.setCashTotal(refundRecordItem.getCashTotal().negate()); |
|
611 |
refundCarryVo.setCashPurenessTotal(refundRecordItem.getCashPurenessTotal().negate()); |
|
612 |
refundCarryVo.setRechargeTotal(refundRecordItem.getRechargeTotal().negate()); |
|
613 |
refundCarryVo.setIncrementTotal(refundRecordItem.getIncrementTotal().negate()); |
|
614 |
|
160c33
|
615 |
//更新子订单信息 |
e490fa
|
616 |
PartialRefundUtil.updateOrderItemOne(orderItem,refundStatus,refundCarryVo,-refundRecordItem.getRealRefundNum(),commonService); |
160c33
|
617 |
} |
C |
618 |
|
|
619 |
/**一级子单-处理促销*/ |
|
620 |
private static void handRefundPromotion(RefundRecordItem refundRecordItem, RefundRecord refundRecord, CommonService commonService) { |
|
621 |
|
|
622 |
//查看订单信息 |
|
623 |
OrderItem orderItem = commonService.selectOneByKey(OrderItemMapper.class,refundRecordItem.getOrderItemId()); |
|
624 |
if(orderItem == null ){ |
|
625 |
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息[84]!"); |
|
626 |
} |
|
627 |
|
|
628 |
SqlSentence sqlSentence = new SqlSentence(); |
|
629 |
Map<String, Object> map = new HashMap<>(); |
|
630 |
|
|
631 |
//获取退款二级单 |
|
632 |
map.put("refundRecordItemId",refundRecordItem.getId()); |
|
633 |
sqlSentence.sqlSentence("select * from refund_record_item_source where isDel = 0 AND refundRecordItemId = #{m.refundRecordItemId}",map); |
|
634 |
List<RefundRecordItemSource> sons = commonService.selectList(RefundRecordItemSourceMapper.class, sqlSentence); |
|
635 |
|
|
636 |
for (RefundRecordItemSource son : sons) { |
|
637 |
switch (GroupTypeEnum.getCode(son.getType())){ |
|
638 |
case PROJECT: |
|
639 |
projectHandleTwo(refundRecord,refundRecordItem, son,orderItem.getUserCardId(),commonService); |
|
640 |
break; |
|
641 |
case RETAIL: |
|
642 |
rerailHandleTwo(refundRecord,refundRecordItem,son,orderItem.getUserCardId(),commonService); |
|
643 |
break; |
|
644 |
case INCREMENT: |
|
645 |
//增值金 |
|
646 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
|
647 |
if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){ |
|
648 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"作废退款:促销赠送增值金扣减",refundRecord.getInvalidId(),refundRecord.getOrderId(),refundRecord.getInvalidAppCode(),refundRecord.getId(),son.getRealRefundTotal(), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES); |
|
649 |
} |
|
650 |
break; |
|
651 |
case STORED: |
|
652 |
//储值金额 |
|
653 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
|
654 |
if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){ |
|
655 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"作废退款:促销赠送储值金额扣减",refundRecord.getInvalidId(),refundRecord.getOrderId(),refundRecord.getInvalidAppCode(),refundRecord.getId(),son.getRealRefundTotal(), UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.NO); |
|
656 |
} |
|
657 |
break; |
|
658 |
case INTEGRAL: |
|
659 |
//积分 |
|
660 |
//判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0 |
|
661 |
if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){ |
|
662 |
UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"作废退款:促销赠送积分扣减",refundRecord.getInvalidId(),refundRecord.getOrderId(),refundRecord.getInvalidAppCode(),refundRecord.getId(),son.getRealRefundTotal(), UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES); |
|
663 |
} |
|
664 |
break; |
|
665 |
} |
|
666 |
|
|
667 |
} |
|
668 |
|
|
669 |
//获取其子项 |
|
670 |
map.put("orderItemId",orderItem.getId()); |
|
671 |
sqlSentence.sqlSentence("select refundStatus from order_item_source WHERE orderItemId=#{m.orderItemId} and isDel=0",map); |
|
672 |
List<OrderItemSon> orderItemSonList=commonService.selectList(OrderItemSonMapper.class,sqlSentence); |
|
673 |
int refundStatus; |
|
674 |
Integer refundNum = 0; |
|
675 |
List<Integer> collect = orderItemSonList.stream().map(OrderItemSon::getRefundStatus).collect(Collectors.toList()); |
|
676 |
|
|
677 |
if(collect.contains(OrderTotalConstants.STATUS_REFUND_PART)){ |
|
678 |
refundStatus = OrderTotalConstants.STATUS_REFUND_PART; |
|
679 |
}else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE)){ |
|
680 |
if(collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){ |
|
681 |
refundStatus = OrderTotalConstants.STATUS_REFUND_PART; |
|
682 |
}else{ |
|
683 |
refundStatus = OrderTotalConstants.STATUS_REFUND_NONE; |
|
684 |
} |
|
685 |
}else if (collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){ |
|
686 |
refundStatus = OrderTotalConstants.STATUS_REFUND_FINSH; |
|
687 |
refundNum = orderItem.getBuyNum(); |
|
688 |
}else { |
|
689 |
refundStatus = OrderTotalConstants.STATUS_REFUND_NONE; |
|
690 |
} |
|
691 |
|
e490fa
|
692 |
RefundCarryVo refundCarryVo = new RefundCarryVo(); |
C |
693 |
refundCarryVo.setRefundTotal(refundRecordItem.getRealRefundTotal().negate()); |
|
694 |
refundCarryVo.setIntegralTotal(refundRecordItem.getRealRefundIntegral().negate()); |
|
695 |
refundCarryVo.setDeductionTotal(refundRecordItem.getDeductionTotal().negate()); |
|
696 |
refundCarryVo.setCashTotal(refundRecordItem.getCashTotal().negate()); |
|
697 |
refundCarryVo.setCashPurenessTotal(refundRecordItem.getCashPurenessTotal().negate()); |
|
698 |
refundCarryVo.setRechargeTotal(refundRecordItem.getRechargeTotal().negate()); |
|
699 |
refundCarryVo.setIncrementTotal(refundRecordItem.getIncrementTotal().negate()); |
|
700 |
|
160c33
|
701 |
//更新子订单信息 |
e490fa
|
702 |
PartialRefundUtil.updateOrderItemOne(orderItem,refundStatus,refundCarryVo,-refundNum,commonService); |
160c33
|
703 |
|
C |
704 |
} |
|
705 |
|
|
706 |
/**二级子订单-项目类型 |
|
707 |
* @param refundRecord 退款总记录 |
|
708 |
* @param refundRecordItem 退款一级子单 |
|
709 |
* @param refundRecordItemSource 退款二级子单 |
|
710 |
* @param userCardId 用户卡包标识 |
|
711 |
* @param commonService 映射 |
|
712 |
*/ |
|
713 |
private static void projectHandleTwo(RefundRecord refundRecord,RefundRecordItem refundRecordItem, RefundRecordItemSource refundRecordItemSource |
|
714 |
,String userCardId,CommonService commonService) { |
|
715 |
|
|
716 |
//判断操作完了去修改子订单状态 |
|
717 |
OrderItemSon orderItemSon = commonService.selectOneByKey(OrderItemSonMapper.class,refundRecordItemSource.getOrderItemSonId()); |
|
718 |
if (orderItemSon==null){ |
|
719 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到二级子订单信息[02]"); |
|
720 |
} |
755975
|
721 |
//计算子单是否还有剩余的可扣疗程数 |
C |
722 |
if(refundRecordItemSource.getRefundNum() > orderItemSon.getHasReNum()){ |
|
723 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,orderItemSon.getGoodsName()+"["+orderItemSon.getGoodsNo()+"]"+"作废退款次数大于已退次数[56]!"); |
|
724 |
} |
160c33
|
725 |
|
C |
726 |
UserProjectItem userProjectItem = PartialRefundUtil.getUserProject(orderItemSon.getId(),commonService); |
|
727 |
if(userProjectItem == null){ |
|
728 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"用户项目获取失败[06]!"); |
|
729 |
} |
755975
|
730 |
//比较作废退款数量 |
160c33
|
731 |
if(refundRecordItemSource.getRefundNum() > userProjectItem.getCancelNum()){ |
755975
|
732 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,orderItemSon.getGoodsName()+"["+orderItemSon.getGoodsNo()+"]"+"作废退款次数大于用户项目已退次数[56]!"); |
160c33
|
733 |
} |
C |
734 |
|
|
735 |
//处理用户项目,减去用户项目数量 |
755975
|
736 |
UserProjectTool.userProjectDeduction(userProjectItem,UserProjectUsedCon.USED_METHOD_ORDER_REFUND,UserProjectUsedCon.USED_TYPE_RETURN,refundRecordItemSource.getDeductionTotalUser() |
C |
737 |
,refundRecordItemSource.getId(),refundRecordItemSource.getRealRefundNum(),refundRecord.getInvalidAppId(),refundRecord.getInvalidAppName(),refundRecord.getRefundShopId(),refundRecord.getRefundShopName(),"员工备注:"+refundRecord.getInvalidRemarks(),commonService); |
160c33
|
738 |
|
C |
739 |
int refundStatus; |
755975
|
740 |
if(orderItemSon.getHasReNum().equals(refundRecordItemSource.getRefundNum())){ |
160c33
|
741 |
refundStatus=OrderTotalConstants.STATUS_REFUND_NONE; |
C |
742 |
}else{ |
|
743 |
refundStatus=OrderTotalConstants.STATUS_REFUND_PART; |
|
744 |
} |
|
745 |
|
e490fa
|
746 |
RefundCarryVo refundCarryVo = new RefundCarryVo(); |
C |
747 |
refundCarryVo.setRefundTotal(refundRecordItemSource.getRealRefundTotal().negate()); |
|
748 |
refundCarryVo.setIntegralTotal(refundRecordItemSource.getRealRefundIntegral().negate()); |
|
749 |
refundCarryVo.setDeductionTotal(refundRecordItemSource.getDeductionTotal().negate()); |
|
750 |
refundCarryVo.setCashTotal(refundRecordItemSource.getCashTotal().negate()); |
|
751 |
refundCarryVo.setCashPurenessTotal(refundRecordItemSource.getCashPurenessTotal().negate()); |
|
752 |
refundCarryVo.setRechargeTotal(refundRecordItemSource.getRechargeTotal().negate()); |
|
753 |
refundCarryVo.setIncrementTotal(refundRecordItemSource.getIncrementTotal().negate()); |
|
754 |
|
160c33
|
755 |
//更新子单信息 |
e490fa
|
756 |
PartialRefundUtil.updateOrderItemTwo(orderItemSon,refundStatus,refundCarryVo,-refundRecordItemSource.getRealRefundNum(),commonService); |
160c33
|
757 |
|
C |
758 |
if(refundRecordItem.getType().equals(OrderItemConstants.CARD_BAG)){ |
755975
|
759 |
//是卡包的,找回卡包使用记录 |
160c33
|
760 |
userCardUsedHandle(userCardId,orderItemSon.getCardItemInfoId(),orderItemSon.getId(),orderItemSon.getOrderId(),refundRecordItemSource.getRefundNum(),commonService); |
C |
761 |
} |
|
762 |
|
|
763 |
} |
|
764 |
|
|
765 |
/**二级订单-商品/药品 |
|
766 |
* @param refundRecord 退款总记录 |
|
767 |
* @param refundRecordItem 退款一级子单 |
|
768 |
* @param refundRecordItemSource 退款二级子单 |
|
769 |
* @param commonService 映射 |
|
770 |
* @return 全局携带参数结构 |
|
771 |
*/ |
|
772 |
private static void rerailHandleTwo(RefundRecord refundRecord,RefundRecordItem refundRecordItem, RefundRecordItemSource refundRecordItemSource |
|
773 |
,String userCardId,CommonService commonService) { |
|
774 |
|
|
775 |
//判断操作完了去修改子订单状态 |
|
776 |
OrderItemSon orderItemSon=commonService.selectOneByKey(OrderItemSonMapper.class,refundRecordItemSource.getOrderItemSonId()); |
|
777 |
if (orderItemSon==null){ |
|
778 |
throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到二级子订单信息"); |
|
779 |
} |
|
780 |
|
|
781 |
//计算子单是否还有剩余的可扣疗程数 |
|
782 |
if(refundRecordItemSource.getRefundNum() > orderItemSon.getHasReNum()){ |
|
783 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"作废退款次数大于已退次数[84]!"); |
|
784 |
} |
|
785 |
|
|
786 |
int refundStatus; |
|
787 |
if(orderItemSon.getHasReNum().equals(refundRecordItemSource.getRefundNum())){ |
|
788 |
refundStatus=OrderTotalConstants.STATUS_REFUND_NONE; |
|
789 |
}else{ |
|
790 |
refundStatus=OrderTotalConstants.STATUS_REFUND_PART; |
|
791 |
} |
|
792 |
|
e490fa
|
793 |
RefundCarryVo refundCarryVo = new RefundCarryVo(); |
C |
794 |
refundCarryVo.setRefundTotal(refundRecordItemSource.getRealRefundTotal().negate()); |
|
795 |
refundCarryVo.setIntegralTotal(refundRecordItemSource.getRealRefundIntegral().negate()); |
|
796 |
refundCarryVo.setDeductionTotal(refundRecordItemSource.getDeductionTotal().negate()); |
|
797 |
refundCarryVo.setCashTotal(refundRecordItemSource.getCashTotal().negate()); |
|
798 |
refundCarryVo.setCashPurenessTotal(refundRecordItemSource.getCashPurenessTotal().negate()); |
|
799 |
refundCarryVo.setRechargeTotal(refundRecordItemSource.getRechargeTotal().negate()); |
|
800 |
refundCarryVo.setIncrementTotal(refundRecordItemSource.getIncrementTotal().negate()); |
|
801 |
|
|
802 |
PartialRefundUtil.updateOrderItemTwo(orderItemSon,refundStatus,refundCarryVo,-refundRecordItemSource.getRealRefundNum(),commonService); |
160c33
|
803 |
|
C |
804 |
if(refundRecordItem.getType().equals(OrderItemConstants.CARD_BAG)){ |
|
805 |
//是卡包的,刪除卡包使用 |
|
806 |
userCardUsedHandle(userCardId,orderItemSon.getCardItemInfoId(),orderItemSon.getId(),orderItemSon.getOrderId(),refundRecordItemSource.getRefundNum(),commonService); |
|
807 |
} |
|
808 |
|
|
809 |
} |
|
810 |
|
|
811 |
/**卡包使用记录-状态变化 |
|
812 |
* @param userCardId 用户卡包 |
|
813 |
* @param cardItemInfoId 卡包的卡项子项 |
|
814 |
* @param sourceId 卡包使用记录来源标识 |
|
815 |
* @param orderId 卡包使用记录来源总表标识 |
|
816 |
* @param refundNum 退款数量 |
|
817 |
* @param commonService 映射 |
|
818 |
*/ |
|
819 |
public static void userCardUsedHandle(String userCardId,String cardItemInfoId,String sourceId,String orderId,Integer refundNum |
|
820 |
,CommonService commonService){ |
|
821 |
|
|
822 |
//查出用户,commonId:卡项的组合项标识 |
755975
|
823 |
CardItemInfo cardItemInfo = commonService.selectOneByKey(CardItemInfoMapper.class,cardItemInfoId); |
C |
824 |
if(cardItemInfo == null){ |
160c33
|
825 |
logger.error("未找到该卡包的组合项-卡包作废退款失败,userCardId:{},cardItemInfoId:{},sourceId:{},orderId:{},refundNum:{}",userCardId,cardItemInfoId,sourceId,orderId,refundNum); |
C |
826 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到该卡包的组合项"); |
|
827 |
} |
|
828 |
|
4ebb90
|
829 |
UserCard userCard = commonService.selectOneByKey(UserCardMapper.class,userCardId); |
C |
830 |
if(userCard == null){ |
|
831 |
logger.error("未找到该卡包-卡包作废退款失败,userCardId:{},cardItemInfoId:{},sourceId:{},orderId:{},refundNum:{}",userCardId,cardItemInfoId,sourceId,orderId,refundNum); |
|
832 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到该卡包信息"); |
|
833 |
} |
|
834 |
|
160c33
|
835 |
//获取权益类型 |
C |
836 |
CardEquity cardEquity = commonService.selectOneByKey(CardEquityMapper.class,cardItemInfo.getCardEquityId()); |
|
837 |
if(cardEquity == null){ |
|
838 |
logger.error("未找到该卡包的组合项权益类型-卡包作废退款失败,userCardId:{},cardItemInfoId:{},sourceId:{},orderId:{},refundNum:{}",userCardId,cardItemInfoId,sourceId,orderId,refundNum); |
|
839 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到该卡包的组合项权益类型"); |
|
840 |
} |
|
841 |
|
|
842 |
SqlSentence sqlSentence = new SqlSentence(); |
|
843 |
Map<String,Object> map = new HashMap<>(); |
|
844 |
|
|
845 |
//获取作废使用记录 |
|
846 |
map.put("cardItemInfoId",cardItemInfoId); |
|
847 |
map.put("sourceId",sourceId); |
|
848 |
map.put("userCardId",userCardId); |
|
849 |
sqlSentence.sqlSentence(" SELECT * FROM user_card_used WHERE isDel = 1 AND userCardId = #{m.userCardId}" + |
|
850 |
" AND cardItemInfoId = #{m.cardItemInfoId} AND sourceId = #{m.sourceId}",map); |
|
851 |
List<UserCardUsed> userCardUsedList = commonService.selectList(UserCardUsedMapper.class,sqlSentence); |
|
852 |
|
|
853 |
//因为之前的使用记录有些没有关联到订单,所以找不到 |
|
854 |
if(userCardUsedList == null || userCardUsedList.size() == 0){ |
|
855 |
map.clear(); |
|
856 |
map.put("cardItemInfoId",cardItemInfoId); |
|
857 |
map.put("userCardId",userCardId); |
|
858 |
map.put("orderId",orderId); |
|
859 |
sqlSentence.sqlSentence(" SELECT * FROM user_card_used WHERE isDel = 1 AND userCardId = #{m.userCardId}" + |
|
860 |
" AND cardItemInfoId = #{m.cardItemInfoId} AND orderId = #{m.orderId} AND sourceId IS NULL",map); |
|
861 |
userCardUsedList = commonService.selectList(UserCardUsedMapper.class,sqlSentence); |
|
862 |
if(userCardUsedList.size() == 0){ |
|
863 |
sqlSentence.sqlSentence(" SELECT * FROM user_card_used WHERE isDel = 1 AND userCardId = #{m.userCardId}" + |
|
864 |
" AND cardItemInfoId = #{m.cardItemInfoId} AND sourceId IS NULL",map); |
|
865 |
userCardUsedList = commonService.selectList(UserCardUsedMapper.class,sqlSentence); |
|
866 |
} |
|
867 |
} |
|
868 |
|
4ebb90
|
869 |
//计算当前数量要扣的卡次 |
C |
870 |
int returnNum = UserCardTool.countUsedNumber(refundNum,cardItemInfo,cardEquity); |
|
871 |
//获取可扣卡次 |
|
872 |
UserCardItemInfoVo userCardItemInfoVo = UserCardTool.getSurplusNumber(userCard,cardItemInfo,cardEquity,commonService); |
|
873 |
if(!userCardItemInfoVo.isNumByNum()){ |
|
874 |
throw new TipsException("作废退款-卡包扣减失败,不符合N选M规则!"); |
|
875 |
} |
|
876 |
if(returnNum > userCardItemInfoVo.getSurplusNum()){ |
|
877 |
throw new TipsException("作废退款-卡包扣减失败,抵扣次数不足!"); |
160c33
|
878 |
} |
C |
879 |
|
|
880 |
if(returnNum > userCardUsedList.size()){ |
|
881 |
logger.error("卡包可退数量错误-卡包作废退款失败,查询语句:{},传入参数:{}",sqlSentence.getSqlSentence(), JSON.toJSONString(sqlSentence.getM())); |
|
882 |
logger.error("卡包可退数量错误-卡包作废退款失败,userCardId:{},cardItemInfoId:{},sourceId:{},orderId:{},refundNum:{},returnNum:{}",userCardId,cardItemInfoId,sourceId,orderId,refundNum,returnNum); |
755975
|
883 |
throw new TipsException("卡包作废退款次数量大于可退次数!"); |
160c33
|
884 |
} |
C |
885 |
|
|
886 |
//已经操作数量 |
4ebb90
|
887 |
int opNum = returnNum; |
160c33
|
888 |
StringBuilder sql; |
C |
889 |
for(UserCardUsed userCardUsed:userCardUsedList){ |
|
890 |
//判断是否够了,跳出循环 |
b3fdea
|
891 |
if(opNum <= 0){ |
160c33
|
892 |
break; |
C |
893 |
} |
4ebb90
|
894 |
if(userCardUsed.getCancelNum() <= 0){ |
C |
895 |
continue; |
|
896 |
} |
160c33
|
897 |
sql = new StringBuilder(); |
C |
898 |
map.clear(); |
|
899 |
map.put("id",userCardUsed.getId()); |
4ebb90
|
900 |
map.put("cancelNumOld",userCardUsed.getCancelNum()); |
C |
901 |
if(opNum >= userCardUsed.getCancelNum()){ |
|
902 |
map.put("isDel",UserCardUsed.NO); |
|
903 |
map.put("countNum",userCardUsed.getCancelNum()); |
|
904 |
opNum = opNum - userCardUsed.getCancelNum(); |
|
905 |
}else{ |
|
906 |
map.put("isDel",UserCardUsed.YES); |
|
907 |
map.put("countNum",opNum); |
|
908 |
opNum = 0; |
|
909 |
} |
|
910 |
sql.append("isDel = #{m.isDel}"); |
|
911 |
sql.append(",usedNum = usedNum + #{m.countNum}"); |
|
912 |
sql.append(",cancelNum = cancelNum - #{m.countNum}"); |
160c33
|
913 |
if(StringUtils.isEmpty(userCardUsed.getOrderId())){ |
C |
914 |
sql.append(",orderId = #{m.orderId}"); |
|
915 |
map.put("orderId",orderId); |
|
916 |
} |
|
917 |
if(StringUtils.isEmpty(userCardUsed.getSourceId())){ |
|
918 |
sql.append(",sourceId = #{m.sourceId}"); |
|
919 |
map.put("sourceId",sourceId); |
|
920 |
} |
4ebb90
|
921 |
sql.append(" WHERE id = #{m.id} AND cancelNum = #{m.cancelNumOld}"); |
160c33
|
922 |
sqlSentence.sqlUpdate(sql.toString(),map); |
4ebb90
|
923 |
if(commonService.updateWhere(UserCardUsedMapper.class,sqlSentence) != 1){ |
C |
924 |
throw new TipsException("卡包使用记录已发生变化,请重试!"); |
|
925 |
} |
160c33
|
926 |
} |
4ebb90
|
927 |
if(opNum != 0){ |
160c33
|
928 |
logger.error("卡包回退数量错误-卡包作废退款失败,userCardId:{},cardItemInfoId:{},sourceId:{},orderId:{},refundNum:{},returnNum:{},opNum:{}",userCardId,cardItemInfoId,sourceId,orderId,refundNum,returnNum,opNum); |
C |
929 |
throw new TipsException("卡包作废回退数量错误!"); |
|
930 |
} |
|
931 |
|
|
932 |
} |
|
933 |
|
|
934 |
/**一级子单-处理卡项 |
|
935 |
* @param refundRecord 退款总记录 |
|
936 |
* @param refundRecordItem 退款一级记录 |
|
937 |
* @param commonService 映射 |
|
938 |
* @return 全局携带参数结构 |
|
939 |
*/ |
|
940 |
public static void cardHandleOne(RefundRecord refundRecord, RefundRecordItem refundRecordItem,CommonService commonService) { |
|
941 |
|
|
942 |
//判断操作完了去修改子订单状态 |
|
943 |
OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,refundRecordItem.getOrderItemId()); |
|
944 |
if (orderItem==null){ |
|
945 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"未找到子订单信息"); |
|
946 |
} |
|
947 |
|
|
948 |
if(refundRecordItem.getRefundNum() > orderItem.getHasReNum()){ |
|
949 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"作废退款-卡包提示:作废卡包退款数量大于已退款数量[020]"); |
|
950 |
} |
|
951 |
|
|
952 |
SqlSentence sqlSentence = new SqlSentence(); |
|
953 |
Map<String,Object> values = new HashMap<>(); |
|
954 |
|
|
955 |
|
|
956 |
//找到已退款卡包 |
|
957 |
values.put("status",RefundRecordCard.YES); |
|
958 |
values.put("refundRecordItemId",refundRecordItem.getId()); |
|
959 |
sqlSentence.sqlSentence("SELECT * FROM refund_record_card WHERE isDel = 0 AND status = #{m.status} AND refundRecordItemId = #{m.refundRecordItemId}",values); |
|
960 |
List<RefundRecordCard> refundRecordCardList = commonService.selectList(RefundRecordCardMapper.class,sqlSentence); |
|
961 |
if(refundRecordItem.getRefundNum() > refundRecordCardList.size()){ |
|
962 |
throw new PlatTipsException(PlatformCode.ERROR_TIPS,"作废退款-卡包提示:作废卡包退款数量大于已退款数量[021]"); |
|
963 |
} |
|
964 |
|
|
965 |
//变更卡项状态 |
|
966 |
RefundRecordCard refundRecordCard; |
|
967 |
for (int i = 0; i < refundRecordItem.getRefundNum(); i++) { |
|
968 |
refundRecordCard= refundRecordCardList.get(i); |
|
969 |
values.clear(); |
|
970 |
values.put("id",refundRecordCard.getUserCardId()); |
|
971 |
values.put("statusOld", UserCard.TYPE_NO_USED); |
|
972 |
values.put("effectiveStatus", UserProjectConstants.EFF_STATUS_YES); |
|
973 |
values.put("oldEffectiveStatus", UserProjectConstants.EFF_STATUS_CANCEL); |
|
974 |
sqlSentence.sqlSentence(" effectiveStatus=#{m.effectiveStatus} WHERE id = #{m.id} AND effectiveStatus = #{m.oldEffectiveStatus} AND status = #{m.statusOld}",values); |
|
975 |
if(commonService.updateWhere(UserCardMapper.class,sqlSentence) != 1){ |
|
976 |
throw new TipsException("用户卡包状态已发生变化,请重试!"); |
|
977 |
} |
|
978 |
|
|
979 |
values.clear(); |
|
980 |
values.put("id",refundRecordCard.getId()); |
|
981 |
values.put("status",RefundRecordCard.NO); |
|
982 |
values.put("statusOld",RefundRecordCard.YES); |
|
983 |
sqlSentence.sqlSentence("status = #{m.status} WHERE id = #{m.id} AND status = #{m.statusOld}",values); |
|
984 |
if(commonService.updateWhere(RefundRecordCardMapper.class,sqlSentence) != 1){ |
|
985 |
throw new TipsException("退款卡包状态已发生变化,请重试!"); |
|
986 |
} |
|
987 |
} |
|
988 |
|
|
989 |
int refundStatus; |
ea4351
|
990 |
//根据数量比较 |
160c33
|
991 |
if (orderItem.getHasReNum().equals(refundRecordItem.getRefundNum())){ |
C |
992 |
refundStatus = OrderTotalConstants.STATUS_REFUND_NONE; |
|
993 |
}else { |
|
994 |
refundStatus = OrderTotalConstants.STATUS_REFUND_PART; |
|
995 |
} |
ea4351
|
996 |
//根据金额比较 |
C |
997 |
if(refundStatus == OrderTotalConstants.STATUS_REFUND_NONE){ |
|
998 |
if(orderItem.getReTotal().compareTo(refundRecordItem.getRealRefundTotal())>0){ |
|
999 |
refundStatus = OrderTotalConstants.STATUS_REFUND_PART; |
|
1000 |
} |
|
1001 |
} |
|
1002 |
|
3badb7
|
1003 |
//查看是否用户卡包退款 |
C |
1004 |
if(RefundSoruceConstants.TYPE_SOURCE_USER_CARD.equals(refundRecord.getSourceAssistantType())){ |
|
1005 |
CardRefundTool.cardItemCancel(refundRecord,refundRecordItem,commonService); |
|
1006 |
} |
|
1007 |
|
e490fa
|
1008 |
RefundCarryVo refundCarryVo = new RefundCarryVo(); |
C |
1009 |
refundCarryVo.setRefundTotal(refundRecordItem.getRealRefundTotal().negate()); |
|
1010 |
refundCarryVo.setIntegralTotal(refundRecordItem.getRealRefundIntegral().negate()); |
|
1011 |
refundCarryVo.setDeductionTotal(refundRecordItem.getDeductionTotal().negate()); |
|
1012 |
refundCarryVo.setCashTotal(refundRecordItem.getCashTotal().negate()); |
|
1013 |
refundCarryVo.setCashPurenessTotal(refundRecordItem.getCashPurenessTotal().negate()); |
|
1014 |
refundCarryVo.setRechargeTotal(refundRecordItem.getRechargeTotal().negate()); |
|
1015 |
refundCarryVo.setIncrementTotal(refundRecordItem.getIncrementTotal().negate()); |
|
1016 |
|
160c33
|
1017 |
//更新子订单信息 |
e490fa
|
1018 |
PartialRefundUtil.updateOrderItemOne(orderItem,refundStatus,refundCarryVo,-refundRecordItem.getRealRefundNum(),commonService); |
160c33
|
1019 |
} |
fd7281
|
1020 |
|
C |
1021 |
} |