| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 | 
							- <?php
 
- namespace App\Service;
 
- use App\Model\TSpaceSet;
 
- use Illuminate\Support\Facades\DB;
 
- class TSpaceService extends Service
 
- {
 
-     public function add($data, $user){
 
-         return [true, ''];
 
-     }
 
-     public function edit($data, $user){
 
-         list($status, $msg) = $this->constructionEditOtherRule($data, $user);
 
-         if(! $status) return [false, $msg];
 
-         DB::beginTransaction();
 
-         try{
 
-             $set = TSpaceSet::where('del_time',0)
 
-                 ->where('type', $data['type'])
 
-                 ->select('file', 'id')
 
-                 ->get()->toArray();
 
-             $set_map = array_column($set,'file','id');
 
-             $time = time();
 
-             $insert = $update = $new = $old = $id = [];
 
-             foreach ($data['data'] as $value){
 
-                 $text = "";
 
-                 if(! empty($value['text'])) $text = json_encode($data['text']);
 
-                 if(! empty($value['id'])){
 
-                     $file = $set_map[$value['id']] ?? "";
 
-                     if($value['file'] != $file){
 
-                         $old[] = $file;
 
-                     }else{
 
-                         $new[] = $value['file'];
 
-                     }
 
-                     $update[] = [
 
-                         'id' => $value['id'],
 
-                         'type' => $data['type'],
 
-                         'text' => $text,
 
-                         'file' => $value['file'],
 
-                         'crt_time' => $time,
 
-                     ];
 
-                     $id[] = $value['id'];
 
-                 }else{
 
-                     $new[] = $value['file'];
 
-                     $insert[] = [
 
-                         'type' => $data['type'],
 
-                         'text' => $text,
 
-                         'file' => $value['file'],
 
-                         'crt_time' => $time,
 
-                     ];
 
-                 }
 
-             }
 
-             foreach ($set as $value){
 
-                 if(! in_array($value['id'], $id)){
 
-                     $update[] = [
 
-                         'id' => $value['id'],
 
-                         'del_time' => $time,
 
-                     ];
 
-                     $old[] = $value['file'];
 
-                 }
 
-             }
 
-             if(! empty($update)){
 
-                 foreach ($update as $value){
 
-                     TSpaceSet::where('id',$value['id'])
 
-                         ->update($value);
 
-                 }
 
-             }
 
-             if(! empty($insert)) TSpaceSet::insert($insert);
 
-             DB::commit();
 
-         }catch (\Exception $exception){
 
-             DB::rollBack();
 
-             return [false, $exception->getMessage()];
 
-         }
 
-         return [true, ['file' => ['new' => $new, 'old' => $old]]];
 
-     }
 
-     public function constructionEditOtherRule($data,$user){
 
-         if(empty($data['type'])) return [false,'TSpace首页设置类型不能为空'];
 
-         if(! isset(TSpaceSet::$model_type_title[$data['type']])) return [false,'TSpace首页设置类型错误'];
 
-         if(empty($data['data'])) return [false, '设置内容不能为空'];
 
-         foreach ($data['data'] as $value){
 
-             if(empty($value['file'])) return [false, '文件不能为空'];
 
-         }
 
-         return [true, ''];
 
-     }
 
-     public function detail($data, $user){
 
-         if(empty($data['type'])) return [false,'TSpace首页设置类型不能为空'];
 
-         if(! isset(TSpaceSet::$model_type_title[$data['type']])) return [false,'TSpace首页设置类型错误'];
 
-         $set = TSpaceSet::where('del_time',0)
 
-             ->where('type', $data['type'])
 
-             ->select('file', 'id', 'text')
 
-             ->get()->toArray();
 
-         foreach ($set as $key => $value){
 
-             if(! empty($value['text'])) $set[$key]['text'] = json_decode($value['text'], true);
 
-         }
 
-         return [true, $set];
 
-     }
 
- }
 
 
  |