浏览代码

增加电子券接口

stanley-king 2 年之前
父节点
当前提交
856e2f6ebd
共有 4 个文件被更改,包括 121 次插入20 次删除
  1. 2 1
      admin/control/control.php
  2. 6 0
      helper/mtopcard/mtopcard.php
  3. 34 19
      helper/refill/order.php
  4. 79 0
      mobile/control/refill.php

+ 2 - 1
admin/control/control.php

@@ -15,7 +15,8 @@ class SystemControl
     const THIRD_PRODUCT_TYPE = [
         mtopcard\ThirdOnlineProduct => '在线产品',
         mtopcard\ThirdElectricProduct => '电费产品',
-        mtopcard\ThirdSMSProduct => '短信产品'
+        mtopcard\ThirdSMSProduct => '短信产品',
+        mtopcard\ThirdSinopecECouponPoroduct => '中石化电子券'
     ];
 	/**
 	 * 管理员资料 name id group

+ 6 - 0
helper/mtopcard/mtopcard.php

@@ -25,6 +25,7 @@ const ThirdRefillCard  = 7;        //三方账号充值
 const ThirdOnlineProduct = 1;
 const ThirdElectricProduct = 2;
 const ThirdSMSProduct = 3;
+const ThirdSinopecECouponPoroduct = 4;
 
 //三方卡号类型:1 手机号,2 QQ号,3 微信号,4 电卡
 const ThirdCardPhone = 1;
@@ -320,6 +321,11 @@ function electric_product_code($company_type,$use_type,$refill_amount)
     return "DF_{$company_type}_{$use_type}_{$refill_amount}";
 }
 
+function sino_coupon_product_code($refill_amount)
+{
+    return "SHDZQ_{$refill_amount}";
+}
+
 function is_alpha($text) {
     return is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text);
 };

+ 34 - 19
helper/refill/order.php

@@ -28,11 +28,12 @@ class order
     private $mIsValidate;
     private $mFirstCommit;
 
+    //mCardType等于7的时候,需要这些参数
     private $mProductCode;
-    private $mQuantity;
+    private $mQuantity; //数量
     private $mThirdPorductType;
     private $mThirdCardType; // 三方充值账号类型
-    private $mElecticExtes = [];
+    private $mThirdExtes = [];  //三方扩展参数
 
     public function __construct()
     {
@@ -195,7 +196,8 @@ class order
         $this->mOriginQuality = intval($params['org_quality']) ?? 0;
 
         $card_type = intval($params['card_type']) ?? 0;
-        if($card_type == 7) {
+        if($card_type == mtopcard\ThirdRefillCard)
+        {
             $this->mCurQuality = $this->mOriginQuality;
             $this->mProductCode = $params['product_code'];
             $this->mThirdPorductType = $params['third_product_type'];
@@ -209,11 +211,15 @@ class order
 
             if($this->mThirdPorductType == mtopcard\ThirdElectricProduct)
             {
-                $this->mElecticExtes['company_type'] = $params['company_type'];
-                $this->mElecticExtes['use_type'] = $params['use_type'];
-                $this->mElecticExtes['province'] = $params['province'];
-                $this->mElecticExtes['city'] = $params['city'];
-                $this->mElecticExtes['card_id'] = $params['card_id'];
+                $this->mThirdExtes['company_type'] = $params['company_type'];
+                $this->mThirdExtes['use_type'] = $params['use_type'];
+                $this->mThirdExtes['province'] = $params['province'];
+                $this->mThirdExtes['city'] = $params['city'];
+                $this->mThirdExtes['card_id'] = $params['card_id'];
+            }
+            elseif($this->mThirdPorductType == mtopcard\ThirdElectricProduct)
+            {
+                $this->mThirdExtes['province'] = $params['province'];
             }
         }
         else
@@ -262,6 +268,7 @@ class order
 
         return $params;
     }
+
     public function refill_params($order_id,$order_sn,$spec,$channel_name,$channel_amout,$mch_amount)
     {
         $refill_amount = $spec * $this->mQuantity;
@@ -276,6 +283,7 @@ class order
             'card_no' => $this->mCardNo, 'quality' => $this->mCurQuality, 'org_quality' => $this->mOriginQuality];
         return $params;
     }
+
     public function third_extparams($order_id,$order_sn)
     {
         $ext = ['order_id' => $order_id, 'order_sn' => $order_sn, 'product_type' => $this->mThirdPorductType,
@@ -284,13 +292,17 @@ class order
             'add_time' => time()
         ];
 
-        if($this->is_third() && $this->mThirdPorductType == mtopcard\ThirdElectricProduct) {
-            $ext['company_type'] = $this->mElecticExtes['company_type'];
-            $ext['use_type'] = $this->mElecticExtes['use_type'];
-            $ext['province'] = $this->mElecticExtes['province'];
-            $ext['city'] = $this->mElecticExtes['city'];
-            $ext['card_id'] = $this->mElecticExtes['card_id'];
+        if($this->is_third())
+        {
+            if($this->mThirdPorductType == mtopcard\ThirdElectricProduct) {
+                $ext['company_type'] = $this->mThirdExtes['company_type'];
+                $ext['use_type'] = $this->mThirdExtes['use_type'];
+                $ext['province'] = $this->mThirdExtes['province'];
+                $ext['city'] = $this->mThirdExtes['city'];
+                $ext['card_id'] = $this->mThirdExtes['card_id'];
+            }
         }
+
         return $ext;
     }
     public function channel_params($order_id,$order_sn,$goods_id)
@@ -309,11 +321,14 @@ class order
             $params['goods_id'] = $goods_id;
 
             if($this->mThirdPorductType == mtopcard\ThirdElectricProduct) {
-                $params['company_type'] = $this->mElecticExtes['company_type'];
-                $params['use_type'] = $this->mElecticExtes['use_type'];
-                $params['province'] = $this->mElecticExtes['province'];
-                $params['city'] = $this->mElecticExtes['city'];
-                $params['card_id'] = $this->mElecticExtes['card_id'];
+                $params['company_type'] = $this->mThirdExtes['company_type'];
+                $params['use_type'] = $this->mThirdExtes['use_type'];
+                $params['province'] = $this->mThirdExtes['province'];
+                $params['city'] = $this->mThirdExtes['city'];
+                $params['card_id'] = $this->mThirdExtes['card_id'];
+            }
+            elseif ($this->mThirdPorductType == mtopcard\ThirdSinopecECouponPoroduct) {
+                $params['province'] = $this->mThirdExtes['province'];
             }
         }
 

+ 79 - 0
mobile/control/refill.php

@@ -327,6 +327,85 @@ class refillControl extends merchantControl
         }
     }
 
+    private function check_sinopec_coupon($params)
+    {
+        if(empty($params['cardno'])) {
+            return [false,'参数没有包含cardno'];
+        }
+        if(empty($params['notifyurl'])) {
+            return [false,'参数没有包含notifyurl'];
+        }
+        if(empty($params['order_sn'])) {
+            return [false,'参数没有包含贵方唯一订单号:order_sn'];
+        }
+        if(empty($params['amount']) || intval($params['amount']) <= 0) {
+            return [false,'参数没有包含充值金额:amount'];
+        }
+        if(empty($params['province']) || !array_key_exists($params['province'],mtopcard\ProvinceList)) {
+            return [false,"请传入省份"];
+        }
+
+        return [true,""];
+    }
+
+    public function add_sinopec_couponOp()
+    {
+        [$success,$error] = $this->check_sinopec_coupon($_GET);
+        if($success === false) {
+            return self::outerr(201,$error);
+        }
+
+        $notify_url = $_GET['notifyurl'];
+        $mch_order  = $_GET['order_sn'];   //对方的order编号
+
+        $card_no = $_GET['cardno'] ?? '';
+
+        $quantity = 1;
+        $third_card_type = mtopcard\ThirdCardPhone;
+        $province = intval($_GET['province']);
+        $amount   = intval($_GET['amount']);
+
+        $product_code = mtopcard\sino_coupon_product_code($amount);
+        $amount = refill\util::ThirdRefillAmount;
+
+        //三方充值没有质量
+        $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,
+            'third_product_type' => mtopcard\ThirdSinopecECouponPoroduct,
+            'province' => $province
+        ];
+
+        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);