HouseRight.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. class HouseRight extends Model
  7. {
  8. public function add(){
  9. $data = [
  10. 'id' => input('id/d',0),
  11. 'title' => input('title','','trim'),
  12. 'org_id' => input('orgId/d',0),
  13. ];
  14. $result = validate('HouseRight')->check($data,[],'');
  15. if(true !== $result){
  16. HelpHander::error(validate('HouseRight')->getError());
  17. }
  18. $id = $data['id'];
  19. unset($data['id']);
  20. if($id > 0){
  21. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  22. }else{
  23. $ret = $this->allowField(true)->save($data);
  24. }
  25. if(!$ret){
  26. HelpHander::error('操作失败');
  27. }
  28. return true;
  29. }
  30. public function del($id){
  31. $res = Db::name('House')->where('right_id',$id)->where('del',0)->find();
  32. if($res){
  33. HelpHander::error('已被使用无法删除');
  34. }
  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){
  42. if($title != ''){
  43. $map[] = ['title','like','%'.$title.'%'];
  44. }else{
  45. $map =[];
  46. }
  47. $lists = $this
  48. ->where($map)
  49. ->page($page,$size)
  50. ->order('id asc')
  51. ->select();
  52. $total = $this->where($map)->count();
  53. $data = [
  54. 'total' => $total,
  55. 'list' => $lists?$lists->toArray():[]
  56. ];
  57. return $data;
  58. }
  59. public function all($orgId){
  60. $map[] = ['org_id','=',$orgId];
  61. $lists = $this
  62. ->where($map)
  63. ->field('id,title')
  64. ->order('id desc')
  65. ->select();
  66. return $lists?$lists->toArray():[];
  67. }
  68. }