Пример #1
0
 /**
  *  Check expired membership card.
  */
 public function actionCheckCardExpiredTime()
 {
     $accounts = Account::find()->where(['isDeleted' => Account::NOT_DELETED])->all();
     if (!empty($accounts)) {
         $nowTimestamp = strtotime(date('Y-m-d')) * 1000;
         $oneDayTimestamp = 24 * 60 * 60 * 1000;
         foreach ($accounts as $account) {
             $accountId = $account->_id;
             for ($day = 0; $day <= 7; $day++) {
                 $startDayTimestamp = $nowTimestamp + $oneDayTimestamp * ($day - 1);
                 $endDayTimestamp = $nowTimestamp + $oneDayTimestamp * $day;
                 if ($day === 0) {
                     $startDayTimestamp = 0;
                 }
                 $expiredCount = Member::find()->where(['accountId' => $accountId, 'cardExpiredAt' => ['$lte' => $endDayTimestamp, '$gt' => $startDayTimestamp], 'isDeleted' => Member::NOT_DELETED])->count();
                 if ($expiredCount > 0) {
                     if ($day === 0) {
                         $content = "有 {$expiredCount} 个会员的会员卡已过期, <a href='/member/member?cardState=3'>(点击查看)</a>";
                     } else {
                         if ($day === 1) {
                             $content = "有 {$expiredCount} 个会员的会员卡即将于1天内过期, <a href='/member/member?cardState=1'>(点击查看)</a>";
                         } else {
                             $date = date("Y-m-d", $startDayTimestamp / 1000);
                             $content = "有 {$expiredCount} 个会员的会员卡即将于 {$date} 过期, <a href='/member/member?cardState=2'>(点击查看)</a>";
                         }
                     }
                     $this->_recordMessage($accountId, $content);
                 }
             }
         }
     }
 }
Пример #2
0
 public function perform()
 {
     $args = $this->args;
     if (empty($args['accountId']) || empty($args['key']) || empty($args['header'])) {
         ResqueUtil::log(['status' => 'fail to export member', 'message' => 'missing params', 'args' => $args]);
         return false;
     }
     Yii::$app->language = empty($args['language']) ? LanguageUtil::DEFAULT_LANGUAGE : $args['language'];
     $accountId = new \MongoId($args['accountId']);
     $header = $args['header'];
     // get member's customized properties
     $memberProperties = MemberProperty::getByAccount($accountId);
     foreach ($memberProperties as $memberProperty) {
         if ($memberProperty->isDefault) {
             $header[$memberProperty->name] = Yii::t('member', $memberProperty->name);
         } else {
             $header[$memberProperty->name] = $memberProperty->name;
         }
     }
     $socialAccountsMap = [];
     $account = Account::findByPk($accountId);
     $channelIds = Channel::getEnableChannelIds($accountId);
     if (!empty($channelIds)) {
         $socialAccounts = \Yii::$app->weConnect->getAccounts($channelIds);
         foreach ($socialAccounts as $socialAccount) {
             $socialAccountsMap[$socialAccount['id']] = $socialAccount['name'];
         }
     }
     $cardMap = [];
     $cards = MemberShipCard::getByAccount($accountId);
     foreach ($cards as $card) {
         $cardMap[(string) $card->_id] = $card->name;
     }
     $condition = unserialize($args['condition']);
     //get properties
     $memberProperties = MemberProperty::findAll(['accountId' => $accountId]);
     $base = ['cardMap' => $cardMap, 'socialAccountsMap' => $socialAccountsMap, 'memberProperties' => $memberProperties];
     $fileName = $args['key'];
     $filePath = ExcelUtil::getFile($fileName, 'csv');
     $orderBy = Member::normalizeOrderBy($args['params']);
     $object = Member::find();
     $classFunction = '\\backend\\modules\\member\\models\\Member::preProcessMemberData';
     ExcelUtil::processMultiData($header, $filePath, $base, $condition, $object, $classFunction, [], $orderBy);
     $hashKey = ExcelUtil::setQiniuKey($filePath, $fileName);
     if ($hashKey) {
         //notice frontend the job is finished
         \Yii::$app->tuisongbao->triggerEvent(Message::EVENT_EXPORT_FINISH, ['key' => $fileName], [Message::CHANNEL_GLOBAL . $args['accountId']]);
         return true;
     } else {
         return false;
     }
 }
Пример #3
0
 /**
  * @args {"description": "Delay: Automatic clear member score. every day"}
  */
 public function perform()
 {
     $month = intval(date('m'));
     $day = intval(date('d'));
     $memberShipCards = MemberShipCard::find()->where(['isDeleted' => MemberShipCard::NOT_DELETED, 'scoreResetDate.month' => $month, 'scoreResetDate.day' => $day])->all();
     if (!empty($memberShipCards)) {
         foreach ($memberShipCards as $memberShipCard) {
             $members = Member::find()->where(['isDeleted' => MemberShipCard::NOT_DELETED, 'cardId' => $memberShipCard->_id, 'score' => ['$ne' => 0]])->all();
             if (!empty($members)) {
                 foreach ($members as $member) {
                     Member::resetScore($member->_id, $member->accountId);
                 }
             }
         }
     }
 }
 /**
  * @args {"description": "Delay: Send member expired message every day"}
  */
 public function perform()
 {
     $accounts = Account::find()->where(['isDeleted' => Account::NOT_DELETED])->all();
     if (!empty($accounts)) {
         $nowTimestamp = strtotime(date('Y-m-d')) * 1000;
         $oneDayTimestamp = 24 * 60 * 60 * 1000;
         foreach ($accounts as $account) {
             $accountId = $account->_id;
             for ($day = 0; $day <= 7; $day++) {
                 $startDayTimestamp = $nowTimestamp + $oneDayTimestamp * ($day - 1);
                 $endDayTimestamp = $nowTimestamp + $oneDayTimestamp * $day;
                 if ($day === 0) {
                     $startDayTimestamp = 0;
                 }
                 $expiredCount = Member::find()->where(['accountId' => $accountId, 'cardExpiredAt' => ['$lte' => $endDayTimestamp, '$gt' => $startDayTimestamp], 'isDeleted' => Member::NOT_DELETED])->count();
                 if ($expiredCount > 0) {
                     if ($day === 0) {
                         if ($expiredCount == 1) {
                             $content = "msg_have {$expiredCount} msg_had_expired <a href='/member/member?cardState=3'> msg_click_read </a>";
                         } else {
                             $content = "msg_have {$expiredCount} msg_had_expireds <a href='/member/member?cardState=3'> msg_click_read </a>";
                         }
                     } else {
                         if ($day === 1) {
                             if ($expiredCount == 1) {
                                 $content = "msg_have {$expiredCount} msg_having_expired <a href='/member/member?cardState=1'> msg_click_read </a>";
                             } else {
                                 $content = "msg_have {$expiredCount} msg_had_expireds <a href='/member/member?cardState=1'> msg_click_read </a>";
                             }
                         } else {
                             $date = date("Y-m-d", $startDayTimestamp / 1000);
                             if ($expiredCount == 1) {
                                 $content = "msg_have {$expiredCount} msg_having {$date} msg_expired <a href='/member/member?cardState=2'> msg_click_read </a>";
                             } else {
                                 $content = "msg_have {$expiredCount} msg_havings {$date} msg_expired <a href='/member/member?cardState=2'> msg_click_read </a>";
                             }
                         }
                     }
                     $this->recordMessage($accountId, $content);
                 }
             }
         }
     }
 }
Пример #5
0
 private function _channel()
 {
     $skip = 0;
     $limit = 100;
     $map = ['WEIXIN' => 'wechat', 'WEIBO' => 'weibo', 'ALIPAY' => 'alipay'];
     $channelTypeMap = [];
     $channels = \Yii::$app->weConnect->allAccounts();
     foreach ($channels as $channel) {
         $channelTypeMap[$channel['id']] = $map[$channel['channel']];
     }
     $query = Member::find()->where([])->orderBy(['createdAt' => SORT_ASC]);
     $query = $query->offset($skip)->limit($limit);
     $members = $query->all();
     $fileMemberNeedCheck = 'fail-' . time();
     $fileMemberError = 'error-' . time();
     while (!empty($members)) {
         foreach ($members as $member) {
             try {
                 if (!empty($member->socialAccountId) && empty($member->origin)) {
                     $member->origin = $channelTypeMap[$member->socialAccountId];
                 }
                 if (!empty($member->openId) && !empty($member->socialAccountId) && empty($member->originScene)) {
                     $openId = $member->openId;
                     $channelId = $member->socialAccountId;
                     $follower = \Yii::$app->weConnect->getFollowerByOriginId($openId, $channelId);
                     $member->originScene = empty($follower['firstSubscribeSource']) ? '' : $follower['firstSubscribeSource'];
                 }
                 $member->save(true, ['origin', 'originScene', 'socials']);
             } catch (\Exception $e) {
                 $msg = 'error member ' . $member->_id . PHP_EOL;
                 echo $msg;
                 $this->_saveFile($msg . $e->getMessage() . PHP_EOL, $fileMemberError);
             }
         }
         $skip += $limit;
         $query = $query->offset($skip)->limit($limit);
         $members = $query->all();
     }
 }
Пример #6
0
 /**
  * get member info even if the member is deleted
  * @param $condition, array
  */
 public static function getAllMember($condition)
 {
     $members = Member::find()->where($condition)->all();
     return $members;
 }
Пример #7
0
 /**
  * return member query object
  */
 public function getQueryObject()
 {
     return ModelMember::find();
 }
Пример #8
0
 public static function createSmsJob($condition, $operator, $smsTag)
 {
     $accountId = Token::getAccountId();
     switch ($smsTag) {
         case 'sms_one':
             $smsTemplate = self::EARLY_BIRD_ONE_TEMPLATE;
             break;
         case 'sms_two':
             $smsTemplate = self::EARLY_BIRD_TWO_TEMPLATE;
             break;
         case 'sms_three':
             $smsTemplate = self::EARLY_BIRD_THREE_TEMPLATE;
             break;
         case 'sms_four':
             $smsTemplate = self::EARLY_BIRD_FOUR_TEMPLATE;
             break;
         default:
             break;
     }
     $recordId = EarlyBirdSmsRecord::createSmsRecord($operator, $smsTag, $smsTemplate);
     $count = 0;
     if (is_bool($recordId) && !$recordId) {
         throw new ServerErrorHttpException("發送失敗,請刷新頁面重試!");
     }
     if (!array_key_exists('accountId', $condition)) {
         $condition = array_merge($condition, ['accountId' => $accountId]);
     }
     if ($smsTag == 'sms_four') {
         $count = count(self::getMemberCanDraw($condition));
         // get發送總量
     } else {
         $count = Member::find()->where($condition)->count();
     }
     $smsRecord = EarlyBirdSmsRecord::findOne($recordId);
     // set發送總量
     $smsRecord->total = $count;
     $smsRecord->save();
     unset($smsRecord);
     $args = ['condition' => serialize($condition), 'smsTag' => $smsTag, 'smsRecord' => (string) $recordId];
     $jobId = Yii::$app->job->create('backend\\modules\\uhkklp\\job\\EarlyBirdSendSms', $args);
     if (!empty($jobId)) {
         return ['smsRecordId' => (string) $recordId, 'count' => $count];
     } else {
         throw new ServerErrorHttpException("發送失敗,請刷新頁面重試!");
     }
 }
Пример #9
0
 public function actionExport()
 {
     $params = $this->getQuery();
     $accountId = $this->getAccountId();
     if (!empty($params['cardStates'])) {
         $params['cardExpiredAt'] = Member::getCardExpiredTime($params);
     }
     $where = Member::getCondition($params, $accountId);
     $condition = $where['condition'];
     //only export enable member
     $condition['isDisabled'] = ['$ne' => true];
     if (!empty($where['cardStatusCondition'])) {
         $condition = ['and', $condition, $where['cardStatusCondition']];
     }
     if (!empty($where['searchCondition'])) {
         $condition = ['and', $condition, $where['searchCondition']];
     }
     $result = Member::find()->where($condition)->one();
     if (!empty($result)) {
         $key = Yii::t('product', 'export_member_file_name') . '_' . date('YmdHis');
         $headerTitle = Yii::t('member', 'member_export_title');
         $headerValue = explode(',', $headerTitle);
         $header = ['cardNumber', 'cardName', 'score', 'totalScore', 'totalScoreAfterZeroed', 'costScoreAfterZeroed', 'channel', 'createdAt', 'tag'];
         $showHeader = array_combine($header, $headerValue);
         $exportArgs = ['key' => $key, 'header' => $showHeader, 'accountId' => (string) $accountId, 'condition' => serialize($condition), 'description' => 'Direct: export member', 'params' => $params];
         $jobId = Yii::$app->job->create('backend\\modules\\member\\job\\ExportMember', $exportArgs);
         return ['result' => 'success', 'message' => 'exporting file', 'data' => ['jobId' => $jobId, 'key' => $key]];
     } else {
         throw new BadRequestHttpException(Yii::t('member', 'export_member_failed'));
         //return ['result' => 'member_error', 'message' => 'no datas', 'data' => []];
     }
 }