Browse Source

签到调整

zhangxiaobin 1 year ago
parent
commit
0aa611ccfb

+ 57 - 0
application/api/controller/User.php

@@ -706,4 +706,61 @@ class User extends Api
 
         $this->success('获取成功',$result);
     }
+
+    //微信登录
+    public function wechatlogin(){
+//        $nickname = input('nickname','');
+//        $avatar = input('avatar','');
+//        $gender = input('gender',1);
+        $wechat_openid = input('wechat_openid','');
+
+        if (!$wechat_openid) {
+            $this->error(__('Invalid parameters'));
+        }
+//        if($gender != 1){
+//            $gender = 0;
+//        }
+
+        $user = \app\common\model\User::getByOpenid($wechat_openid);
+        if ($user) {
+            if ($user->status != 1) {
+                $this->error(__('Account is locked'));
+            }
+            if ($user->frozentime > time()) {
+                $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
+            }
+            //如果已经有账号则直接登录
+            $ret = $this->auth->direct($user->id);
+
+            //非首次注册男性用户每次打开app,系统自动推送女性(公会)打招呼消息3人次
+            /*if($user->gender == 1 && $user->gh_id == 0){
+                $this->firstopen_send($user->id);
+            }*/
+        } else {
+//            $this->success('选择性别', ['code' => 5]);
+
+//            if (!$nickname || !$avatar) {
+//                $this->error(__('Invalid parameters'));
+//            }
+
+            $reg_data = [
+//                'nickname'=>$nickname,
+//                'avatar'=>$avatar,
+//                'gender'=>$gender,
+                'register_from' => input('register_from',''),
+                'gender' => -1
+            ];
+            $ret = $this->auth->openid_register($wechat_openid,$reg_data);
+            //亿米
+            /*if(input('register_from','') == 'xiaomi'){
+                $this->yimi_advert();
+            }*/
+        }
+        if ($ret) {
+            $data = $this->userInfo('return');
+            $this->success(__('Logged in successful'), $data);
+        } else {
+            $this->error($this->auth->getError());
+        }
+    }
 }

+ 2 - 2
application/api/controller/Usersign.php

@@ -98,13 +98,13 @@ class Usersign extends Api
         $userconfigModel = new \app\common\model\UserLevelConfig();
         $where = [];
         $where["empirical"] = ["elt",$userNewEmpirical];
-        $userexplainstart = $userconfigModel->where($where)->order("empirical","desc")->limit(1)->select();
+        $userexplainstart = $userconfigModel->where($where)->order("empirical","desc")->find();
         if (!empty($userexplainstart)) {
             if ($userexplainstart['level'] != $user['level']) {
                 $userUpdate['level'] = $userexplainstart['level'];
             }
         }
-        $res = model('User')->where($userWhere)->lock(true)->update();
+        $res = $user->update($userUpdate,$userWhere);
         if($res === false){
             Db::rollback();
             $this->error('经验更新失败');

File diff suppressed because it is too large
+ 4 - 0
application/common.php


+ 60 - 1
application/common/library/Auth.php

@@ -172,7 +172,7 @@ class Auth
         ];
         //https://bansheng-1304213176.cos.ap-guangzhou.myqcloud.com/
         $params = array_merge($data, [
-            'nickname' => "bans_" . $data["u_id"],
+            'nickname' => "gg_" . $data["u_id"],
             'salt'     => Random::alnum(),
             'joinip'    => $ip,
             'logintime' => $time,
@@ -666,4 +666,63 @@ class Auth
     {
         return $this->_error ? __($this->_error) : '';
     }
+
+    public function openid_register($wechat_openid = '', $extend = [])
+    {
+        /*if ($wechat_openid && User::getByOpenid($wechat_openid)) {
+            $this->setError('openid已存在');
+            return false;
+        }
+
+        $ip = request()->ip();
+        $time = time();
+
+        $introcode = User::column("introcode");
+
+        $data = [
+            'wechat_openid'   => $wechat_openid,
+            //'avatar'   => 'https://meet-1251365327.cos.ap-beijing.myqcloud.com/uploads/20220314/f57ebce8a72b823912904fe76eda0909.png',
+            'avatar' => $extend['gender'] == 1 ? config('avatar_boy') : config('avatar_girl'),//config('site.domain_cdnurl').'/avatar.png',
+            'introcode' => $this->getUinqueNo(6, $introcode),
+            'nickname'  => get_rand_nick_name(),
+        ];
+        $params = array_merge($data, [
+            'salt'      => Random::alnum(),
+            'jointime'  => $time,
+            'joinip'    => $ip,
+            'logintime' => $time,
+            'loginip'   => $ip,
+            'prevtime'  => $time,
+            'status'    => 'normal'
+        ]);
+        $params = array_merge($params, $extend);
+
+        //账号注册时需要开启事务,避免出现垃圾数据
+        Db::startTrans();
+        try {
+            $user = User::create($params, true);
+
+            $this->_user = User::get($user->id);
+            $this->_user->u_id = $this->getUinqueId(8, $user->id);
+            $this->_user->save();
+
+            //设置Token
+            $this->_token = Random::uuid();
+            Token::set($this->_token, $user->id, $this->keeptime);
+
+            //设置登录状态
+            $this->_logined = true;
+
+            
+
+            //注册成功的事件
+            Hook::listen("user_register_successed", $this->_user, $data);
+            Db::commit();
+        } catch (Exception $e) {
+            $this->setError($e->getMessage());
+            Db::rollback();
+            return false;
+        }*/
+        return true;
+    }
 }

Some files were not shown because too many files changed in this diff