user_id ? 1 : 0; $data['avatar_url'] = $this->user['avatar_url'] ?? ''; $ad_list = AddonsOperatingNoteAd::lists([ 'where' => [ ['mall_id' => $this->mall_id], ['status' => StatusEnum::ENABLED], ], 'order' => 'sort desc', 'select' => 'id,title,img,jump_href' ]); $data['ad_list'] = $ad_list ?? []; $cate_list = AddonsOperatingNoteCate::lists([ 'order' => 'sort desc, id desc', 'where' => [ ['mall_id' => $this->mall_id], ['status' => StatusEnum::ENABLED] ], 'select' => 'id,name', ]); $data['cate_list'] = $cate_list ?? []; return $this->success('操作成功', $data); } /** * @desc:文章列表 * @Author: hua * @Date: 2022/2/22 * @Time: 14:26 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionArticleList() { $params = \Yii::$app->request->get(); $params['where'][] = ['mall_id' => $this->mall_id]; $params['where'][] = ['check_status' => 1]; $params['where'][] = ['is_release' => 1]; $params['where'][] = ['status' => StatusEnum::ENABLED]; if (!empty($params['keyword'])) $params['where'][] = ['like', 'title', '%' . $params['keyword'] . '%', false]; if (!empty($params['cate_id'])) $params['where'][] = ['cate_id' => $params['cate_id']]; if (!empty($params['note_type'])) $params['where'][] = ['note_type' => $params['note_type']]; if (!empty($params['id'])) $params['where'][] = ['!=', 'id', $params['id']]; $top = []; if (isset($params['page']) && $params['page'] == 1 && isset($params['id'])) { $top = AddonsOperatingNoteContent::getOne([['id' => $params['id']]], true, ['user', 'goods']); } $params['with'] = ['user', 'goods']; $params['order'] = 'is_top desc,sort desc,created_at desc'; $list = AddonsOperatingNoteContent::listPage($params, false, true); if ($top) { array_unshift($list['list'], $top); } $like = []; if ($list['list']) { $ids = array_column($list['list'], 'id'); $user_ids = array_unique(array_diff(array_column($list['list'], 'user_id'), [0])); $like = AddonsOperatingNoteUserLike::lists(['where' => [['in', 'note_content_id', $ids], ['=', 'user_id', $this->user_id], ['=', 'is_like', 1]], 'index' => 'note_content_id', 'select' => 'id,user_id,is_like,note_content_id']); $buy_list = AddonsOperatingNoteBuy::lists(['where' => [['in', 'note_id', $ids], ['=', 'user_id', $this->user_id], ['=', 'is_pay', NoteEnum::STATUS_ONE]], 'index' => 'note_id']); $follow_list = []; if ($user_ids) { $follow['where'][] = ['=', 'status', StatusEnum::ENABLED]; $follow['where'][] = ['=', 'user_id', $this->user_id]; $follow['where'][] = ['in', 'follow_id', $user_ids]; $follow['index'][] = 'follow_id'; $follow_lists = UserFollow::listPage($follow); $follow_list = $follow_lists['list']; } $view_record_count = AddonsOperatingNoteRewardRecord::lists(['where' => [['=', 'user_id', $this->user_id], ['=', 'reward_source', NoteEnum::STATUS_ONE], ['in', 'note_content_id', $ids], ['=', 'status', StatusEnum::ENABLED]], 'select' => 'note_content_id,status,count(id) as num', 'group' => 'note_content_id', 'index' => 'note_content_id']); $share_record_count = AddonsOperatingNoteRewardRecord::lists(['where' => [['=', 'user_id', $this->user_id], ['=', 'reward_source', NoteEnum::STATUS_TWO], ['in', 'note_content_id', $ids], ['=', 'status', StatusEnum::ENABLED]], 'select' => 'note_content_id,status,count(id) as num', 'group' => 'note_content_id', 'index' => 'note_content_id']); foreach ($list['list'] as $k => &$v) { $v['views_num'] = $v['views_num'] + $v['virtual_views_num']; $v['likes_num'] = $v['likes_num'] + $v['virtual_likes_num']; $v['is_like'] = 0; $v['can_ready'] = false; $v['view_record_count'] = 0; $v['share_record_count'] = 0; $v['is_follow'] = 0; if (isset($follow_list[$v['user_id']])) { $v['is_follow'] = 1; } if (isset($view_record_count[$v['id']])) { $v['view_record_count'] = $view_record_count[$v['id']]['num']; } if (isset($share_record_count[$v['id']])) { $v['share_record_count'] = $share_record_count[$v['id']]['num']; } if (isset($like[$v['id']])) { $v['is_like'] = 1; } if ($this->user_id == $v['user_id']) { $v['can_ready'] = true; } else { if ($v['note_type'] != NoteEnum::STATUS_THREE) { if ($v['view_limit'] == NoteEnum::STATUS_ZERO) { if ($this->user_id == $v['user_id'] && $v['user_id'] > 0) { $v['can_ready'] = true; } else { if ($v['view_limit_content'] == 'all') { $v['can_ready'] = true; } else { $view_limit_content = \Qiniu\json_decode($v['view_limit_content']); if (in_array($this->user['level'], $view_limit_content)) { $v['can_ready'] = true; } } } } else { if (isset($buy_list[$v['id']])) { $v['can_ready'] = true; } } } } } } return $this->success('操作成功', $list); } /** * @desc:发布 * @Author: hua * @Date: 2022/2/22 * @Time: 14:09 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void * @throws \yii\db\Exception */ public function actionRelease() { $params = \Yii::$app->request->post(); $res = \Yii::$app->services->validate->validate($params, [ [['title', 'cate_id'], 'required'], [['title'], 'string', 'max' => 30], [['goods_id', 'source','cover_img', 'content_href', 'id', 'cover_type', 'main_text', 'content_type'], 'safe'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage() == 'Title只能包含至多30个字符。' ? '标题最多只能30个字符' : \Yii::$app->services->validate->getErrorMessage()); $params['mall_id'] = $this->mall_id; $params['user_id'] = $this->user_id; if(!empty($params['main_text'])) $params['content'] = $params['main_text']; if(!empty($params['content_type'])) $params['note_type'] = $params['content_type']; if(!empty($params['source'])){ $params['content_href'] = []; if($params['content_type']==1){ if(!empty($params['source']['source'])){ $params['content_href'] = $params['source']['source']; //$params['cover_img'] =$params['source']['source']; } $params['content_href'] = json_encode( $params['content_href']); } if($params['content_type']==2){ //if(!empty($params['source']['cover']))$params['cover_img'] =[$params['source']['cover']]; if(!empty($params['source']['source'])) $params['content_href'] = $params['source']['source']; } } if (!isset($params['id']) && !isset($params['cover_type'])) { return $this->error('请选择封面图类型'); } if (isset($params['cover_type'])) { $cover_count = NoteEnum::getCoverTypeCount($params['cover_type']); if (is_array($params['cover_img']) && count($params['cover_img']) != $cover_count) { return $this->error('请上传'. $cover_count . '张封面图'); } } $config = Yii::$app->services->setting->addons->get($this->mall_id, NoteEnum::ADDONS_NAME, 'basic', true); if ($config['allow_user_create'] == 0) { return $this->error('暂时未开放会员发布内容'); } if (isset($params['cover_type']) && !$params['cover_type']) unset($params['cover_type']); if (!isset($params['id'])) { $scenarios = 'create'; $params['share_reward_type'] = 0; $params['view_reward_type'] = 0; $params['share_title_type'] = 1; $params['view_limit'] = 0; $params['share_reward'] = 0; $params['share_reward_max_time'] = 0; $params['view_reward'] = 0; $params['view_reward_max_time'] = 0; if ($config['need_check'] == 0) { $params['check_status'] = 1; $params['is_release'] = 1; } } else { if (isset($params['cover_type'])) { unset($params['cover_type']); } $scenarios = 'update'; if ($config['need_check'] == 1) { $params['check_status'] = NoteEnum::STATUS_ZERO; } } $res = AddonsOperatingNoteContent::setData($params, $scenarios, false); if ($res === false) return $this->error(AddonsOperatingNoteContent::getStaticError()); return $this->success('操作成功', []); } /** * @desc:分类列表 * @Author: hua * @Date: 2022/2/22 * @Time: 14:13 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionCateList() { $params = [ 'where' => [ ['mall_id' => $this->mall_id], ['status' => StatusEnum::ENABLED] ], 'select' => 'id,name' ]; $list = AddonsOperatingNoteCate::lists($params); return $this->success('操作成功', $list); } /** * @desc:我的笔记 * @Author: hua * @Date: 2022/2/22 * @Time: 18:14 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionMyNote() { $get = \Yii::$app->request->get(); if (isset($get['user_id']) && $get['user_id'] != 0 && $get['user_id'] != $this->user_id) { $params['where'][] = ['user_id' => $get['user_id']]; $params['where'][] = ['is_release' => StatusEnum::ENABLED]; $params['where'][] = ['check_status' => StatusEnum::ENABLED]; } else { $params['where'][] = ['user_id' => $this->user_id]; } $params['where'][] = ['mall_id' => $this->mall_id]; $params['where'][] = ['status' => StatusEnum::ENABLED]; $params['order'] = 'id desc'; $params['select'] = 'id,title,created_at,check_status,check_remark,cover_img,views_num,likes_num,content_href,note_type,is_release,reply_num'; $list = AddonsOperatingNoteContent::listPage($params, true, true); return $this->success('操作成功', $list); } public function actionDel() { $params = \Yii::$app->request->post(); $res = \Yii::$app->services->validate->validate($params, [ [['id'], 'required'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $params['status'] = StatusEnum::DELETE; $params['user_id'] = $this->user_id; $res = AddonsOperatingNoteContent::setData($params, 'update', false); return $this->success('操作成功', $res); } public function actionBuyList() { $params = \Yii::$app->request->get(); $params['where'][] = ['mall_id' => $this->mall_id]; $params['where'][] = ['user_id' => $this->user_id]; $params['where'][] = ['is_pay' => StatusEnum::ENABLED]; $params['where'][] = ['status' => StatusEnum::ENABLED]; $params['order'] = 'created_at desc'; $params['with'] = ['content']; $list = AddonsOperatingNoteBuy::listPage($params, true, true); $list['list'] = array_column($list['list'], 'content'); return $this->success('操作成功', $list); } /** * 获取详情 * User: wniu * Date: 2022/2/24 * Time: 2:31 下午 * */ public function actionDetail() { $params = \Yii::$app->request->get(); $detail = AddonsOperatingNoteContent::getDetail($params['id'], $this->user); if (!$detail) return $this->error(AddonsOperatingNoteContent::getStaticError()); return $this->success('获取成功', $detail); } /** * 发表评论 * User: wniu * Date: 2022/2/25 * Time: 3:14 下午 * * @throws \yii\db\Exception */ public function actionCreateReply() { $params = \Yii::$app->request->post(); $res = \Yii::$app->services->validate->validate($params, [ [['note_content_id', 'content'], 'required'], [['reply_id'], 'safe'], ]); $params = AddonsOperatingNoteComment::exceptNullVal($params); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $params['mall_id'] = $this->mall_id; $params['user_id'] = $this->user_id; $model = AddonsOperatingNoteComment::setData($params); if ($model) { $user['id'] = $this->user->id; $user['mobile'] = $this->user->mobile; $user['nickname'] = $this->user->nickname; $user['nickname'] = $this->user->nickname; $user['avatar_url'] = $this->user->avatar_url; $user['parent_id'] = $this->user->parent_id; $user['username'] = $this->user->username; $model['user'] = $user; } else { return $this->success('不允许评论'); } return $this->success('发表评论成功', $model); } /** * 获取一级评论 * User: wniu * Date: 2022/2/23 * Time: 6:22 下午 * */ public function actionGetComment() { $params = \Yii::$app->request->get(); $params['where'][] = ['mall_id' => $this->mall_id]; $params['where'][] = ['note_content_id' => $params['id']]; $params['where'][] = ['level' => 1]; $params['where'][] = ['status' => StatusEnum::ENABLED]; $params['order'] = 'is_top desc,top_time desc,created_at desc'; $params['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' => 'count(*) as count,user_id,reply_id,content,created_at']); 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); } /** * 获取二级评论 * User: wniu * Date: 2022/2/23 * Time: 6:22 下午 * */ public function actionGetReply() { $params = \Yii::$app->request->get(); $params['where'][] = ['reply_id' => $params['reply_id']]; $params['where'][] = ['status' => StatusEnum::ENABLED]; $params['with'] = ['user']; $list = AddonsOperatingNoteComment::listPage($params, false, true); if (isset($params['page']) && $params['page'] == 1) { if (isset($list['list'][0])) { array_shift($list['list']); } } return $this->success('操作成功', $list); } /** * 分享 * User: wniu * Date: 2022/2/24 * Time: 3:49 下午 * * @throws \yii\db\Exception */ public function actionShare() { $params = \Yii::$app->request->post(); $res = \Yii::$app->services->validate->validate($params, [ [['id',], 'required'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $data = AddonsOperatingNoteShareRecord::setData($params['id'], $this->user_id); return $this->success('分享成功', $data); } /** * 点赞 * User: wniu * Date: 2022/2/24 * Time: 3:50 下午 * */ public function actionLikes() { $params = \Yii::$app->request->post(); $res = \Yii::$app->services->validate->validate($params, [ [['id',], 'required'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $msg = AddonsOperatingNoteUserLike::setData($params['id'], $this->user_id, $this->mall_id); return $this->success($msg . '成功'); } /** * 购买笔记 * User: wniu * Date: 2022/2/25 * Time: 3:17 下午 * */ public function actionBuy() { $params = \Yii::$app->request->post(); $res = \Yii::$app->services->validate->validate($params, [ [['id',], 'required'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $data = AddonsOperatingNoteBuy::userBuyNote($params['id'], $this->user_id); if ($data === false) return $this->error(AddonsOperatingNoteBuy::getStaticError()); return $this->success('成功', $data); } /** * 获取浏览奖励 * User: wniu * Date: 2022/3/9 * Time: 4:18 下午 * */ public function actionViewReward() { $params = \Yii::$app->request->post(); $res = \Yii::$app->services->validate->validate($params, [ [['id',], 'required'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $data = AddonsOperatingNoteContent::viewReward($params['id'], $this->user); return $this->success('成功', $data); } public function actionConfig() { $Platform_config = PlatformSetting::getConfByGroup('system', true); $config = Yii::$app->services->setting->addons->get($this->mall_id, NoteEnum::ADDONS_NAME, 'basic'); $config['web_url'] = $Platform_config['h5_url']['value']; $config['mall_sign'] = $this->mall['mall_sign']; $this->success('获取成功', $config); } public function actionGetUserInfo() { $params = \Yii::$app->request->get(); $res = \Yii::$app->services->validate->validate($params, [ [['user_id',], 'required'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $data = User::getUser([['id' => $params['user_id']]], 'nickname,avatar_url,mobile'); $this->success('获取成功', $data); } }