OrderController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api\pc;
  12. use app\Request;
  13. use app\services\order\StoreOrderRefundServices;
  14. use app\services\order\StoreOrderServices;
  15. use app\services\pc\OrderServices;
  16. class OrderController
  17. {
  18. protected $services;
  19. public function __construct(OrderServices $services)
  20. {
  21. $this->services = $services;
  22. }
  23. /**
  24. * 轮询订单状态
  25. * @param Request $request
  26. * @return mixed
  27. */
  28. public function checkOrderStatus(Request $request)
  29. {
  30. [$order_id, $end_time] = $request->getMore([
  31. ['order_id', ''],
  32. ['end_time', ''],
  33. ], true);
  34. $data['status'] = $this->services->checkOrderStatus((string)$order_id);
  35. $time = $end_time - time();
  36. $data['time'] = $time > 0 ? $time : 0;
  37. return app('json')->successful($data);
  38. }
  39. /**
  40. * 获取订单列表
  41. * @param Request $request
  42. * @return mixed
  43. * @throws \think\db\exception\DataNotFoundException
  44. * @throws \think\db\exception\DbException
  45. * @throws \think\db\exception\ModelNotFoundException
  46. */
  47. public function getOrderList(Request $request)
  48. {
  49. $where = $request->getMore([
  50. ['type', '', '', 'status'],
  51. ['search', '', '', 'real_name'],
  52. ]);
  53. $where['uid'] = $request->uid();
  54. $where['is_del'] = 0;
  55. $where['is_system_del'] = 0;
  56. if (!in_array($where['status'], [-1, -2, -3])) $where['pid'] = 0;
  57. return app('json')->successful($this->services->getOrderList($where));
  58. }
  59. /**
  60. * 获取退货商品列表
  61. * @param StoreOrderServices $services
  62. * @param $id
  63. * @return mixed
  64. */
  65. public function refundCartInfoList(Request $request, StoreOrderServices $services)
  66. {
  67. [$cart_ids, $id] = $request->postMore([
  68. ['cart_ids', ''],
  69. ['id', 0],
  70. ], true);
  71. if (!$id) {
  72. return app('json')->fail('缺少发货ID');
  73. }
  74. $cart_id = [];
  75. if ($cart_ids) $cart_id[] = ['cart_id' => $cart_ids];
  76. return app('json')->success($services->refundCartInfoList((array)$cart_id, (int)$id));
  77. }
  78. /**
  79. * 订单列表
  80. * @param Request $request
  81. * @return mixed
  82. */
  83. public function refundList(Request $request, StoreOrderRefundServices $services)
  84. {
  85. $where = $request->getMore([
  86. ['refund_type', '', '', 'refundTypes']
  87. ]);
  88. $where['uid'] = $request->uid();
  89. $where['is_cancel'] = 0;
  90. $data['list'] = $services->getRefundOrderList($where);
  91. $data['count'] = $services->count($where);
  92. return app('json')->successful($data);
  93. }
  94. }