123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- /**
- * 喜欢
- */
- class Userlike extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
- //喜欢我的人列表
- public function like_me_list(){
- $list = Db::name('user_like')
- ->alias('like')
- ->join('user','like.uid = user.id','LEFT')
- ->field('user.id,user.nickname,user.avatar,user.bio,user.birthday,user.gender')
- ->where('like.like_uid',$this->auth->id)->order('like.id desc')->autopage()->select();
- $list = list_domain_image($list,['avatar']);
- $list = list_birthday_age($list);
- $this->success('success',$list);
- }
- //解锁喜欢我的人
- public function unlock_like_me(){
- $gold = intval(config('site.unlock_like_me'));
- if($gold > 0){
- Db::startTrans();
- $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,0,'gold',-$gold,62,'解锁喜欢我的人');
- if($rs['status'] === false){
- Db::rollback();
- $this->error($rs['msg']);
- }
- //tag任务赠送金币
- //消费解锁喜欢我的人
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,17);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- Db::commit();
- $this->success('操作成功');
- }
- $this->success('操作成功');
- }
- //我喜欢的人列表
- public function my_like_list(){
- $list = Db::name('user_like')
- ->alias('like')
- ->join('user','like.like_uid = user.id','LEFT')
- ->field('user.id,user.nickname,user.avatar,user.bio,user.birthday,user.gender')
- ->where('like.uid',$this->auth->id)->order('like.id desc')->autopage()->select();
- $list = list_domain_image($list,['avatar']);
- $list = list_birthday_age($list);
- $this->success('success',$list);
- }
- //关注某人
- public function like_one(){
- $like_uid = input('like_uid',0);
- if(!$like_uid){
- $this->error(__('Invalid parameters'));
- }
- $checkuser = Db::name('user')->find($like_uid);
- if(empty($checkuser)){
- $this->error('此用户不存在');
- }
- if($like_uid == $this->auth->id){
- $this->error('不能喜欢自己');
- }
- $map = [
- 'uid' => $this->auth->id,
- 'like_uid' => $like_uid,
- ];
- $check = Db::name('user_like')->where($map)->find();
- if($check){
- $this->error('已经喜欢了此人');
- }
- $id = Db::name('user_like')->insertGetId($map);
- $this->success('操作成功',$id);
- }
- //取关某人
- public function un_like_one(){
- $like_uid = input('like_uid',0);
- if(!$like_uid){
- $this->error(__('Invalid parameters'));
- }
- $map = [
- 'uid' => $this->auth->id,
- 'like_uid' => $like_uid,
- ];
- //不检查,全删
- $rs = Db::name('user_like')->where($map)->delete();
- $this->success('操作成功');
- }
- }
|