public function actionUpdate($id) { $accountId = $this->getAccountId(); //transfer the id from string to MongoId $id = new \MongoId($id); $model = HelpDeskSetting::findByPk($id); $model->scenario = BaseModel::SCENARIO_UPDATE; $helpDeskSetting = json_decode(Yii::$app->getRequest()->getRawBody(), true); $model->load($helpDeskSetting, ''); if ($model->save() === false && !$model->hasErrors()) { throw new ServerErrorHttpException('Failed to update the object for unknown reason.'); } else { $channels = $model->channels; if ($channels && count($channels)) { $customerServicesSessionExpire = intval($helpDeskSetting['maxWaitTime']) * 60 * 1000; $accessToken = Token::createForWechat($accountId); foreach ($channels as $channel) { Yii::$app->weConnect->updateCustomerServiceSetting($channel['id'], $customerServicesSessionExpire, $accessToken->accessToken); } } } $model->_id .= ''; return $model; }