chengwl 4 年之前
父節點
當前提交
c0f89082e3
共有 1 個文件被更改,包括 55 次插入8 次删除
  1. 55 8
      controllers/IndexController.php

+ 55 - 8
controllers/IndexController.php

@@ -59,6 +59,45 @@ class IndexController extends Controller
         '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();
@@ -66,17 +105,25 @@ class IndexController extends Controller
       $request = Yii::$app->request;
       $start_day = $request->get('start', date('Y-m-d'),time()-24*3600);
       $end_day=$start_day;
-      $contentpages=$ga->contentpages($store,$start_day,$end_day);
-      $this->addContentpages($contentpages,$store);
 
-      $data=$ga->trafficsource($store,$start_day,$end_day);
-      $this->addSource($data,$store);
+      $query=ContentPage::find()->where(["store"=>$where,'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"=>$where,'date'=>$start_day]);
+      $count = $query->count();
+      if($count>0){
+        echo $start_day.$store." Trafficsource"."已经执行过,请不要重复执行";
+      }else{
+        $contentpages=$ga->contentpages($store,$start_day,$end_day);
+        $this->addContentpages($contentpages,$store);
+      }
       echo $start_day." 任务完成"."<br/>";
       exit;
-
-
-     
-
     }
     public function addSource($data,$store){
       $i=1;