Browse Source

debug dblock

stanley-king 8 years ago
parent
commit
3d3c06a3b2

+ 46 - 35
core/framework/db/mysqli.php

@@ -17,7 +17,7 @@ class Db
     const ErrLock = 1205;
     const ErrLock = 1205;
 
 
 	private static $link = array();
 	private static $link = array();
-	private static $iftransacte = true;
+	private static $ifTransacting = false;
 
 
 	private function __construct()
 	private function __construct()
 	{
 	{
@@ -31,10 +31,10 @@ class Db
 
 
 	private static function init_link()
 	private static function init_link()
     {
     {
-        if(!isset(self::$link['master']) || is_object(self::$link['master']) == false) {
+        if(!isset(self::$link['master']) || (is_object(self::$link['master']) == false)) {
             self::connect('master');
             self::connect('master');
         }
         }
-        if(!isset(self::$link['slave']) || is_object(self::$link['slave']) == false) {
+        if(!isset(self::$link['slave']) || (is_object(self::$link['slave']) == false)) {
             self::connect('slave');
             self::connect('slave');
         }
         }
     }
     }
@@ -125,22 +125,27 @@ class Db
                 $eno = mysqli_errno(self::$link[$host]);
                 $eno = mysqli_errno(self::$link[$host]);
                 $emsg = mysqli_error(self::$link[$host]);
                 $emsg = mysqli_error(self::$link[$host]);
                 $error = "Db Error eno={$eno} msg={$emsg}";
                 $error = "Db Error eno={$eno} msg={$emsg}";
-
                 Log::record("{$error} \r\n sql={$sql}",Log::ERR);
                 Log::record("{$error} \r\n sql={$sql}",Log::ERR);
-                if($eno == self::ErrUnConnect || $eno == self::ErrLock)
-                {
-                    if($count > 0) return false;
-                    self::closeLink($host);
-                    self::connect($host);
-                    $count++;
+
+                if(self::$ifTransacting) {
+                    throw_exception($error);
                 }
                 }
                 else
                 else
                 {
                 {
-                    if (C('debug')) {
-                        throw_exception($error.'<br/>'.$sql);
-                        return false;
-                    } else {
-                        return false;
+                    if($eno == self::ErrUnConnect)
+                    {
+                        if($count > 0) return false;
+                        self::connect($host);
+                        $count++;
+                    }
+                    else
+                    {
+                        if (C('debug')) {
+                            throw_exception($error.'<br/>'.$sql);
+                            return false;
+                        } else {
+                            return false;
+                        }
                     }
                     }
                 }
                 }
             }
             }
@@ -611,46 +616,52 @@ class Db
     public static function beginTransaction($host = 'master')
     public static function beginTransaction($host = 'master')
     {
     {
         self::init_link();
         self::init_link();
-        if (self::$iftransacte)
+        if (!self::$ifTransacting)
         {
         {
-            Log::record("autocommit start 1",Log::DEBUG);
             $result = self::$link[$host]->autocommit(false);
             $result = self::$link[$host]->autocommit(false);
     		if($result == false)
     		if($result == false)
     		{
     		{
-                $errno = mysqli_errno(self::$link[$host]);
-                $error = "Db Error autocommit no= error={$errno}" . mysqli_error(self::$link[$host]);
-                Log::record($error."\r\n",Log::ERR);
+                self::connect($host);
+                self::$ifTransacting = false;
 
 
-                if($errno == self::ErrUnConnect) {
-                    self::closeLink($host);
-                    self::connect($host);
-                }
                 Log::record("autocommit start 2",Log::DEBUG);
                 Log::record("autocommit start 2",Log::DEBUG);
                 self::$link[$host]->autocommit(false);
                 self::$link[$host]->autocommit(false);
+            } else {
+                Log::record("autocommit start 1",Log::DEBUG);
             }
             }
     	}
     	}
-    	self::$iftransacte = false;
+    	self::$ifTransacting = true;
     }
     }
 
 
     public static function commit($host = 'master')
     public static function commit($host = 'master')
     {
     {
-        if (!self::$iftransacte) {
+        if (self::$ifTransacting)
+        {
     		$result = self::$link[$host]->commit();
     		$result = self::$link[$host]->commit();
-            Log::record("autocommit end 1",Log::DEBUG);
-            self::$link[$host]->autocommit(true);//开启自动提交
-    		self::$iftransacte = true;
-    		if (!$result) throw_exception("Db Error: ".mysqli_error(self::$link[$host]));
+            Log::record("autocommit end commit",Log::DEBUG);
+            self::$link[$host]->autocommit(true);
+    		self::$ifTransacting = false;
+
+    		if (!$result) {
+    		    $err = mysqli_error(self::$link[$host]);
+    		    throw_exception("Db Error: {$err}");
+            }
     	}
     	}
     }
     }
 
 
     public static function rollback($host = 'master')
     public static function rollback($host = 'master')
     {
     {
-        if (!self::$iftransacte){
+        if (self::$ifTransacting){
     		$result = self::$link[$host]->rollback();
     		$result = self::$link[$host]->rollback();
-            Log::record("autocommit end 2",Log::DEBUG);
-            self::$link[$host]->autocommit(true);
-    		self::$iftransacte = true;
-    		if (!$result) throw_exception("Db Error: ".mysqli_error(self::$link[$host]));
+            Log::record("autocommit end rollback",Log::DEBUG);
+            $fsuccess = self::$link[$host]->autocommit(true);
+    		self::$ifTransacting = false;
+
+    		if (!$result || !$fsuccess) {
+                $err = mysqli_error(self::$link[$host]);
+                self::connect('master');
+                throw_exception("Db Error: {$err}");
+    		}
     	}
     	}
     }
     }
 
 

+ 1 - 1
data/logic/buy_1.logic.php

@@ -1007,7 +1007,7 @@ class buy_1Logic
      * 并标识该商品为限时商品
      * 并标识该商品为限时商品
      * @param array $cart_list
      * @param array $cart_list
      */
      */
-    public function getXianshiCartList(& $cart_list)
+    public function getXianshiCartList(&$cart_list)
     {
     {
         if (!C('promotion_allow') || empty($cart_list)) return ;
         if (!C('promotion_allow') || empty($cart_list)) return ;
 
 

+ 2 - 1
data/logic/payment.logic.php

@@ -114,7 +114,8 @@ class paymentLogic
                     DB::commit();
                     DB::commit();
                 }
                 }
 
 
-                account_helper::onPredeposit($change_type,$member_id,$order_info['order_sn']);
+                QueueClient::push('onPredeposit',
+                    array('change_type' => $change_type,'buyer_id'=>$member_id,'order_sn'=>$order_info['order_sn']));
             }
             }
 
 
             return true;
             return true;

+ 7 - 0
data/logic/queue.logic.php

@@ -618,4 +618,11 @@ class queueLogic
         login_helper::onInvite($member_id,$relay_id,$password);
         login_helper::onInvite($member_id,$relay_id,$password);
         return callback(true);
         return callback(true);
     }
     }
+
+    public function onPredeposit($param)
+    {
+        Log::record('queue::onPredeposit',Log::DEBUG);
+        account_helper::onPredeposit($param['change_type'],$param['buyer_id'],$param['order_sn']);
+        return callback(true);
+    }
 }
 }

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

@@ -1168,7 +1168,6 @@ class buyModel {
             $model_cart->commit();
             $model_cart->commit();
 
 
         }catch (Exception $e){
         }catch (Exception $e){
-
             //回滚事务
             //回滚事务
             $model_cart->rollback();
             $model_cart->rollback();
             return array('error' => $e->getMessage());
             return array('error' => $e->getMessage());
@@ -1190,7 +1189,7 @@ class buyModel {
         //删除购物车中的商品
         //删除购物车中的商品
         if ($post['ifcart']) {
         if ($post['ifcart']) {
             $model_cart->delCart('db',array('buyer_id'=>$member_id,'cart_id'=>array('in',array_keys($input_buy_items))));
             $model_cart->delCart('db',array('buyer_id'=>$member_id,'cart_id'=>array('in',array_keys($input_buy_items))));
-//             QueueClient::push('delCart', array('buyer_id'=>$member_id,'cart_ids'=>array_keys($input_buy_items)));
+            //QueueClient::push('delCart', array('buyer_id'=>$member_id,'cart_ids'=>array_keys($input_buy_items)));
         }
         }
 
 
         return array('pay_sn' => $pay_sn);
         return array('pay_sn' => $pay_sn);

+ 31 - 25
helper/bonus/grab.php

@@ -59,33 +59,39 @@ class general_grab extends IGrab
         if(!empty($bonus))
         if(!empty($bonus))
         {
         {
             $user_bonus = user_bonus::create_by_param($bonus);
             $user_bonus = user_bonus::create_by_param($bonus);
-
-            Db::beginTransaction();
-            if($is_new_grab && $is_new_bind)
-            {
-                Log::record("general_grab->get_bonus 1");
-                $bonus_val = $user_bonus->bonus_value();
-                Model('bonus_type')->edit(array('type_id' => $type_id),
-                                          array('grabed_num'    => array('exp', 'grabed_num+1'),
-                                                'binded_num'    => array('exp', 'binded_num+1'),
-                                                'remain_amount' => array('exp', "remain_amount-{$bonus_val}")));
-            }
-            else if($is_new_bind)
+            try
             {
             {
-                Log::record("general_grab->get_bonus 2");
-                $bonus_val = $user_bonus->bonus_value();
-                Model('bonus_type')->edit(array('type_id' => $type_id),
-                                          array('binded_num'    => array('exp', 'binded_num+1'),
-                                                'remain_amount' => array('exp', "remain_amount-{$bonus_val}")));
+                Db::beginTransaction();
+                if($is_new_grab && $is_new_bind)
+                {
+                    Log::record("general_grab->get_bonus 1");
+                    $bonus_val = $user_bonus->bonus_value();
+                    Model('bonus_type')->edit(array('type_id' => $type_id),
+                        array('grabed_num'    => array('exp', 'grabed_num+1'),
+                            'binded_num'    => array('exp', 'binded_num+1'),
+                            'remain_amount' => array('exp', "remain_amount-{$bonus_val}")));
+                }
+                else if($is_new_bind)
+                {
+                    Log::record("general_grab->get_bonus 2");
+                    $bonus_val = $user_bonus->bonus_value();
+                    Model('bonus_type')->edit(array('type_id' => $type_id),
+                        array('binded_num'    => array('exp', 'binded_num+1'),
+                            'remain_amount' => array('exp', "remain_amount-{$bonus_val}")));
+                }
+                else if($is_new_grab) {
+                    Log::record("general_grab->get_bonus 2");
+                    Model('bonus_type')->edit(array('type_id' => $type_id), array('grabed_num' => array('exp', 'grabed_num+1')));
+                }
+                Db::commit();
+                Log::record("general_grab->get_bonus end with one bonus.");
+                return $user_bonus;
+            } catch (Exception $ex) {
+                Db::rollback();
+                return array();
             }
             }
-            else if($is_new_grab) {
-                Log::record("general_grab->get_bonus 2");
-                Model('bonus_type')->edit(array('type_id' => $type_id), array('grabed_num' => array('exp', 'grabed_num+1')));
-            }
-            Db::commit();
-            Log::record("general_grab->get_bonus end with one bonus.");
-            return $user_bonus;
-        } else {
+        }
+        else {
             Log::record("general_grab->get_bonus end with not grab bonus");
             Log::record("general_grab->get_bonus end with not grab bonus");
             return array();
             return array();
         }
         }

+ 17 - 9
helper/bonus/manager.php

@@ -16,6 +16,7 @@ use member_info;
 use algorithm;
 use algorithm;
 use Log;
 use Log;
 use Db;
 use Db;
+use Exception;
 
 
 class manager
 class manager
 {
 {
@@ -323,16 +324,23 @@ class manager
         Log::record("bind_bonus bind ret={$ret}",Log::DEBUG);
         Log::record("bind_bonus bind ret={$ret}",Log::DEBUG);
         if($ret == true)
         if($ret == true)
         {
         {
-            Db::beginTransaction();
-            //bind 一个新红包
-            $bonus_val = $user_bonus->bonus_value();
-            Model('bonus_type')->edit(array('type_id' => $type_id),
-                array('binded_num' => array('exp', 'binded_num+1'),
-                'remain_amount' => array('exp', "remain_amount-" . "{$bonus_val}")));
-            Db::commit();
+            try
+            {
+                //bind 一个新红包
+                $bonus_val = $user_bonus->bonus_value();
 
 
-            $this->clear_session($bonus_sn);
-            dcache($user_bonus->type_sn(),self::type_prefix);
+                Db::beginTransaction();
+                Model('bonus_type')->edit(array('type_id' => $type_id),
+                    array('binded_num' => array('exp', 'binded_num+1'),
+                        'remain_amount' => array('exp', "remain_amount-" . "{$bonus_val}")));
+                Db::commit();
+
+                $this->clear_session($bonus_sn);
+                dcache($user_bonus->type_sn(),self::type_prefix);
+            } catch (Exception $ex) {
+                Db::rollback();
+                return false;
+            }
         }
         }
         else
         else
         {
         {

+ 0 - 1
helper/bonus/shaker.php

@@ -31,7 +31,6 @@ class shaker
             Db::beginTransaction();
             Db::beginTransaction();
 
 
             $mod_bonus = Model('user_bonus');
             $mod_bonus = Model('user_bonus');
-
             $min_amount = self::min_amount;
             $min_amount = self::min_amount;
             $items = $mod_bonus->get(array('type_id' => $type_id,'bonus_status' => 0,'bonus_value' => array('gt',$min_amount)));
             $items = $mod_bonus->get(array('type_id' => $type_id,'bonus_status' => 0,'bonus_value' => array('gt',$min_amount)));
             if(!empty($items))
             if(!empty($items))

+ 38 - 23
helper/fcode/operator.php

@@ -12,6 +12,7 @@ require_once (BASE_ROOT_PATH . '/helper/session_helper.php');
 
 
 use session_helper;
 use session_helper;
 use Log;
 use Log;
+use Exception;
 
 
 class operator
 class operator
 {
 {
@@ -91,20 +92,27 @@ class operator
         $cond['session_id']     = $fcode['session_id'];
         $cond['session_id']     = $fcode['session_id'];
         $cond['mobile']         = $fcode['mobile'];
         $cond['mobile']         = $fcode['mobile'];
 
 
-        $datas = array( 'grab_state' => 2,
+        $datas = array('grab_state' => 2,
             'mobile' => $mobile,
             'mobile' => $mobile,
-            'user_key' => mt_rand(1000, 9999));
+            'user_key' => mt_rand(1000, 9999),
+            'usable_time' => time() + ($fcode['usable_days'] * 24 * 3600));
 
 
-        $this->mod_fcode->beginTransaction();
-        $ret = $this->mod_fcode->where($cond)->update($datas);
-        $affect_rows = $this->mod_fcode->affected_rows();
-        $this->mod_fcode->commit();
-
-        Log::record("fcode::grab try_grab ret={$ret} affected_rows={$affect_rows}",Log::DEBUG);
-        if($ret != false && $affect_rows > 0) {
-            $fcode = array_merge($fcode,$datas);
-            return $fcode;
-        } else {
+        try
+        {
+            $this->mod_fcode->beginTransaction();
+            $ret = $this->mod_fcode->where($cond)->update($datas);
+            $affect_rows = $this->mod_fcode->affected_rows();
+            $this->mod_fcode->commit();
+
+            Log::record("fcode::grab try_grab ret={$ret} affected_rows={$affect_rows}",Log::DEBUG);
+            if($ret != false && $affect_rows > 0) {
+                $fcode = array_merge($fcode,$datas);
+                return $fcode;
+            } else {
+                return false;
+            }
+        } catch (Exception $ex) {
+            $this->mod_fcode->rollback();
             return false;
             return false;
         }
         }
     }
     }
@@ -132,7 +140,8 @@ class operator
                             'grab_time' => time(),
                             'grab_time' => time(),
                             'session_id' => session_helper::session_id(),
                             'session_id' => session_helper::session_id(),
                             'mobile' => session_helper::cur_mobile(),
                             'mobile' => session_helper::cur_mobile(),
-                            'user_key' => mt_rand(1000, 9999));
+                            'user_key' => mt_rand(1000, 9999),
+                            'usable_time' => time() + ($fcode['usable_days'] * 24 * 3600));
         }
         }
         else {
         else {
             $datas = array( 'grab_state' => 1,
             $datas = array( 'grab_state' => 1,
@@ -140,16 +149,22 @@ class operator
                             'session_id' => session_helper::session_id());
                             'session_id' => session_helper::session_id());
         }
         }
 
 
-        $this->mod_fcode->beginTransaction();
-        $ret = $this->mod_fcode->where($cond)->update($datas);
-        $affect_rows = $this->mod_fcode->affected_rows();
-        $this->mod_fcode->commit();
-
-        Log::record("fcode::grab try_grab ret={$ret} affected_rows={$affect_rows}",Log::DEBUG);
-        if($ret != false && $affect_rows > 0) {
-            $fcode = array_merge($fcode,$datas);
-            return $fcode;
-        } else {
+        try
+        {
+            $this->mod_fcode->beginTransaction();
+            $ret = $this->mod_fcode->where($cond)->update($datas);
+            $affect_rows = $this->mod_fcode->affected_rows();
+            $this->mod_fcode->commit();
+
+            Log::record("fcode::grab try_grab ret={$ret} affected_rows={$affect_rows}",Log::DEBUG);
+            if($ret != false && $affect_rows > 0) {
+                $fcode = array_merge($fcode,$datas);
+                return $fcode;
+            } else {
+                return false;
+            }
+        } catch (Exception $ex) {
+            $this->mod_fcode->rollback();
             return false;
             return false;
         }
         }
     }
     }

+ 0 - 1
helper/notify_helper.php

@@ -119,7 +119,6 @@ class notify_helper
             catch (Exception $e)
             catch (Exception $e)
             {
             {
                 Model::rollback();
                 Model::rollback();
-
                 $sresult = implode(',',$type);
                 $sresult = implode(',',$type);
                 Log::record('bonus refund : error:' . $e->getMessage() . " result:{$sresult}.");
                 Log::record('bonus refund : error:' . $e->getMessage() . " result:{$sresult}.");
             }
             }