Uservisit.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 访问足迹
  7. */
  8. class Uservisit extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['*'];
  12. //我的访问列表
  13. public function my_visit_list(){
  14. $list = Db::name('user_visit')
  15. ->alias('visit')
  16. ->join('user','visit.to_uid = user.id','LEFT')
  17. ->join('user_remark ur', 'ur.to_user_id = user.id and ur.user_id = '.$this->auth->id, 'LEFT')
  18. ->field('user.id,user.nickname,user.avatar,user.bio,user.birthday,user.gender,ur.nickname_remark')
  19. ->where('visit.uid',$this->auth->id)->order('visit.updatetime desc')->autopage()->select();
  20. $list = list_domain_image($list,['avatar']);
  21. $list = list_birthday_age($list);
  22. foreach ($list as &$val) {
  23. $val['nickname'] = !empty($val['nickname_remark']) ? $val['nickname_remark'] : $val['nickname'];
  24. }
  25. $this->success('success',$list);
  26. }
  27. //访问我的人列表
  28. public function visit_me_list(){
  29. $time = Db::name('user_visit_time')->where(['user_id' => $this->auth->id])->find();
  30. if ($time) {
  31. Db::name('user_visit_time')->where(['user_id' => $this->auth->id])->setField('visittime', time());
  32. } else {
  33. Db::name('user_visit_time')->insertGetId(['user_id' => $this->auth->id, 'visittime' => time()]);
  34. }
  35. $list = Db::name('user_visit')
  36. ->alias('visit')
  37. ->join('user','visit.uid = user.id','LEFT')
  38. ->join('user_remark ur', 'ur.to_user_id = user.id and ur.user_id = '.$this->auth->id, 'LEFT')
  39. ->field('user.id,user.nickname,user.avatar,visit.updatetime,ur.nickname_remark')
  40. ->where('visit.to_uid',$this->auth->id)->order('visit.updatetime desc')->autopage()->select();
  41. $list = list_domain_image($list,['avatar']);
  42. // $list = list_birthday_age($list);
  43. //查询会员
  44. $user_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->find();
  45. $is_vip = $this->is_vip($user_wallet['vip_endtime'],$user_wallet['vip_level']);
  46. if ($this->auth->gender == 1 && $is_vip == 0) {
  47. $is_show = 0;
  48. } else {
  49. $is_show = 1; //是否正常显示信息: 1显示 0不显示
  50. }
  51. $mt_user_greet = Db::name('user_greet'); //是否打过招呼
  52. foreach ($list as &$v) {
  53. $v['updatetime'] = get_last_time($v['updatetime']);
  54. $v['is_show'] = $is_show;
  55. //查询是否搭讪过
  56. $count = $mt_user_greet->where(['user_id' => $this->auth->id, 'user_to_id' => $v['id']])->count('id');
  57. if ($count) {
  58. $v['is_chat'] = 1; //是否打过招呼: 1是 0否
  59. } else {
  60. $v['is_chat'] = 0; //是否打过招呼: 1是 0否
  61. }
  62. if ($is_show == 0) {
  63. $v['id'] = 0;
  64. $v['nickname'] = 'Ta偷偷来过';
  65. $v['avatar'] = config('avatar_girl');
  66. }
  67. $v['nickname'] = !empty($v['nickname_remark']) ? $v['nickname_remark'] : $v['nickname'];
  68. }
  69. $this->success('success',$list);
  70. }
  71. //谁看过我汇总
  72. public function visitlist(){
  73. $time = Db::name('user_visit_time')->where(['user_id' => $this->auth->id])->value('visittime');
  74. $where = [];
  75. if ($time) {
  76. $where['updatetime'] = ['gt', $time];
  77. }
  78. $list = [];
  79. $count = Db::name('user_visit')->where(['to_uid' => $this->auth->id])->where($where)->count('id');
  80. if ($count) {
  81. $uid_list = Db::name('user_visit')->field('uid')->where(['to_uid' => $this->auth->id])->where($where)->limit(9)->column('uid');
  82. $mt_user = Db::name('user');
  83. foreach ($uid_list as &$v) {
  84. $avatar = $mt_user->where(['id' => $v])->value('avatar');
  85. $list[] = one_domain_image($avatar);
  86. }
  87. }
  88. $data['count'] = $count;
  89. $data['list'] = $list;
  90. $this->success('success',$data);
  91. }
  92. //查看某人
  93. public function visit_one(){
  94. //放到usercenter/getuserinfo里了
  95. }
  96. }