Consult.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\api\controller;
  15. use app\api\controller\Base;
  16. use think\Db;
  17. use think\Model;
  18. /**
  19. * @title 咨询管理
  20. * @controller Consult
  21. * @group member
  22. */
  23. class Consult extends Base
  24. {
  25. function initialize(){
  26. $this->check_login();
  27. }
  28. /**
  29. * @title 添加论坛(內容提供者)
  30. * @desc 添加论坛
  31. * @author QGF
  32. * @url /api/Forum/add_forum
  33. * @method GET
  34. * @tag 添加论坛
  35. * @header name:Authorization require:1 desc:Token
  36. * @param name:title type:string require:1 default:-- desc:公司名称
  37. * @param name:images type:string require:1 default:-- desc:图片地址,多张以英文逗号分隔
  38. */
  39. public function add_forum(){
  40. $uid = $this->uid;
  41. $member_info = Db::name('store_member')->field('current_type')->where('id',$uid)->find();
  42. if($member_info['current_type'] != 2){
  43. $this->error('请切换至内容提供者');
  44. }
  45. $title = input('title');
  46. $images = input('images');
  47. $video = input('video');
  48. if(empty($title) || empty($images)){
  49. $this->error('参数错误');
  50. }
  51. $data = array(
  52. 'user_id' => $uid,
  53. 'title' => $title,
  54. 'images' => $images,
  55. 'video' => $video
  56. );
  57. Db::name('store_forum')->insert($data);
  58. $this->success('添加成功');
  59. }
  60. /**
  61. * @title 论坛列表
  62. * @desc 论坛列表
  63. * @author QGF
  64. * @url /api/Forum/forum_list
  65. * @method GET
  66. * @tag 论坛列表
  67. * @header name:Authorization require:1 desc:Token
  68. * @param name:page type:int require:0 default:1 desc:页数(默认为1)
  69. * @param name:page_size type:int require:0 default:10 desc:每页数量(默认为10)
  70. * @param name:keyword type:string require:0 default:-- desc:搜索的关键词(PC端)
  71. * @return name:user_id type:int default:-- desc:内容提供者(发布者)ID
  72. * @return name:title type:string default:-- desc:论坛标题
  73. * @return name:images type:array default:-- desc:论坛图片(数组)
  74. * @return name:create_at type:string default:-- desc:发布时间
  75. * @return name:is_like type:int default:-- desc:是否点赞(0:未点赞,1:已点赞)
  76. * @return name:is_attention type:int default:-- desc:是否关注(0:未关注,1:已关注)
  77. * @return name:user_name type:string default:-- desc:内容提供者名称
  78. * @return name:user_headimg type:string default:-- desc:内容提供者头像
  79. * @return name:ID type:int default:-- desc:论坛ID
  80. */
  81. public function forum_list(){
  82. $uid = $this->uid;
  83. $page = input('page',1);
  84. $pageSize = input('page_size',10);
  85. $keyword = input('keyword');
  86. if($keyword){
  87. $where = "title like '%".$keyword."%'";
  88. }else{
  89. $where = "id > 0";
  90. }
  91. $list = Db::name('store_forum')->field('id,user_id,title,images,create_at')->where('is_deleted',0)->where('user_id','<>',$uid)->where($where)->group('user_id')->page($page,$pageSize)->order('id','desc')->select();
  92. if($list){
  93. foreach ($list as &$value){
  94. $like_id = Db::name('store_forum_like')->where('forum_id',$value['id'])->where('user_id',$uid)->where('status',1)->value('id');
  95. $value['is_like'] = $like_id?1:0;
  96. $attention_id = Db::name('store_forum_attention')->where('user_id',$uid)->where('from_user_id',$value['user_id'])->where('status',1)->value('id');
  97. $value['is_attention'] = $attention_id?1:0;
  98. $forum_member_info = Db::name('store_member')->field('name,headimg')->where('id',$value['user_id'])->find();
  99. $value['images'] = image_path($value['images']);
  100. $value['user_name'] = $forum_member_info['name'];
  101. $value['user_headimg'] = $forum_member_info['headimg'];
  102. $value['ID'] = $value['id'];
  103. unset($value['id']);
  104. }
  105. }
  106. $this->success('获取成功',$list);
  107. }
  108. /**
  109. * @title 论坛管理(内容提供者)
  110. * @desc 论坛管理(内容提供者)
  111. * @author QGF
  112. * @url /api/Forum/forum_manage
  113. * @method GET
  114. * @tag 论坛管理(内容提供者)
  115. * @header name:Authorization require:1 desc:Token
  116. * @param name:page type:int require:0 default:1 desc:页数(默认为1)
  117. * @param name:page_size type:int require:0 default:10 desc:每页数量(默认为10)
  118. * @return name:title type:string default:-- desc:论坛标题
  119. * @return name:images type:array default:-- desc:论坛图片(数组)
  120. * @return name:create_at type:string default:-- desc:发布时间
  121. * @return name:user_name type:string default:-- desc:内容提供者名称
  122. * @return name:user_headimg type:string default:-- desc:内容提供者头像
  123. */
  124. public function forum_manage(){
  125. $uid = $this->uid;
  126. $member_info = Db::name('store_member')->field('current_type')->where('id',$uid)->find();
  127. if($member_info['current_type'] != 2){
  128. $this->error('请切换至内容提供者');
  129. }
  130. $page = input('page',1);
  131. $pageSize = input('page_size',10);
  132. $list = Db::name('store_forum')->field('id,user_id,title,images,create_at')->where('is_deleted',0)->where('user_id',$uid)->page($page,$pageSize)->order('id','desc')->select();
  133. if($list){
  134. foreach ($list as &$value){
  135. $value['ID'] = $value['id'];
  136. $forum_member_info = Db::name('store_member')->field('name,headimg')->where('id',$value['user_id'])->find();
  137. $value['images'] = image_path($value['images']);
  138. $value['user_name'] = $forum_member_info['name'];
  139. $value['user_headimg'] = $forum_member_info['headimg'];
  140. unset($value['user_id']);
  141. unset($value['id']);
  142. }
  143. }
  144. $this->success('获取成功',$list);
  145. }
  146. /**
  147. * @title 删除论坛(內容提供者)
  148. * @desc 删除论坛
  149. * @author QGF
  150. * @url /api/Forum/deleted_forum
  151. * @method GET
  152. * @tag 删除论坛
  153. * @header name:Authorization require:1 desc:Token
  154. * @param name:id type:int require:1 default:-- desc:论坛ID
  155. */
  156. public function deleted_forum(){
  157. $uid = $this->uid;
  158. $id = input('id');
  159. if(empty($id)){
  160. $this->error('参数错误');
  161. }
  162. $member_info = Db::name('store_member')->field('current_type')->where('id',$uid)->find();
  163. if($member_info['current_type'] != 2){
  164. $this->error('请切换至内容提供者');
  165. }
  166. $forum_info = Db::name('store_forum')->field('id')->where('id',$id)->where('user_id',$uid)->where('is_deleted',0)->find();
  167. if(empty($forum_info)){
  168. $this->error('论坛信息有误');
  169. }
  170. Db::name('store_forum')->where('id',$id)->update(array('is_deleted'=>1));
  171. $this->success('删除成功');
  172. }
  173. /**
  174. * @title 论坛详情
  175. * @desc 论坛详情
  176. * @author QGF
  177. * @url /api/Forum/forum_detail
  178. * @method GET
  179. * @tag 论坛详情
  180. * @header name:Authorization require:1 desc:Token
  181. * @param name:id type:int require:1 default:-- desc:论坛ID
  182. * @return name:user_id type:int default:-- desc:内容提供者(发布者)ID
  183. * @return name:title type:string default:-- desc:论坛标题
  184. * @return name:images type:array default:-- desc:论坛图片(数组)
  185. * @return name:video type:string default:-- desc:视频地址(没有返回null)
  186. * @return name:create_at type:string default:-- desc:发布时间
  187. * @return name:is_like type:int default:-- desc:是否点赞(0:未点赞,1:已点赞)
  188. * @return name:is_attention type:int default:-- desc:是否关注(0:未关注,1:已关注)
  189. * @return name:user_name type:string default:-- desc:内容提供者名称
  190. * @return name:user_headimg type:string default:-- desc:内容提供者头像
  191. * @return name:ID type:int default:-- desc:论坛ID
  192. */
  193. public function forum_detail(){
  194. $uid = $this->uid;
  195. $id = input('id');
  196. if(empty($id)){
  197. $this->error('参数错误');
  198. }
  199. $forum_info = Db::name('store_forum')->field('id,user_id,title,images,video,create_at')->where('id',$id)->where('is_deleted',0)->find();
  200. if(empty($forum_info)){
  201. $this->error('论坛信息有误');
  202. }
  203. $like_id = Db::name('store_forum_like')->where('forum_id',$id)->where('user_id',$uid)->where('status',1)->value('id');
  204. $forum_info['is_like'] = $like_id?1:0;
  205. $attention_id = Db::name('store_forum_attention')->where('user_id',$uid)->where('from_user_id',$forum_info['user_id'])->where('status',1)->value('id');
  206. $forum_info['is_attention'] = $attention_id?1:0;
  207. $forum_member_info = Db::name('store_member')->field('name,headimg')->where('id',$forum_info['user_id'])->find();
  208. $forum_info['images'] = image_path($forum_info['images']);
  209. $forum_info['user_name'] = $forum_member_info['name'];
  210. $forum_info['user_headimg'] = $forum_member_info['headimg'];
  211. $forum_info['ID'] = $forum_info['id'];
  212. unset($forum_info['id']);
  213. $this->success('获取成功',$forum_info);
  214. }
  215. /**
  216. * @title 点赞/取消点赞
  217. * @desc 点赞/取消点赞
  218. * @author QGF
  219. * @url /api/Forum/forum_like
  220. * @method GET
  221. * @tag 点赞/取消点赞
  222. * @header name:Authorization require:1 desc:Token
  223. * @param name:id type:int require:1 default:-- desc:论坛ID
  224. * @param name:type type:int require:1 default:-- desc:类型(0:取消点赞,1:点赞)
  225. */
  226. public function forum_like(){
  227. $uid = $this->uid;
  228. $id = input('id');
  229. $type = input('type');
  230. if(empty($id) || !isset($type)){
  231. $this->error('参数错误');
  232. }
  233. $store_forum = Db::name('store_forum')->field('user_id')->where('id',$id)->where('status',1)->where('is_deleted',0)->find();
  234. if(empty($store_forum)){
  235. $this->error('动态信息有误');
  236. }
  237. $user_id = $store_forum['user_id'];
  238. if($uid == $user_id){
  239. $this->error('不能操作自己');
  240. }
  241. $like = Db::name('store_forum_like')->where('user_id',$uid)->where('forum_id',$id)->where('user_id',$uid)->find();
  242. if($type == 0){ //取消关注
  243. if(empty($like['status'])){
  244. $this->error('没点赞无需取消');
  245. }
  246. Db::name('store_forum_like')->where('user_id',$uid)->where('forum_id',$id)->update(array('status'=>0));
  247. }else{
  248. if(!empty($like['status'])){
  249. $this->error('已点赞无需继续点赞');
  250. }
  251. if($like['id']){
  252. Db::name('store_forum_like')->where('user_id',$uid)->where('forum_id',$id)->update(array('status'=>1));
  253. }else{
  254. $data = array(
  255. 'user_id' => $uid,
  256. 'from_user_id' => $user_id,
  257. 'forum_id' => $id,
  258. 'status' => 1
  259. );
  260. Db::name('store_forum_like')->insert($data);
  261. }
  262. }
  263. $this->success('操作成功');
  264. }
  265. /**
  266. * @title 关注/取消关注
  267. * @desc 关注/取消关注
  268. * @author QGF
  269. * @url /api/Forum/forum_attention
  270. * @method GET
  271. * @tag 关注/取消关注
  272. * @header name:Authorization require:1 desc:Token
  273. * @param name:user_id type:int require:1 default:-- desc:被关注/取消关注的用户ID
  274. * @param name:type type:int require:1 default:-- desc:类型(0:取消关注,1:关注)
  275. */
  276. public function forum_attention(){
  277. $uid = $this->uid;
  278. $user_id = input('user_id');
  279. $type = input('type');
  280. if(empty($user_id) || !isset($type)){
  281. $this->error('参数错误');
  282. }
  283. if($uid == $user_id){
  284. $this->error('不能操作自己');
  285. }
  286. $attention = Db::name('store_forum_attention')->where('user_id',$uid)->where('from_user_id',$user_id)->find();
  287. if($type == 0){ //取消关注
  288. if(empty($attention['status'])){
  289. $this->error('没关注无需取消');
  290. }
  291. Db::name('store_forum_attention')->where('user_id',$uid)->where('from_user_id',$user_id)->update(array('status'=>0));
  292. }else{
  293. if(!empty($attention['status'])){
  294. $this->error('已关注无需继续关注');
  295. }
  296. if($attention['id']){
  297. Db::name('store_forum_attention')->where('user_id',$uid)->where('from_user_id',$user_id)->update(array('status'=>1));
  298. }else{
  299. $data = array(
  300. 'user_id' => $uid,
  301. 'from_user_id' => $user_id,
  302. 'status' => 1
  303. );
  304. Db::name('store_forum_attention')->insert($data);
  305. }
  306. }
  307. $this->success('操作成功');
  308. }
  309. /**
  310. * @title 发表评论
  311. * @desc 发表评论
  312. * @author QGF
  313. * @url /api/Forum/forum_comment
  314. * @method GET
  315. * @tag 发表评论
  316. * @header name:Authorization require:1 desc:Token
  317. * @param name:forum_id type:int require:1 default:-- desc:论坛ID
  318. * @param name:content type:string require:1 default:-- desc:评论内容
  319. */
  320. public function forum_comment(){
  321. $uid = $this->uid;
  322. $forum_id = input('forum_id');
  323. $content = input('content');
  324. if(empty($forum_id) || empty($content)){
  325. $this->error('参数错误');
  326. }
  327. $store_forum = Db::name('store_forum')->field('user_id')->where('id',$forum_id)->where('status',1)->where('is_deleted',0)->find();
  328. if(empty($store_forum)){
  329. $this->error('动态信息有误');
  330. }
  331. $user_id = $store_forum['user_id']; //论坛作者的会员ID
  332. if($uid == $user_id){
  333. $this->error('不能操作自己');
  334. }
  335. $comment_info = Db::name('store_forum_comment')->field('id')->where('user_id',$uid)->where('forum_id',$forum_id)->where('type',1)->find();
  336. if(!empty($comment_info)){
  337. $this->error('已评论过该动态');
  338. }
  339. $comment_data = array(
  340. 'user_id' => $uid,
  341. 'from_user_id' => $user_id,
  342. 'forum_id' => $forum_id,
  343. 'content' => $content,
  344. 'type' => 1
  345. );
  346. Db::name('store_forum_comment')->insert($comment_data);
  347. $comment_id = Db::name('store_forum_comment')->getLastInsID();
  348. Db::name('store_forum_comment')->where('id',$comment_id)->update(array('root_comment_id'=>$comment_id));
  349. $this->success('评论成功');
  350. }
  351. /**
  352. * @title 回复评论(留言)
  353. * @desc 回复评论(留言)
  354. * @author QGF
  355. * @url /api/Forum/reply_comment
  356. * @method GET
  357. * @tag 回复评论(留言)
  358. * @header name:Authorization require:1 desc:Token
  359. * @param name:comment_id type:int require:1 default:-- desc:要留言的评论ID
  360. * @param name:content type:string require:1 default:-- desc:留言内容
  361. */
  362. public function reply_comment(){
  363. $uid = $this->uid;
  364. $comment_id = input('comment_id');//要回复的评论ID
  365. $content = input('content');//回复评论的内容
  366. if(empty($content) || empty($comment_id)){
  367. $this->error('参数错误');
  368. }
  369. $comment = Db::name('store_forum_comment')->field('forum_id,user_id,root_comment_id')->where('id',$comment_id)->find();
  370. if(empty($comment)){
  371. $this->error('要回复的评论不存在');
  372. }
  373. if($comment['user_id'] == $uid){
  374. $this->error('不能回复自己的评论');
  375. }
  376. //判断要是否回复过次评论了
  377. $reply_comment = Db::name('store_forum_comment')->field('id')->where('user_id',$uid)->where('type',2)->where('comment_id',$comment_id)->find();
  378. if(!empty($reply_comment)){
  379. $this->error('已回复过此评论');
  380. }
  381. $root_comment_id = $comment['root_comment_id']?$comment['root_comment_id']:$comment_id;
  382. $comment_data = array(
  383. 'forum_id' => $comment['forum_id'],
  384. 'user_id' => $uid,
  385. 'from_user_id' => $comment['user_id'],
  386. 'content' => $content,
  387. 'comment_id' => $comment_id,
  388. 'root_comment_id' => $root_comment_id,
  389. 'type' => 2
  390. );
  391. Db::name('store_forum_comment')->insert($comment_data);
  392. $this->success('留言成功');
  393. }
  394. /**
  395. * @title 评论列表
  396. * @desc 评论列表
  397. * @author QGF
  398. * @url /api/Forum/comment_list
  399. * @method GET
  400. * @tag 评论列表
  401. * @header name:Authorization require:1 desc:Token
  402. * @param name:page type:int require:0 default:1 desc:页数(默认为1)
  403. * @param name:page_size type:int require:0 default:10 desc:每页数量(默认为10)
  404. * @param name:forum_id type:int require:1 default:-- desc:论坛ID
  405. * @return name:comment_num type:int default:-- desc:评论数量
  406. * @return name:comment_list type:array default:-- desc:content:评论内容,create_time:评论时间,headimg:评论者头像,name:评论者名称,reply_comment:留言的内容列表(content:留言内容,create_time:留言时间,to_user_name:回复的人员名称,user_name:留言者名称,user_headimg:留言者头像),ID:评论ID
  407. */
  408. public function comment_list(){
  409. $forum_id = input('forum_id');
  410. $page = input('page',1);
  411. $pageSize = input('page_size',10);
  412. if(empty($forum_id)){
  413. $this->error('参数错误');
  414. }
  415. //评论列表
  416. $comment_list = Db::name('store_forum_comment')->alias("c")
  417. ->join('store_member m', 'c.user_id = m.id')
  418. ->field('c.id,c.content,c.create_time,c.root_comment_id,m.headimg,m.name')
  419. ->where('forum_id',$forum_id)->where('c.type',1)
  420. ->page($page,$pageSize)
  421. ->order('c.id desc')
  422. ->select();
  423. if(empty($comment_list)){
  424. $this->success('暂无评论',array());
  425. }
  426. foreach ($comment_list as &$value){
  427. //查看回复评论
  428. $value['reply_comment'] = Db::name('store_forum_comment')->field('user_id,content,comment_id,create_time')->where('root_comment_id',$value['root_comment_id'])->where('type',2)->select();
  429. if($value['reply_comment']){
  430. foreach ($value['reply_comment'] as &$v){
  431. $to_user_id = Db::name('store_forum_comment')->where('id',$v['comment_id'])->value('user_id');
  432. $v['to_user_name'] = Db::name('store_member')->where('id',$to_user_id)->value('name');
  433. $user_info = Db::name('store_member')->field('name,headimg')->where('id',$v['user_id'])->find();
  434. $v['user_name'] = $user_info['name'];
  435. $v['user_headimg'] = $user_info['headimg'];
  436. unset($v['comment_id']);
  437. unset($v['user_id']);
  438. }
  439. }
  440. $value['ID'] = $value['id'];
  441. unset($value['id']);
  442. unset($value['root_comment_id']);
  443. }
  444. $data = array(
  445. 'comment_num' => Db::name('store_forum_comment')->where('forum_id',$forum_id)->where('type',1)->count('id'),
  446. 'comment_list' => $comment_list
  447. );
  448. $this->success('获取成功',$data);
  449. }
  450. /**
  451. * @title 论坛发布者详情(用户端)
  452. * @desc 论坛发布者详情(用户端)
  453. * @author QGF
  454. * @url /api/Forum/forum_master
  455. * @method GET
  456. * @tag 论坛发布者详情(用户端)
  457. * @header name:Authorization require:1 desc:Token
  458. * @param name:user_id type:int require:1 default:-- desc:论坛发布者ID
  459. * @return name:headimg type:string default:-- desc:发布者头像
  460. * @return name:name type:string default:-- desc:发布者名称
  461. * @return name:is_like type:int default:-- desc:是否点赞(0:未点赞,1:已点赞)
  462. * @return name:is_attention type:int default:-- desc:是否关注(0:未关注,1:已关注)
  463. * @return name:forum_list type:array default:-- desc:user_id:发布者ID,title:论坛标题,images:评论图片(数组),create_at:发布时间,is_like:是否点赞(0:未点赞,1:已点赞),user_name:发布者名称,user_headimg:发布者头像,ID:论坛ID
  464. */
  465. public function forum_master(){
  466. $uid = $this->uid;
  467. $user_id = input('user_id');
  468. if(empty($user_id)){
  469. $this->error('参数错误');
  470. }
  471. if($uid == $user_id){
  472. $this->error('不能操作自己');
  473. }
  474. //查看是否已关注
  475. $is_attention = Db::name('store_forum_attention')->where('user_id',$uid)->where('from_user_id',$user_id)->where('status',1)->count();
  476. //关注数量
  477. $attention_num = Db::name('store_forum_attention')->where('from_user_id',$user_id)->where('status',1)->count();
  478. //点赞数量
  479. $like_num = Db::name('store_forum_like')->where('from_user_id',$user_id)->where('status',1)->count();
  480. //动态列表
  481. $field = 'id,user_id,title,images,create_at';
  482. $forum_list = Db::name('store_forum')->field($field)->where('user_id',$user_id)->where('status',1)->where('is_deleted',0)->order('id desc')->select();
  483. $member = Db::name('store_member')->field('headimg,name')->where('id',$user_id)->find();
  484. $name = $member['name'];
  485. $headimg = $member['headimg'];
  486. foreach ($forum_list as &$value){
  487. $like_id = Db::name('store_forum_like')->where('forum_id',$value['id'])->where('user_id',$uid)->where('status',1)->value('id');
  488. $value['is_like'] = $like_id?1:0;
  489. $value['images'] = image_path($value['images']);
  490. $value['user_name'] = $name;
  491. $value['user_headimg'] = $headimg;
  492. $value['ID'] = $value['id'];
  493. unset($value['id']);
  494. }
  495. $data = array(
  496. 'headimg' => $headimg,
  497. 'name' => $name,
  498. 'is_attention' => $is_attention,
  499. 'attention_num' => $attention_num,
  500. 'like_num' => $like_num,
  501. 'forum_list' => $forum_list
  502. );
  503. $this->success('获取成功',$data);
  504. }
  505. /**
  506. * @title 我的关注
  507. * @desc 我的关注
  508. * @author QGF
  509. * @url /api/Forum/my_attention
  510. * @method GET
  511. * @tag 我的关注
  512. * @header name:Authorization require:1 desc:Token
  513. * @param name:page type:int require:0 default:1 desc:页数(默认为1)
  514. * @param name:page_size type:int require:0 default:10 desc:每页数量(默认为10)
  515. * @param name:keyword type:string require:0 default:-- desc:搜索的关键词(PC端)
  516. * @return name:user_id type:int default:-- desc:内容提供者(发布者)ID
  517. * @return name:title type:string default:-- desc:论坛标题
  518. * @return name:images type:array default:-- desc:论坛图片(数组)
  519. * @return name:create_at type:string default:-- desc:发布时间
  520. * @return name:is_like type:int default:-- desc:是否点赞(0:未点赞,1:已点赞)
  521. * @return name:is_attention type:int default:-- desc:是否关注(0:未关注,1:已关注)
  522. * @return name:user_name type:string default:-- desc:内容提供者名称
  523. * @return name:user_headimg type:string default:-- desc:内容提供者头像
  524. * @return name:ID type:int default:-- desc:论坛ID
  525. */
  526. public function my_attention(){
  527. $uid = $this->uid;
  528. $page = input('page',1);
  529. $pageSize = input('page_size',10);
  530. $user_id_arr = Db::name('store_forum_attention')->where('user_id',$uid)->where('status',1)->column('from_user_id');
  531. $list = Db::name('store_forum')->field('id,user_id,title,images,create_at')->where('is_deleted',0)->where('user_id','in',$user_id_arr)->group('user_id')->page($page,$pageSize)->order('id','desc')->select();
  532. if($list){
  533. foreach ($list as &$value){
  534. $like_id = Db::name('store_forum_like')->where('forum_id',$value['id'])->where('user_id',$uid)->where('status',1)->value('id');
  535. $value['is_like'] = $like_id?1:0;
  536. $attention_id = Db::name('store_forum_attention')->where('user_id',$uid)->where('from_user_id',$value['user_id'])->where('status',1)->value('id');
  537. $value['is_attention'] = $attention_id?1:0;
  538. $forum_member_info = Db::name('store_member')->field('name,headimg')->where('id',$value['user_id'])->find();
  539. $value['images'] = image_path($value['images']);
  540. $value['user_name'] = $forum_member_info['name'];
  541. $value['user_headimg'] = $forum_member_info['headimg'];
  542. $value['ID'] = $value['id'];
  543. unset($value['id']);
  544. }
  545. }
  546. $this->success('获取成功',$list);
  547. }
  548. }