/**
  * exchange the promotioncode
  */
 public function actionExchange()
 {
     $params = $this->getParams();
     if (empty($params['code']) || empty($params['memberId'])) {
         throw new BadRequestHttpException(Yii::t('common', 'parameters_missing'));
     }
     //get email for user
     $accesstoken = $this->getAccessToken();
     $tokenInfo = Token::findOne(['accessToken' => $accesstoken]);
     $userInfo = User::findByPk($tokenInfo['userId']);
     $params['operaterEmail'] = empty($userInfo['email']) ? '' : $userInfo['email'];
     $params['userInfo'] = empty($userInfo) ? null : ['id' => $userInfo->_id, 'name' => $userInfo->name];
     $memberId = $params['memberId'];
     $params['memberId'] = new MongoId($memberId);
     if (!empty($params['exchangeTime'])) {
         $params['exchangeTime'] = TimeUtil::ms2sTime($params['exchangeTime']);
     }
     //exchange the promotion code
     $accountId = $this->getAccountId();
     if (is_array($params['code'])) {
         //exchaneg code offline
         $codes = $params['code'];
         $successCode = [];
         foreach ($codes as $code) {
             $params['code'] = strtoupper($code);
             $result = PromotionCode::exchangeCampaignCode($params, $accountId, self::EXCHANEG_TYPE_OFFLINE);
             if ('success' == $result['result']) {
                 $successCode[] = $code;
             }
         }
         list($codeNumber, $score) = CampaignLog::getCodeRecord($successCode);
         if (!empty($params['useWebhook'])) {
             $eventData = ['type' => Webhook::EVENT_PROMOTION_CODE_REDEEMED, 'member_id' => $memberId, 'codes' => $params['code'], 'redeemed_codes' => $successCode, 'score' => $score, 'origin' => Member::PORTAL, 'account_id' => (string) $accountId, 'created_at' => TimeUtil::msTime2String($params['exchangeTime'], \DateTime::ATOM)];
             Yii::$app->webhook->triggerEvent($eventData);
         }
         //fix data
         $this->fixData($accountId, $params['memberId'], $successCode);
         return ['result' => 'success', 'codeNumber' => $codeNumber, 'totalScore' => $score, 'codes' => $successCode];
     } else {
         $params['code'] = strtoupper($params['code']);
         $result = PromotionCode::exchangeCampaignCode($params, $accountId, self::EXCHANEG_TYPE_MOBILE);
         if ('error' == $result['result']) {
             throw new InvalidParameterException($result['message']);
         } else {
             return $result;
         }
     }
 }