Topicdongtai.php 25 KB

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