stanley-king 2 anni fa
parent
commit
c43dd4a4da
2 ha cambiato i file con 92 aggiunte e 0 eliminazioni
  1. 84 0
      helper/refill/ops/detail_ops.php
  2. 8 0
      test/TestRefillCommand.php

+ 84 - 0
helper/refill/ops/detail_ops.php

@@ -0,0 +1,84 @@
+<?php
+
+namespace refill;
+use Log;
+
+class detail_ops
+{
+    public function __construct()
+    {
+    }
+    public function correct_state($partition,$start,$last)
+    {
+        $detail_gen = function ($part, $start,$last)
+        {
+            while (true)
+            {
+                $end = $start + 1000;
+                $cond = ['detail_id&detail_id' => ['_multi' => true, ['egt', $start], ['lt', $end]]];
+
+                $start = 0;
+                $items = Model()->table('refill_detail')
+                    ->partition($part)
+                    ->field('detail_id,mchid,mch_order,order_state')
+                    ->where($cond)
+                    ->order('order_id asc')->limit("{$start},1000")->select();
+
+                if(empty($items)) break;
+
+                $last_item = end($items);
+                $start = intval($last_item['detail_id']);
+
+                foreach ($items as $item)
+                {
+                    if ($item['order_state'] == ORDER_STATE_QUEUE) {
+                        yield $item;
+                    }
+                }
+                if($start > $last) {
+                    break;
+                }
+            }
+        };
+
+        $state_check = function ($partition,$mchid,$mch_order)
+        {
+            $mod_refill = Model();
+            $cond_complete = ['mchid' => $mchid, 'mch_order' => $mch_order, 'inner_status' => 0];
+            $cond_sending = ['mchid' => $mchid, 'mch_order' => $mch_order];
+
+
+            $item = $mod_refill->table('refill_order')->partition($partition)->where($cond_complete)->find();
+            if(!empty($item))
+            {
+                if($item['mch_notify_state'] != 0) {
+                    return ORDER_STATE_HANDLED;
+                }
+                else {
+                    return ORDER_STATE_SEND;
+                }
+            }
+            else
+            {
+                $items = $mod_refill->table('refill_order')->partition($partition)->where($cond_sending)->select();
+                if(count($items) > 0) {
+                    return ORDER_STATE_SEND;
+                }
+                else {
+                    return -1;
+                }
+            }
+        };
+
+        $details = $detail_gen($partition,$start,$last);
+        foreach ($details as $item)
+        {
+            $mchid = $item['mchid'];
+            $mch_order = $item['mch_order'];
+            $detail_id = $item['detail_id'];
+
+            $state = $state_check($partition,$mchid,$mch_order);
+            Log::record("detail_id={$detail_id},mchid={$mchid},mch_order={$mch_order} order_state={$state}",Log::DEBUG);
+        }
+    }
+}

+ 8 - 0
test/TestRefillCommand.php

@@ -13,6 +13,7 @@ require_once(BASE_ROOT_PATH . '/fooder.php');
 require_once(BASE_ROOT_PATH . '/helper/stat_helper.php');
 require_once(BASE_HELPER_PATH . '/refill/ops/order_clear.php');
 require_once(BASE_HELPER_PATH . '/refill/ops/pdlog_clear.php');
+require_once(BASE_HELPER_PATH . '/refill/ops/detail_ops.php');
 
 class TestRefillCommand extends TestCase
 {
@@ -55,4 +56,11 @@ class TestRefillCommand extends TestCase
         $refill = new statistics\stat_refill();
         $refill->restat([$sDate]);
     }
+
+    //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillCommand::testFixDetailState)( .*)?$/" --test-suffix TestRefillCommand.php /var/www/html/test
+    public function testFixDetailState()
+    {
+        $detail_ops = new refill\detail_ops();
+        $detail_ops->correct_state('p202301',382586049,383016938);
+    }
 }