123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\library\Ems;
- use app\common\library\Sms;
- use fast\Random;
- use think\Config;
- use think\Validate;
- use app\common\library\Token;
- use think\Db;
- use onlogin\onlogin;
- use app\common\library\Keyworld;
- use addons\epay\library\Service;
- //use addons\epay\library\Wechat;
- use app\common\library\Wechat;
- /**
- * 会员接口,登录,注册,修改资料等
- */
- class User extends Api
- {
- protected $noNeedLogin = ['login','h5register', 'mobilelogin','wechatlogin','applelogin','bindmobile','applebindmobile', 'register', 'resetpwd', 'changemobile', 'onlogin','getUserOpenid_gzh','jssdkBuildConfig'];
- protected $noNeedRight = '*';
- public function _initialize()
- {
- parent::_initialize();
- }
- /**
- * 会员中心
- */
- public function index()
- {
- $this->success('', ['welcome' => $this->auth->nickname]);
- }
- //h5注册
- public function h5register()
- {
- $mobile = input('mobile');
- $captcha = input('captcha');
- $invite_no = input('invite_no','');
- $intro_no = input('intro_no','');
- if (!$mobile || !$captcha) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
- $this->error(__('Captcha is incorrect'));
- }
- $user = \app\common\model\User::getByMobile($mobile);
- if ($user) {
- $this->error('该手机号已经注册过了');
- } else {
- $extend = [];
- if($invite_no == 'undefined'){$invite_no = '';}
- if($intro_no == 'undefined'){$intro_no = '';}
- if(!empty($invite_no)){
- $inviteUserInfo = \app\common\model\User::where(["introcode" => $invite_no])->find();
- if (!$inviteUserInfo) {
- //$this->error("查询不到该邀请码用户信息!");
- }else{
- $extend['invite_uid'] = $inviteUserInfo['id'];
- }
- }elseif(!empty($intro_no)){
- $introUserInfo = \app\common\model\User::where(["introcode" => $intro_no])->find();
- if (!$introUserInfo) {
- //$this->error("查询不到该邀请码用户信息!");
- }else{
- $extend['intro_uid'] = $introUserInfo['id'];
- }
- }
- $ret = $this->auth->register('','','', $mobile, $extend);
- }
- if ($ret) {
- $this->success('注册成功');
- } else {
- $this->error($this->auth->getError());
- }
- }
- /**
- * 手机验证码登录
- *
- * @ApiMethod (POST)
- * @param string $mobile 手机号
- * @param string $captcha 验证码
- */
- public function mobilelogin()
- {
- $mobile = input('mobile');
- $captcha = input('captcha');
- if (!$mobile || !$captcha) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
- $this->error(__('Captcha is incorrect'));
- }
- $user = \app\common\model\User::getByMobile($mobile);
- if ($user) {
- if ($user->status == -1) {
- $this->error('账户已注销');
- }
- if ($user->status != 1) {
- $this->error(__('Account is locked'));
- }
- //如果已经有账号则直接登录
- $ret = $this->auth->direct($user->id);
- } else {
- $extend = [
- 'plat_unique_id' => input('plat_unique_id',''),
- 'plat_from' => input('plat_from',''),
- ];
- $ret = $this->auth->register('', '', '', $mobile, $extend);
- }
- if ($ret) {
- Sms::flush($mobile, 'mobilelogin');
- $data = $this->auth->getUserinfo_simple();
- $this->success(__('Logged in successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
- /**
- * 手机注册来的,绑定微信
- *
- * @ApiMethod (POST)
- * @param string $wechat_openid
- */
- public function bindopenid()
- {
- $code = input('code','');
- if(!$code){
- $this->error(__('Invalid parameters'));
- }
- //微信
- $wechat = new Wechat();
- $wxuserinfo = $wechat->getAccessToken($code);
- if(!$wxuserinfo){
- $this->error('openid获取失败');
- }
- if(!is_array($wxuserinfo) || !isset($wxuserinfo['openid'])){
- $this->error('openid获取失败');
- }
- $wechat_openid = $wxuserinfo['openid'];
- if(!empty($this->auth->wechat_openid)){
- //$this->error('已经绑定了微信号'); //让openid能修改,不报错了
- }
- $otherUserWhere['wechat_openid'] = $wechat_openid;
- $otherUserWhere['id'] = ['neq',$this->auth->id];
- if (\app\common\model\User::where($otherUserWhere)->find()) {
- $this->error('该微信号已被其他用户绑定');
- }
- $user = $this->auth->getUser();
- $user->wechat_openid = $wechat_openid;
- $user->save();
- $this->success('绑定成功',$this->auth->getUserinfo_simple());
- }
- //微信登录+注册
- public function wechatlogin(){
- $code = input('code','');
- if(!$code){
- $this->error(__('Invalid parameters'));
- }
- //微信
- $wechat = new Wechat();
- $wxuserinfo = $wechat->getAccessToken($code);
- if(!$wxuserinfo){
- $this->error('openid获取失败');
- }
- if(!is_array($wxuserinfo) || !isset($wxuserinfo['openid'])){
- $this->error('openid获取失败');
- }
- $openid = $wxuserinfo['openid'];
- //
- $user = Db::name('user')->where('wechat_openid',$openid)->find();
- if ($user) {
- if ($user['status'] == -1) {
- $this->error('账户已注销');
- }
- if ($user['status'] != 1) {
- $this->error(__('Account is locked'));
- }
- //如果已经有账号则直接登录
- $ret = $this->auth->direct($user['id']);
- } else {
- $extend = [
- 'plat_unique_id' => input('plat_unique_id',''),
- 'plat_from' => input('plat_from',''),
- ];
- $ret = $this->auth->openid_register($openid,$extend);
- }
- if ($ret) {
- $data = $this->auth->getUserinfo_simple();
- $this->success(__('Logged in successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
- /**
- * 微信注册来的,绑定手机号
- *
- * @ApiMethod (POST)
- * @param string $mobile 手机号
- * @param string $captcha 验证码
- */
- public function bindmobile()
- {
- $mobile = input('mobile');
- $captcha = input('captcha');
- if(!empty($this->auth->mobile)){
- $this->error('已经绑定了手机号');
- }
- if (!$mobile || !$captcha) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- if (\app\common\model\User::where('mobile', $mobile)->find()) {
- $this->error('该手机号已被其他用户绑定');
- }
- $result = Sms::check($mobile, $captcha, 'changemobile');
- if (!$result) {
- $this->error(__('Captcha is incorrect'));
- }
- $user = $this->auth->getUser();
- $user->mobile = $mobile;
- $user->save();
- Sms::flush($mobile, 'changemobile');
- $this->success('绑定成功',$this->auth->getUserinfo_simple());
- }
- //用户详细资料
- public function userInfo($type = 1){
- $info = $this->auth->getUserinfo();
- if($type == 'return'){
- return $info;
- }
- $this->success(__('success'),$info);
- }
- /**
- * 退出登录
- * @ApiMethod (POST)
- */
- public function logout()
- {
- if (!$this->request->isPost()) {
- $this->error(__('Invalid parameters'));
- }
- //退出im
- // $tenIm = new Tenim();
- // $tenIm->loginoutim($this->auth->id);
- $this->auth->logout();
- $this->success(__('Logout successful'));
- }
- /**
- * 修改会员个人信息
- *
- * @ApiMethod (POST)
- * @param string $avatar 头像地址
- * @param string $username 用户名
- * @param string $nickname 昵称
- * @param string $bio 个人简介
- */
- public function profile()
- {
- $field_array = [
- 'avatar','nickname','birthday','gender',
- 'audio_bio','audio_seconds','photo_images','video_bio',
- 'height','weight','bio',
- 'marital_id','job_id','wages_id','suqiu_id','tag_ids','hobby_ids',
- 'hide_is_finishinfo',
- 'invite_no',
- ];
- $data = [];
- foreach($field_array as $key => $field){
- //前端传不了post,改了
- /*if(!request()->has($field,'post')){
- continue;
- }*/
- if(!input('?'.$field)){
- continue;
- }
- $newone = input($field);
- if($field == 'avatar'){
- $newone = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
- }
- if($field == 'photo_images'){
- $newone = input('photo_images', '', 'trim,strip_tags,htmlspecialchars');
- }
- if($field == 'nickname'){
- $newone = Keyworld::sensitive($newone);
- }
- if($field == 'bio'){
- $newone = Keyworld::sensitive($newone);
- }
- $data[$field] = $newone;
- }
- //视频,需要审核
- $user_audit_switch = 1;
- if(isset($data['video_bio']) && !empty($data['video_bio']) && $user_audit_switch == 1){
- $check_exist = Db::name('user_audit')->where('user_id',$this->auth->id)->where('type','video_bio')->where('status',0)->find();
- if(!empty($check_exist)){
- $this->error('信息已提交等待审核,请勿重复提交');
- }
- if($data['video_bio'] != $this->auth->video_bio){
- $bio_data = [
- 'user_id' => $this->auth->id,
- 'type' => 'video_bio',
- 'old_data' => $this->auth->video_bio,
- 'new_data' => $data['video_bio'],
- 'createtime' => time(),
- ];
- Db::name('user_audit')->insertGetId($bio_data);
- $this->error('信息已提交,审核通过后即可正常展示');//正确不弹出,只能用error
- }
- unset($data['video_bio']);
- }
- //相册,需要审核
- if(isset($data['photo_images']) && !empty($data['photo_images']) && $user_audit_switch == 1){
- $check_exist = Db::name('user_audit')->where('user_id',$this->auth->id)->where('type','photo_images')->where('status',0)->find();
- if(!empty($check_exist)){
- $this->error('信息已提交等待审核,请勿重复提交');
- }
- if($data['photo_images'] != $this->auth->photo_images){
- $bio_data = [
- 'user_id' => $this->auth->id,
- 'type' => 'photo_images',
- 'old_data' => $this->auth->photo_images,
- 'new_data' => $data['photo_images'],
- 'createtime' => time(),
- ];
- Db::name('user_audit')->insertGetId($bio_data);
- $this->error('信息已提交,审核通过后即可正常展示');//正确不弹出,只能用error
- }
- unset($data['photo_images']);
- }
- //语音,需要审核
- if(isset($data['audio_bio']) && !empty($data['audio_bio']) && $user_audit_switch == 1){
- $check_exist = Db::name('user_audit')->where('user_id',$this->auth->id)->where('type','audio_bio')->where('status',0)->find();
- if(!empty($check_exist)){
- $this->error('信息已提交等待审核,请勿重复提交');
- }
- if($data['audio_bio'] != $this->auth->audio_bio){
- $bio_data = [
- 'user_id' => $this->auth->id,
- 'type' => 'audio_bio',
- 'old_data' => $this->auth->audio_bio,
- 'new_data' => $data['audio_bio'],
- 'createtime' => time(),
- ];
- Db::name('user_audit')->insertGetId($bio_data);
- //语音秒数
- $bio_data = [
- 'user_id' => $this->auth->id,
- 'type' => 'audio_seconds',
- 'old_data' => $this->auth->audio_seconds,
- 'new_data' => $data['audio_seconds'],
- 'createtime' => time(),
- ];
- Db::name('user_audit')->insertGetId($bio_data);
- $this->error('信息已提交,审核通过后即可正常展示');//正确不弹出,只能用error
- }
- unset($data['audio_bio']);
- unset($data['audio_seconds']);
- }
- //头像,是否需要审核
- if(isset($data['avatar']) && !empty($data['avatar']) && $data['avatar'] != config('avatar_boy') && $data['avatar'] != config('avatar_girl') && $user_audit_switch == 1){
- $check_exist = Db::name('user_audit')->where('user_id',$this->auth->id)->where('type','avatar')->where('status',0)->find();
- if(!empty($check_exist)){
- $this->error('信息已提交等待审核,请勿重复提交');
- }
- if($data['avatar'] != $this->auth->avatar){
- $bio_data = [
- 'user_id' => $this->auth->id,
- 'type' => 'avatar',
- 'old_data' => $this->auth->avatar,
- 'new_data' => $data['avatar'],
- 'createtime' => time(),
- ];
- Db::name('user_audit')->insertGetId($bio_data);
- //失去真人认证
- $data['real_status'] = -1;
- Db::name('user_auth')->where(['user_id' => $this->auth->id])->delete();
- if(!isset($data['gender'])){
- $this->error('信息已提交,审核通过后即可正常展示');//正确不弹出,只能用error
- }
- }
- unset($data['avatar']);
- }
- //第一次传入性别,头像只能用默认,因为自传头像需要审核
- if(isset($data['gender']) && $user_audit_switch == 1){
- $data['avatar'] = $data['gender'] == 1 ? config('avatar_boy') : config('avatar_girl');
- }
- //初次设置性别为 男
- if(isset($data['gender']) && $data['gender'] == 1 && $this->auth->gender == -1){
- //男性赠送
- $gift_data = [
- 'audio_sec' => config('site.man_reg_audio_sec'),
- 'video_sec' => config('site.man_reg_video_sec'),
- 'typing_times' => config('site.man_reg_typing_times'),
- ];
- Db::name('user_wallet')->where('user_id',$this->auth->id)->update($gift_data);
- //修改财富值等级为1级
- $data['wealth_level'] = 1;
- }
- if(isset($data['invite_no']) && !empty($data['invite_no']) && empty($this->auth->intro_uid) && empty($this->auth->invite_uid)){
- $invite_user = Db::name('user')->where('introcode',$data['invite_no'])->value('id');
- if($invite_user){
- $data['invite_uid'] = $invite_user;
- }
- unset($data['invite_no']);//别人的邀请码,不能改了自己的
- }
- //
- if(isset($data['birthday'])){
- $data['birthday'] = strtotime($data['birthday']);
- }
- if(isset($data['tag_ids'])){
- $data['tag_ids'] = implode(',',explode(',',$data['tag_ids']));
- }
- if(isset($data['hobby_ids'])){
- $data['hobby_ids'] = implode(',',explode(',',$data['hobby_ids']));
- }
- //dump($data);
- if(empty($data)){
- $this->success();
- }
- Db::startTrans();
- //修改用户
- $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
- if($update_rs === false){
- Db::rollback();
- $this->error('修改资料失败');
- }
- //task任务
- if(isset($data['tag_ids']) || isset($data['bio'])){
- $userinfo = Db::name('user')->where('id',$this->auth->id)->find();
- if($userinfo['hide_is_finishinfo'] == 0){
- if($userinfo['tag_ids'] && $userinfo['bio']){
- //task任务
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,4);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务失败');
- }
- $finish['hide_is_finishinfo'] = 1;//完善资料了
- Db::name('user')->where('id',$this->auth->id)->update($finish);
- }
- }
- }
- Db::commit();
- $this->success();
- }
- public function getpower(){
- $rs = Db::name('user_power')->where('user_id',$this->auth->id)->find();
- $this->success(1,$rs);
- }
- /**
- * 修改会员权限
- */
- public function setpower()
- {
- /*$is_vip = $this->is_vip($this->auth->id);
- if(!$is_vip){
- $this->error('VIP才能设置隐私权限');
- }*/
- $field_array = ['meili','caifu','weizhi','giftwall'];
- $data = [];
- foreach($field_array as $key => $field){
- if(!input('?'.$field)){
- continue;
- }
- $newone = input($field);
- $data[$field] = $newone;
- }
- $update_rs = Db::name('user_power')->where('user_id',$this->auth->id)->update($data);
- $this->success();
- }
- //重新绑定
- public function set_intro(){
- if(isset($data['introcode']) && !empty($data['introcode'])){
- $intro_user = Db::name('user')->where('introcode',$data['introcode'])->value('id');
- if(!$intro_user){
- $this->error('不存在的邀请人');
- }
- if(!empty($this->auth->intro_uid)){
- $this->error('您已经填写过邀请人');
- }
- unset($data['introcode']);//别人的邀请码,不能改了自己的
- $data['intro_uid'] = $intro_user;
- }
- }
- /*
- * 修改用户的坐标
- * */
- public function change_longlat(){
- $this->success();
- // $longitude = input('longitude',0);
- // $latitude = input('latitude',0);
- $cityname = input('cityname','');
- $provincename = input('provincename','');
- /*if(empty($longitude) || empty($latitude) || empty($cityname)){
- $this->error();
- }*/
- $data = [];
- // $longitude && $data['longitude'] = $longitude;
- // $latitude && $data['latitude'] = $latitude;
- $cityname && $data['cityname'] = $cityname;
- $provincename && $data['provincename'] = $provincename;
- //传入了城市,但是没传入省,直接省名改空
- if(isset($data['cityname']) && !isset($data['provincename'])){
- $data['provincename'] = '';
- }
- //没传入城市,但是传入省,直接城市名改空
- if(!isset($data['cityname']) && isset($data['provincename'])){
- $data['cityname'] = '';
- }
- if(!empty($data)){
- Db::name('user')->where('id',$this->auth->id)->update($data);
- }
- $this->success();
- }
- //修改用户设备id
- public function change_plat_unique_id(){
- $plat_unique_id = input('plat_unique_id','');
- $plat_from = input('plat_from','');
- $data = [
- 'plat_unique_id' => $plat_unique_id,
- 'plat_from' => $plat_from,
- ];
- Db::name('user')->where('id',$this->auth->id)->update($data);
- $this->success();
- }
- /**
- * 修改手机号
- *
- * @ApiMethod (POST)
- * @param string $mobile 手机号
- * @param string $captcha 验证码
- */
- public function changemobile()
- {
- $user = $this->auth->getUser();
- $oldcaptcha = $this->request->request('oldcaptcha');
- $mobile = $this->request->request('mobile');
- $captcha = $this->request->request('captcha');
- if (!$oldcaptcha || !$mobile || !$captcha) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- if($user->mobile == $mobile){
- $this->error('新手机号不能与旧手机号相同');
- }
- if (\app\common\model\User::where('mobile', $mobile)->find()) {
- $this->error(__('Mobile already exist'));
- }
- $result = Sms::check($user->mobile, $oldcaptcha, 'changemobile');
- if (!$result) {
- $this->error(__('Captcha is incorrect'));
- }
- $result = Sms::check($mobile, $captcha, 'changemobile');
- if (!$result) {
- $this->error(__('Captcha is incorrect'));
- }
- Sms::flush($user->mobile, 'changemobile');
- Sms::flush($mobile, 'changemobile');
- $user->mobile = $mobile;
- $user->save();
- $this->success();
- }
- //假注销
- public function cancleUser(){
- $captcha = input('captcha','');
- if (!$captcha) {
- $this->error(__('Invalid parameters'));
- }
- if (!Sms::check($this->auth->mobile, $captcha, 'mobilelogin')) {
- $this->error(__('Captcha is incorrect'));
- }
- Db::name('user')->where('id',$this->auth->id)->update(['status'=>-1]);
- $this->auth->logout();
- $this->success('注销成功');
- }
- //文字语音视频收费设置
- public function chargeconfig() {
- $type = input('type', 0, 'intval'); //类型:0=文字,1=语音,2=视频
- if (!in_array($type, [0, 1, 2])) {
- $this->error('您的网络开小差啦~');
- }
- $where['type'] = $type;
- $where['level'] = ['elt',$this->auth->charm_level];
- $list = Db::name('charge_config')->field('id, price, level')->where($where)->order('price asc')->select();
- $this->success('success', $list);
- }
- //文字语音视频收费/隐藏所在位置设置
- public function chargeset() {
- if($this->auth->gender == 1 && $this->auth->idcard_status != 1){
- $this->error('请先完成实名认证');
- }
- if($this->auth->gender == 0 && $this->auth->real_status != 1){
- $this->error('请先完成真人认证');
- }
- $chat_id = input('chat_id', 0, 'intval'); //文字收费id
- $voice_id = input('voice_id', 0, 'intval'); //语音收费id
- $video_id = input('video_id', 0, 'intval'); //视频收费id
- $open_match_audio = input('open_match_audio', -1, 'intval'); //是否开启语音:1是 0否
- $open_match_video = input('open_match_video', -1, 'intval'); //是否开启视频:1是 0否
- $data = [];
- //查询我的魅力等级
- $level = $this->auth->charm_level;
- if ($chat_id) {
- $charge_config = Db::name('charge_config')->where(['id' => $chat_id, 'type' => 0])->find();
- if (!$charge_config) {
- $this->error('您的网络开小差啦~');
- }
- if ($level < $charge_config['level']) {
- $this->error('您还未满足条件~');
- }
- $data['match_typing_price'] = $charge_config['price'];
- }
- if ($voice_id) {
- $charge_config = Db::name('charge_config')->where(['id' => $voice_id, 'type' => 1])->find();
- if (!$charge_config) {
- $this->error('您的网络开小差啦~');
- }
- if ($level < $charge_config['level']) {
- $this->error('您还未满足条件~');
- }
- $data['match_audio_price'] = $charge_config['price'];
- }
- if ($video_id) {
- $charge_config = Db::name('charge_config')->where(['id' => $video_id, 'type' => 2])->find();
- if (!$charge_config) {
- $this->error('您的网络开小差啦~');
- }
- if ($level < $charge_config['level']) {
- $this->error('您还未满足条件~');
- }
- $data['match_video_price'] = $charge_config['price'];
- }
- if (in_array($open_match_audio, [1, 0])) {
- $data['open_match_audio'] = $open_match_audio;
- }
- if (in_array($open_match_video, [1, 0])) {
- $data['open_match_video'] = $open_match_video;
- }
- if (!$data) {
- $this->error('没有修改信息~');
- }
- $rs = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
- if ($rs === false) {
- $this->error('您的网络开小差啦~');
- }
- $this->success('设置成功');
- }
- //////////////////////////////////////////////////////////////////////////
- //微信登录,预先假注册
- public function wechatlogin_fake(){
- $code = $this->request->param('code','');
- if(!$code){
- $this->error(__('Invalid parameters'));
- }
- //微信
- $wechat = new Wechat();
- $wxuserinfo = $wechat->getAccessToken($code);
- if(!$wxuserinfo){
- $this->error('openid获取失败');
- }
- if(!is_array($wxuserinfo) || !isset($wxuserinfo['openid'])){
- $this->error('openid获取失败');
- }
- $openid = $wxuserinfo['openid'];
- //检查用户
- $user = Db::name('user')->where('wechat_openid',$openid)->find();
- if ($user) {
- if ($user['status'] == -1) {
- $this->error('账户已注销');
- }
- if ($user['status'] != 1) {
- $this->error(__('Account is locked'));
- }
- //如果已经有账号则直接登录
- $ret = $this->auth->direct($user['id']);
- if ($ret) {
- $userInfo = $this->auth->getUserinfo();
- $userInfo['is_register'] = 0;
- $userInfo['code'] = $code;
- $this->success(__('Logged in successful'), $userInfo);
- } else {
- $this->error($this->auth->getError());
- }
- } else {
- //记录code和openid,绑定手机号的时候更新openid
- $wechatCodeData = [
- 'code' => $code,
- 'openid' => $openid,
- 'createtime' => time(),
- ];
- $wechatCode = Db::name('wechat_code')->where(['openid'=>$openid])->find();
- if (empty($wechatCode)) {
- Db::name('wechat_code')->insertGetId($wechatCodeData);
- } else {
- Db::name('wechat_code')->where(['openid'=>$openid])->update($wechatCodeData);
- }
- //直接返回
- $userInfo = [];
- $userInfo['is_register'] = 1;
- $userInfo['code'] = $code;
- $this->success('获取信息成功', $userInfo);
- }
- }
- /**
- * 微信注册来的,绑定手机号
- *
- * @ApiMethod (POST)
- * @param string $mobile 手机号
- * @param string $captcha 验证码
- */
- public function bindmobile_fake()
- {
- $mobile = $this->request->param('mobile');
- $captcha = $this->request->param('captcha');
- $code = $this->request->param('code');
- if (!$mobile || !$captcha || !$code) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- $result = Sms::check($mobile, $captcha, 'changemobile');
- if (!$result) {
- $this->error(__('Captcha is incorrect'));
- }
- $wechatCodeWhere['code'] = $code;
- $wechatCode = Db::name('wechat_code')->where($wechatCodeWhere)->find();
- if (empty($wechatCode)) {
- $this->error('请先微信登录');
- }
- //检查appid绑定的用户
- $user = Db::name('user')->where('wechat_openid',$wechatCode['openid'])->find();
- if ($user) {
- if ($user['status'] == -1) {
- $this->error('账户已注销');
- }
- if ($user['status'] != 1) {
- $this->error(__('Account is locked'));
- }
- //如果已经有账号则直接登录
- $ret = $this->auth->direct($user['id']);
- $this->success('success',$this->auth->getUserinfo_simple());
- }
- //新的openid用户
- $where = [];
- $where['mobile'] = $mobile;
- $userData = Db::name('user')->where($where)->find();//老用户
- if (!empty($userData)) {
- if (empty($userData['wechat_openid'])) {
- Db::name('user')->where('id',$userData['id'])->update(['wechat_openid' => $wechatCode['openid']]);//老用户更新openid
- } else {
- if ($userData['wechat_openid'] != $wechatCode['openid']) {
- $this->error('该手机号已被其他用户绑定');
- }
- }
- $ret = $this->auth->direct($userData['id']);
- } else {
- $extend = [
- 'wechat_openid' => $wechatCode['openid'],
- 'plat_unique_id' => input('plat_unique_id',''),
- 'plat_from' => input('plat_from',''),
- ];
- $ret = $this->auth->register('', '','', $mobile, $extend);
- }
- if (!$ret) {
- $this->error($this->auth->getError());
- }
- $this->success('success',$this->auth->getUserinfo_simple());
- }
- /**
- * 运营商一键登录
- */
- public function onLogin()
- {
- $accessToken = input('accessToken');// 运营商预取号获取到的token
- $token = input('tokenT');// 易盾返回的token
- if (!$accessToken || !$token) {
- $this->error("参数获取失败!");
- }
- $params = array(
- // 运营商预取号获取到的token
- "accessToken" => $accessToken,
- // 易盾返回的token
- "token" => $token
- );
- // 获取密钥配置
- $configInfo = config("onLogin");
- $onlogin = new onlogin($configInfo["secretid"], $configInfo["secretkey"], $configInfo["businessid"]);
- $onret = $onlogin->check($params);
- // $ret = [];
- // $ret["code"] = 200;
- // $ret["msg"] = "ok";
- // $ret["data"] = [
- // "phone" => "17574504021",
- // "resultCode" => 0
- // ];
- if ($onret["code"] == 200) {
- $mobile = $onret["data"]["phone"];
- if (empty($mobile)) {
- // 取号失败,建议进行二次验证,例如短信验证码
- $this->error("取号登录失败,请用验证码方式登录!");
- } else {
- // 取号成功, 执行登录等流程
- // 用户登录逻辑 === 开始
- $user = \app\common\model\User::getByMobile($mobile);
- if ($user) {
- if ($user->status == -1) {
- $this->error('账户已注销');
- }
- if ($user->status != 1) {
- $this->error(__('Account is locked'));
- }
- //如果已经有账号则直接登录
- $ret = $this->auth->direct($user->id);
- $is_register = 0;
- } else {
- $extend = [
- ];
- $ret = $this->auth->register('', '', '', $mobile, $extend);
- $is_register = 1;
- }
- if ($ret) {
- $this->success(__('Logged in successful'), $this->auth->getUserinfo_simple());
- } else {
- $this->error($this->auth->getError());
- }
- // 用户登录逻辑 === 结束
- }
- } else {
- $this->error("登录失败,请用验证码方式登录!");
- }
- }
- //苹果登录+预注册
- public function applelogin(){
- $iosUserId = $this->request->param('ios_user_id','');
- if(!$iosUserId){
- $this->error(__('Invalid parameters'));
- }
- //检查用户
- $user = Db::name('user')->where('ios_user_id',$iosUserId)->find();
- if ($user) {
- if ($user['status'] == -1) {
- $this->error('账户已经注销');
- }
- if ($user['status'] != 1) {
- $this->error(__('Account is locked'));
- }
- //如果已经有账号则直接登录
- $ret = $this->auth->direct($user['id']);
- if ($ret) {
- $userInfo = $this->auth->getUserinfo_simple();
- $userInfo['is_register'] = 0;
- $userInfo['ios_user_id'] = $iosUserId;
- $this->success(__('Logged in successful'), $userInfo);
- } else {
- $this->error($this->auth->getError());
- }
- } else {
- //直接返回
- $userInfo = [];
- $userInfo['is_register'] = 1;
- $userInfo['ios_user_id'] = $iosUserId;
- $this->success('获取信息成功', $userInfo);
- }
- }
- /**
- * 苹果注册来的,绑定手机号
- *
- * @ApiMethod (POST)
- * @param string $mobile 手机号
- * @param string $captcha 验证码
- */
- public function applebindmobile()
- {
- $mobile = $this->request->param('mobile');
- $captcha = $this->request->param('captcha');
- $iosUserId = $this->request->param('ios_user_id','');
- if (!$mobile || !$captcha || !$iosUserId) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- $result = Sms::check($mobile, $captcha, 'changemobile');
- if (!$result) {
- $this->error(__('Captcha is incorrect'));
- }
- //检查ios_user_id绑定的用户
- $user = Db::name('user')->where('ios_user_id',$iosUserId)->find();
- if ($user) {
- if ($user['status'] == -1) {
- $this->error('账户已经注销');
- }
- if ($user['status'] != 1) {
- $this->error(__('Account is locked'));
- }
- //如果已经有账号则直接登录
- $ret = $this->auth->direct($user['id']);
- $this->success('success',$this->auth->getUserinfo_simple());
- }
- //新的ios用户
- $where = [];
- $where['mobile'] = $mobile;
- $userData = Db::name('user')->where($where)->find();//老用户
- if (!empty($userData)) {
- if (empty($userData['ios_user_id'])) {
- Db::name('user')->where('id',$userData['id'])->update(['ios_user_id' => $iosUserId]);//老用户更新ios_user_id
- } else {
- if ($userData['ios_user_id'] != $iosUserId) {
- $this->error('该手机号已被其他用户绑定');
- }
- }
- $ret = $this->auth->direct($userData['id']);
- } else {
- $extend = [
- 'ios_user_id' => $iosUserId,
- ];
- $ret = $this->auth->register('', '','', $mobile, $extend);
- }
- if (!$ret) {
- $this->error($this->auth->getError());
- }
- $this->success('success',$this->auth->getUserinfo_simple());
- }
- /**
- * 重置密码
- *
- * @ApiMethod (POST)
- * @param string $mobile 手机号
- * @param string $newpassword 新密码
- * @param string $captcha 验证码
- */
- public function resetpwd()
- {
- //$type = input("type");
- $type = 'mobile';
- $mobile = input("mobile");
- // $email = input("email");
- $newpassword = input("newpassword");
- $captcha = input("captcha");
- if (!$mobile || !$newpassword || !$captcha) {
- $this->error(__('Invalid parameters'));
- }
- if ($type == 'mobile') {
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- $user = \app\common\model\User::getByMobile($mobile);
- if (!$user) {
- $this->error(__('User not found'));
- }
- $ret = Sms::check($mobile, $captcha, 'resetpwd');
- if (!$ret) {
- $this->error(__('Captcha is incorrect'));
- }
- Sms::flush($mobile, 'resetpwd');
- }
- //模拟一次登录
- $this->auth->direct($user->id);
- $ret = $this->auth->changepwd($newpassword, '', true);
- if ($ret) {
- $this->success(__('Reset password successful'));
- } else {
- $this->error($this->auth->getError());
- }
- }
- /**
- * 修改密码
- *
- * @ApiMethod (POST)
- * @param string $newpassword 新密码
- * @param string $oldpassword 旧密码
- */
- public function changepwd(){
- $newpassword = input('newpassword');
- $oldpassword = input('oldpassword','');
- if (!$newpassword) {
- $this->error(__('Invalid parameters'));
- }
- if($this->auth->password && empty($oldpassword)){
- $this->error('原密码必填');
- }
- if(empty($this->auth->password)){
- $ret = $this->auth->changepwd($newpassword, '', true);
- }else{
- $ret = $this->auth->changepwd($newpassword,$oldpassword,false);
- }
- if ($ret) {
- $this->success('设置密码成功');
- } else {
- $this->error($this->auth->getError());
- }
- }
- }
|