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 static function generateStatsMemberPropTradeCodeQuarterlyData($propertyId, $condition)
 {
     $campaignLogDailys = StatsMemberCampaignLogDaily::getCollection()->aggregate(['$match' => $condition], ['$group' => ['_id' => ['propValue' => '$memProperty.' . $propertyId, 'code' => '$code']]], ['$group' => ['_id' => ['propValue' => '$_id.propValue'], 'total' => ['$sum' => 1]]]);
     if (!empty($campaignLogDailys)) {
         foreach ($campaignLogDailys as $item) {
             $rows[] = ['propId' => $propertyId, 'propValue' => $item['_id']['propValue'], 'total' => $item['total'], 'year' => $condition['year'], 'quarter' => $condition['quarter'], 'accountId' => $condition['accountId']];
         }
         StatsMemberPropTradeCodeQuarterly::batchInsert($rows);
         LogUtil::info(['message' => $condition['quarter'] . ':StatsMemberPropTradeCodeQuarterl =>' . count($rows)], 'update_job');
         unset($rows);
     }
 }
 public function perform()
 {
     $args = $this->args;
     $date = empty($args['date']) ? '' : $args['date'];
     $datetime = TimeUtil::getDatetime($date);
     $accountId = $args['accountId'];
     //Assume that the subChannel is the secode element in properties
     $propertyKey = $args['properties'][1];
     $memberProperty = MemberProperty::findOne(['propertyId' => $propertyKey]);
     if ($memberProperty != null) {
         return ModelStatsMemberPropTradeCodeQuarterly::generateByYearAndQuarter((string) $memberProperty['_id'], $accountId, $datetime);
     } else {
         ResqueUtil::log("Fail to get memberProperty with propertyId {$propertyKey}");
     }
     return false;
 }
 public function actionProductCode()
 {
     $params = $this->getQuery();
     if (empty($params['year']) || empty($params['quarter'])) {
         throw new BadRequestHttpException(Yii::t('common', 'parameters_missing'));
     }
     $accountId = $this->getAccountId();
     $raw = StatsMemberPropTradeCodeQuarterly::getByYearAndQuarter($params['year'], $params['quarter'], $accountId);
     $data = [];
     foreach ($raw as $item) {
         $propValue = $item['propValue'];
         //Skip the invalid property value (empty array, empty string)
         if (!empty($propValue)) {
             $data[$propValue] = $item['total'];
         }
     }
     return ['data' => $data];
 }