1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- namespace app\common\model;
- use think\Db;
- class PhProtocol extends Base {
- public function updates(){
- $data = request()->post();
- $data['org_id'] =cur_org_id();
- $result = validate('PhProtocol')->check($data,[],'');
- if(true !== $result){
- $this->error = validate('PhProtocol')->getError();
- return false;
- }
- $id = $data['id'];
- unset($data['id']);
- if($id > 0){
- $data['update_time'] = date("Y-m-d H:i:s");
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- // 查询该组织是否已创建协议
- $info = Db::name("ph_protocol")->where('org_id',$data['org_id'])->find();
- if($info){
- $this->error = "已创建协议请编辑修改";
- return false;
- }
- $data['create_time'] = date("Y-m-d H:i:s");
- $data['update_time'] = date("Y-m-d H:i:s");
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- $this->error = '操作失败';
- return false;
- }
- return true;
- }
- }
|