stanley-king il y a 8 ans
Parent
commit
525424d30e

+ 1 - 1
core/framework/db/mysqli.php

@@ -133,7 +133,7 @@ class Db
 
 		if ($query === false)
 		{
-		    $error = 'Db Error: '.mysqli_error(self::$link[$host]);
+		    $error = 'Db Error: no=' . mysqli_errno(self::$link[$host]) . ' error=' .mysqli_error(self::$link[$host]);
 			if (C('debug')) {
 			    throw_exception($error.'<br/>'.$sql);
 			} else {

+ 4 - 2
crontab/control/control.php

@@ -46,13 +46,15 @@ class BaseCronControl
         $store_bind_class = Model('store_bind_class');
         $model_refund_return = Model('refund_return');
 
-        for($i = 0; $i < 5000; $i++) {
+        for($i = 0; $i < 5000; $i++)
+        {
             if ($_break) {
                 break;
             }
             $model_order->beginTransaction();
             $goods_list = $model_order->getOrderGoodsList(array('commis_rate' => 200), 'rec_id,goods_id,store_id,gc_id', 100, null, '');
-            if (!empty($goods_list)) {
+            if (!empty($goods_list))
+            {
                 //$commis_rate_list : store_id => array(gc_id => commis_rate)
                 $commis_rate_list = $store_bind_class->getStoreGcidCommisRateList($goods_list);
                 //更新订单商品佣金值

+ 5 - 0
data/model/goods_fcode.model.php

@@ -27,6 +27,11 @@ class goods_fcodeModel extends Model {
     public function getGoodsFCodeList($condition, $order = 'fc_state asc,fc_id asc') {
         return $this->where($condition)->order($order)->select();
     }
+
+    public function getFcodeList($condition,$field='*', $order = 'fc_state asc,fc_id asc',$page = 0,$count = 0, $limit = 0, $group = '', $lock = false)
+    {
+        return $this->field($field)->where($condition)->group($group)->order($order)->limit($limit)->page($page, $count)->lock($lock)->select();
+    }
     
     /**
      * 删除F码

+ 17 - 11
data/model/user_bonus.model.php

@@ -189,17 +189,23 @@ class user_bonusModel extends Model
                 'session_id' => $sess_id);
         }
 
-        $this->beginTransaction();
-        $ret = $this->where($cond)->update($datas);
-        $affect_rows = $this->affected_rows();
-        $this->commit();
-
-        Log::record("user_bonusModel::grab ret={$ret} affected_rows={$affect_rows}",Log::DEBUG);
-        if($ret != false && $affect_rows > 0) {
-            $bonus = array_merge($bonus,$datas);
-            return $bonus;
-        } else {
-            return false;
+        try
+        {
+            $this->beginTransaction();
+            $ret = $this->where($cond)->update($datas);
+            $affect_rows = $this->affected_rows();
+            $this->commit();
+
+            Log::record("user_bonusModel::grab ret={$ret} affected_rows={$affect_rows}",Log::DEBUG);
+            if($ret != false && $affect_rows > 0) {
+                $bonus = array_merge($bonus,$datas);
+                return $bonus;
+            } else {
+                return false;
+            }
+        }
+        catch (Exception $ex) {
+            $this->rollback();
         }
     }
 

+ 3 - 2
helper/fcgi_server.php

@@ -126,17 +126,18 @@ class fcgi_server
             }
             catch (Exception $ex) {
                 mobileControl::outerr($ex->getCode(),$ex->getMessage());
+                Log::record("run_looper exception catch code={$ex->getCode()} msg={$ex->getMessage()}",Log::ERR);
             }
             session::instance()->end();
             fcgi_headers_sent();
             $contents = ob_get_clean();
             $msg = sprintf("request time=%.6f",microtime(true) - $start);
-            Log::record($msg,Log::ERR);
+            Log::record($msg,Log::DEBUG);
             fcgi_echo($contents);
             //fcgi_finish();//单线程的情况下不需要调用
 
             $msg = sprintf("request time=%.6f",microtime(true) - $start);
-            Log::record($msg,Log::ERR);
+            Log::record($msg,Log::DEBUG);
         }
 
         fcgi_fini();

+ 19 - 1
helper/fcode/mfcode.php

@@ -8,7 +8,10 @@
 
 namespace fcode;
 
+require_once (BASE_ROOT_PATH . '/helper/goods/commonid_helper.php');
+
 use Exception;
+use commonid_helper;
 
 class mfcode
 {
@@ -53,6 +56,21 @@ class mfcode
         }
     }
 
+    public function format()
+    {
+        $result = [];
+        $result['fcode_id'] = $this->fc_id();
+
+        $result['goods_id'] = commonid_helper::instance()->one_goods($this->commonid());
+        $result['fcode']    = $this->fcode();
+        $result['key']      = $this->user_key();
+        $result['usable_time'] = $this->usable_time();
+        $result['used'] = $this->used();
+        $result['expired'] = $this->expired();
+
+        return $result;
+    }
+
     public function fc_id() {
         return intval($this->mParams['fc_id']);
     }
@@ -83,7 +101,7 @@ class mfcode
     public function usable_time() {
         return intval($this->mParams['usable_time']);
     }
-    public function overtime() {
+    public function expired() {
         return $this->usable_time() <= time();
     }
 }

+ 37 - 4
helper/goods/commonid_helper.php

@@ -30,8 +30,8 @@ class commonid_helper
     public function common_id($goods_id)
     {
         $goods_id = intval($goods_id);
-
         if($goods_id <= 0) return false;
+
         if(isset($this->mGid2CidContainer[$goods_id])) {
             return $this->mGid2CidContainer[$goods_id];
         }
@@ -63,10 +63,43 @@ class commonid_helper
 
     public function goods_ids($common_id)
     {
-        if(isset($this->mCid2GidsContainer[$common_id])) {
-            return $this->mCid2GidsContainer[$common_id];
+        if(intval($common_id) <= 0) return false;
+
+        if(isset($this->mCid2GidsContainer[$common_id]))
+        {
+            if(empty($this->mCid2GidsContainer[$common_id])) {
+                return false;
+            } else {
+                return $this->mCid2GidsContainer[$common_id];
+            }
+        }
+        else
+        {
+            $mod = Model('goods');
+            $items = $mod->where(array('goods_commonid' => $common_id))->field('goods_id')->limit(false)->select();
+            if(empty($items)) {
+                $this->mCid2GidsContainer[$common_id] = [];
+                return false;
+            }
+            else
+            {
+                $this->mCid2GidsContainer[$common_id] = [];
+                foreach ($items as $item) {
+                    $goods_id = intval($item['goods_id']);
+                    $this->mCid2GidsContainer[$common_id][] = $goods_id;
+                }
+
+                return $this->mCid2GidsContainer[$common_id];
+            }
+        }
+    }
+    public function one_goods($common_id)
+    {
+        $gids = $this->goods_ids($common_id);
+        if($gids == false) {
+            return false;
         } else {
-            return [];
+            return $gids[0];
         }
     }
 }

+ 68 - 4
mobile/control/member_fcode.php

@@ -7,6 +7,7 @@
  */
 
 require_once(BASE_ROOT_PATH . '/helper/fcode/mfcode.php');
+require_once (BASE_ROOT_PATH . '/helper/goods_helper.php');
 
 class member_fcodeControl extends mbMemberControl
 {
@@ -17,7 +18,69 @@ class member_fcodeControl extends mbMemberControl
 
     public function listOp()
     {
+        $mod_fcode = Model('goods_fcode');
+        $items = $mod_fcode->getFcodeList(array('mobile' => session_helper::cur_mobile()),'*','fc_state asc,fc_id asc',$this->page_size());
+        $page_count = $mod_fcode->gettotalpage();
 
+        $fcodes = [];
+        $gids = [];
+
+        foreach ($items as $item) {
+            $fcoder = new fcode\mfcode($item);
+            $fcode = $fcoder->format();
+            $gids[] = intval($fcode['goods_id']);
+            $fcodes[] = $fcode;
+        }
+
+        if(empty($fcodes))
+        {
+            return self::outsuccess(array('special_list' => null,
+                'fcodes' => null,
+                'summary'  => null,
+                'groupbuy' => null,
+                'limitime' => null,
+                'bundling' => null,
+                'mobile_page' => mobile_page($page_count)));
+        }
+        else
+        {
+            $blocks = $this->format($fcodes);
+            $helper = new goods_helper();
+            $ret = $helper->cart_summary($gids,$related_goods);
+
+            return self::outsuccess(array('special_list' => $blocks,
+                'fcodes' => $fcodes,
+                'summary'  => $ret['summary'],
+                'groupbuy' => $ret['groupbuy'],
+                'limitime' => $ret['limitime'],
+                'bundling' => $ret['bundling'],
+                'mobile_page' => mobile_page($page_count)));
+        }
+    }
+
+    private function format($fcodes)
+    {
+        $blocks = [];
+
+        foreach ($fcodes as $fcode)
+        {
+            $block = [];
+            $block['item_title'] = '';
+            $block['item_type'] = 'home1';
+
+            $item['image'] = '';
+            $item['show_type'] = "fcode";
+            $item['show_data'] = strval($fcode['fcode_id']);
+            $item['type'] = "goods";
+            $item['data'] = strval($fcode['goods_id']);;
+            $item['title'] = '';
+
+            $block['items'][] = $item;
+            $blocks[] = $block;
+            $blocks[] = special_formater::def_divider();
+        }
+
+        return $blocks;
     }
 
     public function addOp()
@@ -32,15 +95,16 @@ class member_fcodeControl extends mbMemberControl
         try
         {
             $fcode = new fcode\mfcode($fc_code);
-            if($fcode->user_key() != $user_key) {
-                return self::outerr(errcode::ErrParamter,"参数错误,密钥不正确.");
-            }
+
             if($fcode->used()) {
                 return self::outerr(errcode::ErrParamter,"该F码已经使用过了,不能添加.");
             }
-            if($fcode->overtime()) {
+            if($fcode->expired()) {
                 return self::outerr(errcode::ErrParamter,"该F码已经过期,不能添加.");
             }
+            if($fcode->user_key() != $user_key) {
+                return self::outerr(errcode::ErrParamter,"密钥不正确,可能输入错误或者已经被其他人占用.");
+            }
 
             $oper = new fcode\operator($fcode->commonid(),$fcode->batch_code());
             $oper->change($fcode,session_helper::cur_mobile());

+ 15 - 2
test/DBTest.php

@@ -236,6 +236,19 @@ class DBTest extends PHPUnit_Framework_TestCase
         $ret = $model->update(array('goods_click' =>array('exp','goods_click+1')));
     }
 
-
-
+    public function testAutoCommit()
+    {
+        $model = Model('member');
+        while (true)
+        {
+            $model->beginTransaction();
+            $ret = $model->where(array('member_id' => 10000000))->update(array('member_mobilex' => '18911779278'));
+            $affect_rows = $model->affected_rows();
+            $model->beginTransaction();
+            $ret = $model->where(array('member_id' => 36490))->update(array('member_mobile' => '18911779279'));
+            $affect_rows = $model->affected_rows();
+
+            $model->commit();
+        }
+    }
 }