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('成功'); } } } }