HouseAuth.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 HouseAuth extends Model
  8. {
  9. public function add(){
  10. $data = [
  11. 'id' => input('id/d',0),
  12. 'user_id' => input('uid/d',0),
  13. 'type' => input('type/d',1),
  14. 'org_id' => input('orgId/d',0),
  15. 'remind' => input('remind/d',0),
  16. 'ids' => input('ids','','trim'),
  17. ];
  18. $result = validate('HouseAuth')->check($data,[],'');
  19. if(true !== $result){
  20. HelpHander::error(validate('HouseAuth')->getError());
  21. }
  22. $id = $data['id'];
  23. unset($data['id']);
  24. if($id > 0){
  25. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  26. }else{
  27. $ret = $this->allowField(true)->save($data);
  28. }
  29. if(!$ret){
  30. HelpHander::error('操作失败');
  31. }
  32. return true;
  33. }
  34. public function del($id){
  35. $ret = $this->where('id',$id)->delete();
  36. if(!$ret){
  37. HelpHander::error('删除失败');
  38. }
  39. return true;
  40. }
  41. public function lists($page,$size,$title,$type,$orgId){
  42. $map[] = ['ha.type','=',$type];
  43. $map[] = ['ha.org_id','=',$orgId];
  44. if($title != ''){
  45. $map[] = ['ui.name','like','%'.$title.'%'];
  46. }
  47. $lists = Db::name('house_auth')
  48. ->alias('ha')
  49. ->join('user_info ui','ui.user_id = ha.user_id')
  50. ->field('ha.*,ui.name as userName')
  51. ->where($map)
  52. ->page($page,$size)
  53. ->order('ha.id desc')
  54. ->select();
  55. $lists = $lists?$lists:[];
  56. foreach ($lists as $k=>$v){
  57. if($v['ids']){
  58. $auths = Db::name('house_level')->where('id','in',$v['ids'])->column('title');
  59. $lists[$k]['auth'] = implode(',',$auths);
  60. }else{
  61. $lists[$k]['auth'] = '';
  62. }
  63. }
  64. $total = Db::name('house_auth')
  65. ->alias('ha')
  66. ->join('user_info ui','ui.user_id = ha.user_id')
  67. ->where($map)->count();
  68. $data = [
  69. 'total' => $total,
  70. 'list' => $lists
  71. ];
  72. return $data;
  73. }
  74. }