| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- <?php
- /**
- * Created by PhpStorm.
- * User: wniu
- * Date: 2022/2/17
- * Time: 2:42 下午
- */
- namespace addons\OperatingNote\backend\controllers;
- use addons\OperatingNote\common\enums\NoteEnum;
- use addons\OperatingNote\common\models\AddonsOperatingNoteCate;
- use addons\OperatingNote\common\models\AddonsOperatingNoteComment;
- use addons\OperatingNote\common\models\AddonsOperatingNoteContent;
- use common\enums\StatusEnum;
- use common\models\goods\Goods;
- use common\models\user\User;
- use common\models\user\UserLevel;
- use Yii;
- use yii\db\Exception;
- class NotesController extends BaseController
- {
- public $enableCsrfValidation = false;
- 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, [
- [['id'], 'integer'],
- [['title', 'note_type', 'is_release', 'cate_id', 'mobile', 'user_name', 'user_id', 'date_start', 'date_end', 'check_status'], 'safe'],
- [['limit'], 'default', 'value' => '15'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $post = AddonsOperatingNoteContent::exceptNullVal($post);
- // 根据搜索手机号查询用户id
- if (isset($post['mobile']) && !empty($post['mobile'])) {
- $user_ids = User::find()->select("id")->where(['mall_id' => $this->mall_id])->andWhere(['like', 'mobile', $post['mobile'] . '%', false])->asArray()->column();
- if (empty($user_ids)) $this->success('查无此用户');
- $where[] = ['in', 'user_id', $user_ids];
- }
- // 根据搜索会员昵称查询用户id
- if (isset($post['user_name']) && !empty($post['user_name'])) {
- $user_ids = User::find()->select("id")->where(['mall_id' => $this->mall_id])->andWhere(['like', 'nickname', $post['user_name'] . '%', false])->asArray()->column();
- $where[] = ['in', 'user_id', $user_ids];
- }
- if (isset($post['user_id']) && !empty($post['user_id'])) {
- $where[] = ['=', 'user_id', $post['user_id']];
- }
- if (isset($post['cate_id']) && !empty($post['cate_id'])) {
- $where[] = ['=', 'cate_id', $post['cate_id']];
- }
- if (isset($post['date_start']) && isset($post['date_end'])) {
- $where[] = ['between', 'created_at', strtotime($post['date_start']), strtotime($post['date_end'])];
- }
- if (isset($post['title']) && !empty($post['title'])) {
- $where[] = ['like', 'title', $post['title']];
- }
- if (isset($post['note_type']) && ($post['note_type'] > 0)) {
- $where[] = ['=', 'note_type', $post['note_type']];
- }
- if (isset($post['is_release']) && ($post['is_release'] >= 0)) {
- $where[] = ['=', 'is_release', $post['is_release']];
- }
- if (isset($post['check_status'])) {
- $where[] = ['=', 'check_status', $post['check_status']];
- } else {
- $where[] = ['=', 'check_status', StatusEnum::ENABLED];
- }
- $where[] = ['=', 'mall_id', $this->mall_id];
- // if (in_array($post['check_status'], [StatusEnum::ENABLED, StatusEnum::DISABLED, NoteEnum::STATUS_TWO])) $where[] = ['=', 'check_status', $post['check_status']]; else $where[] = ['=', 'check_status', StatusEnum::ENABLED];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $order = 'id desc';
- $params = array('where' => $where, 'order' => $order, 'limit' => $post['limit'], 'with' => ['user', 'goods']);
- $list = AddonsOperatingNoteContent::listPage($params, false, true);
- $cate_params = [
- 'where' => [
- ['mall_id' => $this->mall_id],
- ['status' => StatusEnum::ENABLED]
- ],
- 'select' => 'id,name',
- 'index' => 'id'
- ];
- $cate = AddonsOperatingNoteCate::lists($cate_params);
- if ($list['list']) {
- $h5_domain = \Yii::$app->services->setting->mall->get($this->mall_id, 'basic.web_url');
- if (empty($h5_domain)) {
- $h5_domain = \Yii::$app->request->hostInfo;
- } else {
- $h5_domain = substr($h5_domain, 0, strpos($h5_domain, '?'));
- }
- $list['domain'] = $h5_domain . 'plugins/operating_note/detail?sign=' . $this->mall['mall_sign'];
- foreach ($list['list'] as $k => &$v) {
- if ($v['user_id'] == 0) {
- $v['user']['avatar_url'] = '';
- $v['user']['nickname'] = '后台发布';
- }
- if (isset($cate[$v['cate_id']])) {
- $list['list'][$k]['cate_name'] = $cate[$v['cate_id']]['name'];
- }
- if ($v['note_type'] == 1) {
- $v['note_type_name'] = '文章';
- $v['share_url_base'] = $h5_domain . 'plugins/operating_note/detail?sign=' . $this->mall['mall_sign'] . '&id=';
- } elseif ($v['note_type'] == 2) {
- $v['note_type_name'] = '视频';
- $v['share_url_base'] = $h5_domain . 'plugins/operating_note/video/index?sign=' . $this->mall['mall_sign'] . '&content_id=';
- } else {
- $v['note_type_name'] = '广告';
- $v['share_url_base'] = $h5_domain . 'plugins/operating_note/detail?sign=' . $this->mall['mall_sign'] . '&id=';
- }
- $list['list'][$k]['average_time'] = 1;
- }
- }
- $list['cate'] = $cate;
- $this->success('获取成功', $list);
- }
- }
- return $this->render($this->action->id);
- }
- public function actionCheck()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- //提交内容
- if ($request->isPost) {
- $params = Yii::$app->request->post();
- $params['check_time'] = time();
- if ($params['check_status'] == 1) {
- $params['is_release'] = 1;
- }
- AddonsOperatingNoteContent::setData($params, 'update');
- return $this->success('操作成功');
- }
- }
- return $this->render($this->action->id);
- }
- public function actionEdit()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- //提交内容
- if ($request->isPost) {
- $params = Yii::$app->request->post();
- if (empty($params['id'])) {
- $scenarios = 'create';
- $params['mall_id'] = $this->mall_id;
- } else {
- $scenarios = 'update';
- }
- if (is_array($params['cover_img'])) {
- $params['cover_img'] = json_encode($params['cover_img']);
- }
- AddonsOperatingNoteContent::setData($params, $scenarios);
- return $this->success('操作成功');
- } else {
- $params = Yii::$app->request->get();
- $detail = [];
- if (isset($params['id'])) {
- $detail = AddonsOperatingNoteContent::getOne([['mall_id' => $this->mall_id, 'id' => $params['id']]], true);
- if ($detail['goods_id'] > 0) {
- $goods_info = Goods::getOne([['id' => $detail['goods_id']]], true, '', '', 'goods_name,cover_pic,price');
- $detail['goods_name'] = $goods_info['goods_name'];
- $detail['cover_pic'] = $goods_info['cover_pic'];
- $detail['price'] = $goods_info['price'];
- }
- }
- $where = ['where' => [['=', 'mall_id', $this->mall_id], ['=', 'status', StatusEnum::ENABLED]], 'select' => 'id,name', 'order' => 'id desc'];
- $cate_list = AddonsOperatingNoteCate::lists($where);
- $user_level_list = UserLevel::getUserLevel([['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]], [], 1, 'level,name,id');
- $this->success('获取成功', compact('user_level_list', 'cate_list', 'detail'));
- }
- }
- return $this->render($this->action->id);
- }
- /**
- * 获取公众号文章标题&内容
- * User: wniu
- * Date: 2022/2/26
- * Time: 3:09 下午
- *
- */
- public function actionUrlContent()
- {
- $request = Yii::$app->request;
- //提交内容
- if ($request->isPost) {
- $params = Yii::$app->request->post();
- // $params['url'] = 'https://mp.weixin.qq.com/s/wx7vIx5VVlNNkxvD5QH3ug';
- $data = AddonsOperatingNoteContent::getUrlContent($params['url']);
- return $this->success('获取成功', $data);
- }
- }
- /**
- * 后台发布评论
- * User: wniu
- * Date: 2022/2/26
- * Time: 3:09 下午
- *
- * @throws Exception
- */
- public function actionAdminReply()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- if ($request->isPost) {
- $params = Yii::$app->request->post();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($params, [
- [['note_content_id'], 'integer'],
- [['content', 'reply_id'], 'safe'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // $params['note_content_id'] = 1;
- // $params['content'] = '后台评论';
- $params['mall_id'] = $this->mall_id;
- $params['user_id'] = 0;
- AddonsOperatingNoteComment::setData($params);
- return $this->success('评论成功');
- }
- }
- }
- /**
- * 后台搜索评论
- * User: wniu
- * Date: 2022/2/26
- * Time: 3:18 下午
- *
- */
- public function actionSearchComment()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- if ($request->isPost) {
- $post = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($post, [
- [['note_content_id'], 'integer'],
- [['keyword'], 'safe'],
- [['limit'], 'default', 'value' => '15'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $post = AddonsOperatingNoteContent::exceptNullVal($post);
- if (!empty($post['keyword'])) {
- $user_list = User::find()->where(['or',
- ['like', 'id', $post['keyword']],
- ['like', 'mobile', $post['keyword']],
- ['like', 'nickname', $post['keyword']]])->select('id')->asArray()->all();
- $user_id_arr = array_column($user_list, 'id');
- $where[] = ['user_id' => $user_id_arr];
- }
- $where[] = ['=', 'note_content_id', $post['note_content_id']];
- $where[] = ['=', 'level', NoteEnum::STATUS_ONE];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $order = 'is_top desc,id desc';
- $params = array('where' => $where, 'order' => $order, 'limit' => $post['limit'], 'with' => ['user']);
- $list = AddonsOperatingNoteComment::listPage($params, false, true);
- if ($list['list']) {
- $ids = array_column($list['list'], 'id');
- $reply = AddonsOperatingNoteComment::lists(['where' => [['in', 'reply_id', $ids], ['status' => StatusEnum::ENABLED]], 'order' => 'created_at desc', 'group' => 'reply_id', 'select' => 'user_id,reply_id,content,created_at,count(reply_id) as count']);
- if ($reply) {
- foreach ($list['list'] as $k => &$v) {
- foreach ($reply as $item => $value) {
- if ($v['id'] == $value['reply_id']) {
- $v['reply'] = $value;
- }
- }
- }
- }
- }
- return $this->success('获取成功', $list);
- }
- }
- }
- public function actionGetReply()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- if ($request->isGet) {
- $get = Yii::$app->request->get();
- $res = Yii::$app->services->validate->validate($get, [
- [['reply_id', 'note_content_id'], 'integer'],
- // [['limit'], 'default', 'value' => '15'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $get = AddonsOperatingNoteContent::exceptNullVal($get);
- $where[] = ['=', 'note_content_id', $get['note_content_id']];
- $where[] = ['=', 'reply_id', $get['reply_id']];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $order = 'is_top desc';
- $params = array('where' => $where, 'order' => $order, 'with' => ['user']);
- $list = AddonsOperatingNoteComment::listPage($params, false, true);
- return $this->success('获取成功', $list);
- }
- }
- }
- public function actionCommentEdit()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- if ($request->isPost) {
- $post = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($post, [
- [['note_comment_id', 'type'], 'integer'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- AddonsOperatingNoteComment::editComment($post);
- return $this->success('成功');
- }
- }
- }
- }
|