Order.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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\admin\points;
  12. use crmeb\jobs\BatchDeliveryJob;
  13. use crmeb\services\ExcelService;
  14. use think\App;
  15. use crmeb\basic\BaseController;
  16. use app\common\repositories\store\order\StoreOrderRepository;
  17. use think\facade\Queue;
  18. /**
  19. * 订单
  20. */
  21. class Order extends BaseController
  22. {
  23. /**
  24. * @var StoreOrderRepository
  25. */
  26. protected $repository;
  27. /**
  28. * StoreProduct constructor.
  29. * @param App $app
  30. * @param StoreOrderRepository $repository
  31. */
  32. public function __construct(App $app, StoreOrderRepository $repository)
  33. {
  34. parent::__construct($app);
  35. $this->repository = $repository;
  36. }
  37. /**
  38. * 列表
  39. * @Author:Qinii
  40. * @Date: 2020/5/18
  41. * @return mixed
  42. */
  43. public function lst()
  44. {
  45. [$page, $limit] = $this->getPage();
  46. $where = $this->request->params(['keyword', 'date', 'status', 'order_sn', 'product_id', 'nickname', 'phone', 'uid', 'store_name']);
  47. $where['activity_type'] = 20;
  48. if ($where['status'] == -10) {
  49. unset($where['status']);
  50. $where['is_del'] = 1;
  51. }
  52. return app('json')->success($this->repository->pointsOrderAdminList($where, $page, $limit));
  53. }
  54. /**
  55. * 详情
  56. * @param $id
  57. * @return mixed
  58. * @author Qinii
  59. * @day 2020-06-11
  60. */
  61. public function detail($id)
  62. {
  63. $data = $this->repository->getOne($id, 0);
  64. if (!$data) return app('json')->fail('数据不存在');
  65. return app('json')->success($data);
  66. }
  67. /**
  68. * 订单状态
  69. * @param $id
  70. * @return \think\response\Json
  71. * @author Qinii
  72. */
  73. public function getStatus($id)
  74. {
  75. [$page, $limit] = $this->getPage();
  76. $where['user_type'] = $this->request->param('user_type');
  77. $where['date'] = $this->request->param('date');
  78. $where['id'] = $id;
  79. $data = $this->repository->getOrderStatus($where, $page, $limit);
  80. if (!$data) return app('json')->fail('数据不存在');
  81. return app('json')->success($data);
  82. }
  83. /**
  84. * 发货
  85. * @param $id
  86. * @return mixed
  87. * @author Qinii
  88. */
  89. public function delivery($id)
  90. {
  91. $split = $this->request->params(['is_split', ['split', []]]);
  92. if (!$this->repository->merDeliveryExists($id, $this->request->merId(), 1))
  93. return app('json')->fail('订单信息或状态错误');
  94. $data = $this->request->params([
  95. 'delivery_type',
  96. 'delivery_name',
  97. 'delivery_id',
  98. 'remark',
  99. ]);
  100. if (!$data['delivery_type'] || $data['delivery_type'] != 3 && (!$data['delivery_name'] || !$data['delivery_id']))
  101. return app('json')->fail('填写配送信息');
  102. $this->repository->runDelivery($id, $this->request->merId(), $data, $split, 'delivery');
  103. return app('json')->success('发货成功');
  104. }
  105. /**
  106. * 批量发货
  107. * @return \think\response\Json
  108. * @author Qinii
  109. * @day 7/26/21
  110. */
  111. public function batchDelivery()
  112. {
  113. $params = $this->request->params([
  114. 'order_id',
  115. 'delivery_id',
  116. 'delivery_type',
  117. 'delivery_name',
  118. 'remark',
  119. ]);
  120. if (!in_array($params['delivery_type'], [1, 2, 3]))
  121. return app('json')->fail('发货类型错误');
  122. if (!$params['order_id'])
  123. return app('json')->fail('需要订单ID');
  124. $data = ['mer_id' => $this->request->merId(), 'data' => $params];
  125. Queue::push(BatchDeliveryJob::class, $data);
  126. return app('json')->success('开始批量发货');
  127. }
  128. /**
  129. * 导出文件
  130. * @author Qinii
  131. * @day 2020-07-30
  132. */
  133. public function excel()
  134. {
  135. [$page, $limit] = $this->getPage();
  136. $where = $this->request->params(['keyword', 'date', 'status', 'order_sn', 'product_id']);
  137. $data = app()->make(ExcelService::class)->pointsOrder($where, $page, $limit);
  138. return app('json')->success($data);
  139. }
  140. /**
  141. * 删除
  142. * @Author:Qinii
  143. * @Date: 2020/5/18
  144. * @param $id
  145. * @return mixed
  146. */
  147. public function delete($id)
  148. {
  149. if (!$this->repository->userDelExists($id, $this->request->merId()))
  150. return app('json')->fail('订单信息或状态错误');
  151. $this->repository->update($id, ['is_system_del' => 1]);
  152. return app('json')->success('删除成功');
  153. }
  154. /**
  155. * 订单备注
  156. * @param $id
  157. * @return mixed
  158. * @author Qinii
  159. * @day 2020-06-11
  160. */
  161. public function remarkForm($id)
  162. {
  163. return app('json')->success(formToData($this->repository->pointsMarkForm($id)));
  164. }
  165. /**
  166. * 订单备注
  167. * @param $id
  168. * @return mixed
  169. * @author Qinii
  170. * @day 2020-06-11
  171. */
  172. public function remark($id)
  173. {
  174. if (!$this->repository->getOne($id, $this->request->merId()))
  175. return app('json')->fail('数据不存在');
  176. $data = $this->request->params(['remark']);
  177. $this->repository->update($id, $data);
  178. return app('json')->success('备注成功');
  179. }
  180. /**
  181. * 订单备注
  182. * @param $id
  183. * @return \think\response\Json
  184. * @author Qinii
  185. */
  186. public function express($id)
  187. {
  188. if (!$this->repository->getWhereCount(['order_id' => $id]))
  189. return app('json')->fail('订单信息或状态错误');
  190. return app('json')->success($this->repository->express($id, null));
  191. }
  192. }