1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- require_once (BASE_ROOT_PATH . '/helper/model_helper.php');
- class proxy
- {
- const max_retry = 5;
- const max_time_out = 120;
- public function add($params)
- {
- $refill_order = Model('refill_order');
- $mchid = $params['mchid'];
- $buyer_id = $params['buyer_id'];
- $amount = intval($params['amount']);
- $card_no = $params['card_no'];
- $quality = intval($params['quality'] ?? 1);
- $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;
- [$errcode, $errmsg,$order_id,$neterr] = refill\RefillFactory::instance()->add($mchid, $buyer_id, $amount, $card_no,
- $mch_order, $idcard, $card_name, $notify_url,$quality, $order_time, $commit_times,$last_order_id);
- $params['commit_times'] += 1;
- $commit_times += 1;
- if($errcode !== true)
- {
- $fNotify = true;
- if(($errcode === refill\errcode::MERCHANT_REFILL_ERROR && $neterr) || $errcode == refill\errcode::PROVIDER_OVERLOAD)
- {
- if(refill\RefillFactory::instance()->can_nettry($quality,$order_time,$commit_times))
- {
- $fNotify = false;
- $params['order_id'] = $order_id;
- refill\util::push_add($params);
- }
- }
- 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, $order_time, $commit_times,$errmsg);
- }
- else {
- $order_id = $order_info['order_id'];
- }
- }
- QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => false]);
- }
- }
- }
- private function latest_order($refill_order,$mchid,$mch_order)
- {
- $orders = $refill_order->getOrderInfo(['mchid' => $mchid,'mch_order' => $mch_order]);
- if(empty($orders)) {
- return [];
- }
- else {
- $orders[0];
- }
- }
- public function notify($channel,$input)
- {
- refill\RefillFactory::instance()->notify($channel,$input);
- }
- }
|