| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534 |
- <?php
- namespace addons\OperatingNote\api\modules\v1\controllers;
- use addons\OperatingNote\common\enums\NoteEnum;
- use addons\OperatingNote\common\models\AddonsOperatingNoteAd;
- use addons\OperatingNote\common\models\AddonsOperatingNoteBuy;
- use addons\OperatingNote\common\models\AddonsOperatingNoteCate;
- use addons\OperatingNote\common\models\AddonsOperatingNoteComment;
- use addons\OperatingNote\common\models\AddonsOperatingNoteContent;
- use addons\OperatingNote\common\models\AddonsOperatingNoteRewardRecord;
- use addons\OperatingNote\common\models\AddonsOperatingNoteShareRecord;
- use addons\OperatingNote\common\models\AddonsOperatingNoteUserLike;
- use common\enums\StatusEnum;
- use common\models\common\PlatformSetting;
- use common\models\user\User;
- use common\models\user\UserFollow;
- use Yii;
- use api\controllers\OnAuthController;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\OperatingNote\api\modules\v1\controllers
- */
- class DefaultController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = ['index', 'article-list', 'get-comment', 'config', 'detail', 'view-reward'];
- /**
- * @desc:首页
- * @Author: hua
- * @Date: 2022/2/22
- * @Time: 14:33
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionIndex()
- {
- $data['is_login'] = $this->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);
- }
- }
|