Exemplo n.º 1
0
 /**
  * Update location statistics
  * @param mongoId $accountId
  * @return boolean
  */
 private function updateLocationStatistics($accountId)
 {
     $memberStatistics = MemberStatistics::getByAccount($accountId);
     if (empty($memberStatistics)) {
         $memberStatistics = new MemberStatistics();
     }
     $locationStatistics = $this->getlocationStatistics($accountId);
     $memberStatistics->locationStatistics = $locationStatistics;
     $memberStatistics->accountId = $accountId;
     return $memberStatistics->save();
 }
 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;
 }
 /**
  * Query statistics info
  *
  * <b>Request Type: </b>GET<br/>
  * <b>Request Endpoint: </b>http://{server-domain}/api/member/statisticss
  * <b>Summary: </b>This api is for query statistics info
  *
  * <b>Request Params</b>:<br/>
  *     locationProperty: string,country, province, city<br/>
  *     parentCountry: string<br/>
  *     parentProvince: string<br/>
  *     <br/><br/>
  *
  * <b>Response Example: </b>
  * <pre>
  *  {
  *      "items": [
  *          {
  *              "value": "黄冈"
  *          },
  *          {
  *              "value": "武汉"
  *          }
  *      ]
  *  }
  * </pre>
  */
 public function actionIndex()
 {
     $accountId = $this->getAccountId();
     $locationProperty = $this->getQuery('locationProperty');
     $parentCountry = $this->getQuery('parentCountry');
     $parentProvince = $this->getQuery('parentProvince');
     if (empty($locationProperty)) {
         throw new BadRequestHttpException('missing property');
     }
     //get location statistics
     $statistics = MemberStatistics::getByAccount($accountId);
     if (empty($statistics['locationStatistics'])) {
         return ['items' => []];
     }
     $locationStatistics = $statistics['locationStatistics'];
     $items = [];
     //get all country unset provinces
     if ($locationProperty == 'country') {
         foreach ($locationStatistics as $locationStatistic) {
             unset($locationStatistic['provinces']);
             if (!empty($locationStatistic['value'])) {
                 $items[] = $locationStatistic;
             }
         }
     } else {
         if ($locationProperty == 'province') {
             $provinces = [];
             //get provinces
             foreach ($locationStatistics as $locationStatistic) {
                 if ($locationStatistic['value'] == $parentCountry) {
                     $provinces = $locationStatistic['provinces'];
                 }
             }
             //unset city
             foreach ($provinces as $province) {
                 unset($province['cities']);
                 $items[] = $province;
             }
         } else {
             if ($locationProperty == 'city') {
                 foreach ($locationStatistics as $locationStatistic) {
                     if ($locationStatistic['value'] == $parentCountry) {
                         $provinces = $locationStatistic['provinces'];
                         foreach ($provinces as $province) {
                             $cities = $province['cities'];
                             if ($province['value'] == $parentProvince) {
                                 $items = $cities;
                             }
                         }
                     }
                 }
             }
         }
     }
     $result = ['items' => $items];
     return $result;
 }