|
@@ -12,23 +12,24 @@ use support\Request;
|
|
|
use support\Response;
|
|
|
use Tinywan\Jwt\JwtToken;
|
|
|
|
|
|
-class RestaurantTableController extends Curd{
|
|
|
+class RestaurantTableController extends Curd
|
|
|
+{
|
|
|
public function __construct()
|
|
|
{
|
|
|
$this->model = new SysDept();
|
|
|
}
|
|
|
|
|
|
|
|
|
- public function select(Request $request):Response
|
|
|
+ public function select(Request $request): Response
|
|
|
{
|
|
|
$uid = JwtToken::getCurrentId();
|
|
|
- $user = SysUser::where('user_id',$uid)->first();
|
|
|
- $restaurant = SysDept::where('dept_category','餐厅')->where(function($query) use ($user) {
|
|
|
- $query->where('dept_id',$user->join_user_dept_id)->orWhere('dept_super_id',$user->join_user_dept_id);
|
|
|
+ $user = SysUser::where('user_id', $uid)->first();
|
|
|
+ $restaurant = SysDept::where('dept_category', '餐厅')->where(function ($query) use ($user) {
|
|
|
+ $query->where('dept_id', $user->join_user_dept_id)->orWhere('dept_super_id', $user->join_user_dept_id);
|
|
|
})->first();
|
|
|
// $restaurant = SysDept::where('dept_category','餐厅')->where('dept_super_id',$user->join_user_dept_id)->first();
|
|
|
- if(!$restaurant){
|
|
|
- return json_fail('您所在的营业场所没有餐厅,请联系管理员添加!');
|
|
|
+ if (!$restaurant) {
|
|
|
+ return json_fail('您所在的营业场所没有餐厅,请联系管理员添加!');
|
|
|
}
|
|
|
|
|
|
[$where, $format, $limit, $field, $order] = $this->selectInput($request);
|
|
@@ -37,7 +38,7 @@ class RestaurantTableController extends Curd{
|
|
|
$order = $request->get('order', 'desc');
|
|
|
$field = $field ?? 'dept_sort';
|
|
|
$query = $this->doSelect($where, $field, $order);
|
|
|
-
|
|
|
+
|
|
|
return $this->doFormat($query, $format, $limit);
|
|
|
}
|
|
|
|
|
@@ -86,12 +87,12 @@ class RestaurantTableController extends Curd{
|
|
|
public function insert(Request $request): Response
|
|
|
{
|
|
|
$uid = JwtToken::getCurrentId();
|
|
|
- $user = SysUser::where('user_id',$uid)->first();
|
|
|
- $restaurant = SysDept::where('dept_category','餐厅')->where(function($query) use ($user) {
|
|
|
- $query->where('dept_id',$user->join_user_dept_id)->orWhere('dept_super_id',$user->join_user_dept_id);
|
|
|
+ $user = SysUser::where('user_id', $uid)->first();
|
|
|
+ $restaurant = SysDept::where('dept_category', '餐厅')->where(function ($query) use ($user) {
|
|
|
+ $query->where('dept_id', $user->join_user_dept_id)->orWhere('dept_super_id', $user->join_user_dept_id);
|
|
|
})->first();
|
|
|
- if(!$restaurant){
|
|
|
- return json_fail('您所在的营业场所没有餐厅,请联系管理员添加!');
|
|
|
+ if (!$restaurant) {
|
|
|
+ return json_fail('您所在的营业场所没有餐厅,请联系管理员添加!');
|
|
|
}
|
|
|
|
|
|
Db::beginTransaction();
|
|
@@ -110,7 +111,7 @@ class RestaurantTableController extends Curd{
|
|
|
throw new BusinessException('创建桌台失败');
|
|
|
}
|
|
|
// 更新部门path
|
|
|
- $path = $restaurant-> dept_super_path . $deptId . '/';
|
|
|
+ $path = $restaurant->dept_super_path . $deptId . '/';
|
|
|
if (!SysDept::where('dept_id', $deptId)->update(['dept_super_path' => $path])) {
|
|
|
throw new BusinessException('创建桌台失败');
|
|
|
}
|
|
@@ -129,30 +130,30 @@ class RestaurantTableController extends Curd{
|
|
|
public function batchInsert(Request $request)
|
|
|
{
|
|
|
$params = $request->post();
|
|
|
- if(intval($params['dept_code_nbr']) < 1){
|
|
|
+ if (intval($params['dept_code_nbr']) < 1) {
|
|
|
return json_fail('数量不足,无法批量生成!');
|
|
|
}
|
|
|
- if(intval($params['dept_code']) < 1 || intval($params['dept_code'])+intval($params['dept_code']) > 999){
|
|
|
+ if (intval($params['dept_code']) < 1 || intval($params['dept_code']) + intval($params['dept_code']) > 999) {
|
|
|
return json_fail('请填写数字,且生成后不可大于999!');
|
|
|
}
|
|
|
|
|
|
$uid = JwtToken::getCurrentId();
|
|
|
- $user = SysUser::where('user_id',$uid)->first();
|
|
|
- $restaurant = SysDept::where('dept_category','餐厅')->where(function($query) use ($user) {
|
|
|
- $query->where('dept_id',$user->join_user_dept_id)->orWhere('dept_super_id',$user->join_user_dept_id);
|
|
|
+ $user = SysUser::where('user_id', $uid)->first();
|
|
|
+ $restaurant = SysDept::where('dept_category', '餐厅')->where(function ($query) use ($user) {
|
|
|
+ $query->where('dept_id', $user->join_user_dept_id)->orWhere('dept_super_id', $user->join_user_dept_id);
|
|
|
})->first();
|
|
|
- if(!$restaurant){
|
|
|
- return json_fail('您所在的营业场所没有餐厅,请联系管理员添加!');
|
|
|
+ if (!$restaurant) {
|
|
|
+ return json_fail('您所在的营业场所没有餐厅,请联系管理员添加!');
|
|
|
}
|
|
|
|
|
|
Db::beginTransaction();
|
|
|
try {
|
|
|
$data = $this->insertInput($request);
|
|
|
- for($i=0;$i<$params['dept_code_nbr'];$i++){
|
|
|
- $number = $i+intval($params['dept_code']);
|
|
|
+ for ($i = 0; $i < $params['dept_code_nbr']; $i++) {
|
|
|
+ $number = $i + intval($params['dept_code']);
|
|
|
$data['dept_category'] = '桌台';
|
|
|
- $data['dept_name'] = $number.'号桌';
|
|
|
- $data['dept_code'] = $restaurant->dept_code.'-'.$number;
|
|
|
+ $data['dept_name'] = $number . '号桌';
|
|
|
+ $data['dept_code'] = $restaurant->dept_code . '-' . $number;
|
|
|
$data['dept_super_id'] = $restaurant->dept_id;
|
|
|
$data['dept_city'] = $restaurant->dept_city;
|
|
|
$data['dept_telephone'] = $restaurant->dept_telephone;
|
|
@@ -165,7 +166,7 @@ class RestaurantTableController extends Curd{
|
|
|
throw new BusinessException('批量创建桌台失败');
|
|
|
}
|
|
|
// 更新部门path
|
|
|
- $path = $restaurant-> dept_super_path . $deptId . '/';
|
|
|
+ $path = $restaurant->dept_super_path . $deptId . '/';
|
|
|
if (!SysDept::where('dept_id', $deptId)->update(['dept_super_path' => $path])) {
|
|
|
throw new BusinessException('批量创建桌台失败');
|
|
|
}
|
|
@@ -205,76 +206,76 @@ class RestaurantTableController extends Curd{
|
|
|
public function exportTable(Request $request)
|
|
|
{
|
|
|
$uid = JwtToken::getCurrentId();
|
|
|
- $user = SysUser::where('user_id',$uid)->first();
|
|
|
- $restaurant = SysDept::where('dept_category','餐厅')->where(function($query) use ($user) {
|
|
|
- $query->where('dept_id',$user->join_user_dept_id)->orWhere('dept_super_id',$user->join_user_dept_id);
|
|
|
+ $user = SysUser::where('user_id', $uid)->first();
|
|
|
+ $restaurant = SysDept::where('dept_category', '餐厅')->where(function ($query) use ($user) {
|
|
|
+ $query->where('dept_id', $user->join_user_dept_id)->orWhere('dept_super_id', $user->join_user_dept_id);
|
|
|
})->first();
|
|
|
- if(!$restaurant){
|
|
|
- return json_fail('您所在的营业场所没有餐厅,请联系管理员添加!');
|
|
|
+ if (!$restaurant) {
|
|
|
+ return json_fail('您所在的营业场所没有餐厅,请联系管理员添加!');
|
|
|
}
|
|
|
|
|
|
$premisesId = '';
|
|
|
- if($restaurant->dept_category == '营业场所'){
|
|
|
+ if ($restaurant->dept_category == '营业场所') {
|
|
|
$premisesId = $restaurant->dept_id;
|
|
|
- }else{
|
|
|
- $dept = SysDept::where('dept_id',$restaurant->dept_super_id)->first();
|
|
|
- if ($dept && $dept->dept_category == '营业场所'){
|
|
|
+ } else {
|
|
|
+ $dept = SysDept::where('dept_id', $restaurant->dept_super_id)->first();
|
|
|
+ if ($dept && $dept->dept_category == '营业场所') {
|
|
|
$premisesId = $dept->dept_id;
|
|
|
}
|
|
|
}
|
|
|
- if (empty($premisesId)){
|
|
|
+ if (empty($premisesId)) {
|
|
|
return json_fail('没有查找到营业场所');
|
|
|
}
|
|
|
|
|
|
- $deptId = $request->get('dept_id',[]);
|
|
|
- $deptName = $request->get('dept_name','');
|
|
|
+ $deptId = $request->get('dept_id', []);
|
|
|
+ $deptName = $request->get('dept_name', '');
|
|
|
|
|
|
- $tables = SysDept::where('dept_category','桌台')
|
|
|
- ->where('dept_super_id',$restaurant->dept_id)
|
|
|
- ->when(!empty($deptId),function ($query) use ($deptId){
|
|
|
- $query->whereIn('dept_id',$deptId);
|
|
|
- })->when(!empty($deptName),function ($query) use ($deptName){
|
|
|
- $query->where('dept_name','like',$deptName);
|
|
|
+ $tables = SysDept::where('dept_category', '桌台')
|
|
|
+ ->where('dept_super_id', $restaurant->dept_id)
|
|
|
+ ->when(!empty($deptId), function ($query) use ($deptId) {
|
|
|
+ $query->whereIn('dept_id', $deptId);
|
|
|
+ })->when(!empty($deptName), function ($query) use ($deptName) {
|
|
|
+ $query->where('dept_name', 'like', $deptName);
|
|
|
})->get()
|
|
|
->toArray();
|
|
|
$data = [];
|
|
|
- foreach ($tables as $table){
|
|
|
+ foreach ($tables as $table) {
|
|
|
$data[] = [
|
|
|
- 'dept_name'=> $table['dept_name'],
|
|
|
- 'dept_code'=> $table['dept_code'],
|
|
|
- 'qrcode_content'=>json_encode([
|
|
|
- 'action'=>'scan-dishes',
|
|
|
- 'data'=>[
|
|
|
- 'premises'=>$premisesId,
|
|
|
- 'table'=>$table['dept_name'],
|
|
|
- 'dept'=>$table['dept_id']
|
|
|
+ 'dept_name' => $table['dept_name'],
|
|
|
+ 'dept_code' => $table['dept_code'],
|
|
|
+ 'qrcode_content' => json_encode([
|
|
|
+ 'action' => 'scan-dishes',
|
|
|
+ 'data' => [
|
|
|
+ 'premises' => $premisesId,
|
|
|
+ 'table' => $table['dept_name'],
|
|
|
+ 'dept' => $table['dept_id']
|
|
|
]
|
|
|
- ],JSON_UNESCAPED_UNICODE),
|
|
|
+ ], JSON_UNESCAPED_UNICODE),
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- return json_success('',$data);
|
|
|
+ return json_success('', $data);
|
|
|
}
|
|
|
|
|
|
public function downloadQrcode(Request $request)
|
|
|
{
|
|
|
- $tableId = $request->get('table_id','');
|
|
|
+ $tableId = $request->get('table_id', '');
|
|
|
$uid = JwtToken::getCurrentId();
|
|
|
- $user = SysUser::where('user_id',$uid)->first();
|
|
|
- $restaurant = SysDept::where('dept_category','餐厅')->where(function($query) use ($user) {
|
|
|
- $query->where('dept_id',$user->join_user_dept_id)->orWhere('dept_super_id',$user->join_user_dept_id);
|
|
|
+ $user = SysUser::where('user_id', $uid)->first();
|
|
|
+ $restaurant = SysDept::where('dept_category', '餐厅')->where(function ($query) use ($user) {
|
|
|
+ $query->where('dept_id', $user->join_user_dept_id)->orWhere('dept_super_id', $user->join_user_dept_id);
|
|
|
})->first();
|
|
|
- if(!$restaurant){
|
|
|
- return json_fail('您所在的营业场所没有餐厅,请联系管理员添加!');
|
|
|
+ if (!$restaurant) {
|
|
|
+ return json_fail('您所在的营业场所没有餐厅,请联系管理员添加!');
|
|
|
}
|
|
|
- $fileName = 'table-'.md5($tableId);
|
|
|
+ $fileName = 'table-' . md5($tableId);
|
|
|
// 图片已存在,删除之前的
|
|
|
- if (file_exists(public_path() . "/storage/qrcode/".$fileName.'.png')){
|
|
|
- unlink(public_path() . "/storage/qrcode/".$fileName.'.png');
|
|
|
+ if (file_exists(public_path() . "/storage/qrcode/" . $fileName . '.png')) {
|
|
|
+ unlink(public_path() . "/storage/qrcode/" . $fileName . '.png');
|
|
|
}
|
|
|
|
|
|
- $table = SysDept::where('dept_id',$tableId)->where('dept_category','桌台')->first();
|
|
|
- $restaurant = SysDept::where('dept_id',$table->dept_super_id)->first();
|
|
|
+ $table = SysDept::where('dept_id', $tableId)->where('dept_category', '桌台')->first();
|
|
|
+ $restaurant = SysDept::where('dept_id', $table->dept_super_id)->first();
|
|
|
// $premises = SysDept::where('dept_id',$restaurant->dept_super_id)->first();
|
|
|
// if (!$premises){
|
|
|
// return json_fail('营业场所不存在');
|
|
@@ -291,46 +292,84 @@ class RestaurantTableController extends Curd{
|
|
|
// . urlencode(json_encode($qrcodeContent)).
|
|
|
// "%7B%22action%22%3A%22scan-dishes%22%2C%22data%22%3A%7B%22premises%22%3A15%2C%22table%22%3A%221%E5%8F%B7%E5%8F%B0%22%2C%22tableid%22%3A16%7D%7D
|
|
|
// "&response_type=code&scope=snsapi_base&connect_redirect=1&state=#wechat_redirect";
|
|
|
- $url = getenv('TABLE_QRCODE_DOMAIN')."/qr?tid=".$table->dept_id;
|
|
|
+ $url = getenv('TABLE_QRCODE_DOMAIN') . "/qr?tid=" . $table->dept_id;
|
|
|
$qrcode = new Qrcode();
|
|
|
- $qrcode->setLabel($restaurant->dept_name."(".$table->dept_name.")");
|
|
|
- $qrcode = $qrcode->create($url,$fileName);
|
|
|
- if ($qrcode !== false){
|
|
|
- return json_success('success',['url'=>getenv('STORAGE_DOMAIN').'/storage/qrcode/'.$fileName.'.png']);
|
|
|
+ $qrcode->setLabel($restaurant->dept_name . "(" . $table->dept_name . ")");
|
|
|
+ $qrcode = $qrcode->create($url, $fileName);
|
|
|
+ if ($qrcode !== false) {
|
|
|
+ return json_success('success', ['url' => getenv('STORAGE_DOMAIN') . '/storage/qrcode/' . $fileName . '.png']);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public function batchDownloadQrcode(Request $request)
|
|
|
+ {
|
|
|
+ $uid = JwtToken::getCurrentId();
|
|
|
+ $user = SysUser::where('user_id', $uid)->first();
|
|
|
+ $restaurant = SysDept::where('dept_category', '餐厅')->where(function ($query) use ($user) {
|
|
|
+ $query->where('dept_id', $user->join_user_dept_id)->orWhere('dept_super_id', $user->join_user_dept_id);
|
|
|
+ })->first();
|
|
|
+
|
|
|
+ $tables = SysDept::where('dept_super_id',$restaurant->dept_id)
|
|
|
+ ->where('dept_category','桌台')
|
|
|
+ ->where('dept_status','<>','DISABLED')
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+ $zip = new \ZipArchive();
|
|
|
+ $filename = public_path().'/storage/qrcode/zip/'.$restaurant->dept_name.'-桌台.zip';
|
|
|
+ if (file_exists($filename)){
|
|
|
+ unlink($filename);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($zip->open($filename, \ZipArchive::CREATE) !== TRUE) {
|
|
|
+ return json_fail("创建压缩文件失败");
|
|
|
+ }
|
|
|
+ foreach ($tables as $table){
|
|
|
+ $fileName = $table['dept_name'];
|
|
|
+ $url = getenv('TABLE_QRCODE_DOMAIN') . "/qr?tid=" . $table['dept_id'];
|
|
|
+ $qrcode = new Qrcode();
|
|
|
+ $qrcode->setLabel($restaurant->dept_name . "(" . $table['dept_name'] . ")");
|
|
|
+ $qrcode = $qrcode->create($url, $fileName);
|
|
|
+ if ($qrcode !== false) {
|
|
|
+ $zip->addFile(public_path().'/storage/qrcode/' . $fileName . '.png',$fileName . '.png');
|
|
|
+// return json_success('success', ['url' => getenv('STORAGE_DOMAIN') . '/storage/qrcode/' . $fileName . '.png']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $zip->close();
|
|
|
+
|
|
|
+ return json_success('success', ['url' => getenv('STORAGE_DOMAIN') . '/storage/qrcode/zip/' . $restaurant->dept_name.'-桌台.zip']);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 桌台列表
|
|
|
*/
|
|
|
public function selectListByPremiseName(Request $request)
|
|
|
{
|
|
|
- $premiseName = $request->get('premise','');
|
|
|
+ $premiseName = $request->get('premise', '');
|
|
|
|
|
|
$tableList = [];
|
|
|
- try{
|
|
|
-
|
|
|
- $restaurant = SysDept::where('dept_name',$premiseName)->where('dept_category','餐厅')->where('dept_status','ACTIVED')->first();
|
|
|
- if (!$restaurant){
|
|
|
- $premise = SysDept::where('dept_name',$premiseName)->where('dept_category','营业场所')->where('dept_status','ACTIVED')->first();
|
|
|
+ try {
|
|
|
+
|
|
|
+ $restaurant = SysDept::where('dept_name', $premiseName)->where('dept_category', '餐厅')->where('dept_status', 'ACTIVED')->first();
|
|
|
+ if (!$restaurant) {
|
|
|
+ $premise = SysDept::where('dept_name', $premiseName)->where('dept_category', '营业场所')->where('dept_status', 'ACTIVED')->first();
|
|
|
|
|
|
- $restaurant = SysDept::where('dept_super_id',$premise->dept_id)->where('dept_category','餐厅')->where('dept_status','ACTIVED')->first();
|
|
|
- }
|
|
|
+ $restaurant = SysDept::where('dept_super_id', $premise->dept_id)->where('dept_category', '餐厅')->where('dept_status', 'ACTIVED')->first();
|
|
|
+ }
|
|
|
|
|
|
- $tables = SysDept::where('dept_super_id',$restaurant->dept_id)->where('dept_category','桌台')->get()->toArray();
|
|
|
+ $tables = SysDept::where('dept_super_id', $restaurant->dept_id)->where('dept_category', '桌台')->get()->toArray();
|
|
|
|
|
|
- foreach($tables as $table){
|
|
|
+ foreach ($tables as $table) {
|
|
|
$tableList[] = [
|
|
|
- 'key'=>$table['dept_id'],
|
|
|
- 'label'=>$table['dept_name'],
|
|
|
- 'disabled'=>$table['dept_status'] == 'ACTIVED' ? false : true
|
|
|
+ 'key' => $table['dept_id'],
|
|
|
+ 'label' => $table['dept_name'],
|
|
|
+ 'disabled' => $table['dept_status'] == 'ACTIVED' ? false : true
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- return json_success('',$tableList);
|
|
|
- }catch(\Exception $e){
|
|
|
- return json_success('',$tableList);
|
|
|
+ return json_success('', $tableList);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return json_success('', $tableList);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|