Пример #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);
                 }
             }
         }
     }
 }
 /**
  * @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);
                 }
             }
         }
     }
 }
Пример #3
0
 /**
  * Sync the stores data from wechat
  */
 public function actionSync()
 {
     $accountId = Token::getAccountId();
     $result = ['finished' => true];
     $account = Account::find()->select(['syncWechat'])->where(['_id' => $accountId, 'isDeleted' => Account::NOT_DELETED])->one();
     $wechat = Channel::getWechatByAccount($accountId, false);
     if (!empty($wechat)) {
         $unsyncWechat = array_diff($wechat, (array) $account->syncWechat);
         if (!empty($unsyncWechat)) {
             $args = ['accountId' => $accountId . '', 'channels' => $unsyncWechat, 'description' => 'Direct: Sync the stores data from wechat'];
             $token = Yii::$app->job->create('backend\\modules\\channel\\job\\StoreSync', $args);
             $result = ['finished' => false, 'token' => $token];
         }
     }
     return $result;
 }
Пример #4
0
 /**
  * Operate the enabled mods of account
  */
 public function actionOperateEnabledMods($operator, $modsStr, $accountIds = null)
 {
     $mods = split(',', $modsStr);
     $condition = [];
     if (!empty($accountIds)) {
         $ids = split(',', $accountIds);
         $mongoIds = [];
         foreach ($ids as $id) {
             $mongoIds[] = new \MongoId($id);
         }
         $condition['_id'] = ['$in' => $mongoIds];
     }
     $accounts = Account::find()->where($condition)->all();
     if (!empty($accounts)) {
         foreach ($accounts as $account) {
             $oldEnabledMods = $account->enabledMods;
             if ('add' === $operator) {
                 $newEnabledMods = array_merge($oldEnabledMods, $mods);
             } else {
                 if ('remove' === $operator) {
                     $newEnabledMods = array_diff($oldEnabledMods, $mods);
                 }
             }
             $account->enabledMods = array_unique($newEnabledMods);
             if ($account->save()) {
                 echo ucwords($operator) . ' account enabled mods successfully with account id ' . $account->_id . "\n";
             } else {
                 echo 'Fail to ' . $operator . ' add account enabled mods with account id  ' . $account->_id . "\n" . $account->getErrors() . "\n";
             }
         }
     }
 }