HouseLevel.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 HouseLevel extends Model
  8. {
  9. public function add(){
  10. $data = [
  11. 'id' => input('id/d',0),
  12. 'title' => input('title','','trim'),
  13. 'type' => input('type'),
  14. 'org_id' => input('orgId/d',0),
  15. ];
  16. $result = validate('HouseLevel')->check($data,[],'');
  17. if(true !== $result){
  18. HelpHander::error(validate('HouseLevel')->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 del($id){
  33. $res = Db::name('House')->where('level_id',$id)->where('del',0)->find();
  34. if($res){
  35. HelpHander::error('已被使用无法删除');
  36. }
  37. $res = Db::name('HouseTurn')->where('level_id',$id)->where('del',0)->find();
  38. if($res){
  39. HelpHander::error('已被使用无法删除');
  40. }
  41. // $map[] = ['exp',Db::raw("FIND_IN_SET($id,ids)")];
  42. // $res = Db::name('house_auth')->where($map)->find();
  43. // if($res){
  44. // HelpHander::error('已被使用无法删除');
  45. // }
  46. $ret = $this->where('id',$id)->delete();
  47. if(!$ret){
  48. HelpHander::error('删除失败');
  49. }
  50. return true;
  51. }
  52. public function lists($page,$size,$title,$type,$orgId){
  53. $map[] = ['type','=',$type];
  54. $map[] = ['org_id','=',$orgId];
  55. if($title != ''){
  56. $map[] = ['title','like','%'.$title.'%'];
  57. }
  58. $lists = $this
  59. ->where($map)
  60. ->page($page,$size)
  61. ->order('id desc')
  62. ->select();
  63. $total = $this->where($map)->count();
  64. $data = [
  65. 'total' => $total,
  66. 'list' => $lists?$lists->toArray():[]
  67. ];
  68. return $data;
  69. }
  70. public function all($type,$orgId){
  71. $map[] = ['type','=',$type];
  72. $map[] = ['org_id','=',$orgId];
  73. $lists = $this
  74. ->where($map)
  75. ->order('id asc')
  76. ->select();
  77. return $lists?$lists->toArray():[];
  78. }
  79. }