IndexController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\controllers;
  3. use Yii;
  4. use yii\filters\AccessControl;
  5. use yii\web\Controller;
  6. use yii\web\Response;
  7. use yii\filters\VerbFilter;
  8. use app\lib\GA;
  9. use app\models\ContentPage;
  10. class IndexController extends Controller
  11. {
  12. public function actionIndex(){
  13. echo 111;exit;
  14. }
  15. public function actionContentpage(){
  16. $pages=ContentPage::find()->asArray()->all();
  17. \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  18. return [
  19. 'code' => 200,
  20. 'data'=>$pages,
  21. 'status'=>true
  22. ];
  23. }
  24. public function actionSynsdata(){
  25. $ga=new GA();
  26. $store="supernova";
  27. $contentpages=$ga->contentpages($store);
  28. $i=1;
  29. $limit=20;
  30. $modelKey=[
  31. 'pagePath',
  32. 'store',
  33. 'date',
  34. 'pageviews',
  35. 'uniquePageviews',
  36. 'avgTimeOnPage',
  37. 'entrances',
  38. 'bounceRate',
  39. 'exitRate',
  40. 'pageValue',
  41. 'created_at',
  42. ];
  43. if(!empty($contentpages)){
  44. $list=[];
  45. foreach($contentpages as $k=>$v){
  46. $item=[
  47. $v['pagePath'],
  48. $store,
  49. date('y-m-d',strtotime($v['date'])),
  50. $v['pageviews'],
  51. $v['uniquePageviews'],
  52. $v['avgTimeOnPage'],
  53. $v['entrances'],
  54. $v['bounceRate'],
  55. $v['exitRate'],
  56. $v['pageValue'],
  57. time(),
  58. ];
  59. $list[]=$item;
  60. if($i%$limit==0||$i==count($contentpages)){
  61. \Yii::$app->db->createCommand()->batchInsert(ContentPage::tableName(), $modelKey, $list)->execute();
  62. $list=[];
  63. echo 111111;exit;
  64. }
  65. $i++;
  66. }
  67. }
  68. echo 111111;exit;
  69. }