DefaultController.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. namespace addons\Pk\backend\controllers;
  3. use addons\Pk\common\enums\PkEnum;
  4. use addons\Pk\common\models\PkActivity;
  5. use addons\Pk\common\models\PkActivityStatistic;
  6. use addons\Pk\common\models\PkDateStatistic;
  7. use common\enums\StatusEnum;
  8. use Yii;
  9. /**
  10. * 默认控制器
  11. *
  12. * Class DefaultController
  13. * @package addons\Pk\backend\controllers
  14. */
  15. class DefaultController extends BaseController
  16. {
  17. /**
  18. * 首页
  19. *
  20. * @return string
  21. */
  22. public function actionIndex()
  23. {
  24. $request = Yii::$app->request;
  25. if ($request->isAjax) {
  26. //提交内容
  27. if ($request->isGet) {
  28. $params = Yii::$app->request->get();
  29. $scene = $params['scene'];
  30. $params['mall_id'] = $this->mall_id;
  31. $personal_activity_list = [];
  32. $team_activity_list = [];
  33. if ($scene == 'all') {
  34. $where[] = ['=', 'mall_id', $this->mall_id];
  35. $where[] = ['>=', 'status', StatusEnum::DISABLED];
  36. $p_list = array('where' => $where);
  37. $personal_activity_list = PkActivity::lists($p_list, true);
  38. }
  39. $statistics = PkDateStatistic::getPkPanelData($params);
  40. return $this->success('success', compact('statistics', 'personal_activity_list'));
  41. }
  42. }
  43. return $this->render($this->action->id);
  44. }
  45. // 某时间段,个人PK概况
  46. public function actionPersonalPkStatistics()
  47. {
  48. $request = Yii::$app->request;
  49. if ($request->isAjax) {
  50. $mall_id = $this->mall_id;
  51. $start_time = $request->get('start_time', strtotime('-30 days'));
  52. $end_time = $request->get('end_time', time());
  53. $icon_root = Yii::getAlias('@attachurl') . '/static/addons/Pk/';
  54. $list = [
  55. [
  56. 'name' => 'PK活动数量',
  57. 'icon' => $icon_root . 'PKhuodongshuliang.png',
  58. 'number' => PkDateStatistic::pkAcitivityNumCount($mall_id, $start_time, $end_time, 'activity_num')
  59. ],
  60. [
  61. 'name' => '拉新获客',
  62. 'icon' => $icon_root . 'laxin.png',
  63. 'number' => PkDateStatistic::pkAcitivityNumCount($mall_id, $start_time, $end_time, 'new_user_num')
  64. ],
  65. [
  66. 'name' => 'PK业绩(元)',
  67. 'icon' => $icon_root . 'xiaoshouyeji.png',
  68. 'number' => PkDateStatistic::pkAcitivityNumCount($mall_id, $start_time, $end_time, 'order_money_num')
  69. ],
  70. [
  71. 'name' => 'PK参与人数',
  72. 'icon' => $icon_root . 'canyu.png',
  73. 'number' => PkDateStatistic::pkAcitivityNumCount($mall_id, $start_time, $end_time, 'join_user_num')
  74. ],
  75. // [
  76. // 'name' => '分享次数',
  77. // 'icon' => $icon_root . 'fenxiang.png',
  78. // 'number' => PkDateStatistic::pkAcitivityNumCount($mall_id, $start_time, $end_time, 'share_num')
  79. // ],
  80. [
  81. 'name' => '分享访问人数',
  82. 'icon' => $icon_root . 'fenxiangfangwen.png',
  83. 'number' => PkDateStatistic::pkAcitivityNumCount($mall_id, $start_time, $end_time, 'share_visit')
  84. ]
  85. ];
  86. return $this->success('获取成功', compact('list'));
  87. }
  88. }
  89. // 某时间段,每天 拉新、业绩 的PK
  90. public function actionPersonalPkDayStatistics()
  91. {
  92. $request = Yii::$app->request;
  93. $mall_id = $this->mall_id;
  94. if ($request->isAjax) {
  95. // 统计的字段
  96. $valid_field = [
  97. 'new_user_num', //拉新
  98. 'order_money_num', //业绩
  99. ];
  100. $count_field = $request->get('count_field', 'new_user_num');
  101. if (!in_array($count_field, $valid_field)) {
  102. return $this->success('获取成功', ['keys' => [], 'values' => []]);
  103. }
  104. // 时间段
  105. $start_time = $request->get('start_time', strtotime('-30 days'));
  106. $end_time = $request->get('end_time', time());
  107. $statistic = PkDateStatistic::pkActivityNumCountList($mall_id, $start_time, $end_time, $count_field);
  108. return $this->success('获取成功', $statistic);
  109. }
  110. }
  111. // 获取活动列表
  112. public function actionActivityList()
  113. {
  114. $where = [];
  115. $where[] = ['=', 'mall_id', $this->mall_id];
  116. $where[] = ['>=', 'status', StatusEnum::DISABLED];
  117. $where['limit'] = 100;
  118. $orderBy = ['id' => SORT_DESC];
  119. $list = PkActivity::lists(['where' => $where, 'order' => $orderBy], true);
  120. return $this->success('获取成功', compact('list'));
  121. }
  122. /**
  123. * top10 排行
  124. */
  125. public function actionPersonalPkRanking()
  126. {
  127. $request = Yii::$app->request;
  128. $mall_id = $this->mall_id;
  129. $activity_id = $request->get('activity_id', 0);
  130. $topn = $request->get('topn', 10);
  131. $ranking = PkDateStatistic::getPerformanceRank($mall_id, $activity_id, $topn);
  132. return $this->success('获取成功', $ranking);
  133. }
  134. /**
  135. * 当前活动
  136. */
  137. public function actionCurrentPkActivity()
  138. {
  139. $activity = PkActivity::getCurrentPkActivity($this->mall_id);
  140. return $this->success('获取成功', compact('activity'));
  141. }
  142. }