|
@@ -7,6 +7,7 @@ use refill\Quality;
|
|
|
|
|
|
require_once(BASE_ROOT_PATH . '/helper/model_helper.php');
|
|
|
require_once(BASE_HELPER_PATH . '/refill/policy/transfer.php');
|
|
|
+require_once(BASE_HELPER_PATH . '/refill/policy/transfer_timeout.php');
|
|
|
|
|
|
class proxy
|
|
|
{
|
|
@@ -79,7 +80,16 @@ class proxy
|
|
|
return $ret;
|
|
|
}
|
|
|
|
|
|
- private function transfer(refill\order $order) : bool
|
|
|
+ private function need_transfer_timeout(refill\order $order)
|
|
|
+ {
|
|
|
+ $mchid = $order->mchid();
|
|
|
+ $mch_order = $order->mch_order();
|
|
|
+ $order_state = util::query_queue_order($mchid,$mch_order);
|
|
|
+
|
|
|
+ return $order_state == ORDER_STATE_TIMEOUT;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function transfer(refill\order $order, $time_out = false): bool
|
|
|
{
|
|
|
$order_canceler = function ($order_id,$err_msg) {
|
|
|
$logic_vr_order = Logic("vr_order");
|
|
@@ -87,10 +97,15 @@ class proxy
|
|
|
$logic_vr_order->changeOrderStateCancel($order_info, '', $err_msg, true, true);
|
|
|
};
|
|
|
|
|
|
- $transfer_order = function (refill\order $order)
|
|
|
+ $transfer_order = function (refill\order $order,$time_out)
|
|
|
{
|
|
|
$mchid = $order->mchid();
|
|
|
- [$trans_mchid,$adminid] = refill\transfer::instance()->transfer_info($mchid);
|
|
|
+
|
|
|
+ if ($time_out) {
|
|
|
+ [$trans_mchid, $adminid] = refill\transfer_timeout::instance()->transfer_info($mchid);
|
|
|
+ } else {
|
|
|
+ [$trans_mchid, $adminid] = refill\transfer::instance()->transfer_info($mchid);
|
|
|
+ }
|
|
|
|
|
|
if($trans_mchid == 0 || $adminid == 0) {
|
|
|
return false;
|
|
@@ -123,15 +138,18 @@ class proxy
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if(!$transfer_order($order)) {
|
|
|
- $order_canceler($order_id,$errmsg);
|
|
|
+ if (!$transfer_order($order, $time_out)) {
|
|
|
+ $order_canceler($order_id, $errmsg);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
$order->finish();
|
|
|
refill\util::pop_queue_order($mchid, $mch_order, $order->order_time());
|
|
|
- QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => false]);
|
|
|
|
|
|
+ if(!$time_out) {
|
|
|
+ QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => false]);
|
|
|
+ }
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -158,6 +176,7 @@ class proxy
|
|
|
refill\util::push_queue_order($mchid, $mch_order, ORDER_STATE_SEND);
|
|
|
$mod_refill->partition(util::part_refill($order_time))->edit_detail($mchid,$mch_order,['order_state' => ORDER_STATE_SEND]);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
Log::record("proxy::add times={$order->commit_times()} mch_order=$mch_order card_no={$order->card_no()} regin_no={$order->region_no()} org_quality={$order->org_quality()} quality={$order->cur_quality()}",Log::DEBUG);
|
|
|
|
|
@@ -216,7 +235,10 @@ class proxy
|
|
|
refill\util::onEventSubmit($order);
|
|
|
}
|
|
|
}
|
|
|
- elseif($this->need_transfer($order) && $this->transfer($order)) {
|
|
|
+ elseif ($this->need_transfer($order) && $this->transfer($order)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ elseif ($this->need_transfer_timeout($order) && $this->transfer($order, true)) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -260,7 +282,7 @@ class proxy
|
|
|
return $fError;
|
|
|
};
|
|
|
|
|
|
- [$errcode, $errmsg, $order_id, $neterr,$net_errno] = refill\RefillFactory::instance()->add($order);
|
|
|
+ [$errcode, $errmsg, $order_id, $neterr, $net_errno] = refill\RefillFactory::instance()->add($order);
|
|
|
if($errcode !== true)
|
|
|
{
|
|
|
//遇到网络错误情况,查询处理
|
|
@@ -284,11 +306,26 @@ class proxy
|
|
|
if ($fError) {
|
|
|
return $this->onEerror($order,true, $errmsg);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ $fError = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ //超时预回调,需要在下订单号对订单进行监控。
|
|
|
+ if(!$fError and $order->first_commit() and $this->need_tmout_monitor($order)) {
|
|
|
+ refill\transfer_timeout::instance()->monitor($order);
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ private function need_tmout_monitor(refill\order $order)
|
|
|
+ {
|
|
|
+ $mchid = $order->mchid();
|
|
|
+ $ret = refill\transfer_timeout::instance()->need_monitor($mchid);
|
|
|
+
|
|
|
+ return $ret;
|
|
|
+ }
|
|
|
+
|
|
|
private function need_intercept(refill\order $order)
|
|
|
{
|
|
|
if($order->is_third()) return false;
|
|
@@ -360,6 +397,10 @@ class proxy
|
|
|
{
|
|
|
return refill\RefillFactory::instance()->notify_merchant($order_id,$manual);
|
|
|
}
|
|
|
+ public function notify_merchant_success($mchid, $mch_order)
|
|
|
+ {
|
|
|
+ return refill\RefillFactory::instance()->notify_merchant_success($mchid, $mch_order);
|
|
|
+ }
|
|
|
public function query($order_id)
|
|
|
{
|
|
|
return refill\RefillFactory::instance()->query($order_id);
|
|
@@ -373,6 +414,10 @@ class proxy
|
|
|
{
|
|
|
return refill\RefillFactory::instance()->query_net($order_id);
|
|
|
}
|
|
|
+ public function query_timeout($mchid, $mch_order)
|
|
|
+ {
|
|
|
+ return refill\RefillFactory::instance()->query_timeout($mchid, $mch_order);
|
|
|
+ }
|
|
|
public function manual_success($order_id)
|
|
|
{
|
|
|
refill\RefillFactory::instance()->manual_success($order_id);
|