belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0); } /** 通用新增(后台api版本) * @param $params * @param $trans * @return $this * @throws \Exception */ public function add($params,$trans=false){ if (empty($params)) { throw new \Exception(__('Parameter %s can not be empty', '')); } if ($this->dataLimit && $this->dataLimitFieldAutoFill) { $params[$this->dataLimitField] = $this->auth->id; } //判断逻辑 if($trans){ self::beginTrans(); } $res = true; try{ //是否采用模型验证 if ($this->modelValidate) { $name = str_replace("\\model\\", "\\validate\\", get_class($this)); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; $this->validateFailException()->validate($validate); } $result = $this->allowField(true)->save($params); if($trans){ self::commitTrans(); } }catch (\Exception $e){ if($trans){ self::rollbackTrans(); } throw new \Exception($e->getMessage().$e->getFile().$e->getLine()); } return $this; } }