123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922 |
- <?php
- namespace app\api\controller;
- use addons\epay\library\Service;
- use app\api\controller\Common;
- use app\api\validate\user\Report;
- use outh\outh;
- use think\Db;
- use app\common\controller\RedisLeaderboard;
- use Redis;
- use GatewayClient\Gateway;
- /**
- * 会员中心接口
- */
- class UserCenter extends Common
- {
- protected $noNeedLogin = ['shujuhuifu','getAnchorType','getRecharConfig','getExchangeConfig','getLevelExplain'];
- protected $noNeedRight = '*';
- public function _initialize()
- {
- parent::_initialize();
- $this->userModel = new \app\common\model\User();
- }
- /**
- * 获取当前用户信息
- */
- public function getMyUserInfo() {
- $this->success("获取成功!",$this->auth->getUserinfo());
- }
- /**
- * 获取个人信息
- */
- public function getUserInfo() {
- $user_id = $this->request->request("user_id");
- if (!$user_id) {
- $this->error(__('Invalid parameters'));
- }
- // 获取基本信息
- $where = [];
- $where["id"] = $user_id;
- $userInfo = $this->userModel->field("id,nickname,image,mobile,avatar,gender,money,age,u_id,level,jewel,age_id,constellation_id,province_id,city_id,desc")->where($where)->find();
- // 获取技能信息
- $skillList = Model("ViewUserSkill")->getSkillInfo($user_id);
- $userInfo["skill"] = implode("/",$skillList);
- // 获取关注粉丝信息
- $followModel = new \app\common\model\ViewFollows();
- $fansModel = new \app\common\model\ViewFans();
- // 获取关注信息
- $where = [];
- $where["user_id"] = $user_id;
- $userCount = $followModel->where($where)->value("follows"); //该用户关注了几个人
- $userInfo["follows_count"] = $userCount?$userCount:0;
- // 获取粉丝数
- $where = [];
- $where["user_id"] = $user_id;
- $fansCount = $fansModel->where($where)->value("fans"); //该用户的粉丝数
- $userInfo["fans_count"] = $fansCount?$fansCount:0;
- // 获取贵族信息
- $nobleInfo = $this->userModel->getUserNobleInfo($user_id);
- // 查看者是否已关注
- $followid = \app\common\model\UserFansFollow::where(["fans_id"=>$this->auth->id,"user_id"=>$user_id])->value("id");
- $userInfo["is_follow"] = $followid>0?1:0;
- $userInfo = json_decode(json_encode($userInfo),true);
- $userInfo = array_merge($userInfo,$nobleInfo);
- // 获取用户在派对直播间情况信息
- $redis = new Redis();
- $redisconfig = config("redis");
- $redis->connect($redisconfig["host"], $redisconfig["port"]);
- if ($redisconfig['redis_pwd']) {
- $redis->auth($redisconfig['redis_pwd']);
- }
- if($redisconfig['redis_selectdb'] > 0){
- $redis->select($redisconfig['redis_selectdb']);
- }
- $livingUserPartyId = $redis->hGet("livingUser", $user_id);
- $userInfo['party_info'] = json([]);
- if ($livingUserPartyId) {
- $party = \app\common\model\Party::where('id',$livingUserPartyId)->field('id,room_type')->find();
- $userInfo['party_info'] = ['party_id' => $party['id'], 'room_type' => $party['room_type']];
- }
- //访客记录
- $visit_data = [
- 'user_id' => $this->auth->id,
- 'visit_user_id' => $user_id,
- ];
- $visit_check = Db::name('user_visitlist')->where($visit_data)->find();
- if(empty($visit_check)){
- $visit_data['updatetime'] = time();
- Db::name('user_visitlist')->insertGetId($visit_data);
- }else{
- Db::name('user_visitlist')->where('id',$visit_check['id'])->update(['updatetime'=>time()]);
- }
- $this->success("获取成功!",$userInfo);
- }
- /**
- * 添加关注
- */
- public function addFollows() {
- $user_id = $this->request->request("user_id",0,"intval");// 被关注者ID
- $type = $this->request->request("type",1);// 类型:1=关注,2=取消关注
- if (!$user_id || $user_id<=0) {
- $this->error(__('Invalid parameters'));
- }
- if($type == 1) {
- if($user_id == $this->auth->id) {
- $this->error("不需要关注自己哦!");
- }
- $fansfollowModel = new \app\common\model\UserFansFollow();
- $data = [];
- $data["user_id"] = $user_id;
- $data["fans_id"] = $this->auth->id;
- if($fansfollowModel->where($data)->find()) {
- $this->error("你已经关注过ta啦!");
- }
- $data["createtime"] = time();
- $id = $fansfollowModel->insertGetId($data);
- //关注通知
- $msgdata = [
- 'user_id'=>$user_id,
- 'title' => '有人刚刚关注了你',
- 'content'=> '打开[消息][最新关注]即可查看',
- 'createtime' => time(),
- ];
- Db::name('message')->insertGetId($msgdata);
- if($id > 0) {
- // 增加任务进度 +exp
- \app\common\model\TaskLog::tofinish($this->auth->id,"ebxLwnXj3L",1);
- // 增加任务进度 +exp
- \app\common\model\TaskLog::tofinish($this->auth->id,"iA1QgRhL",1);
- // 增加任务进度 +exp
- \app\common\model\TaskLog::tofinish($this->auth->id,"ghopE4Ou",1);
- // 增加任务进度 +exp
- \app\common\model\TaskLog::tofinish($this->auth->id,"TryNGc1x",1);
- $this->success("关注成功!");
- } else {
- $this->error("网络错误,请稍后重试!");
- }
- } else {
- $fansfollowModel = new \app\common\model\UserFansFollow();
- $where = [];
- $where["user_id"] = $user_id;
- $where["fans_id"] = $this->auth->id;
- $fansfollowInfo = $fansfollowModel->where($where)->find();
- if(!$fansfollowInfo) {
- $this->error("关注信息获取失败!");
- }
- $res = $fansfollowModel->where($where)->delete();
- if($res > 0) {
- $this->success("取消成功!");
- } else {
- $this->error("网络错误,请稍后重试!");
- }
- }
- }
- /**
- * 是否关注
- */
- public function isFollows() {
- $user_id = $this->request->request("user_id",0,"intval");// 关注者ID
- if (!$user_id || $user_id<=0) {
- $this->error(__('Invalid parameters'));
- }
- $fansfollowModel = new \app\common\model\UserFansFollow();
- $where = [];
- $where["user_id"] = $user_id;
- $where["fans_id"] = $this->auth->id;
- $fansfollowInfo = $fansfollowModel->where($where)->find();
- $data = [];
- if($fansfollowInfo) {
- $data["is_show_follow"] = 0;
- } else {
- $data["is_show_follow"] = 1;
- }
- $this->success("获取成功!",$data);
- }
- /**
- * 获取关注人列表.派对信息
- */
- public function getFollowsLive() {
- $is_online = $this->request->request("is_online");// 是否在线:1=直播中,0=未开播
- $page = $this->request->request('page',1); // 分页
- $pageNum = $this->request->request('pageNum',10); // 分页
- // 分页搜索构建
- $pageStart = ($page-1)*$pageNum;
- $is_online == 1 || $is_online = 0;
- $fanfollowModel = new \app\common\model\UserFansFollow();
- $where = [];
- $where["a.fans_id"] = $this->auth->id;
- $where["p.room_type"] = 2;
- $where["p.is_online"] = $is_online;
- if($is_online == 1) {
- $field = "p.id as party_id,u.u_id,u.nickname,p.party_name,p.party_hot,p.party_logo,u.avatar,t.id as party_type";
- } else {
- $field = "p.id as party_id,a.user_id,u.avatar,u.gender,u.level,u.nickname,p.party_name,p.party_logo,t.id as party_type";
- }
- $list = $fanfollowModel->alias("a")
- ->field($field)
- ->join("hx_user u","u.id = a.user_id")
- ->join("hx_party p","p.user_id = a.user_id")
- ->join("hx_party_type t","t.id = p.party_type","left")
- ->limit($pageStart,$pageNum)
- ->where($where)->select();
- if($list) {
- foreach($list as $k => $v) {
- $mod = isset($v["party_type"])?intval($v["party_type"])%5:1;
- if(isset($v["type_name"]) && $v["type_name"]) {
- $type_name = $v["type_name"];
- } else {
- $type_name = "普通房";
- }
- $list[$k]["party_type"] = $type_name;
- $list[$k]["party_type_color"] = $mod == 0?5:$mod;
- }
- $this->success("获取成功!",$list);
- } else {
- $this->success("数据为空!",[]);
- }
- }
- /**
- * 获取关注列表
- * (个人中心模块)(消息-最新关注)
- */
- public function getFollowsUser() {
- $type = $this->request->request('type',1); // 1=关注,2=粉丝
- $page = $this->request->request('page',1); // 分页
- $pageNum = $this->request->request('pageNum',10); // 分页
- // 分页搜索构建
- $pageStart = ($page-1)*$pageNum;
- $pageEnd = $pageStart + $pageNum;
- $fanfollowModel = new \app\common\model\UserFansFollow();
- // 获取关注列表
- $where = [];
- $where["a.fans_id"] = $this->auth->id;
- $followlist = $fanfollowModel->alias("a")
- ->field("a.id,a.user_id,a.createtime,u.avatar,u.nickname,u.level,u.gender")
- ->join("hx_user u","u.id = a.user_id")
- // ->limit($pageStart,$pageNum)
- ->where($where)->order('a.id desc')->select();
- // 获取粉丝列表
- $where = [];
- $where["a.user_id"] = $this->auth->id;
- $fanslist = $fanfollowModel->alias("a")
- ->field("a.id,a.fans_id,a.createtime,u.avatar,u.nickname,u.level,u.gender")
- ->join("hx_user u","u.id = a.fans_id")
- // ->limit($pageStart,$pageNum)
- ->where($where)->order('a.id desc')->select();
- // print_r(json_encode($followlist));exit;
- if($type == 1) {
- $ids = [];
- if($fanslist) {
- foreach($fanslist as $k => $v) {
- $ids[] = $v["fans_id"];
- }
- }
- if($followlist) {
- foreach($followlist as $k => $v) {
- $followlist[$k]['createtime_text'] = get_last_time($v['createtime']);
- if(in_array($v["user_id"],$ids)) {
- $followlist[$k]["is_hu"] = 1;
- } else {
- $followlist[$k]["is_hu"] = 0;
- }
- }
- }
- $fansfollow = $followlist;
- } else {
- $ids = [];
- if($followlist) {
- foreach($followlist as $k => $v) {
- $ids[] = $v["user_id"];
- }
- }
- if($fanslist) {
- foreach($fanslist as $k => $v) {
- $fanslist[$k]['createtime_text'] = get_last_time($v['createtime']);
- if(in_array($v["fans_id"],$ids)) {
- $fanslist[$k]["is_hu"] = 1;
- } else {
- $fanslist[$k]["is_hu"] = 0;
- }
- }
- }
- $fansfollow = $fanslist;
- }
- if($fansfollow) {
- $data = [];
- foreach($fansfollow as $k => $v) {
- if($k >= $pageStart && $k < $pageEnd) {
- $data[] = $v;
- }
- }
- $this->success("获取成功!",$data);
- } else {
- $this->success("数据为空!",[]);
- }
- }
- /**
- * 获取最近访客
- * (消息)
- */
- public function getMyVisitList(){
- $list = Db::name('user_visitlist')->alias('uv')
- ->field('uv.id,uv.user_id,uv.updatetime,user.nickname,user.avatar,user.gender,user.desc')
- ->join('user','uv.user_id = user.id','LEFT')
- ->where('uv.visit_user_id',$this->auth->id) //被访问者
- ->order('uv.id desc')->autopage()->select();
- $list = list_domain_image($list,['avatar']);
- if(!empty($list)){
- foreach($list as $key => &$val){
- //关注
- $val['is_follow'] = $this->is_follow($val['user_id'],$this->auth->id);
- }
- }
- $this->success(1,$list);
- }
- /**
- * 获取附近的人
- * (消息-同城)
- */
- public function getSamecityList(){
- if(!$this->auth->city_id){
- $this->success(1,[]);
- }
- $where = [
- 'status' => 'normal',
- 'city_id'=> $this->auth->city_id,
- ];
- //排除黑名单的
- $black_ids = Db::name('user_blacklist')->where('user_id',$this->auth->id)->column('black_user_id');
- if(!empty($black_ids)){
- $where['id'] = ['NOTIN',$black_ids];
- }
- $list = Db::name('user')->where($where)->where('id','neq',$this->auth->id)->field('id,nickname,avatar,gender,desc')->order('id desc')->autopage()->select();
- $list = list_domain_image($list,['avatar']);
- if(!empty($list)){
- foreach($list as $key => &$val){
- //关注
- $val['is_follow'] = $this->is_follow($val['id'],$this->auth->id);
- }
- }
- $this->success(1,$list);
- }
- //是否关注
- private function is_follow($user_id,$fans_id){
- $where = [
- 'user_id' => $user_id,
- 'fans_id' => $fans_id,
- ];
- $check = Db::name('user_fans_follow')->where($where)->find();
- if($check){
- return 1;
- }else{
- return 0;
- }
- }
- /**
- * 获取个人技能列表
- */
- public function getMySkillList() {
- $user_id = $this->request->request('user_id',0); // 用户ID
- $page = $this->request->request('page',1); // 分页
- $pageNum = $this->request->request('pageNum',10); // 分页
- if ($user_id == -1) {
- $user_id = $this->auth->id;
- } elseif($user_id>0) {
- $user_id = intval($user_id);
- } else {
- $this->error(__('Invalid parameters'));
- }
- // 分页搜索构建
- $pageStart = ($page-1)*$pageNum;
- $authModel = new \app\common\model\DispatchAuth();
- $where = [];
- $where["a.user_id"] = $user_id;
- $where["a.status"] = 1;
- $authskillList = $authModel->alias("a")
- ->field("a.id,ds.image,ds.name,a.voice,a.voice_time,a.price,a.is_main,ds.unit")
- ->join("hx_dispatch_skill ds","ds.id = a.skill_id")
- ->where($where)
- ->limit($pageStart,$pageNum)
- ->select();
- $this->success("获取成功!",$authskillList);
- }
- /**
- * 删除个人技能信息
- */
- public function delMySkillInfo() {
- $id = $this->request->request('id'); // 认证ID
- if (!$id) {
- $this->error(__('Invalid parameters'));
- }
- $authModel = new \app\common\model\DispatchAuth();
- $where = [];
- $where["id"] = $id;
- $where["user_id"] = $this->auth->id;
- $authInfo = $authModel->where($where)->find();
- if(!$authInfo) $this->error("技能认证未找到");
- // if($authInfo->is_main == 1) $this->error("请先取消主技能,再删除!");
- Db::startTrans();
- try{
- $res1 = $authInfo->delete();
- $res2 = \app\common\model\UserSkill::where(["user_id"=>$this->auth->id,"skill_id"=>$authInfo->skill_id])->delete();
- if($res1 && $res2) {
- Db::commit();
- $this->success("删除成功!");
- } else {
- $this->error("网络错误,请稍后重试!");
- }
- }catch (ValidateException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (PDOException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- }
- /**
- * 修改个人技能信息
- */
- public function editMySkillInfo() {
- $price = $this->request->request('price'); // 价格
- $id = $this->request->request('id'); // 认证ID
- $is_main = $this->request->request('is_main'); // 是否设置为主技能
- if (!$id && !$price) {
- $this->error(__('Invalid parameters'));
- }
- $authModel = new \app\common\model\DispatchAuth();
- $where = [];
- $where["id"] = $id;
- if(!$authModel->where($where)->find()) $this->error("技能认证未找到");
- Db::startTrans();
- try{
- if($is_main == 1) {
- $where = [];
- $where["user_id"] = $this->auth->id;
- $authModel->update(["is_main"=>0],$where);
- }
- $where = [];
- $where["id"] = $id;
- $data = [];
- $data["price"] = $price;
- $data["is_main"] = $is_main;
- $res = $authModel->update($data,$where);
- $myAuthList = $authModel->where(["user_id"=>$this->auth->id,"is_main"=>1])->find();
- if(!$myAuthList) {
- $this->error("必须至少设置一个主技能");
- Db::rollback();
- }
- if($res) {
- Db::commit();
- $this->success("修改成功!",$data);
- } else {
- $this->error("网络错误,请稍后重试!");
- }
- }catch (ValidateException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (PDOException $e) {
- Db::rollback();
- $this->error($e->getMessage());
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- }
- /**
- * 编辑个人信息
- */
- public function editUserInfo() {
- $avatar = $this->request->request('avatar'); // 头像
- $nickname = $this->request->request('nickname'); // 昵称
- $age = $this->request->request('age'); // 年龄
- $ageId = $this->request->request('age_id'); // 年龄段
- $gender = $this->request->request('gender'); // 性别 0=女,1=男
- $image = $this->request->request('image'); // 个人形象照
- $constellationId = $this->request->request('star_id'); //星座ID
- $provinceId = $this->request->request('province_id'); //省ID
- $cityId = $this->request->request('city_id'); //城市ID
- $desc = $this->request->request('desc'); //个性签名
- /*if (!$avatar && !$nickname && !$age && !$image && !in_array($gender,[0,1])) {
- $this->error(__('请输入要修改的信息'));
- }*/
- $where = [];
- $where["id"] = $this->auth->id;
- $data = [];
- $avatar && $data["avatar"] = $avatar;
- if($nickname){
- if (mb_strlen($nickname) > 8) {
- $this->error('用户昵称最多支持8个汉字或组合');
- }
- $data["nickname"] = $nickname;
- }
- $gender && $data["gender"] = $gender;
- $age && $data["age"] = $age;
- $image && $data["image"] = $image;
- $ageId && $data['age_id'] = $ageId;
- $constellationId && $data['constellation_id'] = $constellationId;
- $provinceId && $data['province_id'] = $provinceId;
- $cityId && $data['city_id'] = $cityId;
- $desc && $data['desc'] = $desc;
- $res = $this->userModel->update($data,$where);
- if($res) {
- $user = $this->userModel->where($where)->find();
- if (!empty($user['nickname']) && !empty($user['avatar']) && !empty($user['age_id']) && $user['has_info']==0) {
- $data['has_info'] = 1;
- $this->userModel->update($data,$where);
- }
- $this->success("修改成功!");
- } else {
- $this->error("网络错误,请稍后重试!");
- }
- }
- /**
- * 主播申请
- */
- public function anchorApply() {
- $type_id = $this->request->request('type_id'); // 技能分类ID
- $desc = $this->request->request('desc'); // 申请备注
- if (!$type_id && !$desc) {
- $this->error(__('Invalid parameters'));
- }
- $useranchorModel = new \app\common\model\UserAnchor();
- $data = [];
- $data["user_id"] = $this->auth->id;
- $data["type_id"] = $type_id;
- if($useranchorModel->where($data)->find()) $this->error(__('您已申请过该类型的主播,请勿重复申请!'));
- $data["desc"] = $desc;
- $data["createtime"] = time();
- $res = $useranchorModel->insertGetId($data);
- if($res) {
- \app\common\model\User::update(["is_anchor"=>1],["id"=>$this->auth->id]);
- $this->success("申请发送成功!");
- } else {
- $this->error("网络错误,请稍后重试");
- }
- }
- /**
- * 实名认证
- */
- public function authApply() {
- $realname = $this->request->request('realname'); // 真实姓名
- $idcard = $this->request->request('idcard'); // 身份证号
- $zimage = $this->request->request('zimage'); // 身份证正面照
- $fimage = $this->request->request('fimage'); // 身份证反面照
- if (!$realname && !$idcard && !$zimage && !$fimage) {
- $this->error(__('Invalid parameters'));
- }
- $userauthModel = new \app\common\model\UserAuth();
- $data = [];
- $data["user_id"] = $this->auth->id;
- //$data["idcard"] = $idcard;
- $userAuth = $userauthModel->where($data)->find();
- if (!empty($userAuth)) {
- if(in_array($userAuth['status'],[0,1])) $this->error('您已经申请过了,请勿重复操作!');
- }
-
- // 测试需要 开始
- $data["realname"] = $realname;
- $zimage && $data["zimage"] = $zimage;
- $fimage && $data["fimage"] = $fimage;
- $data["status"] = 1;
- if (!empty($userAuth)) {
- $data["updatetime"] = time();
- $authWhere['user_id'] = $this->auth->id;
- $res = $userauthModel->where($authWhere)->update($data);
- } else {
- $data["createtime"] = time();
- $res = $userauthModel->insertGetId($data);
- }
- if($res) {
- \app\common\model\User::update(["is_auth"=>2],["id"=>$this->auth->id]);
- $this->success("恭喜,实名认证成功!");
- } else {
- $this->error("网络错误,请稍后重试");
- }
- // 测试需要 结束
- // 实名认证验证
- $configInfo = config("auth");
- $outh = new outh($configInfo["api_url"],$configInfo["customer_code"],$configInfo["private_key"],$configInfo["key"]);
- $out_trade_no = date("YmdHis").rand(1000,9999);
- $ret = $outh->toVerify($out_trade_no,$realname,$idcard);
- if(isset($ret["code"])) {
- if($ret["code"] == "1008") {
- $this->error(__('身份证格式错误'));
- }
- if($ret["code"] == "1009") {
- $this->error(__('身份证格式错误'));
- }
- if($ret["code"] == "0001") {
- $this->error(__('姓名和身份证号不匹配!'));
- }
- if($ret["code"] == "0000") {
- $data["realname"] = $realname;
- $zimage && $data["zimage"] = $zimage;
- $fimage && $data["fimage"] = $fimage;
- $data["status"] = 1;
- $data["createtime"] = time();
- $res = $userauthModel->insertGetId($data);
- if($res) {
- \app\common\model\User::update(["is_auth"=>2],["id"=>$this->auth->id]);
- $this->success("恭喜,实名认证成功!");
- } else {
- $this->error("网络错误,请稍后重试");
- }
- }
- } else {
- $this->error("网络错误,请稍后重试");
- }
- }
- /**
- * 获取主播分类
- */
- public function getAnchorType() {
- $this->success("获取成功!",\app\common\model\UserAnchorType::select());
- }
- /**
- * 加入黑名单
- */
- public function addBlacklist() {
- $black_user_id = $this->request->request('black_user_id'); // 黑名单用户ID
- if (!$black_user_id) {
- $this->error(__('Invalid parameters'));
- }
- $userblacklistModel = new \app\common\model\UserBlacklist();
- $data = [];
- $data["user_id"] = $this->auth->id;
- $data["black_user_id"] = $black_user_id;
- if($userblacklistModel->where($data)->find()) $this->error(__('已在黑名单!'));
- $data["createtime"] = time();
- $res = $userblacklistModel->insertGetId($data);
- if($res) {
- $this->success("加入成功!");
- } else {
- $this->error("网络错误,请稍后重试");
- }
- }
- /**
- * 获取黑名单用户
- */
- public function getBlacklist() {
- $page = $this->request->request('page',1); // 分页
- $pageNum = $this->request->request('pageNum',10); // 分页
- // 分页搜索构建
- $pageStart = ($page-1)*$pageNum;
- $userblacklistModel = new \app\common\model\UserBlacklist();// ->limit($pageStart,$pageNum)
- $where = [];
- $where["a.user_id"] = $this->auth->id;
- $list = $userblacklistModel->alias("a")
- ->field("a.id,a.black_user_id,u.avatar,u.nickname,u.level,u.gender")
- ->join("hx_user u","u.id = a.black_user_id")
- ->where($where)
- ->limit($pageStart,$pageNum)
- ->select();
- if($list) {
- $this->success("获取成功!",$list);
- } else {
- $this->success("数据为空",[]);
- }
- }
- /**
- * 移除用户黑名单
- */
- public function removeUserBlack() {
- $id = $this->request->request('id'); // 黑名单ID
- if (!$id) {
- $this->error(__('Invalid parameters'));
- }
- $userblacklistModel = new \app\common\model\UserBlacklist();
- $where = [];
- $where["id"] = $id;
- $res = $userblacklistModel->where($where)->delete();
- if($res) {
- $this->success("移除成功!",$res);
- } else {
- $this->error("网络错误,请稍后重试!");
- }
- }
- /**
- * 举报用户
- */
- /*public function addReport() {
- $ruser_id = $this->request->request('ruser_id'); // 被举报用户ID
- $content = $this->request->request('content'); // 举报内容
- $image = $this->request->request('image'); // 图片描述(多个用半角逗号隔开)
- if (!$ruser_id) {
- $this->error(__('Invalid parameters'));
- }
- $userreportModel = new \app\common\model\UserReport();
- $data = [];
- $data["user_id"] = $this->auth->id;
- $data["reportable_id"] = $ruser_id;
- $data['reportable_type'] = $this->getModelName('user');
- $data["content"] = $content;
- $data["image"] = $image;
- $data["createtime"] = time();
- $res = $userreportModel->insertGetId($data);
- if($res) {
- $this->success("举报成功!");
- } else {
- $this->error("网络错误,请稍后重试");
- }
- }*/
- /**
- * 举报
- */
- /*public function addReportNew() {
- $params = $this->request->param();
- $validate = new Report();
- $result = $validate->check($params);
- if (!$result) {
- $this->error($validate->getError());
- }
- $userreportModel = new \app\common\model\UserReport();
- $data = [];
- $data["user_id"] = $this->auth->id;
- $data["reportable_id"] = $params['reportable_id'];
- $data['reportable_type'] = $this->getModelName($params['reportable_type']);
- $data["content"] = $params['content'];
- $data["image"] = $params['image'];
- $data["createtime"] = time();
- $res = $userreportModel->insertGetId($data);
- if($res) {
- $this->success("举报成功!");
- } else {
- $this->error("网络错误,请稍后重试");
- }
- }*/
- /**
- * redis 数据恢复---非redis数据丢失请勿使用!!!!
- */
- public function shujuhuifu() {
- $key = $this->request->request("key");// 操作验证 123456
- if($key != 123456) {
- $this->error(__('Invalid parameters'));
- }
- $giftuserpartyModel = new \app\common\model\GiftUserParty();
- $redis = new Redis();
- $redisconfig = config("redis");
- $redis->connect($redisconfig["host"], $redisconfig["port"]);
- if ($redisconfig['redis_pwd']) {
- $redis->auth($redisconfig['redis_pwd']);
- }
- if($redisconfig['redis_selectdb'] > 0){
- $redis->select($redisconfig['redis_selectdb']);
- }
- // 获取本周第一天
- $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
- // 获取本月第一天
- $monthday = date("Ym01");
- $where = [];
- $where["createtime"] = ["gt",strtotime($weekday)];
- $list1 = $giftuserpartyModel->where($where)->select();
- foreach($list1 as $k => $v) {
- // 添加redis记录做财富排行榜周榜用
- $redis->zIncrBy("jewel_get_".$v["party_id"].":".$weekday,$v["value"],$v["user_to_id"]);
- // 添加redis记录做贡献排行榜周榜用
- $redis->zIncrBy("jewel_to_".$v["party_id"].":".$weekday,$v["value"],$v["user_id"]);
- }
- $where = [];
- $where["createtime"] = ["gt",strtotime(date("Y-m-01"))];
- $list2 = $giftuserpartyModel->where($where)->select();
- foreach($list2 as $k => $v) {
- // 添加redis记录做财富排行榜月榜用
- $redis->zIncrBy("jewel_get_".$v["party_id"].":".$monthday,$v["value"],$v["user_to_id"]);
- // 添加redis记录做贡献排行榜月榜用
- $redis->zIncrBy("jewel_to_".$v["party_id"].":".$monthday,$v["value"],$v["user_id"]);
- }
- $this->success("执行成功!");
- }
- /**
- * 获取用户钻石余额
- */
- public function getUserJewel() {
- $data = \app\common\model\User::field("Jewel,money")->where(["id"=>$this->auth->id])->find();
- return $this->success("获取成功!",$data);
- }
- /**
- * 获取用户等级说明
- */
- public function getLevelExplain() {
- $data = \app\common\model\UserLevelExplain::field("title,content")->select();
- return $this->success("获取成功!",$data);
- }
- /**
- * 获取用户等级信息
- */
- public function getUserLevelInfo() {
- $res = [];$exstart = 0;$exend = 0;
- $userModel = new \app\common\model\User();
- $userInfo = $userModel->field("id,nickname,avatar,level,empirical")->where(["id"=>$this->auth->id])->find();
- if(!$userInfo) {
- $this->error("用户信息获取失败!");
- }
- $res["avatar"] = $userInfo['avatar'];
- $res["nickname"] = $userInfo['nickname'];
- // 获取用户当前经验值对应等级
- $userconfigModel = new \app\common\model\UserLevelConfig();
- $where = [];
- $where["empirical"] = ["elt",$userInfo["empirical"]];
- $userexplainstart = $userconfigModel->where($where)->order("empirical","desc")->limit(1)->select();
- $where = [];
- $where["empirical"] = ["gt",$userInfo["empirical"]];
- $userexplainend = $userconfigModel->where($where)->order("empirical","asc")->limit(1)->select();
- if(!$userexplainstart && !$userexplainend) {
- $this->error("经验等级信息获取失败!");
- } elseif(!$userexplainstart && $userexplainend) {
- $res["level_start"] = 0;
- $res["level_end"] = $userexplainend[0]["level"];
- } elseif($userexplainstart && !$userexplainend) {
- $res["level_start"] = $userexplainstart[0]["level"];
- $res["level_end"] = $userexplainstart[0]["level"];
- } elseif($userexplainstart && $userexplainend) {
- $res["level_start"] = $userexplainstart[0]["level"];
- $res["level_end"] = $userexplainend[0]["level"];
- }
- $userexplainstart && $exstart = $userexplainstart[0]["empirical"];
- $userexplainend && $exend = $userexplainend[0]["empirical"];
- $r1 = $exend-$exstart; // 等级经验值差
- $r2 = $userInfo["empirical"]-$exstart; // 当前等级与最低等级经验值差
- $r3 = $exend-$userInfo["empirical"]; // 还需多少经验值升级
- if($r1 == 0) {
- $res["level_rate"] = 1;
- } elseif($r2 == 0) {
- $res["level_rate"] = 0;
- if($res["level_start"] == $res["level_end"]) {
- $res["level_rate"] = 1;
- }
- } else {
- $res["level_rate"] = intval(($r2/$r1)*100)/100;
- }
- $res["to_up_need"] = $r3>0?$r3:0;
- // // 满级
- // if($r3 == 0 && !$userexplainend) {
- // $res["level_rate"] = 1;
- // }
- $this->success("获取成功!",$res);
- }
- }
|