Ejemplo n.º 1
0
 /**
  * Give points to member
  *
  * <b>Request Type: </b>POST<br/>
  * <b>Request Endpoint: </b>http://{server-domain}/api/member/score/give<br/>
  * <b>Content-type: </b>application/json<br/>
  * <b>Summary: </b>This api is for give scores to specific members or conditions to filter member.<br/>
  *
  * <b>Request Parameters: </b>
  *     scores: int, the value of the scores to give, required<br/>
  *     filterType: string, the type of the filter, "name" or "number" or "tag", required<br/>
  *     names: array<string>, the array of the names for filter, required only if the filterType is "name"<br/>
  *     numbers: array<string>, the array of the numbers to filter members, required only if the filterType is "number"<br/>
  *     tags: array<string>, the array of the tags fo filter members, required only if the filterType is "tag"<br/>
  *     description: string, the description. optional. <br/>
  *
  * <b>Request Example</b><br/>
  * <pre>
  * {"score":100, "filterType":"name", "names":["Zhang San", "Li Si"]}
  * </pre>
  *
  */
 public function actionGive()
 {
     $filterType = $this->getParams('filterType');
     $score = $this->getParams('score');
     $description = $this->getParams('description');
     if (empty($filterType) || empty($score)) {
         throw new BadRequestHttpException('Missing required parameters');
     }
     $userId = $this->getUserId();
     $user = User::findByPk($userId);
     $user = ['id' => $userId, 'name' => $user->name];
     $filterKey = $filterType . 's';
     $filterValue = $this->getParams($filterKey);
     if (empty($filterValue)) {
         throw new BadRequestHttpException("Missing required parameters");
     }
     $function = "giveScoreBy" . $filterKey;
     $memberList = Member::$function($score, $filterValue);
     if (empty($memberList)) {
         throw new InvalidParameterException(['member-' . $filterType => \Yii::t('member', 'no_member_find')]);
     }
     if ($memberList) {
         foreach ($memberList as $member) {
             $scoreHistory = new ScoreHistory();
             $scoreHistory->assigner = ScoreHistory::ASSIGNER_ADMIN;
             $scoreHistory->increment = $score;
             $scoreHistory->memberId = $member;
             $scoreHistory->brief = $score >= 0 ? ScoreHistory::ASSIGNER_ADMIN_ISSUE_SCORE : ScoreHistory::ASSIGNER_ADMIN_DEDUCT_SCORE;
             $scoreHistory->description = $description;
             $scoreHistory->channel = ['origin' => ScoreHistory::PORTAL];
             $scoreHistory->user = $user;
             $scoreHistory->accountId = $this->getAccountId();
             if (!$scoreHistory->save()) {
                 LogUtil::error(['message' => 'save scoreHistory failed', 'data' => $scoreHistory->toArray()], 'member');
             }
         }
         return ['status' => 'ok'];
     }
 }
Ejemplo n.º 2
0
 /**
  * Reward shake score
  * @param MongoId $memberId
  * @param int $score
  */
 public function shakeScore($memberId, $score, $channelInfo)
 {
     ModelMember::updateAll(['$inc' => ['score' => $score, 'totalScore' => $score, 'totalScoreAfterZeroed' => $score]], ['_id' => $memberId]);
     $scoreHistory = new ScoreHistory();
     $scoreHistory->assigner = ScoreHistory::ASSIGNER_SHAKE_SCORE;
     $scoreHistory->increment = $score;
     $scoreHistory->memberId = $memberId;
     $scoreHistory->brief = ScoreHistory::ASSIGNER_SHAKE_SCORE;
     $scoreHistory->description = '';
     $scoreHistory->channel = $channelInfo;
     $scoreHistory->user = null;
     $scoreHistory->accountId = $this->accountId;
     if (!$scoreHistory->save()) {
         LogUtil::error(['message' => 'Failed to save the history for unknown problem', 'scoreHistory' => $scoreHistory->toArray()], 'resque');
     }
 }