0
0

PatrolForm.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class PatrolForm extends Base
  5. {
  6. protected $createTime = 'create_time';
  7. protected $updateTime = 'update_time';
  8. public $table = 'patrol_form';
  9. protected $validateName = 'PatrolForm';
  10. public $type = [
  11. '选择框',
  12. '输入框'
  13. ];
  14. public function updates(){
  15. $data = request()->post();
  16. $data['org_id'] =cur_org_id();
  17. $result = validate($this->validateName)->check($data,[],'');
  18. if(true !== $result){
  19. $this->error = validate($this->validateName)->getError();
  20. return false;
  21. }
  22. $id = $data['id'];
  23. unset($data['id']);
  24. if($id > 0){
  25. $data['update_time'] = date('Y-m-d H:i:s');
  26. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  27. }else{
  28. $data['create_time'] = date('Y-m-d H:i:s');
  29. $ret = $this->allowField(true)->save($data);
  30. }
  31. if(!$ret){
  32. $this->error = '操作失败';
  33. return false;
  34. }
  35. return true;
  36. }
  37. /**
  38. * 获取指定mode检查项
  39. *
  40. * @author wst
  41. * @date 2021/9/7 15:15
  42. * @return array
  43. */
  44. public function getByModeList($mode){
  45. $list =$this
  46. ->where('patrol_mode',$mode)
  47. ->where('org_id',cur_org_id())
  48. ->where('del',0)
  49. ->where('enable',1)
  50. ->select()
  51. ->toArray();
  52. return $list;
  53. }
  54. public function getByCateList($cate_id){
  55. if(empty($cate_id)){
  56. return [];
  57. }
  58. $where = '';
  59. foreach ($cate_id as $k=>$v){
  60. //$map[]=['','exp',Db::raw("FIND_IN_SET($v,cate_id)")];
  61. if($k>0){
  62. $where.='or ';
  63. }
  64. $where.='FIND_IN_SET('.$v.',cate_id)';
  65. }
  66. //
  67. // if($mode==4){
  68. // $map[] = ['cate_id','=',$cate_id];
  69. // }
  70. $list = Db::name('patrol_form')
  71. ->where('org_id',cur_org_id())
  72. ->where('del',0)
  73. ->where('enable',1)
  74. //->where($map)
  75. ->whereRaw($where)
  76. ->select();
  77. return $list;
  78. }
  79. }