1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace App\Service;
- use App\Model\Area;
- use App\Model\Screen;
- /**
- * 区域相关
- * @package App\Models
- */
- class AreaService extends Service
- {
- public function edit($data){
- list($status,$msg) = $this->areaRule($data,false);
- if(!$status) return [$status,$msg];
- $model = Area::where('id',$data['id'])->first();
- $model->title = $data['title'];
- $model->code = $data['code'];
- $model->type = $data['type'];
- $model->save();
- return [true,'保存成功!'];
- }
- public function add($data){
- list($status,$msg) = $this->areaRule($data);
- if(!$status) return [$status,$msg];
- $model = new Area();
- $model->title = $data['title'];
- $model->code = $data['code'];
- $model->type = $data['type'];
- $model->save();
- return [true,'保存成功!'];
- }
- public function del($data){
- if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
- $bool = Screen::where('del_time',0)->whereIn('area_id',$data['id'])->exists();
- if($bool) return [false,'区域已经绑定仓'];
- Area::whereIn('id',$data['id'])->update([
- 'del_time'=>time()
- ]);
- return [true,'删除成功'];
- }
- public function AreaList($data){
- $model = Area::where('del_time',0)
- ->select('title','id','code','type')
- ->orderby('id', 'desc');
- if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
- if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
- if(! empty($data['type'])) $model->where('type', $data['type']);
- $list = $this->limit($model,'',$data);
- return [true,$list];
- }
- public function areaRule($data, $is_check = true){
- if(empty($data['title'])) return [false,'区域名称不能为空!'];
- if(empty($data['code'])) return [false,'区域编码不能为空!'];
- if(empty($data['type'])) return [false,'区域类型不能为空'];
- if($is_check){
- $bool = Area::whereRaw("(binary code = '{$data['code']}' OR title = '{$data['title']}')")
- ->where('type',$data['type'])
- ->where('del_time',0)
- ->exists();
- }else{
- if(empty($data['id'])) return [false,'id不能为空!'];
- $bool = Area::whereRaw("(binary code = '{$data['code']}' OR title = '{$data['title']}')")
- ->where('type',$data['type'])
- ->where('id','<>',$data['id'])
- ->where('del_time',0)
- ->exists();
- }
- if($bool) return [false,'编码或区域名称不能重复'];
- return [true, ''];
- }
- }
|