提交 | 用户 | age
|
496b6c
|
1 |
package com.hx.medical.service.impl; |
C |
2 |
|
|
3 |
import javax.annotation.Resource; |
|
4 |
|
|
5 |
import com.hx.common.dao.CommonDao; |
|
6 |
import com.hx.exception.ServiceException; |
|
7 |
import com.hx.medical.config.SystemConfig; |
|
8 |
import com.hx.medical.dao.mapper.*; |
|
9 |
import com.hx.medical.model.*; |
|
10 |
import com.hx.medical.service.log.CreateServiceOrderLog; |
|
11 |
import com.hx.medical.service.tool.CouponTool; |
|
12 |
import com.hx.medical.service.tools.ConfigurationTool; |
|
13 |
import com.hx.medical.service.tools.ServiceOrderTool; |
|
14 |
import com.hx.medical.service.tools.ShopWalletTool; |
|
15 |
import com.hx.medical.statistics.tools.TimerOrderDataTool; |
|
16 |
import com.hx.movie.config.PartnerConfig; |
|
17 |
import com.hx.util.*; |
|
18 |
import org.springframework.stereotype.Service; |
|
19 |
import org.springframework.transaction.annotation.Transactional; |
|
20 |
|
|
21 |
import com.hx.exception.TipsException; |
|
22 |
import com.hx.medical.service.ServiceOrderService; |
|
23 |
import com.hx.mybatisTool.SqlSentence; |
|
24 |
|
|
25 |
import java.util.*; |
|
26 |
|
|
27 |
@Transactional |
|
28 |
@Service |
|
29 |
public class ServiceOrderServiceImpl implements ServiceOrderService { |
|
30 |
|
|
31 |
|
|
32 |
@Resource |
|
33 |
private ServiceOrderMapper serviceOrderMapper; |
|
34 |
@Resource |
|
35 |
private CommonDao commonDao; |
|
36 |
@Resource |
|
37 |
private PayRecordMapper payRecordMapper; |
|
38 |
@Resource |
|
39 |
private SystemConfig systemConfig; |
|
40 |
@Resource |
|
41 |
private PartnerConfig partnerConfig; |
|
42 |
@Resource |
|
43 |
private ShopMapper shopMapper; |
|
44 |
|
|
45 |
/**查询列表*/ |
|
46 |
@Override |
|
47 |
public List<ServiceOrder> selectList(SqlSentence sqlSentence) { |
|
48 |
return serviceOrderMapper.selectList(sqlSentence); |
|
49 |
} |
|
50 |
|
|
51 |
/**查询列表*/ |
|
52 |
@Override |
|
53 |
public List<Map<String,Object>> selectListMap(SqlSentence sqlSentence) { |
|
54 |
return serviceOrderMapper.selectListMap(sqlSentence); |
|
55 |
} |
|
56 |
|
|
57 |
/**查询单个*/ |
|
58 |
@Override |
|
59 |
public ServiceOrder selectOne(SqlSentence sqlSentence) { |
|
60 |
return serviceOrderMapper.selectOne(sqlSentence); |
|
61 |
} |
|
62 |
|
|
63 |
/**查询单个*/ |
|
64 |
@Override |
|
65 |
public Map<String,Object> selectOneMap(SqlSentence sqlSentence) { |
|
66 |
return serviceOrderMapper.selectOneMap(sqlSentence); |
|
67 |
} |
|
68 |
|
|
69 |
/**查询单个,大数据不拿取*/ |
|
70 |
@Override |
|
71 |
public ServiceOrder selectOneByKey(Object object) { |
|
72 |
return serviceOrderMapper.selectOneByKey(object); |
|
73 |
} |
|
74 |
|
|
75 |
/**查询单个,大数据拿取*/ |
|
76 |
@Override |
|
77 |
public ServiceOrder selectOneByKeyBlob(Object object) { |
|
78 |
return serviceOrderMapper.selectOneByKeyBlob(object); |
|
79 |
} |
|
80 |
|
|
81 |
/**新增-常规订单*/ |
|
82 |
@Override |
|
83 |
public void insert(ServiceOrder serviceOrder, ServiceOrderItem item, CouponNumber couponNumber, User user) throws Exception { |
|
84 |
|
|
85 |
//订单总金额计算 |
|
86 |
Double total = NumberUtil.getTypeDouble(item.getPrice()*item.getBuyNum(),2); |
|
87 |
serviceOrder.setTotal(total); |
|
88 |
serviceOrder.setPayTotal(total); |
|
89 |
serviceOrder.setActualTotal(total); |
|
90 |
|
|
91 |
//判断是否使用优惠券 |
|
92 |
ServiceOrderDiscountLog serviceOrderDiscountLog = null; |
|
93 |
if(couponNumber != null){ |
|
94 |
serviceOrderDiscountLog = CouponTool.useCoupon(item.getServiceProId(),total,serviceOrder.getShopId(),couponNumber,user,commonDao); |
|
95 |
serviceOrder.setPayTotal(NumberUtil.getTypeDouble(serviceOrder.getTotal()-serviceOrderDiscountLog.getDiscountTotal() ,2)); |
|
96 |
if(serviceOrder.getPayTotal() < 0){ |
|
97 |
serviceOrder.setPayTotal(0.0); |
|
98 |
} |
|
99 |
serviceOrder.setActualTotal(serviceOrder.getPayTotal()); |
|
100 |
serviceOrder.setDiscountTotal(serviceOrderDiscountLog.getDiscountTotal()); |
|
101 |
} |
|
102 |
|
|
103 |
//计算支付扣除手续费费用 |
|
104 |
SysConfiguration sysConfiguration = ConfigurationTool.configurationData(null,commonDao); |
|
105 |
if(sysConfiguration == null){ |
|
106 |
throw new ServiceException("获取信息失败!"); |
|
107 |
} |
|
108 |
serviceOrder.setNetTotal(NumberUtil.getTypeDouble(serviceOrder.getPayTotal()-(serviceOrder.getPayTotal()*sysConfiguration.getWxCommission()/100),2)); |
|
109 |
serviceOrderMapper.insert(serviceOrder); |
|
110 |
|
|
111 |
//保存优惠信息 |
|
112 |
if(serviceOrderDiscountLog != null){ |
|
113 |
serviceOrderDiscountLog.setServiceOrderId(serviceOrder.getId()); |
|
114 |
commonDao.insert(ServiceOrderDiscountLogMapper.class,serviceOrderDiscountLog); |
|
115 |
} |
|
116 |
|
|
117 |
//子订单 |
|
118 |
item.setOrderId(serviceOrder.getId()); |
|
119 |
commonDao.insert(ServiceOrderItemMapper.class,item); |
|
120 |
|
|
121 |
CreateServiceOrderLog.createLog(serviceOrder.getId(), |
|
122 |
ServiceOrderLog.LOG_TYPE_CREATE,"用户创建订单",user.getUserName(),commonDao); |
|
123 |
|
|
124 |
} |
|
125 |
|
|
126 |
/**修改*/ |
|
127 |
@Override |
|
128 |
public void updateAll(ServiceOrder serviceOrder) { |
|
129 |
int count = serviceOrderMapper.updateAll(serviceOrder); |
|
130 |
if(count!=1) { |
|
131 |
throw new TipsException("保存失败!"); |
|
132 |
} |
|
133 |
} |
|
134 |
|
|
135 |
/**核销订单*/ |
|
136 |
@Override |
|
137 |
public void writeOff(ServiceOrder serviceOrder,ShopPersonal shopPersonal) { |
|
138 |
|
|
139 |
SqlSentence sqlSentence = new SqlSentence(); |
|
140 |
Map<String,Object> values = new HashMap<>(); |
|
141 |
|
|
142 |
values.put("id",serviceOrder.getId()); |
|
143 |
values.put("status",ServiceOrder.STATUS_DONE); |
|
144 |
values.put("status2",ServiceOrder.STATUS_WAIT_SERVICE); |
|
145 |
sqlSentence.sqlUpdate("status = #{m.status} WHERE id = #{m.id} AND status = #{m.status2}",values); |
|
146 |
|
|
147 |
int count = serviceOrderMapper.updateWhere(sqlSentence); |
|
148 |
if(count!=1) { |
|
149 |
throw new TipsException("核销失败!"); |
|
150 |
} |
|
151 |
|
|
152 |
CreateServiceOrderLog.createLog(serviceOrder.getId(), |
|
153 |
ServiceOrderLog.LOG_TYPE_WRITE,"店铺核销订单",shopPersonal.getAccount()+"["+shopPersonal.getName()+"]",commonDao); |
|
154 |
|
|
155 |
//用户到店时间更新 |
|
156 |
ServiceOrderTool.userToShop(serviceOrder,commonDao); |
|
157 |
|
|
158 |
//统计数据 |
|
159 |
TimerOrderDataTool.add(serviceOrder.getUserId(),TimerOrderData.TYPE_SERVICE_ORDER_WRITE,1,serviceOrder.getActualTotal(),new Date(),serviceOrder.getId(),commonDao); |
|
160 |
|
|
161 |
Shop shop = commonDao.selectOneByKey(ShopMapper.class,serviceOrder.getShopId()); |
|
162 |
|
|
163 |
//店铺钱包变化 |
|
164 |
ShopWalletTool.walletHandle(shop,serviceOrder.getActualTotal(),serviceOrder.getActualTotal(),"店铺核销", ShopWalletLog.LOG_TYPE_SERVICE_DONE |
|
165 |
,serviceOrder.getId(),shopPersonal.getAccount()+"【"+shopPersonal.getName()+"】",commonDao); |
|
166 |
|
|
167 |
} |
|
168 |
|
|
169 |
/**修改备注*/ |
|
170 |
@Override |
|
171 |
public void updateRemark(ServiceOrder serviceOrder,ShopPersonal shopPersonal,String personalRemark) { |
|
172 |
|
|
173 |
SqlSentence sqlSentence = new SqlSentence(); |
|
174 |
Map<String,Object> values = new HashMap<>(); |
|
175 |
|
|
176 |
values.put("personalRemark",personalRemark); |
|
177 |
values.put("id",serviceOrder.getId()); |
|
178 |
sqlSentence.sqlUpdate("personalRemark = #{m.personalRemark} WHERE id = #{m.id}",values); |
|
179 |
int count = serviceOrderMapper.updateWhere(sqlSentence); |
|
180 |
if(count!=1) { |
|
181 |
throw new TipsException("保存失败!"); |
|
182 |
} |
|
183 |
CreateServiceOrderLog.createLog(serviceOrder.getId(), |
|
184 |
ServiceOrderLog.LOG_TYPE_ADD_REMARK,"店铺添加备注",shopPersonal.getAccount()+"["+shopPersonal.getName()+"]",commonDao); |
|
185 |
|
|
186 |
} |
|
187 |
|
|
188 |
/**确认*/ |
|
189 |
@Override |
|
190 |
public void confirm(ServiceOrder serviceOrder,ShopPersonal shopPersonal) { |
|
191 |
|
|
192 |
SqlSentence sqlSentence = new SqlSentence(); |
|
193 |
Map<String,Object> values = new HashMap<>(); |
|
194 |
|
|
195 |
values.put("status",ServiceOrder.STATUS_WAIT_SERVICE); |
|
196 |
values.put("status0",ServiceOrder.STATUS_WAIT_CONFIRM); |
|
197 |
values.put("id",serviceOrder.getId()); |
|
198 |
sqlSentence.sqlUpdate("status = #{m.status} WHERE id = #{m.id} AND status = #{m.status0}",values); |
|
199 |
int count = serviceOrderMapper.updateWhere(sqlSentence); |
|
200 |
if(count!=1) { |
|
201 |
throw new TipsException("保存失败!"); |
|
202 |
} |
|
203 |
CreateServiceOrderLog.createLog(serviceOrder.getId(), |
|
204 |
ServiceOrderLog.LOG_TYPE_CONFIRM,"店铺确认订单",shopPersonal.getAccount()+"["+shopPersonal.getName()+"]",commonDao); |
|
205 |
|
|
206 |
} |
|
207 |
|
|
208 |
@Override |
|
209 |
public void cancelConfirm(ServiceOrder serviceOrder, ShopPersonal shopPersonal, Integer type) { |
|
210 |
|
|
211 |
if(type == 1) { |
|
212 |
//同意取消 |
|
213 |
//订单状态修改 |
|
214 |
SqlSentence sqlSentence = new SqlSentence(); |
|
215 |
Map<String, Object> sqlMap = new HashMap<>(); |
|
216 |
sqlMap.put("status", ServiceOrder.STATUS_CANCEL); |
|
217 |
sqlMap.put("id", serviceOrder.getId()); |
|
218 |
sqlMap.put("userId", serviceOrder.getUserId()); |
|
219 |
sqlMap.put("cancelTime", new Date()); |
|
220 |
sqlMap.put("status11", ServiceOrder.STATUS_CANCEL_WAIT); |
|
221 |
sqlSentence.sqlUpdate("cancelTime = #{m.cancelTime},status = #{m.status} WHERE id = #{m.id}" + |
|
222 |
" AND userId = #{m.userId} AND status = #{m.status11} ", sqlMap); |
|
223 |
if (serviceOrderMapper.updateWhere(sqlSentence) != 1) { |
|
224 |
throw new TipsException("取消失败!"); |
|
225 |
} |
|
226 |
|
|
227 |
//生成订单日志 |
|
228 |
CreateServiceOrderLog.createLog(serviceOrder.getId(), |
|
229 |
ServiceOrderLog.LOG_TYPE_CANCEL_APPLY, "工作人员确认取消订单", shopPersonal.getName(), commonDao); |
|
230 |
|
|
231 |
|
|
232 |
//已经支付的订单 |
|
233 |
if (serviceOrder.getPayStatus() == ServiceOrder.PAY_STATUS_SUC) { |
|
234 |
//统计数据 |
|
235 |
TimerOrderDataTool.add(serviceOrder.getUserId(), TimerOrderData.TYPE_SERVICE_ORDER_CANCEL, -1, -serviceOrder.getActualTotal(), serviceOrder.getCreateTime(), serviceOrder.getId(), commonDao); |
|
236 |
|
|
237 |
//开始退款 |
|
238 |
boolean refundStatus = ServiceOrderTool.orderRefund(shopPersonal.getAccount() + "[" + shopPersonal.getName() + "]", serviceOrder, serviceOrder.getPayTotal() |
|
239 |
, systemConfig.getAppId(), systemConfig.getMchId(), systemConfig.getMchKey(), systemConfig.getMchCertPath(), commonDao); |
|
240 |
if (!refundStatus) { |
|
241 |
throw new ServiceException("取消失败"); |
|
242 |
} |
|
243 |
} |
|
244 |
}else if(type == 2){ |
|
245 |
//拒绝取消 |
|
246 |
//订单状态修改 |
|
247 |
SqlSentence sqlSentence = new SqlSentence(); |
|
248 |
Map<String, Object> sqlMap = new HashMap<>(); |
|
249 |
sqlMap.put("status", serviceOrder.getCancelBeforeStatus()); |
|
250 |
sqlMap.put("id", serviceOrder.getId()); |
|
251 |
sqlMap.put("userId", serviceOrder.getUserId()); |
|
252 |
sqlMap.put("cancelTime", new Date()); |
|
253 |
sqlMap.put("status11", ServiceOrder.STATUS_CANCEL_WAIT); |
|
254 |
sqlSentence.sqlUpdate("cancelTime = #{m.cancelTime},status = #{m.status} WHERE id = #{m.id}" + |
|
255 |
" AND userId = #{m.userId} AND status = #{m.status11} ", sqlMap); |
|
256 |
if (serviceOrderMapper.updateWhere(sqlSentence) != 1) { |
|
257 |
throw new TipsException("取消失败!"); |
|
258 |
} |
|
259 |
|
|
260 |
//生成订单日志 |
|
261 |
CreateServiceOrderLog.createLog(serviceOrder.getId(), |
|
262 |
ServiceOrderLog.LOG_TYPE_CANCEL_APPLY, "工作人员拒绝取消订单", shopPersonal.getName(), commonDao); |
|
263 |
} |
|
264 |
} |
|
265 |
|
|
266 |
/**修改*/ |
|
267 |
@Override |
|
268 |
public void updateWhere(SqlSentence sqlSentence) { |
|
269 |
int count = serviceOrderMapper.updateWhere(sqlSentence); |
|
270 |
if(count!=1) { |
|
271 |
throw new TipsException("保存失败!"); |
|
272 |
} |
|
273 |
} |
|
274 |
|
|
275 |
/**删除一个*/ |
|
276 |
@Override |
|
277 |
public void deleteOne(String delId) { |
|
278 |
int count = serviceOrderMapper.deleteById(delId); |
|
279 |
if(count!=1) { |
|
280 |
throw new TipsException("删除失败!"); |
|
281 |
} |
|
282 |
} |
|
283 |
|
|
284 |
/**查询条数*/ |
|
285 |
@Override |
|
286 |
public int selectCount(SqlSentence sqlSentence) { |
|
287 |
int count = serviceOrderMapper.selectCount(sqlSentence); |
|
288 |
return count; |
|
289 |
} |
|
290 |
|
|
291 |
|
|
292 |
/**用户取消*/ |
|
293 |
@Override |
|
294 |
public void orderCancel(User user,ServiceOrder serviceOrder) { |
|
295 |
|
|
296 |
Shop shop = shopMapper.selectOneByKey(serviceOrder.getShopId()); |
|
297 |
if(shop == null) |
|
298 |
{ |
|
299 |
throw new RuntimeException("找不到门店订单"); |
|
300 |
} |
|
301 |
|
|
302 |
if(shop.getIsDirCancel() == BaseEntity.YES) { |
|
303 |
//订单状态修改 |
|
304 |
SqlSentence sqlSentence = new SqlSentence(); |
|
305 |
Map<String, Object> sqlMap = new HashMap<>(); |
|
306 |
sqlMap.put("status", ServiceOrder.STATUS_CANCEL); |
|
307 |
sqlMap.put("id", serviceOrder.getId()); |
|
308 |
sqlMap.put("userId", user.getId()); |
|
309 |
sqlMap.put("cancelTime", new Date()); |
|
310 |
sqlMap.put("status11", ServiceOrder.STATUS_WAIT_PAY); |
|
311 |
sqlMap.put("status0", ServiceOrder.STATUS_WAIT_CONFIRM); |
|
312 |
sqlMap.put("status2", ServiceOrder.STATUS_WAIT_SERVICE); |
|
313 |
sqlSentence.sqlUpdate("cancelTime = #{m.cancelTime},status = #{m.status} WHERE id = #{m.id}" + |
|
314 |
" AND userId = #{m.userId} AND (status = #{m.status11} OR status = #{m.status0} OR status = #{m.status2})", sqlMap); |
|
315 |
if (serviceOrderMapper.updateWhere(sqlSentence) != 1) { |
|
316 |
throw new TipsException("取消失败!"); |
|
317 |
} |
|
318 |
|
|
319 |
//生成订单日志 |
|
320 |
CreateServiceOrderLog.createLog(serviceOrder.getId(), |
|
321 |
ServiceOrderLog.LOG_TYPE_CANCEL_APPLY, "用户取消订单", user.getUserName(), commonDao); |
|
322 |
|
|
323 |
|
|
324 |
//已经支付的订单 |
|
325 |
if (serviceOrder.getPayStatus() == ServiceOrder.PAY_STATUS_SUC) { |
|
326 |
//统计数据 |
|
327 |
TimerOrderDataTool.add(serviceOrder.getUserId(), TimerOrderData.TYPE_SERVICE_ORDER_CANCEL, -1, -serviceOrder.getActualTotal(), serviceOrder.getCreateTime(), serviceOrder.getId(), commonDao); |
|
328 |
|
|
329 |
//开始退款 |
|
330 |
boolean refundStatus = ServiceOrderTool.orderRefund(user.getUserNo() + "[" + user.getUserName() + "]", serviceOrder, serviceOrder.getPayTotal() |
|
331 |
, systemConfig.getAppId(), systemConfig.getMchId(), systemConfig.getMchKey(), systemConfig.getMchCertPath(), commonDao); |
|
332 |
if (!refundStatus) { |
|
333 |
throw new ServiceException("取消失败,请联系店铺!"); |
|
334 |
} |
|
335 |
} |
|
336 |
}else{ |
|
337 |
//订单状态修改 |
|
338 |
SqlSentence sqlSentence = new SqlSentence(); |
|
339 |
Map<String, Object> sqlMap = new HashMap<>(); |
|
340 |
sqlMap.put("status", ServiceOrder.STATUS_CANCEL_WAIT); |
|
341 |
sqlMap.put("cancelBeforeStatus", serviceOrder.getStatus()); |
|
342 |
sqlMap.put("id", serviceOrder.getId()); |
|
343 |
sqlMap.put("userId", user.getId()); |
|
344 |
sqlMap.put("cancelTime", new Date()); |
|
345 |
sqlMap.put("status11", ServiceOrder.STATUS_WAIT_PAY); |
|
346 |
sqlMap.put("status0", ServiceOrder.STATUS_WAIT_CONFIRM); |
|
347 |
sqlMap.put("status2", ServiceOrder.STATUS_WAIT_SERVICE); |
|
348 |
sqlSentence.sqlUpdate("cancelBeforeStatus = #{m.cancelBeforeStatus}, cancelTime = #{m.cancelTime},status = #{m.status} WHERE id = #{m.id}" + |
|
349 |
" AND userId = #{m.userId} AND (status = #{m.status11} OR status = #{m.status0} OR status = #{m.status2})", sqlMap); |
|
350 |
if (serviceOrderMapper.updateWhere(sqlSentence) != 1) { |
|
351 |
throw new TipsException("申请取消失败!"); |
|
352 |
} |
|
353 |
|
|
354 |
//生成订单日志 |
|
355 |
CreateServiceOrderLog.createLog(serviceOrder.getId(), |
|
356 |
ServiceOrderLog.LOG_TYPE_CANCEL_APPLY, "用户申请取消订单", user.getUserName(), commonDao); |
|
357 |
} |
|
358 |
|
|
359 |
} |
|
360 |
|
|
361 |
/**店铺取消*/ |
|
362 |
@Override |
|
363 |
public void shopCancel(ShopPersonal shopPersonal, ServiceOrder serviceOrder,String cancelInfo) { |
|
364 |
|
|
365 |
//没有支付订单直接取消 |
|
366 |
SqlSentence sqlSentence = new SqlSentence(); |
|
367 |
Map<String,Object> sqlMap = new HashMap<>(); |
|
368 |
sqlMap.put("status",ServiceOrder.STATUS_CANCEL); |
|
369 |
sqlMap.put("id",serviceOrder.getId()); |
|
370 |
sqlMap.put("shopId",shopPersonal.getShopId()); |
|
371 |
sqlMap.put("cancelTime",new Date()); |
|
372 |
sqlMap.put("cancelInfo",cancelInfo); |
|
373 |
sqlMap.put("cancelType",ServiceOrder.CANCEL_TYPE_CORP_USER); |
|
374 |
sqlMap.put("status11",ServiceOrder.STATUS_WAIT_PAY); |
|
375 |
sqlMap.put("status0",ServiceOrder.STATUS_WAIT_CONFIRM); |
|
376 |
sqlMap.put("status2",ServiceOrder.STATUS_WAIT_SERVICE); |
|
377 |
sqlSentence.sqlUpdate("cancelTime = #{m.cancelTime},cancelInfo = #{m.cancelInfo},cancelType = #{m.cancelType},status = #{m.status} WHERE id = #{m.id}" + |
|
378 |
" AND shopId = #{m.shopId} AND (status = #{m.status11} OR status = #{m.status0} OR status = #{m.status2})",sqlMap); |
|
379 |
if(serviceOrderMapper.updateWhere(sqlSentence)!=1){ |
|
380 |
throw new TipsException("取消失败!"); |
|
381 |
} |
|
382 |
|
|
383 |
//生成订单日志 |
|
384 |
CreateServiceOrderLog.createLog(serviceOrder.getId(), |
|
385 |
ServiceOrderLog.LOG_TYPE_CANCEL_APPLY,"店铺取消订单",shopPersonal.getAccount()+"["+shopPersonal.getName()+"]",commonDao); |
|
386 |
|
|
387 |
|
|
388 |
//已经支付的订单 |
|
389 |
if(serviceOrder.getPayStatus() == ServiceOrder.PAY_STATUS_SUC){ |
|
390 |
//统计数据 |
|
391 |
TimerOrderDataTool.add(serviceOrder.getUserId(),TimerOrderData.TYPE_SERVICE_ORDER_CANCEL,-1,-serviceOrder.getActualTotal(),serviceOrder.getCreateTime(),serviceOrder.getId(),commonDao); |
|
392 |
|
|
393 |
//开始退款 |
|
394 |
boolean refundStatus = ServiceOrderTool.orderRefund(shopPersonal.getAccount()+"["+shopPersonal.getName()+"]",serviceOrder,serviceOrder.getPayTotal() |
|
395 |
,systemConfig.getAppId(),systemConfig.getMchId(),systemConfig.getMchKey(),systemConfig.getMchCertPath(),commonDao); |
|
396 |
if(!refundStatus){ |
|
397 |
throw new ServiceException("取消失败,请联系管理员!"); |
|
398 |
} |
|
399 |
|
|
400 |
} |
|
401 |
|
|
402 |
} |
|
403 |
|
|
404 |
/**定时取消取消*/ |
|
405 |
@Override |
|
406 |
public void autoCancel(ServiceOrder serviceOrder) { |
|
407 |
|
|
408 |
//订单状态修改 |
|
409 |
SqlSentence sqlSentence = new SqlSentence(); |
|
410 |
Map<String,Object> sqlMap = new HashMap<>(); |
|
411 |
sqlMap.put("status",ServiceOrder.STATUS_CANCEL); |
|
412 |
sqlMap.put("payStatus",ServiceOrder.PAY_STATUS_WAIT); |
|
413 |
sqlMap.put("id",serviceOrder.getId()); |
|
414 |
sqlMap.put("cancelTime",new Date()); |
|
415 |
sqlMap.put("status11",ServiceOrder.STATUS_WAIT_PAY); |
|
416 |
sqlSentence.sqlUpdate("cancelTime = #{m.cancelTime},status = #{m.status} WHERE id = #{m.id} AND status = #{m.status11} AND payStatus = #{m.payStatus}",sqlMap); |
|
417 |
if(serviceOrderMapper.updateWhere(sqlSentence)!=1){ |
|
418 |
throw new TipsException("取消失败!"); |
|
419 |
} |
|
420 |
|
|
421 |
//生成订单日志 |
|
422 |
CreateServiceOrderLog.createLog(serviceOrder.getId(), |
|
423 |
ServiceOrderLog.LOG_TYPE_CANCEL_AUTO,"24小时未支付取消订单","系统自动",commonDao); |
|
424 |
|
|
425 |
} |
|
426 |
|
|
427 |
/**微信小程序支付回调(服务订单) |
|
428 |
* @param serviceOrder 支付的订单 |
|
429 |
* @param user 支付的用户 |
|
430 |
* @param payTime 支付时间 |
|
431 |
* @param payTotal 支付金额 |
|
432 |
* @param wxOrderNo 微信支付号 |
|
433 |
* @param wxMsgXml 支付返回的数据 |
|
434 |
*/ |
|
435 |
@Override |
|
436 |
public void wxPayNotify(ServiceOrder serviceOrder, User user, Date payTime, Double payTotal, |
|
437 |
String wxOrderNo, String wxMsgXml) { |
|
438 |
|
|
439 |
//修改订单状态 |
|
440 |
SqlSentence sqlSentence = new SqlSentence(); |
|
441 |
Map<String,Object> sqlMap = new HashMap<>(); |
|
442 |
sqlMap.put("payStatus",ServiceOrder.PAY_STATUS_SUC); |
|
443 |
if(serviceOrder.getIsPre() == ServiceOrder.YES){ |
|
444 |
sqlMap.put("status",ServiceOrder.STATUS_WAIT_CONFIRM); |
|
445 |
}else{ |
|
446 |
sqlMap.put("status",ServiceOrder.STATUS_WAIT_SERVICE); |
|
447 |
} |
|
448 |
sqlMap.put("payStatusF",ServiceOrder.PAY_STATUS_SUC); |
|
449 |
sqlMap.put("payTime",payTime); |
|
450 |
sqlMap.put("payNo",wxOrderNo); |
|
451 |
sqlMap.put("id",serviceOrder.getId()); |
|
452 |
sqlSentence.sqlUpdate("payNo = #{m.payNo},payStatus = #{m.payStatus},payTime = #{m.payTime},status = #{m.status} WHERE id = #{m.id} AND payStatus != #{m.payStatusF}",sqlMap); |
|
453 |
if(serviceOrderMapper.updateWhere(sqlSentence)!=1){ |
|
454 |
throw new RuntimeException("回调失败,order is null"); |
|
455 |
} |
|
456 |
|
|
457 |
//生成支付记录 |
|
458 |
PayRecord payRecord = new PayRecord(PayRecord.ORDER_TYPE_SERVICE_ADD,serviceOrder.getId(),payTotal |
|
459 |
,serviceOrder.getOrderNo(),wxOrderNo,user.getId(),user.getOpenId(),user.getUserName(),wxMsgXml); |
|
460 |
if(payRecordMapper.insert(payRecord)!=1){ |
|
461 |
throw new RuntimeException("回调失败,insert pay record error!"); |
|
462 |
} |
|
463 |
|
|
464 |
//生成订单日志 |
|
465 |
CreateServiceOrderLog.createLog(serviceOrder.getId(), |
|
466 |
ServiceOrderLog.LOG_TYPE_PAY,"服务项目订单支付",user.getUserName(),commonDao); |
|
467 |
|
|
468 |
//统计数据 |
|
469 |
TimerOrderDataTool.add(serviceOrder.getUserId(),TimerOrderData.TYPE_SERVICE_ORDER_ADD,1,serviceOrder.getActualTotal(),serviceOrder.getCreateTime(),serviceOrder.getId(),commonDao); |
|
470 |
|
|
471 |
//生成ipad订单页面二维码 |
|
472 |
/*String imgUrl = null; |
|
473 |
try{ |
|
474 |
BufferedImage bi = QRCodeUtil.getBufferedImage(PathConfige.IPAD_MP_ORDER_DETAIL+ serviceProjectOrder.getId(), 250, null); |
|
475 |
ByteArrayOutputStream os = new ByteArrayOutputStream(); |
|
476 |
ImageIO.write(bi, "jpg", os); |
|
477 |
InputStream is = new ByteArrayInputStream(os.toByteArray()); |
|
478 |
|
|
479 |
imgUrl = OSSUtil.uploadImg(Constants.FILE_URL_QRCODE + UUID.randomUUID().toString() + ".jpg", is, systemConfig.getOssKeyId(), systemConfig.getOssKeySecret(), systemConfig.getOssEndPoint(), systemConfig.getOssBucket()); |
|
480 |
}catch (Exception e){ |
|
481 |
e.printStackTrace(); |
|
482 |
} |
|
483 |
|
|
484 |
sqlMap.clear(); |
|
485 |
sqlMap.put("twoCodeImg",imgUrl); |
|
486 |
sqlMap.put("id",serviceProjectOrder.getId()); |
|
487 |
sqlParam.sqlUpdate("twoCodeImg = #{m.twoCodeImg} WHERE id = #{m.id}",sqlMap); |
|
488 |
serviceProjectOrderMapper.updateWhere(sqlParam); |
|
489 |
*/ |
|
490 |
|
|
491 |
} |
|
492 |
|
|
493 |
} |