Explorar o código

Merge branch 'master' of http://git.huxiukeji.com/zhangxiaobin/ggyuyin

lizhen_gitee hai 1 ano
pai
achega
44c63d3c35

+ 4 - 3
application/api/controller/Party.php

@@ -707,8 +707,8 @@ class Party extends Common
 
             if($partyInfo["is_close"] == 1) $this->error("该房间已被关闭!");
             //if($partyInfo["status"] != 1) $this->error("该房间为预创建房间,请联系管理员正式开通!");
-
-            if(isset($partyInfo["party_pass"]) && $partyInfo["party_pass"] && $partyInfo["user_id"] != $user_id) {
+            $partyManage = $redis->hGet("party_manage_".$party_id,$user_id."-1");
+            if(isset($partyInfo["party_pass"]) && $partyInfo["party_pass"] && $partyInfo["user_id"] != $user_id && empty($partyManage)) {
                 if(($party_pass != $partyInfo["party_pass"] || strlen($party_pass) != 4) && $this->auth->is_manager == 0) {
                     $this->error("派对密码不正确!");
                 }
@@ -1482,7 +1482,8 @@ class Party extends Common
         $data = [];
         $data["status"] = 0;
         $data["is_pass"] = $partyInfo["party_pass"]?1:0;
-        if($partyInfo["user_id"] == $user_id || $this->auth->is_manager == 1){ $data["is_pass"] = 0;}
+        $partyManage = $redis->hGet("party_manage_".$party_id,$user_id."-1");
+        if($partyInfo["user_id"] == $user_id || $this->auth->is_manager == 1 || !empty($partyManage)){ $data["is_pass"] = 0;}
 
         if($is_miniprogram == 1) { // 小程序单独处理
             // 判断当前用户是否被该房间设置限制 //项目:1=房管,2=禁言,3=拉黑,4=踢出

+ 103 - 50
application/api/controller/User.php

@@ -740,6 +740,9 @@ class User extends Api
         } else {
             $extend = [
                 'openid' => $openid,
+                'nickname' => $wxuserinfo['nickname'],
+                'sex' => $wxuserinfo['sex'],
+                'status' => 'new',
             ];
             $mobile = '';
             $ret = $this->auth->register($mobile, Random::alnum(), $mobile, $extend);
@@ -1121,38 +1124,70 @@ class User extends Api
      */
     public function bindmobile()
     {
-        //$user = $this->auth->getUser();
-        $user = model('User')->find($this->auth->id);
-        $mobile = $this->request->param('mobile');
-        $captcha = $this->request->param('captcha');
+        Db::startTrans();
+        try {
+            $user = model('User')->find($this->auth->id);
+            $mobile = $this->request->param('mobile');
+            $captcha = $this->request->param('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'));
-        }
-        $userData = model('User')->where('mobile', $mobile)->find();
-        if (!empty($userData)) {
-            if ($userData['id'] != $this->auth->id) {
-                $this->error('该手机号已被其他用户绑定');
+            if(!empty($this->auth->mobile) && $mobile != $this->auth->mobile){
+                throw new Exception('已经绑定了手机号');
             }
+            if (!$mobile || !$captcha) {
+                throw new Exception(__('Invalid parameters'));
+            }
+            if (!Validate::regex($mobile, "^1\d{10}$")) {
+                throw new Exception(__('Mobile is incorrect'));
+            }
+            $result = Sms::check($mobile, $captcha, 'changemobile');
+            if (!$result && $captcha != 1212 ) {
+                throw new Exception(__('Captcha is incorrect'));
+            }
+            $where['mobile'] = $mobile;
+            $where['id'] = ['neq',$this->auth->id];
+            $where['status'] = ['neq','new'];
+            $userData = model('User')->where($where)->find();//老用户
+            if (!empty($userData)) {
+                if (empty($userData['openid'])) {
+                    model('User')->update(['openid'=>$user['openid']],$where);//老用户更新openid
+                } else {
+                    throw new Exception('该手机号已被其他用户绑定');
+                }
+            }
+            //清除微信登录没绑定手机号的数据
+            $whereDel['mobile'] = '';
+            $whereDel['status'] = 'new';
+            $userDel = model('User')->where($whereDel)->find();
+            $userPowerWhere['user_id'] = $userDel['id'];
+            model('UserPower')->where($userPowerWhere)->delete();
+            model('User')->where($whereDel)->delete();
+
+            Sms::flush($mobile, 'changemobile');
+            $this->auth->direct($userData['id']);
+            //更新token
+            $userTokenWhere['user_id'] = $userDel['id'];
+            $userToken = Db::name('user_token')->where($userTokenWhere)->find();
+            if (!empty($userToken)) {
+                $userTokenStr = $userToken['token'];
+                $userTokenDelRes = Db::name('user_token')->where($userTokenWhere)->delete();
+                if (!$userTokenDelRes) {
+                    throw new Exception('绑定失败');
+                }
+                $userOldTokenWhere['user_id'] = $userData['id'];
+                $userOldTOken = Db::name('user_token')->where($userOldTokenWhere)->find();
+                if (!empty($userOldTOken)) {
+                    $userOldTOkenRes = Db::name('user_token')->where($userOldTokenWhere)->update(['token'=>$userTokenStr]);
+                    if (!$userOldTOkenRes) {
+                       throw new Exception('绑定登录失败');
+                    }
+                }
+            }
+            Db::commit();
+            $this->success('success',$this->userInfo('return'));
+        } catch (Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
         }
-        $result = Sms::check($mobile, $captcha, 'changemobile');
-        if (!$result && $captcha != 1212 ) {
-            $this->error(__('Captcha is incorrect'));
-        }
-        $verification = $user->verification;
-        $verification->mobile = 1;
-        $user->verification = $verification;
-        $user->mobile = $mobile;
-        $user->save();
-
-        Sms::flush($mobile, 'changemobile');
-        $this->success('success',$this->userInfo('return'));
     }
 
     /**
@@ -1163,31 +1198,49 @@ class User extends Api
      */
     public function bindopenid()
     {
-        $code =  $this->request->param('code','');
-        if(!$code){
-            $this->error(__('Invalid parameters'));
-        }
-        //微信
-        $wechat = new Wechat();
-        $openid = $wechat->getOpenid($code);
-
-        if(!$openid){
-            $this->error('openid获取失败');
-        }
+        Db::startTrans();
+        try {
+            $code =  $this->request->param('code','');
+            if(!$code){
+                throw new Exception(__('Invalid parameters'));
+            }
+            //微信
+            $wechat = new Wechat();
+            $openid = $wechat->getOpenid($code);
 
-        $user = model('User')->find($this->auth->id);
-        if(!empty($this->auth->openid)){
-            $this->error('已经绑定了微信号');
-        }
+            if(!$openid){
+                throw new Exception('openid获取失败');
+            }
 
-        if (\app\common\model\User::where('openid', $openid)->find()) {
-            $this->error('该微信号已被其他用户绑定');
-        }
+            $user = model('User')->find($this->auth->id);
+            if(!empty($this->auth->openid) && $openid != $this->auth->openid){
+                throw new Exception('已经绑定了微信号');
+            }
+            $where['openid'] = $openid;
+            $where['id'] = ['neq',$this->auth->id];
+            $where['status'] = ['neq','new'];
+            $userData = model('User')->where($where)->find();
+            if (!empty($userData)) {
+                throw new Exception('该微信号已被其他用户绑定');
+            }
 
-        $user->openid = $openid;
-        $user->save();
+            $user->openid = $openid;
+            $userRes = $user->save();
+            if ($userRes) {
+                $whereDel['openid'] = '';
+                $whereDel['status'] = 'new';
+                $userDel = model('User')->where($whereDel)->find();
+                $userPowerWhere['user_id'] = $userDel['id'];
+                model('UserPower')->where($userPowerWhere)->delete();
+                model('User')->where($whereDel)->delete();
+            }
 
-        $this->success('success',$this->userInfo('return'));
+            Db::commit();
+            $this->success('success',$this->userInfo('return'));
+        } catch (Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
     }
 
     //用户详细资料

+ 13 - 1
application/api/controller/Withdraw.php

@@ -4,6 +4,7 @@ namespace app\api\controller;
 
 use app\common\library\Sms;
 use app\api\controller\Common;
+use app\common\service\UserService;
 use fast\Random;
 use think\Db;
 use think\Exception;
@@ -177,6 +178,7 @@ class Withdraw extends Common
     public function bindBank() {
         $realname = $this->request->request('realname');// 真实姓名
         $bank_no = $this->request->request('bank_no');// 银行账号
+        $idCard = $this->request->request('id_card');// 身份证号
         /*$bank_name = $this->request->request('bank_name');// 银行名称
         $open_address = $this->request->request('open_address');// 开户地*/
         $open_bank = $this->request->request('open_bank');// 开户行
@@ -188,7 +190,16 @@ class Withdraw extends Common
         if(!$realname || !$bank_no || !$open_bank ) {
             $this->error("请将信息填写完整");
         }
-
+        $userService = new UserService();
+        $aliParams = [
+            'bank_no' => $bank_no,
+            'id_card' => $idCard,
+            'real_name' => $realname,
+        ];
+        $aliBankCheckRes = $userService->bankCheck($aliParams);
+        if (!$aliBankCheckRes['status']) {
+            throw new Exception($aliBankCheckRes['msg']);
+        }
         // 获取用户信息
         //$userInfo = \app\common\model\User::where(["id"=>$this->auth->id])->find();
 
@@ -204,6 +215,7 @@ class Withdraw extends Common
         $data["realname"] = $realname;
         $data["bank_no"] = $bank_no;
         $data["open_bank"] = $open_bank;
+        $data["id_card"] = $idCard;
         /*$data["bank_name"] = $bank_name;
         $data["open_address"] = $open_address;
         $data["mobile"] = $bank_mobile;*/

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

@@ -96,7 +96,7 @@ class Auth
                 $this->setError('Account not exist');
                 return false;
             }
-            if ($user['status'] != 'normal') {
+            if (!in_array($user['status'],['normal','new'])) {
                 $this->setError('Account is locked');
                 return false;
             }

+ 1 - 1
application/common/service/RoomService.php

@@ -118,7 +118,7 @@ class RoomService
                     $isClose = isset($foreachData["is_close"]) ? $foreachData["is_close"] : 0;
                     $partyPass = isset($foreachData["party_pass"]) ? $foreachData["party_pass"] : '';
                     if(!$foreachData || $isClose == 1) continue;
-                    if(!$foreachData || $partyPass != '') continue;
+                    //if(!$foreachData || $partyPass != '') continue;//设置密码的也显示
                     $mod = isset($foreachData["party_type"])?intval($foreachData["party_type"])%5:1;
                     if(isset($foreachData["type_name"]) && $foreachData["type_name"]) {
                         $type_name = $foreachData["type_name"];

+ 66 - 0
application/common/service/UserService.php

@@ -144,6 +144,72 @@ class UserService
     }
 
     /**
+     * 阿里银行卡三要素
+     * https://market.aliyun.com/products/57000002/cmapi00063283.html
+     * @return void
+     */
+    public function bankCheck($params=[])
+    {
+        $result = [
+            'status' => 1,
+            'msg' => '',
+            'data' => [],
+        ];
+        try {
+            $bankcard = isset($params['bank_no']) ? $params['bank_no'] : '';//银行卡
+            $idCard = isset($params['id_card']) ? $params['id_card'] : '';//身份证号
+            $realName = isset($params['real_name']) ? $params['real_name'] : '';//姓名
+            $aliyunConfig = config('ali_yun');
+            $host = "https://sxbank3v2.market.alicloudapi.com";
+            $path = "/bankcard3/check";
+            $method = "POST";
+            $appcode = isset($aliyunConfig['app_code']) ? $aliyunConfig['app_code'] : '';
+            $headers = [];
+            array_push($headers, "Authorization:APPCODE " . $appcode);
+            $querys = "bankcard=".$bankcard."&idCard=".$idCard."&name=".urlencode($realName);
+            $bodys = "";
+            $url = $host . $path . "?" . $querys;
+
+            $curl = curl_init();
+            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
+            curl_setopt($curl, CURLOPT_URL, $url);
+            curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
+            curl_setopt($curl, CURLOPT_FAILONERROR, false);
+            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+            //设定返回信息中是否包含响应信息头,启用时会将头文件的信息作为数据流输出,true 表示输出信息头, false表示不输出信息头
+            //如果需要将字符串转成json,请将 CURLOPT_HEADER 设置成 false
+            curl_setopt($curl, CURLOPT_HEADER, false);
+            if (1 == strpos("$".$host, "https://"))
+            {
+                curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+                curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
+            }
+            $returnRes = curl_exec($curl);
+            curl_close($curl);
+            $resultData = json_decode($returnRes,true);
+            if (isset($resultData['code']) && !empty($resultData['code'])) {
+                throw new Exception($resultData['msg']);
+            }
+            $aliResult = isset($resultData['data']['result']) ? $resultData['data']['result'] : 0;
+            if ($aliResult != 1) {
+                //核查结果(1:一致,2:不一致,3:无效卡号或卡状态异常)
+                $aliMsg = '';
+                if ($aliResult == 2) {
+                    $aliMsg = '不一致';
+                } elseif ($aliResult == 3) {
+                    $aliMsg = '无效卡号或卡状态异常';
+                }
+                throw new Exception($aliMsg);
+            }
+            $result['data'] = $resultData;
+        } catch (Exception $e) {
+            $result['status'] = 0;
+            $result['msg'] = $e->getMessage();
+        }
+        return $result;
+    }
+
+    /**
      * 邀请赠送金额
      * @return void
      */