|
@@ -0,0 +1,62 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Service;
|
|
|
+
|
|
|
+use App\Model\TableSetting;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
+
|
|
|
+class TableHeadService extends Service
|
|
|
+{
|
|
|
+ public function tableheadAdd($data, $user){
|
|
|
+ if(empty($data['table_head'])) return [false,'自定义表头不能为空'];
|
|
|
+ if(empty($data['menu_id'])) return [false, 'menu_id不能为空'];
|
|
|
+
|
|
|
+ $time = time();
|
|
|
+ $insert = [];
|
|
|
+ foreach ($data['table_head'] as $value){
|
|
|
+ if(empty($value['key'])) return [false, 'key不能为空'];
|
|
|
+ if(empty($value['value'])) return [false, 'value不能为空'];
|
|
|
+ if(empty($value['sort'])) return [false, 'sort不能为空'];
|
|
|
+ if(empty($value['is_show'])) return [false, 'is_show不能为空'];
|
|
|
+
|
|
|
+ $insert[] = [
|
|
|
+ 'key' => $value['key'],
|
|
|
+ 'value' => $value['value'],
|
|
|
+ 'sort' => $value['sort'],
|
|
|
+ 'is_show' => $value['is_show'],
|
|
|
+ 'menu_id' => $data['menu_id'],
|
|
|
+ 'crt_time' => $time,
|
|
|
+ 'crt_id' => $user['id'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ try{
|
|
|
+ TableSetting::where('del_time',0)
|
|
|
+ ->where('crt_id',$user['id'])
|
|
|
+ ->where('menu_id',$data['menu_id'])
|
|
|
+ ->update(['del_time' => $time]);
|
|
|
+ TableSetting::insert($insert);
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ return [false, $exception->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true,''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function tableheadGet($data, $user){
|
|
|
+ if(empty($data['menu_id'])) return [false,'menu_id不能为空!'];
|
|
|
+
|
|
|
+ $header = config("header.{$data['menu_id']}") ?? [];
|
|
|
+
|
|
|
+ foreach ($header as $key => $value){
|
|
|
+ $header[$key]['sort'] = $key + 1;
|
|
|
+ $header[$key]['is_show'] = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, $header];
|
|
|
+ }
|
|
|
+}
|