|
@@ -1,329 +1,329 @@
|
|
|
-<?php
|
|
|
-
|
|
|
-require_once(BASE_ROOT_PATH . '/mobile/control/merchant.php');
|
|
|
-require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
|
|
|
-require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
|
|
|
-require_once(BASE_HELPER_PATH . '/model/member_info.php');
|
|
|
-
|
|
|
-
|
|
|
-//商家充值接口中心
|
|
|
-class refillControl extends merchantControl
|
|
|
-{
|
|
|
- public function __construct()
|
|
|
- {
|
|
|
- parent::__construct();
|
|
|
- }
|
|
|
-
|
|
|
- public function goodsOp()
|
|
|
- {
|
|
|
- $goods_list = refill\RefillFactory::instance()->goods();
|
|
|
-
|
|
|
- $sorter = function (array $items) {
|
|
|
- $ret = [];
|
|
|
- foreach ($items as $key => $val) {
|
|
|
- sort($val);
|
|
|
- $ret[$key] = $val;
|
|
|
- }
|
|
|
- return $ret;
|
|
|
- };
|
|
|
-
|
|
|
- $goods_list = $sorter($goods_list);
|
|
|
-
|
|
|
- $result = [];
|
|
|
- foreach ($goods_list as $card_type => $value) {
|
|
|
- $key = mtopcard\scard_type($card_type);
|
|
|
- $result[$key] = $value;
|
|
|
- }
|
|
|
-
|
|
|
- return self::outsuccess($result);
|
|
|
- }
|
|
|
-
|
|
|
- private function check_params($params)
|
|
|
- {
|
|
|
- if(empty($params['cardno'])) {
|
|
|
- return [false,'参数没有包含cardno'];
|
|
|
- }
|
|
|
- if(empty($params['amount'])) {
|
|
|
- return [false,'参数没有包含充值金额:amount'];
|
|
|
- }
|
|
|
-
|
|
|
- $card_no = $_GET['cardno'];
|
|
|
- $card_type = mtopcard\simple_card_type($card_no);
|
|
|
- if($card_type == mtopcard\UnknownCard) {
|
|
|
- return [false,'卡类型无法识别'];
|
|
|
- }
|
|
|
-
|
|
|
- if(empty($params['notifyurl'])) {
|
|
|
- return [false,'参数没有包含notifyurl'];
|
|
|
- }
|
|
|
- if(empty($params['order_sn'])) {
|
|
|
- return [false,'参数没有包含贵方唯一订单号:order_sn'];
|
|
|
- }
|
|
|
-
|
|
|
- return [true,""];
|
|
|
- }
|
|
|
-
|
|
|
- public function addOp()
|
|
|
- {
|
|
|
- [$success,$error] = $this->check_params($_GET);
|
|
|
- if($success === false) {
|
|
|
- return self::outerr(201,$error);
|
|
|
- }
|
|
|
-
|
|
|
- $amount = intval($_GET['amount']);
|
|
|
- $card_no = $_GET['cardno'];
|
|
|
- $notify_url = $_GET['notifyurl'];
|
|
|
- $mch_order = $_GET['order_sn']; //对方的order编号
|
|
|
- $quality = $_GET['quality'] ?? 0;
|
|
|
-
|
|
|
- if(!$this->check_mchorder($this->mchid(),$mch_order)) {
|
|
|
- return self::outerr(205,"客户订单号重复或者为空.");
|
|
|
- }
|
|
|
-
|
|
|
- $card_type = mtopcard\simple_card_type($card_no);
|
|
|
- if($card_type === mtopcard\SinopecCard || $card_type === mtopcard\PetroChinaCard)
|
|
|
- {
|
|
|
- if(!$this->can_refill($card_no)) {
|
|
|
- return self::outerr(206,"平台不支持该卡充值.");
|
|
|
- }
|
|
|
-
|
|
|
-// $allow = refill\RefillFactory::instance()->allow($this->mchid(),$card_type,$amount,$quality);
|
|
|
- $allow = true;
|
|
|
- if(!$allow)
|
|
|
- {
|
|
|
- if ($card_type === mtopcard\SinopecCard) {
|
|
|
- $text = "中石化";
|
|
|
- }
|
|
|
- else {
|
|
|
- $text = "中石油";
|
|
|
- }
|
|
|
- return self::outerr(207,"今日贵司{$amount}{$text}充值库存已经用完.");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $params = ['mchid' => $this->mchid(),
|
|
|
- 'buyer_id' => $this->adminid(),
|
|
|
- 'amount' => $amount,
|
|
|
- 'card_no' => $card_no,
|
|
|
- 'mch_order' => $mch_order,
|
|
|
- 'notify_url' => $notify_url,
|
|
|
- 'org_quality' => $quality,
|
|
|
- 'order_time' => time()
|
|
|
- ];
|
|
|
-
|
|
|
- refill\util::push_queue_order($this->mchid(),$mch_order,ORDER_STATE_QUEUE);
|
|
|
- Model('refill_order')->add_detail($this->mchid(),$mch_order,$params,ORDER_STATE_QUEUE);
|
|
|
-
|
|
|
- [$can_refill, $period] = refill\util::can_commit($card_no, $card_type);
|
|
|
- if ($can_refill === false) {
|
|
|
- $state = refill\util::async_add($params, $period);
|
|
|
- } else {
|
|
|
- $state = refill\util::push_add($params);
|
|
|
- }
|
|
|
-
|
|
|
- $mchid = $this->mchid();
|
|
|
- if ($state === true) {
|
|
|
- Log::record("refill::util::push_add success mchid={$mchid} mch_order={$mch_order} state={$state}",Log::DEBUG);
|
|
|
- return self::outsuccess(['state' => true]);
|
|
|
- } else {
|
|
|
- refill\util::del_queue_order($this->mchid(),$mch_order);
|
|
|
- Model('refill_order')->del_detail($this->mchid(),$mch_order);
|
|
|
- Log::record("refill::util::push_add error mchid={$mchid} mch_order={$mch_order} state={$state}",Log::DEBUG);
|
|
|
- return self::outerr(208, '提交失败');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private function check_third($params)
|
|
|
- {
|
|
|
- if(empty($params['product_code'])) {
|
|
|
- return [false,'参数没有包含product_code'];
|
|
|
- }
|
|
|
-
|
|
|
- $pcode = $params['product_code'];
|
|
|
- if($this->check_pcode($pcode) == false) {
|
|
|
- return [false,"对应的产品编码{$pcode}"];
|
|
|
- }
|
|
|
-
|
|
|
- if(empty($params['quantity']) || intval($params['quantity']) < 1) {
|
|
|
- return [false,"购买数量参数不存在,或者小于0"];
|
|
|
- }
|
|
|
-
|
|
|
- if(empty($params['notifyurl'])) {
|
|
|
- return [false,'参数没有包含notifyurl'];
|
|
|
- }
|
|
|
- if(empty($params['order_sn'])) {
|
|
|
- return [false,'参数没有包含贵方唯一订单号:order_sn'];
|
|
|
- }
|
|
|
-
|
|
|
- return [true,""];
|
|
|
- }
|
|
|
-
|
|
|
- private function check_pcode($pcode)
|
|
|
- {
|
|
|
- $mod_third = Model('thrid_refill');
|
|
|
- $product = $mod_third->getProduct(['system_code' => $pcode]);
|
|
|
- return !empty($product);
|
|
|
- }
|
|
|
-
|
|
|
- public function add_thirdOp()
|
|
|
- {
|
|
|
- [$success,$error] = $this->check_third($_GET);
|
|
|
- if($success === false) {
|
|
|
- return self::outerr(201,$error);
|
|
|
- }
|
|
|
-
|
|
|
- $amount = refill\util::ThirdRefillAmount;
|
|
|
- $notify_url = $_GET['notifyurl'];
|
|
|
- $mch_order = $_GET['order_sn']; //对方的order编号
|
|
|
-
|
|
|
- $product_code = $_GET['product_code'];
|
|
|
- $card_no = $_GET['cardno'] ?? '';
|
|
|
- $quantity = $_GET['quantity'];
|
|
|
- $third_card_type = $_GET['card_type'] ?? 1;
|
|
|
-
|
|
|
- //三方充值没有质量
|
|
|
- $quality = 1;
|
|
|
- $card_type = mtopcard\ThirdRefillCard;
|
|
|
-
|
|
|
- if(!$this->check_mchorder($this->mchid(),$mch_order)) {
|
|
|
- return self::outerr(205,"客户订单号重复或者为空.");
|
|
|
- }
|
|
|
-
|
|
|
- $params = ['mchid' => $this->mchid(),
|
|
|
- 'buyer_id' => $this->adminid(),
|
|
|
- 'amount' => $amount,
|
|
|
- 'mch_order' => $mch_order,
|
|
|
- 'notify_url' => $notify_url,
|
|
|
- 'org_quality' => $quality,
|
|
|
- 'card_type' => $card_type,
|
|
|
- 'card_no' => $card_no,
|
|
|
- 'product_code' => $product_code,
|
|
|
- 'quantity' => $quantity,
|
|
|
- 'third_card_type' => $third_card_type
|
|
|
- ];
|
|
|
-
|
|
|
- refill\util::push_queue_order($this->mchid(),$mch_order,ORDER_STATE_QUEUE);
|
|
|
- Model('refill_order')->add_detail($this->mchid(),$mch_order,$params,ORDER_STATE_QUEUE);
|
|
|
-
|
|
|
- $state = refill\util::push_addthird($params);
|
|
|
- if ($state === true) {
|
|
|
- return self::outsuccess(['state' => true]);
|
|
|
- } else {
|
|
|
- refill\util::del_queue_order($this->mchid(),$mch_order);
|
|
|
- Model('refill_order')->del_detail($this->mchid(),$mch_order);
|
|
|
- return self::outerr(208, '提交失败');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private function can_refill($cardno)
|
|
|
- {
|
|
|
- $card_info = refill\util::read_card($cardno);
|
|
|
- if(empty($card_info)) return false;
|
|
|
-
|
|
|
- return intval($card_info['black_card']) === 0;
|
|
|
- }
|
|
|
-
|
|
|
- private function check_mchorder($mchid,$mch_order)
|
|
|
- {
|
|
|
- if (empty($mch_order)) {
|
|
|
- return false;
|
|
|
- } else {
|
|
|
- $refill_order = Model('refill_order');
|
|
|
- $ret = $refill_order->exist($mchid, $mch_order);
|
|
|
- return ($ret == false);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public function balanceOp()
|
|
|
- {
|
|
|
- $uid = $this->adminid();
|
|
|
- $minfo = new member_info($uid);
|
|
|
- $available = $minfo->available_predeposit();
|
|
|
- return self::outsuccess(['balance' => $available]);
|
|
|
- }
|
|
|
-
|
|
|
- public function query_tradeOp()
|
|
|
- {
|
|
|
- $mchid = $this->mchid();
|
|
|
- $trade_no = $_GET['trade_no'];
|
|
|
- if(empty($trade_no)) {
|
|
|
- return self::outerr(201,"交易号trade_no错误");
|
|
|
- }
|
|
|
-
|
|
|
- $mod_refill = Model('refill_order');
|
|
|
- $refill_info = $mod_refill->getOrderInfo(['order_sn' => $trade_no,'mchid' => $mchid]);
|
|
|
-
|
|
|
- $vr_order = Model('vr_order');
|
|
|
- $order_info = $vr_order->getOrderInfo(['order_sn' => $trade_no]);
|
|
|
-
|
|
|
- if(empty($refill_info) || empty($order_info)) {
|
|
|
- return self::outerr(201,"无此交易号");
|
|
|
- }
|
|
|
-
|
|
|
- $result = $this->format($order_info,$refill_info);
|
|
|
-
|
|
|
- return self::outsuccess($result);
|
|
|
- }
|
|
|
-
|
|
|
- private function format($order_info,$refill_info)
|
|
|
- {
|
|
|
- $result = [];
|
|
|
- $result['mchid'] = $refill_info['mchid'];
|
|
|
- $result['trade_no'] = $refill_info['order_sn'];
|
|
|
- $result['order_sn'] = $refill_info['mch_order'];
|
|
|
- $result['card_no'] = $refill_info['card_no'];
|
|
|
- $result['card_type'] = $refill_info['card_type'];
|
|
|
- $result['refill_amount'] = $refill_info['refill_amount'];
|
|
|
- $result['order_amount'] = $refill_info['mch_amount'];
|
|
|
- $result['order_time'] = $refill_info['order_time'];
|
|
|
- $result['success_time'] = $refill_info['notify_time'];
|
|
|
- $result['official_sn'] = $refill_info['official_sn'] ?? "";
|
|
|
- $result['order_state'] = $order_info['order_state'];
|
|
|
-
|
|
|
- return $result;
|
|
|
- }
|
|
|
-
|
|
|
- public function queryOp()
|
|
|
- {
|
|
|
- $mchid = $this->mchid();
|
|
|
- $order_sn = $_GET['order_sn']; //用户方的订单号,对应数据库中的mch_order
|
|
|
-
|
|
|
- if(empty($order_sn)) {
|
|
|
- return self::outerr(201,"客户订单号order_sn错误");
|
|
|
- }
|
|
|
-
|
|
|
- $order_state = refill\util::query_queue_order($mchid,$order_sn);
|
|
|
- if ($order_state == ORDER_STATE_QUEUE || $order_state == ORDER_STATE_SEND) {
|
|
|
- Log::record("query_state in queue mchid={$mchid} mch_order={$order_sn} order_state={$order_state}" ,Log::DEBUG);
|
|
|
- $result['mchid'] = $mchid;
|
|
|
- $result['order_sn'] = $order_sn;
|
|
|
- $result['order_state'] = $order_state;
|
|
|
- return self::outsuccess($result);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- $mod_refill = Model('refill_order');
|
|
|
- $refill_info = $mod_refill->getOrderInfo(['mch_order' => $order_sn,'mchid' => $mchid,'inner_status' => 0]);
|
|
|
-
|
|
|
- if(empty($refill_info))
|
|
|
- {
|
|
|
- Log::record("query_state in db no order mchid={$mchid} mch_order={$order_sn}" ,Log::DEBUG);
|
|
|
- return self::outerr(202, "无此订单");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- $vr_order = Model('vr_order');
|
|
|
- $order_info = $vr_order->getOrderInfo(['order_sn' => $refill_info['order_sn']]);
|
|
|
- Log::record("query_state in db mchid={$mchid} mch_order={$order_sn} order_state={$order_info['order_state']}" ,Log::DEBUG);
|
|
|
-
|
|
|
- if (empty($order_info)) {
|
|
|
- return self::outerr(203, "无此交易号");
|
|
|
- } else {
|
|
|
- $result = $this->format($order_info, $refill_info);
|
|
|
- return self::outsuccess($result);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+<?php
|
|
|
+
|
|
|
+require_once(BASE_ROOT_PATH . '/mobile/control/merchant.php');
|
|
|
+require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
|
|
|
+require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
|
|
|
+require_once(BASE_HELPER_PATH . '/model/member_info.php');
|
|
|
+
|
|
|
+
|
|
|
+//商家充值接口中心
|
|
|
+class refillControl extends merchantControl
|
|
|
+{
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ parent::__construct();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function goodsOp()
|
|
|
+ {
|
|
|
+ $goods_list = refill\RefillFactory::instance()->goods();
|
|
|
+
|
|
|
+ $sorter = function (array $items) {
|
|
|
+ $ret = [];
|
|
|
+ foreach ($items as $key => $val) {
|
|
|
+ sort($val);
|
|
|
+ $ret[$key] = $val;
|
|
|
+ }
|
|
|
+ return $ret;
|
|
|
+ };
|
|
|
+
|
|
|
+ $goods_list = $sorter($goods_list);
|
|
|
+
|
|
|
+ $result = [];
|
|
|
+ foreach ($goods_list as $card_type => $value) {
|
|
|
+ $key = mtopcard\scard_type($card_type);
|
|
|
+ $result[$key] = $value;
|
|
|
+ }
|
|
|
+
|
|
|
+ return self::outsuccess($result);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function check_params($params)
|
|
|
+ {
|
|
|
+ if(empty($params['cardno'])) {
|
|
|
+ return [false,'参数没有包含cardno'];
|
|
|
+ }
|
|
|
+ if(empty($params['amount'])) {
|
|
|
+ return [false,'参数没有包含充值金额:amount'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $card_no = $_GET['cardno'];
|
|
|
+ $card_type = mtopcard\simple_card_type($card_no);
|
|
|
+ if($card_type == mtopcard\UnknownCard) {
|
|
|
+ return [false,'卡类型无法识别'];
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($params['notifyurl'])) {
|
|
|
+ return [false,'参数没有包含notifyurl'];
|
|
|
+ }
|
|
|
+ if(empty($params['order_sn'])) {
|
|
|
+ return [false,'参数没有包含贵方唯一订单号:order_sn'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true,""];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function addOp()
|
|
|
+ {
|
|
|
+ [$success,$error] = $this->check_params($_GET);
|
|
|
+ if($success === false) {
|
|
|
+ return self::outerr(201,$error);
|
|
|
+ }
|
|
|
+
|
|
|
+ $amount = intval($_GET['amount']);
|
|
|
+ $card_no = $_GET['cardno'];
|
|
|
+ $notify_url = $_GET['notifyurl'];
|
|
|
+ $mch_order = $_GET['order_sn']; //对方的order编号
|
|
|
+ $quality = $_GET['quality'] ?? 0;
|
|
|
+
|
|
|
+ if(!$this->check_mchorder($this->mchid(),$mch_order)) {
|
|
|
+ return self::outerr(205,"客户订单号重复或者为空.");
|
|
|
+ }
|
|
|
+
|
|
|
+ $card_type = mtopcard\simple_card_type($card_no);
|
|
|
+ if($card_type === mtopcard\SinopecCard || $card_type === mtopcard\PetroChinaCard)
|
|
|
+ {
|
|
|
+ if(!$this->can_refill($card_no)) {
|
|
|
+ return self::outerr(206,"平台不支持该卡充值.");
|
|
|
+ }
|
|
|
+
|
|
|
+// $allow = refill\RefillFactory::instance()->allow($this->mchid(),$card_type,$amount,$quality);
|
|
|
+ $allow = true;
|
|
|
+ if(!$allow)
|
|
|
+ {
|
|
|
+ if ($card_type === mtopcard\SinopecCard) {
|
|
|
+ $text = "中石化";
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $text = "中石油";
|
|
|
+ }
|
|
|
+ return self::outerr(207,"今日贵司{$amount}{$text}充值库存已经用完.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $params = ['mchid' => $this->mchid(),
|
|
|
+ 'buyer_id' => $this->adminid(),
|
|
|
+ 'amount' => $amount,
|
|
|
+ 'card_no' => $card_no,
|
|
|
+ 'mch_order' => $mch_order,
|
|
|
+ 'notify_url' => $notify_url,
|
|
|
+ 'org_quality' => $quality,
|
|
|
+ 'order_time' => time()
|
|
|
+ ];
|
|
|
+
|
|
|
+ refill\util::push_queue_order($this->mchid(),$mch_order,ORDER_STATE_QUEUE);
|
|
|
+ Model('refill_order')->add_detail($this->mchid(),$mch_order,$params,ORDER_STATE_QUEUE);
|
|
|
+
|
|
|
+ [$can_refill, $period] = refill\util::can_commit($card_no, $card_type);
|
|
|
+ if ($can_refill === false) {
|
|
|
+ $state = refill\util::async_add($params, $period);
|
|
|
+ } else {
|
|
|
+ $state = refill\util::push_add($params);
|
|
|
+ }
|
|
|
+
|
|
|
+ $mchid = $this->mchid();
|
|
|
+ if ($state === true) {
|
|
|
+ Log::record("refill::util::push_add success mchid={$mchid} mch_order={$mch_order} state={$state}",Log::DEBUG);
|
|
|
+ return self::outsuccess(['state' => true]);
|
|
|
+ } else {
|
|
|
+ refill\util::del_queue_order($this->mchid(),$mch_order);
|
|
|
+ Model('refill_order')->del_detail($this->mchid(),$mch_order);
|
|
|
+ Log::record("refill::util::push_add error mchid={$mchid} mch_order={$mch_order} state={$state}",Log::DEBUG);
|
|
|
+ return self::outerr(208, '提交失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function check_third($params)
|
|
|
+ {
|
|
|
+ if(empty($params['product_code'])) {
|
|
|
+ return [false,'参数没有包含product_code'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $pcode = $params['product_code'];
|
|
|
+ if($this->check_pcode($pcode) == false) {
|
|
|
+ return [false,"对应的产品编码{$pcode}"];
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($params['quantity']) || intval($params['quantity']) < 1) {
|
|
|
+ return [false,"购买数量参数不存在,或者小于0"];
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($params['notifyurl'])) {
|
|
|
+ return [false,'参数没有包含notifyurl'];
|
|
|
+ }
|
|
|
+ if(empty($params['order_sn'])) {
|
|
|
+ return [false,'参数没有包含贵方唯一订单号:order_sn'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true,""];
|
|
|
+ }
|
|
|
+
|
|
|
+ private function check_pcode($pcode)
|
|
|
+ {
|
|
|
+ $mod_third = Model('thrid_refill');
|
|
|
+ $product = $mod_third->getProduct(['system_code' => $pcode]);
|
|
|
+ return !empty($product);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function add_thirdOp()
|
|
|
+ {
|
|
|
+ [$success,$error] = $this->check_third($_GET);
|
|
|
+ if($success === false) {
|
|
|
+ return self::outerr(201,$error);
|
|
|
+ }
|
|
|
+
|
|
|
+ $amount = refill\util::ThirdRefillAmount;
|
|
|
+ $notify_url = $_GET['notifyurl'];
|
|
|
+ $mch_order = $_GET['order_sn']; //对方的order编号
|
|
|
+
|
|
|
+ $product_code = $_GET['product_code'];
|
|
|
+ $card_no = $_GET['cardno'] ?? '';
|
|
|
+ $quantity = $_GET['quantity'];
|
|
|
+ $third_card_type = $_GET['card_type'] ?? 1;
|
|
|
+
|
|
|
+ //三方充值没有质量
|
|
|
+ $quality = 1;
|
|
|
+ $card_type = mtopcard\ThirdRefillCard;
|
|
|
+
|
|
|
+ if(!$this->check_mchorder($this->mchid(),$mch_order)) {
|
|
|
+ return self::outerr(205,"客户订单号重复或者为空.");
|
|
|
+ }
|
|
|
+
|
|
|
+ $params = ['mchid' => $this->mchid(),
|
|
|
+ 'buyer_id' => $this->adminid(),
|
|
|
+ 'amount' => $amount,
|
|
|
+ 'mch_order' => $mch_order,
|
|
|
+ 'notify_url' => $notify_url,
|
|
|
+ 'org_quality' => $quality,
|
|
|
+ 'card_type' => $card_type,
|
|
|
+ 'card_no' => $card_no,
|
|
|
+ 'product_code' => $product_code,
|
|
|
+ 'quantity' => $quantity,
|
|
|
+ 'third_card_type' => $third_card_type
|
|
|
+ ];
|
|
|
+
|
|
|
+ refill\util::push_queue_order($this->mchid(),$mch_order,ORDER_STATE_QUEUE);
|
|
|
+ Model('refill_order')->add_detail($this->mchid(),$mch_order,$params,ORDER_STATE_QUEUE);
|
|
|
+
|
|
|
+ $state = refill\util::push_addthird($params);
|
|
|
+ if ($state === true) {
|
|
|
+ return self::outsuccess(['state' => true]);
|
|
|
+ } else {
|
|
|
+ refill\util::del_queue_order($this->mchid(),$mch_order);
|
|
|
+ Model('refill_order')->del_detail($this->mchid(),$mch_order);
|
|
|
+ return self::outerr(208, '提交失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private function can_refill($cardno)
|
|
|
+ {
|
|
|
+ $card_info = refill\util::read_card($cardno);
|
|
|
+ if(empty($card_info)) return false;
|
|
|
+
|
|
|
+ return intval($card_info['black_card']) === 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function check_mchorder($mchid,$mch_order)
|
|
|
+ {
|
|
|
+ if (empty($mch_order)) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ $refill_order = Model('refill_order');
|
|
|
+ $ret = $refill_order->exist($mchid, $mch_order);
|
|
|
+ return ($ret == false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function balanceOp()
|
|
|
+ {
|
|
|
+ $uid = $this->adminid();
|
|
|
+ $minfo = new member_info($uid);
|
|
|
+ $available = $minfo->available_predeposit();
|
|
|
+ return self::outsuccess(['balance' => $available]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function query_tradeOp()
|
|
|
+ {
|
|
|
+ $mchid = $this->mchid();
|
|
|
+ $trade_no = $_GET['trade_no'];
|
|
|
+ if(empty($trade_no)) {
|
|
|
+ return self::outerr(201,"交易号trade_no错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ $mod_refill = Model('refill_order');
|
|
|
+ $refill_info = $mod_refill->getOrderInfo(['order_sn' => $trade_no,'mchid' => $mchid]);
|
|
|
+
|
|
|
+ $vr_order = Model('vr_order');
|
|
|
+ $order_info = $vr_order->getOrderInfo(['order_sn' => $trade_no]);
|
|
|
+
|
|
|
+ if(empty($refill_info) || empty($order_info)) {
|
|
|
+ return self::outerr(201,"无此交易号");
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = $this->format($order_info,$refill_info);
|
|
|
+
|
|
|
+ return self::outsuccess($result);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function format($order_info,$refill_info)
|
|
|
+ {
|
|
|
+ $result = [];
|
|
|
+ $result['mchid'] = $refill_info['mchid'];
|
|
|
+ $result['trade_no'] = $refill_info['order_sn'];
|
|
|
+ $result['order_sn'] = $refill_info['mch_order'];
|
|
|
+ $result['card_no'] = $refill_info['card_no'];
|
|
|
+ $result['card_type'] = $refill_info['card_type'];
|
|
|
+ $result['refill_amount'] = $refill_info['refill_amount'];
|
|
|
+ $result['order_amount'] = $refill_info['mch_amount'];
|
|
|
+ $result['order_time'] = $refill_info['order_time'];
|
|
|
+ $result['success_time'] = $refill_info['notify_time'];
|
|
|
+ $result['official_sn'] = $refill_info['official_sn'] ?? "";
|
|
|
+ $result['order_state'] = $order_info['order_state'];
|
|
|
+
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function queryOp()
|
|
|
+ {
|
|
|
+ $mchid = $this->mchid();
|
|
|
+ $order_sn = $_GET['order_sn']; //用户方的订单号,对应数据库中的mch_order
|
|
|
+
|
|
|
+ if(empty($order_sn)) {
|
|
|
+ return self::outerr(201,"客户订单号order_sn错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ $order_state = refill\util::query_queue_order($mchid,$order_sn);
|
|
|
+ if ($order_state == ORDER_STATE_QUEUE || $order_state == ORDER_STATE_SEND) {
|
|
|
+ Log::record("query_state in queue mchid={$mchid} mch_order={$order_sn} order_state={$order_state}" ,Log::DEBUG);
|
|
|
+ $result['mchid'] = $mchid;
|
|
|
+ $result['order_sn'] = $order_sn;
|
|
|
+ $result['order_state'] = $order_state;
|
|
|
+ return self::outsuccess($result);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $mod_refill = Model('refill_order');
|
|
|
+ $refill_info = $mod_refill->getOrderInfo(['mch_order' => $order_sn,'mchid' => $mchid,'inner_status' => 0]);
|
|
|
+
|
|
|
+ if(empty($refill_info))
|
|
|
+ {
|
|
|
+ Log::record("query_state in db no order mchid={$mchid} mch_order={$order_sn}" ,Log::DEBUG);
|
|
|
+ return self::outerr(202, "无此订单");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $vr_order = Model('vr_order');
|
|
|
+ $order_info = $vr_order->getOrderInfo(['order_sn' => $refill_info['order_sn']]);
|
|
|
+ Log::record("query_state in db mchid={$mchid} mch_order={$order_sn} order_state={$order_info['order_state']}" ,Log::DEBUG);
|
|
|
+
|
|
|
+ if (empty($order_info)) {
|
|
|
+ return self::outerr(203, "无此交易号");
|
|
|
+ } else {
|
|
|
+ $result = $this->format($order_info, $refill_info);
|
|
|
+ return self::outsuccess($result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|