Order.php 25 KB

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