0
0

DailyForm.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class DailyForm extends Base {
  5. protected $createTime = 'create_time';
  6. protected $updateTime = 'update_time';
  7. public $table = 'daily_form';
  8. protected $validateName = 'DailyForm';
  9. public function updates(){
  10. $data = request()->post();
  11. $data['org_id'] =cur_org_id();
  12. $result = validate($this->validateName)->check($data,[],'');
  13. if(true !== $result){
  14. $this->error = validate($this->validateName)->getError();
  15. return false;
  16. }
  17. $id = $data['id'];
  18. unset($data['id']);
  19. if($id > 0){
  20. $data['update_time'] = date('Y-m-d H:i:s');
  21. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  22. }else{
  23. $data['create_time'] = date('Y-m-d H:i:s');
  24. $ret = $this->allowField(true)->save($data);
  25. }
  26. if(!$ret){
  27. $this->error = '操作失败';
  28. return false;
  29. }
  30. return true;
  31. }
  32. /**
  33. * 获取检查项列表
  34. *
  35. * @author wst
  36. * @date 2021/9/6 15:00
  37. * @return array
  38. */
  39. public function list(){
  40. $where['del']=0;
  41. $where['enable']=1;
  42. $where['org_id']=cur_org_id();
  43. $dailyForm=$this->field('id,content as title')->where($where)->select()->toArray();
  44. return $dailyForm;
  45. }
  46. /**
  47. * 根据id获取检查项列表
  48. *
  49. * @author wst
  50. * @date 2021/9/6 15:00
  51. * @return array
  52. */
  53. public function getByIdList($id){
  54. $dailyForm = Db::name('daily_form')
  55. ->where('enable',1)
  56. ->where('del',0)
  57. ->whereIn('id',explode(',',$id))
  58. ->select();
  59. $ids = [];
  60. foreach ($dailyForm as $k=>$v){
  61. $ids[$k]=(string)$v['id'];
  62. }
  63. return $ids;
  64. }
  65. }