HouseCompany.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 HouseCompany 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('HouseCompany')->check($data,[],'');
  15. if(true !== $result){
  16. HelpHander::error(validate('HouseCompany')->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('company_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 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. $lists = $this
  62. ->where($map)
  63. ->field('id,title')
  64. ->order('id desc')
  65. ->select();
  66. return $lists?$lists->toArray():[];
  67. }
  68. }