Topicdongtai.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use app\common\library\Keyworld;
  6. use think\Exception;
  7. /**
  8. * 圈子动态
  9. */
  10. class Topicdongtai extends Api
  11. {
  12. protected $noNeedLogin = [];
  13. protected $noNeedRight = ['*'];
  14. //发布动态
  15. public function addone(){
  16. $content = input('content','');
  17. $images = input('images','');
  18. $topic_id = input('topic_id',1);
  19. if(!$content && !$images){
  20. $this->error(__('Invalid parameters'));
  21. }
  22. //关键字替换
  23. $content = Keyworld::sensitive($content);
  24. $data = [
  25. 'topic_id' => $topic_id,
  26. 'user_id' => $this->auth->id,
  27. 'content' => $content,
  28. 'images' => $images,
  29. 'type' => input('type',1),
  30. 'createtime' => time(),
  31. 'updatetime' => time(),
  32. ];
  33. Db::startTrans();
  34. $id = Db::name('topic_dongtai')->insertGetId($data);
  35. //圈子新增一个贴
  36. $rs = Db::name('topic_hub')->where('id',$topic_id)->setInc('t_number');
  37. Db::commit();
  38. $this->success('发布成功',$id);
  39. }
  40. //自己看列表
  41. //某用户的帖子列表
  42. public function my_lists(){
  43. $uid = input('uid',$this->auth->id);
  44. if (empty($uid)) {
  45. $uid = $this->auth->id;
  46. }
  47. $list = Db::name('topic_dongtai')->alias('dt')
  48. ->join('user','dt.user_id = user.id','LEFT')
  49. ->join('topic_hub topic','dt.topic_id = topic.id','LEFT')
  50. ->field('dt.*,user.nickname,user.avatar,user.gender,topic.name as topic_name')
  51. ->where('dt.user_id',$uid)
  52. ->order('dt.id desc')->autopage()->select();
  53. $list = list_domain_image($list,['images','avatar']);
  54. if(!empty($list)){
  55. foreach($list as $key => &$val){
  56. //追加点赞
  57. $val['isgood'] = $this->is_good($val['id'],$this->auth->id);
  58. //创建视频缩略图
  59. $val['images_thumb'] = '';
  60. if ($val['type'] == 2) {
  61. $images_url = explode('.', $val['images']);
  62. unset($images_url[count($images_url) - 1]);
  63. $val['images_thumb'] = join('.', $images_url) . '_0.jpg';
  64. }
  65. //时间
  66. $val['createtime_text'] = get_last_time($val['createtime']);
  67. //关注
  68. $val['is_follow'] = $this->is_follow($this->auth->id,$val['user_id']);
  69. //评论
  70. $val['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$val['id'],'level'=>1])->count();
  71. }
  72. }
  73. $this->success('success',$list);
  74. }
  75. //动态删除
  76. public function delete(){
  77. $id = input('id',0);
  78. $where['id'] = $id;
  79. $where['user_id'] = $this->auth->id;
  80. $dongtai = Db::name('topic_dongtai')->field('id,topic_id')->where($where)->find();
  81. if (empty($dongtai)) {
  82. $this->error('未找到动态信息');
  83. }
  84. Db::startTrans();
  85. $delRes = Db::name('topic_dongtai')->where('id',$id)->where('user_id',$this->auth->id)->delete();
  86. if (!$delRes) {
  87. Db::rollback();
  88. $this->error('动态删除失败');
  89. }
  90. //圈子新增一个贴
  91. if (!empty($dongtai['topic_id'])) {
  92. $res = Db::name('topic_hub')->where('id',$dongtai['topic_id'])->setDec('t_number');
  93. if (!$res) {
  94. Db::rollback();
  95. $this->error('更新话题数量失败');
  96. }
  97. }
  98. //删除对应的评论,
  99. Db::name('topic_dongtai_answer')->where('dt_id',$id)->delete();
  100. //点赞,
  101. Db::name('topic_dongtai_good')->where('dt_id',$id)->delete();
  102. //评论点赞
  103. Db::name('topic_answer_good')->where('dt_id',$id)->delete();
  104. Db::commit();
  105. $this->success('删除成功');
  106. }
  107. //是否点赞
  108. private function is_good($dt_id,$uid){
  109. $where = [
  110. 'dt_id' => $dt_id,
  111. 'user_id' => $uid,
  112. ];
  113. $check = Db::name('topic_dongtai_good')->where($where)->find();
  114. if($check){
  115. return 1;
  116. }else{
  117. return 0;
  118. }
  119. }
  120. //回复是否点赞
  121. private function answer_is_good($answer_id,$uid){
  122. $where = [
  123. 'answer_id' => $answer_id,
  124. 'user_id' => $uid,
  125. ];
  126. $check = Db::name('topic_answer_good')->where($where)->find();
  127. if($check){
  128. return 1;
  129. }else{
  130. return 0;
  131. }
  132. }
  133. //用户是否拉黑
  134. private function is_black($uid,$black_uid){
  135. $where = [
  136. 'user_id' => $uid,
  137. 'black_user_id' => $black_uid,
  138. ];
  139. $check = Db::name('user_blacklist')->where($where)->find();
  140. if($check){
  141. return 1;
  142. }else{
  143. return 0;
  144. }
  145. }
  146. //详情
  147. public function info(){
  148. $id = input('id');
  149. $info = Db::name('topic_dongtai')->alias('dt')
  150. ->join('user','dt.user_id = user.id','LEFT')
  151. ->join('topic_hub topic','dt.topic_id = topic.id','LEFT')
  152. ->field('dt.*,user.nickname,user.avatar,user.gender,topic.name as topic_name')
  153. ->where('dt.id',$id)->find();
  154. $info = info_domain_image($info,['images','avatar']);
  155. if($info){
  156. //是否点赞过
  157. $info['isgood'] = $this->is_good($id,$this->auth->id);
  158. //创建视频缩略图
  159. $info['images_thumb'] = '';
  160. if ($info['type'] == 2) {
  161. $images_url = explode('.', $info['images']);
  162. unset($images_url[count($images_url) - 1]);
  163. $info['images_thumb'] = join('.', $images_url) . '_0.jpg';
  164. }
  165. //时间
  166. $info['createtime_text'] = get_last_time($info['createtime']);
  167. //关注
  168. $info['is_follow'] = $this->is_follow($this->auth->id,$info['user_id']);
  169. //评论
  170. $info['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$id,'level'=>1])->count();
  171. //$info['answer'] = $this->answer_list($id);
  172. }
  173. $this->success('success',$info);
  174. }
  175. //点赞
  176. public function good(){
  177. $id = input('id');
  178. $where = [
  179. 'dt_id' => $id,
  180. 'user_id' => $this->auth->id,
  181. ];
  182. $check = Db::name('topic_dongtai_good')->where($where)->find();
  183. $dt_user_id = Db::name('topic_dongtai')->where('id',$id)->value('user_id');
  184. if($check){
  185. Db::name('topic_dongtai_good')->where($where)->delete();
  186. $down = Db::name('topic_dongtai')->where('id',$id)->setDec('goodnum');
  187. $this->success('已取消点赞');
  188. }else{
  189. Db::startTrans();
  190. $where['createtime'] = time();
  191. $rs = Db::name('topic_dongtai_good')->insertGetId($where);
  192. if(!$rs){
  193. Db::rollback();
  194. $this->error('点赞失败');
  195. }
  196. $up = Db::name('topic_dongtai')->where('id',$id)->setInc('goodnum');
  197. if($up === false){
  198. Db::rollback();
  199. $this->error('点赞失败');
  200. }
  201. //系统消息
  202. $msg_id = \app\common\model\Message::addMessage($dt_user_id,'动态点赞','有人赞了你的动态','dongtai_good',$id);
  203. Db::commit();
  204. $this->success('点赞成功');
  205. }
  206. }
  207. //评论
  208. public function answer(){
  209. $id = input('id',0);
  210. $content = input('content','');
  211. $to_user_id = input('to_user_id',0);
  212. $level = input('level',1); //回复类型:1=层主回复楼主,2=层中回复
  213. $floor = input('floor',0);
  214. if(empty($content) || empty($id)){
  215. $this->error();
  216. }
  217. //关键字替换
  218. $content = Keyworld::sensitive($content);
  219. //判断
  220. if($level == 2 && $floor == 0){
  221. $this->error('楼层错误');
  222. }
  223. //回复楼主,最新楼层
  224. if($level == 1 || $floor == 0){
  225. $to_user_id = 0;
  226. $floor = 1; //默认一楼
  227. $last_floor = Db::name('topic_dongtai_answer')->where(['dt_id'=>$id,'level'=>1])->order('floor desc')->value('floor');
  228. if($last_floor){
  229. $floor = $last_floor + 1;
  230. }
  231. }
  232. //判断user_id
  233. if($to_user_id){
  234. $to_user = Db::name('user')->where('id',$to_user_id)->value('id');
  235. if(empty($to_user)){
  236. $this->error('被回复的用户不存在');
  237. }
  238. }
  239. //data
  240. $data = [
  241. 'dt_id' => $id,
  242. 'floor' => $floor,
  243. 'user_id' => $this->auth->id,
  244. 'content' => $content,
  245. 'to_user_id' => $to_user_id,
  246. 'level' => $level,
  247. 'createtime' => time(),
  248. 'updatetime' => time(),
  249. ];
  250. Db::startTrans();
  251. $rs = Db::name('topic_dongtai_answer')->insertGetId($data);
  252. Db::name('topic_dongtai')->where('id',$id)->setInc('answernum');
  253. //系统消息
  254. if($level == 1){
  255. //发给动态用户
  256. $msg_user_id = Db::name('topic_dongtai')->where('id',$id)->value('user_id');
  257. $msg_title = '动态评论';
  258. $msg_content = '有人评论了你的动态';
  259. $infotype_id = $rs;
  260. }else{
  261. //发给层主
  262. $answer_info = Db::name('topic_dongtai_answer')->where(['dt_id'=>$id,'level'=>1,'floor'=>$floor])->find();
  263. $msg_user_id = $answer_info['user_id'];
  264. $msg_title = '动态评论点评';
  265. $msg_content = '有人点评了你的动态评论';
  266. $infotype_id = $answer_info['id'];
  267. }
  268. $msg_id = \app\common\model\Message::addMessage($msg_user_id,$msg_title,$msg_content,'dongtai_answer',$infotype_id);
  269. Db::commit();
  270. $this->success('评价成功');
  271. }
  272. //对评论点赞
  273. public function answer_good(){
  274. $dt_id = input('dt_id',0);
  275. $answer_id = input('answer_id',0);
  276. $where = [
  277. 'dt_id' => $dt_id,
  278. 'answer_id' => $answer_id,
  279. 'user_id' => $this->auth->id,
  280. ];
  281. $check = Db::name('topic_answer_good')->where($where)->find();
  282. if($check){
  283. Db::name('topic_answer_good')->where($where)->delete();
  284. Db::name('topic_dongtai_answer')->where('id',$answer_id)->setDec('goodnum');
  285. $this->success('已取消点赞');
  286. }
  287. Db::startTrans();
  288. $where['createtime'] = time();
  289. $rs = Db::name('topic_answer_good')->insertGetId($where);
  290. $up = Db::name('topic_dongtai_answer')->where('id',$answer_id)->setInc('goodnum');
  291. if($rs && $up !== false){
  292. Db::commit();
  293. $this->success('点赞成功');
  294. }
  295. Db::rollback();
  296. $this->error('点赞失败');
  297. }
  298. //举报枚举
  299. public function report_enum(){
  300. $arr = [
  301. '侮辱谩骂',
  302. '色情低俗',
  303. '整治敏感',
  304. '违法违规',
  305. '其他',
  306. ];
  307. $this->success(1,$arr);
  308. }
  309. //举报
  310. public function report(){
  311. $field = ['dt_id','type','content','images'];
  312. $data = request_post_hub($field);
  313. $check = Db::name('topic_dongtai')->where('id',$data['dt_id'])->find();
  314. $data['user_id'] = $this->auth->id;
  315. $data['ruser_id'] = $check['user_id'];
  316. $data['createtime'] = time();
  317. Db::name('topic_dongtai_report')->insertGetId($data);
  318. $this->success('举报成功');
  319. }
  320. //不感兴趣,屏蔽某条
  321. public function screen(){
  322. $data = [
  323. 'user_id' => $this->auth->id,
  324. 'dt_id' => input('dt_id',0),
  325. ];
  326. $check = Db::name('topic_dongtai_screen')->where($data)->find();
  327. if($check){
  328. $this->success('操作成功');
  329. }
  330. Db::name('topic_dongtai_screen')->insertGetId($data);
  331. $this->success('操作成功');
  332. }
  333. //评论列表
  334. public function answer_list(){
  335. $dt_id = input('dt_id',0);
  336. //楼
  337. $floor_list = Db::name('topic_dongtai_answer')
  338. ->alias('a')
  339. ->field('a.*,user.nickname,user.avatar,user.gender')
  340. ->join('user','a.user_id = user.id','LEFT')
  341. ->where(['a.dt_id'=>$dt_id,'a.level'=>1])->order('a.id desc')->autopage()->select();
  342. $floor_list = list_domain_image($floor_list,['avatar']);
  343. //追加子评论
  344. if(!empty($floor_list)){
  345. foreach($floor_list as $key => &$val){
  346. //下面几条子回复,字符串
  347. $val['childremark'] = '';
  348. $map = [
  349. 'a.dt_id' => $dt_id,
  350. 'a.floor' => $val['floor'],
  351. 'a.level' => 2,
  352. ];
  353. $number = Db::name('topic_dongtai_answer')->alias('a')->where($map)->count();
  354. if($number > 0){
  355. $answer_info = Db::name('topic_dongtai_answer')
  356. ->alias('a')
  357. ->field('user.nickname')
  358. ->join('user','a.user_id = user.id','LEFT')
  359. ->where($map)->order('a.id desc')->find();
  360. $val['childremark'] = $answer_info['nickname'].'...等人,共'.$number.'条回复';
  361. }
  362. //时间处理
  363. $val['createtime_text'] = get_last_time($val['createtime']);
  364. //回复是否已赞
  365. $val['is_good'] = $this->answer_is_good($val['id'],$this->auth->id);
  366. }
  367. }
  368. $this->success(1,$floor_list);
  369. }
  370. //单独某一层的详细
  371. public function answer_info(){
  372. $answer_id = input('answer_id');
  373. //楼
  374. $floor_info = Db::name('topic_dongtai_answer')
  375. ->alias('a')
  376. ->field('a.*,user.nickname,user.avatar,user.gender')
  377. ->join('user','a.user_id = user.id','LEFT')
  378. ->where(['a.id'=>$answer_id])->find();
  379. $floor_info = info_domain_image($floor_info,['avatar']);
  380. $floor_info['createtime_text'] = get_last_time($floor_info['createtime']);
  381. //回复是否已赞
  382. $floor_info['is_good'] = $this->answer_is_good($answer_id,$this->auth->id);
  383. $floor_info['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$floor_info['dt_id'],'floor'=>$floor_info['floor'],'level'=>2])->count();
  384. //层
  385. $floors = $floor_info['floor'];
  386. $child_lists = Db::name('topic_dongtai_answer')->alias('a')
  387. ->field('a.*,user.nickname,user.avatar,user.gender,tuser.nickname as to_nickname,tuser.avatar as to_avatar,tuser.gender as to_gender')
  388. ->join('user','a.user_id = user.id','LEFT')
  389. ->join('user tuser','a.to_user_id = tuser.id','LEFT')
  390. ->where(['a.dt_id'=>$floor_info['dt_id'],'a.floor'=>$floors,'a.level'=>2])->order('a.id desc')->autopage()->select();
  391. $child_lists = list_domain_image($child_lists,['avatar','to_avatar']);
  392. if(!empty($child_lists)){
  393. foreach($child_lists as $key => &$answer){
  394. $answer['is_good'] = $this->answer_is_good($answer['id'],$this->auth->id);
  395. $answer['createtime_text'] = get_last_time($answer['createtime']);
  396. }
  397. }
  398. //合并
  399. $floor_info['child'] = $child_lists;
  400. $this->success('success',$floor_info);
  401. }
  402. //某个圈子里的动态列表,最新,推荐
  403. public function topic_list(){
  404. $where = [];
  405. $topic_id = input('topic_id',0);
  406. if($topic_id){
  407. $where['dt.topic_id'] = $topic_id;
  408. }
  409. $order = input('orderby','new');
  410. $orderby = 'dt.id desc';
  411. if($order == 'hot'){
  412. $orderby = 'dt.goodnum desc';
  413. }
  414. if($order == 'follow'){
  415. $follow_user_ids = Db::name('user_follow')->where(['uid'=>$this->auth->id])->column('follow_uid');
  416. $where['dt.user_id'] = ['IN',$follow_user_ids];
  417. }
  418. ////
  419. //排除屏蔽的
  420. $screen_ids = Db::name('topic_dongtai_screen')->where('user_id',$this->auth->id)->column('dt_id');
  421. if(!empty($screen_ids)){
  422. $where['dt.id'] = ['NOTIN',$screen_ids];
  423. }
  424. //排除黑名单的
  425. $where2 = [];
  426. $black_ids = Db::name('user_blacklist')->where('user_id',$this->auth->id)->column('black_user_id');
  427. if(!empty($black_ids)){
  428. $where2['dt.user_id'] = ['NOTIN',$black_ids];
  429. }
  430. //
  431. $list = Db::name('topic_dongtai')->alias('dt')
  432. ->join('user','dt.user_id = user.id','LEFT')
  433. ->join('topic_hub topic','dt.topic_id = topic.id','LEFT')
  434. ->field('dt.*,user.nickname,user.avatar,user.gender,topic.name as topic_name')
  435. ->where($where)
  436. ->where($where2)
  437. ->order($orderby)->autopage()->select();
  438. $list = list_domain_image($list,['images','avatar']);
  439. if(!empty($list)){
  440. foreach($list as $key => &$val){
  441. //追加点赞
  442. $val['isgood'] = $this->is_good($val['id'],$this->auth->id);
  443. //创建视频缩略图
  444. $val['images_thumb'] = '';
  445. if ($val['type'] == 2) {
  446. $images_url = explode('.', $val['images']);
  447. unset($images_url[count($images_url) - 1]);
  448. $val['images_thumb'] = join('.', $images_url) . '_0.jpg';
  449. }
  450. //时间
  451. $val['createtime_text'] = get_last_time($val['createtime']);
  452. //关注
  453. $val['is_follow'] = $this->is_follow($this->auth->id,$val['user_id']);
  454. //评论
  455. $val['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$val['id'],'level'=>1])->count();
  456. }
  457. }
  458. $this->success('success',$list);
  459. }
  460. ////////////////////////////////////////////////////////////
  461. //消息-互动消息-评论
  462. //谁评论了我
  463. public function msg_answer(){
  464. $map = [
  465. 'dt.user_id' => $this->auth->id,
  466. 'a.level' => 1,
  467. ];
  468. $list = Db::name('topic_dongtai_answer')->alias('a')
  469. ->field('a.id,a.createtime,user.nickname,user.gender,user.avatar')
  470. ->join('topic_dongtai dt','a.dt_id = dt.id','LEFT')
  471. ->join('user','a.user_id = user.id','LEFT')
  472. ->where($map)->order('a.id desc')->autopage()->select();
  473. $list = list_domain_image($list,['avatar']);
  474. if(!empty($list)){
  475. foreach($list as $key => &$val){
  476. //时间
  477. $val['createtime_text'] = get_last_time($val['createtime']);
  478. }
  479. }
  480. $this->success(1,$list);
  481. }
  482. //消息-互动消息-获赞
  483. //谁赞了我
  484. public function msg_good(){
  485. $map = [
  486. 'dt.user_id' => $this->auth->id,
  487. ];
  488. $list = Db::name('topic_dongtai_good')->alias('g')
  489. ->field('g.id,g.createtime,user.nickname,user.gender,user.avatar')
  490. ->join('topic_dongtai dt','g.dt_id = dt.id','LEFT')
  491. ->join('user','g.user_id = user.id','LEFT')
  492. ->where($map)->order('g.id desc')->autopage()->select();
  493. $list = list_domain_image($list,['avatar']);
  494. if(!empty($list)){
  495. foreach($list as $key => &$val){
  496. //时间
  497. $val['createtime_text'] = get_last_time($val['createtime']);
  498. }
  499. }
  500. $this->success(1,$list);
  501. }
  502. ////////////////////
  503. //我的评论
  504. public function my_answer(){
  505. $map = [
  506. 'a.user_id' => $this->auth->id,
  507. 'a.level' => 1,
  508. ];
  509. $list = Db::name('topic_dongtai_answer')->alias('a')
  510. ->field('a.id,a.createtime,a.content,a.dt_id,
  511. dt.images,dt.content as dt_content,dt.type as dt_type,dtuser.nickname as dtuser_nickname,dtuser.username as dtuser_username,user.username,
  512. user.nickname,user.avatar,user.gender,user.birthday,user.attribute,uw.vip_endtime')
  513. ->join('topic_dongtai dt','a.dt_id = dt.id','LEFT')
  514. ->join('user dtuser','dt.user_id = dtuser.id','LEFT')
  515. ->join('user user','a.user_id = user.id','LEFT')
  516. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  517. ->where($map)->order('a.id desc')->autopage()->select();
  518. $list = list_domain_image($list,['avatar']);
  519. if(!empty($list)){
  520. foreach($list as $key => &$val){
  521. //用户年龄
  522. $val['age'] = birthtime_to_age($val['birthday']);
  523. unset($val['birthday']);
  524. //用户vip
  525. $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
  526. unset($val['vip_endtime']);
  527. }
  528. }
  529. $this->success(1,$list);
  530. }
  531. //删除我的某个评论
  532. public function delete_answer(){
  533. $id = input('id',0);
  534. if(!$id){
  535. $this->error();
  536. }
  537. Db::startTrans();
  538. $info = Db::name('topic_dongtai_answer')->where('id',$id)->where('user_id',$this->auth->id)->find();
  539. if(!$info){
  540. $this->error('不存在的动态评论');
  541. }
  542. if($info['level'] == 1){
  543. //楼层内都删
  544. $louceng_id = Db::name('topic_dongtai_answer')->where('dt_id',$info['dt_id'])->where('level',2)->where('floor',$info['floor'])->column('id');
  545. if(!empty($louceng_id)){
  546. Db::name('topic_dongtai')->where('id',$info['dt_id'])->setDec('answernum',count($louceng_id));//回复数减1
  547. Db::name('topic_dongtai_answer')->where('id','IN',$louceng_id)->delete();//评论删掉
  548. Db::name('topic_answer_good')->where('answer_id','IN',$louceng_id)->delete();//评论点赞删掉
  549. }
  550. }
  551. Db::name('topic_dongtai')->where('id',$info['dt_id'])->setDec('answernum');//回复数减1
  552. Db::name('topic_dongtai_answer')->where('id',$id)->delete(); //评论删掉
  553. Db::name('topic_answer_good')->where('answer_id',$id)->delete();//评论点赞删掉
  554. Db::commit();
  555. $this->success();
  556. }
  557. //我点赞的动态
  558. public function my_good(){
  559. $where = ['good.user_id'=>$this->auth->id];
  560. $list = Db::name('topic_dongtai')->alias('dt')
  561. ->join('user','dt.user_id = user.id','LEFT')
  562. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  563. ->join('topic_dongtai_good good','dt.id = good.dt_id','LEFT')
  564. ->field('dt.*,dt.id as dt_id,user.username,user.nickname,user.avatar,user.gender,user.birthday,user.attribute,uw.vip_endtime')
  565. ->where($where)
  566. ->order('dt.id desc')->autopage()->select();
  567. $list = list_domain_image($list,['images','audio_file','avatar']);
  568. if(!empty($list)){
  569. foreach($list as $key => &$val){
  570. $val['aite'] = json_decode($val['aite'],true);
  571. //用户年龄
  572. $val['age'] = birthtime_to_age($val['birthday']);
  573. unset($val['birthday']);
  574. //用户vip
  575. $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
  576. unset($val['vip_endtime']);
  577. //追加点赞
  578. $val['isgood'] = $this->is_good($val['id'],$this->auth->id);
  579. //时间
  580. $val['createtime_text'] = get_last_time($val['createtime']);
  581. //关注
  582. $val['is_follow'] = $this->is_follow($this->auth->id,$val['user_id']);
  583. //收藏
  584. $val['is_collect'] = $this->is_collect($val['id'],$this->auth->id);
  585. //拉黑
  586. $val['is_black'] = $this->is_black($this->auth->id,$val['user_id']);
  587. //层主评论数量
  588. $val['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$val['id'],'level'=>1])->count();
  589. //话题
  590. $ids_str = $val['topic_ids'];
  591. if($ids_str){
  592. $val['topic_text'] = Db::name('topic_hub')->where('id','IN',$val['topic_ids'])->orderRaw('field(id,'.$ids_str.')')->column('name');
  593. }else{
  594. $val['topic_text'] = [];
  595. }
  596. }
  597. }
  598. $this->success('success',$list);
  599. }
  600. }