DeviceForm.php 1.6 KB

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