| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- namespace addons\OperatingNote\backend\controllers;
- use addons\OperatingNote\common\models\AddonsOperatingNoteComment;
- use addons\OperatingNote\common\models\AddonsOperatingNoteContent;
- use addons\OperatingNote\common\models\AddonsOperatingNoteStatistics;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Yii;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\OperatingNote\backend\controllers
- */
- class DefaultController extends BaseController
- {
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- if ($request->isPost) {
- $post = Yii::$app->request->post();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($post, [
- [['start_time', 'end_time'], 'safe'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $post = AddonsOperatingNoteContent::exceptNullVal($post);
- //趋势分析
- $statistical_list = AddonsOperatingNoteStatistics::statistics($this->mall_id, isset($post['start_time']) ? $post['start_time'] : '', isset($post['end_time']) ? $post['end_time'] : '');
- //数据汇总
- $Yesterdaywhere[] = ['=', 'mall_id', $this->mall_id];
- $yesterday_data = AddonsOperatingNoteStatistics::getOne($Yesterdaywhere, true);
- $yesterday_data = AddonsOperatingNoteStatistics::format($yesterday_data);
- //人气排行TOP5
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['>=', 'status', StatusEnum::DISABLED];
- $post['limit'] = 5;
- $order = 'stars_count desc';
- $params = array('where' => $where, 'order' => $order, 'limit' => $post['limit']);
- // $start_list = AddonsXhsContent::lists($params, true);
- $start_list = [];
- if ($start_list) foreach ($start_list as $k => $v) $start_list[$k]['source'] = json_decode($v['source']);
- //带货排行TOP5
- $order = 'total_amount desc';
- $goods_where[] = ['=', 'mall_id', $this->mall_id];
- $params = array('where' => $goods_where, 'order' => $order, 'limit' => $post['limit'], 'with' => ['goods']);
- // $goods_list = AddonsXhsGoodsStatistics::lists($params, true);
- $goods_list = [];
- if ($goods_list) foreach ($goods_list as $k => $v) $goods_list[$k]['source'] = json_decode($v['source']);
- $this->success('获取成功', compact('start_list', 'goods_list', 'yesterday_data', 'statistical_list'));
- }
- }
- return $this->render($this->action->id);
- }
- public function actionCommentList()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $params = \Yii::$app->request->get();
- $where[] = ['mall_id' => $this->mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]];
- !empty($params['user_id']) && $where[] = ['=', 'user_id', $params['user_id']];
- if (!empty($params['mobile'])) {
- $user_id = User::find()->select('id')->where(['mall_id' => $this->mall_id, 'mobile' => $params['mobile'], 'status' => StatusEnum::ENABLED])->scalar() ?? 0;
- $where[] = ['=', 'user_id', $user_id];
- }
- if (!empty($params['start_at']) && !empty($params['end_at'])) {
- $where[] = ['between', 'created_at', strtotime($params['start_at']), strtotime($params['end_at'])];
- }
- if(!empty($params['content'])){
- $where[] = ['like', 'content', $params['content']];
- }
- $params['where'] = $where;
- $params['order'] = 'id desc';
- $params['with'] = ['user'];
- $comment_list = AddonsOperatingNoteComment::listPage($params);
- if($comment_list==false) return $this->error(AddonsOperatingNoteComment::getStaticError());
- if (!empty($comment_list['list'])) {
- }
- return $this->success('success', $comment_list);
- }
- } else {
- return $this->render('comment-list');
- }
- }
- public function actionCommentDel()
- {
- $request = \Yii::$app->request;
- if ($request->isAjax && $request->isPost) {
- // 检查提交的参数
- $post = $request->post();
- $res = \Yii::$app->services->validate->validate($post, [
- [['id'], 'required'],
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $post['mall_id'] = $this->mall_id;
- $post['attributes'] = ['status'=>StatusEnum::DELETE];
- AddonsOperatingNoteComment::updateData($post);
- return $this->success('成功');
- }
- }
- public function actionCommentUpTop()
- {
- $request = \Yii::$app->request;
- if ($request->isAjax && $request->isPost) {
- // 检查提交的参数
- $post = $request->post();
- $res = \Yii::$app->services->validate->validate($post, [
- [['id','is_top'], 'required'],
- ['is_top', 'integer', 'min' => 0, 'max' => 1],
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $post['mall_id'] = $this->mall_id;
- $post['attributes'] = ['is_top'=>$post['is_top']];
- AddonsOperatingNoteComment::updateData($post);
- return $this->success('成功');
- }
- }
- public function actionCommentChangeStatus()
- {
- $request = \Yii::$app->request;
- if ($request->isAjax && $request->isPost) {
- // 检查提交的参数
- $post = $request->post();
- $res = \Yii::$app->services->validate->validate($post, [
- [['id','status'], 'required'],
- ['status', 'integer', 'min' => 0, 'max' => 1],
- ]);
- if ($res == false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $post['mall_id'] = $this->mall_id;
- $post['attributes'] = ['status'=> $post['status']];
- AddonsOperatingNoteComment::updateData($post);
- return $this->success('成功');
- }
- }
- }
|