Userfollow.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 关注
  7. */
  8. class Userfollow extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['*'];
  12. //我的关注列表/好友列表
  13. public function my_follow_list(){
  14. $type = input('type', 0, 'intval'); //类型:0关注 1好友
  15. $where = [];
  16. if ($type == 1) {
  17. $where['follow.status'] = 1;
  18. }
  19. $list = Db::name('user_follow')
  20. ->alias('follow')
  21. ->join('user','follow.follow_uid = user.id','LEFT')
  22. ->join('user_wallet uw','follow.follow_uid = uw.id','LEFT')
  23. ->field('user.id,user.nickname,user.avatar,user.real_status,user.idcard_status,user.birthday,user.gender,follow.status,uw.vip_endtime')
  24. ->where('follow.uid',$this->auth->id)->where($where)->order('follow.id desc')->autopage()->select();
  25. $list = list_domain_image($list,['avatar']);
  26. $list = list_birthday_age($list);
  27. if ($list) {
  28. /*$mt_user_wallet = Db::name('user_wallet'); //钱包
  29. $mt_wealth_level = Db::name('wealth_level'); //财富等级
  30. $mt_charm_level = Db::name('charm_level'); //魅力等级*/
  31. foreach ($list as &$val) {
  32. //查询财富等级和魅力等级
  33. /*$wallet_info = $mt_user_wallet->where(['user_id' => $val['id']])->find();
  34. $wealth_level = $mt_wealth_level->where(['value' => ['elt', $wallet_info['pay_money']]])->order('id desc')->find();
  35. if ($wealth_level) {
  36. $val['wealth_level'] = $wealth_level['name'];
  37. } else {
  38. $val['wealth_level'] = '';
  39. }
  40. $charm_level = $mt_charm_level->where(['value' => ['elt', $wallet_info['get_money']]])->order('id desc')->find();
  41. if ($charm_level) {
  42. $val['charm_level'] = $charm_level['name'];
  43. } else {
  44. $val['charm_level'] = '';
  45. }*/
  46. $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
  47. }
  48. }
  49. $this->success('success',$list);
  50. }
  51. //我的粉丝列表
  52. public function my_fans_list(){
  53. $list = Db::name('user_follow')
  54. ->alias('follow')
  55. ->join('user','follow.uid = user.id','LEFT')
  56. ->join('user_wallet uw','follow.follow_uid = uw.id','LEFT')
  57. ->field('user.id,user.nickname,user.avatar,user.real_status,user.idcard_status,user.birthday,user.gender,follow.status,uw.vip_endtime')
  58. ->where('follow.follow_uid',$this->auth->id)->order('follow.id desc')->autopage()->select();
  59. $list = list_domain_image($list,['avatar']);
  60. $list = list_birthday_age($list);
  61. if ($list) {
  62. /*$mt_user_wallet = Db::name('user_wallet'); //钱包
  63. $mt_wealth_level = Db::name('wealth_level'); //财富等级
  64. $mt_charm_level = Db::name('charm_level'); //魅力等级*/
  65. foreach ($list as &$val) {
  66. //查询财富等级和魅力等级
  67. /*$wallet_info = $mt_user_wallet->where(['user_id' => $val['id']])->find();
  68. $wealth_level = $mt_wealth_level->where(['value' => ['elt', $wallet_info['pay_money']]])->order('id desc')->find();
  69. if ($wealth_level) {
  70. $val['wealth_level'] = $wealth_level['name'];
  71. } else {
  72. $val['wealth_level'] = '';
  73. }
  74. $charm_level = $mt_charm_level->where(['value' => ['elt', $wallet_info['get_money']]])->order('id desc')->find();
  75. if ($charm_level) {
  76. $val['charm_level'] = $charm_level['name'];
  77. } else {
  78. $val['charm_level'] = '';
  79. }*/
  80. $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
  81. }
  82. }
  83. $this->success('success',$list);
  84. }
  85. //关注某人
  86. public function follow_one(){
  87. // 接口防并发
  88. if (!$this->apiLimit(1, 1)) {
  89. $this->error(__('Operation frequently'));
  90. }
  91. $follow_uid = input('follow_uid',0);
  92. // $gift_id = input('gift_id');// 礼物ID
  93. // $number = input('number',1,'intval');//数量
  94. if(!$follow_uid){
  95. $this->error(__('Invalid parameters'));
  96. }
  97. $checkuser = Db::name('user')->find($follow_uid);
  98. if(empty($checkuser)){
  99. $this->error('此用户不存在');
  100. }
  101. if($follow_uid == $this->auth->id){
  102. $this->error('不能关注自己');
  103. }
  104. $map = [
  105. 'uid' => $this->auth->id,
  106. 'follow_uid' => $follow_uid,
  107. ];
  108. $check = Db::name('user_follow')->where($map)->find();
  109. if($check){
  110. $this->error('已经关注此人');
  111. }
  112. //查询对方是否关注自己
  113. $where = [
  114. 'uid' => $follow_uid,
  115. 'follow_uid' => $this->auth->id
  116. ];
  117. $count = Db::name('user_follow')->where($where)->count('id');
  118. if ($count) {
  119. $map['status'] = 1; //状态:0=关注,1=互为关注
  120. }
  121. $return_data['money'] = ''; //获得金额
  122. $return_data['level_remark'] = ''; //亲密度等级提示语
  123. //开启事务
  124. Db::startTrans();
  125. $id = Db::name('user_follow')->insertGetId($map);
  126. if(!$id){
  127. Db::rollback();
  128. $this->error('您的网络开小差啦~');
  129. }
  130. if ($count) {
  131. //若对方已关注, 则将状态改为 互为关注
  132. $rs = Db::name('user_follow')->where($where)->where(['status' => 0])->setField('status', 1);
  133. if (!$rs) {
  134. Db::rollback();
  135. $this->error('您的网络开小差啦~');
  136. }
  137. }
  138. //系统消息
  139. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'喜欢','您已喜欢用户' . $checkuser['nickname']);
  140. Db::commit();
  141. $this->success('操作成功', $return_data);
  142. }
  143. //取关某人
  144. public function un_follow_one(){
  145. $follow_uid = input('follow_uid',0);
  146. if(!$follow_uid){
  147. $this->error(__('Invalid parameters'));
  148. }
  149. $checkuser = Db::name('user')->find($follow_uid);
  150. if(empty($checkuser)){
  151. $this->error('此用户不存在');
  152. }
  153. $map = [
  154. 'uid' => $this->auth->id,
  155. 'follow_uid' => $follow_uid,
  156. ];
  157. $info = Db::name('user_follow')->where($map)->find();
  158. if (!$info) {
  159. $this->error('您尚未关注此人~');
  160. }
  161. //开启事务
  162. Db::startTrans();
  163. $rs = Db::name('user_follow')->where($map)->delete();
  164. if (!$rs) {
  165. Db::rollback();
  166. $this->error('您的网络开小差啦~');
  167. }
  168. $where = [
  169. 'uid' => $follow_uid,
  170. 'follow_uid' => $this->auth->id,
  171. ];
  172. $count = Db::name('user_follow')->where($where)->count('id');
  173. if ($count) {
  174. $rt = Db::name('user_follow')->where($where)->where(['status' => 1])->setField('status', 0);
  175. if (!$rt) {
  176. Db::rollback();
  177. $this->error('您的网络开小差啦~');
  178. }
  179. }
  180. Db::commit();
  181. $this->success('操作成功');
  182. }
  183. }