Commit cd9470c7 authored by Menethil's avatar Menethil
Browse files

添加退款通知用户,退款申请通知管理员,发货通知用户

修复AdminOrder参数处理类型错误
parent 3ccc4298
...@@ -3,6 +3,8 @@ package org.linlinjava.litemall.admin.web; ...@@ -3,6 +3,8 @@ package org.linlinjava.litemall.admin.web;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.admin.annotation.LoginAdmin; import org.linlinjava.litemall.admin.annotation.LoginAdmin;
import org.linlinjava.litemall.core.notify.LitemallNotifyService;
import org.linlinjava.litemall.core.notify.util.ConfigUtil;
import org.linlinjava.litemall.core.util.JacksonUtil; import org.linlinjava.litemall.core.util.JacksonUtil;
import org.linlinjava.litemall.db.domain.*; import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.service.LitemallOrderGoodsService; import org.linlinjava.litemall.db.service.LitemallOrderGoodsService;
...@@ -43,16 +45,19 @@ public class AdminOrderController { ...@@ -43,16 +45,19 @@ public class AdminOrderController {
@Autowired @Autowired
private LitemallUserService userService; private LitemallUserService userService;
@Autowired
private LitemallNotifyService litemallNotifyService;
@GetMapping("/list") @GetMapping("/list")
public Object list(@LoginAdmin Integer adminId, public Object list(@LoginAdmin Integer adminId,
Integer userId, String orderSn, @RequestParam(required = false, value = "orderStatusArray[]")List<Short> orderStatusArray, Integer userId, String orderSn, @RequestParam(required = false, value = "orderStatusArray[]") List<Short> orderStatusArray,
@RequestParam(value = "page", defaultValue = "1") Integer page, @RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "limit", defaultValue = "10") Integer limit, @RequestParam(value = "limit", defaultValue = "10") Integer limit,
String sort, String order){ String sort, String order) {
if(adminId == null){ if (adminId == null) {
return ResponseUtil.unlogin(); return ResponseUtil.unlogin();
} }
List<LitemallOrder> orderList = orderService.querySelective(userId, orderSn,orderStatusArray, page, limit, sort, order); List<LitemallOrder> orderList = orderService.querySelective(userId, orderSn, orderStatusArray, page, limit, sort, order);
int total = orderService.countSelective(userId, orderSn, orderStatusArray, page, limit, sort, order); int total = orderService.countSelective(userId, orderSn, orderStatusArray, page, limit, sort, order);
Map<String, Object> data = new HashMap<>(); Map<String, Object> data = new HashMap<>();
...@@ -64,7 +69,7 @@ public class AdminOrderController { ...@@ -64,7 +69,7 @@ public class AdminOrderController {
@GetMapping("/detail") @GetMapping("/detail")
public Object detail(@LoginAdmin Integer adminId, Integer id) { public Object detail(@LoginAdmin Integer adminId, Integer id) {
if(adminId == null){ if (adminId == null) {
return ResponseUtil.unlogin(); return ResponseUtil.unlogin();
} }
...@@ -86,7 +91,7 @@ public class AdminOrderController { ...@@ -86,7 +91,7 @@ public class AdminOrderController {
* 3. 订单商品恢复 * 3. 订单商品恢复
* *
* @param adminId 管理员ID * @param adminId 管理员ID
* @param body 订单信息,{ orderId:xxx } * @param body 订单信息,{ orderId:xxx }
* @return 订单操作结果 * @return 订单操作结果
* 成功则 { errno: 0, errmsg: '成功' } * 成功则 { errno: 0, errmsg: '成功' }
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
...@@ -97,7 +102,7 @@ public class AdminOrderController { ...@@ -97,7 +102,7 @@ public class AdminOrderController {
return ResponseUtil.unlogin(); return ResponseUtil.unlogin();
} }
Integer orderId = JacksonUtil.parseInteger(body, "orderId"); Integer orderId = JacksonUtil.parseInteger(body, "orderId");
Integer refundMoney = JacksonUtil.parseInteger(body, "refundMoney"); String refundMoney = JacksonUtil.parseString(body, "refundMoney");
if (orderId == null) { if (orderId == null) {
return ResponseUtil.badArgument(); return ResponseUtil.badArgument();
} }
...@@ -107,7 +112,7 @@ public class AdminOrderController { ...@@ -107,7 +112,7 @@ public class AdminOrderController {
return ResponseUtil.badArgument(); return ResponseUtil.badArgument();
} }
if(order.getActualPrice().compareTo(new BigDecimal(refundMoney)) != 0){ if (order.getActualPrice().compareTo(new BigDecimal(refundMoney)) != 0) {
return ResponseUtil.badArgumentValue(); return ResponseUtil.badArgumentValue();
} }
...@@ -139,6 +144,18 @@ public class AdminOrderController { ...@@ -139,6 +144,18 @@ public class AdminOrderController {
logger.error("系统内部错误", ex); logger.error("系统内部错误", ex);
return ResponseUtil.fail(403, "订单退款失败"); return ResponseUtil.fail(403, "订单退款失败");
} }
//TODO 发送邮件和短信通知,这里采用异步发送
// 退款成功通知用户
/**
*
* 您申请的订单退款 [ 单号:{1} ] 已成功,请耐心等待到账。
* 注意订单号只发后6位
*
*/
litemallNotifyService.notifySMSTemplate(order.getMobile(), ConfigUtil.NotifyType.REFUND, new String[]{order.getOrderSn().substring(8, 14)});
txManager.commit(status); txManager.commit(status);
return ResponseUtil.ok(); return ResponseUtil.ok();
...@@ -150,7 +167,7 @@ public class AdminOrderController { ...@@ -150,7 +167,7 @@ public class AdminOrderController {
* 2. 设置订单发货状态 * 2. 设置订单发货状态
* *
* @param adminId 管理员ID * @param adminId 管理员ID
* @param body 订单信息,{ orderId:xxx, shipSn: xxx, shipChannel: xxx } * @param body 订单信息,{ orderId:xxx, shipSn: xxx, shipChannel: xxx }
* @return 订单操作结果 * @return 订单操作结果
* 成功则 { errno: 0, errmsg: '成功' } * 成功则 { errno: 0, errmsg: '成功' }
* 失败则 { errno: XXX, errmsg: XXX } * 失败则 { errno: XXX, errmsg: XXX }
...@@ -183,29 +200,38 @@ public class AdminOrderController { ...@@ -183,29 +200,38 @@ public class AdminOrderController {
order.setShipTime(LocalDateTime.now()); order.setShipTime(LocalDateTime.now());
orderService.update(order); orderService.update(order);
//TODO 发送邮件和短信通知,这里采用异步发送
// 发货会发送通知短信给用户
/**
*
* 您的订单已经发货,快递公司 {1},快递单 {2} ,请注意查收
*
*/
litemallNotifyService.notifySMSTemplate(order.getMobile(), ConfigUtil.NotifyType.SHIP, new String[]{shipChannel, shipSn});
return ResponseUtil.ok(); return ResponseUtil.ok();
} }
/** /**
* 自动取消订单 * 自动取消订单
* * <p>
* 定时检查订单未付款情况,如果超时半个小时则自动取消订单 * 定时检查订单未付款情况,如果超时半个小时则自动取消订单
* 定时时间是每次相隔半个小时。 * 定时时间是每次相隔半个小时。
* * <p>
* 注意,因为是相隔半小时检查,因此导致有订单是超时一个小时以后才设置取消状态。 * 注意,因为是相隔半小时检查,因此导致有订单是超时一个小时以后才设置取消状态。
* TODO * TODO
* 这里可以进一步地配合用户订单查询时订单未付款检查,如果订单超时半小时则取消。 * 这里可以进一步地配合用户订单查询时订单未付款检查,如果订单超时半小时则取消。
*/ */
@Scheduled(fixedDelay = 30*60*1000) @Scheduled(fixedDelay = 30 * 60 * 1000)
public void checkOrderUnpaid() { public void checkOrderUnpaid() {
logger.debug(LocalDateTime.now()); logger.debug(LocalDateTime.now());
List<LitemallOrder> orderList = orderService.queryUnpaid(); List<LitemallOrder> orderList = orderService.queryUnpaid();
for(LitemallOrder order : orderList){ for (LitemallOrder order : orderList) {
LocalDateTime add = order.getAddTime(); LocalDateTime add = order.getAddTime();
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
LocalDateTime expired = add.plusMinutes(30); LocalDateTime expired = add.plusMinutes(30);
if(expired.isAfter(now)){ if (expired.isAfter(now)) {
continue; continue;
} }
...@@ -239,15 +265,15 @@ public class AdminOrderController { ...@@ -239,15 +265,15 @@ public class AdminOrderController {
/** /**
* 自动确认订单 * 自动确认订单
* * <p>
* 定时检查订单未确认情况,如果超时七天则自动确认订单 * 定时检查订单未确认情况,如果超时七天则自动确认订单
* 定时时间是每天凌晨3点。 * 定时时间是每天凌晨3点。
* * <p>
* 注意,因为是相隔一天检查,因此导致有订单是超时八天以后才设置自动确认。 * 注意,因为是相隔一天检查,因此导致有订单是超时八天以后才设置自动确认。
* 这里可以进一步地配合用户订单查询时订单未确认检查,如果订单超时7天则自动确认。 * 这里可以进一步地配合用户订单查询时订单未确认检查,如果订单超时7天则自动确认。
* 但是,这里可能不是非常必要。相比订单未付款检查中存在商品资源有限所以应该 * 但是,这里可能不是非常必要。相比订单未付款检查中存在商品资源有限所以应该
* 早点清理未付款情况,这里八天再确认是可以的。 * 早点清理未付款情况,这里八天再确认是可以的。
* * <p>
* TODO * TODO
* 目前自动确认是基于管理后台管理员所设置的商品快递时间,见orderService.queryUnconfirm。 * 目前自动确认是基于管理后台管理员所设置的商品快递时间,见orderService.queryUnconfirm。
* 那么在实际业务上有可能存在商品寄出以后商品因为一些原因快递最终没有到达, * 那么在实际业务上有可能存在商品寄出以后商品因为一些原因快递最终没有到达,
...@@ -259,11 +285,11 @@ public class AdminOrderController { ...@@ -259,11 +285,11 @@ public class AdminOrderController {
logger.debug(LocalDateTime.now()); logger.debug(LocalDateTime.now());
List<LitemallOrder> orderList = orderService.queryUnconfirm(); List<LitemallOrder> orderList = orderService.queryUnconfirm();
for(LitemallOrder order : orderList){ for (LitemallOrder order : orderList) {
LocalDateTime ship = order.getShipTime(); LocalDateTime ship = order.getShipTime();
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
LocalDateTime expired = ship.plusDays(7); LocalDateTime expired = ship.plusDays(7);
if(expired.isAfter(now)){ if (expired.isAfter(now)) {
continue; continue;
} }
// 设置订单已取消状态 // 设置订单已取消状态
......
...@@ -7,6 +7,7 @@ public class ConfigUtil { ...@@ -7,6 +7,7 @@ public class ConfigUtil {
/** /**
* 通过枚举获取对应的 templateId,注意 application.yaml 里字段名必须一致 * 通过枚举获取对应的 templateId,注意 application.yaml 里字段名必须一致
*
* @param notifyType * @param notifyType
* @param values * @param values
* @return * @return
...@@ -23,16 +24,20 @@ public class ConfigUtil { ...@@ -23,16 +24,20 @@ public class ConfigUtil {
/** /**
* 该处字符串对应 application.yaml 里 template.name 的值,请注意 * 该处字符串对应 application.yaml 里 template.name 的值,请注意
*
* @param notifyType * @param notifyType
* @return * @return
*/ */
private static String getNotifyType(NotifyType notifyType) private static String getNotifyType(NotifyType notifyType) {
{
switch (notifyType) { switch (notifyType) {
case PAY_SUCCEED: case PAY_SUCCEED:
return "paySucceed"; return "paySucceed";
case CAPTCHA: case CAPTCHA:
return "captcha"; return "captcha";
case SHIP:
return "ship";
case REFUND:
return "refund";
} }
return ""; return "";
...@@ -40,12 +45,14 @@ public class ConfigUtil { ...@@ -40,12 +45,14 @@ public class ConfigUtil {
/** /**
* 该枚举定义了所有的需要通知的事件,调用通知时作为参数 * 该枚举定义了所有的需要通知的事件,调用通知时作为参数
* * <p>
* PAY_SUCCEED 支付成功,通常用于用户支付成功 * PAY_SUCCEED 支付成功,通常用于用户支付成功
* CAPTCHA 验证码,通常用于登录、注册、找回密码 * CAPTCHA 验证码,通常用于登录、注册、找回密码
*/ */
public enum NotifyType { public enum NotifyType {
PAY_SUCCEED, PAY_SUCCEED,
SHIP,
REFUND,
CAPTCHA CAPTCHA
} }
} }
...@@ -18,6 +18,11 @@ SMSNotifyConfig: ...@@ -18,6 +18,11 @@ SMSNotifyConfig:
templateId: 156349 templateId: 156349
- name: captcha - name: captcha
templateId: 156433 templateId: 156433
- name: ship
templateId: 158002
- name: refund
templateId: 159447
# 微信模版通知配置 # 微信模版通知配置
# 微信模版用于通知客户或者运营者,注意配置格式;template-name,template-templateId 请参考 ConfigUtil 内枚举值 # 微信模版用于通知客户或者运营者,注意配置格式;template-name,template-templateId 请参考 ConfigUtil 内枚举值
......
...@@ -554,7 +554,11 @@ public class WxOrderController { ...@@ -554,7 +554,11 @@ public class WxOrderController {
//TODO 发送邮件和短信通知,这里采用异步发送 //TODO 发送邮件和短信通知,这里采用异步发送
// 订单支付成功以后,会发送短信给用户,以及发送邮件给管理员 // 订单支付成功以后,会发送短信给用户,以及发送邮件给管理员
litemallNotifyService.notifyMailMessage("新订单通知", order.toString()); litemallNotifyService.notifyMailMessage("新订单通知", order.toString());
litemallNotifyService.notifySMSTemplate(order.getMobile(), ConfigUtil.NotifyType.PAY_SUCCEED, new String[]{orderSn}); /**
* 这里微信的短信平台对参数长度有限制,所以将订单号只截取后6位
*
*/
litemallNotifyService.notifySMSTemplate(order.getMobile(), ConfigUtil.NotifyType.PAY_SUCCEED, new String[]{orderSn.substring(8, 14)});
return WxPayNotifyResponse.success("处理成功!"); return WxPayNotifyResponse.success("处理成功!");
} catch (Exception e) { } catch (Exception e) {
...@@ -601,6 +605,10 @@ public class WxOrderController { ...@@ -601,6 +605,10 @@ public class WxOrderController {
order.setOrderStatus(OrderUtil.STATUS_REFUND); order.setOrderStatus(OrderUtil.STATUS_REFUND);
orderService.update(order); orderService.update(order);
//TODO 发送邮件和短信通知,这里采用异步发送
// 有用户申请退款,邮件通知运营人员
litemallNotifyService.notifyMailMessage("退款申请", order.toString());
return ResponseUtil.ok(); return ResponseUtil.ok();
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment