Пример #1
0
 public function get_ad_happy_lock_task_stat($id, $start, $end, $type)
 {
     $params = '{
   "index" : "task_stat",
   "type" : "' . $type . '",
   "body" : {
     "query" : {
       "bool": {
         "must": [
           {
             "query_string": {
               "default_field": "app_id",
               "query": "' . self::HAPPY_LOCK_SQL . '"
             }
           },
           {
             "term": {
               "ad_id": "' . $id . '"
             }
           },
           {
             "range": {
               "task_date": {
                 "gte": "' . $start . '",
                 "lte": "' . $end . '"
               }
             }
           }
         ]
       }
     },
     "aggs": {
       "all_dates": {
         "terms": {
           "field": "task_date",
           "size": 100
         },
         "aggs": {
           "sum_rmb": {
             "sum": {
               "field": "rmb"
             }
           }
         }
       }
     },
     "size": 0
   }
 }';
     $es_service = new ES();
     $es_task = $es_service->query($params);
     $happy_lock_task = array();
     if ($es_task) {
         foreach ($es_task['aggregations']['all_dates']['buckets'] as $ad_task) {
             $happy_lock_task[substr($ad_task['key_as_string'], 0, 10)] = $ad_task['sum_rmb']['value'];
         }
     }
     return $happy_lock_task;
 }
 public function get_all_ad_transfer_by_user($start, $end, $app_ids)
 {
     if (strtotime($start) > time() - 86400 * 89) {
         $app_ids_sql = implode("','", $app_ids);
         $sql = "SELECT `ad_id`,sum(`rmb_total`) AS `rmb`,sum(`transfer_total`) AS `transfer`\n              FROM `s_transfer_stat_app_ad`\n              WHERE `transfer_date`>=:start AND `transfer_date`<=:end AND `app_id` IN ('{$app_ids_sql}')\n              GROUP BY `ad_id`";
         $DB = $this->get_read_pdo();
         $state = $DB->prepare($sql);
         $state->execute(array(':start' => $start, ':end' => $end));
         return $state->fetchAll(PDO::FETCH_ASSOC | PDO::FETCH_UNIQUE);
     } else {
         $app_ids_sql = implode(') OR (', $app_ids);
         $params = '{
     "index" : "stat_data",
     "type" : "transfer_stat_app_ad",
     "body" : {
       "query" : {
         "bool": {
           "must": [
             {
               "query_string": {
                 "default_field": "app_id",
                 "query": "(' . $app_ids_sql . ')"
               }
             },
             {
               "range": {
                 "transfer_date": {
                   "gte": "' . $start . '",
                   "lte": "' . $end . '"
                 }
               }
             }
           ]
         }
       },
       "aggs": {
         "all_ad_ids": {
           "terms": {
             "field": "ad_id",
             "size": 100000
           },
           "aggs": {
             "sum_rmb": {
               "sum": {
                 "field": "rmb_total"
               }
             },
             "sum_transfer": {
               "sum": {
                 "field": "transfer_total"
               }
             }
           }
         }
       },
       "size": 0
     }
   }';
         $es_service = new ES();
         $transfer_stat = $es_service->query($params);
         $transfer = array();
         foreach ($transfer_stat['aggregations']['all_ad_ids']['buckets'] as $transfer_ad) {
             $transfer[$transfer_ad['key']]['transfer'] += $transfer_ad['sum_transfer']['value'];
             $transfer[$transfer_ad['key']]['rmb'] += $transfer_ad['sum_rmb']['value'];
         }
         return $transfer;
     }
 }