Order.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  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\merchant\store\order;
  12. use app\validate\merchant\OrderValidate;
  13. use app\common\repositories\store\ExcelRepository;
  14. use app\common\repositories\delivery\DeliveryServiceRepository;
  15. use app\common\repositories\system\merchant\MerchantRepository;
  16. use app\common\repositories\store\order\MerchantReconciliationRepository;
  17. use app\common\repositories\store\order\StoreOrderRepository;
  18. use crmeb\exceptions\UploadException;
  19. use crmeb\jobs\BatchDeliveryJob;
  20. use crmeb\services\ExcelService;
  21. use think\App;
  22. use crmeb\basic\BaseController;
  23. use app\common\repositories\store\order\StoreOrderRepository as repository;
  24. use think\facade\Queue;
  25. class Order extends BaseController
  26. {
  27. protected $repository;
  28. /**
  29. * Product constructor.
  30. * @param App $app
  31. * @param repository $repository
  32. */
  33. public function __construct(App $app, repository $repository)
  34. {
  35. parent::__construct($app);
  36. $this->repository = $repository;
  37. }
  38. /**
  39. * 获取订单统计数据
  40. *
  41. * @return \think\response\Json
  42. */
  43. public function title()
  44. {
  45. $where = $this->request->params(['status', 'date', 'order_sn', 'username', 'order_type', 'keywords', 'order_id', 'activity_type', 'filter_delivery', 'filter_product', 'delivery_id', 'uid', 'nickname', 'real_name', 'phone']);
  46. // 添加商家ID查询条件
  47. $where['mer_id'] = $this->request->merId();
  48. $pay_type = $this->request->param('pay_type', '');
  49. // 如果支付类型不为空,则添加支付类型查询条件
  50. if ($pay_type != '') $where['pay_type'] = $this->repository::PAY_TYPE_FILTEER[$pay_type];
  51. // 调用仓库的获取统计数据方法,并返回JSON格式的结果
  52. return app('json')->success($this->repository->getStat($where, $where['status']));
  53. }
  54. /**
  55. * 订单列表
  56. * @return mixed
  57. * @author Qinii
  58. */
  59. public function lst()
  60. {
  61. [$page, $limit] = $this->getPage();
  62. $where = $this->request->params(['status', 'date', 'order_sn', 'username', 'order_type', 'keywords', 'order_id', 'activity_type', 'group_order_sn', 'store_name', 'filter_delivery', 'filter_product', 'delivery_id', 'group_order_id', 'uid', 'nickname', 'real_name', 'phone','is_behalf', 'is_virtual']);
  63. $where['mer_id'] = $this->request->merId();
  64. $pay_type = $this->request->param('pay_type', '');
  65. if ($pay_type != '') $where['pay_type'] = $this->repository::PAY_TYPE_FILTEER[$pay_type];
  66. return app('json')->success($this->repository->merchantGetList($where, $page, $limit));
  67. }
  68. /**
  69. * 获取标题统计数据
  70. *
  71. * @return \think\response\Json
  72. */
  73. public function takeTitle()
  74. {
  75. // 从请求参数中获取日期、订单号、用户名和关键字
  76. $where = $this->request->params(['date', 'order_sn', 'username', 'keywords']);
  77. $where['take_order'] = 1; // 只查询已接单的订单
  78. $where['status'] = -1; // 只查询未完成的订单
  79. $where['verify_date'] = $where['date']; // 将日期作为验证日期
  80. unset($where['date']); // 删除日期参数
  81. $where['mer_id'] = $this->request->merId(); // 添加商家ID查询条件
  82. $pay_type = $this->request->param('pay_type', '');
  83. if ($pay_type != '') $where['pay_type'] = $this->repository::PAY_TYPE_FILTEER[$pay_type];
  84. // 调用仓库的 getStat 方法获取统计数据并返回 JSON 格式的响应
  85. return app('json')->success($this->repository->getStat($where, ''));
  86. }
  87. /**
  88. * 自提订单列表
  89. * @return mixed
  90. * @author Qinii
  91. * @day 2020-08-17
  92. */
  93. public function takeLst()
  94. {
  95. [$page, $limit] = $this->getPage();
  96. $where = $this->request->params(['date', 'order_sn', 'username', 'keywords']);
  97. $where['take_order'] = 1;
  98. $where['status'] = -1;
  99. $where['verify_date'] = $where['date'];
  100. unset($where['date']);
  101. $where['mer_id'] = $this->request->merId();
  102. $pay_type = $this->request->param('pay_type', '');
  103. if ($pay_type != '') $where['pay_type'] = $this->repository::PAY_TYPE_FILTEER[$pay_type];
  104. return app('json')->success($this->repository->merchantGetList($where, $page, $limit));
  105. }
  106. /**
  107. * 订单头部统计
  108. * @return mixed
  109. * @author Qinii
  110. */
  111. public function chart()
  112. {
  113. return app('json')->success($this->repository->OrderTitleNumber($this->request->merId(), null));
  114. }
  115. /**
  116. * 自提订单头部统计
  117. * @return mixed
  118. * @author Qinii
  119. * @day 2020-08-17
  120. */
  121. public function takeChart()
  122. {
  123. return app('json')->success($this->repository->OrderTitleNumber($this->request->merId(), 1));
  124. }
  125. /**
  126. * 订单类型
  127. * @return mixed
  128. * @author Qinii
  129. * @day 2020-08-15
  130. */
  131. public function orderType()
  132. {
  133. $where['mer_id'] = $this->request->merId();
  134. return app('json')->success($this->repository->orderType($where));
  135. }
  136. /**
  137. * @param $id
  138. * @return mixed
  139. * @author Qinii
  140. */
  141. public function deliveryForm($id)
  142. {
  143. $data = $this->repository->getWhere(['order_id' => $id, 'mer_id' => $this->request->merId(), 'is_del' => 0]);
  144. if (!$data) return app('json')->fail('数据不存在');
  145. if (!$data['paid']) return app('json')->fail('订单未支付');
  146. if (!in_array($data['status'], [0, 1])) return app('json')->fail('订单状态错误');
  147. return app('json')->success(formToData($this->repository->sendProductForm($id, $data)));
  148. }
  149. /**
  150. * 发货
  151. * @param $id
  152. * @return mixed
  153. * @author Qinii
  154. */
  155. public function delivery($id)
  156. {
  157. $type = $this->request->param('delivery_type');
  158. $split = $this->request->params(['is_split', ['split', []]]);
  159. if (!$this->repository->merDeliveryExists($id, $this->request->merId()))
  160. return app('json')->fail('订单信息或状态错误');
  161. switch ($type) {
  162. case 2:
  163. $data = $this->request->params(['delivery_type', 'delivery_name', 'delivery_id', 'remark',]);
  164. if (!$data['delivery_type'] || !$data['delivery_name'] || !$data['delivery_id'])
  165. return app('json')->fail('填写配送信息');
  166. $ser = app()->make(DeliveryServiceRepository::class)->get($data['delivery_name']);
  167. $data['delivery_name'] = $ser['name'] ?? $data['delivery_name'];
  168. $method = 'delivery';
  169. break;
  170. case 3: //虚拟发货
  171. $data = $this->request->params([
  172. 'delivery_type',
  173. 'remark',
  174. ]);
  175. $data['delivery_name'] = '';
  176. $data['delivery_id'] = '';
  177. $method = 'delivery';
  178. // 因为没有确认收货所以要判断判断积分份额
  179. $order = $this->repository->getWhere(['order_id' => $id]);
  180. // app()->make(StoreOrderRepository::class)->getOrderAward($order);
  181. // app()->make(StoreOrderRepository::class)->spreadOrder($order['uid'],$order['order_id']); //查找上级是否有冻结份额
  182. break;
  183. case 4: //电子面单
  184. if (!systemConfig('crmeb_serve_dump') || merchantConfig($this->request->merId(), 'mer_dump_switch') == 0)
  185. return app('json')->fail('电子面单功能未开启');
  186. $data = $this->request->params([
  187. 'delivery_type',
  188. 'delivery_name',
  189. 'from_name',
  190. 'from_tel',
  191. 'from_addr',
  192. 'temp_id',
  193. 'remark',
  194. ['is_cargo', 1],
  195. ]);
  196. if (!$data['from_name'] ||
  197. !$data['delivery_name'] ||
  198. !$data['from_tel'] ||
  199. !$data['from_addr'] ||
  200. !$data['temp_id']
  201. )
  202. return app('json')->fail('填写配送信息');
  203. $method = 'dump';
  204. break;
  205. case 5: //同城配送
  206. if (systemConfig('delivery_status') != 1)
  207. return app('json')->fail('未开启第三方配送');
  208. $data = $this->request->params(['delivery_type', 'station_id', 'mark', ['cargo_weight', 0], 'remark',]);
  209. if ($data['cargo_weight'] < 0) return app('json')->fail('包裹重量能为负数');
  210. if (!$data['station_id']) return app('json')->fail('请选择门店');
  211. $method = 'cityDelivery';
  212. break;
  213. default: //快递
  214. $data = $this->request->params(['delivery_type', 'delivery_name', 'delivery_id', 'remark',]);
  215. if (!$data['delivery_type'] || !$data['delivery_name'] || !$data['delivery_id'])
  216. return app('json')->fail('填写配送信息');
  217. $method = 'delivery';
  218. break;
  219. }
  220. $res = $this->repository->runDelivery($id, $this->request->merId(), $data, $split, $method);
  221. return app('json')->success('发货成功', $res);
  222. }
  223. /**
  224. *
  225. * @return \think\response\Json
  226. * @author Qinii
  227. * @day 7/26/21
  228. */
  229. public function batchDelivery()
  230. {
  231. $params = $this->request->params([
  232. 'order_id',
  233. 'delivery_id',
  234. 'delivery_type',
  235. 'delivery_name',
  236. 'remark',
  237. ['select_type', 'select'],
  238. ['where', []],
  239. ]);
  240. if (!in_array($params['select_type'], ['all', 'select'])) return app('json')->fail('选择了类型错误');
  241. if (!in_array($params['delivery_type'], [2, 3, 4])) return app('json')->fail('发货类型错误');
  242. if ($params['delivery_type'] ==2 ) {
  243. $data = $this->request->params(['delivery_type', 'delivery_name', 'delivery_id', 'remark',]);
  244. if (!$data['delivery_type'] || !$data['delivery_name'] || !$data['delivery_id'])
  245. return app('json')->fail('填写配送信息');
  246. $ser = app()->make(DeliveryServiceRepository::class)->get($data['delivery_name']);
  247. $data['delivery_name'] = $ser['name'];
  248. }
  249. if ($params['delivery_type'] == 4) {
  250. $data = $this->request->params([
  251. 'from_name',
  252. 'from_tel',
  253. 'from_addr',
  254. 'temp_id',
  255. 'remark',
  256. ['is_cargo', 1],
  257. ]);
  258. $params = array_merge($params, $data);
  259. if (!systemConfig('crmeb_serve_dump') || merchantConfig($this->request->merId(), 'mer_dump_switch') == 0)
  260. return app('json')->fail('电子面单功能未开启');
  261. if (!merchantConfig($this->request->merId(), 'mer_dump_type'))
  262. return app('json')->fail('通用打印机不支持批量打印');
  263. }
  264. if ($params['select_type'] == 'select' && !$params['order_id']) return app('json')->fail('需要订单ID');
  265. if ($params['select_type'] == 'all' && empty($params['where'])) return app('json')->fail('需要搜索条件');
  266. //$this->repository->batchDelivery($this->request->merId(),$params);
  267. Queue::push(BatchDeliveryJob::class, [
  268. 'mer_id' => $this->request->merId(),
  269. 'data' => $params
  270. ]);
  271. return app('json')->success('以开始批量发货,请稍后查看');
  272. }
  273. public function repeatDump($id)
  274. {
  275. if (!systemConfig('crmeb_serve_dump') || merchantConfig($this->request->merId(), 'mer_dump_switch') == 0)
  276. return app('json')->fail('电子面单功能未开启');
  277. $data = $this->repository->repeat_dump($id, $this->request->merId());
  278. return app('json')->success($data);
  279. }
  280. /**
  281. * 改价form
  282. * @param $id
  283. * @return mixed
  284. * @author Qinii
  285. * @day 2020-06-11
  286. */
  287. public function updateForm($id)
  288. {
  289. if (!$this->repository->merStatusExists($id, $this->request->merId()))
  290. return app('json')->fail('订单信息或状态错误');
  291. return app('json')->success(formToData($this->repository->form($id)));
  292. }
  293. /**
  294. * 改价
  295. * @param $id
  296. * @return mixed
  297. * @author Qinii
  298. * @day 2020-06-11
  299. */
  300. public function update($id)
  301. {
  302. $data = $this->request->params(['total_price', 'pay_postage']);
  303. if ($data['total_price'] < 0 || $data['pay_postage'] < 0)
  304. return app('json')->fail('金额不可未负数');
  305. if (!$this->repository->merStatusExists($id, $this->request->merId()))
  306. return app('json')->fail('订单信息或状态错误');
  307. $this->repository->eidt($id, $data);
  308. return app('json')->success('修改成功');
  309. }
  310. /**
  311. * @param $id
  312. * @return mixed
  313. * @author Qinii
  314. * @day 2020-06-11
  315. */
  316. public function detail($id)
  317. {
  318. $data = $this->repository->getOne($id, $this->request->merId());
  319. if (!$data) return app('json')->fail('数据不存在');
  320. return app('json')->success($data);
  321. }
  322. /**
  323. * @param $id
  324. * @return mixed
  325. * @author Qinii
  326. * @day 2020-06-11
  327. */
  328. public function status($id)
  329. {
  330. [$page, $limit] = $this->getPage();
  331. $where = $this->request->params(['date', 'user_type']);
  332. $where['id'] = $id;
  333. if (!$this->repository->getOne($id, $this->request->merId()))
  334. return app('json')->fail('数据不存在');
  335. return app('json')->success($this->repository->getOrderStatus($where, $page, $limit));
  336. }
  337. /**
  338. * @param $id
  339. * @return mixed
  340. * @author Qinii
  341. * @day 2020-06-11
  342. */
  343. public function remarkForm($id)
  344. {
  345. return app('json')->success(formToData($this->repository->remarkForm($id)));
  346. }
  347. /**
  348. * @param $id
  349. * @return mixed
  350. * @author Qinii
  351. * @day 2020-06-11
  352. */
  353. public function remark($id)
  354. {
  355. if (!$this->repository->getOne($id, $this->request->merId()))
  356. return app('json')->fail('数据不存在');
  357. $data = $this->request->params(['remark']);
  358. $this->repository->update($id, $data);
  359. return app('json')->success('备注成功');
  360. }
  361. public function collectCargoForm($id)
  362. {
  363. return app('json')->success(formToData($this->repository->collectCargoForm($id)));
  364. }
  365. public function collectCargo($id)
  366. {
  367. if (!$this->repository->getOne($id, $this->request->merId()))
  368. return app('json')->fail('数据不存在');
  369. $data = $this->request->params(['real_name','user_phone','user_address']);
  370. $this->repository->update($id, $data);
  371. return app('json')->success('操作成功');
  372. }
  373. /**
  374. * 核销
  375. * @param $code
  376. * @author xaboy
  377. * @day 2020/8/15
  378. */
  379. public function verify($id)
  380. {
  381. $data = $this->request->params(['data', 'verify_code']);
  382. $merId = $this->request->merId();
  383. // 根据订单ID、商家ID、验证码和订单类型查询订单,并连带查询订单产品信息
  384. $order = $this->repository->getWhere(['order_id' => $id, 'mer_id' => $merId, 'verify_code' => $data['verify_code'], 'order_type' => 1], '*', ['orderProduct']);
  385. // 如果订单不存在,则抛出验证异常
  386. if (!$order) return app('json')->fail('订单不存在');
  387. // 如果订单未支付,则抛出验证异常
  388. if (!$order->paid) return app('json')->fail('订单未支付');
  389. // 如果订单已全部核销,则抛出验证异常
  390. if ($order['status']) return app('json')->fail('订单已全部核销,请勿重复操作');
  391. $this->repository->verifyOrder($order, $data);
  392. return app('json')->success('订单核销成功');
  393. }
  394. /**
  395. * 根据订单编号获取订单详情
  396. *
  397. * @param string $code 订单编号
  398. * @return \Illuminate\Http\JsonResponse 返回订单详情或错误信息
  399. */
  400. public function verifyDetail($code)
  401. {
  402. // 通过订单编号查询订单
  403. $order = $this->repository->codeByDetail($code);
  404. // 如果订单不存在则返回错误信息
  405. if (!$order) return app('json')->fail('订单不存在');
  406. // 返回订单详情
  407. return app('json')->success($order);
  408. }
  409. /**
  410. * @param $id
  411. * @return mixed
  412. * @author Qinii
  413. * @day 2020-06-11
  414. */
  415. public function delete($id)
  416. {
  417. if (!$this->repository->userDelExists($id, $this->request->merId()))
  418. return app('json')->fail('订单信息或状态错误');
  419. $this->repository->merDelete($id);
  420. return app('json')->success('删除成功');
  421. }
  422. /**
  423. * 快递查询
  424. * @param $id
  425. * @return mixed
  426. * @author Qinii
  427. * @day 2020-06-25
  428. */
  429. public function express($id)
  430. {
  431. return app('json')->success($this->repository->express($id, $this->request->merId()));
  432. }
  433. /**
  434. *
  435. * @param $id
  436. * @return mixed
  437. * @author Qinii
  438. * @day 2020-07-30
  439. */
  440. public function reList($id)
  441. {
  442. [$page, $limit] = $this->getPage();
  443. $make = app()->make(MerchantReconciliationRepository::class);
  444. if (!$make->getWhereCount(['mer_id' => $this->request->merId(), 'reconciliation_id' => $id]))
  445. return app('json')->fail('数据不存在');
  446. $where = ['reconciliation_id' => $id, 'type' => 0];
  447. return app('json')->success($this->repository->reconList($where, $page, $limit));
  448. }
  449. /**
  450. * 导出文件
  451. * @author Qinii
  452. * @day 2020-07-30
  453. */
  454. public function excel()
  455. {
  456. [$page, $limit] = $this->getPage();
  457. $where = $this->request->params(['status', 'date', 'order_sn', 'order_type', 'username', 'keywords', 'take_order', 'order_id', 'activity_type', 'group_order_sn', 'store_name', 'filter_delivery', 'filter_product', 'pay_type', 'uid', 'nickname', 'real_name', 'phone']);
  458. $where['order_ids'] = $this->request->param('ids','');
  459. if ($where['pay_type'] != '') $where['pay_type'] = $this->repository::PAY_TYPE_FILTEER[$where['pay_type']];
  460. if ($where['take_order']) {
  461. $where['status'] = -1;
  462. $where['verify_date'] = $where['date'];
  463. unset($where['date']);
  464. unset($where['order_type']);
  465. }
  466. $where['mer_id'] = $this->request->merId();
  467. $data = app()->make(ExcelService::class)->order($where, $page, $limit);
  468. return app('json')->success($data);
  469. }
  470. /**
  471. * 打印小票
  472. * @param $id
  473. * @return mixed
  474. * @author Qinii
  475. * @day 2020-07-30
  476. */
  477. public function printer($id)
  478. {
  479. $merId = $this->request->merId();
  480. if (!$this->repository->getWhere(['order_id' => $id, 'mer_id' => $merId]))
  481. return app('json')->fail('数据不存在');
  482. $this->repository->batchPrinter($id, $merId,null);
  483. return app('json')->success('打印成功');
  484. }
  485. /**
  486. * 导出发货单
  487. * @return \think\response\Json
  488. * @author Qinii
  489. * @day 3/13/21
  490. */
  491. public function deliveryExport()
  492. {
  493. $where = $this->request->params(['username', 'date', 'activity_type', 'order_type', 'username', 'keywords', 'id']);
  494. $where['order_ids'] = $this->request->param('ids');
  495. $where['mer_id'] = $this->request->merId();
  496. $where['status'] = 0;
  497. $where['paid'] = 1;
  498. $make = app()->make(StoreOrderRepository::class);
  499. if (is_array($where['id'])) $where['order_ids'] = $where['id'];
  500. $count = $make->search($where)->find();
  501. if (!$count) return app('json')->fail('没有可导出数据');
  502. [$page, $limit] = $this->getPage();
  503. $data = app()->make(ExcelService::class)->delivery($where, $page, $limit);
  504. return app('json')->success($data);
  505. }
  506. /**
  507. * 获取指定节点的子节点列表
  508. *
  509. * @param int $id 节点ID
  510. * @return \think\response\Json 返回JSON格式的数据
  511. */
  512. public function childrenList($id)
  513. {
  514. // 调用repository层的childrenList方法获取子节点列表
  515. $data = $this->repository->childrenList($id, $this->request->merId());
  516. // 返回JSON格式的数据
  517. return app('json')->success($data);
  518. }
  519. /**
  520. * 将指定节点设置为下线状态
  521. *
  522. * @param int $id 节点ID
  523. * @return \think\response\Json 返回JSON格式的数据
  524. */
  525. public function offline($id)
  526. {
  527. // 调用repository层的offline方法将节点设置为下线状态
  528. $this->repository->offline($id, $this->request->merId());
  529. return app('json')->success('确认成功');
  530. }
  531. /**
  532. * 订单配货单
  533. * @return \think\response\Json
  534. * @author Qinii
  535. */
  536. public function note()
  537. {
  538. $where = $this->request->params(['status', 'date', 'order_sn', 'order_type', 'username', 'keywords', 'take_order', 'order_id', 'activity_type', 'group_order_sn', 'store_name', 'filter_delivery', 'filter_product', 'pay_type', 'uid', 'nickname', 'real_name', 'phone']);
  539. $where['order_ids'] = $this->request->param('ids','');
  540. if ($where['pay_type'] != '') $where['pay_type'] = $this->repository::PAY_TYPE_FILTEER[$where['pay_type']];
  541. if ($where['take_order']) {
  542. $where['status'] = -1;
  543. $where['verify_date'] = $where['date'];
  544. unset($where['date']);
  545. unset($where['order_type']);
  546. }
  547. $limit = $this->request->param('limit', 10);
  548. $merchant = $this->request->merchant()->toArray();
  549. // $merchant['qrcode'] = app()->make(MerchantRepository::class)->wxQrcode(intval($this->request->merId()));
  550. $data = $this->repository->note($where,$limit);
  551. return app('json')->success($data);
  552. }
  553. /**
  554. * 预约订单派单
  555. *
  556. * @param integer $id
  557. * @return json
  558. */
  559. public function reservationDispatch(int $id)
  560. {
  561. $params = $this->request->params(['staffs_id']);
  562. if (!$params['staffs_id']) {
  563. return app('json')->fail('请选择服务人员');
  564. }
  565. $res = $this->repository->reservationDispatch($id, $this->request->merId(), $params);
  566. if (!$res) {
  567. return app('json')->fail('派单失败');
  568. }
  569. return app('json')->success('派单成功');
  570. }
  571. /**
  572. * 预约订单改派
  573. *
  574. * @param integer $id
  575. * @return json
  576. */
  577. public function reservationUpdateDispatch(int $id)
  578. {
  579. $params = $this->request->params(['staffs_id']);
  580. if (!$params['staffs_id']) {
  581. return app('json')->fail('请选择服务人员');
  582. }
  583. $res = $this->repository->reservationUpdateDispatch($id, $this->request->merId(), $params);
  584. if (!$res) {
  585. return app('json')->fail('改派失败');
  586. }
  587. return app('json')->success('改派成功');
  588. }
  589. /**
  590. * 预约订单改期
  591. *
  592. * @param [type] $id
  593. * @return void
  594. */
  595. public function reservationReschedule(int $id)
  596. {
  597. $params = $this->request->params(
  598. [
  599. 'order_type',
  600. 'reservation_date',
  601. 'real_name',
  602. 'user_phone',
  603. 'user_address',
  604. 'order_extend',
  605. 'part_start',
  606. 'part_end'
  607. ]
  608. );
  609. $validate = app()->make(OrderValidate::class);
  610. if (!$validate->sceneReservationReschedule($params)) {
  611. return app('json')->fail($validate->getError());
  612. }
  613. $res = $this->repository->reservationReschedule($id, $this->request->merId(), $params);
  614. if (!$res) {
  615. return app('json')->fail('改约失败');
  616. }
  617. return app('json')->success('改约成功');
  618. }
  619. /**
  620. * 单独修改预约时间
  621. *
  622. * @param integer $id
  623. * @return json
  624. */
  625. public function reservationTime(int $id)
  626. {
  627. $params = $this->request->params(
  628. [
  629. 'reservation_date',
  630. 'part_start',
  631. 'part_end'
  632. ]
  633. );
  634. $validate = app()->make(OrderValidate::class);
  635. if (!$validate->sceneOnlyReservationTime($params)) {
  636. return app('json')->fail($validate->getError());
  637. }
  638. $res = $this->repository->updateReservationTime($id, $this->request->merId(), $params);
  639. if (!$res) {
  640. return app('json')->fail('修过失败');
  641. }
  642. return app('json')->success('修改成功');
  643. }
  644. /**
  645. * 预约订单核销
  646. *
  647. * @param integer $id
  648. * @return void
  649. */
  650. public function reservationVerify(int $id)
  651. {
  652. $res = $this->repository->reservationVerify($id, $this->request->merId());
  653. if (!$res) {
  654. return app('json')->fail('核销失败');
  655. }
  656. return app('json')->success('核销成功');
  657. }
  658. }