stanley-king 4 vuotta sitten
vanhempi
commit
f2fa14e26b

+ 15 - 1
data/config/dev/refill.ini.php

@@ -351,4 +351,18 @@ $phone_providers = [
     ['name' => 'weiyi', 'cfg' => $weiyi_phone],
     ['name' => 'tonglu', 'cfg' => $tonglu_phone],
 ];
-$config['phone_providers'] = $phone_providers;
+$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]
+];
+$config['third_providers'] = $third_providers;

+ 2 - 0
helper/mtopcard/mtopcard.php

@@ -15,6 +15,8 @@ const ChinaMobileCard  = 4;        //手机卡
 const ChinaUnicomCard  = 5;        //手机卡
 const ChinaTelecomCard = 6;        //手机卡
 
+const ThirdRefillCard  = 7;        //三方账号充值
+
 
 #卡的状态
 const CardNormal = 1;

+ 1 - 1
helper/refill/CalcMerchantPrice.php

@@ -13,7 +13,7 @@ use Log;
 class CalcMerchantPrice implements ICalc
 {
     private $mPrice;
-    public function __construct($mchid,$spec,$card_type,$quality,$policy)
+    public function __construct($mchid,$spec,$card_type,$quality,$policy,$pcode='',$count=1)
     {
         $price = $policy->price($mchid,$spec,$card_type,$quality);
 

+ 2 - 2
helper/refill/RefillBase.php

@@ -235,9 +235,9 @@ class RefillBase
     //     其它情况,则需要判断订单ID
     public function add($mchid, $buyer_id, $amount, $card_no,
                         $mch_order, $idcard, $card_name, $notify_url, $quality, $org_quality,
-                        $order_time, $commit_times, $last_orderid = 0, $card_type = 0,$regin_no = 0)
+                        $order_time, $commit_times, $last_orderid = 0, $card_type = 0,$regin_no = 0,$other = [])
     {
-        if($card_type == 0) {
+        if($card_type == 0 && $card_type != mtopcard\ThirdRefillCard ) {
             $card_type = mtopcard\card_type($card_no,$regin_no);
         }
         [$providers, $overload] = $this->mPolicy->find_providers($mchid,$amount, $card_type, $quality, $regin_no);

+ 13 - 0
helper/refill/api/lingzh/app/RefillPhone.php

@@ -14,6 +14,19 @@ class RefillPhone extends refill\IRefillPhone
         parent::__construct($cfgs);
     }
 
+    public function goods($quality,int $amount,int $card_type)
+    {
+        $maps = $this->mAmountTypes[$quality] ?? [];
+        $key = "{$amount}-{$card_type}";
+        if(array_key_exists($key,$maps)) {
+            $params = $maps[$key];
+            return [$params['goods_id'], round($params['price'],2)];
+        }
+        else {
+            return [];
+        }
+    }
+
     private function req_params(string $order_sn, string $product_code)
     {
         $params['AppKey'] = config::APP_KEY;

+ 10 - 0
helper/refill/util.php

@@ -218,6 +218,16 @@ class util
         }
     }
 
+    public static function push_addthird($params)
+    {
+        try {
+            queue\DispatcherClient::instance()->push('addthird', $params);
+            return true;
+        } catch (Exception $ex) {
+            return false;
+        }
+    }
+
     public static function push_notify($chname, $params)
     {
         try {

+ 96 - 0
racc/control/lzrefill.php

@@ -108,6 +108,102 @@ class lzrefillControl extends lzbaseControl
         }
     }
 
+    private function check_third($params)
+    {
+        if(empty($params['product_code'])) {
+            return -9;
+        }
+        if(empty($params['quantity'])) {
+            return -9;
+        }
+
+        $card_no = $params['card_no'];
+        if(empty($card_no)) {
+            return -9;
+        }
+
+        $third_card_type = $params['card_type'];
+        if(empty($third_card_type)) {
+            return -9;
+        }
+
+        if(empty($params['notifyurl'])) {
+            return -9;
+        }
+
+        if(empty($params['ord'])) {
+            return -9;
+        }
+
+        if(empty($params['tim'])) {
+            return -9;
+        }
+
+        $tim = strtotime($params['tim']);
+        if($tim === false) {
+            return -9;
+        }
+
+        $cur = time();
+        $start = strtotime(date('Y-m-d',$cur - 1800));
+        if($tim < $start || $tim > $cur + 1800) {
+            return -9;
+        }
+
+        return true;
+    }
+
+    public function add_thirdOp()
+    {
+        $code = $this->check_params($_GET);
+        if($code !== true) {
+            return self::outerr($code,$this->merchant_available);
+        }
+
+        $amount = 10;
+        $mch_order = $_GET['ord'];
+        $notify_url = $_GET['notifyurl'];
+
+        //三方充值没有质量
+        $quality = 1;
+        $card_type = 7;
+
+        $product_code = $_GET['product_code'];
+        $card_no = $_GET['mob'];
+        $quantity = $_GET['quantity'];
+        $third_card_type = $_GET['card_type'];
+
+        //此处判断是对的
+        if($this->member_available <= 0) {
+            return self::outerr(4,$this->merchant_available);
+        }
+
+        if(!$this->check_mchorder($this->mchid(),$mch_order)) {
+            return self::outerr(11,$this->merchant_available);
+        }
+
+        $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,
+            'card_type' => $card_type,
+            'product_code' => $product_code,
+            'quantity' => $quantity,
+            'third_card_type' => $third_card_type
+        ];
+
+        $ret = refill\util::push_addthird($params);
+        if($ret) {
+            return self::outsuccess($this->merchant_available);
+        }
+        else {
+            return self::outerr(-6,$this->merchant_available);
+        }
+    }
+
     private function can_refill($cardno)
     {
         $card_info = refill\util::read_card($cardno);

+ 3 - 0
rdispatcher/processor.php

@@ -56,6 +56,9 @@ class processor extends queue\ILooper
                         $order_id = intval($params['order_id']);
                         $this->mProxy->manual_cancel($order_id);
                     }
+                    if ($method == 'addthird') {
+                        $this->mProxy->addthird($params);
+                    }
                     else {
                         Log::record("Error Method={$method}", Log::DEBUG);
                     }

+ 79 - 1
rdispatcher/proxy.php

@@ -141,8 +141,86 @@ class proxy
     public function manual_success($order_id)
     {
         refill\RefillFactory::instance()->manual_success($order_id);
-    }    public function manual_cancel($order_id)
+    }
+    public function manual_cancel($order_id)
     {
         refill\RefillFactory::instance()->manual_cancel($order_id);
     }
+
+    public function addthird($params)
+    {
+        $refill_order = Model('refill_order');
+
+        $mchid = $params['mchid'];
+        $buyer_id = $params['buyer_id'];
+        $amount = intval($params['amount']);
+
+        $card_no = $params['card_no'];
+        $mch_order = $params['mch_order'];
+        $notify_url = $params['notify_url'];
+        $idcard = $params['idcard'] ?? '';
+        $card_name = $params['card_name'] ?? '';
+
+        $order_time = $params['order_time'] ?? time();
+        $commit_times = $params['commit_times'] ?? 0;
+        $last_order_id = $params['order_id'] ?? 0;
+
+        $org_quality = intval($params['org_quality']) ?? 0;
+        $card_type   = intval($params['card_type']) ?? 0;
+        $regin_no   = intval($params['regin_no']) ?? 0;
+
+        Log::record("proxy::add mch_order={$mch_order} card_no = {$card_no}",Log::DEBUG);
+
+        refill\util::incr_user_commit($card_type,$amount);
+
+        [$errcode, $errmsg, $order_id, $neterr] = refill\RefillFactory::instance()->add($mchid, $buyer_id, $amount, $card_no,
+            $mch_order, $idcard, $card_name, $notify_url, $quality,$org_quality,
+            $order_time, $commit_times, $last_order_id,$card_type,$regin_no);
+        $params['commit_times'] += 1;
+        $commit_times += 1;
+
+        if(!empty($mch_order) && $last_order_id == 0 && $order_id > 0) {
+            refill\util::pop_queue($mchid,$mch_order);
+        }
+
+        if($errcode !== true)
+        {
+            $fNotify = true;
+            if(($errcode === refill\errcode::MERCHANT_REFILL_ERROR && $neterr) || $errcode == refill\errcode::PROVIDER_OVERLOAD || $errcode == errcode::MERCHANT_PRICE_UNSETTING)
+            {
+                [$org_quality,$quality] = refill\RefillFactory::instance()->find_quality($mchid,$amount,$card_type,$org_quality,$commit_times,time() - $order_time);
+                if ($quality > 0) {
+                    $fNotify = false;
+                    $params['order_id'] = $order_id;
+                    if($order_id > 0) {
+                        $refill_order->edit($order_id, ['is_retrying' => 1]);
+                    }
+                    if(defined('USE_COROUTINE') && USE_COROUTINE && $errcode == refill\errcode::PROVIDER_OVERLOAD) {
+                        \Swoole\Coroutine::sleep(1);
+                    }
+                    refill\util::push_add($params);
+                }
+            }
+
+            if($fNotify)
+            {
+                if ($order_id === 0)
+                {
+                    $order_info = $this->latest_order($refill_order, $mchid, $mch_order);
+                    if (empty($order_info)) {
+                        $order_id = refill\RefillFactory::instance()->zero_order($mchid, $buyer_id, $amount, $card_no,
+                            $mch_order, $idcard, $card_name, $notify_url, $quality, $org_quality, $order_time, $commit_times, $errmsg);
+                        refill\util::pop_queue($mchid,$mch_order);
+                    } else {
+                        $order_id = $order_info['order_id'];
+                    }
+                }
+                else {
+                    $refill_order->edit($order_id, ['notify_time' => time(), 'notify_state' => 1,'is_retrying' => 0]);
+                }
+
+                QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => false]);
+            }
+        }
+    }
 }