Staffs.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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\api\store\service;
  12. use think\App;
  13. use crmeb\basic\BaseController;
  14. use think\exception\ValidateException;
  15. use app\common\repositories\store\order\OrderStatus;
  16. use app\common\repositories\store\order\StoreOrderRepository;
  17. class Staffs extends BaseController
  18. {
  19. protected $repository;
  20. public function __construct(App $app, StoreOrderRepository $repository)
  21. {
  22. parent::__construct($app);
  23. $this->repository = $repository;
  24. }
  25. /**
  26. * 员工订单
  27. * @return \think\response\Json
  28. * @author Qinii
  29. */
  30. public function order_lst()
  31. {
  32. [$page, $limit] = $this->getPage();
  33. $where = $this->request->params([
  34. ['paid',1],
  35. ['status',''],
  36. ['assigned',''], // 0待领取 1已分配
  37. ['is_del',0],
  38. ['filter_product',4],
  39. ['order_type',0],
  40. ['store_name',''],
  41. ]);
  42. $where['reservation_date'] = $this->request->param('date','');
  43. $where['search'] = $this->request->param('store_name','');
  44. $where['staffs_ids'] = $this->request->staffsIds();
  45. if ($where['assigned'] == 1) {
  46. $where['enable_assigned'] = 0;
  47. $where['staffs_id'] = 0;
  48. $where['status'] = 0;
  49. unset($where['assigned'], $where['staffs_ids']);
  50. }
  51. $where['mer_ids'] = $this->request->staffsMerIds();
  52. $data = $this->repository->getList($where, $page, $limit);
  53. return app('json')->success($data);
  54. }
  55. /**
  56. * 订单详情
  57. * @param $id
  58. * @return \think\response\Json
  59. * @author Qinii
  60. */
  61. public function orderDetail($id)
  62. {
  63. $detail = $this->repository->getDetail($id);
  64. $this->checkAuth($detail);
  65. return app('json')->success($detail->toArray());
  66. }
  67. /**
  68. * 领取订单
  69. * @param int $id
  70. * @return \think\response\Json
  71. * @author Qinii
  72. */
  73. public function reservationDispatch(int $id)
  74. {
  75. $order = $this->repository->getWhere(['order_id' => $id,'order_type' => 0, 'status' => 0, 'paid' => 1, 'is_del' => 0], '*', ['refundOrder']);
  76. $this->checkAuth($order, 1);
  77. if($order['staffs_id'] != 0){
  78. return app('json')->fail('订单已派单,请检查');
  79. }
  80. $staffs_id = $this->request->staffsList()[$order['mer_id']]['staffs_id'];
  81. $res = $this->repository->selfDispatch($order['mer_id'], $order, $staffs_id);
  82. if (!$res)return app('json')->fail('领取失败');
  83. return app('json')->success('领取成功');
  84. }
  85. /**
  86. * 打卡
  87. * @param $id
  88. * @return \think\response\Json
  89. * @author Qinii
  90. */
  91. public function checkIn($id)
  92. {
  93. $clock_in_info = $this->request->param('clock_in_info');
  94. $order = $this->repository->getWhere(['order_id' => $id, 'status' => 1, 'paid' => 1, 'is_del' => 0]);
  95. if (!$order) {
  96. throw new ValidateException('订单不存在或未支付,请检查');
  97. }
  98. $this->checkAuth($order, $order['order_type']);
  99. $data['status'] = OrderStatus::RESERVATION_ORDER_STATUS_INSERVICE;
  100. $data['clock_in_info'] = json_encode($clock_in_info);
  101. $this->repository->update($id,$data);
  102. return app('json')->success('打卡成功');
  103. }
  104. /**
  105. * 提交服务凭证
  106. * @param $id
  107. * @return \think\response\Json
  108. * @author Qinii
  109. */
  110. public function addTrace($id)
  111. {
  112. $reservation_service_voucher = $this->request->param('reservation_service_voucher');
  113. $order = $this->repository->getWhere(['order_id' => $id, 'status' => 20, 'paid' => 1, 'is_del' => 0]);
  114. if (!$order) {
  115. throw new ValidateException('订单不存在或未支付,请检查');
  116. }
  117. $this->checkAuth($order, $order['order_type']);
  118. $data['reservation_service_voucher'] = json_encode($reservation_service_voucher);
  119. $this->repository->update($id,$data);
  120. return app('json')->success('提交成功');
  121. }
  122. /**
  123. * 核销订单
  124. * @param $id
  125. * @return \think\response\Json
  126. * @author Qinii
  127. */
  128. public function verify($id)
  129. {
  130. $params = $this->request->params(['mer_id']);
  131. if (!$params['mer_id']) {
  132. throw new ValidateException('参数错误');
  133. }
  134. $res = $this->repository->reservationVerify($id, $params['mer_id'], 0, $this->request->staffsList()[$params['mer_id']]['staffs_id']);
  135. if (!$res) {
  136. return app('json')->fail('核销失败');
  137. }
  138. return app('json')->success('核销成功');
  139. }
  140. public function checkAuth($order, $orderType = 0)
  141. {
  142. if (!$order)
  143. throw new ValidateException('订单不存在或未支付,请检查');
  144. if (!in_array($order['mer_id'],$this->request->staffsMerIds()))
  145. throw new ValidateException('没有权限');
  146. if (!$orderType) {
  147. if (!in_array($order['staffs_id'],$this->request->staffsIds()))
  148. return app('json')->fail('订单不属于你');
  149. }
  150. return true;
  151. }
  152. /**
  153. * 预约配置
  154. *
  155. * @return json
  156. */
  157. public function reservationConfig()
  158. {
  159. $data = $this->request->params(['mer_id']);
  160. if (!$data['mer_id']) {
  161. throw new ValidateException('参数错误');
  162. }
  163. $config = merchantConfig($data['mer_id'], ['enable_assigned', 'enable_checkin', 'checkin_radius','checkin_take_photo', 'enable_trace', 'trace_form_id']);
  164. $config['enable_assigned'] = $config['enable_assigned'] ?: 0;
  165. $config['enable_checkin'] = $config['enable_checkin'] ?: 0;
  166. $config['checkin_radius'] = $config['checkin_radius'] ?: 0;
  167. $config['enable_trace'] = $config['enable_trace'] ?: 0;
  168. $config['trace_form_id'] = $config['trace_form_id'] ?: 0;
  169. return app('json')->success($config);
  170. }
  171. public function mark($id, StoreOrderRepository $repository)
  172. {
  173. $order = $repository->getWhere(['order_id' => $id,]);
  174. $this->checkAuth($order);
  175. $data = $this->request->params(['remark']);
  176. $repository->update($id, $data);
  177. return app('json')->success('备注成功');
  178. }
  179. }