1
0

OrderController.java 9.0 KB

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