PatrolAddrForm.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class PatrolAddrForm extends Base
  5. {
  6. protected $createTime = 'create_time';
  7. protected $updateTime = 'update_time';
  8. public $table = 'patrol_addr_form';
  9. protected $validateName = 'PatrolAddrForm';
  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. /**
  34. * 获取指定mode检查项
  35. *
  36. * @author wst
  37. * @date 2021/9/7 15:15
  38. * @return array
  39. */
  40. public function getByModeList($mode){
  41. $list =$this
  42. ->where('patrol_mode',$mode)
  43. ->where('org_id',cur_org_id())
  44. ->where('del',0)
  45. ->where('enable',1)
  46. ->select()
  47. ->toArray();
  48. return $list?$list:[];
  49. }
  50. public function getModeTitle($mode){
  51. return Db::name('patrol_mode')
  52. ->where('id',$mode)
  53. ->value('name');
  54. }
  55. }