Topicdongtai.php 25 KB

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