Exemplo n.º 1
0
 private function updateScoreRuleStatistics($ruleName, $accountId)
 {
     list($scoreTimes, $scoreMemberCount) = $this->getTimeAndmemberCountWithScore($ruleName, $accountId);
     list($couponTimes, $couponMemberCount) = $this->getTimeAndmemberCountWithCoupon($ruleName, $accountId);
     $times = $scoreTimes + $couponTimes;
     $memberCount = $scoreMemberCount + $couponMemberCount;
     $result = ScoreRule::updateAll(['times' => $times, 'memberCount' => $memberCount], ['name' => $ruleName, 'accountId' => $accountId]);
 }
Exemplo n.º 2
0
 private function getBirthDayReward($accountId, $memberId = null)
 {
     //get reward type
     $birthdayRule = ScoreRule::getByName(ScoreRule::NAME_BIRTHDAY, $accountId);
     if (!empty($birthdayRule) && $birthdayRule->isEnabled && $birthdayRule->rewardType == ScoreRule::REWARD_SCORE_TYPE) {
         //score
         $this->issueBirthdayScore($accountId, $birthdayRule, $memberId);
     } else {
         if (!empty($birthdayRule) && $birthdayRule->isEnabled && $birthdayRule->rewardType == ScoreRule::REWARD_COUPON_TYPE) {
             //coupon
             $this->issueBirthdayCoupon($accountId, $birthdayRule, $memberId);
         }
     }
 }
Exemplo n.º 3
0
 public function actionUpdate($id)
 {
     $id = new MongoId($id);
     $rule = ScoreRule::findByPk($id);
     if (empty($rule)) {
         throw new BadRequestHttpException(Yii::t('common', 'data_error'));
     }
     $params = $this->getParams();
     $rule->load($params, '');
     if (false == $rule->save(true)) {
         throw new ServerErrorHttpException(Yii::t('common', 'save_fail'));
     }
     return $rule;
 }
Exemplo n.º 4
0
 /**
  * Get score rules.
  *
  * <b>Request Type</b>: GET<br/><br/>
  * <b>Request Endpoint</b>:http://{server-domain}/api/mobile/score-rule<br/><br/>
  * <b>Response Content-type</b>: application/json<br/><br/>
  * <b>Summary</b>: This api is used for get score rules.
  * <br/><br/>
  *
  * <b>Request Params</b>:<br/>
  *     channelId: string<br/>
  *     where: json string, where = {"isEnabled" : true}
  *     <br/><br/>
  *
  * <b>Response Params:</b><br/>
  *     <br/><br/>
  *
  * <br/><br/>
  *
  * <b>Response Example</b>:<br/>
  * <pre>
  * {
  *     "items": [
  *         {
  *             "id": "54b34be2e9c2fb61298b4568",
  *             "name": "birthday",
  *             "type": "time",
  *             "score": "100",
  *             "triggerTime": "week",
  *             "description": "",
  *             "isEnabled": true,
  *             "startTime": "",
  *             "endTime": "",
  *             "times": 0,
  *             "memberCount": 0
  *         },
  *         {
  *             "id": "54b34be2e9c2fb61298b4569",
  *             "name": "first_card",
  *             "type": "time",
  *             "score": "200",
  *             "triggerTime": "day",
  *             "description": "<p>首次开卡送200积分</p>",
  *             "isEnabled": true,
  *             "startTime": "",
  *             "endTime": "",
  *             "times": 0,
  *             "memberCount": 0
  *         }
  *     ],
  *     "_links": {
  *         "self": {
  *             "href": "http://wm.com/api/mobile/score-rule?channelId=54add01be4b026aee36dd26e&where=%7B%22isEnabled%22%3Atrue%7D&page=1"
  *         }
  *     },
  *     "_meta": {
  *         "totalCount": 2,
  *         "pageCount": 1,
  *         "currentPage": 0,
  *         "perPage": 20
  *     }
  * }
  * </pre>
  */
 public function actionScoreRule()
 {
     $channelId = $this->getQuery('channelId');
     $where = $this->getQuery('where');
     $channel = Channel::getEnableByChannelId($channelId);
     $accountId = $channel->accountId;
     if (!empty($where)) {
         $where = Json::decode($where, true);
     }
     return ScoreRule::search($accountId, $where);
 }
Exemplo n.º 5
0
 public static function rewardByScoreRule($ruleName, $memberId, $accountId)
 {
     //get score rule
     $rule = ScoreRule::getByName($ruleName, $accountId);
     if (!empty($rule) && $rule->isEnabled) {
         //if check the property, the property is not filled,not need to give reward
         if (!self::_checkRulePropertiesFilled($rule, $memberId)) {
             return true;
         }
         //get reward type
         if ($rule->rewardType == ScoreRule::REWARD_SCORE_TYPE) {
             // member rewarded
             $rewardHistory = ScoreHistory::getByRuleName($ruleName, $memberId, $accountId);
             if (!empty($rewardHistory)) {
                 return true;
             }
             //reward score
             $memberList = Member::giveScoreByIds($rule->score, [$memberId]);
             //update history
             $scoreHistory = new ScoreHistory();
             $scoreHistory->assigner = ScoreHistory::ASSIGNER_RULE;
             $scoreHistory->increment = $rule->score + 0;
             $scoreHistory->memberId = $memberId;
             $scoreHistory->brief = ScoreHistory::ASSIGNER_RULE;
             $scoreHistory->description = $ruleName;
             $scoreHistory->channel = ['origin' => ScoreHistory::PORTAL];
             $scoreHistory->accountId = $accountId;
             $scoreHistory->save();
         } else {
             if ($rule->rewardType == ScoreRule::REWARD_COUPON_TYPE && !empty($rule->couponId)) {
                 $rewardCouponLog = CouponLog::getLogByRuleName($ruleName, $memberId, $accountId);
                 if (!empty($rewardCouponLog)) {
                     return true;
                 }
                 $coupon = Coupon::findByPk($rule->couponId);
                 if (empty($coupon)) {
                     LogUtil::error(['message' => 'can not find the coupon when give member birthday reward', 'couponId' => (string) $couponId], 'member');
                     return true;
                 }
                 if (Coupon::updateAll(['$inc' => ['total' => -1]], ['total' => ['$gt' => 0], '_id' => $rule->couponId])) {
                     //issue membershipdiscount
                     $member = Member::findByPk($memberId);
                     $membershipDiscount = MembershipDiscount::transformMembershipDiscount($coupon, $member, $ruleName);
                     if (false == $membershipDiscount->save()) {
                         Coupon::updateAll(['$inc' => ['total' => 1]], ['_id' => $rule->couponId]);
                         LogUtil::error(['message' => 'add membershipdiscount fail', 'memberId' => (string) $member->_id, 'couponId' => (string) $coupon->_id], 'member');
                     }
                 } else {
                     LogUtil::error(['message' => 'coupon is not enough when give member birthday reward', 'memberId' => (string) $member->_id, 'couponId' => (string) $coupon->_id], 'member');
                 }
             }
         }
     }
 }
 /**
  * Update the member property
  *
  * <b>Request Type:</b> PUT<br/>
  * <b>Request Endpoint:</b> http://{{server-domain}}/api/common/member-property/{{id}}
  * <b>Content-type:</b> application/json<br/>
  * <b>Summary</b> This api is for update member property<br/>
  *
  * <b>Request Parameters</b><br/>
  * <pre>
  *     {
  *         "order": 7,
  *         "name": "name123",
  *         "defaultValue": "Devin Jin 1",
  *         "isRequired": true,
  *         "isUnique": true,
  *         "isVisible": true
  *       }
  * </pre>
  */
 public function actionUpdate($id)
 {
     $propertyId = new \MongoId($id);
     $property = MemberProperty::findByPk($propertyId);
     $oldOptions = $property->options;
     $property->load($this->getParams(), '');
     if ($property->save()) {
         //update all the members of the account
         $modifier = ['$set' => ['properties.$.name' => $property->name]];
         if (($property->type == MemberProperty::TYPE_CHECKBOX || $property->type == MemberProperty::TYPE_RADIO) && $property->options != $oldOptions) {
             $modifier['$set']['properties.$.value'] = $property->defaultValue;
         }
         if (!$property->isVisible) {
             $scoreRuleModifier = ['$pull' => ['properties' => $property->_id]];
             $scoreRuleCondition = ['accountId' => $property->accountId, 'name' => ScoreRule::NAME_PERFECT_INFO, 'properties' => $property->_id];
             ScoreRule::updateAll($scoreRuleModifier, $scoreRuleCondition);
         }
         Member::updateAll($modifier, ['properties.id' => $propertyId]);
         return $property;
     } else {
         if ($property->hasErrors()) {
             throw new BadRequestHttpException(Json::encode($property->errors));
         }
     }
     throw new ServerErrorHttpException('Failed to save the object for unknown reason.');
 }
Exemplo n.º 7
0
 /**
  * create default score rule for the current account
  */
 public static function createDefaultScoreRule($accountId)
 {
     $now = time();
     ScoreRule::getCollection()->batchInsert([['name' => ScoreRule::NAME_PERFECT_INFO, 'type' => ScoreRule::TYPE_EVENT, "accountId" => $accountId, "createdAt" => new \MongoDate($now), "updatedAt" => new \MongoDate($now), "isEnabled" => false, "isDeleted" => false], ['name' => ScoreRule::NAME_BIRTHDAY, 'type' => ScoreRule::TYPE_EVENT, "accountId" => $accountId, "createdAt" => new \MongoDate($now), "updatedAt" => new \MongoDate($now), "isEnabled" => false, "isDeleted" => false], ['name' => ScoreRule::NAME_FIRST_CARD, 'type' => ScoreRule::TYPE_EVENT, "accountId" => $accountId, "createdAt" => new \MongoDate($now), "updatedAt" => new \MongoDate($now), "isEnabled" => false, "isDeleted" => false]]);
 }