Bläddra i källkod

add update locker to account

stanley-king 3 år sedan
förälder
incheckning
3f76ee7807

+ 2 - 2
data/config/dev/base.ini.php

@@ -46,8 +46,8 @@ $config['gip'] 		= 0;
 $config['dbdriver'] = 'mysqli';
 $config['tablepre']	= 'lrlz_';
 
-//define('SSH_TUNEL_PROD','local');
-define('SSH_TUNEL_PROD','xyz');
+define('SSH_TUNEL_PROD','local');
+//define('SSH_TUNEL_PROD','xyz');
 //define('SSH_TUNEL_PROD','lingzh');
 
 if(SSH_TUNEL_PROD ==='local') {

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

@@ -117,7 +117,7 @@ class buy_virtualLogic
             $model_goods = Model('goods');
             //开始事务
             $trans = new trans_wapper($model_goods,__METHOD__);
-            $member_info = Model('member')->getMemberInfo(['member_id' => $member_id], '*', true);
+            $member_info = Model('member')->getMemberInfoLock(['member_id' => $member_id]);
             $order_info = $this->_createOrder($input,$goods_info,$member_info);
             if (!empty($post['password']))
             {

+ 6 - 0
data/model/member.model.php

@@ -28,6 +28,12 @@ class memberModel extends Model
     {
         return $this->table('member')->field($field)->where($condition)->master($master)->find();
     }
+
+    public function getMemberInfoLock($condition, $field = '*')
+    {
+        return $this->table('member')->field($field)->where($condition)->master(true)->lock(true)->find();
+    }
+
     public function getBindedMemberByMobile($mobile, $field = '*', $master = false)
     {
         $cond = ['member_mobile' => $mobile,'member_mobile_bind' => 1];

+ 1 - 0
docker/compose/stanley/docker-compose.yml

@@ -197,6 +197,7 @@ services:
       - ../../../:/var/www/html
       - /Volumes/Transcend/upload:/var/www/html/data/upload
       - /Users/stanley-king/work/PHPProject/shoplog:/var/www/html/data/log
+      - /Users/stanley-king/work/PHPProject/amount:/var/www/html/data/amount
     container_name: "panda-php"
     depends_on:
       - "redisrv"

+ 68 - 0
test/TestAccount.php

@@ -0,0 +1,68 @@
+<?php
+
+
+use PHPUnit\Framework\TestCase;
+
+define('APP_ID', 'test');
+define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
+
+require_once(BASE_ROOT_PATH . '/global.php');
+require_once(BASE_CORE_PATH . '/lrlz.php');
+require_once(BASE_ROOT_PATH . '/fooder.php');
+
+class TestAccount extends TestCase
+{
+    public static function setUpBeforeClass(): void
+    {
+        Base::run_util();
+    }
+
+    public function testLog()
+    {
+        $files = ['65937-81.log','65937-45.log','65937-175.log'];
+
+        $total = 0.0;
+        foreach ($files as $file)
+        {
+            $amount = $this->parase_file($file);
+            $total += $amount;
+            Log::record("total={$total} {$file} amount = {$amount}",Log::DEBUG);
+        }
+
+        Log::record("total = {$total}",Log::DEBUG);
+    }
+
+    private function parase_file($file)
+    {
+        $fn = fopen(BASE_ROOT_PATH . "/data/amount/{$file}", "r");
+
+
+        $total_amount = ncPriceFormat(0.00);
+
+        $i = 0;
+        while (!feof($fn)) {
+            $i++;
+            $line = trim(fgets($fn));
+            $ret = preg_match('/[\w\W]+UPDATE[\w\W]+available_predeposit=available_predeposit(?P<oper>[-+]+)(?P<amount>[.\d]+)/i', $line, $matches);
+            if ($ret)
+            {
+                $oper = $matches['oper'];
+                $amount = $matches['amount'];
+                if ($oper == '-') {
+                    $total_amount = ncPriceFormat($total_amount) - ncPriceFormat($amount);
+
+                } else {
+                    $total_amount = ncPriceFormat($total_amount) + ncPriceFormat($amount);
+                }
+
+                Log::record("index = {$i} {$total_amount} = {$total_amount} {$oper} {$amount}", Log::DEBUG);
+            }
+        }
+
+        Log::record("total_amount:{$total_amount}", Log::DEBUG);
+        fclose($fn);
+
+        return $total_amount;
+    }
+}
+//docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestAccount::testLog)( .*)?$/" --test-suffix TestAccount.php /var/www/html/test

+ 0 - 35
test/TestRefill.php

@@ -1622,44 +1622,9 @@ class TestRefill extends TestCase
         $ret = preg_match('/[\w\W]+"channelOrderNumber":"(?P<order_sn>[^"]+)"[\w\W]+"message":"(?P<message>[\x{4e00}-\x{9fa5}]+)"[\w\W]+"status":109/u', $line, $matches);
     }
 
-    public function testLog()
-    {
-//        $line = './LOG/20210203-mobile.log:[15 2021-02-03 10:41:17] SQL: UPDATE `lrlz_member` SET available_predeposit=available_predeposit+975 WHERE ( member_id = \'65818\' ) [ RunTime:0.000297s ]';
-        $fn = fopen(BASE_ROOT_PATH . "/10096.log", "r");
-        $mod = Model();
-        $mod->table('tfloat')->where(['member_id' => 65818])->update(['pdamount' => 0]);
-
 
-        $total_amount = ncPriceFormat(0.00);
-
-        $i = 0;
-        while (!feof($fn)) {
-
-            $i++;
-            $line = trim(fgets($fn));
-            $ret = preg_match('/[\w\W]+UPDATE[\w\W]+available_predeposit=available_predeposit(?P<oper>[-+]+)(?P<amount>[.\d]+)/i', $line, $matches);
-            if ($ret) {
-                $oper = $matches['oper'];
-                $amount = $matches['amount'];
-                if ($oper == '-') {
-                    $total_amount = ncPriceFormat($total_amount) - ncPriceFormat($amount);
-//                    $mod->table('tfloat')->where(['member_id' => 65818])->update( ['pdamount'=>['exp','pdamount-'.$amount]]);
 
-                } else {
-                    $total_amount = ncPriceFormat($total_amount) + ncPriceFormat($amount);
-//                    $mod->table('tfloat')->where(['member_id' => 65818])->update( ['pdamount'=>['exp','pdamount+'.$amount]]);
-
-                }
 
-                Log::record("index = {$i} {$total_amount} = {$total_amount} {$oper} {$amount}", Log::DEBUG);
-            }
-        }
-
-        Log::record("total_amount:{$total_amount}", Log::DEBUG);
-        fclose($fn);
-
-
-    }
 
     public function testMchctl()
     {