コード例 #1
0
ファイル: Member.php プロジェクト: timelessmemory/uhkklp
 public function upgradeCard()
 {
     $currentCard = MemberShipCard::findByPk($this->cardId);
     if (isset($currentCard->isAutoUpgrade) && $currentCard->isAutoUpgrade) {
         // get the right card according member score.
         $card = MemberShipCard::getSuitableCard($this->totalScore, $this->accountId);
         $cardCondition = $card->condition;
         $currentCardCondition = $currentCard->condition;
         // if member's card is not right, update member card
         if (!empty($card->_id) && (string) $this->cardId != (string) $card->_id && $cardCondition['minScore'] > $currentCardCondition['minScore']) {
             $this->cardId = $card->_id;
             $this->save(false, ['cardId']);
         }
     }
 }
コード例 #2
0
 public function actionSetDefault()
 {
     $cardId = $this->getParams('id');
     $card = MemberShipCard::findByPk(new \MongoId($cardId));
     if (empty($card)) {
         throw new InvalidParameterException(Yii::t('member', 'no_card_find'));
     }
     $card->isDefault = true;
     if ($card->save(true, ['isDefault'])) {
         MemberShipCard::updateAll(['$set' => ['isDefault' => false]], ['accountId' => $card->accountId, '_id' => ['$ne' => $card->_id]]);
         return ['message' => 'OK', 'data' => ''];
     } else {
         throw new ServerErrorHttpException(Yii::t('common', 'update_fail'));
     }
 }