Userlike.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. ->field('user.id,user.nickname,user.avatar,user.bio,user.birthday,user.gender')
  18. ->where('like.like_uid',$this->auth->id)->order('like.id desc')->autopage()->select();
  19. $list = list_domain_image($list,['avatar']);
  20. $list = list_birthday_age($list);
  21. $this->success('success',$list);
  22. }
  23. //解锁喜欢我的人
  24. public function unlock_like_me(){
  25. $gold = intval(config('site.unlock_like_me'));
  26. if($gold > 0){
  27. Db::startTrans();
  28. $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,0,'gold',-$gold,62,'解锁喜欢我的人');
  29. if($rs['status'] === false){
  30. Db::rollback();
  31. $this->error($rs['msg']);
  32. }
  33. //tag任务赠送金币
  34. //消费解锁喜欢我的人
  35. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,17);
  36. if($task_rs === false){
  37. Db::rollback();
  38. $this->error('完成任务赠送奖励失败');
  39. }
  40. Db::commit();
  41. $this->success('操作成功');
  42. }
  43. $this->success('操作成功');
  44. }
  45. //我喜欢的人列表
  46. public function my_like_list(){
  47. $list = Db::name('user_like')
  48. ->alias('like')
  49. ->join('user','like.like_uid = user.id','LEFT')
  50. ->field('user.id,user.nickname,user.avatar,user.bio,user.birthday,user.gender')
  51. ->where('like.uid',$this->auth->id)->order('like.id desc')->autopage()->select();
  52. $list = list_domain_image($list,['avatar']);
  53. $list = list_birthday_age($list);
  54. $this->success('success',$list);
  55. }
  56. //关注某人
  57. public function like_one(){
  58. $like_uid = input('like_uid',0);
  59. if(!$like_uid){
  60. $this->error(__('Invalid parameters'));
  61. }
  62. $checkuser = Db::name('user')->find($like_uid);
  63. if(empty($checkuser)){
  64. $this->error('此用户不存在');
  65. }
  66. if($like_uid == $this->auth->id){
  67. $this->error('不能喜欢自己');
  68. }
  69. $map = [
  70. 'uid' => $this->auth->id,
  71. 'like_uid' => $like_uid,
  72. ];
  73. $check = Db::name('user_like')->where($map)->find();
  74. if($check){
  75. $this->error('已经喜欢了此人');
  76. }
  77. $id = Db::name('user_like')->insertGetId($map);
  78. $this->success('操作成功',$id);
  79. }
  80. //取关某人
  81. public function un_like_one(){
  82. $like_uid = input('like_uid',0);
  83. if(!$like_uid){
  84. $this->error(__('Invalid parameters'));
  85. }
  86. $map = [
  87. 'uid' => $this->auth->id,
  88. 'like_uid' => $like_uid,
  89. ];
  90. //不检查,全删
  91. $rs = Db::name('user_like')->where($map)->delete();
  92. $this->success('操作成功');
  93. }
  94. }