Article.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class Article extends Base
  5. {
  6. protected $createTime = 'create_time';
  7. protected $updateTime = 'update_time';
  8. public $table = 'article';
  9. protected $validateName = 'Article';
  10. public function updates(){
  11. $data = request()->post();
  12. $data['org_id'] =cur_org_id();
  13. $result = validate($this->validateName)->check($data,[],'');
  14. if(true !== $result){
  15. $this->error = validate($this->validateName)->getError();
  16. return false;
  17. }
  18. if($data['type']!=2){
  19. if(empty($data['path']) && empty($data['video'])){
  20. $this->error = '文件不能为空';
  21. return false;
  22. }
  23. if($data['type']==1){
  24. $s = explode('.',$data['path']);
  25. $a = $s[count($s)-1];
  26. if($a!='pdf'){
  27. $this->error = '只能上传pdf文件';
  28. return false;
  29. }
  30. }
  31. }
  32. $id = $data['id'];
  33. unset($data['id']);
  34. if($id > 0){
  35. $data['update_time'] = date('Y-m-d H:i:s');
  36. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  37. }else{
  38. $data['create_time'] = date('Y-m-d H:i:s');
  39. $data['create_yyyy'] = date('Y');
  40. $data['create_mm'] = date('d');
  41. $data['create_yyyymmdd'] = date('Ymd');
  42. $ret = $this->allowField(true)->save($data);
  43. }
  44. if(!$ret){
  45. $this->error = '操作失败';
  46. return false;
  47. }
  48. return true;
  49. }
  50. public function getList(){
  51. $list =$this
  52. ->where('org_id',cur_org_id())
  53. ->where('del',0)
  54. ->where('enable',1)
  55. ->select()
  56. ->toArray();
  57. return $list;
  58. }
  59. /*----------API-----------*/
  60. public function lists($page,$size,$orgId,$roleId,$token){
  61. $offset = ($page - 1) * $size;
  62. $map[] = ['org_id','=',$orgId];
  63. $map[] = ['del','=',0];
  64. $map[] = ['enable','=',1];
  65. $parentId = Db::name('roles')
  66. ->where('id',$roleId)
  67. ->find();
  68. if($parentId['parent_id'] >0){
  69. $roleId = $parentId['parent_id'];
  70. }
  71. $m1 = $map;
  72. $m1[] = ['','exp', Db::raw("FIND_IN_SET({$roleId},roles_ids)")];
  73. $m2 = $map;
  74. $m2[] = ['roles_ids','=',null];
  75. $m3 = $map;
  76. $m3[] = ['roles_ids','=',''];
  77. $ret = $this->field('id,title,view,create_time,path,description as descrip,cate_id,limit,org_id')
  78. ->whereOr([ $m1, $m2, $m3 ])
  79. ->limit($offset,$size)
  80. ->order(['sort'=>'desc','id'=>'desc'])
  81. ->select();
  82. $ret = $ret?$ret->toArray():[];
  83. $a = [];
  84. foreach ($ret as $k=>$v){
  85. $v['url']=getSite().'/h5/Index/article?id='.$v['id'].'&token='.$token.'&org_id='.$orgId;
  86. $a[] = formatArray(['id','title','url','descrip','limit','create_time']
  87. ,$v);
  88. }
  89. return $a;
  90. }
  91. }