HouseSelect.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. class HouseSelect extends Model
  7. {
  8. public function add(){
  9. $data = [
  10. 'id' => input('id/d',0),
  11. 'title' => input('title','','trim'),
  12. 'type' => input('type'),
  13. 'org_id' => input('orgId/d',0),
  14. ];
  15. $result = validate('HouseSelect')->check($data,[],'');
  16. if(true !== $result){
  17. HelpHander::error(validate('HouseSelect')->getError());
  18. }
  19. $id = $data['id'];
  20. unset($data['id']);
  21. if($id > 0){
  22. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  23. }else{
  24. $ret = $this->allowField(true)->save($data);
  25. }
  26. if(!$ret){
  27. HelpHander::error('操作失败');
  28. }
  29. return true;
  30. }
  31. public function del($id){
  32. $ret = $this->where('id',$id)->setField('del',1);
  33. if(!$ret){
  34. HelpHander::error('删除失败');
  35. }
  36. return true;
  37. }
  38. public function lists($page,$size,$title,$type,$orgId){
  39. $map[] = ['org_id','=',$orgId];
  40. $map[] = ['del','=',0];
  41. if($title != ''){
  42. $map[] = ['title','like','%'.$title.'%'];
  43. }
  44. if($type){
  45. $map[] = ['type','=',$type];
  46. }
  47. $lists = $this
  48. ->where($map)
  49. ->page($page,$size)
  50. ->order('id desc')
  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. $map[] = ['del','=',0];
  62. $lists = $this
  63. ->where($map)
  64. ->field('id,title,type')
  65. ->order('id asc')
  66. ->select();
  67. return $lists?$lists->toArray():[];
  68. }
  69. }