HouseRepair.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. class HouseRepair extends Model
  7. {
  8. public function add(){
  9. $data = [
  10. 'id' => input('id/d',0),
  11. 'org_id' => input('orgId',0),
  12. 'house_id' => input('houseId/d',0),
  13. 'reason' => input('reason','','trim'),
  14. 'repair_date' =>input('repairDate','','trim'),
  15. 'remark' => input('remark','','trim'),
  16. ];
  17. $result = validate('HouseRepair')->check($data,[],'');
  18. if(true !== $result){
  19. HelpHander::error(validate('HouseRepair')->getError());
  20. }
  21. $id = $data['id'];
  22. unset($data['id']);
  23. if($id > 0){
  24. $data['update_time'] = date('Y-m-d H:i:s');
  25. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  26. }else{
  27. $data['create_time'] = date('Y-m-d H:i:s');
  28. $ret = $this->allowField(true)->save($data);
  29. }
  30. if(!$ret){
  31. HelpHander::error('操作失败');
  32. }
  33. return true;
  34. }
  35. public function del($id){
  36. $ret = $this->where('id',$id)->delete();
  37. if(!$ret){
  38. HelpHander::error('删除失败');
  39. }
  40. return true;
  41. }
  42. public function lists($page,$size,$houseId,$reason,$orgId){
  43. $map[] = ['org_id','=',$orgId];
  44. if($reason != ''){
  45. $map[] = ['reason','like','%'.$reason.'%'];
  46. }
  47. if($houseId > 0){
  48. $map[] = ['house_id','=',$houseId];
  49. }
  50. $lists = $this
  51. ->where($map)
  52. ->page($page,$size)
  53. ->order('id desc')
  54. ->select();
  55. $total = $this->where($map)->count();
  56. $data = [
  57. 'total' => $total,
  58. 'list' => $lists?$lists->toArray():[]
  59. ];
  60. return $data;
  61. }
  62. }