Table.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\cashier;
  12. use app\Request;
  13. use app\services\activity\table\TableSeatsServices;
  14. use app\services\activity\table\TableQrcodeServices;
  15. use app\services\message\NoticeService;
  16. use app\services\order\StoreOrderCartInfoServices;
  17. use app\services\order\StoreOrderServices;
  18. use app\services\other\CategoryServices;
  19. use app\services\store\SystemStoreStaffServices;
  20. use app\services\user\UserServices;
  21. use app\services\other\queue\QueueServices;
  22. use app\services\other\QrcodeServices;
  23. use app\services\activity\collage\UserCollageServices;
  24. use app\services\activity\collage\UserCollagePartakeServices;
  25. /**
  26. * 收银台桌码
  27. * Class Table
  28. * @package app\controller\cashier
  29. */
  30. class Table extends AuthController
  31. {
  32. /**桌码管理
  33. * @param CategoryServices $services
  34. * @return \think\Response
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\DbException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. */
  39. public function getTableCode(CategoryServices $services)
  40. {
  41. $where = ['type' => 1, 'relation_id' => $this->storeId, 'group' => 6, 'is_show' => 1];
  42. $list = $services->getTableCodeCateList($where, ['id', 'relation_id', 'name', 'group'], ['tableQrcode']);
  43. return $this->success($list);
  44. }
  45. /**桌码订单列表
  46. * @param Request $request
  47. * @param UserCollageServices $services
  48. * @return \think\Response
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\DbException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. */
  53. public function getTableCodeList(Request $request, UserCollageServices $services)
  54. {
  55. $where = $request->getMore([
  56. ['type', 10],
  57. ['status', ''],
  58. ['time', ''],
  59. ['staff_id', 0],
  60. ['keyword', '', '', 'serial_number']
  61. ]);
  62. if ($where['time'] && is_array($where['time']) && count($where['time']) == 2) {
  63. [$start, $end] = $where['time'];
  64. if (strtotime($start) > strtotime($end)) {
  65. return $this->fail('开始时间不能大于结束时间,请重新选择时间');
  66. }
  67. }
  68. if (isset($where['status']) && $where['status'] == '') {
  69. $where['status'] = [0, 1, 2, 3];
  70. } else if (isset($where['status']) && $where['status'] == 1) {
  71. $where['status'] = [0, 1];
  72. }
  73. $where['store_id'] = $this->storeId;
  74. $data = $services->getStoreTableCodeList($where);
  75. return $this->success($data);
  76. }
  77. /**订单购物车信息
  78. * @param $oid
  79. * @return mixed
  80. */
  81. public function getOrderInfo($oid)
  82. {
  83. /** @var StoreOrderServices $orderService */
  84. $orderService = app()->make(StoreOrderServices::class);
  85. $orderInfo = $orderService->get($oid, ['id', 'uid', 'order_id', 'status as order_status', 'pay_type', 'paid', 'deduction_price', 'coupon_price', 'total_price', 'pay_price','change_price', 'paid', 'refund_status', 'staff_id', 'remark', 'is_del', 'is_system_del']);
  86. $orderInfo = $orderInfo->toArray();
  87. if ($orderInfo['paid'] == 1 && $orderInfo['refund_status'] == 4) {
  88. $orderInfo['status_name'] = '退款中';
  89. } else if ($orderInfo['paid'] == 1 && $orderInfo['refund_status'] == 3) {
  90. $orderInfo['status_name'] = '部分退款';
  91. } else if ($orderInfo['paid'] == 1 && $orderInfo['refund_status'] == 2) {
  92. $orderInfo['status_name'] = '已退款';
  93. } else {
  94. $orderInfo['status_name'] = '';
  95. }
  96. /** @var UserServices $userService */
  97. $userService = app()->make(UserServices::class);
  98. $orderInfo['userInfo'] = $userService->getUserInfo($orderInfo['uid']);
  99. $orderInfo['staff'] = [];
  100. if (isset($orderInfo['staff_id']) && $orderInfo['staff_id']) {
  101. /** @var SystemStoreStaffServices $staffService */
  102. $staffService = app()->make(SystemStoreStaffServices::class);
  103. $staff = $staffService->get((int)$orderInfo['staff_id'], ['uid', 'staff_name']);
  104. $orderInfo['staff'] = $staff ?? [];
  105. }
  106. /** @var StoreOrderCartInfoServices $services */
  107. $services = app()->make(StoreOrderCartInfoServices::class);
  108. $_info = $services->getOrderCartInfo((int)$oid);
  109. foreach ($_info as $key => &$item) {
  110. $item['cart_info']['vip_sum_truePrice'] = bcmul($item['cart_info']['vip_truePrice'], $item['cart_info']['cart_num'] ? $item['cart_info']['cart_num'] : 1, 2);
  111. }
  112. $orderInfo['_info'] = $_info;
  113. //核算优惠金额
  114. $vipTruePrice = 0;
  115. foreach ($orderInfo['_info'] ?? [] as $key => $cart) {
  116. $vipTruePrice = bcadd((string)$vipTruePrice, (string)$cart['cart_info']['vip_sum_truePrice'], 2);
  117. }
  118. $orderInfo['vip_true_price'] = $vipTruePrice;
  119. $orderInfo['is_cashier_yue_pay_verify'] = (int)sys_config('is_cashier_yue_pay_verify'); // 收银台余额支付是否需要验证【是/否】
  120. return $this->success($orderInfo);
  121. }
  122. /**获取全部点餐用户信息
  123. * @param Request $request
  124. * @param UserCollagePartakeServices $services
  125. * @return \think\Response
  126. * @throws \think\db\exception\DataNotFoundException
  127. * @throws \think\db\exception\DbException
  128. * @throws \think\db\exception\ModelNotFoundException
  129. */
  130. public function getTableCodeUserAll(Request $request, UserCollagePartakeServices $services)
  131. {
  132. $where = $request->getMore([
  133. ['table_id', 0],
  134. ]);
  135. if (!$where['table_id']) return $this->fail('参数有误!');
  136. $store_id = (int)$this->storeId;
  137. $uids = $services->tableCodeUserAll($where, $store_id);
  138. return $this->success($uids);
  139. }
  140. /**
  141. * 购物车处理
  142. * @param Request $request
  143. * @return mixed
  144. */
  145. public function getCartList(Request $request)
  146. {
  147. [$table_id, $uid] = $request->getMore([
  148. ['table_id', 0],
  149. ['uid', 0],
  150. ], true);
  151. if (!$table_id) return app('json')->fail('参数有误!');
  152. /** @var UserCollagePartakeServices $partakeService */
  153. $partakeService = app()->make(UserCollagePartakeServices::class);
  154. $cartIds = $partakeService->allUserSettleAccountsTableCode($table_id, $uid, 10);
  155. return $this->success($cartIds);
  156. }
  157. /**收银台购物车数量操作
  158. * @param Request $request
  159. * @return mixed
  160. * @throws \think\db\exception\DataNotFoundException
  161. * @throws \think\db\exception\DbException
  162. * @throws \think\db\exception\ModelNotFoundException
  163. */
  164. public function editCart(Request $request)
  165. {
  166. $where = $request->postMore([
  167. ['productId', 0],//普通商品编号
  168. [['cartNum', 'd'], 1], //购物车数量
  169. ['uniqueId', ''],//属性唯一值
  170. ['tableId', 0],//桌码ID
  171. ['isAdd', 1],//购物车数量加减 1 加 0 减
  172. ]);
  173. $store_id = (int)$this->storeId;
  174. /** @var UserCollagePartakeServices $partakeService */
  175. $partakeService = app()->make(UserCollagePartakeServices::class);
  176. $res = $partakeService->editTableCartProduct($where, $store_id);
  177. if ($res) {
  178. return $this->success('ok');
  179. } else {
  180. return $this->fail('操作失败');
  181. }
  182. }
  183. /**取消桌码
  184. * @param Request $request
  185. * @param UserCollageServices $services
  186. * @return \think\Response
  187. */
  188. public function cancelInitiateTable(Request $request, UserCollageServices $services)
  189. {
  190. [$tableId, $qrcodeId, $oid] = $request->getMore([
  191. ['tableId', 0],
  192. ['qrcode_id', 0],
  193. ['oid', 0],
  194. ], true);
  195. $where = ['status' => -1];
  196. if (!$tableId) return app('json')->fail('参数有误!');
  197. $res = $services->userUpdate((int)$tableId, $where);
  198. if ($res) {
  199. /** @var UserCollagePartakeServices $partakeService */
  200. $partakeService = app()->make(UserCollagePartakeServices::class);
  201. $partakeService->del(['collate_code_id' => $tableId]);
  202. /** @var TableQrcodeServices $qrcodeService */
  203. $qrcodeService = app()->make(TableQrcodeServices::class);
  204. $qrcodeService->update($qrcodeId, ['is_use' => 0, 'eat_number' => 0, 'order_time' => 0]);
  205. if ($oid) {
  206. /** @var StoreOrderServices $orderService */
  207. $orderService = app()->make(StoreOrderServices::class);
  208. $orderService->update($oid, ['is_del' => 1, 'is_system_del' => 1]);
  209. }
  210. return app('json')->successful('ok');
  211. } else {
  212. return app('json')->fail('取消失败');
  213. }
  214. }
  215. /**
  216. * 手动打单
  217. * @param Request $request
  218. * @param UserCollageServices $services
  219. * @return \think\Response
  220. * @throws \think\db\exception\DataNotFoundException
  221. * @throws \think\db\exception\DbException
  222. * @throws \think\db\exception\ModelNotFoundException
  223. */
  224. public function staffPlaceOrder(Request $request, UserCollageServices $services)
  225. {
  226. [$tableId] = $request->getMore([
  227. ['tableId', 0],
  228. ], true);
  229. $store_id = (int)$this->storeId;
  230. $res = $services->tablePrint((int)$tableId, $store_id);
  231. if ($res) {
  232. return app('json')->successful('打单成功');
  233. } else {
  234. return app('json')->fail('打单失败');
  235. }
  236. }
  237. }