Parcourir la source

fix bind phone random

stanley-king il y a 4 ans
Parent
commit
8606fd26ca

+ 1 - 0
data/model/topcard.model.php

@@ -14,6 +14,7 @@ class topcardModel extends Model
     {
         return $this->table('topcard')->where(['card_no' => $card_no])->select();
     }
+
     public function add_money($card_no,$amount,$time)
     {
         $ret = $this->table('topcard')->where(['card_no' => $card_no])

+ 43 - 6
helper/refill/gftdsinop/RefillOil.php

@@ -29,16 +29,51 @@ class RefillOil extends refill\IRefillOil
         $params['fuelCardUserName'] = "";
         $params['fuelCardUserID'] = "";
 
-        $mobile = $this->make_mobile();
-        $params['telephone'] = $mobile;
-        $params['phoneNumber'] = $mobile;
+        $refill_info = $this->refill_info($card_no,$card_type);
+        $params['telephone'] = $refill_info['bind_phone'];
+        $params['phoneNumber'] = $refill_info['bind_phone'];
 
-        return $params;
+        return [$params, $refill_info];
+    }
+
+    private function refill_info($card_no, $card_type)
+    {
+        $data = rcache($card_no, 'cardrefill-');
+        if(empty($data))
+        {
+            $mod_topcard = Model('topcard');
+            $ret = $mod_topcard->get_card($card_no);
+            if(empty($ret)) {
+                $bind_phone = $this->make_mobile();
+                $mod_topcard->add($card_no,$card_type,time(),$bind_phone);
+                $data['bind_phone'] = $bind_phone;
+                $data['refill_time'] = time();
+                $data['times'] = 0;
+
+                wcache($card_no,$data,'cardrefill-');
+            }
+            else {
+                $val = $ret[0];
+
+                $data['bind_phone'] = $val['bind_phone'];
+                $data['refill_time'] = time();
+                $data['times'] = 0;
+            }
+        }
+
+        return $data;
+    }
+
+    private function inc_card($card_no, $refill_info)
+    {
+        $refill_info['times'] += 1;
+        $refill_info['refill_time'] = time();
+        wcache($card_no,$refill_info,'cardrefill-');
     }
 
     private function make_mobile()
     {
-        $no = "1" . mt_rand(3000000000, 9999999999);
+        $no = "1" . mt_rand(3000000000, 3999999999);
         return $no;
     }
 
@@ -109,7 +144,8 @@ class RefillOil extends refill\IRefillOil
 
     public function add($card_no,$card_type,$amount,$input)
     {
-        $params = $this->req_params($card_no,$card_type,$amount,$input);
+        [$params,$refill_info] = $this->req_params($card_no,$card_type,$amount,$input);
+
         $sign = $this->sign($params);
         $params['signature'] = $sign;
 
@@ -125,6 +161,7 @@ class RefillOil extends refill\IRefillOil
 
             if($resp['code'] == 0)
             {
+                $this->inc_card($card_no,$refill_info);
                 $data = $resp['data'];
                 return [true,$data['orderNumber']];
             }

+ 0 - 10
mobile/control/refill.php

@@ -49,16 +49,6 @@ class refillControl extends merchantControl
             return [false,'卡类型无法识别'];
         }
 
-//        if($card_type === mtopcard\PetroChinaCard)
-//        {
-//            if(empty($params['idcard'])) {
-//                return [false,'中石油需要参数没有包含身份证号码:idcard'];
-//            }
-//            if(empty($params['card_name'])) {
-//                return [false,'参数没有包含身份证姓名:card_name'];
-//            }
-//        }
-
         if(empty($params['notifyurl'])) {
             return [false,'参数没有包含notifyurl'];
         }

+ 47 - 0
test/TestRefill.php

@@ -462,6 +462,9 @@ class TestRefill extends TestCase
         $logic->NotifyMerchantComplete(['order_id' => 18171]);
     }
 
+    //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testCallMech)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
+
+
     private function send($url, $params)
     {
         $mchid = $params['mchid'];
@@ -674,8 +677,52 @@ class TestRefill extends TestCase
     {
         $goods = refill\RefillFactory::instance()->goods();
     }
+
+    private function make_mobile()
+    {
+        $no = "1" . mt_rand(3000000000, 3999999999);
+        return $no;
+    }
+
+    private function refill_info($card_no, $card_type)
+    {
+        $data = rcache($card_no, 'cardrefill-');
+        if(empty($data))
+        {
+            $mod_topcard = Model('topcard');
+            $ret = $mod_topcard->get_card($card_no);
+            if(empty($ret)) {
+                $bind_phone = $this->make_mobile();
+                $mod_topcard->add($card_no,$card_type,time(),$bind_phone);
+                $data['bind_phone'] = $bind_phone;
+                $data['refill_time'] = time();
+                $data['times'] = 0;
+
+                wcache($card_no,$data,'cardrefill-');
+            }
+            else {
+                $val = $ret[0];
+
+                $data['bind_phone'] = $val['bind_phone'];
+                $data['refill_time'] = time();
+                $data['times'] = 0;
+            }
+        }
+
+        return $data;
+    }
+
+    public function testGetMobile()
+    {
+        $card_no = '1000119000001679247';
+        $card_type = 1;
+
+        $info = $this->refill_info($card_no,$card_type);
+
+    }
 }
 
 
 //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testCall)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
+
 //docker-compose -f ./docker-compose-dev.yml run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testCall)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test