Explorar el Código

fix wxauthor login

stanley-king hace 7 años
padre
commit
999a531b7b

+ 2 - 1
data/model/member.model.php

@@ -94,8 +94,10 @@ class memberModel extends Model
         $_SESSION['is_login'] = '1';
         $_SESSION['member_id'] = $member_info['member_id'];
         $_SESSION['member_mobile'] = $member_info['member_mobile'];
+        $_SESSION['member_mobile_bind'] = $member_info['member_mobile_bind'];
         $_SESSION['member_wxunionid'] = $member_info['member_wxunionid'];
         $_SESSION['member_wxopenid'] = $member_info['member_wxopenid'];
+        $_SESSION['member_wechat_bind'] = $member_info['member_wechat_bind'];
         $_SESSION['member_name'] = $member_info['member_name'];
         $_SESSION['member_email'] = $member_info['member_email'];
         $_SESSION['is_buy'] = isset($member_info['is_buy']) ? $member_info['is_buy'] : 1;
@@ -106,7 +108,6 @@ class memberModel extends Model
         $_SESSION['member_signname'] = $member_info['member_signname'];
         $_SESSION['member_sex'] = $member_info['member_sex'];
         $_SESSION['member_birthday'] = $member_info['member_birthday'];
-        $_SESSION['member_mobile_bind'] = $member_info['member_mobile_bind'];
         $_SESSION['member_state'] = $member_info['member_state'];
 
         $seller_info = Model('seller')->getSellerInfo(array('member_id' => $_SESSION['member_id']));

+ 2 - 2
helper/bonus/factory.php

@@ -15,7 +15,7 @@ class factory
     {
         try
         {
-            $type = type::crate_by_input($paramer);
+            $type = type::create_by_input($paramer);
             $iGen = create_generator($type);
             $iGen->make_type();
 
@@ -31,7 +31,7 @@ class factory
     {
         try
         {
-            $type = type::crate_by_input($paramer);
+            $type = type::create_by_input($paramer);
             $iGen = create_generator($type);
             $iGen->make_type();
 

+ 1 - 1
helper/bonus/manager.php

@@ -351,7 +351,7 @@ class manager
             foreach ($items as &$bonus)
             {
                 $user_mobile = $mobiles[$index];
-                $infos = $mod_member->getMemberInfo(['member_mobile' => $user_mobile]);
+                $infos = $mod_member->getMemberInfo(['member_mobile' => $user_mobile,'member_mobile_bind' => 1]);
                 if(!empty($infos)) {
                     $minfo = new member_info($infos);
                     $bonus['user_id'] = $minfo->member_id();

+ 2 - 2
helper/bonus/parameters.php

@@ -36,7 +36,7 @@ class parameters
         $param['type_name']  = $type_name;
         $param['type_bless'] = $bless;
         $param['send_type']  = type::SendType_Fixed;
-        $param['grab_type']  = type::GrabType_EXEXIST;
+        $param['grab_type']  = type::GrabType_Invite;
         $param['relayer_id'] = $inviter;
         $param['sender_id']   = self::admin_member_id;
         $param['sender_name'] = self::admin_name;
@@ -469,7 +469,7 @@ class parameters
         $param['type_name']  = $type_name;
         $param['type_bless'] = $bless;
         $param['send_type']  = type::SendType_Fixed;
-        $param['grab_type']  = type::GrabType_EXEXIST;
+        $param['grab_type']  = type::GrabType_Invite;
         $param['relayer_id'] = 0;
         $param['sender_id']   = self::admin_member_id;
         $param['sender_name'] = self::admin_name;

+ 5 - 4
helper/bonus/type.php

@@ -48,9 +48,10 @@ class type
     const max_person_total_num  = 1000;
     const max_admin_total_num   = 5000;
 
-    const GrabType_All = 0;         //所有人都可以抢的红包
-    const GrabType_EXSENDER = 1;    //自己不可以抢
-    const GrabType_EXEXIST  = 2;    //注册用户不可以抢
+    const GrabType_All      = 0;         //所有人都可以抢的红包
+    const GrabType_ExSender = 1;    //自己不可以抢
+    const GrabType_Invite   = 2;   //邀请红包只可以抢一次不可以抢
+    const GrabType_ExMember = 3;   //已经是会员不可以抢
 
     private $mParam;
     private function __construct($param,$crete_type)
@@ -426,7 +427,7 @@ class type
         return intval($this->mParam['can_share']);
     }
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-    static public function crate_by_input($paramer)
+    static public function create_by_input($paramer)
     {
         return new type($paramer,self::create_type);
     }

+ 93 - 35
helper/bonus_helper.php

@@ -34,9 +34,9 @@ class bonus_helper
 
     static public function filter_type($type_info)
     {
-        $type = \bonus\type::create_by_paramer($type_info);
+        $type = bonus\type::create_by_paramer($type_info);
         $ret = $type->get_param();
-        $ret['time_out'] = \bonus\manager::grab_period_timeout;
+        $ret['time_out'] = bonus\manager::grab_period_timeout;
         if($type->binded_over()) {
             $ret['binded_over'] = 1;
         } else {
@@ -67,36 +67,36 @@ class bonus_helper
     }
 
     static public function isFixed($send_type) {
-        return ($send_type == \bonus\type::SendType_Fixed);
+        return ($send_type == bonus\type::SendType_Fixed);
     }
     static public function isRandom($send_type) {
-        return ($send_type == \bonus\type::SendType_Random);
+        return ($send_type == bonus\type::SendType_Random);
     }
 
     static public function create_type_input($param) {
-        return \bonus\type::crate_by_input($param);
+        return bonus\type::create_by_input($param);
     }
     static public function create_by_paramer($param) {
-        return \bonus\type::create_by_paramer($param);
+        return bonus\type::create_by_paramer($param);
     }
     static public function create_type_sn($type_sn) {
-        return \bonus\type::create_by_sn($type_sn);
+        return bonus\type::create_by_sn($type_sn);
     }
 
     static public function make_bonus($param, $rate_moneys)
     {
-        $ret = \bonus\factory::make_bonus($param,$rate_moneys);
+        $ret = bonus\factory::make_bonus($param,$rate_moneys);
         return $ret;
     }
     static public function make_vote_type($param, $rate_moneys)
     {
-        $ret = \bonus\factory::make_vote_type($param,$rate_moneys);
+        $ret = bonus\factory::make_vote_type($param,$rate_moneys);
         return $ret;    }
 
     static public function last_invite_type($member_id)
     {
         $mod = Model('bonus_type');
-        $items = $mod->get(array('relayer_id' => $member_id, 'make_type' => \bonus\type::MakeInviteType));
+        $items = $mod->get(['relayer_id' => $member_id, 'make_type' => bonus\type::MakeInviteType]);
         if(empty($items)) {
             return null;
         } else {
@@ -106,39 +106,74 @@ class bonus_helper
 
     static public function get_typeinfo($type_sn)
     {
-        $manager = new \bonus\manager();
+        $manager = new bonus\manager();
         return $manager->get_typeinfo($type_sn);
     }
 
     static public function get_mine_by_typesn($type_sn) {
-        $manager = new \bonus\manager();
+        $manager = new bonus\manager();
         return $manager->get_mine_by_typesn($type_sn);
     }
 
     static public function get_mine_by_bonussn($bonus_sn) {
-        $manager = new \bonus\manager();
+        $manager = new bonus\manager();
         return $manager->get_mine_by_bonussn($bonus_sn);
     }
 
     static public function grab_bonus($type_sn)
     {
-        $manager = new \bonus\manager();
+        $manager = new bonus\manager();
         return $manager->grab_bonus($type_sn);
     }
 
+    static private function onBinded($bonus_sn,$mobile,$userid)
+    {
+        try
+        {
+            $bonus = bonus\user_bonus::create_by_sn($bonus_sn);
+            $type_sn = $bonus->type_sn();
+            $type = bonus\type::create_by_sn($type_sn);
+            if($type->grab_type() != bonus\type::GrabType_Invite) return true;
+
+            if($userid > 0) {
+                $member_id = $userid;
+            }
+            elseif(!empty($mobile)) {
+                $loginner = new login\mobile_log($mobile);
+                if($loginner->ismember() == false) return false;
+                $member_id = $loginner->memberid();
+            }
+            else {
+                $member_id = 0;
+            }
+
+            if($member_id > 0) {
+                $mod_member = Model('member');
+                $mod_member->editMember(['member_id' => $member_id],['invited_bonus' => 1]);
+            }
+
+            return true;
+        }
+        catch (Exception $ex) {
+            Log::record(__METHOD__ . " " . $ex->getMessage(),Log::ERR);
+        }
+    }
+
     static public function bind_bonus($bonus_sn,$session_id,$mobile,$userid,&$new_bonus_sn)
     {
         try
         {
-            $manager = new \bonus\manager();
-            return $manager->bind_bonus($bonus_sn,$session_id,$mobile,$userid,$new_bonus_sn);
+            $manager = new bonus\manager();
+            $ret = $manager->bind_bonus($bonus_sn,$session_id,$mobile,$userid,$new_bonus_sn);
+            if($ret) self::onBinded($bonus_sn,$mobile,$userid);
+            return $ret;
         } catch (Exception $ex) {
             return array($ex->getCode(),$ex->getMessage());
         }
     }
     static public function shake($bonus_sn,$strength,$direction)
     {
-        $manager = new \bonus\manager();
+        $manager = new bonus\manager();
         return $manager->shake($bonus_sn,$strength,$direction);
     }
 
@@ -146,7 +181,7 @@ class bonus_helper
     {
         try
         {
-            $manager = new \bonus\manager();
+            $manager = new bonus\manager();
             return $manager->comment($bonus_sn,$comment);
         } catch (Exception $ex) {
             return false;
@@ -161,13 +196,13 @@ class bonus_helper
             return false;
         }
 
-        $manager = new \bonus\manager();
+        $manager = new bonus\manager();
         $bonusex = array();
         foreach($bind_bonus as $val)
         {
             $type_id = $val['type_id'];
-            $type  = \bonus\type::create_by_id($type_id);
-            $bonus = \bonus\user_bonus::create_by_param($val);
+            $type  = bonus\type::create_by_id($type_id);
+            $bonus = bonus\user_bonus::create_by_param($val);
 
             try
             {
@@ -188,10 +223,10 @@ class bonus_helper
     }
 
     static public function direct_asc() {
-        return \bonus\shaker::direct_asc;
+        return bonus\shaker::direct_asc;
     }
     static public function direct_dec() {
-        return \bonus\shaker::direct_dec;
+        return bonus\shaker::direct_dec;
     }
 
     static public function get_direction($first)
@@ -250,7 +285,7 @@ class bonus_helper
     {
         $fsuccess =  true;
         $total = 0.00;
-        $holder = new \bonus\witholder($member_id,$used_type);
+        $holder = new bonus\witholder($member_id,$used_type);
         foreach ($rates as $rate => $money)
         {
             if($holder->withold($rate,$money) == true) {
@@ -270,7 +305,7 @@ class bonus_helper
 
     static public function withold_money($member_id,$rate,$money,$used_type)
     {
-        $holder = new \bonus\witholder($member_id,$used_type);
+        $holder = new bonus\witholder($member_id,$used_type);
         if($holder->withold($rate,$money) == false) {
             Log::record("withold user member_id={$member_id} money={$money}.",Log::ERR);
         }
@@ -279,7 +314,7 @@ class bonus_helper
 
     static public function withold_bonus($member_id,$bonus_sn,$rate,$money,$used_type)
     {
-        $holder = new \bonus\witholder($member_id,$used_type);
+        $holder = new bonus\witholder($member_id,$used_type);
         return $holder->withold_bonus($rate,$bonus_sn,$money);
     }
 
@@ -287,7 +322,7 @@ class bonus_helper
     {
         try
         {
-            $manager = new \bonus\manager();
+            $manager = new bonus\manager();
             return $manager->send($type_sn,$member_ids);
         } catch (Exception $ex) {
             return false;
@@ -297,23 +332,23 @@ class bonus_helper
     {
         try
         {
-            $manager = new \bonus\manager();
+            $manager = new bonus\manager();
             return $manager->send_mobile($type_sn,$mobiles,$status);
         } catch (Exception $ex) {
             return false;
         }
     }
     static public function get_share($share_id = 0) {
-        return \bonus\open_sharer::instance()->get($share_id);
+        return bonus\open_sharer::instance()->get($share_id);
     }
 
-    static public function can_grab(\bonus\type $type,$member_id,$mobile)
+    static public function can_grab(bonus\type $type,$member_id,$mobile)
     {
         $grab_type = $type->grab_type();
-        if($grab_type == \bonus\type::GrabType_All) {
+        if($grab_type == bonus\type::GrabType_All) {
             return true;
         }
-        elseif($grab_type == \bonus\type::GrabType_EXSENDER)
+        elseif($grab_type == bonus\type::GrabType_ExSender)
         {
             if($type->sender_id() == $member_id) {
                 return false;
@@ -323,11 +358,31 @@ class bonus_helper
             }
             return true;
         }
-        else
+        elseif($grab_type == bonus\type::GrabType_Invite)
+        {
+            $member_id = intval($member_id);
+            if($member_id <= 0 && empty($mobile)) return true;
+
+            if($member_id > 0)
+            {
+                $loginner = new login\memberid_log($member_id);
+                if(!$loginner->ismember()) return true;
+                $mInfo = $loginner->member_info();
+            }
+            else
+            {
+                $loginner = new login\mobile_log($mobile);
+                if(!$loginner->ismember()) return true;
+                $mInfo = $loginner->member_info();
+            }
+
+            return ($mInfo->invited_bonus() == false);
+        }
+        elseif ($grab_type == bonus\type::GrabType_ExMember)
         {
             $member_id = intval($member_id);
             if($member_id > 0 && !empty($mobile)) {
-                $cond['member_id|member_mobile'] = array('_multi'=>true,$member_id,$mobile);
+                $cond['member_id|member_mobile'] = ['_multi'=>true,$member_id,$mobile];
             }
             elseif($member_id > 0) {
                 $cond['member_id'] = $member_id;
@@ -342,12 +397,15 @@ class bonus_helper
             $items = Model('member')->getMemberInfo($cond);
             return (empty($items) == true);
         }
+        else {
+            return false;
+        }
     }
 
     static public function match_price($rate_moneys)
     {
         if(empty($rate_moneys)) return false;
-        $scaler = new \bonus\scaler($rate_moneys);
+        $scaler = new bonus\scaler($rate_moneys);
         return $scaler->calc();
     }
 }

+ 4 - 0
helper/login/ilogin.php

@@ -161,4 +161,8 @@ abstract class ILogin
             return false;
         }
     }
+    public function member_info() {
+        if($this->mMemberId <= 0) return false;
+        return new member_info($this->mMemberInfo);
+    }
 }

+ 4 - 0
helper/model/member_info.php

@@ -184,4 +184,8 @@ class member_info
     public function binded_wechat() {
         return intval($this->member_info['member_wechat_bind']) == 1;
     }
+    public function invited_bonus() {
+        return intval($this->member_info['invited_bonus']) == 1;
+    }
+
 }

+ 1 - 1
helper/predeposit_helper.php

@@ -564,7 +564,7 @@ class predeposit_helper
         $name = $minfo->nickname();
         $param['type_name'] = "{$name}";
 
-        $type = \bonus\type::crate_by_input($param);
+        $type = \bonus\type::create_by_input($param);
 
         $rate_moneys = [];
         $item['amount'] = $type->getTotal_amount();

+ 71 - 39
helper/session_helper.php

@@ -251,57 +251,77 @@ class session_helper
         return $ar_contact;
     }
 
-    static public function session_id()
-    {
+    static public function session_id() {
         return empty($_SESSION['MPHPSESSID']) ? "" : $_SESSION['MPHPSESSID'];
     }
+    static public function binded_mobile() {
+        return intval($_SESSION['member_mobile_bind']) == 1;
+    }
+    static public function binded_wechat() {
+        return intval($_SESSION['member_wechat_bind']) == 1;
+    }
 
     static public function need_wechat_author()
     {
-        if(array_key_exists('author_orgin_url',$_SESSION)) {
-            unset($_SESSION['author_orgin_url']);
-        }
+        wechat_helper::clear_origin_url();
 
         if (util::from_wechat() == false) {
             return false;
         }
         else
         {
-            if (array_key_exists('wx_author', $_SESSION))
+            if (wechat_helper::has_userinfo())
             {
-                if (array_key_exists('handled', $_SESSION['wx_author']))
+                $user_info = wechat_helper::userinfo();
+                if(session_helper::logined())
                 {
-                    $user_info = $_SESSION['wx_author']['user_info'];
-                    $loginer = new login\unionid_log($user_info['unionid']);
-                    if ($loginer->ismember() == true) {
-                        $loginer->bind($user_info);
-                        $loginer->login();
-                        wechat_helper::clear_wxinfo();
+                    $id_logginer = new login\memberid_log(session_helper::memberid());
+                    if(session_helper::binded_wechat())
+                    {
+                        $wechat_loginer = new login\open_userinfo_log($user_info);
+                        if($wechat_loginer->ismember()) {
+                            $wechat_loginer->login();
+                        }
+                        else {
+                            $id_logginer->unbind_wechat();
+                            $id_logginer->bind($user_info);
+                            $id_logginer->login();
+                        }
                     }
                     else {
-                        $loginer->register($user_info,session_helper::relay_id(),session_helper::mobile());
+                        $id_logginer->bind($user_info);
+                        $id_logginer->login();
                     }
                 }
-
+                else
+                {
+                    $wechat_loginer = new login\open_userinfo_log($user_info);
+                    if ($wechat_loginer->ismember()) {
+                        $wechat_loginer->login();
+                    }
+                    else {
+                        $wechat_loginer->register($user_info,session_helper::relay_id(),session_helper::mobile());
+                        $wechat_loginer->login();
+                    }
+                }
+                wechat_helper::clear_wxinfo();
                 return false;
             }
             else
             {
-                return true;
-
-//                if (!empty($_SESSION['member_wxunionid']) && !empty($_SESSION['member_wxopenid']))
-//                {
-//                    $author_time = $_SESSION['wxauthor_time'];
-//                    $max_time = 2 * 86400;
-//                    if (time() - $author_time > $max_time) {
-//                        return true;
-//                    } else {
-//                        return false;
-//                    }
-//                }
-//                else {
-//                    return true;
-//                }
+                if (session_helper::binded_wechat())
+                {
+                    $author_time = $_SESSION['wxauthor_time'];
+                    $max_time = 86400;
+                    if (time() - $author_time > $max_time) {
+                        return true;
+                    } else {
+                        return false;
+                    }
+                }
+                else {
+                    return true;
+                }
             }
         }
     }
@@ -544,18 +564,9 @@ class wechat_helper
             return "";
         }
     }
-    static public function handled()
-    {
-        if(array_key_exists('wx_author',$_SESSION)) {
-            return boolval($_SESSION['wxauthor']['handled']);
-        } else {
-            return false;
-        }
-    }
 
     static public function set_userinfo($userinfo) {
         $_SESSION['wx_author']['user_info'] = $userinfo;
-        $_SESSION['wx_author']['handled'] = false;
     }
 
     static public function clear_wxinfo()
@@ -564,4 +575,25 @@ class wechat_helper
             unset($_SESSION['wx_author']);
         }
     }
+
+    static public function has_origin_url()
+    {
+        return array_key_exists('author_orgin_url',$_SESSION);
+    }
+    static public function set_origin_url($url) {
+        $_SESSION['author_orgin_url'] = $url;
+    }
+    static public function get_origin_url() {
+        if(array_key_exists('author_orgin_url',$_SESSION)) {
+            return $_SESSION['author_orgin_url'];
+        } else {
+            return "";
+        }
+    }
+    static public function clear_origin_url()
+    {
+        if(array_key_exists('author_orgin_url',$_SESSION)) {
+            unset($_SESSION['author_orgin_url']);
+        }
+    }
 }

+ 2 - 1
helper/third_author/wxauthor.php

@@ -13,6 +13,7 @@ require_once(BASE_ROOT_PATH . '/core/framework/function/http.php');
 
 use util;
 use Log;
+use wechat_helper;
 
 class wxauthor
 {
@@ -43,7 +44,7 @@ class wxauthor
                     'state' => urlencode(BASE_SITE_URL)];
         $ref_url = util::http_add_params(self::authorize_url,$params);
         $ref_url .= '#wechat_redirect';
-        $_SESSION['author_orgin_url'] = $origin_url;
+        wechat_helper::set_origin_url($origin_url);
         return $ref_url;
     }
 

+ 1 - 1
mobile/control/mshop.php

@@ -1,4 +1,4 @@
-猛兽ps<?php
+<?php
 /**
  * Created by PhpStorm.
  * User: stanley-king

+ 9 - 14
mobile/wxauthor.php

@@ -15,30 +15,25 @@ error_reporting(E_ERROR);
 $code  = $_GET['code'];
 $state = $_GET['state'];
 
-$sid = session_helper::session_id();
-$org_url = $_SESSION['author_orgin_url'];
-
-Log::record("sid = {$sid},author_orgin_url={$org_url}",Log::DEBUG);
 if(empty($code)) {
     Log::record("没有同意授权");
 }
 else
 {
-    if(array_key_exists('author_orgin_url',$_SESSION))
+    if(wechat_helper::has_origin_url())
     {
         $author = new \thrid_author\wxauthor();
         $user_info = $author->callback($code);
         if(empty($user_info)) {
             Log::record("微信取到的信息为空",Log::DEBUG);
         }
-        else {
-            $_SESSION['wx_author']['user_info'] = $user_info;
-            $_SESSION['wx_author']['handled'] = false;
-
-            $origin_url = $_SESSION['author_orgin_url'];
-            unset($_SESSION['author_orgin_url']);
-
+        else
+        {
+            wechat_helper::set_userinfo($user_info);
+            $origin_url = wechat_helper::get_origin_url();
+            wechat_helper::clear_origin_url();
             Log::record("origin_url={$origin_url}",Log::DEBUG);
+            
             if(!empty($origin_url))
             {
                 $html = "<!DOCTYPE html>
@@ -58,11 +53,11 @@ else
             }
         }
     }
-    else {
+    else
+    {
         $host = $state;
         $state = urlencode($state);
         $url = "{$host}/mobile/wxauthor.php?code={$code}&state={$state}";
-
         Log::record("redirect url={$url}",Log::DEBUG);
         $html = "<!DOCTYPE html>
                         <html lang=\"en\">

+ 0 - 1
room_srv.php

@@ -83,4 +83,3 @@ while ($count-- > 0) {
 //search_work($listen_fd);
 
 
-