コード例 #1
0
ファイル: Birthday.php プロジェクト: timelessmemory/uhkklp
 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;
         }
     }
 }
コード例 #2
0
ファイル: Coupon.php プロジェクト: timelessmemory/uhkklp
 public function makeUsed($memberId, $couponId)
 {
     if (is_string($memberId)) {
         $memberId = new MongoId($memberId);
     }
     if (is_string($couponId)) {
         $couponId = new MongoId($couponId);
     }
     $condition = ['member.id' => $memberId, 'coupon.id' => $couponId];
     $update = ['coupon.status' => ModelMembershipDiscount::USED];
     return ModelMembershipDiscount::updateAll($update, $condition);
 }
コード例 #3
0
 public function perform()
 {
     $args = $this->job->payload['args'];
     $args = json_decode($args, true);
     if (empty($args['qrcodeType']) || empty($args['accountId']) || empty($args['associatedId']) || empty($args['membershipDiscountId'])) {
         LogUtil::error(['message' => 'Missing params', 'params' => $args], 'upload_resque');
         return false;
     }
     $qrcode = Yii::$app->qrcode->create(rtrim(DOMAIN, '/'), $args['qrcodeType'], $args['associatedId'], new MongoId($args['accountId']));
     //update membership discount qrcode info
     $qrcodeItem = ['_id' => $qrcode->_id, 'qiniuKey' => $qrcode->qiniuKey];
     if (false == MembershipDiscount::updateAll(['$set' => ['qrcode' => $qrcodeItem]], ['_id' => new MongoId($args['membershipDiscountId'])])) {
         LogUtil::error(['message' => 'Fail to update MembershipDiscount qrcode info', 'qrcodeItem' => var_export($qrcodeItem, true), 'membershipDiscountId' => $args['membershipDiscountId']], 'upload_resque');
     }
     return true;
 }
コード例 #4
0
ファイル: Member.php プロジェクト: timelessmemory/uhkklp
 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');
                 }
             }
         }
     }
 }
コード例 #5
0
 public function actionIndex($accountId)
 {
     if (empty($accountId)) {
         echo 'accountId is invaild' . PHP_EOL;
         exit;
     }
     $where['accountId'] = new \MongoId($accountId);
     // delete member info
     Member::getCollection()->remove($where);
     //delete MemberLogs
     MemberLogs::getCollection()->remove($where);
     //delete scoreHistory
     ScoreHistory::getCollection()->remove($where);
     //delete CampaignLog
     CampaignLog::getCollection()->remove($where);
     //delete GoodsExchangeLog
     GoodsExchangeLog::getCollection()->remove($where);
     //delete MemberStatistics
     MemberStatistics::getCollection()->remove($where);
     //delete ReMemberCampaign
     ReMemberCampaign::getCollection()->remove($where);
     //delete StatsCampaignProductCodeQuarterly
     StatsCampaignProductCodeQuarterly::getCollection()->remove($where);
     //delete StatsMemberCampaignLogDaily
     StatsMemberCampaignLogDaily::getCollection()->remove($where);
     //delete StatsMemberDaily
     StatsMemberDaily::getCollection()->remove($where);
     //delete StatsMemberGrowthMonthly
     StatsMemberGrowthMonthly::getCollection()->remove($where);
     //delete StatsMemberGrowthQuarterly
     StatsMemberGrowthQuarterly::getCollection()->remove($where);
     //delete StatsMemberMonthly
     StatsMemberMonthly::getCollection()->remove($where);
     //delete StatsMemberPropAvgTradeQuarterly
     StatsMemberPropAvgTradeQuarterly::getCollection()->remove($where);
     //delete StatsMemberPropMonthly
     StatsMemberPropMonthly::getCollection()->remove($where);
     //delete StatsMemberPropQuaterly
     StatsMemberPropQuaterly::getCollection()->remove($where);
     //delete StatsMemberPropTradeCodeAvgQuarterly
     StatsMemberPropTradeCodeAvgQuarterly::getCollection()->remove($where);
     //delete StatsMemberPropTradeCodeQuarterly
     StatsMemberPropTradeCodeQuarterly::getCollection()->remove($where);
     //delete StatsMemberPropTradeQuarterly
     StatsMemberPropTradeQuarterly::getCollection()->remove($where);
     //delete PromotionCodeAnalysis
     PromotionCodeAnalysis::getCollection()->remove($where);
     //delete order
     Order::getCollection()->remove($where);
     //delete stats member order
     StatsMemberOrder::getCollection()->remove($where);
     //delete stats order
     StatsOrder::getCollection()->remove($where);
     //delete MembershipDiscount
     MembershipDiscount::getCollection()->remove($where);
     //delete couponLog
     CouponLog::getCollection()->remove($where);
     echo 'delete data successful.' . PHP_EOL;
 }
コード例 #6
0
 /**
  * receive copon through oauth recall this api
  */
 public function actionReceivedCoupon()
 {
     $params = $this->getQuery();
     $defaultId = -1;
     $message = '';
     if (empty($params['couponId']) || empty($params['memberId']) || empty($params['channelId'])) {
         LogUtil::error(['message' => 'missing params when receive coupon', 'params' => $params], 'product');
         exit;
     }
     $number = !empty($params['number']) && intval($params['number']) > 1 ? intval($params['number']) : 1;
     $couponId = new MongoId($params['couponId']);
     $coupon = Coupon::findByPk($couponId);
     if (empty($coupon)) {
         LogUtil::error(['message' => 'invalid couponIdi when receive coupon', 'params' => $params], 'product');
         exit;
     }
     $memberId = new MongoId($params['memberId']);
     $member = Member::findByPk($memberId);
     if (empty($member)) {
         LogUtil::error(['message' => 'invalid memberId when receive coupon', 'params' => $params], 'product');
         exit;
     }
     $args = ['mainDomain' => Yii::$app->request->hostInfo . '/mobile/product/coupon', 'couponId' => $params['couponId'], 'id' => $defaultId, 'memberId' => $params['memberId'], 'result' => 'fail', 'channelId' => $params['channelId']];
     //check the total
     if ($coupon->total < $number) {
         $message = Yii::t('product', 'coupon_no_exists');
         return $this->_redirectCouponDetail($message, $args, $params);
     }
     //check limit
     $couponNumber = CouponLog::count(['couponId' => $couponId, 'member.id' => $memberId]);
     if ($couponNumber >= $coupon->limit) {
         $message = Yii::t('product', 'coupon_is_received');
         return $this->_redirectCouponDetail($message, $args, $params);
     }
     //check the time
     $current = new MongoDate(strtotime(date('Y-m-d')));
     if ($coupon->time['type'] == Coupon::COUPON_RELATIVE_TIME && $coupon->time['endTime'] < $current) {
         $message = Yii::t('product', 'coupon_expired');
         return $this->_redirectCouponDetail($message, $args, $params);
     }
     //receive coupon
     $where = ['total' => ['$gte' => $number], '_id' => $couponId];
     $number -= 2 * $number;
     if (Coupon::updateAll(['$inc' => ['total' => $number]], $where)) {
         $membershipDiscount = MembershipDiscount::transformMembershipDiscount($coupon, $member);
         if (false === $membershipDiscount->save()) {
             //to avoid the error show to user
             LogUtil::error(['message' => 'Failed to save couponLog error:' . $membershipDiscount->getErrors()], 'product');
             $message = Yii::t('common', 'save_fail');
             return $this->_redirectCouponDetail($message, $args, $params);
         }
         $args['id'] = isset($membershipDiscount->_id) ? $membershipDiscount->_id : $defaultId;
         $args['result'] = 'success';
     } else {
         $message = '优惠券库存不足!';
     }
     return $this->_redirectCouponDetail($message, $args, $params);
 }
コード例 #7
0
 public static function getAvailableMembershipDiscount($params, $current)
 {
     $where = ['member.id' => $params['memberId'], 'coupon.type' => Coupon::COUPON_CASH, 'coupon.status' => self::UNUSED, 'coupon.startTime' => ['$lt' => $current], '$or' => [['coupon.discountCondition' => null], ['coupon.discountCondition' => ['$lte' => intval($params['price'])]]]];
     return MembershipDiscount::findAll($where);
 }
コード例 #8
0
 public function perform()
 {
     $now = new MongoDate(strtotime('+1 minute'));
     $result = MembershipDiscount::updateAll(['$set' => ['coupon.status' => MembershipDiscount::EXPIRED]], ['coupon.endTime' => ['$lte' => $now], 'coupon.status' => ['$in' => [MembershipDiscount::UNUSED, MembershipDiscount::USED]]]);
     echo $result;
 }