| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 | 
							- <?php
 
- namespace App\Service;
 
- use App\Model\BasicType;
 
- class BasicTypeService extends Service
 
- {
 
-     public function basicTypeEdit($data){
 
-         list($status,$msg) = $this->basicTypeRule($data,false);
 
-         if(!$status) return [$status,$msg];
 
-         $update = $msg['data'][0];
 
-         BasicType::where('id',$data['id'])->update($update);
 
-         return [true,''];
 
-     }
 
-     public function basicTypeAdd($data){
 
-         list($status,$msg) = $this->basicTypeRule($data);
 
-         if(!$status) return [$status,$msg];
 
-         BasicType::insert($msg['data']);
 
-         return [true,''];
 
-     }
 
-     public function basicTypeDel($data){
 
-         if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
 
-         BasicType::whereIn('id',$data['id'])->update([
 
-             'del_time'=>time()
 
-         ]);
 
-         return [true,''];
 
-     }
 
-     public function basicTypeList($data){
 
-         $model = BasicType::where('del_time',0)
 
-             ->select('title','id','type')
 
-             ->orderby('id', 'asc');
 
-         if(! empty($data['type'])) $model->where('type',$data['type']);
 
-         if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
 
-         $list = $this->limit($model,'',$data);
 
-         $list = $this->fillData($list);
 
-         return [true, $list];
 
-     }
 
-     public function basicTypeRule($data,$is_check = true){
 
-         if($this->isEmpty($data,'type')) return [false,'基础类型不能为空'];
 
-         if(! isset(BasicType::$type[$data['type']])) return [false,'基础类型不存在'];
 
-         if($this->isEmpty($data,'data')) return [false,'数据不能为空!'];
 
-         $title = array_column($data['data'],'title');
 
-         $title = array_map(function($val) {
 
-             return $val !== null ? $val : 0;
 
-         }, $title);
 
-         $title_count = array_count_values($title);
 
-         foreach ($title as $value){
 
-             if(empty($value)) return [false,'名称不能为空!'];
 
-             if($title_count[$value] > 1) return [false,'名称不能重复'];
 
-         }
 
-         foreach ($data['data'] as $key => $value){
 
-             $data['data'][$key]['type'] = $data['type'];
 
-             $data['data'][$key]['upd_time'] = time();
 
-             if($is_check){
 
-                 $bool = BasicType::where('title',$value['title'])
 
-                     ->where('type',$data['type'])
 
-                     ->where('del_time',0)
 
-                     ->exists();
 
-                 $data['data'][$key]['crt_time'] = time();
 
-             }else{
 
-                 if($this->isEmpty($data,'id')) return [false,'id不能为空!'];
 
-                 $bool = BasicType::where('title',$value['title'])
 
-                     ->where('type',$data['type'])
 
-                     ->where('id','<>',$data['id'])
 
-                     ->where('del_time',0)
 
-                     ->exists();
 
-             }
 
-             if($bool) return [false,'名称不能重复'];
 
-         }
 
-         return [true, $data];
 
-     }
 
-     public function fillData($data){
 
-         if(empty($data['data'])) return $data;
 
-         return $data;
 
-     }
 
- }
 
 
  |