stanley-king преди 4 години
родител
ревизия
7b97a1c9d6

+ 2 - 2
data/logic/queue.logic.php

@@ -1235,7 +1235,7 @@ class queueLogic
         $extra_info = json_decode($order['extra_info'], true);
         $card_no = $extra_info['input']['card_no'];
         $card_type = mtopcard\topcard_type($extra_info['input']['card_type']);
-        [$ret,$info] = mtopcard\cards_helper::reserve(mtopcard\OilCardPaper, $amount, $member_id, $card_no, $card_type, $order_id,$store_id);
+        [$ret,$info] = mtopcard\cards_helper::reserve(mtopcard\OilCardPaper, $amount, $member_id, $card_no, $card_type, $order_id,[$store_id]);
 
         $vr_order = Model();
         $vr_order->table('vr_order')->where(['order_id' => $order_id])->update(['card_no' => $card_no]);
@@ -1255,7 +1255,7 @@ class queueLogic
         $extra_info = json_decode($order['extra_info'], true);
         $card_no = $extra_info['input']['card_no'];
         $card_type = mtopcard\topcard_type($extra_info['input']['card_type']);
-        [$ret,$info] = mtopcard\cards_helper::reserve(mtopcard\PhoneCardPaper, $amount, $member_id, $card_no, $card_type, $order_id, $store_id);
+        [$ret,$info] = mtopcard\cards_helper::reserve(mtopcard\PhoneCardPaper, $amount, $member_id, $card_no, $card_type, $order_id, [$store_id]);
 
         $vr_order = Model();
         $vr_order->table('vr_order')->where(['order_id' => $order_id])->update(['card_no' => $card_no]);

+ 9 - 2
data/model/card_key.model.php

@@ -10,6 +10,8 @@ use const mtopcard\FreezedCard;
 
 class card_keyModel extends Model
 {
+    private $str;
+
     public function __construct()
     {
         parent::__construct('card_key');
@@ -30,9 +32,14 @@ class card_keyModel extends Model
         return $this->insert($params);
     }
 
-    public function getUsable($card_type, $amount)
+    public function getUsable($card_type, $amount,$store_ids)
     {
-        return $this->where(['card_state' => UnusedCard, 'card_type' => $card_type, 'amount' => $amount])
+        if(empty($store_ids)) {
+            Log::record("获取卡密需要指定获取的店铺",Log::ERR);
+            return [];
+        }
+
+        return $this->where(['card_state' => UnusedCard, 'card_type' => $card_type, 'amount' => $amount, 'store_id' => ['in',$store_ids]])
             ->lock(true)
             ->master(true)
             ->find();

+ 3 - 3
helper/mtopcard/cards_helper.php

@@ -10,12 +10,12 @@ use Log;
 
 class cards_helper
 {
-    static public function reserve($card_type, $amount, $userid, $user_card_no, $user_card_type,$order_id,$store_id = 0)
+    static public function reserve($card_type, $amount, $userid, $user_card_no, $user_card_type,$order_id,$store_ids = [],$out_store_id = 0)
     {
         try {
             $model = Model('card_key');
             $trans = new trans_wapper($model, __METHOD__);
-            $info = $model->getUsable($card_type, $amount);
+            $info = $model->getUsable($card_type, $amount,$store_ids);
             if (empty($info)) {
                 $trans->commit();
                 Log::record("cards_helper::reserve 找不到可用的卡了", Log::ERR);
@@ -32,7 +32,7 @@ class cards_helper
                                    'order_id' => $order_id,
                                    'receive_card_no' => $user_card_no,
                                    'receive_card_type' => $user_card_type,
-                                   'out_store_id' => $store_id,
+                                   'out_store_id' => $out_store_id,
                                    'reserved_time' => time()]);
             $rows = $model->affected_rows();
             return [true,$card];

+ 3 - 1
helper/refill/RefillBase.php

@@ -316,7 +316,9 @@ class RefillBase
 
             $order_success = true;
             util::incr_order($channel_name,$card_type,$amount,$quality);
-            $params = ['order_sn' => $order_sn, 'idcard' => $idcard, 'card_name' => $card_name,'quality' => $quality];
+            $params = ['order_sn' => $order_sn, 'idcard' => $idcard, 'card_name' => $card_name,
+                'buyer_id' => $buyer_id,
+                'quality' => $quality,'order_id' => $order_id];
             [$state, $errmsg,$neterr] = $provider->add($card_no, $card_type, $amount, $params);
 
             if ($state)

+ 30 - 23
helper/refill/api/lingzh/legou/RefillPhone.php

@@ -4,6 +4,7 @@ namespace refill\legou;
 
 require_once(BASE_HELPER_RAPI_PATH . '/legou/config.php');
 
+use mtopcard\cards_helper;
 use refill;
 use Log;
 
@@ -14,17 +15,13 @@ class RefillPhone extends refill\IRefillPhone
         parent::__construct($cfgs);
     }
 
-    private function req_params(int $phone, int $amount, string $order_sn)
+    private function req_params(int $phone,$card_type, int $amount, string $order_sn)
     {
         $params['username'] = config::USERNAME;
         $params['orderNumber'] = $order_sn;
         $params['cardNumber'] = $phone;
         $params['cardExt'] = $amount;
-
-        $rechargeCard = $this->getrechargeCard($phone);
-        $params['rechargeNum'] = $rechargeCard['rechargeNum'];
-        $params['rechargePwd'] = $rechargeCard['rechargePwd'];
-        $params['productNo'] = $rechargeCard['productNo'];
+        $params['productNo'] = config::ProductIDS[$card_type];
         $params['timestamp'] = $this->getMillisecond();
         $params['notifyUrl'] = config::NOTIFY_URL;
 
@@ -33,19 +30,39 @@ class RefillPhone extends refill\IRefillPhone
 
     public function add($card_no, $card_type, $amount, $params)
     {
-        $params = $this->req_params($card_no, $amount, $params['order_sn']);
+        $params = $this->req_params($card_no,$card_type, $amount, $params['order_sn']);
+
+        [$success,$card] = cards_helper::reserve($card_type,$amount,$params['buyer_id'],$card_no,$card_type,$params['order_id'],config::StoreIDS);
+        if(!$success) {
+            return [false, '没有可用卡密', false];
+        }
+
+        $rcard_no = $card->card_no();
+        $rcard_key = $card->card_key();
+        $params['rechargeNum'] = $rcard_no;
+        $params['rechargePwd'] = $rcard_key;
         $sign = $this->sign($params);
         $params['sign'] = $sign;
-        $params['rechargeNum'] = $this->encryptWithOpenssl($params['rechargeNum']);
-        $params['rechargePwd'] = $this->encryptWithOpenssl($params['rechargePwd']);
+
+        $params['rechargeNum'] = $this->encryptWithOpenssl($rcard_no);
+        $params['rechargePwd'] = $this->encryptWithOpenssl($rcard_key);
 
         $resp = http_request(config::ORDER_URL, $params , 'POST' , false , config::ExtHeaders);
         if ($resp === false) {
-            return [false, '系统错误', true];
-        } else {
+            return [false, '网络错误', true];
+        }
+        else
+        {
             Log::record($resp, Log::DEBUG);
             $resp = json_decode($resp ,true);
-            if($resp['code']['status'] == 100000) {
+
+            if($resp == false) {
+                return [false, '网络错误', true];
+            }
+
+            $status = intval($resp['code']['status']);
+
+            if($status == 100000) {
                 return [true, $resp['obj'], false];
             }
             return [false , $resp['code']['desc'], false];
@@ -104,17 +121,7 @@ class RefillPhone extends refill\IRefillPhone
     private function encryptWithOpenssl($data = '')
     {
         $key = substr(config::KEY , 0 ,16);
-        $iv = substr(config::KEY , -16);;
+        $iv = substr(config::KEY , -16);
         return base64_encode(openssl_encrypt($data, "AES-128-CBC", $key, OPENSSL_RAW_DATA, $iv));
     }
-
-    private function getrechargeCard($phone)
-    {
-        //判断手机号运营商,获取卡号卡密,产品编号
-        $rechargeNum = 1;
-        $rechargePwd = 2;
-        $productNo = 3;
-        return ['rechargeNum' => $rechargeNum , 'rechargePwd' => $rechargePwd , 'productNo' => $productNo];
-
-    }
 }

+ 4 - 1
helper/refill/api/lingzh/legou/config.php

@@ -3,7 +3,7 @@
 
 namespace refill\legou;
 
-
+use mtopcard;
 class config
 {
     const ORDER_URL = 'https://recv.shujubuy.com/api/recv/submitOrder';
@@ -13,4 +13,7 @@ class config
     const KEY = '953b8e10a70ef4e85b77f09448c0e316';
     const NOTIFY_URL = "https://www.xyzshops.cn/mobile/refill_legou.php";
     const ExtHeaders = ['ContentType: application/x-www-form-urlencoded;charset=utf-8'];
+
+    const ProductIDS = [mtopcard\ChinaMobileCard => 400002,mtopcard\ChinaUnicomCard => 400003,mtopcard\ChinaTelecomCard => 400004];
+    const StoreIDS = [];
 }

BIN
helper/refill/api/lingzh/legou/乐友充值接口.docx


+ 1 - 1
test/TestCardKey.php

@@ -29,7 +29,7 @@ class TestCardKey extends TestCase
     public function testGetUsable()
     {
         $amount = 1000;
-        [$ret,$info] = mtopcard\cards_helper::reserve(mtopcard\OilCardPaper,1000,35268,'xxxyyyzzzkkkdj',mtopcard\PetroChinaCard,0);
+        [$ret,$info] = mtopcard\cards_helper::reserve(mtopcard\OilCardPaper,1000,35268,'xxxyyyzzzkkkdj',mtopcard\PetroChinaCard,[0]);