123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace app\common\model;
- use think\Db;
- class Article extends Base
- {
- protected $createTime = 'create_time';
- protected $updateTime = 'update_time';
- public $table = 'article';
- protected $validateName = 'Article';
- 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']!=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;
- }
- }
|