1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace app\common\model;
- use think\Db;
- class CleanType extends Base
- {
- protected $createTime = 'create_time';
- protected $updateTime = 'update_time';
- public $table = 'clean_type';
- protected $validateName = 'CleanType';
- public function updates(){
- $data = request()->post();
- $data['org_id'] = cur_org_id();
- $result = validate($this->validateName)->check($data,[],'');
- if(true !== $result){
- $this->error = validate($this->validateName)->getError();
- return false;
- }
- if($data['type']==1){
- if(empty($data['parent_id'])){
- $this->error = '请选择任务类型';
- return false;
- }
- }
- $id = $data['id'];
- unset($data['id']);
- unset($data['type']);
- if($id > 0){
- $data['update_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $data['create_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- $this->error = '操作失败';
- return false;
- }
- return true;
- }
- //获取任务类型
- public function list(){
- $list =$this
- ->where('parent_id',0)
- ->where('enable',1)
- ->where('del',0)
- ->where('org_id',cur_org_id())
- ->select()
- ->toArray();
- return $list;
- }
- //获取任务项
- public function getList(){
- $list =$this
- ->where('parent_id','>',0)
- ->where('enable',1)
- ->where('del',0)
- ->where('org_id',cur_org_id())
- ->select()
- ->toArray();
- return $list?$list:[];
- }
- public function getGroupList(){
- $arr =[];
- $list = $this->list();
- foreach ($list as $k=>$v){
- $ids = $this
- ->where('enable',1)
- ->where('del',0)
- ->where('parent_id',$v['id'])->column('id');
- $a = [];
- $lists = Db::name('clean_form')
- ->whereIn('type_id',$ids)
- ->select();
- foreach ($lists as $v1){
- $a[] = $v1;
- }
- $arr[] = [
- 'label'=>$v['title'],
- 'options'=>$a
- ];
- }
- return $arr;
- }
- }
|