123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\controller\store\table;
- use think\facade\App;
- use app\controller\store\AuthController;
- use app\services\activity\table\TableSeatsServices;
- use app\services\activity\table\TableQrcodeServices;
- use app\services\other\CategoryServices;
- use app\services\user\UserServices;
- use app\services\other\queue\QueueServices;
- use app\services\other\QrcodeServices;
- /**
- * 桌码
- * Class TableCode
- * @package app\controller\store\table
- */
- class TableCode extends AuthController
- {
- /**
- * TableQrcodeServices constructor.
- * @param App $app
- * @param TableQrcodeServices $qrcodeServices
- */
- public function __construct(App $app, TableQrcodeServices $qrcodeServices)
- {
- parent::__construct($app);
- $this->qrcodeServices = $qrcodeServices;
- }
- /**获取餐桌座位数列表
- * @param TableSeatsServices $services
- * @return \think\Response
- */
- public function getTableSeats(TableSeatsServices $services)
- {
- $list = $services->TableSeatsList((int)$this->storeId);
- return app('json')->successful($list);
- }
- /**获取单个餐桌座位数
- * @param TableSeatsServices $services
- * @param $id
- * @return \think\Response
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getSeats(TableSeatsServices $services, $id)
- {
- $data = $services->get($id);
- return app('json')->successful($data);
- }
- /**添加、编辑餐桌座位数
- * @param TableSeatsServices $services
- * @param $id
- * @return \think\Response
- */
- public function setTableSeats(TableSeatsServices $services, $id)
- {
- $data = $this->request->getMore([
- ['number', 0]
- ]);
- if ($id) {
- $res = $services->update($id, ['number' => $data['number']]);
- } else {
- $data['store_id'] = (int)$this->storeId;
- $data['add_time'] = time();
- $res = $services->save($data);
- }
- if ($res) {
- return app('json')->success($id ? '修改成功' : '添加成功');
- } else {
- return app('json')->fail($id ? '修改失败' : '添加失败');
- }
- }
- /**删除餐桌座位数
- * @param TableSeatsServices $services
- * @param $id
- * @return \think\Response
- */
- public function delTableSeats(TableSeatsServices $services, $id)
- {
- $res = $services->delete($id);
- if ($res) {
- return app('json')->success('删除成功');
- } else {
- return app('json')->fail('删除失败');
- }
- }
- /**获取桌码分类列表
- * @param CategoryServices $services
- * @return \think\Response
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getTableCodeClassify(CategoryServices $services)
- {
- $where = ['type' => 1, 'relation_id' => $this->storeId, 'group' => 6, 'is_show' => 1];
- $list = $services->getCateList($where);
- foreach ($list['data'] as $key => &$itme) {
- $itme['add_time'] = date('Y-m-d H:i:s', $itme['add_time']);
- $itme['sum'] = $this->qrcodeServices->count(['cate_id' => $itme['id'], 'store_id' => $this->storeId, 'is_del' => 0]);
- }
- return app('json')->successful($list);
- }
- /**获取单个桌码分类
- * @param CategoryServices $services
- * @param $id
- * @return \think\Response
- */
- public function getOneClassify(CategoryServices $services, $id)
- {
- $data = $services->get($id);
- return app('json')->successful($data);
- }
- /**添加、编辑桌码分类
- * @param CategoryServices $services
- * @param $id
- * @return \think\Response
- */
- public function setTableCodeClassify(CategoryServices $services, $id)
- {
- $data = $this->request->getMore([
- ['name', '']
- ]);
- if ($id) {
- $res = $services->update($id, ['name' => $data['name']]);
- } else {
- $data['pid'] = 0;
- $data['type'] = 1;
- $data['group'] = 6;
- $data['is_show'] = 1;
- $data['relation_id'] = (int)$this->storeId;
- $data['add_time'] = time();
- $res = $services->save($data);
- }
- if ($res) {
- return app('json')->success($id ? '修改成功' : '添加成功');
- } else {
- return app('json')->fail($id ? '修改失败' : '添加失败');
- }
- }
- /**删除桌码分类
- * @param CategoryServices $services
- * @param $id
- * @return \think\Response
- */
- public function delTableCodeClassify(CategoryServices $services, $id)
- {
- $res = $services->delete($id);
- if ($res) {
- return app('json')->success('删除成功');
- } else {
- return app('json')->fail('删除失败');
- }
- }
- /**桌码添加、编辑
- * @param $id
- * @return \think\Response
- */
- public function addTableQrcode($id)
- {
- $data = $this->request->postMore([
- ['cate_id', 0],
- ['seat_num', 0],
- ['number', []],
- ['is_using', 0],
- ['remarks', '']
- ]);
- if ($id) {
- $data['table_number'] = is_array($data['number']) ? $data['number'][0] : $data['number'];
- unset($data['number']);
- $res = $this->qrcodeServices->update($id, $data);
- } else {
- $data['store_id'] = (int)$this->storeId;
- $data['add_time'] = time();
- $number = $data['number'];
- unset($data['number']);
- if (count($number) >= 2) {
- $dat = [];
- foreach ($number as $key => $datum) {
- if (!$this->qrcodeServices->be(['cate_id' => $data['cate_id'], 'store_id' => $data['store_id'], 'table_number' => $datum, 'is_del' => 0])) {
- $dat[$key] = $data;
- $dat[$key]['table_number'] = $datum;
- }
- }
- if (count($dat)) {
- $res = $this->qrcodeServices->saveAll($dat);
- } else {
- return app('json')->fail('同一分类下桌码不能重复');
- }
- } else {
- $data['table_number'] = $number[0];
- 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('同一分类下桌码不能重复');
- $res = $this->qrcodeServices->save($data);
- }
- }
- if ($res) {
- return app('json')->success($id ? '修改成功' : '添加成功');
- } else {
- return app('json')->fail($id ? '修改失败' : '添加失败');
- }
- }
- /**获取单个桌码
- * @param $id
- * @return \think\Response
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getOneTableQrcodey($id)
- {
- $data = $this->qrcodeServices->get($id);
- return app('json')->successful($data);
- }
- /**删除桌码
- * @param $id
- * @return \think\Response
- */
- public function delTableQrcodey($id)
- {
- $res = $this->qrcodeServices->update($id, ['is_del' => 1]);
- if ($res) {
- return app('json')->success('删除成功');
- } else {
- return app('json')->fail('删除失败');
- }
- }
- /**获取桌码列表
- * @return \think\Response
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getTableQrcodeyList()
- {
- $where = $this->request->getMore([
- ['cate_id', '']
- ]);
- $list = $this->qrcodeServices->tableQrcodeyList($where, (int)$this->storeId);
- return app('json')->successful($list);
- }
- /**桌码操作启用
- * @param $id
- * @return \think\Response
- */
- public function updateUsing($id)
- {
- $where = $this->request->getMore([
- ['is_using', 0]
- ]);
- $res = $this->qrcodeServices->update($id, ['is_using' => $where['is_using']]);
- if ($res) {
- return app('json')->success('操作成功');
- } else {
- return app('json')->fail('操作失败');
- }
- }
- }
|