123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293 |
- <?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 app\common\model\UserDeviceInfo;
- use onlogin\onlogin;
- use addons\epay\library\Service;
- use app\common\library\Wechat;
- class User extends Api
- {
- protected $noNeedLogin = ['emaillogin','emailregister','mobilelogin','resetpwd'];
- protected $noNeedRight = '*';
- public function _initialize()
- {
- parent::_initialize();
- }
-
- public function emaillogin()
- {
- $account = input('account');
- $password = input('password');
- if (!$account || !$password) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::is($account, 'email')) {
- $this->error(__('Email is incorrect'));
- }
- $ret = $this->auth->login($account, $password);
- if ($ret) {
- $this->success(__('Logged in successful'), $this->auth->getUserinfo_simple());
- } else {
- $this->error($this->auth->getError());
- }
- }
-
- public function emailregister()
- {
- $account = input('account');
- $captcha = input('captcha');
- $password = input('password');
- if (!$account || !$captcha || !$password) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::is($account, 'email')) {
- $this->error(__('Email is incorrect'));
- }
- $ret = Ems::check($account, $captcha, 'register');
- if (!$ret) {
- $this->error(__('Captcha is incorrect'));
- }
- $extend = [
- 'register_from' => input('register_from',''),
- 'gender' => -1
- ];
- $ret = $this->auth->register('',$password,$account,'', $extend);
- if ($ret) {
- Ems::flush($account);
- $this->success('注册成功', $this->auth->getUserinfo_simple());
- } else {
- $this->error($this->auth->getError());
- }
- }
-
- 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 (!in_array($user->status,[1,2])) {
- $this->error(__('Account is locked'));
- }
- if ($user->frozentime > time()) {
- $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
- }
-
- $ret = $this->auth->direct($user->id);
- } else {
- $extend = [
- 'register_from' => input('register_from',''),
- 'gender' => -1
- ];
- $ret = $this->auth->register('', '', '', $mobile, $extend);
- }
- if ($ret) {
- Sms::flush($mobile, 'mobilelogin');
- $this->success(__('Logged in successful'), $this->auth->getUserinfo_simple());
- } else {
- $this->error($this->auth->getError());
- }
- }
-
- public function setgender() {
- $user_id = $this->auth->id;
- $gender = input('gender', -1, 'intval');
- if (!in_array($gender, [1, 0])) {
- $this->error('性别错误');
- }
- $edit_data['gender'] = $gender;
- $edit_data['avatar'] = $gender == 1 ? config('avatar_boy') : config('avatar_girl');
- $rs = Db::name('user')->where(['id' => $user_id])->update($edit_data);
- if ($rs === false) {
- $this->error('您的网络开小差啦~');
- }
-
- $data['gender'] = $edit_data['gender'];
- $data['avatar'] = $edit_data['avatar'];
- $this->success('success', $data);
- }
-
- public function get_rand_nick_name(){
- $nickname = $this->auth->get_rand_nick_name();
- $this->success('success', $nickname);
- }
-
- public function perfect_info() {
- $avatar = input('avatar', '', 'trim');
- $nickname = input('nickname', '', 'trim');
- $birthday = input('birthday', '', 'strtotime');
- $hometown_cityid = input('hometown_cityid', '', 'trim');
- $bio = input('bio', '', 'trim');
- $hobby = input('hobby', '', 'trim');
- $marital = input('marital', '', 'trim');
- $introcode = input('introcode', '', 'trim');
- $data = [];
- if ($avatar) {
- $data['avatar'] = $avatar;
- }
- if ($nickname !== '') {
- if (iconv_strlen($nickname, 'utf-8') > 10) {
- $this->error('昵称最多10个字~');
- }
- $data['nickname'] = $nickname;
- }
- if ($birthday) {
- $data['birthday'] = $birthday;
- }
- if ($hometown_cityid) {
- $count = Db::name('area')->where('id', $hometown_cityid)->count('id');
- if (!$count) {
- $this->error('城市不存在');
- }
- $data['hometown_cityid'] = $hometown_cityid;
- }
- if ($bio) {
- $data['bio'] = $bio;
- }
- if ($hobby) {
- $data['hobby'] = $hobby;
- }
- if ($marital) {
- $data['marital'] = $marital;
- }
- if ($introcode && !$this->auth->intro_uid) {
- $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $introcode)->find();
- if ($intro_user && $intro_user['id'] != $this->auth->id && $intro_user['intro_uid'] != $this->auth->id) {
- $data['intro_uid'] = $intro_user['id'];
- $data['invite_time'] = time();
- }
- }
-
- Db::startTrans();
- $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
- if($update_rs === false){
- Db::rollback();
- $this->error('修改失败');
- }
-
- if(isset($data['intro_uid'])){
- $intro_gold = config('site.new_user_intro_gold');
- if($intro_gold > 0){
- $rs_wallet = model('wallet')->lockChangeAccountRemain($data['intro_uid'], 0,'gold',$intro_gold,34,'邀请'.$this->auth->username.'注册奖励');
- if($rs_wallet['status'] === false){
- Db::rollback();
- $this->error('邀请新人奖励赠送失败');
- }
- }
- }
-
- if(isset($data['avatar'])){
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,19);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- }
- if (isset($data['birthday'])) {
-
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- }
- Db::commit();
- $this->success('修改成功');
- }
-
- public function userInfo($type = 1){
- $info = $this->auth->getUserinfo();
- if($type == 'return'){
- return $info;
- }
- $this->success(__('success'),$info);
- }
-
- public function profile()
- {
- $field_array = ['nickname','introcode','birthday','height','weight','bio','audio_bio','avatar','photo_images','education','hobby','job','marital','tag','wages','hometown_cityid','hide_is_finishinfo','character','constellation','stature','is_appointment', 'greet_voice', 'greet_chat', 'is_cohabit', 'live', 'is_house', 'car', 'chest', 'waist'];
- $data = [];
- foreach($field_array as $key => $field){
- 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');
- }
- $data[$field] = $newone;
- }
- if(isset($data['birthday'])){
- $data['birthday'] = strtotime($data['birthday']);
- }
- if(isset($data['avatar'])){
-
- }
- if(isset($data['introcode'])){
- if ($this->auth->intro_uid != 0) {
- $this->error('邀请人不可修改~');
- }
- $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $data['introcode'])->find();
- if(!$intro_user){
- $this->error('不存在的邀请人');
- }
- if ($intro_user['id'] == $this->auth->id) {
- $this->error('不能填写自己邀请码');
- }
- if ($intro_user['intro_uid'] == $this->auth->id) {
- $this->error('不能填写下级邀请码');
- }
- unset($data['introcode']);
- $data['intro_uid'] = $intro_user['id'];
- $data['invite_time'] = time();
- }
-
- if(empty($data)){
- $this->error('没有任何改变');
- }
- Db::startTrans();
- $userData = Db::name('user')->field('avatar,gender,status')->where('id',$this->auth->id)->find();
- if (isset($data['avatar']) && !empty($data['avatar']) && $userData['status'] == 2) {
- $boyAvatar = config('avatar_boy');
- $girlAvatar = config('avatar_girl');
- if ($userData['gender'] == 1 && $data['avatar'] != $boyAvatar) {
- $data['status'] = 1;
- } elseif ($userData['gender'] == 0 && $data['avatar'] != $girlAvatar) {
- $data['status'] = 1;
- }
- }
- $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
- if($update_rs === false){
- Db::rollback();
- $this->error('修改资料失败');
- }
-
- if(isset($data['intro_uid'])){
- $intro_gold = config('site.new_user_intro_gold');
- if($intro_gold > 0){
- $rs_wallet = model('wallet')->lockChangeAccountRemain($data['intro_uid'], 0,'gold',$intro_gold,34,'邀请'.$this->auth->username.'注册奖励');
- if($rs_wallet['status'] === false){
- Db::rollback();
- $this->error('邀请新人奖励赠送失败');
- }
- }
- }
-
-
- if(isset($data['avatar'])){
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,19);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- }
-
- if (isset($data['birthday'])) {
-
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- }
-
- if(isset($data['bio'])){
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,2);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- }
-
- if(isset($data['audio_bio'])){
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,21);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- }
-
- if(isset($data['photo_images'])){
- $photo_images_num = count(explode(',',$data['photo_images'])) + count(explode(',',$this->auth->photo_images));
- if ($photo_images_num >= 5) {
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id, 5);
- if ($task_rs === false) {
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- }
- }
- Db::commit();
- $this->success();
- }
-
- public function logout()
- {
- if (!$this->request->isPost()) {
- $this->error(__('Invalid parameters'));
- }
-
- $tenIm = new Tenim();
- $tenIm->loginoutim($this->auth->id);
-
- Db::name('user')->where('id',$this->auth->id)->update(['is_active' => 0]);
- $this->auth->logout();
- $this->success(__('Logout successful'));
- }
-
- public function resetpwd()
- {
-
- $type = 'email';
- $mobile = input("mobile");
- $email = input("email");
- $newpassword = input("newpassword");
- $captcha = input("captcha");
- if (!$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');
- } else {
- if (!Validate::is($email, "email")) {
- $this->error(__('Email is incorrect'));
- }
- $user = \app\common\model\User::getByEmail($email);
- if (!$user) {
- $this->error(__('User not found'));
- }
- $ret = Ems::check($email, $captcha, 'resetpwd');
- if (!$ret) {
- $this->error(__('Captcha is incorrect'));
- }
- Ems::flush($email, '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());
- }
- }
-
- public function bindmobile()
- {
- $user = $this->auth->getUser();
- $mobile = $this->request->request('mobile');
- $captcha = $this->request->request('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->mobile = $mobile;
- $user->save();
- Sms::flush($mobile, 'changemobile');
-
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,18);
- if($task_rs === false){
- Db::rollback();
- return false;
- }
- $this->success('success',$this->userInfo('return'));
- }
-
- public function cancleconfig(){
- $rs = [
- 'rule' => config('site.user_cancle_rules'),
- 'reason' => [
- '想换个新账号',
- '没有聊得来的',
- '不想玩了',
- '其他原因',
- ],
- ];
- $this->success(1,$rs);
- }
-
- public function cancleUser(){
- if (!$this->request->isPost()) {
- $this->error(__('Invalid parameters'));
- }
-
- $tenIm = new Tenim();
- $tenIm->loginoutim($this->auth->id);
- $data = [
- 'status' => -1,
- 'mobile' => 'close_'.$this->auth->mobile,
- 'wechat_openid' => 'close_'.$this->auth->wechat_openid,
- ];
- Db::name('user')->where('id',$this->auth->id)->update($data);
- $this->auth->logout();
- $this->success('注销成功');
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public function change_longlat(){
- $longitude = input_post('longitude');
- $latitude = input_post('latitude');
- $cityname = input_post('cityname');
- if(empty($longitude) || empty($latitude) || empty($cityname)){
- $this->error();
- }
- $data = [
- 'longitude' => $longitude,
- 'latitude' => $latitude,
- 'cityname' => $cityname,
- ];
- Db::name('user')->where('id',$this->auth->id)->update($data);
- $this->success();
- }
-
- 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'));
- }
-
- $user->mobile = $mobile;
- $user->save();
- Sms::flush($user->mobile, 'changemobile');
- Sms::flush($mobile, 'changemobile');
- $this->success();
- }
-
-
-
- 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(__('Reset password successful'));
- } else {
- $this->error($this->auth->getError());
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public function kefu() {
- $type = input('type', 0, 'intval');
- if (!in_array($type, [0, 1])) {
- $this->error('您的网络开小差啦~');
- }
- if ($type == 0) {
- $user_id = config('site.customer_service_id') ? : 0;
- } else {
- $user_id = config('site.pay_customer_service_id') ? : 0;
- }
- $list = Db::name('user')->field('id')->where(['status' => 1, 'is_kefu' => 1, 'id' => $user_id])->select();
- if (!$list) {
- $this->success('success', $list);
- }
- foreach ($list as $k => &$v) {
- $v['nickname'] = '客服' . ($k + 1);
- $v['avatar'] = config('avatar_girl');
- }
- $this->success('success', $list);
- }
-
- public function editcity() {
- $name = input('name', '', 'trim');
- if ($name === '') {
- $this->error('参数缺失');
- }
- $hometown_cityid = Db::name('area')->where(['name' => $name])->value('id');
- if (!$hometown_cityid) {
- $this->success('修改成功');
- }
- Db::name('user')->where(['id' => $this->auth->id])->setField('hometown_cityid', $hometown_cityid);
- $this->success('修改成功');
- }
-
- public function searchuser() {
- $keyword = input('keyword', '', 'trim');
- if ($keyword === '') {
- $this->error('请输入关键字');
- }
- $id = Db::name('user')->where(['nickname|username' => $keyword])->value('id');
- $id = $id ? : 0;
- $this->success('用户', $id);
- }
-
- }
|