HouseFee.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class HouseFee extends Base
  5. {
  6. protected $createTime = 'create_time';
  7. protected $updateTime = 'update_time';
  8. public $table = 'house_fee';
  9. protected $validateName = 'HouseFee';
  10. public function updates(){
  11. $data = request()->post();
  12. $data['org_id'] =cur_org_id();
  13. $result = validate($this->validateName)->check($data,[],'');
  14. if(true !== $result){
  15. $this->error = validate($this->validateName)->getError();
  16. return false;
  17. }
  18. $id = $data['id'];
  19. unset($data['id']);
  20. if($id > 0){
  21. $data['update_time'] = date('Y-m-d H:i:s');
  22. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  23. }else{
  24. $data['create_time'] = date('Y-m-d H:i:s');
  25. $ret = $this->allowField(true)->save($data);
  26. }
  27. if(!$ret){
  28. $this->error = '操作失败';
  29. return false;
  30. }
  31. return true;
  32. }
  33. public function getTree($orgId){
  34. $list = $this
  35. ->where('parent_id',0)
  36. ->where('del',0)
  37. ->where('org_id',$orgId)
  38. ->order('sort','asc')
  39. ->select()
  40. ->toArray();
  41. foreach ($list as $k=>$v){
  42. $list[$k]['depth'] = 0;
  43. $two =$this
  44. ->where('parent_id',$v['id'])
  45. ->where('del',0)
  46. ->where('org_id',$orgId)
  47. ->order('sort','asc')
  48. ->select()
  49. ->toArray();
  50. foreach ($two as $l=>$t){
  51. $two[$l]['depth'] = 1;
  52. }
  53. $list[$k]['child'] =$two;
  54. }
  55. return $list;
  56. }
  57. }