Userfollow.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. ->field('user.id,user.nickname,user.avatar,user.real_status,user.idcard_status,user.birthday,user.gender,follow.status')
  23. ->where('follow.uid',$this->auth->id)->where($where)->order('follow.id desc')->autopage()->select();
  24. $list = list_domain_image($list,['avatar']);
  25. $list = list_birthday_age($list);
  26. if ($list) {
  27. $mt_user_wallet = Db::name('user_wallet'); //钱包
  28. $mt_wealth_level = Db::name('wealth_level'); //财富等级
  29. $mt_charm_level = Db::name('charm_level'); //魅力等级
  30. foreach ($list as &$val) {
  31. //查询财富等级和魅力等级
  32. $wallet_info = $mt_user_wallet->where(['user_id' => $val['id']])->find();
  33. $wealth_level = $mt_wealth_level->where(['value' => ['elt', $wallet_info['pay_money']]])->order('id desc')->find();
  34. if ($wealth_level) {
  35. $val['wealth_level'] = $wealth_level['name'];
  36. } else {
  37. $val['wealth_level'] = '';
  38. }
  39. $charm_level = $mt_charm_level->where(['value' => ['elt', $wallet_info['get_money']]])->order('id desc')->find();
  40. if ($charm_level) {
  41. $val['charm_level'] = $charm_level['name'];
  42. } else {
  43. $val['charm_level'] = '';
  44. }
  45. }
  46. }
  47. $this->success('success',$list);
  48. }
  49. //我的粉丝列表
  50. public function my_fans_list(){
  51. $list = Db::name('user_follow')
  52. ->alias('follow')
  53. ->join('user','follow.uid = user.id','LEFT')
  54. ->field('user.id,user.nickname,user.avatar,user.real_status,user.idcard_status,user.birthday,user.gender,follow.status')
  55. ->where('follow.follow_uid',$this->auth->id)->order('follow.id desc')->autopage()->select();
  56. $list = list_domain_image($list,['avatar']);
  57. $list = list_birthday_age($list);
  58. if ($list) {
  59. $mt_user_wallet = Db::name('user_wallet'); //钱包
  60. $mt_wealth_level = Db::name('wealth_level'); //财富等级
  61. $mt_charm_level = Db::name('charm_level'); //魅力等级
  62. foreach ($list as &$val) {
  63. //查询财富等级和魅力等级
  64. $wallet_info = $mt_user_wallet->where(['user_id' => $val['id']])->find();
  65. $wealth_level = $mt_wealth_level->where(['value' => ['elt', $wallet_info['pay_money']]])->order('id desc')->find();
  66. if ($wealth_level) {
  67. $val['wealth_level'] = $wealth_level['name'];
  68. } else {
  69. $val['wealth_level'] = '';
  70. }
  71. $charm_level = $mt_charm_level->where(['value' => ['elt', $wallet_info['get_money']]])->order('id desc')->find();
  72. if ($charm_level) {
  73. $val['charm_level'] = $charm_level['name'];
  74. } else {
  75. $val['charm_level'] = '';
  76. }
  77. }
  78. }
  79. $this->success('success',$list);
  80. }
  81. //关注某人
  82. public function follow_one(){
  83. // 接口防并发
  84. if (!$this->apiLimit(1, 1000)) {
  85. $this->error(__('Operation frequently'));
  86. }
  87. $follow_uid = input('follow_uid',0);
  88. // $gift_id = input('gift_id');// 礼物ID
  89. // $number = input('number',1,'intval');//数量
  90. if(!$follow_uid){
  91. $this->error(__('Invalid parameters'));
  92. }
  93. $checkuser = Db::name('user')->find($follow_uid);
  94. if(empty($checkuser)){
  95. $this->error('此用户不存在');
  96. }
  97. if($follow_uid == $this->auth->id){
  98. $this->error('不能关注自己');
  99. }
  100. $map = [
  101. 'uid' => $this->auth->id,
  102. 'follow_uid' => $follow_uid,
  103. ];
  104. $check = Db::name('user_follow')->where($map)->find();
  105. if($check){
  106. $this->error('已经关注此人');
  107. }
  108. /*//查询自己是否是会员, 不是会员需要赠送礼物
  109. $vip_endtime = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('vip_endtime');
  110. $time = time();
  111. if ($vip_endtime < $time) {
  112. $user_id = $follow_uid;// 赠送对象
  113. if (!$gift_id) {
  114. $this->error('请选择要赠送的礼物');
  115. }
  116. if ($number < 1) {
  117. $this->error('请输入正确赠送礼物数量');
  118. }
  119. // 获取礼物信息
  120. $giftinfo = Db::name('gift')->where('id',$gift_id)->find();
  121. if (!$giftinfo)
  122. {
  123. $this->error("请选择礼物");
  124. }
  125. $giftvalue = bcmul($giftinfo['value'],$number);
  126. //被赠送人信息
  127. $touserinfo = $checkuser;
  128. // 判断当前用户余额
  129. $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
  130. if($user_gold < $giftvalue)
  131. {
  132. $this->error("您的金币余额不足");
  133. }
  134. }*/
  135. //查询对方是否关注自己
  136. $where = [
  137. 'uid' => $follow_uid,
  138. 'follow_uid' => $this->auth->id
  139. ];
  140. $count = Db::name('user_follow')->where($where)->count('id');
  141. if ($count) {
  142. $map['status'] = 1; //状态:0=关注,1=互为关注
  143. }
  144. $return_data['money'] = ''; //获得金额
  145. $return_data['level_remark'] = ''; //亲密度等级提示语
  146. //开启事务
  147. Db::startTrans();
  148. $id = Db::name('user_follow')->insertGetId($map);
  149. if(!$id){
  150. Db::rollback();
  151. $this->error('您的网络开小差啦~');
  152. }
  153. if ($count) {
  154. //若对方已关注, 则将状态改为 互为关注
  155. $rs = Db::name('user_follow')->where($where)->where(['status' => 0])->setField('status', 1);
  156. if (!$rs) {
  157. Db::rollback();
  158. $this->error('您的网络开小差啦~');
  159. }
  160. }
  161. //赠送礼物
  162. // if ($vip_endtime < $time) {
  163. // // 添加礼物赠送记录表
  164. // $data = [
  165. // 'user_id' => $this->auth->id,
  166. // 'user_to_id' => $user_id,
  167. // 'gift_id' => $giftinfo['id'],
  168. // 'gift_name' => $giftinfo['name'],
  169. // 'number' => $number,
  170. // 'price' => $giftvalue,
  171. // 'createtime' => time(),
  172. // ];
  173. // $log_id = Db::name('gift_user_typing')->insertGetId($data);
  174. // if(!$log_id){
  175. // Db::rollback();
  176. // $this->error('赠送失败');
  177. // }
  178. //
  179. // if($giftvalue > 0){
  180. // // 扣除当前用户余额
  181. // $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'gold',-$giftvalue,53,'赠送礼物:'.$giftinfo["name"] . '*' . $number,'gift_user_typing',$log_id);
  182. // if($wallet_rs['status'] === false){
  183. // Db::rollback();
  184. // $this->error($wallet_rs['msg']);
  185. // }
  186. //
  187. // // 添加赠送用户余额
  188. // $money_to_gold = config('site.money_to_gold');
  189. // $gift_plat_scale = config('site.gift_plat_scale');
  190. //
  191. // $giftmoney = bcdiv($giftvalue,$money_to_gold,2);
  192. //
  193. // $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
  194. // $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,$this->auth->id,'money',$money,54,'获得礼物:'.$giftinfo["name"] . '*' . $number,'gift_user_typing',$log_id,2);
  195. // if($wallet_rs['status'] === false){
  196. // Db::rollback();
  197. // $this->error($wallet_rs['msg']);
  198. // }
  199. //
  200. // /*//增加赠送用户上级金币
  201. // if ($touserinfo['intro_uid']) {
  202. // //获取返利比率
  203. // $intro_gift_rebate_rate = (int)config('site.intro_gift_rebate_rate'); //邀请人收礼物返利比率
  204. // if ($intro_gift_rebate_rate > 0 && $intro_gift_rebate_rate <= 100) {
  205. // //上级获得金币数量
  206. // $intro_uid_gold = floor($giftvalue * $intro_gift_rebate_rate / 100);
  207. // if ($intro_uid_gold > 0) {
  208. // $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'gold',$intro_uid_gold,66, '聊天礼物获赠奖励','gift_user_typing',$log_id);
  209. // if($intro_result['status']===false)
  210. // {
  211. // Db::rollback();
  212. // $this->error($intro_result['msg']);
  213. // }
  214. // }
  215. // }
  216. // }*/
  217. //
  218. // //增加赠送用户上级余额
  219. // if ($touserinfo['intro_uid']) {
  220. // //获取返利比率
  221. // $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  222. // $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  223. // if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  224. // //上级获得金额
  225. // $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  226. // if ($intro_uid_money > 0) {
  227. // $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'money',$intro_uid_money,68, '邀请人聊天礼物获赠奖励','gift_user_typing',$log_id);
  228. // if($intro_result['status']===false)
  229. // {
  230. // Db::rollback();
  231. // $this->error($intro_result['msg']);
  232. // }
  233. // }
  234. // }
  235. // }
  236. //
  237. // if ($this->auth->gender == 1 && $touserinfo['gender'] == 0) {
  238. // //增加亲密度
  239. // $user_intimacy_rs = addintimacy($this->auth->id, $user_id, $giftvalue);
  240. // if (!$user_intimacy_rs['status']) {
  241. // Db::rollback();
  242. // $this->error('您的网络开小差啦~');
  243. // }
  244. // }
  245. // }
  246. //
  247. // //tag任务赠送金币
  248. // //搭讪奖励
  249. //// $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
  250. //// if($task_rs === false){
  251. //// Db::rollback();
  252. //// $this->error('完成任务赠送奖励失败');
  253. //// }
  254. //
  255. // //发送消息
  256. // if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  257. // $tenim = new \app\api\controller\Tenim;
  258. // $tenim->sendMessageToUser($this->auth->id, $user_id, $user_intimacy_rs['level_remark'], 1);
  259. // }
  260. //
  261. // $return_data['money'] = $money; //获得金额
  262. // $return_data['level_remark'] = isset($user_intimacy_rs) ? $user_intimacy_rs['level_remark'] : ''; //亲密度等级提示语
  263. // }
  264. //tag任务赠送金币
  265. //关注3人加3金币
  266. // $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,2);
  267. // if($task_rs === false){
  268. // Db::rollback();
  269. // $this->error('完成任务赠送奖励失败');
  270. // }
  271. //系统消息
  272. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'喜欢','您已喜欢用户' . $checkuser['nickname']);
  273. Db::commit();
  274. $this->success('操作成功', $return_data);
  275. }
  276. //取关某人
  277. public function un_follow_one(){
  278. $follow_uid = input('follow_uid',0);
  279. if(!$follow_uid){
  280. $this->error(__('Invalid parameters'));
  281. }
  282. $checkuser = Db::name('user')->find($follow_uid);
  283. if(empty($checkuser)){
  284. $this->error('此用户不存在');
  285. }
  286. $map = [
  287. 'uid' => $this->auth->id,
  288. 'follow_uid' => $follow_uid,
  289. ];
  290. $info = Db::name('user_follow')->where($map)->find();
  291. if (!$info) {
  292. $this->error('您尚未关注此人~');
  293. }
  294. //开启事务
  295. Db::startTrans();
  296. $rs = Db::name('user_follow')->where($map)->delete();
  297. if (!$rs) {
  298. Db::rollback();
  299. $this->error('您的网络开小差啦~');
  300. }
  301. $where = [
  302. 'uid' => $follow_uid,
  303. 'follow_uid' => $this->auth->id,
  304. ];
  305. $count = Db::name('user_follow')->where($where)->count('id');
  306. if ($count) {
  307. $rt = Db::name('user_follow')->where($where)->where(['status' => 1])->setField('status', 0);
  308. if (!$rt) {
  309. Db::rollback();
  310. $this->error('您的网络开小差啦~');
  311. }
  312. }
  313. Db::commit();
  314. $this->success('操作成功');
  315. }
  316. }