|
@@ -14,16 +14,57 @@ class refillControl extends merchantControl
|
|
|
parent::__construct();
|
|
|
}
|
|
|
|
|
|
+ private function check_params($params)
|
|
|
+ {
|
|
|
+ if(empty($params['cardno'])) {
|
|
|
+ return [false,'参数没有包含cardno'];
|
|
|
+ }
|
|
|
+ if(empty($params['amount'])) {
|
|
|
+ return [false,'参数没有包含充值金额:amount'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $card_no = $_GET['cardno'];
|
|
|
+ $oil_type = mtopcard\oil_type($card_no);
|
|
|
+
|
|
|
+ if($oil_type == mtopcard\UnknownCard) {
|
|
|
+ return [false,"充值卡不是中石油也不是中石化"];
|
|
|
+ }
|
|
|
+
|
|
|
+ if($oil_type === mtopcard\PetroChinaCard)
|
|
|
+ {
|
|
|
+ if(empty($params['idcard'])) {
|
|
|
+ return [false,'中石油需要参数没有包含身份证号码:idcard'];
|
|
|
+ }
|
|
|
+ if(empty($params['card_name'])) {
|
|
|
+ return [false,'参数没有包含身份证姓名:card_name'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($params['notifyurl'])) {
|
|
|
+ return [false,'参数没有包含notifyurl'];
|
|
|
+ }
|
|
|
+ if(empty($params['order_sn'])) {
|
|
|
+ return [false,'参数没有包含贵方唯一订单号:order_sn'];
|
|
|
+ }
|
|
|
+ return [true,""];
|
|
|
+ }
|
|
|
+
|
|
|
public function addoilOp()
|
|
|
{
|
|
|
+ [$success,$error] = $this->check_params($_GET);
|
|
|
+ if($success === false) {
|
|
|
+ return self::outerr(201,$error);
|
|
|
+ }
|
|
|
+
|
|
|
$amount = intval($_GET['amount']);
|
|
|
$card_no = $_GET['cardno'];
|
|
|
$oil_type = mtopcard\oil_type($card_no);
|
|
|
- $notify_url = $_GET['notify_url'];
|
|
|
+ $notify_url = $_GET['notifyurl'];
|
|
|
+ $mch_order = $_GET['order_sn']; //对方的order
|
|
|
|
|
|
$providers = refill\RefillFactory::instance()->find_oil($amount,$oil_type);
|
|
|
if(empty($providers)) {
|
|
|
- return self::outerr(201,"找不到合适的充值通道");
|
|
|
+ return self::outerr(202,"找不到合适的充值通道");
|
|
|
}
|
|
|
|
|
|
$buyer_id = $this->adminid();
|
|
@@ -32,7 +73,7 @@ class refillControl extends merchantControl
|
|
|
$calc = new refill\CalcMerchantPrice($this->mchid(),$amount);
|
|
|
$mch_amount = $calc->calc_vgoods_price([]);
|
|
|
if($mch_amount > $minfo->available_predeposit()) {
|
|
|
- return self::outerr(202,"余额不足");
|
|
|
+ return self::outerr(203,"余额不足");
|
|
|
}
|
|
|
|
|
|
$refill_state = false;
|
|
@@ -61,23 +102,18 @@ class refillControl extends merchantControl
|
|
|
$order_id = $result['data']['order_id'];
|
|
|
//虚拟订单表信息扩展
|
|
|
$orderext = ['order_id' => $order_id,'order_sn' => $order_sn,'mchid' => $this->mchid(),
|
|
|
+ 'refill_amount' => $amount,'mch_order' => $mch_order,
|
|
|
'notify_url' => $notify_url,'channel_name' => $channel_name,
|
|
|
'mch_amount' => $mch_amount,'channel_amount' => $price,'order_time' => time(),
|
|
|
'card_type' => $oil_type,'card_no' => $card_no];
|
|
|
- $ret = $mod_refill->add_refill($orderext);
|
|
|
-
|
|
|
- if($ret) {
|
|
|
-
|
|
|
- }
|
|
|
- else {
|
|
|
- Log::record("Create Refill Order Error",Log::ERR);
|
|
|
- }
|
|
|
+ $mod_refill->add_refill($orderext);
|
|
|
}
|
|
|
else {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- [$state,$err] = $provider->add($card_no,$oil_type,$amount,$input);
|
|
|
+ $params = ['order_sn' => $order_sn];
|
|
|
+ [$state,$err] = $provider->add($card_no,$oil_type,$amount,$params);
|
|
|
if($state) {
|
|
|
$trade_no = $err;
|
|
|
$logic_vr_order = Logic("vr_order");
|
|
@@ -85,17 +121,20 @@ class refillControl extends merchantControl
|
|
|
$data = ['commit_time' => time(),'ch_trade_no' => $trade_no];
|
|
|
$mod_refill->edit($order_id,$data);
|
|
|
$refill_state = true;
|
|
|
+ break;
|
|
|
}
|
|
|
else {
|
|
|
+ Log::record("channel:{$channel_name} err:{$err}");
|
|
|
$logic_vr_order = Logic("vr_order");
|
|
|
$order_info = Model('vr_order')->getOrderInfo(['order_id' => $order_id]);
|
|
|
$logic_vr_order->changeOrderStateCancel($order_info,'',"调用{$channel_name}接口失败");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
if($refill_state) {
|
|
|
- return self::outsuccess(['state' => true]);
|
|
|
+ return self::outsuccess(['state' => true,'trade_no' => $order_sn]);
|
|
|
} else {
|
|
|
- return self::outerr(203,"充值失败.");
|
|
|
+ return self::outerr(204,"充值失败.");
|
|
|
}
|
|
|
}
|
|
|
|