| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- namespace addons\Pk\backend\controllers;
- use addons\Pk\common\enums\PkEnum;
- use addons\Pk\common\models\PkActivity;
- use addons\Pk\common\models\PkActivityStatistic;
- use addons\Pk\common\models\PkDateStatistic;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\Pk\backend\controllers
- */
- class DefaultController extends BaseController
- {
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- //提交内容
- if ($request->isGet) {
- $params = Yii::$app->request->get();
- $scene = $params['scene'];
- $params['mall_id'] = $this->mall_id;
- $personal_activity_list = [];
- $team_activity_list = [];
- if ($scene == 'all') {
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['>=', 'status', StatusEnum::DISABLED];
- $p_list = array('where' => $where);
- $personal_activity_list = PkActivity::lists($p_list, true);
- }
- $statistics = PkDateStatistic::getPkPanelData($params);
- return $this->success('success', compact('statistics', 'personal_activity_list'));
- }
- }
- return $this->render($this->action->id);
- }
- // 某时间段,个人PK概况
- public function actionPersonalPkStatistics()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- $mall_id = $this->mall_id;
- $start_time = $request->get('start_time', strtotime('-30 days'));
- $end_time = $request->get('end_time', time());
- $icon_root = Yii::getAlias('@attachurl') . '/static/addons/Pk/';
- $list = [
- [
- 'name' => 'PK活动数量',
- 'icon' => $icon_root . 'PKhuodongshuliang.png',
- 'number' => PkDateStatistic::pkAcitivityNumCount($mall_id, $start_time, $end_time, 'activity_num')
- ],
- [
- 'name' => '拉新获客',
- 'icon' => $icon_root . 'laxin.png',
- 'number' => PkDateStatistic::pkAcitivityNumCount($mall_id, $start_time, $end_time, 'new_user_num')
- ],
- [
- 'name' => 'PK业绩(元)',
- 'icon' => $icon_root . 'xiaoshouyeji.png',
- 'number' => PkDateStatistic::pkAcitivityNumCount($mall_id, $start_time, $end_time, 'order_money_num')
- ],
- [
- 'name' => 'PK参与人数',
- 'icon' => $icon_root . 'canyu.png',
- 'number' => PkDateStatistic::pkAcitivityNumCount($mall_id, $start_time, $end_time, 'join_user_num')
- ],
- // [
- // 'name' => '分享次数',
- // 'icon' => $icon_root . 'fenxiang.png',
- // 'number' => PkDateStatistic::pkAcitivityNumCount($mall_id, $start_time, $end_time, 'share_num')
- // ],
- [
- 'name' => '分享访问人数',
- 'icon' => $icon_root . 'fenxiangfangwen.png',
- 'number' => PkDateStatistic::pkAcitivityNumCount($mall_id, $start_time, $end_time, 'share_visit')
- ]
- ];
- return $this->success('获取成功', compact('list'));
- }
- }
- // 某时间段,每天 拉新、业绩 的PK
- public function actionPersonalPkDayStatistics()
- {
- $request = Yii::$app->request;
- $mall_id = $this->mall_id;
- if ($request->isAjax) {
- // 统计的字段
- $valid_field = [
- 'new_user_num', //拉新
- 'order_money_num', //业绩
- ];
- $count_field = $request->get('count_field', 'new_user_num');
- if (!in_array($count_field, $valid_field)) {
- return $this->success('获取成功', ['keys' => [], 'values' => []]);
- }
- // 时间段
- $start_time = $request->get('start_time', strtotime('-30 days'));
- $end_time = $request->get('end_time', time());
- $statistic = PkDateStatistic::pkActivityNumCountList($mall_id, $start_time, $end_time, $count_field);
- return $this->success('获取成功', $statistic);
- }
- }
- // 获取活动列表
- public function actionActivityList()
- {
- $where = [];
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['>=', 'status', StatusEnum::DISABLED];
- $where['limit'] = 100;
- $orderBy = ['id' => SORT_DESC];
- $list = PkActivity::lists(['where' => $where, 'order' => $orderBy], true);
- return $this->success('获取成功', compact('list'));
- }
- /**
- * top10 排行
- */
- public function actionPersonalPkRanking()
- {
- $request = Yii::$app->request;
- $mall_id = $this->mall_id;
- $activity_id = $request->get('activity_id', 0);
- $topn = $request->get('topn', 10);
- $ranking = PkDateStatistic::getPerformanceRank($mall_id, $activity_id, $topn);
- return $this->success('获取成功', $ranking);
- }
- /**
- * 当前活动
- */
- public function actionCurrentPkActivity()
- {
- $activity = PkActivity::getCurrentPkActivity($this->mall_id);
- return $this->success('获取成功', compact('activity'));
- }
- }
|