/** * @args {"description": "Delay: Stats of StatsMemberGrowthMonthly every day"} * @author Rex Chen */ public function perform() { $args = $this->args; $date = empty($args['date']) ? '' : $args['date']; $datetime = TimeUtil::getDatetime($date); $dateStr = date('Y-m', $datetime); $startTime = new \MongoDate(strtotime($dateStr . '-01')); $endTime = new \MongoDate(strtotime($dateStr . '-01 +1 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 = ModelStatsMemberGrowthMonthly::getByMonthAndAccount($accountId, $dateStr); if (empty($statsGrowth)) { $statsGrowth = new ModelStatsMemberGrowthMonthly(); $statsGrowth->accountId = $accountId; $statsGrowth->month = $dateStr; } $statsGrowth->totalNew = $totalNew; $statsGrowth->totalActive = $totalActive; $statsGrowth->totalInactive = $totalMember - $totalActive; try { $statsGrowth->save(); } catch (Exception $e) { ResqueUtil::log(['Update StatsMemberGrowthMonthly error' => $e->getMessage(), 'StatsMemberGrowthMonthly' => $statsGrowth]); continue; } } return true; }
public function actionEngagement() { $params = $this->getQuery(); if (empty($params['year'])) { throw new BadRequestHttpException(Yii::t('common', 'parameters_missing')); } $accountId = $this->getAccountId(); $startDate = $params['year'] . '-01'; $endDate = $params['year'] . '-12'; $statsGrowth = StatsMemberGrowthMonthly::getByMonth($accountId, $startDate, $endDate); $monthActiveMap = []; foreach ($statsGrowth as $growth) { $monthActiveMap[$growth->month] = $growth->totalActive; } $dates = []; $data = []; $dateTime = strtotime($startDate); $endTime = strtotime($endDate); while ($dateTime <= $endTime) { $date = date('Y-m', $dateTime); $dates[] = date('M', $dateTime); $data[] = empty($monthActiveMap[$date]) ? 0 : $monthActiveMap[$date]; $dateTime = strtotime('+1 month', $dateTime); } return ['date' => $dates, 'data' => $data]; }
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; }