adminOperateLogger = new AdminOperate([ 'fetchClass' => UserPerf::class, ]); } /** * @inheritdoc */ public function rules() { return [ [['USER_ID', 'SURPLUS_1L', 'SURPLUS_1L_ZC', 'SURPLUS_1L_FX', 'SURPLUS_2L', 'SURPLUS_2L_ZC', 'SURPLUS_2L_FX'], 'required'], ]; } /** * 指定场景 * @return array */ public function scenarios() { $parentScenarios = parent::scenarios(); $customScenarios = [ 'perfAdjustment' => ['USER_ID', 'USER_NAME', 'SURPLUS_1L', 'SURPLUS_1L_ZC', 'SURPLUS_1L_FX', 'SURPLUS_2L', 'SURPLUS_2L_ZC', 'SURPLUS_2L_FX'] ]; return array_merge($parentScenarios, $customScenarios); } /** * @inheritdoc */ public function attributeLabels() { return [ 'USER_ID' => '会员ID', 'SURPLUS_1L' => '一市场综合结余业绩', 'SURPLUS_1L_ZC' => '一市场综合报单业绩', 'SURPLUS_1L_FX' => '一市场复消结余业绩', 'SURPLUS_2L' => '二市场综合结余业绩', 'SURPLUS_2L_ZC' => '二市场综合报单业绩', 'SURPLUS_2L_FX' => '二市场复消结余业绩', ]; } /** * 调整会员业绩 * @return bool|null */ public function perfAdjustment(): ?bool { if (!$this->validate()) { return false; } $transaction = \Yii::$app->db->beginTransaction(); try { // 修改前业绩 $userPerf = UserPerf::find() ->where('USER_ID=:USER_ID', [':USER_ID' => $this->USER_ID]) ->select('USER_ID,SURPLUS_1L,SURPLUS_1L_ZC,SURPLUS_1L_FX,SURPLUS_2L,SURPLUS_2L_ZC,SURPLUS_2L_FX') ->one(); if (!$userPerf->toArray()) { throw new Exception('Member performance does not exist'); // 会员业绩不存在 } $this->adminOperateLogger->beforeUpdate($userPerf); $modernPerf = [ 'SURPLUS_1L' => $this->SURPLUS_1L, 'SURPLUS_1L_ZC' => $this->SURPLUS_1L_ZC, 'SURPLUS_1L_FX' => $this->SURPLUS_1L_FX, 'SURPLUS_2L' => $this->SURPLUS_2L, 'SURPLUS_2L_ZC' => $this->SURPLUS_2L_ZC, 'SURPLUS_2L_FX' => $this->SURPLUS_2L_FX, ]; if (!UserPerf::updateAll($modernPerf, 'USER_ID=:USER_ID', [':USER_ID' => $this->USER_ID])) { throw new Exception(Form::formatErrorsForApi($userPerf->getErrors())); } $transaction->commit(); $afterUpdate = UserPerf::find() ->where('USER_ID=:USER_ID', [':USER_ID' => $this->USER_ID]) ->select('USER_ID,SURPLUS_1L,SURPLUS_1L_ZC,SURPLUS_1L_FX,SURPLUS_2L,SURPLUS_2L_ZC,SURPLUS_2L_FX') ->one(); $this->adminOperateLogger->afterUpdate($afterUpdate)->clean()->save([ 'optType' => 'perf adjustment', // 调整业绩 'userId' => $this->USER_ID, 'userName' => $this->USER_NAME, 'periodNum' => Period::instance()->getNowPeriodNum(), ]); } catch (Exception $e) { $transaction->rollBack(); $this->addError('perfAdjustment', $e->getMessage()); return false; } return true; } }