stanley-king il y a 4 ans
Parent
commit
e16578c8d2

+ 11 - 5
data/config/dev/refill.ini.php

@@ -333,6 +333,13 @@ $tonglu_phone = ['name' => 'tonglu', 'store_id' => 33,'qualitys' => '4',
     ],
     'official_sn' => true, 'refill_type' => 'api'];
 
+$sctongqian = ['name' => 'tonglu', 'store_id' => 34,'qualitys' => '4',
+    'amount' => [
+        100 => [['goods_id' => 6426, 'price' => 99, 'quality' => 4, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+    ],
+    'official_sn' => true, 'refill_type' => 'api'];
+
+
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
@@ -350,17 +357,16 @@ $phone_providers = [
     ['name' => 'tongy', 'cfg' => $tongy_phone],
     ['name' => 'weiyi', 'cfg' => $weiyi_phone],
     ['name' => 'tonglu', 'cfg' => $tonglu_phone],
+    ['name' => 'sctongqian', 'cfg' => $sctongqian]
+
+
 ];
 $config['phone_providers'] = $phone_providers;
 
 
 $config['refill_third_specs'] = [100];
 
-$sctongqian = ['name' => 'tonglu', 'store_id' => 34,'qualitys' => '4',
-    'amount' => [
-        100 => [['goods_id' => 6426, 'price' => 99, 'quality' => 4, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
-    ],
-    'official_sn' => true, 'refill_type' => 'api'];
+
 
 $third_providers = [
     ['name' => 'sctongqian', 'cfg' => $sctongqian]

+ 23 - 0
data/model/thrid_refill.model.php

@@ -15,4 +15,27 @@ class thrid_refillModel extends Model
     {
         return $this->table('third_product')->field($field)->where($condition)->order($order)->limit($limit)->page($page)->select();
     }
+
+    public function getMerchantPrice($mchid,$pcode)
+    {
+        $item = $this->table('merchant_price')
+                     ->field('*')
+                     ->where(['mchid' => $mchid, 'pcode' => $pcode])
+                     ->find();
+        if(empty($item)) {
+            return false;
+        }
+
+        $card_types = explode(',',$item['card_types']);
+        if(in_array(mtopcard\ThirdRefillCard,$card_types)) {
+            return ncPriceFormat($item['price']);
+        } else {
+            return false;
+        }
+    }
+
+    public function addExt($data)
+    {
+
+    }
 }

+ 2 - 1
helper/mtopcard/mtopcard.php

@@ -314,4 +314,5 @@ function formatProvince(string $province) : string
     }
 
     return $province;
-}
+}
+

+ 0 - 1
helper/refill/CalcMerchantPrice.php

@@ -23,7 +23,6 @@ class CalcMerchantPrice implements ICalc
         }
 
         $price = $policy->price($mchid,$spec,$card_type,$quality,$pcode);
-
         if($price === false) {
             throw new Exception("没有协商商品购买价格.");
         }

+ 12 - 0
helper/refill/RefillBase.php

@@ -323,6 +323,12 @@ class RefillBase
                     'card_no' => $card_no, 'quality' => $quality, 'org_quality' => $org_quality];
                 $mod_refill->add_refill($orderext);
 
+                if($card_type == mtopcard\ThirdRefillCard) {
+                    $thrid_refill = Model('thrid_refill');
+                    $ext = ['order_id' => $order_id,'order'];
+                    $thrid_refill->add_ext($ext);
+                }
+
                 if(!$this->pay_completed($order_sn)) {
                     $logic_vr_order = Logic("vr_order");
                     $order_info = Model('vr_order')->getOrderInfo(['order_id' => $order_id]);
@@ -339,6 +345,12 @@ class RefillBase
             $params = ['order_sn' => $order_sn, 'idcard' => $idcard, 'card_name' => $card_name,
                 'buyer_id' => $buyer_id,
                 'quality' => $quality,'order_id' => $order_id];
+            if($card_type == mtopcard\ThirdRefillCard) {
+                $params['quantity'] = $quantity;
+                $params['product_code'] = $third_params['product_code'];
+                $params['third_card_type'] = $third_params['third_card_type'];
+                $params['goods_id'] = $goods_id;
+            }
 
             util::incr_commit_pre($channel_name,$card_type,$amount,$quality);
             util::decr_amount_lock($mchid,$card_type,$amount);

+ 15 - 9
helper/refill/api/lingzh/sctongqian/RefillCallBack.php

@@ -3,6 +3,8 @@ namespace refill\sctongqian;
 require_once(BASE_HELPER_RAPI_PATH . '/sctongqian/config.php');
 
 use refill;
+use Log;
+
 class RefillCallBack implements refill\IRefillCallBack
 {
     public function verify($params): bool
@@ -27,14 +29,13 @@ class RefillCallBack implements refill\IRefillCallBack
         $status = intval($params['State']);
         $order_sn = $params['MOrderID'];
         $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
-        if (empty($order_info)) {
-            return [false, false, false,false];
-        }
+//        if (empty($order_info)) {
+//            return [false, false, false,false];
+//        }
         $order_id = $order_info['order_id'];
 
         if ($status === 2) {
-            //卡密信息,需返回
-            $CardInfo = $this->rsa_decode($params['CardInfo']);
+            $result = $this->rsa_decode($params['CardInfo']);
             return [$order_id, true, false,true];
         }
         elseif ($status === 3) {
@@ -47,9 +48,14 @@ class RefillCallBack implements refill\IRefillCallBack
 
     private function rsa_decode($encrypted)
     {
-        $private_key = config::PRIVATE_KEY;
-        //使用私钥解密数据
-        openssl_private_decrypt(base64_decode($encrypted), $decrypted,$private_key);
-        return $decrypted;
+        $ret = openssl_private_decrypt(base64_decode($encrypted), $decrypted, config::PRIVATE_KEY);
+        if ($ret) {
+            $result = json_decode($decrypted, true);
+            return $result;
+        } else {
+            $err = openssl_error_string();
+            Log::record("sctongqian callback openssl_private_decrypt error={$err}",Log::ERR);
+            return false;
+        }
     }
 }

+ 34 - 8
helper/refill/api/lingzh/sctongqian/RefillPhone.php

@@ -31,12 +31,12 @@ class RefillPhone extends refill\IRefillPhone
         }
     }
 
-    private function req_params(string $order_sn, string $product_code)
+    private function req_params(string $order_sn, string $product_code,$quantity)
     {
         $params['AppKey'] = config::APP_KEY;
         $params['TimesTamp'] = time();
-        $params['ProductCode'] = 'PLM100024'; //产品编码需传入
-        $params['BuyCount'] = 1;
+        $params['ProductCode'] = $product_code;
+        $params['BuyCount'] = $quantity;
         $params['MOrderID'] = $order_sn;
         $params['CustomerIP'] = config::API_IP;
         $params['IsCallback'] = 1;
@@ -45,12 +45,35 @@ class RefillPhone extends refill\IRefillPhone
         return $params;
     }
 
+    private function getProductCode($goods_id,$sys_pcode)
+    {
+        $thrid_refill = Model('thrid_refill');
+        $product = $thrid_refill->getProviderProduct($this->mStoreID,$goods_id,$sys_pcode);
+        if (empty($product)) {
+            return false;
+        } else {
+            return $product['channel_code'];
+        }
+    }
+
     //直充提单
     public function add($card_no, $card_type, $amount, $params)
     {
+        if(empty($card_no)) {
+            return $this->cardkey_add($params);
+        } else {
+            return $this->direct_add($card_no, $params);
+        }
+    }
+
+    private function direct_add($card_no, $params)
+    {
         $order_sn = $params['order_sn'];
-        $product_code = $params['product_code'];
-        $params = $this->req_params($order_sn,$product_code);
+        $goods_id = intval($params['goods_id']);
+        $product_code = $this->getProductCode($goods_id,$params['product_code']);
+        $quantity = intval($params['quantity']);
+
+        $params = $this->req_params($order_sn,$product_code,$quantity);
 
         $params['ChargeAccount'] = $card_no;
         $params['ChargeAccountType'] = 1;//账号类型1 手机号,2 QQ号,3 微信号
@@ -77,11 +100,14 @@ class RefillPhone extends refill\IRefillPhone
         }
     }
 
-    public function CardOrderAdd($card_no, $card_type, $amount, $params)
+    private function cardkey_add($params)
     {
         $order_sn = $params['order_sn'];
-        $product_code = $params['product_code'];
-        $params = $this->req_params($order_sn,$product_code);
+        $goods_id = intval($params['goods_id']);
+        $product_code = $this->getProductCode($goods_id,$params['product_code']);
+        $quantity = intval($params['quantity']);
+
+        $params = $this->req_params($order_sn,$product_code,$quantity);
 
         $params['PublicKey'] = config::PUBLIC_KEY;
 

+ 9 - 10
helper/refill/policy/merchant_price.php

@@ -46,23 +46,22 @@ class merchant_price
     public function price($mchid,$card_type,$spec,$quality,$pcode)
     {
         $card_type = intval($card_type);
-        if(in_array($card_type,[1,2,4,5,6]))
+        if(in_array($card_type,[1,2,4,5,6])) //油,话费价格查找.
         {
             $key = "{$mchid}-{$quality}-{$card_type}-{$spec}";
-            if(array_key_exists($key,$this->mPrices)) {
+            if (array_key_exists($key, $this->mPrices)) {
                 return $this->mPrices[$key];
-            }
-            else {
+            } else {
                 return false;
             }
         }
         elseif($card_type === mtopcard\ThirdRefillCard) {
-            return $this->third_price($mchid,$card_type,$pcode);
+            $thrid_refill = Model('thrid_refill');
+            $price = $thrid_refill->getMerchantPrice($mchid,$pcode);
+            return $price;
+        }
+        else {
+            return false;
         }
-    }
-
-    private function third_price($mchid,$card_type,$pcode)
-    {
-
     }
 }

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 11
test/TestRefill.php


Fichier diff supprimé car celui-ci est trop grand
+ 17 - 1
test/TestThirdRefill.php