PhProtocol.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class PhProtocol extends Base {
  5. public function updates(){
  6. $data = request()->post();
  7. $data['org_id'] =cur_org_id();
  8. $result = validate('PhProtocol')->check($data,[],'');
  9. if(true !== $result){
  10. $this->error = validate('PhProtocol')->getError();
  11. return false;
  12. }
  13. $id = $data['id'];
  14. unset($data['id']);
  15. if($id > 0){
  16. $data['update_time'] = date("Y-m-d H:i:s");
  17. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  18. }else{
  19. // 查询该组织是否已创建协议
  20. $info = Db::name("ph_protocol")->where('org_id',$data['org_id'])->find();
  21. if($info){
  22. $this->error = "已创建协议请编辑修改";
  23. return false;
  24. }
  25. $data['create_time'] = date("Y-m-d H:i:s");
  26. $data['update_time'] = date("Y-m-d H:i:s");
  27. $ret = $this->allowField(true)->save($data);
  28. }
  29. if(!$ret){
  30. $this->error = '操作失败';
  31. return false;
  32. }
  33. return true;
  34. }
  35. }