Car.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. use think\Exception;
  5. class Car extends Base
  6. {
  7. protected $createTime = 'create_time';
  8. protected $updateTime = 'update_time';
  9. public $table = 'car';
  10. protected $validateName = 'Car';
  11. public function updates(){
  12. $data = request()->post();
  13. $data['org_id'] =cur_org_id();
  14. $result = validate($this->validateName)->check($data,[],'');
  15. if(true !== $result){
  16. $this->error = validate($this->validateName)->getError();
  17. return false;
  18. }
  19. $id = $data['id'];
  20. unset($data['id']);
  21. $carportId = explode(',',$data['carport_id']);
  22. $data['carport_id'] = $carportId[count($carportId)-1];
  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. $this->error = '操作失败';
  32. return false;
  33. }
  34. return true;
  35. }
  36. public function getList(){
  37. $list =$this
  38. ->where('org_id',cur_org_id())
  39. ->where('del',0)
  40. ->select()
  41. ->toArray();
  42. return $list;
  43. }
  44. public function tree(){
  45. $area = (new HouseAreas())->getList();
  46. foreach ($area as $k=>$v){
  47. $area[$k]['child'] = Db::name('house')
  48. ->where('org_id',cur_org_id())
  49. ->where('area_id',$v['id'])
  50. ->where('enable',1)
  51. ->where('del',0)
  52. ->where('type',3)
  53. ->where('cate',5)
  54. ->select();
  55. }
  56. return $area;
  57. }
  58. }