|
@@ -1,19 +1,19 @@
|
|
|
<?php
|
|
|
|
|
|
-
|
|
|
namespace refill;
|
|
|
|
|
|
require_once(BASE_HELPER_PATH . '/queue/rdispatcher.php');
|
|
|
require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
|
|
|
require_once(BASE_HELPER_PATH . '/rbridge/RBridgeFactory.php');
|
|
|
-
|
|
|
-
|
|
|
require_once(BASE_HELPER_PATH . '/refill/IRefill.php');
|
|
|
require_once(BASE_HELPER_PATH . '/refill/IRefillOil.php');
|
|
|
require_once(BASE_HELPER_PATH . '/refill/IRefillPhone.php');
|
|
|
require_once(BASE_HELPER_PATH . '/refill/IRefillCallBack.php');
|
|
|
+require_once(BASE_HELPER_PATH . '/refill/ProviderManager.php');
|
|
|
require_once(BASE_HELPER_PATH . '/refill/CalcMerchantPrice.php');
|
|
|
require_once(BASE_HELPER_PATH . '/refill/util.php');
|
|
|
+require_once(BASE_HELPER_PATH . '/refill/errcode.php');
|
|
|
+
|
|
|
require_once(BASE_HELPER_RAPI_PATH . '/api.php');
|
|
|
|
|
|
use Log;
|
|
@@ -23,269 +23,38 @@ use member_info;
|
|
|
use Exception;
|
|
|
use rbridge\RBridgeFactory;
|
|
|
use trans_wapper;
|
|
|
-use StatesHelper;
|
|
|
-use queue;
|
|
|
|
|
|
class RefillBase
|
|
|
{
|
|
|
- protected $mOilProvider;
|
|
|
- protected $mPhoneProvider;
|
|
|
- protected $mProviderNames;
|
|
|
- protected $mLimits = [];
|
|
|
-
|
|
|
- public function allow($mchid,$card_type,$amount)
|
|
|
- {
|
|
|
- $reader = function () {
|
|
|
- $cache = rcache("refill_able",'merchant-');
|
|
|
- if(!empty($cache)) {
|
|
|
- $result = unserialize($cache['data']);
|
|
|
- }
|
|
|
- else {
|
|
|
- $result = [];
|
|
|
- }
|
|
|
- return $result;
|
|
|
- };
|
|
|
-
|
|
|
- if(defined('MOBILE_SERVER') && MOBILE_SERVER === true)
|
|
|
- {
|
|
|
- if(StatesHelper::fetch_state('merchant')) {
|
|
|
- $this->mLimits = $reader();
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- $this->mLimits = $reader();
|
|
|
- }
|
|
|
-
|
|
|
- $key = "{$mchid}-{$card_type}-{$amount}";
|
|
|
- if(empty($this->mLimits)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- elseif(array_key_exists($key,$this->mLimits)) {
|
|
|
- return $this->mLimits[$key];
|
|
|
- }
|
|
|
- else {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public function goods()
|
|
|
- {
|
|
|
- global $config;
|
|
|
-
|
|
|
- $oil = $this->combine_goods($config['oil_providers'], 1);
|
|
|
- $phone = $this->combine_goods($config['phone_providers'], 2);
|
|
|
-
|
|
|
- return array_merge($oil, $phone);
|
|
|
- }
|
|
|
-
|
|
|
- public function providers()
|
|
|
- {
|
|
|
- return ['oil' => $this->mOilProvider,'phone' => $this->mPhoneProvider];
|
|
|
- }
|
|
|
-
|
|
|
- private function combine_goods($configs,$type)
|
|
|
- {
|
|
|
- $mod_prov = Model('refill_provider');
|
|
|
- $provider_items = $mod_prov->getProviderList(['type' => $type]);
|
|
|
- foreach ($provider_items as $item) {
|
|
|
- $providers[$item['name']] = $item;
|
|
|
- }
|
|
|
- $result = [];
|
|
|
- foreach ($configs as $item)
|
|
|
- {
|
|
|
- if($providers[$item['name']]['opened'] != 1) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- $cfg = $item['cfg'];
|
|
|
-
|
|
|
- $card_types = $cfg['card_type'] ?? [];
|
|
|
- $amounts = $cfg['amount'] ?? [];
|
|
|
-
|
|
|
- foreach ($card_types as $type) {
|
|
|
- if (array_key_exists($type, $result)) {
|
|
|
- $item = $result[$type];
|
|
|
- } else {
|
|
|
- $item = [];
|
|
|
- }
|
|
|
-
|
|
|
- foreach ($amounts as $amount => $val) {
|
|
|
- $item[] = $amount;
|
|
|
- }
|
|
|
- $item = array_unique($item);
|
|
|
- $result[$type] = $item;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return $result;
|
|
|
- }
|
|
|
-
|
|
|
- public function read_channel()
|
|
|
- {
|
|
|
- $refill_provider = Model('refill_provider');
|
|
|
- $items = $refill_provider->getProviderList([]);
|
|
|
-
|
|
|
- $result = [];
|
|
|
- foreach ($items as $item) {
|
|
|
- $name = $item['name'];
|
|
|
- $val = ['type' => intval($item['type']),
|
|
|
- 'opened' => (intval($item['opened']) == 1) ? true : false,
|
|
|
- 'sort' => intval($item['sort'])];
|
|
|
- $result[$name] = $val;
|
|
|
- }
|
|
|
-
|
|
|
- return $result;
|
|
|
- }
|
|
|
-
|
|
|
- protected function load()
|
|
|
- {
|
|
|
- $this->mOilProvider = [];
|
|
|
- $this->mPhoneProvider = [];
|
|
|
- $this->mProviderNames = [];
|
|
|
-
|
|
|
- global $config;
|
|
|
- $oil_configs = $config['oil_providers'];
|
|
|
-
|
|
|
- $cfg_table = $this->read_channel();
|
|
|
- $names = [];
|
|
|
- foreach ($oil_configs as $item)
|
|
|
- {
|
|
|
- $name = $item['name'];
|
|
|
- $cfg = $item['cfg'];
|
|
|
-
|
|
|
- if(!array_key_exists($name,$cfg_table)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- $class = "refill\\{$name}\\RefillOil";
|
|
|
- $table = $cfg_table[$name];
|
|
|
-
|
|
|
- if (class_exists($class, false)) {
|
|
|
- $provider = new $class($cfg);
|
|
|
- $provider->setOpened($table['opened']);
|
|
|
- $provider->setSort($table['sort']);
|
|
|
-
|
|
|
- $names[] = $name;
|
|
|
- $this->mOilProvider[] = $provider;
|
|
|
- } else {
|
|
|
- $error = "Base Error: class {$class} isn't exists!";
|
|
|
- throw new Exception($error);
|
|
|
- }
|
|
|
- } catch (Exception $ex) {
|
|
|
- Log::record($ex->getMessage(), Log::ERR);
|
|
|
- }
|
|
|
- }
|
|
|
+ protected $mPolicy;
|
|
|
|
|
|
- $pho_configs = $config['phone_providers'];
|
|
|
- foreach ($pho_configs as $item)
|
|
|
- {
|
|
|
- $name = $item['name'];
|
|
|
- $cfg = $item['cfg'];
|
|
|
-
|
|
|
- if(!array_key_exists($name,$cfg_table)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- $class = "refill\\{$name}\\RefillPhone";
|
|
|
- $table = $cfg_table[$name];
|
|
|
-
|
|
|
- if (class_exists($class, false)) {
|
|
|
- $provider = new $class($cfg);
|
|
|
- $provider->setOpened($table['opened']);
|
|
|
- $provider->setSort($table['sort']);
|
|
|
- $names[] = $name;
|
|
|
-
|
|
|
- $this->mPhoneProvider[] = $provider;
|
|
|
- } else {
|
|
|
- $error = "Base Error: class {$class} isn't exists!";
|
|
|
- throw new Exception($error);
|
|
|
- }
|
|
|
- } catch (Exception $ex) {
|
|
|
- Log::record($ex->getMessage(), Log::ERR);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $this->mProviderNames = array_unique($names);
|
|
|
- }
|
|
|
-
|
|
|
- public function find_providers(int $amount, int $card_type): array
|
|
|
+ protected $mLimits = [];
|
|
|
+ protected function __construct()
|
|
|
{
|
|
|
- if ($card_type == mtopcard\SinopecCard || $card_type == mtopcard\PetroChinaCard) {
|
|
|
- return $this->find_oil($amount, $card_type);
|
|
|
- } elseif ($card_type == mtopcard\ChinaMobileCard || $card_type == mtopcard\ChinaUnicomCard || $card_type == mtopcard\ChinaTelecomCard) {
|
|
|
- return $this->find_phone($amount, $card_type);
|
|
|
- } else {
|
|
|
- return [];
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
- private function find_oil(int $amount, int $card_type): array
|
|
|
+ public function allow($mchid,$card_type,$amount,$quality)
|
|
|
{
|
|
|
- $providers = [];
|
|
|
- foreach ($this->mOilProvider as $provider) {
|
|
|
- $name = $provider->name();
|
|
|
- [$success, $err] = $provider->check($amount, $card_type);
|
|
|
- if ($success) {
|
|
|
- $providers[] = $provider;
|
|
|
- } else {
|
|
|
- Log::record("{$name} provider cannot match check,err:{$err}", Log::DEBUG);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return $providers;
|
|
|
+ return $this->mPolicy->allow($mchid,$card_type,$amount,$quality);
|
|
|
}
|
|
|
|
|
|
- public function provider(string $chname, int $card_type)
|
|
|
+ public function goods()
|
|
|
{
|
|
|
- if ($card_type == mtopcard\SinopecCard || $card_type == mtopcard\PetroChinaCard) {
|
|
|
- $providers = $this->mOilProvider;
|
|
|
- } elseif ($card_type == mtopcard\ChinaMobileCard || $card_type == mtopcard\ChinaUnicomCard || $card_type == mtopcard\ChinaTelecomCard) {
|
|
|
- $providers = $this->mPhoneProvider;
|
|
|
- } else {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- foreach ($providers as $provider) {
|
|
|
- if ($provider->name() == $chname) {
|
|
|
- return $provider;
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
+ return $this->mPolicy->goods();
|
|
|
}
|
|
|
|
|
|
- private function find_phone(int $amount, int $card_type): array
|
|
|
+ public function providers()
|
|
|
{
|
|
|
- $providers = [];
|
|
|
- foreach ($this->mPhoneProvider as $provider) {
|
|
|
- $name = $provider->name();
|
|
|
- [$success, $err] = $provider->check($amount, $card_type);
|
|
|
- if ($success) {
|
|
|
- $providers[] = $provider;
|
|
|
- } else {
|
|
|
- Log::record("{$name} provider cannot match check,err:{$err}", Log::DEBUG);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return $providers;
|
|
|
+ return $this->mPolicy->providers();
|
|
|
}
|
|
|
|
|
|
public function notify($chname, $input)
|
|
|
{
|
|
|
- try {
|
|
|
- $class_name = "refill\\{$chname}\\RefillCallBack";
|
|
|
- if (class_exists($class_name, false)) {
|
|
|
- $caller = new $class_name();
|
|
|
- } else {
|
|
|
- $error = "Base Error: class {$class_name} isn't exists!";
|
|
|
- throw new Exception($error);
|
|
|
- }
|
|
|
- } catch (Exception $ex) {
|
|
|
- Log::record($ex->getMessage(), Log::ERR);
|
|
|
+ $caller = $this->mPolicy->getCaller($chname);
|
|
|
+ if($caller === false) {
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
- if ($caller->verify($input))
|
|
|
+ elseif ($caller->verify($input))
|
|
|
{
|
|
|
[$order_id, $success, $can_try, $need_handle] = $caller->notify($input);
|
|
|
if (!$need_handle) {
|
|
@@ -311,7 +80,6 @@ class RefillBase
|
|
|
try
|
|
|
{
|
|
|
$mod_refill = Model('refill_order');
|
|
|
-
|
|
|
$trans = new trans_wapper($mod_refill, __METHOD__);
|
|
|
$refill_info = $mod_refill->getOrderInfo(['order_id' => $order_id,'inner_status' => 0]);
|
|
|
if(!empty($refill_info))
|
|
@@ -323,9 +91,7 @@ class RefillBase
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
$trans->commit();
|
|
|
-
|
|
|
}
|
|
|
catch (Exception $ex) {
|
|
|
$trans->rollback();
|
|
@@ -341,81 +107,105 @@ class RefillBase
|
|
|
QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => false]);
|
|
|
} else {
|
|
|
Log::record("系统无此订单ID:{$order_id}", Log::ERR);
|
|
|
-
|
|
|
}
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
Log::record("{$chname} 签名失败.");
|
|
|
}
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
private function retry(array $refill_info, array $order_info)
|
|
|
{
|
|
|
- $checker = function ($refill, $order) {
|
|
|
- $state = intval($order['order_state']);
|
|
|
- if ($state !== ORDER_STATE_SEND) {
|
|
|
- Log::record("retry false:order_state != send", Log::DEBUG);
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- $times = intval($refill['commit_times']);
|
|
|
- if ($times > 15) {
|
|
|
- return false;
|
|
|
- }
|
|
|
+ if($this->mPolicy->can_retry($refill_info,$order_info)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- $period = time() - $refill['order_time'];
|
|
|
- if ($period >= 15 * 60) {
|
|
|
- Log::record("retry false:time > 15m", Log::DEBUG);
|
|
|
- return false;
|
|
|
- }
|
|
|
+ $params = [ 'mchid' => $refill_info['mchid'],
|
|
|
+ 'buyer_id' => $order_info['buyer_id'],
|
|
|
+ 'amount' => $refill_info['refill_amount'],
|
|
|
+ 'card_no' => $refill_info['card_no'],
|
|
|
+ 'quality' => $refill_info['quality'],
|
|
|
+ 'mch_order' => $refill_info['mch_order'],
|
|
|
+ 'notify_url' => $refill_info['notify_url'],
|
|
|
+ 'idcard' => $refill_info['idcard'] ?? '',
|
|
|
+ 'card_name' => $refill_info['card_name'] ?? '',
|
|
|
+ 'order_time' => $refill_info['order_time'],
|
|
|
+ 'commit_times' => $refill_info['commit_times'] + 1
|
|
|
+ ];
|
|
|
+
|
|
|
+ return util::push_add($params);
|
|
|
+ }
|
|
|
|
|
|
- return true;
|
|
|
- };
|
|
|
+ public function zero_order($mchid, $buyer_id, $amount, $card_no,
|
|
|
+ $mch_order, $idcard, $card_name, $notify_url,$quality,
|
|
|
+ $order_time = 0, $commit_times = 0,$errmsg='')
|
|
|
+ {
|
|
|
+ $card_type = mtopcard\card_type($card_no);
|
|
|
+ $minfo = new member_info($buyer_id);
|
|
|
|
|
|
- $can_try = $checker($refill_info, $order_info);
|
|
|
- if (!$can_try) {
|
|
|
- return false;
|
|
|
- }
|
|
|
+ $calc = new ZeroMerchantPrice($mchid, $amount, $card_type);
|
|
|
+ $mch_amount = $calc->calc_vgoods_price([]);
|
|
|
|
|
|
- $mchid = $refill_info['mchid'];
|
|
|
- $buyer_id = $order_info['buyer_id'];
|
|
|
- $amount = $refill_info['refill_amount'];
|
|
|
- $card_no = $refill_info['card_no'];
|
|
|
- $mch_order = $refill_info['mch_order'];
|
|
|
- $notify_url = $refill_info['notify_url'];
|
|
|
- $commit_times = $refill_info['commit_times'] + 1;
|
|
|
- $order_time = $refill_info['order_time'];
|
|
|
+ $input['goods_id'] = ZERO_GOODS_ID;
|
|
|
+ $input['quantity'] = 1; //数量
|
|
|
+ $input['buyer_phone'] = $minfo->mobile();
|
|
|
+ $input['buyer_name'] = $minfo->truename();
|
|
|
+ $input['buyer_msg'] = $_POST['buyer_msg'] ?? '';
|
|
|
+ $input['order_from'] = 1;
|
|
|
+ $input['pd_pay'] = true;
|
|
|
|
|
|
- $idcard = $refill_info['idcard'] ?? '';
|
|
|
- $card_name = $refill_info['card_name'] ?? '';
|
|
|
+ $logic_buy_virtual = Logic('buy_virtual');
|
|
|
+ $result = $logic_buy_virtual->buyStep3($input, $buyer_id, [$calc, 'calc_vorder_amount'], true);
|
|
|
|
|
|
- [$success, $err] = $this->add($mchid, $buyer_id, $amount, $card_no, $mch_order, $idcard, $card_name, $notify_url, $order_time, $commit_times);
|
|
|
- Log::record("retry result:{$success} , err: {$err}", Log::DEBUG);
|
|
|
- return ($success === true);
|
|
|
- }
|
|
|
+ $mod_refill = Model('refill_order');
|
|
|
+ if ($result['state'] === true)
|
|
|
+ {
|
|
|
+ $order_sn = $result['data']['order_sn'];
|
|
|
+ $order_id = $result['data']['order_id'];
|
|
|
|
|
|
- public function push_add($params)
|
|
|
- {
|
|
|
- return queue\DispatcherClient::instance()->push('add',$params);
|
|
|
- }
|
|
|
+ $logic_vr_order = Logic("vr_order");
|
|
|
+ $order_info = Model('vr_order')->getOrderInfo(['order_id' => $order_id]);
|
|
|
+ $logic_vr_order->changeOrderStateCancel($order_info, '', '无法下单创建0元订单');
|
|
|
|
|
|
- public function push_notify($params)
|
|
|
- {
|
|
|
- queue\DispatcherClient::instance()->push('notify',$params);
|
|
|
+ if (empty($mch_order)) {
|
|
|
+ $mch_order = $order_sn;
|
|
|
+ }
|
|
|
+ //虚拟订单表信息扩展
|
|
|
+ $orderext = ['order_id' => $order_id, 'order_sn' => $order_sn, 'mchid' => $mchid,
|
|
|
+ 'refill_amount' => $amount, 'mch_order' => $mch_order,
|
|
|
+ 'idcard' => $idcard, 'card_name' => $card_name,
|
|
|
+ 'notify_url' => $notify_url, 'channel_name' => '',
|
|
|
+ 'mch_amount' => $mch_amount, 'channel_amount' => 0,
|
|
|
+ 'order_time' => $order_time, 'commit_times' => $commit_times,
|
|
|
+ 'card_type' => $card_type, 'card_no' => $card_no,'quality' => $quality,'err_msg' => $errmsg];
|
|
|
+ $mod_refill->add_refill($orderext);
|
|
|
+ return $order_id;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public function push_notify_merchant($params)
|
|
|
+ public function can_nettry($quality,$order_time,$commit_times) : bool
|
|
|
{
|
|
|
- queue\DispatcherClient::instance()->push('notify_mechant',$params);
|
|
|
+ return $this->mPolicy->can_nettry($quality,$order_time,$commit_times);
|
|
|
}
|
|
|
|
|
|
- public function add($mchid, $buyer_id, $amount, $card_no, $mch_order, $idcard, $card_name, $notify_url, $order_time = 0, $commit_times = 0)
|
|
|
+ //$quality,质量
|
|
|
+ //返回值:[ 错误码,错误信息,订单ID,是否是网络错误]
|
|
|
+ //说明:错误码为true 表示成功
|
|
|
+ // 其它情况,则需要判断订单ID
|
|
|
+ public function add($mchid, $buyer_id, $amount, $card_no,
|
|
|
+ $mch_order, $idcard, $card_name, $notify_url,$quality,
|
|
|
+ $order_time, $commit_times)
|
|
|
{
|
|
|
$card_type = mtopcard\card_type($card_no);
|
|
|
- $providers = $this->find_providers($amount, $card_type);
|
|
|
+ $providers = $this->mPolicy->find_providers($amount,$card_type,$quality);
|
|
|
|
|
|
if (empty($providers)) {
|
|
|
- return [202, "找不到合适的充值通道"];
|
|
|
+ return [errcode::CANNOT_MATCH_PROVIDER, "匹配不到合适的充值通道",0,false];
|
|
|
}
|
|
|
|
|
|
if (empty($notify_url)) {
|
|
@@ -425,50 +215,29 @@ class RefillBase
|
|
|
$minfo = new member_info($buyer_id);
|
|
|
$calc = new CalcMerchantPrice($mchid, $amount, $card_type);
|
|
|
$mch_amount = $calc->calc_vgoods_price([]);
|
|
|
+
|
|
|
$available = $minfo->available_predeposit();
|
|
|
if ($mch_amount > $available) {
|
|
|
Log::record("下单时机构余额不足,可用余额为:{$available}", Log::DEBUG);
|
|
|
- return [203, "余额不足"];
|
|
|
- }
|
|
|
-
|
|
|
- if ($order_time === 0) {
|
|
|
- $order_time = time();
|
|
|
+ return [errcode::MERCHANT_SHORT_MONEY, "余额不足支付订单",0,false];
|
|
|
}
|
|
|
|
|
|
- $ascending = function ($l, $r) use ($amount) {
|
|
|
- [$lid, $lprice] = $l->goods($amount);
|
|
|
- [$rid, $rprice] = $r->goods($amount);
|
|
|
-
|
|
|
- $lsort = $l->sort();
|
|
|
- $rsort = $r->sort();
|
|
|
-
|
|
|
- if($lprice == $rprice) {
|
|
|
- return $lsort < $rsort ? -1 : 1;
|
|
|
- }
|
|
|
- else {
|
|
|
- return $lprice < $rprice ? -1 : 1;
|
|
|
- }
|
|
|
- };
|
|
|
- usort($providers, $ascending);
|
|
|
-
|
|
|
$refill_state = false;
|
|
|
+ $order_success = false;
|
|
|
foreach ($providers as $provider)
|
|
|
{
|
|
|
- if(!$provider->opened()) continue;
|
|
|
-
|
|
|
$channel_name = $provider->name();
|
|
|
- [$goods_id, $price] = $provider->goods($amount);
|
|
|
|
|
|
+ //通道价格大于客户价格,换通道.
|
|
|
+ [$goods_id, $price] = $provider->goods($amount);
|
|
|
if ($price > $mch_amount) continue;
|
|
|
|
|
|
$input['goods_id'] = $goods_id;
|
|
|
- $input['quantity'] = 1;
|
|
|
- $input['price'] = $price;
|
|
|
-
|
|
|
+ $input['quantity'] = 1; //数量
|
|
|
$input['buyer_phone'] = $minfo->mobile();
|
|
|
- $input['buyer_name'] = $minfo->truename();
|
|
|
- $input['buyer_msg'] = $_POST['buyer_msg'] ?? '';
|
|
|
- $input['order_from'] = 1;
|
|
|
+ $input['buyer_name'] = $minfo->truename();
|
|
|
+ $input['buyer_msg'] = $_POST['buyer_msg'] ?? '';
|
|
|
+ $input['order_from'] = 1;
|
|
|
$input['pd_pay'] = true;
|
|
|
|
|
|
$logic_buy_virtual = Logic('buy_virtual');
|
|
@@ -497,21 +266,21 @@ class RefillBase
|
|
|
'notify_url' => $notify_url, 'channel_name' => $channel_name,
|
|
|
'mch_amount' => $mch_amount, 'channel_amount' => $price,
|
|
|
'order_time' => $order_time, 'commit_times' => $commit_times,
|
|
|
- 'card_type' => $card_type, 'card_no' => $card_no];
|
|
|
+ 'card_type' => $card_type, 'card_no' => $card_no,'quality' => $quality];
|
|
|
$mod_refill->add_refill($orderext);
|
|
|
} else {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
+ $order_success = true;
|
|
|
+ util::incr_order($channel_name,$card_type,$amount,$quality);
|
|
|
$params = ['order_sn' => $order_sn, 'idcard' => $idcard, 'card_name' => $card_name];
|
|
|
-// [$state, $err] = $provider->add($card_no, $card_type, $amount, $params);
|
|
|
-
|
|
|
- $px = $this->provider('baidu',$card_type);
|
|
|
- [$state, $err] = $px->add($card_no, $card_type, $amount, $params);
|
|
|
+ [$state, $errmsg,$neterr] = $provider->add($card_no, $card_type, $amount, $params);
|
|
|
|
|
|
if ($state)
|
|
|
{
|
|
|
- $trade_no = $err;
|
|
|
+ //提交成功
|
|
|
+ $trade_no = $errmsg;
|
|
|
if ($provider->refill_type() == 'api') {
|
|
|
$logic_vr_order = Logic("vr_order");
|
|
|
$logic_vr_order->changeOrderStateSend($order_id);
|
|
@@ -527,8 +296,10 @@ class RefillBase
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
- } else {
|
|
|
- Log::record("channel:{$channel_name} err:{$err}");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ //提交失败
|
|
|
+ Log::record("channel:{$channel_name} err:{$errmsg}");
|
|
|
$logic_vr_order = Logic("vr_order");
|
|
|
$order_info = Model('vr_order')->getOrderInfo(['order_id' => $order_id]);
|
|
|
$logic_vr_order->changeOrderStateCancel($order_info, '', "调用{$channel_name}接口失败");
|
|
@@ -537,9 +308,13 @@ class RefillBase
|
|
|
}
|
|
|
|
|
|
if ($refill_state) {
|
|
|
- return [true, $order_sn];
|
|
|
- } else {
|
|
|
- return [204, "充值失败."];
|
|
|
+ return [true, '', $order_id,false];
|
|
|
+ }
|
|
|
+ elseif($order_success) {
|
|
|
+ return [errcode::MERCHANT_REFILL_ERROR, "充值失败",$order_id,$neterr];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return [errcode::MERCHANT_REFILL_ERROR, "充值失败",0,false];
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -552,16 +327,6 @@ class RefillBase
|
|
|
return ($api_pay_amount == ncPriceFormat(0.00));
|
|
|
}
|
|
|
|
|
|
- private function is_url($url)
|
|
|
- {
|
|
|
- $checker = function ($haystack, $needle) {
|
|
|
- $length = strlen($needle);
|
|
|
- return (substr($haystack, 0, $length) === $needle);
|
|
|
- };
|
|
|
-
|
|
|
- return $checker($url, "http://") || $checker($url, "https://");
|
|
|
- }
|
|
|
-
|
|
|
public function notify_merchant($order_id,$manual)
|
|
|
{
|
|
|
if ($order_id <= 0) {
|
|
@@ -589,32 +354,19 @@ class RefillBase
|
|
|
return [false, "回调地址为空"];
|
|
|
}
|
|
|
|
|
|
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
$order_state = $order_info['order_state'];
|
|
|
- if ($order_state == ORDER_STATE_CANCEL) {
|
|
|
- $state = "CANCEL";
|
|
|
- } elseif ($order_state == ORDER_STATE_SUCCESS) {
|
|
|
- $state = "SUCCESS";
|
|
|
- } else {
|
|
|
+ if ($order_state !== ORDER_STATE_CANCEL && $order_state !== ORDER_STATE_SUCCESS) {
|
|
|
return [false, "错误的订单状态,不能通知."];
|
|
|
}
|
|
|
+ $resp = $this->mPolicy->notify($order_info,$refill_info);
|
|
|
|
|
|
- $mchid = $refill_info['mchid'];
|
|
|
- $mch_info = Model('merchant')->getMerchantInfo(['mchid' => $mchid]);
|
|
|
-
|
|
|
- [$params, $sign] = $this->body($state, $refill_info, $mch_info);
|
|
|
- $params['sign'] = $sign;
|
|
|
-
|
|
|
- //如果http请求内部,又发出回调自己的请求,在处理进程非动态扩容的情况下,容易造成阻塞.
|
|
|
- if ($this->is_url($notify_url)) {
|
|
|
- $resp = http_request($notify_url, $params, 'POST');
|
|
|
- } else {
|
|
|
- $resp = RBridgeFactory::instance()->notify($notify_url, $params);
|
|
|
- }
|
|
|
-
|
|
|
- if ($resp == "SUCCESS") {
|
|
|
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
+ if ($resp) {
|
|
|
$refill_order->edit($order_id, ['mch_notify_state' => 1, 'mch_notify_times' => ['exp', 'mch_notify_times+1']]);
|
|
|
return [true, ""];
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
$refill_order->edit($order_id, ['mch_notify_times' => ['exp', 'mch_notify_times+1']]);
|
|
|
$times = $refill_info['mch_notify_times'] + 1;
|
|
|
|
|
@@ -625,6 +377,7 @@ class RefillBase
|
|
|
$period = intval(pow(2, $N));
|
|
|
QueueClient::async_push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => false], $period);
|
|
|
}
|
|
|
+
|
|
|
return [false, "通知{$times}次,失败."];
|
|
|
}
|
|
|
}
|
|
@@ -637,7 +390,7 @@ class RefillBase
|
|
|
$chname = $refill_info['channel_name'];
|
|
|
$card_type = intval($refill_info['card_type']);
|
|
|
|
|
|
- $provider = $this->provider($chname, $card_type);
|
|
|
+ $provider = $this->mPolicy->provider($chname, $card_type);
|
|
|
[$state, $order_state] = $provider->query($refill_info);
|
|
|
|
|
|
if ($state === true)
|
|
@@ -673,58 +426,4 @@ class RefillBase
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- private function body($state, $refill_info, $mch_info)
|
|
|
- {
|
|
|
- $params = [
|
|
|
- "mchid" => $refill_info['mchid'],
|
|
|
- "order_sn" => $refill_info['mch_order'],
|
|
|
- "amount" => $refill_info['refill_amount'],//intval($refill_info['refill_amount'] + 0.05),
|
|
|
- "cardno" => $refill_info['card_no'],
|
|
|
- "trade_no" => $refill_info['order_sn'],
|
|
|
- "idcard" => $refill_info['idcard'] ?? "",
|
|
|
- "card_name" => $refill_info['card_name'] ?? "",
|
|
|
- 'official_sn' => $refill_info['official_sn'] ?? "",
|
|
|
- 'message' => $refill_info['err_msg'] ?? "",
|
|
|
- "state" => $state];
|
|
|
-
|
|
|
- $secure_key = $mch_info['secure_key'];
|
|
|
- $sign = $this->sign($params, $secure_key);
|
|
|
-
|
|
|
- return [$params, $sign];
|
|
|
- }
|
|
|
-
|
|
|
- private function sign($params, $key)
|
|
|
- {
|
|
|
- ksort($params);
|
|
|
-
|
|
|
- $body = "";
|
|
|
- $i = 0;
|
|
|
- foreach ($params as $k => $v) {
|
|
|
- if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) {
|
|
|
- if ($i == 0) {
|
|
|
- $body .= "{$k}" . "=" . urlencode($v);
|
|
|
- } else {
|
|
|
- $body .= "&" . "{$k}" . "=" . urlencode($v);
|
|
|
- }
|
|
|
- $i++;
|
|
|
- }
|
|
|
- }
|
|
|
- $body .= "&key={$key}";
|
|
|
- Log::record("notify body={$body}",Log::DEBUG);
|
|
|
-
|
|
|
- return md5($body);
|
|
|
- }
|
|
|
-
|
|
|
- private function check_empty($value)
|
|
|
- {
|
|
|
- if (!isset($value))
|
|
|
- return true;
|
|
|
- if ($value === null)
|
|
|
- return true;
|
|
|
- if (trim($value) === "")
|
|
|
- return true;
|
|
|
-
|
|
|
- return false;
|
|
|
- }
|
|
|
}
|