|
@@ -3,6 +3,7 @@
|
|
|
namespace app\admin\controller\sys_manage;
|
|
|
|
|
|
use app\controller\Curd;
|
|
|
+use app\model\Device;
|
|
|
use app\model\Supplier;
|
|
|
use app\model\SysDept;
|
|
|
use app\model\SysUser;
|
|
@@ -12,21 +13,22 @@ use support\Request;
|
|
|
use support\Response;
|
|
|
use Tinywan\Jwt\JwtToken;
|
|
|
|
|
|
-class RestaurantController extends Curd{
|
|
|
+class RestaurantController extends Curd
|
|
|
+{
|
|
|
public function __construct()
|
|
|
{
|
|
|
$this->model = new SysDept();
|
|
|
}
|
|
|
|
|
|
|
|
|
- public function select(Request $request):Response
|
|
|
- {
|
|
|
+ public function select(Request $request): Response
|
|
|
+ {
|
|
|
[$where, $format, $limit, $field, $order] = $this->selectInput($request);
|
|
|
$where['dept_category'] = '餐厅';
|
|
|
$order = $request->get('order', 'desc');
|
|
|
$field = $field ?? 'dept_sort';
|
|
|
$query = $this->doSelect($where, $field, $order);
|
|
|
-
|
|
|
+
|
|
|
return $this->doFormat($query, $format, $limit);
|
|
|
}
|
|
|
|
|
@@ -71,7 +73,7 @@ class RestaurantController extends Curd{
|
|
|
}
|
|
|
return $model;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public function afterQuery($items)
|
|
|
{
|
|
|
foreach ($items as &$item) {
|
|
@@ -87,6 +89,21 @@ class RestaurantController extends Curd{
|
|
|
}
|
|
|
|
|
|
$item->dept_work = $deptWork;
|
|
|
+ if (!empty($extendJson['printer'])) {
|
|
|
+ $devices = Device::whereIn('device_id', $extendJson['printer'])
|
|
|
+ ->select('device_id', 'device_name', 'device_config_json')
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+ $deviceName = [];
|
|
|
+ foreach ($devices as $printer) {
|
|
|
+ if (empty($printer['device_config_json'])) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $deviceConfigJson = json_decode($printer['device_config_json'], true);
|
|
|
+ $deviceName[] = (isset($deviceConfigJson['dept_name']) ? $deviceConfigJson['dept_name'] . '-' : '') . $printer['device_name'];
|
|
|
+ }
|
|
|
+ $item->printer = implode(', ', $deviceName);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -107,8 +124,8 @@ class RestaurantController extends Curd{
|
|
|
Db::beginTransaction();
|
|
|
try {
|
|
|
$data = $this->insertInput($request);
|
|
|
- $premises = SysDept::where('dept_id',$data['dept_super_id'])->where('dept_category','营业场所')->first();
|
|
|
- if (!$premises){
|
|
|
+ $premises = SysDept::where('dept_id', $data['dept_super_id'])->where('dept_category', '营业场所')->first();
|
|
|
+ if (!$premises) {
|
|
|
Db::rollBack();
|
|
|
return json_fail('营销场所不存在');
|
|
|
}
|
|
@@ -118,18 +135,18 @@ class RestaurantController extends Curd{
|
|
|
throw new BusinessException('创建餐厅失败');
|
|
|
}
|
|
|
// 更新部门path
|
|
|
- $path = $premises-> dept_super_path . $deptId . '/';
|
|
|
+ $path = $premises->dept_super_path . $deptId . '/';
|
|
|
if (!SysDept::where('dept_id', $deptId)->update(['dept_super_path' => $path])) {
|
|
|
throw new BusinessException('创建餐厅失败');
|
|
|
}
|
|
|
// 新餐厅到供应商里
|
|
|
$supplierData = [
|
|
|
- 'join_supplier_category_id'=>55,
|
|
|
- 'join_supplier_dept_id'=>$deptId,
|
|
|
- 'supplier_status'=>'ACTIVED',
|
|
|
- 'supplier_category'=>'DEPT',
|
|
|
+ 'join_supplier_category_id' => 55,
|
|
|
+ 'join_supplier_dept_id' => $deptId,
|
|
|
+ 'supplier_status' => 'ACTIVED',
|
|
|
+ 'supplier_category' => 'DEPT',
|
|
|
'supplier_name' => $data['dept_name'],
|
|
|
- 'supplier_addtimes'=>time()
|
|
|
+ 'supplier_addtimes' => time()
|
|
|
];
|
|
|
Supplier::insert($supplierData);
|
|
|
|
|
@@ -144,13 +161,14 @@ class RestaurantController extends Curd{
|
|
|
}
|
|
|
return json_success('success');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
protected function insertInput(Request $request): array
|
|
|
{
|
|
|
$data = $this->inputFilter($request->post());
|
|
|
|
|
|
$work = $request->post('dept_work', []);
|
|
|
$dateWeek = $request->post('dept_week', []);
|
|
|
+ $printerIds = $request->post('printer_id', []);
|
|
|
$extendJson = [];
|
|
|
if (isset($work[0]) && isset($work[1])) {
|
|
|
$start = date('H:i', strtotime($work[0]));
|
|
@@ -181,6 +199,7 @@ class RestaurantController extends Curd{
|
|
|
$extendJson['weeks'] = $weekStr;
|
|
|
$extendJson['week'] = $dateWeek;
|
|
|
}
|
|
|
+ $extendJson['printer'] = $printerIds;
|
|
|
|
|
|
$data['dept_extend_json'] = json_encode($extendJson);
|
|
|
|
|
@@ -201,13 +220,13 @@ class RestaurantController extends Curd{
|
|
|
|
|
|
try {
|
|
|
[$id, $data] = $this->updateInput($request);
|
|
|
- $premises = SysDept::where('dept_id',$data['dept_super_id'])->where('dept_category','营业场所')->first();
|
|
|
- if (!$premises){
|
|
|
+ $premises = SysDept::where('dept_id', $data['dept_super_id'])->where('dept_category', '营业场所')->first();
|
|
|
+ if (!$premises) {
|
|
|
Db::rollBack();
|
|
|
return json_fail('营销场所不存在');
|
|
|
}
|
|
|
// 更新部门path
|
|
|
- $data['dept_super_path'] = $premises-> dept_super_path . $id . '/';
|
|
|
+ $data['dept_super_path'] = $premises->dept_super_path . $id . '/';
|
|
|
|
|
|
$this->doUpdate($id, $data);
|
|
|
} catch (BusinessException $customException) {
|
|
@@ -218,7 +237,7 @@ class RestaurantController extends Curd{
|
|
|
|
|
|
return json_success('success');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 更新前置方法
|
|
|
* @param Request $request
|
|
@@ -229,6 +248,7 @@ class RestaurantController extends Curd{
|
|
|
{
|
|
|
$work = $request->post('dept_work', []);
|
|
|
$dateWeek = $request->post('dept_week', []);
|
|
|
+ $printerIds = $request->post('printer_id', []);
|
|
|
$primary_key = $this->model->getKeyName();
|
|
|
$id = $request->post($primary_key);
|
|
|
$data = $this->inputFilter($request->post());
|
|
@@ -269,6 +289,7 @@ class RestaurantController extends Curd{
|
|
|
$extendJson['weeks'] = $weekStr;
|
|
|
$extendJson['week'] = $dateWeek;
|
|
|
}
|
|
|
+ $extendJson['printer'] = $printerIds;
|
|
|
|
|
|
$data['dept_extend_json'] = json_encode($extendJson);
|
|
|
|
|
@@ -291,26 +312,27 @@ class RestaurantController extends Curd{
|
|
|
*/
|
|
|
public function getPrinterByPremiseName(Request $request)
|
|
|
{
|
|
|
- $premiseName = $request->get('premise','');
|
|
|
+ $premiseName = $request->get('premise', '');
|
|
|
|
|
|
$printerList = [];
|
|
|
- try{
|
|
|
+ try {
|
|
|
|
|
|
- $resraurant = SysDept::where('dept_name',$premiseName)->where('dept_category','餐厅')->first();
|
|
|
- if (!$resraurant){
|
|
|
- $premise = SysDept::where('dept_name',$premiseName)->where('dept_category','营业场所')->first();
|
|
|
- $resraurant = SysDept::where('dept_super_id',$premise->dept_id)->where('dept_category','餐厅')->first();
|
|
|
+ $resraurant = SysDept::where('dept_name', $premiseName)->where('dept_category', '餐厅')->first();
|
|
|
+ if (!$resraurant) {
|
|
|
+ $premise = SysDept::where('dept_name', $premiseName)->where('dept_category', '营业场所')->first();
|
|
|
+ $resraurant = SysDept::where('dept_super_id', $premise->dept_id)->where('dept_category', '餐厅')->first();
|
|
|
}
|
|
|
-
|
|
|
- if (!empty($resraurant->dept_extend_json)){
|
|
|
- $deptExtendJson = json_decode($resraurant->dept_extend_json,true);
|
|
|
- if (isset($deptExtendJson['printer'])){
|
|
|
+
|
|
|
+ if (!empty($resraurant->dept_extend_json)) {
|
|
|
+ $deptExtendJson = json_decode($resraurant->dept_extend_json, true);
|
|
|
+ if (isset($deptExtendJson['printer'])) {
|
|
|
$printerList = $deptExtendJson['printer'];
|
|
|
}
|
|
|
}
|
|
|
- }catch(\Exception $e){}
|
|
|
-
|
|
|
- return json_success('',$printerList);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ }
|
|
|
+
|
|
|
+ return json_success('', $printerList);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -318,26 +340,26 @@ class RestaurantController extends Curd{
|
|
|
*/
|
|
|
public function getByUser(Request $request)
|
|
|
{
|
|
|
- $userId = $request->get('user_id',JwtToken::getCurrentId());
|
|
|
-
|
|
|
- $user = SysUser::where('user_id',$userId)->first();
|
|
|
- $restaurant = SysDept::where('dept_id',$user->join_user_dept_id)->where('dept_category','餐厅')->get()->toArray();
|
|
|
-
|
|
|
- if(empty($restaurant)){
|
|
|
- $premise = SysDept::where('dept_id',$user->join_user_dept_id)->where('dept_category','营业场所')->first();
|
|
|
- if (!empty($premise)){
|
|
|
- $restaurant = SysDept::where('dept_super_id',$premise->dept_id)->where('dept_category','餐厅')->get()->toArray();
|
|
|
+ $userId = $request->get('user_id', JwtToken::getCurrentId());
|
|
|
+
|
|
|
+ $user = SysUser::where('user_id', $userId)->first();
|
|
|
+ $restaurant = SysDept::where('dept_id', $user->join_user_dept_id)->where('dept_category', '餐厅')->get()->toArray();
|
|
|
+
|
|
|
+ if (empty($restaurant)) {
|
|
|
+ $premise = SysDept::where('dept_id', $user->join_user_dept_id)->where('dept_category', '营业场所')->first();
|
|
|
+ if (!empty($premise)) {
|
|
|
+ $restaurant = SysDept::where('dept_super_id', $premise->dept_id)->where('dept_category', '餐厅')->get()->toArray();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$data = [];
|
|
|
- foreach ($restaurant as $item){
|
|
|
+ foreach ($restaurant as $item) {
|
|
|
$data[] = [
|
|
|
- 'key'=>$item['dept_id'],
|
|
|
+ 'key' => $item['dept_id'],
|
|
|
'label' => $item['dept_name']
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- return json_success('success',$data);
|
|
|
+ return json_success('success', $data);
|
|
|
}
|
|
|
}
|