Browse Source

fix 下订单未判断是否全款支付的情况

stanley-king 4 năm trước cách đây
mục cha
commit
f7e2e97b0e

+ 11 - 1
data/config/prod/refill.ini.php

@@ -57,6 +57,15 @@ $gftd_oil = ['name' => 'gftd', 'store_id' => 19, 'card_type' => ['petrochina','s
     ],
     'period' => [], 'refill_type' => 'api'];
 
+$gftdsinop_oil = ['name' => 'gftdsinop', 'store_id' => 20, 'card_type' => ['petrochina','sinopec'],
+    'amount' => [
+        100 => ['goods_id' => 6343, 'price' => 95],
+        200 => ['goods_id' => 6344, 'price' => 190],
+        500 => ['goods_id' => 6345, 'price' => 475],
+        1000 => ['goods_id' => 6346, 'price' => 950]
+    ],
+    'period' => [], 'refill_type' => 'api'];
+
 $oil_providers = [
     ['name' => 'suhc', 'cfg' => $suhc_oil, 'opened' => false, 'sort' => 3],
     ['name' => 'suhctm', 'cfg' => $suhctm_oil, 'opened' => false, 'sort' => 1],
@@ -64,7 +73,8 @@ $oil_providers = [
     ['name' => 'zzx', 'cfg' => $zzx_oil, 'opened' => false, 'sort' => 5],
     ['name' => 'lx', 'cfg' => $lx_oil, 'opened' => false, 'sort' => 1],
     ['name' => 'saihu', 'cfg' => $saihu_oil, 'opened' => false, 'sort' => 6],
-    ['name' => 'gftd', 'cfg' => $gftd_oil, 'opened' => true, 'sort' => 1]
+    ['name' => 'gftd', 'cfg' => $gftd_oil, 'opened' => true, 'sort' => 1],
+    ['name' => 'gftdsinop', 'cfg' => $gftdsinop_oil, 'opened' => true, 'sort' => 1]
     ];
 $config['oil_providers'] = $oil_providers;
 

+ 19 - 2
helper/refill/RefillFactory.php

@@ -61,6 +61,9 @@ require_once(BASE_HELPER_PATH . '/refill/xc/RefillCallBack.php');
 require_once(BASE_HELPER_PATH . '/refill/gftd/RefillOil.php');
 require_once(BASE_HELPER_PATH . '/refill/gftd/RefillCallBack.php');
 
+require_once(BASE_HELPER_PATH . '/refill/gftdsinop/RefillOil.php');
+require_once(BASE_HELPER_PATH . '/refill/gftdsinop/RefillCallBack.php');
+
 require_once(BASE_HELPER_PATH . '/refill/weit/RefillPhone.php');
 require_once(BASE_HELPER_PATH . '/refill/weit/RefillCallBack.php');
 
@@ -459,6 +462,13 @@ class RefillFactory
                 $order_sn = $result['data']['order_sn'];
                 $order_id = $result['data']['order_id'];
 
+                if(!$this->pay_completed($order_sn)) {
+                    $logic_vr_order = Logic("vr_order");
+                    $order_info = Model('vr_order')->getOrderInfo(['order_id' => $order_id]);
+                    $logic_vr_order->changeOrderStateCancel($order_info, '', "预存款不足以支付该订单");
+                    continue;
+                }
+
                 if (empty($mch_order)) {
                     $mch_order = $order_sn;
                 }
@@ -504,8 +514,6 @@ class RefillFactory
             }
         }
 
-
-
         if ($refill_state) {
             return [true, $order_sn];
         } else {
@@ -513,6 +521,15 @@ class RefillFactory
         }
     }
 
+    private function pay_completed($order_sn)
+    {
+        $logic_payment = Logic('payment');
+        $order = $logic_payment->getVrOrderInfo($order_sn);
+        $api_pay_amount = $order['data']['api_pay_amount'];
+
+        return ($api_pay_amount == ncPriceFormat(0.00));
+    }
+
     private function is_url($url)
     {
         $checker = function ($haystack, $needle) {

+ 94 - 0
helper/refill/gftdsinop/RefillCallBack.php

@@ -0,0 +1,94 @@
+<?php
+
+
+namespace refill\gftdsinop;
+
+require_once(BASE_HELPER_PATH . '/refill/gftdsinop/config.php');
+
+
+use refill;
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['signature']);
+
+        $sign = $this->sign($input);
+        if ($params['signature'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        $body = $this->body($params);
+        $body .= config::APP_SECRET;
+
+        return md5($body);
+    }
+
+    protected function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
+    private function body($params)
+    {
+        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}" . "=" . $v;
+                } else {
+                    $body .= "&" . "{$k}" . "=" . $v;
+                }
+                $i++;
+            }
+        }
+        return $body;
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['status']);
+
+        $order_sn = $params['channelOrderNumber'];
+        $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
+        if (empty($order_info)) {
+            return [false, false, false,false];
+        }
+        $order_id = $order_info['order_id'];
+        $data['official_sn'] = $params['voucher'];
+        $data['ch_trade_no'] = $params['orderNumber'];
+        Model('refill_order')->edit($order_id, $data);
+
+        //[$order_id, 成功失败, 是否能重试,接下来是否需要处理]
+        if ($status === 101) {
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 109) {
+            return [$order_id, false, false,true];
+        }
+        elseif ($status === 120) {
+            return [$order_id, false, false,false];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 141 - 0
helper/refill/gftdsinop/RefillOil.php

@@ -0,0 +1,141 @@
+<?php
+
+
+namespace refill\gftdsinop;
+
+require_once(BASE_HELPER_PATH . '/refill/gftdsinop/config.php');
+
+
+use refill;
+use mtopcard;
+use Log;
+
+class RefillOil extends refill\IRefillOil
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(string $card_no,int $card_type,int $amount,array $other)
+    {
+        $params['appid'] = config::APP_ID;
+        $params['ts'] = time();
+
+        $params['productId'] = $this->product_id($amount,$card_type);
+        $params['outOrderNumber'] = $other['order_sn'];
+        $params['fuelCardNumber'] = $card_no;
+
+        $params['fuelCardUserName'] = "";
+        $params['fuelCardUserID'] = "";
+
+        $mobile = $this->make_mobile();
+        $params['telephone'] = $mobile;
+        $params['phoneNumber'] = $mobile;
+
+        return $params;
+    }
+
+    private function make_mobile()
+    {
+        $no = "1" . mt_rand(3000000000, 9999999999);
+        return $no;
+    }
+
+    private function product_id(int $amount,int $cart_type)
+    {
+        if($cart_type === mtopcard\PetroChinaCard)
+        {
+            switch ($amount) {
+                case 100: return 1;
+                case 200: return 2;
+                case 500: return 3;
+                case 1000: return 4;
+            }
+        }
+        else
+        {
+            switch ($amount) {
+                case 100: return 5;
+                case 200: return 6;
+                case 500: return 7;
+                case 1000: return 8;
+            }
+        }
+
+        return false;
+    }
+
+    private function sign($params)
+    {
+        $body = $this->body($params);
+        $body .= config::APP_SECRET;
+
+        return md5($body);
+    }
+
+    protected function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
+    private function body($params)
+    {
+        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}" . "=" . $v;
+                } else {
+                    $body .= "&" . "{$k}" . "=" . $v;
+                }
+
+                $i++;
+            }
+        }
+        return $body;
+    }
+
+    public function add($card_no,$card_type,$amount,$input)
+    {
+        $params = $this->req_params($card_no,$card_type,$amount,$input);
+        $sign = $this->sign($params);
+        $params['signature'] = $sign;
+
+        $uri = config::ORDER_URL . "/fuelRecharge/create";
+        $resp = http_post_data($uri,json_encode($params), config::ExtHeaders);
+        if($resp === false) {
+            return [false,'系统错误'];
+        }
+        else
+        {
+            Log::record($resp,Log::DEBUG);
+            $resp = json_decode($resp,true);
+
+            if($resp['code'] == 0)
+            {
+                $data = $resp['data'];
+                return [true,$data['orderNumber']];
+            }
+            else {
+                return [false,$resp['message']];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        return [false,'未实现查询接口'];
+    }
+}

+ 24 - 0
helper/refill/gftdsinop/RefillPhone.php

@@ -0,0 +1,24 @@
+<?php
+namespace refill\gftd;
+
+require_once(BASE_HELPER_PATH . '/refill/gftdsinop/config.php');
+
+use refill;
+use refill\IRefillPhone;
+
+class RefillPhone extends IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    public function add($card_no,$card_type,$amount,$input)
+    {
+        return [false,'No Implement'];
+    }
+    public function query($refill_info)
+    {
+        return [false,'No Implement'];
+    }
+}

+ 17 - 0
helper/refill/gftdsinop/config.php

@@ -0,0 +1,17 @@
+<?php
+
+
+namespace refill\gftdsinop;
+
+
+class config
+{
+//    const ORDER_URL = 'https://dev.oapi.chinasaltenergy.com/open-api'; #dev
+    const ORDER_URL = 'https://oapi.chinasaltenergy.com/open-api';   #prod
+
+    const APP_ID= 'CAE45C97727DECDF';
+    const APP_SECRET = '4023D6F779324C21BF8D8FC10A21CFD4';
+
+    const NOTIFY_URL = "https://www.xyzshops.cn/mobile/refill_gftd.php";
+    const ExtHeaders = ['Content-Type: application/json;charset=UTF-8;','Accept:application/json;charset=UTF-8;'];
+}

+ 2 - 2
test/TestRefill.php

@@ -17,7 +17,7 @@ require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
 const LocalTest = 1;
 const NetTest = 2;
 
-const CurrentTest = NetTest;
+const CurrentTest = LocalTest;
 
 class TestRefill extends TestCase
 {
@@ -250,7 +250,7 @@ class TestRefill extends TestCase
     {
         $url = $this->mReqHost . "/mobile/index.php";
         $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
-        $params = ['mchid' => 1092,
+        $params = ['mchid' => $this->mMchid,
             'cardno' => '1000111100020445281',
             'amount' => "100",
             "act" => "refill",

+ 135 - 0
test/TestRefillCB.php

@@ -0,0 +1,135 @@
+<?php
+
+
+use PHPUnit\Framework\TestCase;
+use refill\gftd\config;
+
+define('APP_ID', 'test');
+define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
+
+require_once(BASE_ROOT_PATH . '/global.php');
+require_once(BASE_CORE_PATH . '/lrlz.php');
+require_once(BASE_ROOT_PATH . '/fooder.php');
+
+require_once(BASE_CORE_PATH . '/framework/function/http.php');
+require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
+require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
+
+const LocalTest = 1;
+const NetTest = 2;
+
+const CurrentTest = NetTest;
+
+
+class Gftd
+{
+    const APP_ID = 'CAE45C97727DECDF';
+    const APP_SECRET = '4023D6F779324C21BF8D8FC10A21CFD4';
+
+    public function params($params)
+    {
+        $params['appid'] = config::APP_ID;
+        $params['ts'] = time();
+        $params['signature'] = $this->sign($params);
+        return $params;
+    }
+
+    public function sign($params)
+    {
+        $body = $this->body($params);
+        $body .= Gftd::APP_SECRET;
+
+        return md5($body);
+    }
+
+    protected function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
+    private function body($params)
+    {
+        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}" . "=" . $v;
+                } else {
+                    $body .= "&" . "{$k}" . "=" . $v;
+                }
+                $i++;
+            }
+        }
+        return $body;
+    }
+}
+
+class TestRefillCancel extends TestCase
+{
+    private $mReqHost;
+    private $mKey;
+    private $mMchid;
+
+    public function __construct(?string $name = null, array $data = [], $dataName = '')
+    {
+        parent::__construct($name, $data, $dataName);
+
+        if (CurrentTest == LocalTest) {
+            $this->mReqHost = BASE_SITE_URL;
+            $this->mMchid = 1;
+            $this->mKey = '1ff02223b771c0414468c8892151c602';
+        } else {
+            $this->mReqHost = 'https://www.xyzshops.cn';
+            $this->mMchid = 1092;
+            $this->mKey = '210fe406954220f56085997d6a4c5b80';
+        }
+    }
+
+    public function testGFTDCancel()
+    {
+        $params['channelOrderNumber'] = '600664387134838632';
+        $params['orderNumber'] = 'GYFL1611043135784640';
+        $params['message'] = '只能给绑定正确手机号的油卡充值或只能给主卡充值';
+        $params['status'] = 109;
+
+        $prov = new Gftd();
+        $result = $prov->params($params);
+        $resp = http_post_data("https://www.xyzshops.cn/mobile/refill_gftd.php",json_encode($result,JSON_UNESCAPED_UNICODE),config::ExtHeaders);
+        Log::record($resp,Log::DEBUG);
+    }
+
+    public function testGFTDSuccess()
+    {
+        #{"channelOrderNumber":"750664483985964632",
+        #"orderNumber":"GYFL1611139986728407",
+        #"message":"充值成功",
+        #"signature":"f0eec4d0ccc1a0b6ec06003a648fd9b4",
+        #"voucher":"2421012018536345",
+        #"status":101}
+        $params['channelOrderNumber'] = '390664474809855793';
+        $params['orderNumber'] = 'GYFL1611130810782129';
+        $params['message'] = '充值成功';
+        $params['status'] = 101;
+        $params["voucher"] = "2421012018536345";
+
+        $prov = new Gftd();
+        $result = $prov->params($params);
+        $resp = http_post_data("https://www.xyzshops.cn/mobile/refill_gftd.php",json_encode($result,JSON_UNESCAPED_UNICODE),config::ExtHeaders);
+        Log::record($resp,Log::DEBUG);
+    }
+}
+
+
+//docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testCall)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test
+//docker-compose -f ./docker-compose-dev.yml run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testCall)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test