public function perform() { $args = $this->args; $date = empty($args['date']) ? '' : $args['date']; $datetime = TimeUtil::getDatetime($date); $dateStr = date('Y-m', $datetime); $monthData = ModelStatsMemberDaily::getMonthData($dateStr); $rowsMonthly = []; foreach ($monthData as $item) { $origin = $item['_id']['origin']; $originName = $item['_id']['originName']; $accountId = $item['_id']['accountId']; $total = $item['total']; $statsMemberMonthly = ModelStatsMemberMonthly::getByDateAndOriginInfo($dateStr, $origin, $originName, $accountId); if (!empty($statsMemberMonthly)) { $statsMemberMonthly->total = $total; try { $statsMemberMonthly->save(true, ['total']); } catch (Exception $e) { ResqueUtil::log(['Update StatsMemberMonthly error' => $e->getMessage(), 'StatsMemberMonthly' => $statsMemberMonthly]); continue; } } else { $rowsMonthly[] = ['month' => $dateStr, 'origin' => $origin, 'originName' => $originName, 'accountId' => $accountId, 'total' => $total]; } } ModelStatsMemberMonthly::batchInsert($rowsMonthly); return true; }
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 actionSignupSummary() { $params = $this->getQuery(); if (!isset($params['start']) || !isset($params['end'])) { throw new BadRequestHttpException(Yii::t('common', 'parameters_missing')); } if ($params['start'] > $params['end']) { throw new BadRequestHttpException(Yii::t('common', 'data_error')); } $accountId = $this->getAccountId(); $startDate = TimeUtil::msTime2String($params['start'], 'Y-m'); $endDate = TimeUtil::msTime2String($params['end'], 'Y-m'); $statsData = StatsMemberMonthly::getByDate($startDate, $endDate, $accountId); $data = []; foreach ($statsData as $item) { $date = $item->month; $data[$item->origin][$date] = empty($data[$item->origin][$date]) ? 0 : $data[$item->origin][$date]; $data[$item->origin][$date] += $item->total; } //ensure origins $channelOrigins = Channel::getOriginsByAccount($accountId); $origins = array_merge(StatsMemberMonthly::$originWithoutChannels, $channelOrigins); foreach ($origins as $origin) { if (empty($data[$origin])) { $data[$origin] = []; } } $endTime = strtotime($endDate); $dates = []; $totals = []; $dateTime = strtotime($startDate); while ($dateTime <= $endTime) { $date = date('Y-m', $dateTime); $dates[] = $date; foreach ($data as $origin => $dateTotal) { $totals[$origin][] = empty($dateTotal[$date]) ? 0 : $dateTotal[$date]; } $dateTime = strtotime('+1 month', $dateTime); } return ['date' => $dates, 'data' => $totals]; }