TableCode.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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\store\table;
  12. use think\facade\App;
  13. use app\controller\store\AuthController;
  14. use app\services\activity\table\TableSeatsServices;
  15. use app\services\activity\table\TableQrcodeServices;
  16. use app\services\other\CategoryServices;
  17. use app\services\user\UserServices;
  18. use app\services\other\queue\QueueServices;
  19. use app\services\other\QrcodeServices;
  20. /**
  21. * 桌码
  22. * Class TableCode
  23. * @package app\controller\store\table
  24. */
  25. class TableCode extends AuthController
  26. {
  27. /**
  28. * TableQrcodeServices constructor.
  29. * @param App $app
  30. * @param TableQrcodeServices $qrcodeServices
  31. */
  32. public function __construct(App $app, TableQrcodeServices $qrcodeServices)
  33. {
  34. parent::__construct($app);
  35. $this->qrcodeServices = $qrcodeServices;
  36. }
  37. /**获取餐桌座位数列表
  38. * @param TableSeatsServices $services
  39. * @return \think\Response
  40. */
  41. public function getTableSeats(TableSeatsServices $services)
  42. {
  43. $list = $services->TableSeatsList((int)$this->storeId);
  44. return app('json')->successful($list);
  45. }
  46. /**获取单个餐桌座位数
  47. * @param TableSeatsServices $services
  48. * @param $id
  49. * @return \think\Response
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\DbException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. */
  54. public function getSeats(TableSeatsServices $services, $id)
  55. {
  56. $data = $services->get($id);
  57. return app('json')->successful($data);
  58. }
  59. /**添加、编辑餐桌座位数
  60. * @param TableSeatsServices $services
  61. * @param $id
  62. * @return \think\Response
  63. */
  64. public function setTableSeats(TableSeatsServices $services, $id)
  65. {
  66. $data = $this->request->getMore([
  67. ['number', 0]
  68. ]);
  69. if ($id) {
  70. $res = $services->update($id, ['number' => $data['number']]);
  71. } else {
  72. $data['store_id'] = (int)$this->storeId;
  73. $data['add_time'] = time();
  74. $res = $services->save($data);
  75. }
  76. if ($res) {
  77. return app('json')->success($id ? '修改成功' : '添加成功');
  78. } else {
  79. return app('json')->fail($id ? '修改失败' : '添加失败');
  80. }
  81. }
  82. /**删除餐桌座位数
  83. * @param TableSeatsServices $services
  84. * @param $id
  85. * @return \think\Response
  86. */
  87. public function delTableSeats(TableSeatsServices $services, $id)
  88. {
  89. $res = $services->delete($id);
  90. if ($res) {
  91. return app('json')->success('删除成功');
  92. } else {
  93. return app('json')->fail('删除失败');
  94. }
  95. }
  96. /**获取桌码分类列表
  97. * @param CategoryServices $services
  98. * @return \think\Response
  99. * @throws \think\db\exception\DataNotFoundException
  100. * @throws \think\db\exception\DbException
  101. * @throws \think\db\exception\ModelNotFoundException
  102. */
  103. public function getTableCodeClassify(CategoryServices $services)
  104. {
  105. $where = ['type' => 1, 'relation_id' => $this->storeId, 'group' => 6, 'is_show' => 1];
  106. $list = $services->getCateList($where);
  107. foreach ($list['data'] as $key => &$itme) {
  108. $itme['add_time'] = date('Y-m-d H:i:s', $itme['add_time']);
  109. $itme['sum'] = $this->qrcodeServices->count(['cate_id' => $itme['id'], 'store_id' => $this->storeId, 'is_del' => 0]);
  110. }
  111. return app('json')->successful($list);
  112. }
  113. /**获取单个桌码分类
  114. * @param CategoryServices $services
  115. * @param $id
  116. * @return \think\Response
  117. */
  118. public function getOneClassify(CategoryServices $services, $id)
  119. {
  120. $data = $services->get($id);
  121. return app('json')->successful($data);
  122. }
  123. /**添加、编辑桌码分类
  124. * @param CategoryServices $services
  125. * @param $id
  126. * @return \think\Response
  127. */
  128. public function setTableCodeClassify(CategoryServices $services, $id)
  129. {
  130. $data = $this->request->getMore([
  131. ['name', '']
  132. ]);
  133. if ($id) {
  134. $res = $services->update($id, ['name' => $data['name']]);
  135. } else {
  136. $data['pid'] = 0;
  137. $data['type'] = 1;
  138. $data['group'] = 6;
  139. $data['is_show'] = 1;
  140. $data['relation_id'] = (int)$this->storeId;
  141. $data['add_time'] = time();
  142. $res = $services->save($data);
  143. }
  144. if ($res) {
  145. return app('json')->success($id ? '修改成功' : '添加成功');
  146. } else {
  147. return app('json')->fail($id ? '修改失败' : '添加失败');
  148. }
  149. }
  150. /**删除桌码分类
  151. * @param CategoryServices $services
  152. * @param $id
  153. * @return \think\Response
  154. */
  155. public function delTableCodeClassify(CategoryServices $services, $id)
  156. {
  157. $res = $services->delete($id);
  158. if ($res) {
  159. return app('json')->success('删除成功');
  160. } else {
  161. return app('json')->fail('删除失败');
  162. }
  163. }
  164. /**桌码添加、编辑
  165. * @param $id
  166. * @return \think\Response
  167. */
  168. public function addTableQrcode($id)
  169. {
  170. $data = $this->request->postMore([
  171. ['cate_id', 0],
  172. ['seat_num', 0],
  173. ['number', []],
  174. ['is_using', 0],
  175. ['remarks', '']
  176. ]);
  177. if ($id) {
  178. $data['table_number'] = is_array($data['number']) ? $data['number'][0] : $data['number'];
  179. unset($data['number']);
  180. $res = $this->qrcodeServices->update($id, $data);
  181. } else {
  182. $data['store_id'] = (int)$this->storeId;
  183. $data['add_time'] = time();
  184. $number = $data['number'];
  185. unset($data['number']);
  186. if (count($number) >= 2) {
  187. $dat = [];
  188. foreach ($number as $key => $datum) {
  189. if (!$this->qrcodeServices->be(['cate_id' => $data['cate_id'], 'store_id' => $data['store_id'], 'table_number' => $datum, 'is_del' => 0])) {
  190. $dat[$key] = $data;
  191. $dat[$key]['table_number'] = $datum;
  192. }
  193. }
  194. if (count($dat)) {
  195. $res = $this->qrcodeServices->saveAll($dat);
  196. } else {
  197. return app('json')->fail('同一分类下桌码不能重复');
  198. }
  199. } else {
  200. $data['table_number'] = $number[0];
  201. if ($this->qrcodeServices->be(['cate_id' => $data['cate_id'], 'store_id' => $data['store_id'], 'table_number' => $data['table_number'], 'is_del' => 0])) return app('json')->fail('同一分类下桌码不能重复');
  202. $res = $this->qrcodeServices->save($data);
  203. }
  204. }
  205. if ($res) {
  206. return app('json')->success($id ? '修改成功' : '添加成功');
  207. } else {
  208. return app('json')->fail($id ? '修改失败' : '添加失败');
  209. }
  210. }
  211. /**获取单个桌码
  212. * @param $id
  213. * @return \think\Response
  214. * @throws \think\db\exception\DataNotFoundException
  215. * @throws \think\db\exception\DbException
  216. * @throws \think\db\exception\ModelNotFoundException
  217. */
  218. public function getOneTableQrcodey($id)
  219. {
  220. $data = $this->qrcodeServices->get($id);
  221. return app('json')->successful($data);
  222. }
  223. /**删除桌码
  224. * @param $id
  225. * @return \think\Response
  226. */
  227. public function delTableQrcodey($id)
  228. {
  229. $res = $this->qrcodeServices->update($id, ['is_del' => 1]);
  230. if ($res) {
  231. return app('json')->success('删除成功');
  232. } else {
  233. return app('json')->fail('删除失败');
  234. }
  235. }
  236. /**获取桌码列表
  237. * @return \think\Response
  238. * @throws \think\db\exception\DataNotFoundException
  239. * @throws \think\db\exception\DbException
  240. * @throws \think\db\exception\ModelNotFoundException
  241. */
  242. public function getTableQrcodeyList()
  243. {
  244. $where = $this->request->getMore([
  245. ['cate_id', '']
  246. ]);
  247. $list = $this->qrcodeServices->tableQrcodeyList($where, (int)$this->storeId);
  248. return app('json')->successful($list);
  249. }
  250. /**桌码操作启用
  251. * @param $id
  252. * @return \think\Response
  253. */
  254. public function updateUsing($id)
  255. {
  256. $where = $this->request->getMore([
  257. ['is_using', 0]
  258. ]);
  259. $res = $this->qrcodeServices->update($id, ['is_using' => $where['is_using']]);
  260. if ($res) {
  261. return app('json')->success('操作成功');
  262. } else {
  263. return app('json')->fail('操作失败');
  264. }
  265. }
  266. }