find_quality($mchid,$amount,$card_type,$org_quality,$commit_times,time() - $order_time,'',$regin_no); if($first_comit) { refill\util::incr_user_commit($mchid,$card_type,$amount,$org_quality); } if ($need_check) { $valided = mtopcard\valid_phone($card_no); if (!$valided) { $order_id = refill\RefillFactory::instance()->zero_order($mchid, $buyer_id, $amount, $card_no, $mch_order, $idcard, $card_name, $notify_url, $quality, $org_quality, $order_time, $commit_times, "无效的手机号"); refill\util::pop_queue_order($mchid,$mch_order); QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => false]); util::del_exclude_channel($mchid,$mch_order,$card_type); return; } } [$errcode, $errmsg, $order_id, $neterr,$net_errno] = refill\RefillFactory::instance()->add($mchid, $buyer_id, $amount, $card_no, $mch_order, $idcard, $card_name, $notify_url, $quality,$org_quality, $order_time, $commit_times, $last_order_id,$card_type,$regin_no,$quantity); $params['commit_times'] += 1; $commit_times += 1; if($errcode !== true) { $fNotify = true; if($errcode === refill\errcode::MERCHANT_REFILL_ERROR && $neterr && util::need_check($net_errno)) { $fNotify = false; QueueClient::async_push("QueryOrderNeterr",['order_id' => $order_id],5); } elseif(($errcode === refill\errcode::MERCHANT_REFILL_ERROR && $neterr) || $errcode == refill\errcode::PROVIDER_OVERLOAD || $errcode == errcode::MERCHANT_PRICE_UNSETTING) { [$org_quality,$quality] = refill\RefillFactory::instance()->find_quality($mchid,$amount,$card_type,$org_quality,$commit_times,time() - $order_time,'',$regin_no); if ($quality > 0) { $fNotify = false; $params['order_id'] = $order_id; if($order_id > 0) { $refill_order->edit($order_id, ['is_retrying' => 1]); } if(!refill\util::push_add($params)) { $fNotify = true; } } } if($fNotify) { if ($order_id === 0) { $order_info = $this->latest_order($refill_order, $mchid, $mch_order); if (empty($order_info)) { $order_id = refill\RefillFactory::instance()->zero_order($mchid, $buyer_id, $amount, $card_no, $mch_order, $idcard, $card_name, $notify_url, $quality, $org_quality, $order_time, $commit_times, $errmsg); } else { $order_id = $order_info['order_id']; $refill_order->edit($order_id, ['notify_time' => time(), 'notify_state' => 1,'is_retrying' => 0]); } } else { $refill_order->edit($order_id, ['notify_time' => time(), 'notify_state' => 1,'is_retrying' => 0]); } refill\util::pop_queue_order($mchid,$mch_order); QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => false]); util::del_exclude_channel($mchid,$mch_order,$card_type); } } } private function latest_order($refill_order,$mchid,$mch_order) { $orders = $refill_order->getMerchantOrderList(['mchid' => $mchid,'mch_order' => $mch_order]); if(empty($orders)) { return []; } else { $orders[0]; } } public function notify($channel,$input) { return refill\RefillFactory::instance()->notify($channel,$input); } public function notify_merchant($order_id,$manual) { return refill\RefillFactory::instance()->notify_merchant($order_id,$manual); } public function query($order_id) { return refill\RefillFactory::instance()->query($order_id); } public function query_net($order_id) { return refill\RefillFactory::instance()->query_net($order_id); } public function manual_success($order_id) { refill\RefillFactory::instance()->manual_success($order_id); } public function manual_cancel($order_id) { refill\RefillFactory::instance()->manual_cancel($order_id); } public function addthird($params) { $refill_order = Model('refill_order'); $mchid = $params['mchid']; $buyer_id = $params['buyer_id']; $amount = intval($params['amount']); $card_no = $params['card_no']; $mch_order = $params['mch_order']; $notify_url = $params['notify_url']; $idcard = $params['idcard'] ?? ''; $card_name = $params['card_name'] ?? ''; $order_time = $params['order_time'] ?? time(); $commit_times = $params['commit_times'] ?? 0; $last_order_id = $params['order_id'] ?? 0; $org_quality = intval($params['org_quality']) ?? 0; $card_type = intval($params['card_type']); $regin_no = 0; $product_code = $params['product_code']; $quantity = intval($params['quantity']); $third_card_type = $params['third_card_type']; $third_params = ['product_code' => $product_code, 'quantity' => $quantity, 'third_card_type' => $third_card_type]; refill\util::push_queue_order($mchid,$mch_order,ORDER_STATE_SEND); refill\util::incr_user_commit($mchid,$card_type,$amount,$org_quality); [$errcode, $errmsg, $order_id, $neterr,$net_errno] = refill\RefillFactory::instance()->add($mchid, $buyer_id, $amount, $card_no, $mch_order, $idcard, $card_name, $notify_url, $org_quality,$org_quality, $order_time, $commit_times, $last_order_id,$card_type,$regin_no,$quantity,$third_params); if($errcode !== true) { if ($order_id === 0) { $order_info = $this->latest_order($refill_order, $mchid, $mch_order); if (empty($order_info)) { $order_id = refill\RefillFactory::instance()->zero_order($mchid, $buyer_id, $amount, $card_no, $mch_order, $idcard, $card_name, $notify_url, $org_quality, $org_quality, $order_time, $commit_times, $errmsg,$quantity,$third_params); } else { $order_id = $order_info['order_id']; } } elseif($errcode === refill\errcode::MERCHANT_REFILL_ERROR && $neterr && util::need_check($net_errno)) { QueueClient::async_push("QueryOrderNeterr",['order_id' => $order_id],5); return; } else { $refill_order->edit($order_id, ['notify_time' => time(), 'notify_state' => 1,'is_retrying' => 0]); } refill\util::pop_queue_order($mchid,$mch_order); QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => false]); util::del_exclude_channel($mchid,$mch_order,$card_type); } } }