Topicdongtai.php 27 KB

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