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;
 }
 public function perform()
 {
     $args = $this->args;
     if (empty($args['accountId']) || empty($args['properties'][0])) {
         ResqueUtil::log('Missing required arguments accountId or properties!');
         return false;
     }
     $accountId = new \MongoId($args['accountId']);
     $property = $args['properties'][0];
     $memberProperty = MemberProperty::findOne(['propertyId' => $property, 'accountId' => $accountId]);
     if (empty($memberProperty)) {
         ResqueUtil::log('Can not find member property with propertyId:' . $property);
         return false;
     }
     $date = empty($args['date']) ? '' : $args['date'];
     $date = TimeUtil::getDatetime($date);
     $month = date('Y-m', $date);
     $startDate = strtotime($month);
     $endDate = strtotime(date('Y-m', strtotime('+1 month', $date)));
     $raw = Member::getCollection()->aggregate([['$unwind' => '$properties'], ['$match' => ['createdAt' => ['$gte' => new \MongoDate($startDate), '$lt' => new \MongoDate($endDate)], 'properties.id' => $memberProperty->_id, 'accountId' => $accountId]], ['$group' => ['_id' => '$properties.value', 'total' => ['$sum' => 1]]]]);
     foreach ($raw as $item) {
         $total = $item['total'];
         $propValue = $item['_id'];
         // save the stats member property monthly
         $statsMemberPropMonthly = ModelStatsMemberPropMonthly::findOne(['propId' => $property, 'propValue' => $propValue, 'month' => $month, 'accountId' => $accountId]);
         if (empty($statsMemberPropMonthly)) {
             $statsMemberPropMonthly = new ModelStatsMemberPropMonthly();
             $statsMemberPropMonthly->propId = $property;
             $statsMemberPropMonthly->propValue = $propValue;
             $statsMemberPropMonthly->month = $month;
             $statsMemberPropMonthly->accountId = $accountId;
         }
         $statsMemberPropMonthly->total = $total;
         ResqueUtil::log($statsMemberPropMonthly->attributes);
         $statsMemberPropMonthly->save();
     }
     return true;
 }
 public function actionMemberMonthly()
 {
     $startDate = $this->getQuery('start');
     $endDate = $this->getQuery('end');
     if (empty($startDate) || empty($endDate)) {
         throw new BadRequestHttpException(Yii::t('common', 'parameters_missing'));
     }
     $startDate = TimeUtil::msTime2String($startDate, 'Y-m');
     $endDate = TimeUtil::msTime2String($endDate, 'Y-m');
     $accountId = $this->getAccountId();
     $condition = ['accountId' => $accountId, 'month' => ['$gte' => $startDate, '$lte' => $endDate]];
     $data = [];
     $stats = StatsMemberPropMonthly::findAll($condition);
     $dateCondition = ['dateFormat' => 'Y-m', 'dateDiff' => '+1 month', 'startDate' => $startDate, 'endDate' => $endDate];
     $result = $this->_formatStatsWithDate($stats, 'month', 'total', $dateCondition);
     return $result;
 }