OrderController.java 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. package com.kmall.admin.controller;
  2. import com.kmall.admin.entity.OrderEntity;
  3. import com.kmall.admin.entity.OrderExceptionRecordEntity;
  4. import com.kmall.admin.entity.OrderRefundEntity;
  5. import com.kmall.admin.service.*;
  6. import com.kmall.admin.entity.OrderProcessRecordEntity;
  7. import com.kmall.admin.service.OrderExceptionRecordService;
  8. import com.kmall.admin.service.OrderProcessRecordService;
  9. import com.kmall.admin.service.OrderService;
  10. import com.kmall.api.contants.Dict;
  11. import com.kmall.common.utils.print.ticket.item.Ticket;
  12. import com.kmall.common.utils.PageUtils;
  13. import com.kmall.common.utils.Query;
  14. import com.kmall.common.utils.R;
  15. import com.kmall.common.utils.wechat.WechatRefundApiResult;
  16. import com.kmall.common.utils.wechat.WechatUtil;
  17. import org.apache.shiro.authz.annotation.RequiresPermissions;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.web.bind.annotation.*;
  20. import java.math.BigDecimal;
  21. import java.util.Date;
  22. import java.util.List;
  23. import java.util.Map;
  24. /**
  25. * @author Scott
  26. * @email
  27. * @date 2017-08-13 10:41:09
  28. */
  29. @RestController
  30. @RequestMapping("order")
  31. public class OrderController {
  32. @Autowired
  33. private OrderService orderService;
  34. @Autowired
  35. private OrderProcessRecordService orderProcessRecordService;
  36. @Autowired
  37. private OrderRefundService orderRefundService;
  38. @Autowired
  39. private OrderExceptionRecordService orderExceptionRecordService;
  40. /**
  41. * 列表
  42. */
  43. @RequestMapping("/list")
  44. @RequiresPermissions("order:list")
  45. public R list(@RequestParam Map<String, Object> params) {
  46. //查询列表数据
  47. Query query = new Query(params);
  48. List<OrderEntity> orderList = orderService.queryList(query);
  49. int total = orderService.queryTotal(query);
  50. PageUtils pageUtil = new PageUtils(orderList, total, query.getLimit(), query.getPage());
  51. return R.ok().put("page", pageUtil);
  52. }
  53. /**
  54. * 信息
  55. */
  56. @RequestMapping("/info/{id}")
  57. @RequiresPermissions("order:info")
  58. public R info(@PathVariable("id") Long id) {
  59. OrderEntity order = orderService.queryObject(id);
  60. return R.ok().put("order", order);
  61. }
  62. /**
  63. * 信息
  64. */
  65. @RequestMapping("/infos/{id}")
  66. @RequiresPermissions("order:infos")
  67. public R infos(@PathVariable("id") Long id) {
  68. OrderEntity order = orderService.queryInfos(id);
  69. return R.ok().put("order", order);
  70. }
  71. /**
  72. * 保存
  73. */
  74. @RequestMapping("/save")
  75. @RequiresPermissions("order:save")
  76. public R save(@RequestBody OrderEntity order) {
  77. orderService.save(order);
  78. return R.ok();
  79. }
  80. /**
  81. * 修改
  82. */
  83. @RequestMapping("/update")
  84. @RequiresPermissions("order:update")
  85. public R update(@RequestBody OrderEntity order) {
  86. orderService.update(order);
  87. return R.ok();
  88. }
  89. /**
  90. * 删除
  91. */
  92. @RequestMapping("/delete")
  93. @RequiresPermissions("order:delete")
  94. public R delete(@RequestBody Long[] ids) {
  95. orderService.deleteBatch(ids);
  96. return R.ok();
  97. }
  98. /**
  99. * 查看所有列表
  100. */
  101. @RequestMapping("/queryAll")
  102. public R queryAll(@RequestParam Map<String, Object> params) {
  103. List<OrderEntity> list = orderService.queryList(params);
  104. return R.ok().put("list", list);
  105. }
  106. /**
  107. * 总计
  108. */
  109. @RequestMapping("/queryTotal")
  110. public R queryTotal(@RequestParam Map<String, Object> params) {
  111. int sum = orderService.queryTotal(params);
  112. return R.ok().put("sum", sum);
  113. }
  114. /**
  115. * 确定收货
  116. *
  117. * @param id
  118. * @return
  119. */
  120. @RequestMapping("/confirm")
  121. @RequiresPermissions("order:confirm")
  122. public R confirm(@RequestBody Long id) {
  123. orderService.confirm(id);
  124. return R.ok();
  125. }
  126. /**
  127. * 发货
  128. *
  129. * @param order
  130. * @return
  131. */
  132. @RequestMapping("/sendGoods")
  133. @RequiresPermissions("order:sendGoods")
  134. public R sendGoods(@RequestBody OrderEntity order) {
  135. orderService.sendGoods(order);
  136. return R.ok();
  137. }
  138. /**
  139. * 跟踪快递轨迹
  140. * @param id
  141. * @return
  142. */
  143. @RequestMapping("/getLogistics/{id}")
  144. @RequiresPermissions("order:getLogistics")
  145. public R getLogistics(@PathVariable("id") Long id) {
  146. Map result = orderService.getLogistics(id);
  147. return R.ok().put("result", result);
  148. }
  149. /**
  150. * 获取订单清关信息
  151. * @param orderSn
  152. * @return
  153. */
  154. @RequestMapping("/getProcess/{orderSn}")
  155. @RequiresPermissions("order:getProcess")
  156. public R getProcess(@PathVariable("orderSn") String orderSn) {
  157. OrderProcessRecordEntity orderProcessRecordEntity = orderProcessRecordService.queryObjectByOrderSn(orderSn);
  158. return R.ok().put("orderProcessRecordEntity", orderProcessRecordEntity);
  159. }
  160. /**
  161. * 打印小票
  162. *
  163. * @param id
  164. * @return
  165. */
  166. @RequestMapping("/printMsg")
  167. public R printMsg(@RequestBody Long id) {
  168. Ticket ticket = orderService.printMsg(id);
  169. return R.ok().put("ticket", ticket);
  170. }
  171. /**
  172. * 订单取消请求
  173. */
  174. @RequiresPermissions(value = {"order:refund"})
  175. @RequestMapping(value = "cancel", method = RequestMethod.POST)
  176. public Object cancel(Long orderId) {
  177. OrderEntity orderInfo = orderService.queryObject(orderId);
  178. if (null == orderInfo) {
  179. return R.error("订单不存在");
  180. }
  181. if (orderInfo.getOrderStatus() != 0) {
  182. return R.error("订单状态不支持取消");
  183. }
  184. orderService.cancelOrder(orderInfo);
  185. return R.ok();
  186. }
  187. /**
  188. * 订单退款请求
  189. */
  190. @RequiresPermissions(value = {"order:refund"})
  191. @RequestMapping(value = "refund", method = RequestMethod.POST)
  192. public Object refund(Long orderId, BigDecimal refundMoney) {
  193. OrderEntity orderInfo = orderService.queryObject(orderId);
  194. if (null == orderInfo) {
  195. return R.error("订单不存在");
  196. }
  197. if (orderInfo.getOrderStatus() == Integer.parseInt(Dict.orderStatus.item_401.getItem())
  198. || orderInfo.getOrderStatus() == Integer.parseInt(Dict.orderStatus.item_402.getItem())) {
  199. return R.error("订单已退款");
  200. }
  201. Double totalActualPrice = orderService.getTotalActualPrice(orderInfo.getMerchOrderSn());
  202. if(totalActualPrice == null){
  203. totalActualPrice = 0d;
  204. }
  205. if (orderInfo.getOrderStatus() != 0) {
  206. // todo 退款
  207. // WechatRefundApiResult result = WechatUtil.wxRefund(orderInfo.getOrderSn().toString(),
  208. // orderInfo.getActualPrice().doubleValue(), refundMoney.doubleValue());
  209. WechatRefundApiResult result = WechatUtil.wxRefund(orderInfo.getMerchOrderSn().toString(),
  210. totalActualPrice, orderInfo.getActualPrice().doubleValue());
  211. if (result.getResult_code().equals("SUCCESS")) {
  212. orderService.refund(orderInfo,result);
  213. }else{
  214. OrderRefundEntity mallOrderRefund = orderRefundService.queryObjectByOrderId(orderInfo.getId());
  215. OrderRefundEntity orderRefund = new OrderRefundEntity();
  216. orderRefund.setRefundType(Integer.parseInt(Dict.RefundType.item_1.getItem()));
  217. orderRefund.setRefundMoney(BigDecimal.valueOf(orderInfo.getActualPrice().doubleValue()));
  218. orderRefund.setRefundStatus(Integer.parseInt(Dict.RefundStatus.item_4.getItem()));
  219. orderRefund.setModTime(new Date());
  220. if(mallOrderRefund !=null){
  221. orderRefund.setId(mallOrderRefund.getId());
  222. orderRefundService.update(orderRefund);//退款记录
  223. }
  224. OrderExceptionRecordEntity mallOrderExceptionRecord = new OrderExceptionRecordEntity();
  225. mallOrderExceptionRecord.setUserId(Integer.parseInt(orderInfo.getUserId()+""));
  226. mallOrderExceptionRecord.setOrderSn(orderInfo.getOrderSn());
  227. mallOrderExceptionRecord.setExceptionStatus(Dict.exceptionStatus.item_03.getItem());
  228. mallOrderExceptionRecord.setExceptionContent("退款失败"+result.getErr_code_des());
  229. mallOrderExceptionRecord.setCreateTime(new Date());
  230. orderExceptionRecordService.save(mallOrderExceptionRecord);
  231. return R.error(result.getErr_code_des());
  232. }
  233. }
  234. return R.ok();
  235. }
  236. /**
  237. * 获取首页展示信息--会员购买率相关
  238. * @param params
  239. * @return
  240. */
  241. @RequestMapping("/getUserOrderInfo")
  242. public R getUserOrderInfo(@RequestParam Map<String, Object> params) {
  243. int result = orderService.getUserOrderInfo(params);
  244. return R.ok().put("result", result);
  245. }
  246. }