stanley-king 3 年之前
父節點
當前提交
022a47f3aa
共有 3 個文件被更改,包括 66 次插入33 次删除
  1. 50 0
      data/model/card_info.model.php
  2. 16 9
      test/TestCardInfo.php
  3. 0 24
      test/TestRefillThird.php

+ 50 - 0
data/model/card_info.model.php

@@ -0,0 +1,50 @@
+<?php
+
+declare(strict_types=0);
+
+defined('InShopNC') or exit('Access Invalid!');
+
+class card_infoModel extends Model
+{
+    public function __construct()
+    {
+        parent::__construct('card_info');
+    }
+
+    public function import_old($info)
+    {
+        //'card_no,order_time,card_type,regin_no,is_transfer,cardno_state'
+        $card_no = $info['card_no'];
+        if(strlen($card_no) != 11) return false;
+
+        $item = $this->getCard($card_no);
+        if(empty($item)) {
+            $data['card_no'] = $card_no;
+            $data['add_time'] = $info['order_time'];
+            $data['update_time'] = $info['order_time'];
+            $data['using_times'] = 1;
+            $data['update_times'] = 1;
+
+            $data['orgin_type'] = $info['card_type'];
+            $data['card_type'] = $info['card_type'];
+            $data['regin'] = $info['regin_no'];
+            $data['transfer'] = $info['is_transfer'];
+            $data['card_state'] = $info['cardno_state'];
+
+            return $this->insert($data);
+        }
+        else {
+            $item['add_time'] = $info['order_time'];
+            $item['using_times'] = $item['using_times'] + 1;
+            $item['update_times'] = $item['using_times'] + 1;
+
+            return $this->where(['card_no' => $card_no])->update($item);
+        }
+    }
+
+    private function getCard($card_no)
+    {
+        $card_no = intval($card_no);
+        return $this->field('*')->where(['card_no' => $card_no])->find();
+    }
+}

+ 16 - 9
test/TestCardInfo.php

@@ -21,7 +21,17 @@ class TestCardInfo extends TestCase
     //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestCardInfo::testImport)( .*)?$/" --test-suffix TestCardInfo.php /var/www/html/test
     public function testImport()
     {
-        $import_hour = function ($end)
+        $mod_cardinfo = Model('card_info');
+        $importer = function ($info) use($mod_cardinfo)
+        {
+            $card_no = trim($info['card_no']);
+            if(strlen($card_no) != 11) {
+                return;
+            }
+            $mod_cardinfo->import_old($info);
+        };
+
+        $import_hour = function ($end) use ($importer)
         {
             $start = $end - 3600;
             $cond = ['order_time&order_time' => ['_multi' => true, ['egt', $start], ['lt', $end]],
@@ -38,9 +48,8 @@ class TestCardInfo extends TestCase
                 $i++;
 
                 if(empty($items)) break;
-                foreach ($items as $item)
-                {
-                    Log::record("{$item['card_no']}",Log::DEBUG);
+                foreach ($items as $item) {
+                    $importer($item);
                 }
             }
         };
@@ -48,16 +57,14 @@ class TestCardInfo extends TestCase
         $import_date = function ($end) use ($import_hour)
         {
             $start = $end - 86400;
-            for ($hour = $end; $hour >= $start; $hour -= 3600)
-            {
+            for ($hour = $end; $hour >= $start; $hour -= 3600) {
                 $import_hour($hour);
             }
         };
 
-        $import_days = function ($start_date,$end_date) use ($import_date)
+        $import_days = function ($start_date, $end_date) use ($import_date)
         {
-            for ($date = $end_date; $date > $start_date; $date -= 86400)
-            {
+            for ($date = $end_date; $date > $start_date; $date -= 86400) {
                 $import_date($date);
             }
         };

+ 0 - 24
test/TestRefillThird.php

@@ -262,30 +262,6 @@ class TestRefillThird extends TestCase
             . sprintf('%06d', (float)microtime() * 1000000);
     }
 
-    public function testAddQQ()
-    {
-        $params = $this->params();
-    }
-
-    private function params($card_no,$card_type,$quantity,$pcode,$order_sn)
-    {
-        $params['act'] = 'lzrefill';
-        $params['op'] = 'add_third';
-        $params['notifyurl'] = 'https://www.xyzshops.cn/mobile/signature.php';
-        $params['usr'] = 9618;
-
-        $params['card_no'] = $card_no;
-        $params['quantity'] = $quantity;
-        $params['product_code'] = $pcode;
-        $params['card_type'] = $card_type;
-
-        $params['ord'] = $order_sn;
-        $params['tim'] = date("YmdHis");
-        $params['yysid'] = 0;
-        $params['hmlx'] = 0;
-        return $params;
-    }
-
     public function testLingzhthirdPhone()
     {
         $providers = $this->getProvider('lingzhthird');