proxy.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. require_once (BASE_ROOT_PATH . '/helper/model_helper.php');
  3. class proxy
  4. {
  5. const max_retry = 5;
  6. const max_time_out = 120;
  7. public function add($params)
  8. {
  9. $refill_order = Model('refill_order');
  10. $mchid = $params['mchid'];
  11. $buyer_id = $params['buyer_id'];
  12. $amount = intval($params['amount']);
  13. $card_no = $params['card_no'];
  14. $quality = intval($params['quality'] ?? 1);
  15. $mch_order = $params['mch_order'];
  16. $notify_url = $params['notify_url'];
  17. $idcard = $params['idcard'] ?? '';
  18. $card_name = $params['card_name'] ?? '';
  19. $order_time = $params['order_time'] ?? time();
  20. $commit_times = $params['commit_times'] ?? 0;
  21. $last_order_id = $params['order_id'] ?? 0;
  22. [$errcode, $errmsg,$order_id,$neterr] = refill\RefillFactory::instance()->add($mchid, $buyer_id, $amount, $card_no,
  23. $mch_order, $idcard, $card_name, $notify_url,$quality, $order_time, $commit_times,$last_order_id);
  24. $params['commit_times'] += 1;
  25. $commit_times += 1;
  26. if($errcode !== true)
  27. {
  28. $fNotify = true;
  29. if(($errcode === refill\errcode::MERCHANT_REFILL_ERROR && $neterr) || $errcode == refill\errcode::PROVIDER_OVERLOAD)
  30. {
  31. if(refill\RefillFactory::instance()->can_nettry($quality,$order_time,$commit_times))
  32. {
  33. $fNotify = false;
  34. $params['order_id'] = $order_id;
  35. refill\util::push_add($params);
  36. }
  37. }
  38. if($fNotify)
  39. {
  40. if($order_id === 0)
  41. {
  42. $order_info = $this->latest_order($refill_order,$mchid,$mch_order);
  43. if(empty($order_info)) {
  44. $order_id = refill\RefillFactory::instance()->zero_order($mchid, $buyer_id, $amount, $card_no,
  45. $mch_order, $idcard, $card_name, $notify_url,$quality, $order_time, $commit_times,$errmsg);
  46. }
  47. else {
  48. $order_id = $order_info['order_id'];
  49. }
  50. }
  51. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => false]);
  52. }
  53. }
  54. }
  55. private function latest_order($refill_order,$mchid,$mch_order)
  56. {
  57. $orders = $refill_order->getOrderInfo(['mchid' => $mchid,'mch_order' => $mch_order]);
  58. if(empty($orders)) {
  59. return [];
  60. }
  61. else {
  62. $orders[0];
  63. }
  64. }
  65. public function notify($channel,$input)
  66. {
  67. refill\RefillFactory::instance()->notify($channel,$input);
  68. }
  69. }