FileUserTemp.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use app\Request;
  5. use think\Db;
  6. use think\Model;
  7. class FileUserTemp extends Model
  8. {
  9. public function add(){
  10. $data = [
  11. 'id' => input('id/d',0),
  12. 'userids' => input('userids','','trim'),
  13. 'title' => input('title','','trim'),
  14. 'org_id' => input('orgId/d',0),
  15. ];
  16. $result = validate('FileUserTemp')->check($data,[],'');
  17. if(true !== $result){
  18. HelpHander::error(validate('FileUserTemp')->getError());
  19. }
  20. $id = $data['id'];
  21. unset($data['id']);
  22. if($id > 0){
  23. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  24. }else{
  25. $ret = $this->allowField(true)->save($data);
  26. }
  27. if(!$ret){
  28. HelpHander::error('操作失败');
  29. }
  30. return true;
  31. }
  32. public function info($id){
  33. $info = $this->where('id',$id)->find();
  34. if(!$info){
  35. HelpHander::error('数据不存在');
  36. }
  37. $data = $info->toArray();
  38. return $data;
  39. }
  40. public function del($id){
  41. $ret = $this->where('id',$id)->delete();
  42. if(!$ret){
  43. HelpHander::error('删除失败');
  44. }
  45. return true;
  46. }
  47. public function lists($page,$size,$title,$orgId){
  48. $map[] = ['org_id','=',$orgId];
  49. if($title != ''){
  50. $map[] = ['title','like','%'.$title.'%'];
  51. }
  52. $lists = Db::name('file_user_temp')
  53. ->where($map)
  54. ->page($page,$size)
  55. ->order('id desc')
  56. ->select();
  57. $lists = $lists?$lists:[];
  58. foreach ($lists as $k=>$v){
  59. $userids = $v['userids']?explode(',',$v['userids']):[];
  60. $userNames = [];
  61. foreach ($userids as $kk=>$vv){
  62. $uinfo = Db::name('user_info')
  63. ->where('user_id',$vv)
  64. ->field('user_id,name')
  65. ->find();
  66. $userNames[] = $uinfo?$uinfo['name']:'';
  67. }
  68. $lists[$k]['userNames'] = $userNames?implode(',',$userNames):'';
  69. }
  70. $total = Db::name('file_user_temp')->where($map)->count();
  71. $data = [
  72. 'total' => $total,
  73. 'list' => $lists
  74. ];
  75. return $data;
  76. }
  77. public function all($orgId){
  78. $map[] = ['org_id','=',$orgId];
  79. $lists = Db::name('file_user_temp')
  80. ->where($map)
  81. ->order('id desc')
  82. ->select();
  83. $lists = $lists?$lists:[];
  84. return $lists?$lists:[];
  85. }
  86. }