|
@@ -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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|