NoticeUserTemp.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 NoticeUserTemp 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. trace($data);
  17. $result = validate('NoticeUserTemp')->check($data,[],'');
  18. if(true !== $result){
  19. HelpHander::error(validate('NoticeUserTemp')->getError());
  20. }
  21. $id = $data['id'];
  22. unset($data['id']);
  23. if($id > 0){
  24. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  25. }else{
  26. $ret = $this->allowField(true)->save($data);
  27. }
  28. if(!$ret){
  29. HelpHander::error('操作失败');
  30. }
  31. return true;
  32. }
  33. public function info($id){
  34. $info = $this->where('id',$id)->find();
  35. if(!$info){
  36. HelpHander::error('数据不存在');
  37. }
  38. $data = $info->toArray();
  39. return $data;
  40. }
  41. public function del($id){
  42. $ret = $this->where('id',$id)->delete();
  43. if(!$ret){
  44. HelpHander::error('删除失败');
  45. }
  46. return true;
  47. }
  48. public function lists($page,$size,$title,$orgId){
  49. $map[] = ['org_id','=',$orgId];
  50. if($title != ''){
  51. $map[] = ['title','like','%'.$title.'%'];
  52. }
  53. $lists = Db::name('notice_user_temp')
  54. ->where($map)
  55. ->page($page,$size)
  56. ->order('id desc')
  57. ->select();
  58. $lists = $lists?$lists:[];
  59. foreach ($lists as $k=>$v){
  60. $userids = $v['userids']?explode(',',$v['userids']):[];
  61. $userNames = [];
  62. foreach ($userids as $kk=>$vv){
  63. $uinfo = Db::name('user_info')
  64. ->where('user_id',$vv)
  65. ->field('user_id,name')
  66. ->find();
  67. $userNames[] = $uinfo?$uinfo['name']:'';
  68. }
  69. $lists[$k]['userNames'] = $userNames?implode(',',$userNames):'';
  70. }
  71. $total = Db::name('notice_user_temp')->where($map)->count();
  72. $data = [
  73. 'total' => $total,
  74. 'list' => $lists
  75. ];
  76. return $data;
  77. }
  78. public function all($orgId){
  79. $map[] = ['org_id','=',$orgId];
  80. $lists = Db::name('notice_user_temp')
  81. ->where($map)
  82. ->order('id desc')
  83. ->select();
  84. $lists = $lists?$lists:[];
  85. foreach ($lists as $k=>$v){
  86. $userids = $v['userids']?explode(',',$v['userids']):[];
  87. $userNames = [];
  88. foreach ($userids as $kk=>$vv){
  89. $uinfo[$kk] = Db::name('user_info')
  90. ->where('user_id',$vv)
  91. ->field('user_id,name')
  92. ->find();
  93. $userNames = $uinfo?$uinfo:[];
  94. }
  95. $lists[$k]['userNames']=$userNames;
  96. }
  97. return $lists?$lists:[];
  98. }
  99. }