HouseLabel.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. class HouseLabel 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. 'house_id' => input('houseId/d',0),
  14. 'status' => input('status/d',0),
  15. 'end_time' => input('endTime','','trim'),
  16. ];
  17. $result = validate('HouseLabel')->check($data,[],'');
  18. if(true !== $result){
  19. HelpHander::error(validate('HouseLabel')->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. return $info->toArray();
  39. }
  40. public function lists($page,$size,$title,$orgId){
  41. $map[] = ['org_id','=',$orgId];
  42. if($title){
  43. $map[] = ['title','like','%'.$title.'%'];
  44. }
  45. $lists = $this
  46. ->where($map)
  47. ->page($page,$size)
  48. ->order('id desc')
  49. ->select();
  50. $total = $this->where($map)->count();
  51. $data = [
  52. 'total' => $total,
  53. 'list' => $lists?$lists->toArray():[]
  54. ];
  55. return $data;
  56. }
  57. public function all($orgId){
  58. $map[] = ['org_id','=',$orgId];
  59. $lists = $this
  60. ->where($map)
  61. ->field('id,title')
  62. ->order('id desc')
  63. ->select();
  64. return $lists?$lists->toArray():[];
  65. }
  66. public function del($id){
  67. $ret = $this->where('id',$id)->delete();
  68. if(!$ret){
  69. HelpHander::error('删除失败');
  70. }
  71. return true;
  72. }
  73. }