Intimacy.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Cache;
  5. use think\Db;
  6. /**
  7. * 亲密度
  8. */
  9. class Intimacy extends Api
  10. {
  11. protected $noNeedLogin = [''];
  12. protected $noNeedRight = '*';
  13. //消息列表好友/密友
  14. public function intimacyfriends() {
  15. $type = input('type', 0, 'intval'); //类型:0消息列表好友 1密友 2好友
  16. $where = [];
  17. /*if ($type == 0) {
  18. $list = Db::name('user_follow')->field('follow_uid user_id')->where(['uid' => $this->auth->id])->autopage()->order('id desc')->select();
  19. $mt_user = Db::name('user');
  20. // $mt_user_follow = Db::name('user_follow');
  21. $mt_user_intimacy = Db::name('user_intimacy');
  22. foreach ($list as &$v) {
  23. //查询亲密度
  24. if ($this->auth->gender == 1) {
  25. $where['uid'] = $this->auth->id;
  26. $where['other_uid'] = $v['user_id'];
  27. } else {
  28. $where['other_uid'] = $this->auth->id;
  29. $where['uid'] = $v['user_id'];
  30. }
  31. $user_intimacy = $mt_user_intimacy->field('value, updatetime')->where($where)->find();
  32. $v['value'] = $user_intimacy ? $user_intimacy['value'] : 0;
  33. $v['updatetime'] = $user_intimacy ? $user_intimacy['updatetime'] : 0;
  34. //查询对方信息
  35. $user_info = $mt_user->field('nickname, avatar,birthday,gender,real_status')->where(['id' => $v['user_id']])->find();
  36. $v['nickname'] = $user_info['nickname'];
  37. $v['avatar'] = one_domain_image($user_info['avatar']);
  38. $v['updatetime'] = get_last_time($v['updatetime']);
  39. $v['age'] = birthtime_to_age($user_info['birthday']);
  40. $v['gender'] = $user_info['gender'];
  41. $v['real_status'] = $user_info['real_status'];
  42. // $v['status'] = $mt_user_follow->where(['uid' => $this->auth->id, 'follow_uid' => $v['user_id']])->count('id');
  43. $v['status'] = 1;
  44. }
  45. } else {*/
  46. if ($this->auth->gender == 1) {
  47. $where['uid'] = $this->auth->id;
  48. $field = 'other_uid user_id, value, updatetime';
  49. } else {
  50. $where['other_uid'] = $this->auth->id;
  51. $field = 'uid user_id, value, updatetime';
  52. }
  53. if ($type == 1) { //密友
  54. $where['value'] = ['egt', 1000];
  55. } elseif ($type == 2) { //好友
  56. $where['value'] = ['egt', 100];
  57. } else { //消息列表好友
  58. $where['value'] = ['egt', 10];
  59. }
  60. $list = Db::name('user_intimacy')->field($field)->where($where)->autopage()->order('updatetime desc')->select();
  61. $mt_user = Db::name('user');
  62. $mt_user_follow = Db::name('user_follow');
  63. foreach ($list as &$v) {
  64. $user_info = $mt_user->field('nickname, avatar,birthday,gender,real_status,is_active')->where(['id' => $v['user_id']])->find();
  65. $v['nickname'] = $user_info['nickname'];
  66. $v['avatar'] = one_domain_image($user_info['avatar']);
  67. $v['updatetime'] = get_last_time($v['updatetime']);
  68. $v['age'] = birthtime_to_age($user_info['birthday']);
  69. $v['gender'] = $user_info['gender'];
  70. $v['real_status'] = $user_info['real_status'];
  71. $v['status'] = $mt_user_follow->where(['uid' => $this->auth->id, 'follow_uid' => $v['user_id']])->count('id');
  72. $v['is_active'] = $user_info['is_active'];
  73. }
  74. // }
  75. $this->success('success',$list);
  76. }
  77. //亲密度等级信息
  78. public function intimacylevel() {
  79. $user_id = input('user_id', 0, 'intval'); //对方id
  80. if (!$user_id) {
  81. $this->error('参数缺失');
  82. }
  83. if ($this->auth->gender == 0) { //女用户
  84. $where['uid'] = $user_id;
  85. $where['other_uid'] = $this->auth->id;
  86. } else { //男用户
  87. $where['uid'] = $this->auth->id;
  88. $where['other_uid'] = $user_id;
  89. }
  90. $level = 0; //当前等级
  91. $level_name = ''; //当前等级名称
  92. $level_value = 0;//当前等级亲密度
  93. $qinmi_sum = 0; //当前亲密度
  94. $next_level_diff = 0; //距下一等级亲密度差值
  95. $next_level_name = ''; //下一等级名称
  96. $next_level_value = 0;//下一等级亲密度值
  97. //亲密度等级列表
  98. $list = Db::name('intimacy_level')->field('name,level,value')->order('value')->select();
  99. //当前亲密度信息
  100. $user_intimacy_info = Db::name('user_intimacy')->where($where)->find();
  101. if ($user_intimacy_info) {
  102. //当前亲密度
  103. $qinmi_sum = $user_intimacy_info['value'];
  104. if ($list) {
  105. //当前等级信息
  106. $level_info = Db::name('intimacy_level')->where(['value' => ['elt', $user_intimacy_info['value']]])->order('level desc')->find();
  107. if ($level_info) {
  108. $level = $level_info['level'];
  109. $level_name = $level_info['name'];
  110. $level_value = $level_info['value'];
  111. }
  112. //下一等级信息
  113. $next_level_info = Db::name('intimacy_level')->where(['value' => ['gt', $user_intimacy_info['value']]])->order('value')->find();
  114. if ($next_level_info) {
  115. $next_level_name = $next_level_info['name'];
  116. $next_level_value = $next_level_info['value'];
  117. $next_level_diff = $next_level_info['value'] - $user_intimacy_info['value'];
  118. }
  119. }
  120. } else {
  121. $next_level_info = Db::name('intimacy_level')->where('level',1)->find();
  122. $next_level_diff = $next_level_info['value'];
  123. $next_level_name = $next_level_info['name'];
  124. $next_level_value = $next_level_info['value'];
  125. }
  126. if ($list) {
  127. foreach ($list as &$v) {
  128. if ($v['level'] < $level) {
  129. $v['is_unlock'] = 1; //当前等级是否解锁: 1已解锁 2当前等级 3未解锁
  130. } elseif ($v['level'] == $level) {
  131. $v['is_unlock'] = 2;
  132. } else {
  133. $v['is_unlock'] = 3;
  134. }
  135. }
  136. }
  137. $data['avatar'] = localpath_to_netpath($this->auth->avatar);
  138. $data['other_avatar'] = localpath_to_netpath(Db::name('user')->where('id',$user_id)->value('avatar'));
  139. $data['rate'] = $next_level_value == 0 ? 0 : bcdiv($qinmi_sum,$next_level_value,2)*100;
  140. $data['level'] = $level; //当前等级
  141. $data['level_name'] = $level_name; //当前等级名称
  142. $data['qinmi_sum'] = $qinmi_sum; //当前亲密度
  143. $data['next_level_diff'] = $next_level_diff; //距下一等级亲密度差值
  144. $data['next_level_name'] = $next_level_name; //下一等级名称
  145. $data['next_level_value'] = $next_level_value; //下一等级亲密度值
  146. $data['level_list'] = $list; //等级列表
  147. $this->success('亲密度等级信息', $data);
  148. }
  149. }