|
@@ -9,6 +9,7 @@ use yii\web\Response;
|
|
|
use yii\filters\VerbFilter;
|
|
|
use app\lib\GA;
|
|
|
use app\models\ContentPage;
|
|
|
+use yii\data\Pagination;
|
|
|
|
|
|
class IndexController extends Controller
|
|
|
{
|
|
@@ -19,11 +20,41 @@ class IndexController extends Controller
|
|
|
echo 111;exit;
|
|
|
}
|
|
|
public function actionContentpage(){
|
|
|
- $pages=ContentPage::find()->asArray()->all();
|
|
|
+ $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'=>$pages,
|
|
|
+ 'data'=>$data,
|
|
|
'status'=>true
|
|
|
];
|
|
|
}
|
|
@@ -31,51 +62,56 @@ class IndexController extends Controller
|
|
|
public function actionSynsdata(){
|
|
|
$ga=new GA();
|
|
|
$store="supernova";
|
|
|
- $contentpages=$ga->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 111111;exit;
|
|
|
+ $data=$ga->trafficsource($store);
|
|
|
+ // $contentpages=$ga->contentpages($store);
|
|
|
+ // $this->addContentpages($contentpages,$store);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ 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=[];
|
|
|
+ }
|
|
|
+ $i++;
|
|
|
}
|
|
|
- $i++;
|
|
|
}
|
|
|
- }
|
|
|
- echo 111111;exit;
|
|
|
-
|
|
|
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|