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']!=2){ if(empty($data['path']) && empty($data['video'])){ $this->error = '文件不能为空'; return false; } if($data['type']==1){ $s = explode('.',$data['path']); $a = $s[count($s)-1]; if($a!='pdf'){ $this->error = '只能上传pdf文件'; return false; } } } $id = $data['id']; unset($data['id']); 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'); $data['create_yyyy'] = date('Y'); $data['create_mm'] = date('d'); $data['create_yyyymmdd'] = date('Ymd'); $ret = $this->allowField(true)->save($data); } if(!$ret){ $this->error = '操作失败'; return false; } return true; } public function getList(){ $list =$this ->where('org_id',cur_org_id()) ->where('del',0) ->where('enable',1) ->select() ->toArray(); return $list; } /*----------API-----------*/ public function lists($page,$size,$orgId,$roleId,$token){ $offset = ($page - 1) * $size; $map[] = ['org_id','=',$orgId]; $map[] = ['del','=',0]; $map[] = ['enable','=',1]; $parentId = Db::name('roles') ->where('id',$roleId) ->find(); if($parentId['parent_id'] >0){ $roleId = $parentId['parent_id']; } $m1 = $map; $m1[] = ['','exp', Db::raw("FIND_IN_SET({$roleId},roles_ids)")]; $m2 = $map; $m2[] = ['roles_ids','=',null]; $m3 = $map; $m3[] = ['roles_ids','=','']; $ret = $this->field('id,title,view,create_time,path,description as descrip,cate_id,limit,org_id') ->whereOr([ $m1, $m2, $m3 ]) ->limit($offset,$size) ->order(['sort'=>'desc','id'=>'desc']) ->select(); $ret = $ret?$ret->toArray():[]; $a = []; foreach ($ret as $k=>$v){ $v['url']=getSite().'/h5/Index/article?id='.$v['id'].'&token='.$token.'&org_id='.$orgId; $a[] = formatArray(['id','title','url','descrip','limit','create_time'] ,$v); } return $a; } }