| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 | 
							- <?php
 
- namespace app\controllers;
 
- use Yii;
 
- use yii\filters\AccessControl;
 
- use yii\web\Controller;
 
- use yii\web\Response;
 
- use yii\filters\VerbFilter;
 
- use app\lib\GA;
 
- use app\models\ContentPage;
 
- use app\models\Trafficsource;
 
- use yii\data\Pagination;
 
- class IndexController extends Controller
 
- {
 
-    
 
-   
 
-     public function  actionIndex(){
 
-       echo 111;exit;
 
-     }
 
-     public function actionContentpage(){
 
-       $request = Yii::$app->request;
 
-       \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
 
-       $store = $request->get('store', "supernova");  
 
-       $limit = $request->get('limit', "10");  
 
-       $page = $request->get('page', "1"); 
 
-       
 
-       $page=$page-1>=0?$page-1:0;
 
-       $where=[];
 
-       if(!$store){
 
-         return ['status'=>false,'msg'=>"参数异常"];
 
-       }
 
-       $where['store']=$store;
 
-       $query=ContentPage::find()->where(["store"=>$where]);
 
-       $count = $query->count();
 
-       $pagination = new Pagination(['totalCount' => $count,'pageSize'=>$limit,'page'=>$page]);
 
-       $items = $query->offset($pagination->offset)
 
-           ->limit($pagination->limit)
 
-           ->orderBy([
 
-             'pageviews'=>SORT_DESC,
 
-             'id'=>SORT_DESC
 
-           ])
 
-           ->all();
 
-         foreach($items as $k=>$v){
 
-           $items[$k]['created_at']=date('Y-m-d H:i:s',$v['created_at']);
 
-         }
 
-       $data=[
 
-         'total'=>$count,
 
-         'items'=>$items,
 
-       ];
 
-       
 
-       return [
 
-         'code' => 200,
 
-         'data'=>$data,
 
-         'status'=>true    
 
-       ];
 
-     }
 
-     public function actionSource(){
 
-       $request = Yii::$app->request;
 
-       \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
 
-       $store = $request->get('store', "supernova");  
 
-       $limit = $request->get('limit', "10");  
 
-       $page = $request->get('page', "1"); 
 
-       
 
-       $page=$page-1>=0?$page-1:0;
 
-       $where=[];
 
-       if(!$store){
 
-         return ['status'=>false,'msg'=>"参数异常"];
 
-       }
 
-       $where['store']=$store;
 
-       $query=Trafficsource::find()->where(["store"=>$where]);
 
-       $count = $query->count();
 
-       $pagination = new Pagination(['totalCount' => $count,'pageSize'=>$limit,'page'=>$page]);
 
-       $items = $query->offset($pagination->offset)
 
-           ->limit($pagination->limit)
 
-           ->orderBy([
 
-             'date'=>SORT_DESC,
 
-             'users'=>SORT_DESC
 
-           ])
 
-           ->all();
 
-         foreach($items as $k=>$v){
 
-           $items[$k]['created_at']=date('Y-m-d H:i:s',$v['created_at']);
 
-         }
 
-       $data=[
 
-         'total'=>$count,
 
-         'items'=>$items,
 
-       ];
 
-       
 
-       return [
 
-         'code' => 200,
 
-         'data'=>$data,
 
-         'status'=>true    
 
-       ];
 
-     }
 
-     public function actionSynsdata(){
 
-       $ga=new GA();
 
-       $store="supernova";
 
-       $request = Yii::$app->request;
 
-       $start_day = $request->get('start', date('Y-m-d'),time()-24*3600);
 
-       $end_day=$start_day;
 
-       $query=ContentPage::find()->where(["store"=>$store,'date'=>$start_day]);
 
-       $count = $query->count();
 
-       if($count>0){
 
-         echo $start_day.$store." ContentPage"."已经执行过,请不要重复执行";
 
-       }else{
 
-         $contentpages=$ga->contentpages($store,$start_day,$end_day);
 
-         $this->addContentpages($contentpages,$store);
 
-       }
 
-       $query=Trafficsource::find()->where(["store"=>$store,'date'=>$start_day]);
 
-       $count = $query->count();
 
-       if($count>0){
 
-         echo $start_day.$store." Trafficsource"."已经执行过,请不要重复执行";
 
-       }else{
 
-         $contentpages=$ga->trafficsource($store,$start_day,$end_day);
 
-         $this->addSource($contentpages,$store);
 
-       }
 
-       echo $start_day." 任务完成"."<br/>";
 
-       exit;
 
-     }
 
-     public function addSource($data,$store){
 
-       $i=1;
 
-       $limit=200;
 
-       $modelKey=[
 
-         'date',
 
-         'store',
 
-         'source',
 
-         'channelGrouping',
 
-         'landingPagePath',
 
-         'keyword',
 
-         'socialNetwork',
 
-         'users',
 
-         'newUsers',
 
-         'sessions',
 
-         'bounceRate',
 
-         'pageviewsPerSession',
 
-         'avgSessionDuration',
 
-         'transactionsPerVisit',
 
-         'transactions',
 
-         'transactionRevenue',
 
-         'created_at',
 
-       ];
 
-       if(!empty($data)){
 
-         $list=[];
 
-         foreach($data as $k=>$v){
 
-           $item=[
 
-             date('Y-m-d',strtotime($v['date'])),
 
-             $store,
 
-             $v['source'],
 
-             $v['channelGrouping'],
 
-             $v['landingPagePath']!=="(not set)"?$v["landingPagePath"]:"",
 
-             $v['keyword']!=="(not set)"?$v['keyword']:"",
 
-             $v['socialNetwork']!=="(not set)"?$v['socialNetwork']:"",
 
-             $v['users'],
 
-             $v['newUsers'],
 
-             $v['sessions'],
 
-             $v['bounceRate'],
 
-             $v['pageviewsPerSession'],
 
-             $v['avgSessionDuration'],
 
-             $v['transactionsPerVisit'],
 
-             $v['transactions'],
 
-             $v['transactionRevenue'],
 
-             time(),
 
-           ];
 
-           $list[]=$item;
 
-           if($i%$limit==0||$i==count($data)){
 
-             \Yii::$app->db->createCommand()->batchInsert(Trafficsource::tableName(), $modelKey, $list)->execute();
 
-             $list=[];
 
-             echo  "addSource 任务完成".$i."个"."<br/>";
 
-           }
 
-           $i++;
 
-         }
 
-         echo "addSource 任务全部完成"."<br/>";
 
-       }
 
-     }
 
-     public function actionTest(){
 
-       $ga=new GA();
 
-       $store="supernova";
 
-       $request = Yii::$app->request;
 
-       $start_day=$request->get('start', date('Y-m-d',time()-3600*24*7));
 
-       $end_day = $request->get('end', date('Y-m-d'));
 
-       //销量
 
-       $sells=$ga->visitors_geo($store,$start_day,$end_day);
 
-       $sellSku=$ga->productSku($store,$start_day,$end_day);
 
-       $visitors=$ga->visitors_type($store,$start_day,$end_day);
 
-       
 
-       echo "<pre>";
 
-       print_r($visitors);exit;
 
-     }
 
-     public function addContentpages($contentpages,$store){
 
-         $i=1;
 
-         $limit=20;
 
-         $modelKey=[
 
-           'pagePath',
 
-           'store',
 
-           'date',
 
-           'pageviews',
 
-           'uniquePageviews',
 
-           'avgTimeOnPage',
 
-           'entrances',
 
-           'bounceRate',
 
-           'exitRate',
 
-           'pageValue',
 
-           'created_at',
 
-         ];
 
-         if(!empty($contentpages)){
 
-           $list=[];
 
-           foreach($contentpages as $k=>$v){
 
-             $item=[
 
-               $v['pagePath'],
 
-               $store,
 
-               date('Y-m-d',strtotime($v['date'])),
 
-               $v['pageviews'],
 
-               $v['uniquePageviews'],
 
-               $v['avgTimeOnPage'],
 
-               $v['entrances'],
 
-               $v['bounceRate'],
 
-               $v['exitRate'],
 
-               $v['pageValue'],
 
-               time(),
 
-             ];
 
-             $list[]=$item;
 
-             if($i%$limit==0||$i==count($contentpages)){
 
-               \Yii::$app->db->createCommand()->batchInsert(ContentPage::tableName(), $modelKey, $list)->execute();
 
-               $list=[];
 
-               echo "addContentpages 任务完成".$i."个"."<br/>";
 
-             }
 
-             $i++;
 
-           }
 
-           echo "addContentpages 任务全部完成"."<br/>";
 
-         }
 
-     }
 
-   }
 
-     
 
 
  |