Topicdongtai.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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',0);
  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. }
  172. $this->success('success',$info);
  173. }
  174. //点赞
  175. public function good(){
  176. $id = input('id');
  177. $where = [
  178. 'dt_id' => $id,
  179. 'user_id' => $this->auth->id,
  180. ];
  181. $check = Db::name('topic_dongtai_good')->where($where)->find();
  182. $dt_user_id = Db::name('topic_dongtai')->where('id',$id)->value('user_id');
  183. if($check){
  184. Db::name('topic_dongtai_good')->where($where)->delete();
  185. $down = Db::name('topic_dongtai')->where('id',$id)->setDec('goodnum');
  186. $this->success('已取消点赞');
  187. }else{
  188. Db::startTrans();
  189. $where['createtime'] = time();
  190. $rs = Db::name('topic_dongtai_good')->insertGetId($where);
  191. if(!$rs){
  192. Db::rollback();
  193. $this->error('点赞失败');
  194. }
  195. $up = Db::name('topic_dongtai')->where('id',$id)->setInc('goodnum');
  196. if($up === false){
  197. Db::rollback();
  198. $this->error('点赞失败');
  199. }
  200. //系统消息
  201. $msg_id = \app\common\model\Message::addMessage($dt_user_id,'动态点赞','有人赞了你的动态','dongtai_good',$id);
  202. Db::commit();
  203. $this->success('点赞成功');
  204. }
  205. }
  206. //评论
  207. public function answer(){
  208. $id = input('id',0);
  209. $content = input('content','');
  210. $to_user_id = input('to_user_id',0);
  211. $level = input('level',1); //回复类型:1=层主回复楼主,2=层中回复
  212. $floor = input('floor',0);
  213. if(empty($content) || empty($id)){
  214. $this->error();
  215. }
  216. //关键字替换
  217. $content = Keyworld::sensitive($content);
  218. //判断
  219. if($level == 2 && $floor == 0){
  220. $this->error('楼层错误');
  221. }
  222. //回复楼主,最新楼层
  223. if($level == 1 || $floor == 0){
  224. $to_user_id = 0;
  225. $floor = 1; //默认一楼
  226. $last_floor = Db::name('topic_dongtai_answer')->where(['dt_id'=>$id,'level'=>1])->order('floor desc')->value('floor');
  227. if($last_floor){
  228. $floor = $last_floor + 1;
  229. }
  230. }
  231. //判断user_id
  232. if($to_user_id){
  233. $to_user = Db::name('user')->where('id',$to_user_id)->value('id');
  234. if(empty($to_user)){
  235. $this->error('被回复的用户不存在');
  236. }
  237. }
  238. //data
  239. $data = [
  240. 'dt_id' => $id,
  241. 'floor' => $floor,
  242. 'user_id' => $this->auth->id,
  243. 'content' => $content,
  244. 'to_user_id' => $to_user_id,
  245. 'level' => $level,
  246. 'createtime' => time(),
  247. 'updatetime' => time(),
  248. ];
  249. Db::startTrans();
  250. $rs = Db::name('topic_dongtai_answer')->insertGetId($data);
  251. Db::name('topic_dongtai')->where('id',$id)->setInc('answernum');
  252. //系统消息
  253. if($level == 1){
  254. //发给动态用户
  255. $msg_user_id = Db::name('topic_dongtai')->where('id',$id)->value('user_id');
  256. $msg_title = '动态评论';
  257. $msg_content = '有人评论了你的动态';
  258. $infotype_id = $rs;
  259. }else{
  260. //发给层主
  261. $answer_info = Db::name('topic_dongtai_answer')->where(['dt_id'=>$id,'level'=>1,'floor'=>$floor])->find();
  262. $msg_user_id = $answer_info['user_id'];
  263. $msg_title = '动态评论点评';
  264. $msg_content = '有人点评了你的动态评论';
  265. $infotype_id = $answer_info['id'];
  266. }
  267. $msg_id = \app\common\model\Message::addMessage($msg_user_id,$msg_title,$msg_content,'dongtai_answer',$infotype_id);
  268. Db::commit();
  269. $this->success('评价成功');
  270. }
  271. //对评论点赞
  272. public function answer_good(){
  273. $dt_id = input('dt_id',0);
  274. $answer_id = input('answer_id',0);
  275. $where = [
  276. 'dt_id' => $dt_id,
  277. 'answer_id' => $answer_id,
  278. 'user_id' => $this->auth->id,
  279. ];
  280. $check = Db::name('topic_answer_good')->where($where)->find();
  281. if($check){
  282. Db::name('topic_answer_good')->where($where)->delete();
  283. Db::name('topic_dongtai_answer')->where('id',$answer_id)->setDec('goodnum');
  284. $this->success('已取消点赞');
  285. }
  286. Db::startTrans();
  287. $where['createtime'] = time();
  288. $rs = Db::name('topic_answer_good')->insertGetId($where);
  289. $up = Db::name('topic_dongtai_answer')->where('id',$answer_id)->setInc('goodnum');
  290. if($rs && $up !== false){
  291. Db::commit();
  292. $this->success('点赞成功');
  293. }
  294. Db::rollback();
  295. $this->error('点赞失败');
  296. }
  297. //举报枚举
  298. /* public function report_enum(){
  299. $arr = [
  300. '侮辱谩骂',
  301. '色情低俗',
  302. '整治敏感',
  303. '违法违规',
  304. '其他',
  305. ];
  306. $this->success(1,$arr);
  307. }
  308. //举报
  309. public function report(){
  310. $field = ['dt_id','type','content','images'];
  311. $data = request_post_hub($field);
  312. $check = Db::name('topic_dongtai')->where('id',$data['dt_id'])->find();
  313. $data['user_id'] = $this->auth->id;
  314. $data['ruser_id'] = $check['user_id'];
  315. $data['createtime'] = time();
  316. Db::name('topic_dongtai_report')->insertGetId($data);
  317. $this->success('举报成功');
  318. }*/
  319. //不感兴趣,屏蔽某条
  320. public function screen(){
  321. $data = [
  322. 'user_id' => $this->auth->id,
  323. 'dt_id' => input('dt_id',0),
  324. ];
  325. $check = Db::name('topic_dongtai_screen')->where($data)->find();
  326. if($check){
  327. $this->success('操作成功');
  328. }
  329. Db::name('topic_dongtai_screen')->insertGetId($data);
  330. $this->success('操作成功');
  331. }
  332. //评论列表
  333. public function answer_list(){
  334. $dt_id = input('dt_id',0);
  335. //楼
  336. $floor_list = Db::name('topic_dongtai_answer')
  337. ->alias('a')
  338. ->field('a.*,user.nickname,user.avatar,user.gender')
  339. ->join('user','a.user_id = user.id','LEFT')
  340. ->where(['a.dt_id'=>$dt_id,'a.level'=>1])->order('a.id desc')->autopage()->select();
  341. $floor_list = list_domain_image($floor_list,['avatar']);
  342. //追加子评论
  343. if(!empty($floor_list)){
  344. foreach($floor_list as $key => &$val){
  345. //下面几条子回复,字符串
  346. $val['childremark'] = '';
  347. $map = [
  348. 'a.dt_id' => $dt_id,
  349. 'a.floor' => $val['floor'],
  350. 'a.level' => 2,
  351. ];
  352. $number = Db::name('topic_dongtai_answer')->alias('a')->where($map)->count();
  353. if($number > 0){
  354. $answer_info = Db::name('topic_dongtai_answer')
  355. ->alias('a')
  356. ->field('user.nickname')
  357. ->join('user','a.user_id = user.id','LEFT')
  358. ->where($map)->order('a.id desc')->find();
  359. $val['childremark'] = $answer_info['nickname'].'...等人,共'.$number.'条回复';
  360. }
  361. //时间处理
  362. $val['createtime_text'] = get_last_time($val['createtime']);
  363. //回复是否已赞
  364. $val['is_good'] = $this->answer_is_good($val['id'],$this->auth->id);
  365. }
  366. }
  367. $this->success(1,$floor_list);
  368. }
  369. //单独某一层的详细
  370. public function answer_info(){
  371. $answer_id = input('answer_id');
  372. //楼
  373. $floor_info = Db::name('topic_dongtai_answer')
  374. ->alias('a')
  375. ->field('a.*,user.nickname,user.avatar,user.gender')
  376. ->join('user','a.user_id = user.id','LEFT')
  377. ->where(['a.id'=>$answer_id])->find();
  378. $floor_info = info_domain_image($floor_info,['avatar']);
  379. $floor_info['createtime_text'] = get_last_time($floor_info['createtime']);
  380. //回复是否已赞
  381. $floor_info['is_good'] = $this->answer_is_good($answer_id,$this->auth->id);
  382. $floor_info['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$floor_info['dt_id'],'floor'=>$floor_info['floor'],'level'=>2])->count();
  383. //层
  384. $floors = $floor_info['floor'];
  385. $child_lists = Db::name('topic_dongtai_answer')->alias('a')
  386. ->field('a.*,user.nickname,user.avatar,user.gender,tuser.nickname as to_nickname,tuser.avatar as to_avatar,tuser.gender as to_gender')
  387. ->join('user','a.user_id = user.id','LEFT')
  388. ->join('user tuser','a.to_user_id = tuser.id','LEFT')
  389. ->where(['a.dt_id'=>$floor_info['dt_id'],'a.floor'=>$floors,'a.level'=>2])->order('a.id desc')->autopage()->select();
  390. $child_lists = list_domain_image($child_lists,['avatar','to_avatar']);
  391. if(!empty($child_lists)){
  392. foreach($child_lists as $key => &$answer){
  393. $answer['is_good'] = $this->answer_is_good($answer['id'],$this->auth->id);
  394. $answer['createtime_text'] = get_last_time($answer['createtime']);
  395. }
  396. }
  397. //合并
  398. $floor_info['child'] = $child_lists;
  399. $this->success('success',$floor_info);
  400. }
  401. //某个圈子里的动态列表,最新,推荐,关注
  402. public function topic_list(){
  403. $where = [];
  404. $topic_id = input('topic_id',0);
  405. if($topic_id){
  406. $where['dt.topic_id'] = $topic_id;
  407. }
  408. $order = input('orderby','new');
  409. $orderby = 'dt.id desc';
  410. if($order == 'hot'){
  411. $orderby = 'dt.goodnum desc';
  412. }
  413. if($order == 'follow'){
  414. $follow_user_ids = Db::name('user_follow')->where(['uid'=>$this->auth->id])->column('follow_uid');
  415. $where['dt.user_id'] = ['IN',$follow_user_ids];
  416. }
  417. ////
  418. //排除屏蔽的
  419. $screen_ids = Db::name('topic_dongtai_screen')->where('user_id',$this->auth->id)->column('dt_id');
  420. if(!empty($screen_ids)){
  421. $where['dt.id'] = ['NOTIN',$screen_ids];
  422. }
  423. //排除黑名单的
  424. $where2 = [];
  425. $black_ids = Db::name('user_blacklist')->where('user_id',$this->auth->id)->column('black_user_id');
  426. if(!empty($black_ids)){
  427. $where2['dt.user_id'] = ['NOTIN',$black_ids];
  428. }
  429. //
  430. $list = Db::name('topic_dongtai')->alias('dt')
  431. ->join('user','dt.user_id = user.id','LEFT')
  432. ->join('topic_hub topic','dt.topic_id = topic.id','LEFT')
  433. ->field('dt.*,user.nickname,user.avatar,user.gender,topic.name as topic_name')
  434. ->where($where)
  435. ->where($where2)
  436. ->order($orderby)->autopage()->select();
  437. $list = list_domain_image($list,['images','avatar']);
  438. if(!empty($list)){
  439. foreach($list as $key => &$val){
  440. //追加点赞
  441. $val['isgood'] = $this->is_good($val['id'],$this->auth->id);
  442. //创建视频缩略图
  443. $val['images_thumb'] = '';
  444. if ($val['type'] == 2) {
  445. $images_url = explode('.', $val['images']);
  446. unset($images_url[count($images_url) - 1]);
  447. $val['images_thumb'] = join('.', $images_url) . '_0.jpg';
  448. }
  449. //时间
  450. $val['createtime_text'] = get_last_time($val['createtime']);
  451. //关注
  452. $val['is_follow'] = $this->is_follow($this->auth->id,$val['user_id']);
  453. //评论
  454. $val['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$val['id'],'level'=>1])->count();
  455. }
  456. }
  457. $this->success('success',$list);
  458. }
  459. ////////////////////////////////////////////////////////////
  460. //消息-互动消息-评论
  461. //谁评论了我的动态
  462. public function msg_answer(){
  463. $map = [
  464. 'dt.user_id' => $this->auth->id,
  465. 'a.level' => 1,
  466. ];
  467. $list = Db::name('topic_dongtai_answer')->alias('a')
  468. ->field('a.id,a.createtime,user.nickname,user.gender,user.avatar')
  469. ->join('topic_dongtai dt','a.dt_id = dt.id','LEFT')
  470. ->join('user','a.user_id = user.id','LEFT')
  471. ->where($map)->order('a.id desc')->autopage()->select();
  472. $list = list_domain_image($list,['avatar']);
  473. if(!empty($list)){
  474. foreach($list as $key => &$val){
  475. //时间
  476. $val['createtime_text'] = get_last_time($val['createtime']);
  477. }
  478. }
  479. $this->success(1,$list);
  480. }
  481. //消息-互动消息-获赞
  482. //谁赞了我的动态
  483. public function msg_good(){
  484. $map = [
  485. 'dt.user_id' => $this->auth->id,
  486. ];
  487. $list = Db::name('topic_dongtai_good')->alias('g')
  488. ->field('g.id,g.createtime,user.nickname,user.gender,user.avatar')
  489. ->join('topic_dongtai dt','g.dt_id = dt.id','LEFT')
  490. ->join('user','g.user_id = user.id','LEFT')
  491. ->where($map)->order('g.id desc')->autopage()->select();
  492. $list = list_domain_image($list,['avatar']);
  493. if(!empty($list)){
  494. foreach($list as $key => &$val){
  495. //时间
  496. $val['createtime_text'] = get_last_time($val['createtime']);
  497. }
  498. }
  499. $this->success(1,$list);
  500. }
  501. ////////////////////
  502. //我的评论
  503. public function my_answer(){
  504. $map = [
  505. 'a.user_id' => $this->auth->id,
  506. 'a.level' => 1,
  507. ];
  508. $list = Db::name('topic_dongtai_answer')->alias('a')
  509. ->field('a.id,a.createtime,a.content,a.dt_id,
  510. dt.images,dt.content as dt_content,dt.type as dt_type,dtuser.nickname as dtuser_nickname,dtuser.username as dtuser_username,user.username,
  511. user.nickname,user.avatar,user.gender,user.birthday,user.attribute,uw.vip_endtime')
  512. ->join('topic_dongtai dt','a.dt_id = dt.id','LEFT')
  513. ->join('user dtuser','dt.user_id = dtuser.id','LEFT')
  514. ->join('user user','a.user_id = user.id','LEFT')
  515. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  516. ->where($map)->order('a.id desc')->autopage()->select();
  517. $list = list_domain_image($list,['avatar']);
  518. if(!empty($list)){
  519. foreach($list as $key => &$val){
  520. //用户年龄
  521. $val['age'] = birthtime_to_age($val['birthday']);
  522. unset($val['birthday']);
  523. //用户vip
  524. $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
  525. unset($val['vip_endtime']);
  526. }
  527. }
  528. $this->success(1,$list);
  529. }
  530. //删除我的某个评论
  531. public function delete_answer(){
  532. $id = input('id',0);
  533. if(!$id){
  534. $this->error();
  535. }
  536. Db::startTrans();
  537. $info = Db::name('topic_dongtai_answer')->where('id',$id)->where('user_id',$this->auth->id)->find();
  538. if(!$info){
  539. $this->error('不存在的动态评论');
  540. }
  541. if($info['level'] == 1){
  542. //楼层内都删
  543. $louceng_id = Db::name('topic_dongtai_answer')->where('dt_id',$info['dt_id'])->where('level',2)->where('floor',$info['floor'])->column('id');
  544. if(!empty($louceng_id)){
  545. Db::name('topic_dongtai')->where('id',$info['dt_id'])->setDec('answernum',count($louceng_id));//回复数减1
  546. Db::name('topic_dongtai_answer')->where('id','IN',$louceng_id)->delete();//评论删掉
  547. Db::name('topic_answer_good')->where('answer_id','IN',$louceng_id)->delete();//评论点赞删掉
  548. }
  549. }
  550. Db::name('topic_dongtai')->where('id',$info['dt_id'])->setDec('answernum');//回复数减1
  551. Db::name('topic_dongtai_answer')->where('id',$id)->delete(); //评论删掉
  552. Db::name('topic_answer_good')->where('answer_id',$id)->delete();//评论点赞删掉
  553. Db::commit();
  554. $this->success();
  555. }
  556. //我点赞的动态
  557. public function my_good(){
  558. $where = ['good.user_id'=>$this->auth->id];
  559. $list = Db::name('topic_dongtai')->alias('dt')
  560. ->join('user','dt.user_id = user.id','LEFT')
  561. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  562. ->join('topic_dongtai_good good','dt.id = good.dt_id','LEFT')
  563. ->field('dt.*,dt.id as dt_id,user.username,user.nickname,user.avatar,user.gender,user.birthday,user.attribute,uw.vip_endtime')
  564. ->where($where)
  565. ->order('dt.id desc')->autopage()->select();
  566. $list = list_domain_image($list,['images','audio_file','avatar']);
  567. if(!empty($list)){
  568. foreach($list as $key => &$val){
  569. $val['aite'] = json_decode($val['aite'],true);
  570. //用户年龄
  571. $val['age'] = birthtime_to_age($val['birthday']);
  572. unset($val['birthday']);
  573. //用户vip
  574. $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
  575. unset($val['vip_endtime']);
  576. //追加点赞
  577. $val['isgood'] = $this->is_good($val['id'],$this->auth->id);
  578. //时间
  579. $val['createtime_text'] = get_last_time($val['createtime']);
  580. //关注
  581. $val['is_follow'] = $this->is_follow($this->auth->id,$val['user_id']);
  582. //收藏
  583. $val['is_collect'] = $this->is_collect($val['id'],$this->auth->id);
  584. //拉黑
  585. $val['is_black'] = $this->is_black($this->auth->id,$val['user_id']);
  586. //层主评论数量
  587. $val['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$val['id'],'level'=>1])->count();
  588. //话题
  589. $ids_str = $val['topic_ids'];
  590. if($ids_str){
  591. $val['topic_text'] = Db::name('topic_hub')->where('id','IN',$val['topic_ids'])->orderRaw('field(id,'.$ids_str.')')->column('name');
  592. }else{
  593. $val['topic_text'] = [];
  594. }
  595. }
  596. }
  597. $this->success('success',$list);
  598. }
  599. }