Topicdongtai.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  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 = ['poi','poi2'];
  13. protected $noNeedRight = ['*'];
  14. //发布动态
  15. public function addone(){
  16. $content = input('content','');
  17. $images = input('images','');
  18. $audio_file = input('audio_file','');
  19. $aite = input('aite','','htmlspecialchars_decode');
  20. $type = input('type',1);
  21. $audio_second = input('audio_second',0);
  22. if(!$content && !$images && !$audio_file){
  23. $this->error(__('Invalid parameters'));
  24. }
  25. if(!$this->user_auth_limit()){
  26. $this->error('请先完成实名认证');
  27. }
  28. //关键字替换
  29. $content = Keyworld::sensitive($content);
  30. //只保留一个
  31. if($type == 1){
  32. $audio_file = '';
  33. $audio_second = 0;
  34. }else{
  35. $images = '';
  36. }
  37. $data = [
  38. 'user_id' => $this->auth->id,
  39. 'content' => $content,
  40. 'images' => $images,
  41. 'audio_file' => $audio_file,
  42. 'type' => $type,
  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. 'address' => input('address',''),
  49. 'createtime' => time(),
  50. 'updatetime' => time(),
  51. 'auditstatus' => 1, //默认通过
  52. ];
  53. //如果强制审核,默认不通过
  54. $dongtai_audit_switch = config('site.dongtai_audit_switch');
  55. if($dongtai_audit_switch == 1){
  56. $data['auditstatus'] = 0;
  57. }
  58. Db::startTrans();
  59. $id = Db::name('topic_dongtai')->insertGetId($data);
  60. //task任务
  61. //发第一条动态
  62. $task_count = Db::name('topic_dongtai')->where('user_id',$this->auth->id)->count();
  63. if($task_count == 1){
  64. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,16);
  65. if($task_rs === false){
  66. Db::rollback();
  67. $this->error('完成任务失败');
  68. }
  69. }
  70. //通知艾特的人
  71. if(!empty($aite)){
  72. $aite = json_decode($aite,true);
  73. if(!empty($aite) && is_array($aite)){
  74. foreach($aite as $key => $uid){
  75. //系统消息
  76. if(is_array($uid) && isset($uid['id'])){
  77. $msg_id = \app\common\model\Message::addMessage($uid['id'],'动态通知',$this->auth->nickname.'发布动态并@了你,快去看看吧','dongtai_aite',$id);
  78. }
  79. }
  80. }
  81. }
  82. Db::commit();
  83. $this->success('发布成功',$id);
  84. }
  85. //自己看列表
  86. //某用户的帖子列表
  87. public function my_lists(){
  88. $page = input('page',1);
  89. if($page > 1){
  90. $this->success('success',[]);
  91. }
  92. $uid = input('uid',$this->auth->id);
  93. if (empty($uid)) {
  94. $uid = $this->auth->id;
  95. }
  96. $where = [
  97. 'dt.user_id'=>$uid,
  98. ];
  99. if($uid != $this->auth->id){
  100. $where['dt.is_public'] = 1; //不是自己的,就只能看公开的。公开:1=公开,2=私密
  101. $where['dt.auditstatus'] = 1; //不是自己的,就只能看审核通过的
  102. }
  103. $list = Db::name('topic_dongtai')->alias('dt')
  104. ->join('user','dt.user_id = user.id','LEFT')
  105. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  106. ->field('dt.*,user.username,user.nickname,user.avatar,user.gender,user.birthday,user.idcard_status,uw.vip_endtime')
  107. ->where($where)
  108. ->order('dt.id desc')->select();
  109. $list = list_domain_image($list,['images','audio_file','avatar']);
  110. if(!empty($list)){
  111. foreach($list as $key => &$val){
  112. $val['aite'] = json_decode($val['aite'],true);
  113. //用户年龄
  114. $val['age'] = birthtime_to_age($val['birthday']);
  115. unset($val['birthday']);
  116. //用户vip
  117. $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
  118. unset($val['vip_endtime']);
  119. //追加点赞
  120. $val['isgood'] = $this->is_good($val['id'],$this->auth->id);
  121. //时间
  122. $val['createtime_text'] = get_last_time($val['createtime']);
  123. //关注
  124. $val['is_follow'] = $this->is_follow($this->auth->id,$val['user_id']);
  125. //收藏
  126. $val['is_collect'] = $this->is_collect($val['id'],$this->auth->id);
  127. //拉黑
  128. $val['is_black'] = $this->is_black($this->auth->id,$val['user_id']);
  129. //层主评论数量
  130. $val['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$val['id'],'level'=>1])->count();
  131. //话题
  132. $val['topic_text'] = [];
  133. }
  134. }
  135. $this->success('success',$list);
  136. }
  137. //动态删除
  138. public function delete(){
  139. $id = input('id',0);
  140. $where['id'] = $id;
  141. $where['user_id'] = $this->auth->id;
  142. Db::startTrans();
  143. $delRes = Db::name('topic_dongtai')->where('id',$id)->where('user_id',$this->auth->id)->delete();
  144. if (!$delRes) {
  145. Db::rollback();
  146. $this->error('动态删除失败');
  147. }
  148. //删除对应的评论,
  149. Db::name('topic_dongtai_answer')->where('dt_id',$id)->delete();
  150. //点赞,
  151. Db::name('topic_dongtai_good')->where('dt_id',$id)->delete();
  152. //评论点赞
  153. Db::name('topic_answer_good')->where('dt_id',$id)->delete();
  154. Db::commit();
  155. $this->success('删除成功');
  156. }
  157. //某个圈子里的动态列表,关注,最新,附近
  158. public function topic_list(){
  159. $where = [
  160. 'dt.is_public' => 1,
  161. 'dt.auditstatus' => 1,
  162. ];
  163. //最新
  164. $order = input('orderby','new');
  165. $orderby = 'dt.toptime desc,dt.id desc';
  166. //关注
  167. $where_follow = '';
  168. if($order == 'follow'){
  169. //关注的人
  170. $follow_user_ids = Db::name('user_follow')->where(['uid'=>$this->auth->id])->column('follow_uid');
  171. if(!empty($follow_user_ids)){
  172. $where_follow .= '(dt.user_id IN ('.implode(',',$follow_user_ids).'))';
  173. }
  174. //默认
  175. if($where_follow == ''){
  176. $where_follow = 'dt.id = 0';
  177. }
  178. }
  179. //附近,根据距离排序
  180. $having_dis = '';
  181. if($order == 'near'){
  182. $having_dis = 'distance < ' . 100000; //100公里范围
  183. $orderby = 'dt.toptime desc,distance asc,dt.id desc';
  184. }
  185. //性别
  186. $gender = input('gender','all');
  187. if($gender != 'all'){
  188. $where['user.gender'] = $gender;
  189. }
  190. //排除黑名单的
  191. $where_black = [];
  192. $black_ids = Db::name('user_black')->where(['uid'=>$this->auth->id])->column('black_uid');
  193. if(!empty($black_ids)){
  194. $where_black['dt.user_id'] = ['NOTIN',$black_ids];
  195. }
  196. //列表
  197. $field = 'dt.*,user.username,user.nickname,user.avatar,user.gender,user.birthday,user.idcard_status,uw.vip_endtime';
  198. if($order == 'near'){
  199. $field .= ',(st_distance(point (' . $this->auth->longitude . ', ' . $this->auth->latitude . '),point(dt.longitude,dt.latitude))*111195) as distance';
  200. }
  201. $list = Db::name('topic_dongtai')->alias('dt')
  202. ->join('user','dt.user_id = user.id','LEFT')
  203. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  204. ->field($field)
  205. ->where($where)
  206. ->where($where_follow)
  207. ->where($where_black);
  208. if($order == 'near'){
  209. $list = $list->having($having_dis);
  210. }
  211. $list = $list->order($orderby)
  212. ->autopage()->select();
  213. $list = list_domain_image($list,['images','audio_file','avatar']);
  214. if(!empty($list)){
  215. foreach($list as $key => &$val){
  216. //艾特
  217. $val['aite'] = json_decode($val['aite'],true);
  218. //距离
  219. $val['distance'] = isset($val['distance']) ? $val['distance'] : 0;
  220. $val['distance'] = bcdiv(intval($val['distance']),1000,1).'km';
  221. if($this->auth->longitude == 0 || $val['longitude'] == 0){
  222. $val['distance'] = '未知';
  223. }
  224. //vip如果开了隐私保护,需要隐藏距离
  225. $yinsi = $this->user_power($val['user_id'],'yinsi');
  226. if($yinsi == 1){
  227. $val['distance'] = '';
  228. }
  229. //用户年龄
  230. $val['age'] = birthtime_to_age($val['birthday']);
  231. unset($val['birthday']);
  232. //用户vip
  233. $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
  234. unset($val['vip_endtime']);
  235. //追加点赞
  236. $val['isgood'] = $this->is_good($val['id'],$this->auth->id);
  237. //时间
  238. $val['createtime_text'] = get_last_time($val['createtime']);
  239. //关注
  240. $val['is_follow'] = $this->is_follow($this->auth->id,$val['user_id']);
  241. //收藏
  242. $val['is_collect'] = $this->is_collect($val['id'],$this->auth->id);
  243. //拉黑
  244. $val['is_black'] = $this->is_black($this->auth->id,$val['user_id']);
  245. //层主评论数量
  246. $val['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$val['id'],'level'=>1])->count();
  247. //话题
  248. $val['topic_text'] = [];
  249. //艾特了谁
  250. // $val['aite_user'] = Db::name('user')->where('id','IN',$val['aite'])->column('nickname');
  251. }
  252. }
  253. $this->success('success',$list);
  254. }
  255. //详情
  256. public function info(){
  257. $id = input('id');
  258. $info = Db::name('topic_dongtai')->alias('dt')
  259. ->join('user','dt.user_id = user.id','LEFT')
  260. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  261. ->field('dt.*,user.username,user.nickname,user.avatar,user.gender,user.birthday,user.idcard_status,uw.vip_endtime')
  262. ->where('dt.id',$id)->find();
  263. $info = info_domain_image($info,['images','audio_file','avatar']);
  264. if($info){
  265. $info['aite'] = json_decode($info['aite'],true);
  266. //用户年龄
  267. $info['age'] = birthtime_to_age($info['birthday']);
  268. unset($info['birthday']);
  269. //用户vip
  270. $info['is_vip'] = $info['vip_endtime'] > time() ? 1 : 0;
  271. unset($info['vip_endtime']);
  272. //是否点赞过
  273. $info['isgood'] = $this->is_good($id,$this->auth->id);
  274. //时间
  275. $info['createtime_text'] = get_last_time($info['createtime']);
  276. //关注
  277. $info['is_follow'] = $this->is_follow($this->auth->id,$info['user_id']);
  278. //收藏
  279. $info['is_collect'] = $this->is_collect($id,$this->auth->id);
  280. //拉黑
  281. $info['is_black'] = $this->is_black($this->auth->id,$info['user_id']);
  282. //层主评论数量
  283. $info['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$id,'level'=>1])->count();
  284. //话题
  285. $info['topic_text'] = [];
  286. }else{
  287. $this->error('此动态已被删除');
  288. }
  289. $this->success('success',$info);
  290. }
  291. //点赞,取消点赞
  292. public function good(){
  293. $id = input('id');
  294. $where = [
  295. 'dt_id' => $id,
  296. 'user_id' => $this->auth->id,
  297. ];
  298. $check = Db::name('topic_dongtai_good')->where($where)->find();
  299. $dt_user_id = Db::name('topic_dongtai')->where('id',$id)->value('user_id');
  300. if($check){
  301. Db::name('topic_dongtai_good')->where($where)->delete();
  302. $down = Db::name('topic_dongtai')->where('id',$id)->setDec('goodnum');
  303. $this->success('已取消点赞');
  304. }else{
  305. Db::startTrans();
  306. $where['createtime'] = time();
  307. $rs = Db::name('topic_dongtai_good')->insertGetId($where);
  308. if(!$rs){
  309. Db::rollback();
  310. $this->error('点赞失败');
  311. }
  312. $up = Db::name('topic_dongtai')->where('id',$id)->setInc('goodnum');
  313. if($up === false){
  314. Db::rollback();
  315. $this->error('点赞失败');
  316. }
  317. //系统消息
  318. if($dt_user_id != $this->auth->id){
  319. $msg_id = \app\common\model\Message::addMessage($dt_user_id,'动态点赞',$this->auth->nickname.'('.$this->auth->username.')赞了你的动态','dongtai_good',$id);
  320. }
  321. Db::commit();
  322. $this->success('点赞成功');
  323. }
  324. }
  325. //评论
  326. public function answer(){
  327. if($this->apiLimit(1,5000) == false){
  328. $this->error('抱歉,您在5秒内只能进行一次回复');
  329. }
  330. $id = input('id',0);
  331. $content = input('content','');
  332. $to_user_id = input('to_user_id',0);
  333. $level = input('level',1); //回复类型:1=层主回复楼主,2=层中回复
  334. $floor = input('floor',0);
  335. if(empty($content) || empty($id)){
  336. $this->error();
  337. }
  338. //判断
  339. if($level == 2 && $floor == 0){
  340. $this->error('楼层错误');
  341. }
  342. //黑名单判断
  343. //是否被动态发布者拉黑
  344. $dongtai_user_id = Db::name('topic_dongtai')->where('id',$id)->value('user_id');
  345. $black_check = $this->is_black($dongtai_user_id,$this->auth->id);
  346. if($black_check){
  347. $this->error('您已被对方拉黑,禁止评论此动态');
  348. }
  349. //是否被层主拉黑
  350. if($level == 2){
  351. $answer_info = Db::name('topic_dongtai_answer')->where(['dt_id'=>$id,'level'=>1,'floor'=>$floor])->find();
  352. $black_check = $this->is_black($answer_info['user_id'],$this->auth->id);
  353. if($black_check){
  354. $this->error('您已被对方拉黑,禁止点评此评论');
  355. }
  356. }
  357. //关键字替换
  358. $content = Keyworld::sensitive($content);
  359. //回复楼主,最新楼层
  360. if($level == 1 || $floor == 0){
  361. $to_user_id = 0;
  362. $floor = 1; //默认一楼
  363. $last_floor = Db::name('topic_dongtai_answer')->where(['dt_id'=>$id,'level'=>1])->order('floor desc')->value('floor');
  364. if($last_floor){
  365. $floor = $last_floor + 1;
  366. }
  367. }
  368. //判断user_id
  369. if($to_user_id){
  370. $to_user = Db::name('user')->where('id',$to_user_id)->value('id');
  371. if(empty($to_user)){
  372. $this->error('被回复的用户不存在');
  373. }
  374. }
  375. //data
  376. $data = [
  377. 'dt_id' => $id,
  378. 'floor' => $floor,
  379. 'user_id' => $this->auth->id,
  380. 'content' => $content,
  381. 'to_user_id' => $to_user_id,
  382. 'level' => $level,
  383. 'createtime' => time(),
  384. 'updatetime' => time(),
  385. ];
  386. Db::startTrans();
  387. $rs = Db::name('topic_dongtai_answer')->insertGetId($data);
  388. Db::name('topic_dongtai')->where('id',$id)->setInc('answernum');
  389. //系统消息
  390. if($level == 1){
  391. //发给动态用户
  392. $msg_user_id = Db::name('topic_dongtai')->where('id',$id)->value('user_id');
  393. $msg_title = '动态评论';
  394. $msg_content = $this->auth->nickname.'评论了你的动态';
  395. $infotype_id = $rs;
  396. }else{
  397. //发给层主
  398. $answer_info = Db::name('topic_dongtai_answer')->where(['dt_id'=>$id,'level'=>1,'floor'=>$floor])->find();
  399. $msg_user_id = $answer_info['user_id'];
  400. $msg_title = '动态评论点评';
  401. $msg_content = $this->auth->nickname.'点评了你的动态评论';
  402. $infotype_id = $answer_info['id'];
  403. }
  404. $msg_id = \app\common\model\Message::addMessage($msg_user_id,$msg_title,$msg_content,'dongtai_answer',$infotype_id);
  405. Db::commit();
  406. $this->success('评论成功');
  407. }
  408. //对评论点赞
  409. public function answer_good(){
  410. $dt_id = input('dt_id',0);
  411. $answer_id = input('answer_id',0);
  412. $where = [
  413. 'dt_id' => $dt_id,
  414. 'answer_id' => $answer_id,
  415. 'user_id' => $this->auth->id,
  416. ];
  417. $check = Db::name('topic_answer_good')->where($where)->find();
  418. if($check){
  419. Db::name('topic_answer_good')->where($where)->delete();
  420. Db::name('topic_dongtai_answer')->where('id',$answer_id)->setDec('goodnum');
  421. $this->success('已取消点赞');
  422. }else{
  423. Db::startTrans();
  424. $where['createtime'] = time();
  425. $rs = Db::name('topic_answer_good')->insertGetId($where);
  426. $up = Db::name('topic_dongtai_answer')->where('id',$answer_id)->setInc('goodnum');
  427. if($rs && $up !== false){
  428. Db::commit();
  429. $this->success('点赞成功');
  430. }
  431. Db::rollback();
  432. $this->error('点赞失败');
  433. }
  434. }
  435. //举报枚举
  436. /*public function report_enum(){
  437. $arr = [
  438. '侮辱谩骂',
  439. '色情低俗',
  440. '政治敏感',
  441. '违法违规',
  442. '其他',
  443. ];
  444. $this->success(1,$arr);
  445. }*/
  446. //举报
  447. public function report(){
  448. $dt_id = input('dt_id',0);
  449. $data['dt_id'] = $dt_id;
  450. $check = Db::name('topic_dongtai')->where('id',$data['dt_id'])->find();
  451. if(empty($check)){
  452. $this->error('不存在的动态');
  453. }
  454. $data['user_id'] = $this->auth->id;
  455. $data['to_user_id'] = $check['user_id'];
  456. $data['createtime'] = time();
  457. Db::name('topic_dongtai_report')->insertGetId($data);
  458. $this->success('举报成功');
  459. }
  460. //收藏,取消收藏
  461. public function collect(){
  462. $where = [
  463. 'user_id' => $this->auth->id,
  464. 'table' => 'topic_dongtai',
  465. 'table_id' => input('id',0),
  466. ];
  467. $check = Db::name('user_collect')->where($where)->find();
  468. if($check){
  469. Db::name('user_collect')->where($where)->delete();
  470. $this->success('已取消收藏');
  471. }else{
  472. Db::name('user_collect')->insertGetId($where);
  473. $this->success('收藏成功');
  474. }
  475. }
  476. //我的收藏
  477. public function my_collect(){
  478. $collect_id = Db::name('user_collect')->where(['table'=>'topic_dongtai','user_id'=>$this->auth->id])->column('table_id');
  479. $where = ['dt.id'=>['IN',$collect_id]];
  480. $list = Db::name('topic_dongtai')->alias('dt')
  481. ->join('user','dt.user_id = user.id','LEFT')
  482. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  483. ->field('dt.*,user.username,user.nickname,user.avatar,user.gender,user.birthday,user.idcard_status,uw.vip_endtime')
  484. ->where($where)
  485. ->order('dt.id desc')->autopage()->select();
  486. $list = list_domain_image($list,['images','audio_file','avatar']);
  487. if(!empty($list)){
  488. foreach($list as $key => &$val){
  489. $val['aite'] = json_decode($val['aite'],true);
  490. //用户年龄
  491. $val['age'] = birthtime_to_age($val['birthday']);
  492. unset($val['birthday']);
  493. //用户vip
  494. $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
  495. unset($val['vip_endtime']);
  496. //追加点赞
  497. $val['isgood'] = $this->is_good($val['id'],$this->auth->id);
  498. //时间
  499. $val['createtime_text'] = get_last_time($val['createtime']);
  500. //关注
  501. $val['is_follow'] = $this->is_follow($this->auth->id,$val['user_id']);
  502. //收藏
  503. $val['is_collect'] = $this->is_collect($val['id'],$this->auth->id);
  504. //拉黑
  505. $val['is_black'] = $this->is_black($this->auth->id,$val['user_id']);
  506. //层主评论数量
  507. $val['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$val['id'],'level'=>1])->count();
  508. //话题
  509. $val['topic_text'] = [];
  510. }
  511. }
  512. $this->success('success',$list);
  513. }
  514. //不感兴趣,屏蔽某条
  515. /*public function screen(){
  516. $data = [
  517. 'user_id' => $this->auth->id,
  518. 'dt_id' => input('dt_id',0),
  519. ];
  520. $check = Db::name('topic_dongtai_screen')->where($data)->find();
  521. if($check){
  522. $this->success('操作成功');
  523. }
  524. Db::name('topic_dongtai_screen')->insertGetId($data);
  525. $this->success('操作成功');
  526. }*/
  527. //评论列表
  528. public function answer_list(){
  529. $dt_id = input('dt_id',0);
  530. //楼
  531. $floor_list = Db::name('topic_dongtai_answer')
  532. ->alias('a')
  533. ->field('a.*,user.username,user.nickname,user.avatar,user.gender,user.birthday,user.idcard_status')
  534. ->join('user','a.user_id = user.id','LEFT')
  535. ->where(['a.dt_id'=>$dt_id,'a.level'=>1])->order('a.id desc')->autopage()->select();
  536. $floor_list = list_domain_image($floor_list,['avatar']);
  537. //追加子评论
  538. if(!empty($floor_list)){
  539. foreach($floor_list as $key => &$val){
  540. //下面几条子回复,字符串
  541. $val['childremark'] = '';
  542. $map = [
  543. 'a.dt_id' => $dt_id,
  544. 'a.floor' => $val['floor'],
  545. 'a.level' => 2,
  546. ];
  547. $number = Db::name('topic_dongtai_answer')->alias('a')->where($map)->count();
  548. if($number > 0){
  549. $answer_info = Db::name('topic_dongtai_answer')
  550. ->alias('a')
  551. ->field('user.nickname')
  552. ->join('user','a.user_id = user.id','LEFT')
  553. ->where($map)->order('a.id desc')->find();
  554. $val['childremark'] = $answer_info['nickname'].'...等人,共'.$number.'条回复';
  555. }
  556. //时间处理
  557. $val['createtime_text'] = get_last_time($val['createtime']);
  558. //回复是否已赞
  559. $val['is_good'] = $this->answer_is_good($val['id'],$this->auth->id);
  560. //用户年龄
  561. $val['age'] = birthtime_to_age($val['birthday']);
  562. unset($val['birthday']);
  563. }
  564. }
  565. $this->success(1,$floor_list);
  566. }
  567. //单独某一层的详细
  568. public function answer_info(){
  569. $answer_id = input('answer_id');
  570. //楼
  571. $floor_info = Db::name('topic_dongtai_answer')
  572. ->alias('a')
  573. ->field('a.*,user.username,user.nickname,user.avatar,user.gender,user.birthday,user.idcard_status')
  574. ->join('user','a.user_id = user.id','LEFT')
  575. ->where(['a.id'=>$answer_id])->find();
  576. if(empty($floor_info)){
  577. $this->success(1,[]);
  578. }
  579. $floor_info = info_domain_image($floor_info,['avatar']);
  580. $floor_info['createtime_text'] = get_last_time($floor_info['createtime']);
  581. //用户年龄
  582. $floor_info['age'] = birthtime_to_age($floor_info['birthday']);
  583. unset($floor_info['birthday']);
  584. //回复是否已赞
  585. $floor_info['is_good'] = $this->answer_is_good($answer_id,$this->auth->id);
  586. $floor_info['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$floor_info['dt_id'],'floor'=>$floor_info['floor'],'level'=>2])->count();
  587. //层
  588. $floors = $floor_info['floor'];
  589. $child_lists = Db::name('topic_dongtai_answer')->alias('a')
  590. ->field('a.*,user.username,user.nickname,user.avatar,user.gender,user.birthday,user.idcard_status')
  591. ->join('user','a.user_id = user.id','LEFT')
  592. ->where(['a.dt_id'=>$floor_info['dt_id'],'a.floor'=>$floors,'a.level'=>2])->order('a.id desc')->autopage()->select();
  593. $child_lists = list_domain_image($child_lists,['avatar','to_avatar']);
  594. if(!empty($child_lists)){
  595. foreach($child_lists as $key => &$answer){
  596. //用户年龄
  597. $answer['age'] = birthtime_to_age($answer['birthday']);
  598. unset($answer['birthday']);
  599. $answer['is_good'] = $this->answer_is_good($answer['id'],$this->auth->id);
  600. $answer['createtime_text'] = get_last_time($answer['createtime']);
  601. }
  602. }
  603. //合并
  604. $floor_info['child'] = $child_lists;
  605. $this->success('success',$floor_info);
  606. }
  607. //是否点赞
  608. private function is_good($dt_id,$uid){
  609. $where = [
  610. 'dt_id' => $dt_id,
  611. 'user_id' => $uid,
  612. ];
  613. $check = Db::name('topic_dongtai_good')->where($where)->find();
  614. if($check){
  615. return 1;
  616. }else{
  617. return 0;
  618. }
  619. }
  620. //回复是否点赞
  621. private function answer_is_good($answer_id,$uid){
  622. $where = [
  623. 'answer_id' => $answer_id,
  624. 'user_id' => $uid,
  625. ];
  626. $check = Db::name('topic_answer_good')->where($where)->find();
  627. if($check){
  628. return 1;
  629. }else{
  630. return 0;
  631. }
  632. }
  633. //动态是否收藏
  634. private function is_collect($dt_id,$uid){
  635. $where = [
  636. 'user_id' => $uid,
  637. 'table' => 'topic_dongtai',
  638. 'table_id' => $dt_id,
  639. ];
  640. $check = Db::name('user_collect')->where($where)->find();
  641. if($check){
  642. return 1;
  643. }else{
  644. return 0;
  645. }
  646. }
  647. //用户是否拉黑
  648. private function is_black($uid,$black_uid){
  649. $where = [
  650. 'uid' => $uid,
  651. 'black_uid' => $black_uid,
  652. ];
  653. $check = Db::name('user_black')->where($where)->find();
  654. if($check){
  655. return 1;
  656. }else{
  657. return 0;
  658. }
  659. }
  660. //我的评论
  661. public function my_answer(){
  662. $map = [
  663. 'a.user_id' => $this->auth->id,
  664. 'a.level' => 1,
  665. ];
  666. $list = Db::name('topic_dongtai_answer')->alias('a')
  667. ->field('a.id,a.createtime,a.content,a.dt_id,
  668. dt.images,dt.content as dt_content,dt.type as dt_type,dtuser.nickname as dtuser_nickname,dtuser.username as dtuser_username,user.username,
  669. user.nickname,user.avatar,user.gender,user.birthday,user.idcard_status,uw.vip_endtime')
  670. ->join('topic_dongtai dt','a.dt_id = dt.id','LEFT')
  671. ->join('user dtuser','dt.user_id = dtuser.id','LEFT')
  672. ->join('user user','a.user_id = user.id','LEFT')
  673. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  674. ->where($map)->order('a.id desc')->autopage()->select();
  675. $list = list_domain_image($list,['avatar']);
  676. if(!empty($list)){
  677. foreach($list as $key => &$val){
  678. //用户年龄
  679. $val['age'] = birthtime_to_age($val['birthday']);
  680. unset($val['birthday']);
  681. //用户vip
  682. $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
  683. unset($val['vip_endtime']);
  684. }
  685. }
  686. $this->success(1,$list);
  687. }
  688. //删除我的某个评论
  689. public function delete_answer(){
  690. $id = input('id',0);
  691. if(!$id){
  692. $this->error();
  693. }
  694. Db::startTrans();
  695. $info = Db::name('topic_dongtai_answer')->where('id',$id)->where('user_id',$this->auth->id)->find();
  696. if(!$info){
  697. $this->error('不存在的动态评论');
  698. }
  699. if($info['level'] == 1){
  700. //楼层内都删
  701. $louceng_id = Db::name('topic_dongtai_answer')->where('dt_id',$info['dt_id'])->where('level',2)->where('floor',$info['floor'])->column('id');
  702. if(!empty($louceng_id)){
  703. Db::name('topic_dongtai')->where('id',$info['dt_id'])->setDec('answernum',count($louceng_id));//回复数减1
  704. Db::name('topic_dongtai_answer')->where('id','IN',$louceng_id)->delete();//评论删掉
  705. Db::name('topic_answer_good')->where('answer_id','IN',$louceng_id)->delete();//评论点赞删掉
  706. }
  707. }
  708. Db::name('topic_dongtai')->where('id',$info['dt_id'])->setDec('answernum');//回复数减1
  709. Db::name('topic_dongtai_answer')->where('id',$id)->delete(); //评论删掉
  710. Db::name('topic_answer_good')->where('answer_id',$id)->delete();//评论点赞删掉
  711. Db::commit();
  712. $this->success();
  713. }
  714. //我点赞的动态
  715. public function my_good(){
  716. $where = ['good.user_id'=>$this->auth->id];
  717. $list = Db::name('topic_dongtai')->alias('dt')
  718. ->join('user','dt.user_id = user.id','LEFT')
  719. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  720. ->join('topic_dongtai_good good','dt.id = good.dt_id','LEFT')
  721. ->field('dt.*,dt.id as dt_id,user.username,user.nickname,user.avatar,user.gender,user.birthday,user.idcard_status,uw.vip_endtime')
  722. ->where($where)
  723. ->order('dt.id desc')->autopage()->select();
  724. $list = list_domain_image($list,['images','audio_file','avatar']);
  725. if(!empty($list)){
  726. foreach($list as $key => &$val){
  727. $val['aite'] = json_decode($val['aite'],true);
  728. //用户年龄
  729. $val['age'] = birthtime_to_age($val['birthday']);
  730. unset($val['birthday']);
  731. //用户vip
  732. $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
  733. unset($val['vip_endtime']);
  734. //追加点赞
  735. $val['isgood'] = $this->is_good($val['id'],$this->auth->id);
  736. //时间
  737. $val['createtime_text'] = get_last_time($val['createtime']);
  738. //关注
  739. $val['is_follow'] = $this->is_follow($this->auth->id,$val['user_id']);
  740. //收藏
  741. $val['is_collect'] = $this->is_collect($val['id'],$this->auth->id);
  742. //拉黑
  743. $val['is_black'] = $this->is_black($this->auth->id,$val['user_id']);
  744. //层主评论数量
  745. $val['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$val['id'],'level'=>1])->count();
  746. //话题
  747. $val['topic_text'] = [];
  748. }
  749. }
  750. $this->success('success',$list);
  751. }
  752. //维智地图,POI搜索API
  753. /*public function poi(){
  754. $access_key = 'oLv7qgwJ5E4SdxSLvKLDRzdrkgQdLYV0';
  755. $keyword = '人民广场';
  756. $city_code = '';
  757. $city = '临沂';
  758. $page = input('page',1);
  759. $url = 'https://api.newayz.com/location/scenario/v1/placesearch?name='.$keyword.'&access_key='.$access_key.'&city='.$city.'&page_index='.$page.'&page_size=10';
  760. $header = ['Content-Type: application/json'];
  761. $rs = curl_get($url,$header);
  762. dump($rs);
  763. }*/
  764. //维智地图,POI搜索API
  765. public function poi2(){
  766. $access_key = 'oLv7qgwJ5E4SdxSLvKLDRzdrkgQdLYV0';
  767. $longitude = input('longitude','');
  768. $latitude = input('latitude','');
  769. $location = $longitude.','.$latitude;
  770. $keyword = input('keyword','');
  771. $radius = 5000;//周边半径,最大支持5000
  772. $page = input('page',1);
  773. $page_size = input('listrow',10);
  774. $url = 'https://api.newayz.com/location/scenario/v1/nearbysearch?access_key='.$access_key.'&location='.$location.'&keywords='.$keyword.'&radius='.$radius.'&page_index='.$page.'&page_size='.$page_size;
  775. $header = ['Content-Type: application/json'];
  776. $rs = curl_get($url,$header);
  777. $rs = json_decode($rs,true);
  778. $result = [];
  779. if(!empty($rs)){
  780. foreach($rs as $key => $val){
  781. if(!isset($val['geoPoint']) || empty($val['geoPoint'])){ continue; }
  782. if(!isset($val['name']) || empty($val['name'])){ continue; }
  783. if(!isset($val['address']['name']) || empty($val['address']['name'])){ continue; }
  784. $location = explode(',',$val['geoPoint']);
  785. if( !isset($location[0]) || !isset($location[1]) ){ continue; }
  786. $result[] = [
  787. 'longitude' => $location[0],
  788. 'latitude' => $location[1],
  789. 'name' => $val['name'],
  790. 'address' => $val['address']['name'],
  791. ];
  792. }
  793. }
  794. // $this->success(1,$rs);
  795. $this->success(1,$result);
  796. }
  797. }