Userlike.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 喜欢
  7. */
  8. class Userlike extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['*'];
  12. //喜欢我的人列表
  13. public function like_me_list(){
  14. $list = Db::name('user_like')
  15. ->alias('like')
  16. ->join('user','like.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('like.like_uid',$this->auth->id)->order('like.id 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 unlock_like_me(){
  29. $gold = intval(config('site.unlock_like_me'));
  30. if($gold > 0){
  31. Db::startTrans();
  32. $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,0,'gold',-$gold,62,'解锁喜欢我的人');
  33. if($rs['status'] === false){
  34. Db::rollback();
  35. $this->error($rs['msg']);
  36. }
  37. //tag任务赠送金币
  38. //消费解锁喜欢我的人
  39. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,17);
  40. if($task_rs === false){
  41. Db::rollback();
  42. $this->error('完成任务赠送奖励失败');
  43. }
  44. Db::commit();
  45. $this->success('操作成功');
  46. }
  47. $this->success('操作成功');
  48. }*/
  49. //我喜欢的人列表
  50. public function my_like_list(){
  51. $list = Db::name('user_like')
  52. ->alias('like')
  53. ->join('user','like.like_uid = user.id','LEFT')
  54. ->join('user_remark ur', 'ur.to_user_id = user.id and ur.user_id = '.$this->auth->id, 'LEFT')
  55. ->field('user.id,user.nickname,user.avatar,user.bio,user.birthday,user.gender,ur.nickname_remark')
  56. ->where('like.uid',$this->auth->id)->order('like.id desc')->autopage()->select();
  57. $list = list_domain_image($list,['avatar']);
  58. $list = list_birthday_age($list);
  59. foreach ($list as &$val) {
  60. $val['nickname'] = !empty($val['nickname_remark']) ? $val['nickname_remark'] : $val['nickname'];
  61. }
  62. $this->success('success',$list);
  63. }
  64. //关注某人
  65. public function like_one(){
  66. $like_uid = input('like_uid',0);
  67. if(!$like_uid){
  68. $this->error(__('Invalid parameters'));
  69. }
  70. $checkuser = Db::name('user')->find($like_uid);
  71. if(empty($checkuser)){
  72. $this->error('此用户不存在');
  73. }
  74. if($like_uid == $this->auth->id){
  75. $this->error('不能喜欢自己');
  76. }
  77. $map = [
  78. 'uid' => $this->auth->id,
  79. 'like_uid' => $like_uid,
  80. ];
  81. $check = Db::name('user_like')->where($map)->find();
  82. if($check){
  83. $this->error('已经喜欢了此人');
  84. }
  85. $id = Db::name('user_like')->insertGetId($map);
  86. $this->success('操作成功',$id);
  87. }
  88. //取关某人
  89. public function un_like_one(){
  90. $like_uid = input('like_uid',0);
  91. if(!$like_uid){
  92. $this->error(__('Invalid parameters'));
  93. }
  94. $map = [
  95. 'uid' => $this->auth->id,
  96. 'like_uid' => $like_uid,
  97. ];
  98. //不检查,全删
  99. $rs = Db::name('user_like')->where($map)->delete();
  100. $this->success('操作成功');
  101. }
  102. }