Order.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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. break;
  182. case 4: //电子面单
  183. if (!systemConfig('crmeb_serve_dump') || merchantConfig($this->request->merId(), 'mer_dump_switch') == 0)
  184. return app('json')->fail('电子面单功能未开启');
  185. $data = $this->request->params([
  186. 'delivery_type',
  187. 'delivery_name',
  188. 'from_name',
  189. 'from_tel',
  190. 'from_addr',
  191. 'temp_id',
  192. 'remark',
  193. ['is_cargo', 1],
  194. ]);
  195. if (!$data['from_name'] ||
  196. !$data['delivery_name'] ||
  197. !$data['from_tel'] ||
  198. !$data['from_addr'] ||
  199. !$data['temp_id']
  200. )
  201. return app('json')->fail('填写配送信息');
  202. $method = 'dump';
  203. break;
  204. case 5: //同城配送
  205. if (systemConfig('delivery_status') != 1)
  206. return app('json')->fail('未开启第三方配送');
  207. $data = $this->request->params(['delivery_type', 'station_id', 'mark', ['cargo_weight', 0], 'remark',]);
  208. if ($data['cargo_weight'] < 0) return app('json')->fail('包裹重量能为负数');
  209. if (!$data['station_id']) return app('json')->fail('请选择门店');
  210. $method = 'cityDelivery';
  211. break;
  212. default: //快递
  213. $data = $this->request->params(['delivery_type', 'delivery_name', 'delivery_id', 'remark',]);
  214. if (!$data['delivery_type'] || !$data['delivery_name'] || !$data['delivery_id'])
  215. return app('json')->fail('填写配送信息');
  216. $method = 'delivery';
  217. break;
  218. }
  219. $res = $this->repository->runDelivery($id, $this->request->merId(), $data, $split, $method);
  220. return app('json')->success('发货成功', $res);
  221. }
  222. /**
  223. *
  224. * @return \think\response\Json
  225. * @author Qinii
  226. * @day 7/26/21
  227. */
  228. public function batchDelivery()
  229. {
  230. $params = $this->request->params([
  231. 'order_id',
  232. 'delivery_id',
  233. 'delivery_type',
  234. 'delivery_name',
  235. 'remark',
  236. ['select_type', 'select'],
  237. ['where', []],
  238. ]);
  239. if (!in_array($params['select_type'], ['all', 'select'])) return app('json')->fail('选择了类型错误');
  240. if (!in_array($params['delivery_type'], [2, 3, 4])) return app('json')->fail('发货类型错误');
  241. if ($params['delivery_type'] ==2 ) {
  242. $data = $this->request->params(['delivery_type', 'delivery_name', 'delivery_id', 'remark',]);
  243. if (!$data['delivery_type'] || !$data['delivery_name'] || !$data['delivery_id'])
  244. return app('json')->fail('填写配送信息');
  245. $ser = app()->make(DeliveryServiceRepository::class)->get($data['delivery_name']);
  246. $data['delivery_name'] = $ser['name'];
  247. }
  248. if ($params['delivery_type'] == 4) {
  249. $data = $this->request->params([
  250. 'from_name',
  251. 'from_tel',
  252. 'from_addr',
  253. 'temp_id',
  254. 'remark',
  255. ['is_cargo', 1],
  256. ]);
  257. $params = array_merge($params, $data);
  258. if (!systemConfig('crmeb_serve_dump') || merchantConfig($this->request->merId(), 'mer_dump_switch') == 0)
  259. return app('json')->fail('电子面单功能未开启');
  260. if (!merchantConfig($this->request->merId(), 'mer_dump_type'))
  261. return app('json')->fail('通用打印机不支持批量打印');
  262. }
  263. if ($params['select_type'] == 'select' && !$params['order_id']) return app('json')->fail('需要订单ID');
  264. if ($params['select_type'] == 'all' && empty($params['where'])) return app('json')->fail('需要搜索条件');
  265. //$this->repository->batchDelivery($this->request->merId(),$params);
  266. Queue::push(BatchDeliveryJob::class, [
  267. 'mer_id' => $this->request->merId(),
  268. 'data' => $params
  269. ]);
  270. return app('json')->success('以开始批量发货,请稍后查看');
  271. }
  272. public function repeatDump($id)
  273. {
  274. if (!systemConfig('crmeb_serve_dump') || merchantConfig($this->request->merId(), 'mer_dump_switch') == 0)
  275. return app('json')->fail('电子面单功能未开启');
  276. $data = $this->repository->repeat_dump($id, $this->request->merId());
  277. return app('json')->success($data);
  278. }
  279. /**
  280. * 改价form
  281. * @param $id
  282. * @return mixed
  283. * @author Qinii
  284. * @day 2020-06-11
  285. */
  286. public function updateForm($id)
  287. {
  288. if (!$this->repository->merStatusExists($id, $this->request->merId()))
  289. return app('json')->fail('订单信息或状态错误');
  290. return app('json')->success(formToData($this->repository->form($id)));
  291. }
  292. /**
  293. * 改价
  294. * @param $id
  295. * @return mixed
  296. * @author Qinii
  297. * @day 2020-06-11
  298. */
  299. public function update($id)
  300. {
  301. $data = $this->request->params(['total_price', 'pay_postage']);
  302. if ($data['total_price'] < 0 || $data['pay_postage'] < 0)
  303. return app('json')->fail('金额不可未负数');
  304. if (!$this->repository->merStatusExists($id, $this->request->merId()))
  305. return app('json')->fail('订单信息或状态错误');
  306. $this->repository->eidt($id, $data);
  307. return app('json')->success('修改成功');
  308. }
  309. /**
  310. * @param $id
  311. * @return mixed
  312. * @author Qinii
  313. * @day 2020-06-11
  314. */
  315. public function detail($id)
  316. {
  317. $data = $this->repository->getOne($id, $this->request->merId());
  318. if (!$data) return app('json')->fail('数据不存在');
  319. return app('json')->success($data);
  320. }
  321. /**
  322. * @param $id
  323. * @return mixed
  324. * @author Qinii
  325. * @day 2020-06-11
  326. */
  327. public function status($id)
  328. {
  329. [$page, $limit] = $this->getPage();
  330. $where = $this->request->params(['date', 'user_type']);
  331. $where['id'] = $id;
  332. if (!$this->repository->getOne($id, $this->request->merId()))
  333. return app('json')->fail('数据不存在');
  334. return app('json')->success($this->repository->getOrderStatus($where, $page, $limit));
  335. }
  336. /**
  337. * @param $id
  338. * @return mixed
  339. * @author Qinii
  340. * @day 2020-06-11
  341. */
  342. public function remarkForm($id)
  343. {
  344. return app('json')->success(formToData($this->repository->remarkForm($id)));
  345. }
  346. /**
  347. * @param $id
  348. * @return mixed
  349. * @author Qinii
  350. * @day 2020-06-11
  351. */
  352. public function remark($id)
  353. {
  354. if (!$this->repository->getOne($id, $this->request->merId()))
  355. return app('json')->fail('数据不存在');
  356. $data = $this->request->params(['remark']);
  357. $this->repository->update($id, $data);
  358. return app('json')->success('备注成功');
  359. }
  360. public function collectCargoForm($id)
  361. {
  362. return app('json')->success(formToData($this->repository->collectCargoForm($id)));
  363. }
  364. public function collectCargo($id)
  365. {
  366. if (!$this->repository->getOne($id, $this->request->merId()))
  367. return app('json')->fail('数据不存在');
  368. $data = $this->request->params(['real_name','user_phone','user_address']);
  369. $this->repository->update($id, $data);
  370. return app('json')->success('操作成功');
  371. }
  372. /**
  373. * 核销
  374. * @param $code
  375. * @author xaboy
  376. * @day 2020/8/15
  377. */
  378. public function verify($id)
  379. {
  380. $data = $this->request->params(['data', 'verify_code']);
  381. $merId = $this->request->merId();
  382. // 根据订单ID、商家ID、验证码和订单类型查询订单,并连带查询订单产品信息
  383. $order = $this->repository->getWhere(['order_id' => $id, 'mer_id' => $merId, 'verify_code' => $data['verify_code'], 'order_type' => 1], '*', ['orderProduct']);
  384. // 如果订单不存在,则抛出验证异常
  385. if (!$order) return app('json')->fail('订单不存在');
  386. // 如果订单未支付,则抛出验证异常
  387. if (!$order->paid) return app('json')->fail('订单未支付');
  388. // 如果订单已全部核销,则抛出验证异常
  389. if ($order['status']) return app('json')->fail('订单已全部核销,请勿重复操作');
  390. $this->repository->verifyOrder($order, $data);
  391. return app('json')->success('订单核销成功');
  392. }
  393. /**
  394. * 根据订单编号获取订单详情
  395. *
  396. * @param string $code 订单编号
  397. * @return \Illuminate\Http\JsonResponse 返回订单详情或错误信息
  398. */
  399. public function verifyDetail($code)
  400. {
  401. // 通过订单编号查询订单
  402. $order = $this->repository->codeByDetail($code);
  403. // 如果订单不存在则返回错误信息
  404. if (!$order) return app('json')->fail('订单不存在');
  405. // 返回订单详情
  406. return app('json')->success($order);
  407. }
  408. /**
  409. * @param $id
  410. * @return mixed
  411. * @author Qinii
  412. * @day 2020-06-11
  413. */
  414. public function delete($id)
  415. {
  416. if (!$this->repository->userDelExists($id, $this->request->merId()))
  417. return app('json')->fail('订单信息或状态错误');
  418. $this->repository->merDelete($id);
  419. return app('json')->success('删除成功');
  420. }
  421. /**
  422. * 快递查询
  423. * @param $id
  424. * @return mixed
  425. * @author Qinii
  426. * @day 2020-06-25
  427. */
  428. public function express($id)
  429. {
  430. return app('json')->success($this->repository->express($id, $this->request->merId()));
  431. }
  432. /**
  433. *
  434. * @param $id
  435. * @return mixed
  436. * @author Qinii
  437. * @day 2020-07-30
  438. */
  439. public function reList($id)
  440. {
  441. [$page, $limit] = $this->getPage();
  442. $make = app()->make(MerchantReconciliationRepository::class);
  443. if (!$make->getWhereCount(['mer_id' => $this->request->merId(), 'reconciliation_id' => $id]))
  444. return app('json')->fail('数据不存在');
  445. $where = ['reconciliation_id' => $id, 'type' => 0];
  446. return app('json')->success($this->repository->reconList($where, $page, $limit));
  447. }
  448. /**
  449. * 导出文件
  450. * @author Qinii
  451. * @day 2020-07-30
  452. */
  453. public function excel()
  454. {
  455. [$page, $limit] = $this->getPage();
  456. $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']);
  457. $where['order_ids'] = $this->request->param('ids','');
  458. if ($where['pay_type'] != '') $where['pay_type'] = $this->repository::PAY_TYPE_FILTEER[$where['pay_type']];
  459. if ($where['take_order']) {
  460. $where['status'] = -1;
  461. $where['verify_date'] = $where['date'];
  462. unset($where['date']);
  463. unset($where['order_type']);
  464. }
  465. $where['mer_id'] = $this->request->merId();
  466. $data = app()->make(ExcelService::class)->order($where, $page, $limit);
  467. return app('json')->success($data);
  468. }
  469. /**
  470. * 打印小票
  471. * @param $id
  472. * @return mixed
  473. * @author Qinii
  474. * @day 2020-07-30
  475. */
  476. public function printer($id)
  477. {
  478. $merId = $this->request->merId();
  479. if (!$this->repository->getWhere(['order_id' => $id, 'mer_id' => $merId]))
  480. return app('json')->fail('数据不存在');
  481. $this->repository->batchPrinter($id, $merId,null);
  482. return app('json')->success('打印成功');
  483. }
  484. /**
  485. * 导出发货单
  486. * @return \think\response\Json
  487. * @author Qinii
  488. * @day 3/13/21
  489. */
  490. public function deliveryExport()
  491. {
  492. $where = $this->request->params(['username', 'date', 'activity_type', 'order_type', 'username', 'keywords', 'id']);
  493. $where['order_ids'] = $this->request->param('ids');
  494. $where['mer_id'] = $this->request->merId();
  495. $where['status'] = 0;
  496. $where['paid'] = 1;
  497. $make = app()->make(StoreOrderRepository::class);
  498. if (is_array($where['id'])) $where['order_ids'] = $where['id'];
  499. $count = $make->search($where)->find();
  500. if (!$count) return app('json')->fail('没有可导出数据');
  501. [$page, $limit] = $this->getPage();
  502. $data = app()->make(ExcelService::class)->delivery($where, $page, $limit);
  503. return app('json')->success($data);
  504. }
  505. /**
  506. * 获取指定节点的子节点列表
  507. *
  508. * @param int $id 节点ID
  509. * @return \think\response\Json 返回JSON格式的数据
  510. */
  511. public function childrenList($id)
  512. {
  513. // 调用repository层的childrenList方法获取子节点列表
  514. $data = $this->repository->childrenList($id, $this->request->merId());
  515. // 返回JSON格式的数据
  516. return app('json')->success($data);
  517. }
  518. /**
  519. * 将指定节点设置为下线状态
  520. *
  521. * @param int $id 节点ID
  522. * @return \think\response\Json 返回JSON格式的数据
  523. */
  524. public function offline($id)
  525. {
  526. // 调用repository层的offline方法将节点设置为下线状态
  527. $this->repository->offline($id, $this->request->merId());
  528. return app('json')->success('确认成功');
  529. }
  530. /**
  531. * 订单配货单
  532. * @return \think\response\Json
  533. * @author Qinii
  534. */
  535. public function note()
  536. {
  537. $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']);
  538. $where['order_ids'] = $this->request->param('ids','');
  539. if ($where['pay_type'] != '') $where['pay_type'] = $this->repository::PAY_TYPE_FILTEER[$where['pay_type']];
  540. if ($where['take_order']) {
  541. $where['status'] = -1;
  542. $where['verify_date'] = $where['date'];
  543. unset($where['date']);
  544. unset($where['order_type']);
  545. }
  546. $limit = $this->request->param('limit', 10);
  547. $merchant = $this->request->merchant()->toArray();
  548. // $merchant['qrcode'] = app()->make(MerchantRepository::class)->wxQrcode(intval($this->request->merId()));
  549. $data = $this->repository->note($where,$limit);
  550. return app('json')->success($data);
  551. }
  552. /**
  553. * 预约订单派单
  554. *
  555. * @param integer $id
  556. * @return json
  557. */
  558. public function reservationDispatch(int $id)
  559. {
  560. $params = $this->request->params(['staffs_id']);
  561. if (!$params['staffs_id']) {
  562. return app('json')->fail('请选择服务人员');
  563. }
  564. $res = $this->repository->reservationDispatch($id, $this->request->merId(), $params);
  565. if (!$res) {
  566. return app('json')->fail('派单失败');
  567. }
  568. return app('json')->success('派单成功');
  569. }
  570. /**
  571. * 预约订单改派
  572. *
  573. * @param integer $id
  574. * @return json
  575. */
  576. public function reservationUpdateDispatch(int $id)
  577. {
  578. $params = $this->request->params(['staffs_id']);
  579. if (!$params['staffs_id']) {
  580. return app('json')->fail('请选择服务人员');
  581. }
  582. $res = $this->repository->reservationUpdateDispatch($id, $this->request->merId(), $params);
  583. if (!$res) {
  584. return app('json')->fail('改派失败');
  585. }
  586. return app('json')->success('改派成功');
  587. }
  588. /**
  589. * 预约订单改期
  590. *
  591. * @param [type] $id
  592. * @return void
  593. */
  594. public function reservationReschedule(int $id)
  595. {
  596. $params = $this->request->params(
  597. [
  598. 'order_type',
  599. 'reservation_date',
  600. 'real_name',
  601. 'user_phone',
  602. 'user_address',
  603. 'order_extend',
  604. 'part_start',
  605. 'part_end'
  606. ]
  607. );
  608. $validate = app()->make(OrderValidate::class);
  609. if (!$validate->sceneReservationReschedule($params)) {
  610. return app('json')->fail($validate->getError());
  611. }
  612. $res = $this->repository->reservationReschedule($id, $this->request->merId(), $params);
  613. if (!$res) {
  614. return app('json')->fail('改约失败');
  615. }
  616. return app('json')->success('改约成功');
  617. }
  618. /**
  619. * 单独修改预约时间
  620. *
  621. * @param integer $id
  622. * @return json
  623. */
  624. public function reservationTime(int $id)
  625. {
  626. $params = $this->request->params(
  627. [
  628. 'reservation_date',
  629. 'part_start',
  630. 'part_end'
  631. ]
  632. );
  633. $validate = app()->make(OrderValidate::class);
  634. if (!$validate->sceneOnlyReservationTime($params)) {
  635. return app('json')->fail($validate->getError());
  636. }
  637. $res = $this->repository->updateReservationTime($id, $this->request->merId(), $params);
  638. if (!$res) {
  639. return app('json')->fail('修过失败');
  640. }
  641. return app('json')->success('修改成功');
  642. }
  643. /**
  644. * 预约订单核销
  645. *
  646. * @param integer $id
  647. * @return void
  648. */
  649. public function reservationVerify(int $id)
  650. {
  651. $res = $this->repository->reservationVerify($id, $this->request->merId());
  652. if (!$res) {
  653. return app('json')->fail('核销失败');
  654. }
  655. return app('json')->success('核销成功');
  656. }
  657. }