/**
  * @args {"description": "Delay: Stats of StatsMemberGrowthQuarterly every day"}
  * @author Rex Chen
  */
 public function perform()
 {
     $args = $this->args;
     $date = empty($args['date']) ? '' : $args['date'];
     $datetime = TimeUtil::getDatetime($date);
     $year = date('Y', $datetime);
     $quarter = TimeUtil::getQuarter($datetime);
     $startMonth = ($quarter - 1) * 3 + 1;
     $startTime = new \MongoDate(strtotime($year . '-' . $startMonth . '-01'));
     $endTime = new \MongoDate(strtotime($year . '-' . $startMonth . '-01' . ' +3 month'));
     $accounts = Account::findAll(['enabledMods' => 'member']);
     foreach ($accounts as $account) {
         $accountId = $account->_id;
         $totalMember = Member::countByAccount($accountId, null, $endTime);
         $totalActive = MemberLogs::getTotalActiveByAccount($accountId, $startTime, $endTime);
         $totalNew = Member::countByAccount($accountId, $startTime, $endTime);
         $statsGrowth = ModelStatsMemberGrowthQuarterly::getByQuarterAndAccount($accountId, $year, $quarter);
         if (empty($statsGrowth)) {
             $statsGrowth = new ModelStatsMemberGrowthQuarterly();
             $statsGrowth->accountId = $accountId;
             $statsGrowth->year = $year;
             $statsGrowth->quarter = $quarter;
         }
         $statsGrowth->totalNew = $totalNew;
         $statsGrowth->totalActive = $totalActive;
         $statsGrowth->totalInactive = $totalMember - $totalActive;
         try {
             $statsGrowth->save();
         } catch (Exception $e) {
             ResqueUtil::log(['Update StatsMemberGrowthQuarterly error' => $e->getMessage(), 'StatsMemberGrowthMonthly' => $statsGrowth]);
             continue;
         }
     }
     return true;
 }
Exemplo n.º 2
0
 public function actionActiveTracking()
 {
     $params = $this->getQuery();
     if (empty($params['year']) || empty($params['quarter'])) {
         throw new BadRequestHttpException(Yii::t('common', 'parameters_missing'));
     }
     if ($params['quarter'] > 4 || $params['quarter'] < 1) {
         throw new BadRequestHttpException(Yii::t('common', 'data_error'));
     }
     $accountId = $this->getAccountId();
     return StatsMemberGrowthQuarterly::getByQuarterAndAccount($accountId, $params['year'], (int) $params['quarter']);
 }