stanley-king 4 лет назад
Родитель
Сommit
93dcc17d2e
4 измененных файлов с 56 добавлено и 7 удалено
  1. 17 0
      helper/mtopcard/mtopcard.php
  2. 2 1
      mobile/control/member_card.php
  3. 2 1
      queue/control/index.php
  4. 35 5
      test/TestQueue.php

+ 17 - 0
helper/mtopcard/mtopcard.php

@@ -54,6 +54,23 @@ function topcard_type($str_type)
     }
 }
 
+
+function scard_type($card_type)
+{
+    if($card_type == PetroChinaCard) { //中石油
+        return 'petrochina';
+    }
+    elseif ($card_type == SinopecCard) { //中石化
+        return 'sinopec';
+    }
+    elseif($card_type == PhoneCard) { //手机卡
+        return 'phone';
+    }
+    else {
+        return 'unknown';
+    }
+}
+
 require_once(BASE_HELPER_PATH . '/mtopcard/topcard.php');
 require_once(BASE_HELPER_PATH . '/mtopcard/user_topcards.php');
 require_once(BASE_HELPER_PATH . '/mtopcard/CardPaper.php');

+ 2 - 1
mobile/control/member_card.php

@@ -37,6 +37,7 @@ class member_cardControl extends mbMemberControl
         foreach ($card_list as $item) {
             $card = new mtopcard\topcard($item);
             $ret[] = $card->format();
+            $ret['card_type'] = mtopcard\scard_type($ret['card_type']);
         }
         return $ret;
     }
@@ -56,7 +57,7 @@ class member_cardControl extends mbMemberControl
         if ($result) {
             self::outsuccess(null);
         } else {
-            return self::outerr(errcode::ErrTopCard, '充值卡保存失败保存失败');
+            return self::outerr(errcode::ErrTopCard, '充值卡保存失败');
         }
     }
 

+ 2 - 1
queue/control/index.php

@@ -20,7 +20,8 @@ class indexControl
         while (true) 
         {
             $list_key = $worker->scan();
-            if (!empty($list_key) && is_array($list_key)) {
+            if (!empty($list_key) && is_array($list_key))
+            {
                 foreach ($list_key as $key) {
                     $content = $worker->pop($key, time());
                     if (empty($content)) continue;

+ 35 - 5
test/TestQueue.php

@@ -1,4 +1,6 @@
-<?php
+<?php declare(strict_types=1);
+
+use PHPUnit\Framework\TestCase;
 
 /**
  * Created by PhpStorm.
@@ -9,21 +11,49 @@
 
 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 testQueue extends PHPUnit_Framework_TestCase
+class testQueue extends TestCase
 {
-    public static function setUpBeforeClass()
+    public static function setUpBeforeClass() :void
     {
         Base::run_util();
     }
 
+    public function testQueueSrv()
+    {
+        if (ob_get_level()) ob_end_clean();
+        $model_queue = Model('queue',BASE_PATH);
+
+        $worker = new QueueServer();
+        while (true)
+        {
+            $list_key = $worker->scan();
+            if (!empty($list_key) && is_array($list_key))
+            {
+                foreach ($list_key as $key) {
+                    $content = $worker->pop($list_key, 0);
+                    if (empty($content)) continue;
+                    $method = key($content);
+                    $arg = current($content);
+//                    $model_queue->$method($arg);
+                    echo date('Y-m-d H:i:s',time()).' '.$method."\n";
+                    flush();
+                    ob_flush();
+                }
+            }
+            sleep(1);
+        }
+    }
+
     public function testPush()
     {
         //{"action":"sendreq","params":null}
         $x['action'] = 'sendreq';
-        $x['params'] = array('speed' => 30);
+        $x['params'] = ['speed' => 30];
 
         $y = json_encode($x);
 
@@ -43,7 +73,7 @@ class testQueue extends PHPUnit_Framework_TestCase
 
     }
 
-    public static function tearDownAfterClass()
+    public static function tearDownAfterClass():void
     {
     }
 }