Ejemplo n.º 1
0
 private function issueBirthdayCoupon($accountId, $birthdayCoupon, $memberId)
 {
     //check coupon
     $couponId = $birthdayCoupon->couponId;
     $suitMemberIds = $this->getRewardMemberIds($accountId, $memberId, $birthdayCoupon);
     if (!empty($suitMemberIds)) {
         $members = Member::findAll(['_id' => ['$in' => $suitMemberIds]]);
         $coupon = Coupon::findByPk($couponId);
         if (empty($coupon)) {
             LogUtil::error(['message' => 'can not find the coupon', 'couponId' => (string) $couponId], 'member');
             return false;
         }
         $total = count($members);
         $result = Coupon::updateAll(['$inc' => ['total' => 0 - $total]], ['total' => ['$gt' => $total], '_id' => $couponId]);
         if ($result) {
             foreach ($members as $member) {
                 //issue membershipdiscount
                 $membershipDiscount = MembershipDiscount::transformMembershipDiscount($coupon, $member, ScoreRule::NAME_BIRTHDAY);
                 if (false === $membershipDiscount->save()) {
                     Coupon::updateAll(['$inc' => ['total' => 1]], ['_id' => $couponId]);
                     LogUtil::error(['message' => 'add membershipdiscount fail', 'memberId' => (string) $member->_id, 'couponId' => (string) $coupon->_id], 'member');
                 } else {
                     LogUtil::info(['message' => 'issue coupon successful', 'couponId' => (string) $couponId, 'memberId' => (string) $member->_id], 'member');
                 }
             }
         } else {
             LogUtil::error(['message' => 'coupon is not enough when give member birthday reward'], 'member');
             return false;
         }
     }
 }
 public static function getMemberInfo($condition)
 {
     $memberIds = CampaignLog::distinct('member.id', $condition);
     $members = Member::findAll(['_id' => ['$in' => $memberIds]]);
     $data = [];
     if (!empty($members)) {
         foreach ($members as $member) {
             $data[(string) $member->_id] = $member;
         }
     }
     return $data;
 }
Ejemplo n.º 3
0
 private function _repairData()
 {
     $fileName = 'deleted-' . time();
     $result = $this->_getRepairData();
     foreach ($result as $item) {
         $condition = ['properties' => ['$elemMatch' => ['name' => Member::DEFAULT_PROPERTIES_MOBILE, 'value' => $item['_id']['tel']]], 'accountId' => $item['_id']['accountId']];
         $members = Member::findAll($condition);
         $score = [];
         $keepMember = [];
         $deleteMember = [];
         foreach ($members as $member) {
             if (!in_array($member->score, $score)) {
                 $score[] = $member->score;
                 $keepMember[] = $member->_id;
             } else {
                 $msg = 'deleted member ' . $member->_id . PHP_EOL;
                 $deleteMember[] = $member->_id;
                 echo $msg;
                 $this->_saveFile($msg, $fileName);
             }
         }
         $deleteCondition = ['_id' => ['$in' => $deleteMember]];
         Member::deleteAll($deleteCondition);
     }
 }
Ejemplo n.º 4
0
 /**
  * get member info by condition
  * @return array
  * @param $condition, array
  * @param $one,boolean,if this value is true,it will return a data,otherwise it will return all datas
  */
 public function getByCondition($condition, $one = true)
 {
     if ($one) {
         return ModelMember::findOne($condition);
     } else {
         return ModelMember::findAll($condition);
     }
 }
Ejemplo n.º 5
0
 public function actionMerge()
 {
     $params = $this->getParams();
     if (empty($params['main']) || empty($params['others'])) {
         throw new BadRequestHttpException(Yii::t('common', 'parameters_missing'));
     }
     if (!is_array($params['others']) || in_array($params['main'], $params['others'])) {
         throw new BadRequestHttpException(Yii::t('common', 'data_error'));
     }
     $accountId = $this->getAccountId();
     $mainMember = Member::findByPk(new \MongoId($params['main']), ['accountId' => $accountId]);
     if (empty($mainMember)) {
         throw new InvalidParameterException(Yii::t('member', 'no_member_find'));
     }
     //get mongoIds
     $otherMemberIds = [];
     foreach ($params['others'] as $otherId) {
         $otherMemberIds[] = new \MongoId($otherId);
     }
     $otherMembers = Member::findAll(['_id' => ['$in' => $otherMemberIds], 'accountId' => $accountId]);
     if (empty($otherMembers) || count($otherMembers) != count($params['others'])) {
         throw new InvalidParameterException(Yii::t('member', 'no_member_find'));
     }
     $mainProperties = [];
     $mainPropertyIds = [];
     foreach ($mainMember->properties as $mainProperty) {
         if (!empty($mainProperty['value'])) {
             $mainPropertyIds[] = $mainProperty['id'];
             $mainProperties[] = $mainProperty;
         }
     }
     $mainMemberLocation = $mainMember->location;
     $otherMemberLocation = [];
     $newMemberTag = empty($mainMember->tags) ? [] : $mainMember->tags;
     foreach ($otherMembers as $otherMember) {
         $mainMember->score += $otherMember->score;
         $mainMember->totalScore += $otherMember->totalScore;
         $mainMember->totalScoreAfterZeroed += $otherMember->totalScoreAfterZeroed;
         $newMemberTag = array_merge($newMemberTag, empty($otherMember->tags) ? [] : $otherMember->tags);
         $location = $otherMember->location;
         if (empty($otherMemberLocation['country']) && !empty($location['country'])) {
             $otherMemberLocation = $location;
         }
         foreach ($otherMember->properties as $otherProperty) {
             if (!in_array($otherProperty['id'], $mainPropertyIds) && !empty($otherProperty['value'])) {
                 $mainPropertyIds[] = $otherProperty['id'];
                 $mainProperties[] = $otherProperty;
             }
         }
     }
     $mainMember->properties = $mainProperties;
     $mainMember->tags = array_values(array_unique($newMemberTag));
     if (empty($mainMemberLocation['country']) && !empty($otherMemberLocation)) {
         $mainMember->location = $otherMemberLocation;
     }
     $updateMember = $mainMember->save(false);
     $deleteMember = Member::deleteAll(['_id' => ['$in' => $otherMemberIds]]);
     if ($updateMember && $deleteMember) {
         $mainMember->upgradeCard();
         $jobArgs = ['mainMember' => serialize($mainMember), 'otherMemberIds' => serialize($otherMemberIds)];
         Yii::$app->job->create('backend\\modules\\member\\job\\MergeMember', $jobArgs);
         return ['message' => 'OK', 'data' => ''];
     } else {
         throw new ServerErrorHttpException('Merge member fail');
     }
 }