DefaultController.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace addons\OperatingNote\backend\controllers;
  3. use addons\OperatingNote\common\models\AddonsOperatingNoteComment;
  4. use addons\OperatingNote\common\models\AddonsOperatingNoteContent;
  5. use addons\OperatingNote\common\models\AddonsOperatingNoteStatistics;
  6. use common\enums\StatusEnum;
  7. use common\models\user\User;
  8. use Yii;
  9. /**
  10. * 默认控制器
  11. *
  12. * Class DefaultController
  13. * @package addons\OperatingNote\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. if ($request->isPost) {
  27. $post = Yii::$app->request->post();
  28. // 检查提交的参数
  29. $res = Yii::$app->services->validate->validate($post, [
  30. [['start_time', 'end_time'], 'safe'],
  31. ]);
  32. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  33. $post = AddonsOperatingNoteContent::exceptNullVal($post);
  34. //趋势分析
  35. $statistical_list = AddonsOperatingNoteStatistics::statistics($this->mall_id, isset($post['start_time']) ? $post['start_time'] : '', isset($post['end_time']) ? $post['end_time'] : '');
  36. //数据汇总
  37. $Yesterdaywhere[] = ['=', 'mall_id', $this->mall_id];
  38. $yesterday_data = AddonsOperatingNoteStatistics::getOne($Yesterdaywhere, true);
  39. $yesterday_data = AddonsOperatingNoteStatistics::format($yesterday_data);
  40. //人气排行TOP5
  41. $where[] = ['=', 'mall_id', $this->mall_id];
  42. $where[] = ['>=', 'status', StatusEnum::DISABLED];
  43. $post['limit'] = 5;
  44. $order = 'stars_count desc';
  45. $params = array('where' => $where, 'order' => $order, 'limit' => $post['limit']);
  46. // $start_list = AddonsXhsContent::lists($params, true);
  47. $start_list = [];
  48. if ($start_list) foreach ($start_list as $k => $v) $start_list[$k]['source'] = json_decode($v['source']);
  49. //带货排行TOP5
  50. $order = 'total_amount desc';
  51. $goods_where[] = ['=', 'mall_id', $this->mall_id];
  52. $params = array('where' => $goods_where, 'order' => $order, 'limit' => $post['limit'], 'with' => ['goods']);
  53. // $goods_list = AddonsXhsGoodsStatistics::lists($params, true);
  54. $goods_list = [];
  55. if ($goods_list) foreach ($goods_list as $k => $v) $goods_list[$k]['source'] = json_decode($v['source']);
  56. $this->success('获取成功', compact('start_list', 'goods_list', 'yesterday_data', 'statistical_list'));
  57. }
  58. }
  59. return $this->render($this->action->id);
  60. }
  61. public function actionCommentList()
  62. {
  63. if (\Yii::$app->request->isAjax) {
  64. if (\Yii::$app->request->isGet) {
  65. $params = \Yii::$app->request->get();
  66. $where[] = ['mall_id' => $this->mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]];
  67. !empty($params['user_id']) && $where[] = ['=', 'user_id', $params['user_id']];
  68. if (!empty($params['mobile'])) {
  69. $user_id = User::find()->select('id')->where(['mall_id' => $this->mall_id, 'mobile' => $params['mobile'], 'status' => StatusEnum::ENABLED])->scalar() ?? 0;
  70. $where[] = ['=', 'user_id', $user_id];
  71. }
  72. if (!empty($params['start_at']) && !empty($params['end_at'])) {
  73. $where[] = ['between', 'created_at', strtotime($params['start_at']), strtotime($params['end_at'])];
  74. }
  75. if(!empty($params['content'])){
  76. $where[] = ['like', 'content', $params['content']];
  77. }
  78. $params['where'] = $where;
  79. $params['order'] = 'id desc';
  80. $params['with'] = ['user'];
  81. $comment_list = AddonsOperatingNoteComment::listPage($params);
  82. if($comment_list==false) return $this->error(AddonsOperatingNoteComment::getStaticError());
  83. if (!empty($comment_list['list'])) {
  84. }
  85. return $this->success('success', $comment_list);
  86. }
  87. } else {
  88. return $this->render('comment-list');
  89. }
  90. }
  91. public function actionCommentDel()
  92. {
  93. $request = \Yii::$app->request;
  94. if ($request->isAjax && $request->isPost) {
  95. // 检查提交的参数
  96. $post = $request->post();
  97. $res = \Yii::$app->services->validate->validate($post, [
  98. [['id'], 'required'],
  99. ]);
  100. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  101. $post['mall_id'] = $this->mall_id;
  102. $post['attributes'] = ['status'=>StatusEnum::DELETE];
  103. AddonsOperatingNoteComment::updateData($post);
  104. return $this->success('成功');
  105. }
  106. }
  107. public function actionCommentUpTop()
  108. {
  109. $request = \Yii::$app->request;
  110. if ($request->isAjax && $request->isPost) {
  111. // 检查提交的参数
  112. $post = $request->post();
  113. $res = \Yii::$app->services->validate->validate($post, [
  114. [['id','is_top'], 'required'],
  115. ['is_top', 'integer', 'min' => 0, 'max' => 1],
  116. ]);
  117. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  118. $post['mall_id'] = $this->mall_id;
  119. $post['attributes'] = ['is_top'=>$post['is_top']];
  120. AddonsOperatingNoteComment::updateData($post);
  121. return $this->success('成功');
  122. }
  123. }
  124. public function actionCommentChangeStatus()
  125. {
  126. $request = \Yii::$app->request;
  127. if ($request->isAjax && $request->isPost) {
  128. // 检查提交的参数
  129. $post = $request->post();
  130. $res = \Yii::$app->services->validate->validate($post, [
  131. [['id','status'], 'required'],
  132. ['status', 'integer', 'min' => 0, 'max' => 1],
  133. ]);
  134. if ($res == false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  135. $post['mall_id'] = $this->mall_id;
  136. $post['attributes'] = ['status'=> $post['status']];
  137. AddonsOperatingNoteComment::updateData($post);
  138. return $this->success('成功');
  139. }
  140. }
  141. }