Procházet zdrojové kódy

add inner store for sell oil

stanley-king před 4 roky
rodič
revize
586e9b9309

+ 2 - 1
data/config/dev/base.ini.php

@@ -107,4 +107,5 @@ $config['area_version'] = 5;
 $config['appjump_prefix'] = 'xyzshop://www.xyzshops.com';
 
 $config['client_setting'] = ['running' => 174,'home' => 0];
-$config['wsd_bradge_port'] = 60987;
+$config['wsd_bradge_port'] = 60987;
+$config['card_key_stores'] = [6];

+ 7 - 6
data/config/dev/refill.ini.php

@@ -18,14 +18,15 @@ $suhctm_oil = ['name' => 'suhctm', 'store_id' => 8, 'card_type' => ['sinopec'],
     'period' => ['start' => '8:30', 'end' => '22:30'], 'refill_type' => 'api'];
 
 $lx_oil = ['name' => 'lx', 'store_id' => 10, 'card_type' => ['sinopec'],
-    'amount' => [100 => ['goods_id' => 6234, 'price' => 99],
-        200 => ['goods_id' => 6235, 'price' => 198],
-        500 => ['goods_id' => 6236, 'price' => 495],
-        1000 => ['goods_id' => 6237, 'price' => 990],
-        2000 => ['goods_id' => 6238, 'price' => 1980]],
+    'amount' => [100 => ['goods_id' => 6234, 'price' => 95.5],
+        200 => ['goods_id' => 6235, 'price' => 191],
+        500 => ['goods_id' => 6236, 'price' => 477.5],
+        1000 => ['goods_id' => 6237, 'price' => 955],
+        2000 => ['goods_id' => 6238, 'price' => 1910]],
     'period' => ['start' => '8:30', 'end' => '22:30'], 'refill_type' => 'inner_store'];
 
-$oil_providers = ['suhc' => $suhc_oil, 'suhctm' => $suhctm_oil,'lx' => $lx_oil];
+//$oil_providers = ['suhc' => $suhc_oil, 'suhctm' => $suhctm_oil,'lx' => $lx_oil];
+$oil_providers = ['lx' => $lx_oil];
 $config['oil_providers'] = $oil_providers;
 
 

+ 1 - 1
helper/fcgi_server.php

@@ -29,7 +29,7 @@ class fcgi_server
             'cmbpay_notify.php','cmbpay_sign.php','wxauthor.php','api/wxLogin/index.php','api/wxLogin/callback.php',
             'signature.php',
             'refill_suhc.php','refill_suhctm.php','refill_beixt.php','refill_bxtwt.php','refill_bjb.php','refill_xyz.php',
-            'refill_zzx.php',
+            'refill_zzx.php','refill_inner.php',
             'bridge_shr.php'
         ];
         $path = BASE_ROOT_PATH . '/mobile/';

+ 19 - 8
helper/refill/RefillFactory.php

@@ -307,12 +307,15 @@ class RefillFactory
         $commit_times = $refill_info['commit_times'] + 1;
         $order_time = $refill_info['order_time'];
 
-        [$success,$err] = $this->add($mchid,$buyer_id,$amount,$card_no,$mch_order,$notify_url,$order_time,$commit_times);
+        $idcard = $refill_info['idcard'] ?? '';
+        $card_name = $refill_info['card_name'] ?? '';
+
+        [$success, $err] = $this->add($mchid, $buyer_id, $amount, $card_no, $mch_order, $idcard, $card_name, $notify_url, $order_time, $commit_times);
 
         return ($success === true);
     }
 
-    public function add($mchid, $buyer_id, $amount, $card_no, $mch_order, $notify_url, $order_time = 0, $commit_times = 0)
+    public function add($mchid, $buyer_id, $amount, $card_no, $mch_order, $idcard, $card_name, $notify_url, $order_time = 0, $commit_times = 0)
     {
         $card_type = mtopcard\card_type($card_no);
         $providers = $this->find_providers($amount, $card_type);
@@ -346,7 +349,8 @@ class RefillFactory
         usort($providers, $ascending);
 
         $refill_state = false;
-        foreach ($providers as $provider) {
+        foreach ($providers as $provider)
+        {
             $channel_name = $provider->name();
             [$goods_id, $price] = $provider->goods($amount);
 
@@ -366,7 +370,8 @@ class RefillFactory
             $result = $logic_buy_virtual->buyStep3($input, $buyer_id, [$calc, 'calc_vorder_amount'], true);
 
             $mod_refill = Model('refill_order');
-            if ($result['state'] === true) {
+            if ($result['state'] === true)
+            {
                 $order_sn = $result['data']['order_sn'];
                 $order_id = $result['data']['order_id'];
 
@@ -376,6 +381,7 @@ class RefillFactory
                 //虚拟订单表信息扩展
                 $orderext = ['order_id' => $order_id, 'order_sn' => $order_sn, 'mchid' => $mchid,
                     'refill_amount' => $amount, 'mch_order' => $mch_order,
+                    'idcard' => $idcard, 'card_name' => $card_name,
                     'notify_url' => $notify_url, 'channel_name' => $channel_name,
                     'mch_amount' => $mch_amount, 'channel_amount' => $price,
                     'order_time' => $order_time, 'commit_times' => $commit_times,
@@ -385,14 +391,19 @@ class RefillFactory
                 continue;
             }
 
-            $params = ['order_sn' => $order_sn];
+            $params = ['order_sn' => $order_sn, 'idcard' => $idcard, 'card_name' => $card_name];
             [$state, $err] = $provider->add($card_no, $card_type, $amount, $params);
-            if ($state) {
+            if ($state)
+            {
                 $trade_no = $err;
-                $logic_vr_order = Logic("vr_order");
-                $logic_vr_order->changeOrderStateSend($order_id);
+                if($provider->refill_type() == 'api') {
+                    $logic_vr_order = Logic("vr_order");
+                    $logic_vr_order->changeOrderStateSend($order_id);
+                }
+
                 $data = ['commit_time' => time(), 'ch_trade_no' => $trade_no];
                 $mod_refill->edit($order_id, $data);
+
                 $refill_state = true;
                 break;
             } else {

+ 9 - 54
helper/refill/lx/RefillCallBack.php

@@ -9,66 +9,21 @@ class RefillCallBack implements refill\IRefillCallBack
 {
     public function verify($params): bool
     {
-        $input = $params;
-        unset($input['sign']);
-
-        $sign = $this->sign($input);
-        if ($params['sign'] == $sign) {
-            return true;
-        } else {
-            return false;
-        }
-    }
-
-    private function check_empty($value)
-    {
-        if (!isset($value))
-            return true;
-        if ($value === null)
-            return true;
-        if (trim($value) === "")
-            return true;
-
-        return false;
-    }
-
-    private function sign($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}" . "=" . urldecode($v);
-                } else {
-                    $body .= "&" . "{$k}" . "=" . urldecode($v);
-                }
-                $i++;
-            }
-        }
-
-        $body .= "&key=" . config::KEY;
-        return md5($body);
+        return true;
     }
 
+    //        $params = ['state_type' => 'order_cancel','order_id' => 313,'channel_name' => 'lx'];
     public function notify($params)
     {
-        $status = intval($params['status']);
-        $order_sn = $params['onlystr'];
-
-        $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
-        if (empty($order_info)) {
-            return [false, false, false,false];
-        }
+        $state = $params['state_type'];
+        $order_id = $params['order_id'];
 
-        $order_id = $order_info['order_id'];
-        if ($status === 2) {
-            return [$order_id, true, false,true];
+        if ($state == 'order_success') {
+            return [$order_id, true, false, true];
+        } elseif ($state == 'order_cancel') {
+            return [$order_id, false, false, true];
         } else {
-            //速汇充反馈此时可以提交多次.
-            return [$order_id, false, true,true];
+            return [$order_id, false, false, false];
         }
     }
 }

+ 28 - 31
helper/refill/lx/RefillOil.php

@@ -17,42 +17,39 @@ class RefillOil extends refill\IRefillOil
         parent::__construct($cfgs);
     }
 
-    public function add($card_no,$card_type,$amount,$input)
+    public function add($card_no, $card_type, $amount, $input)
     {
-        return [true,$input['order_sn']];
-    }
-
-    public function query($refill_info)
-    {
-        $params['batchid'] = $refill_info['ch_trade_no'];
-        $params['orgid'] = config::ORGID;
-        $params['cardno'] = $refill_info['card_no'];
-        $params['onlystr'] = $refill_info['order_sn'];
-        $sign = $this->sign($params);
-        $params['sign'] = $sign;
-
-        $resp = http_request(config::ORDER_QUERY_URL,$params,'POST',false,config::ExtHeaders);
-        if($resp === false) {
-            return [false,'系统错误'];
+        //lx 加油需要身份证姓名
+        if (empty($input['card_name'])) {
+            return [false, '参数没有包含身份证姓名:card_name'];
         }
-        else
-        {
-            Log::record($resp,Log::DEBUG);
-            $resp = json_decode($resp,true);
-            if($resp['state'] == 0) {
-                return [true,$resp['data']];
-            }
-            else {
-                return [false,$resp['msg']];
-            }
+        else {
+            return [true, $input['order_sn']];
         }
     }
 
-    private function store()
+    public function query($refill_info)
     {
-        $count = count(config::STOREIDS);
-        $pos = mt_rand(0,$count - 1);
-
-        return config::STOREIDS[$pos];
+        return [true,''];
+
+//        $params['batchid'] = $refill_info['ch_trade_no'];
+//        $params['orgid'] = config::ORGID;
+//        $params['cardno'] = $refill_info['card_no'];
+//        $params['onlystr'] = $refill_info['order_sn'];
+//        $sign = $this->sign($params);
+//        $params['sign'] = $sign;
+//
+//        $resp = http_request(config::ORDER_QUERY_URL, $params, 'POST', false, config::ExtHeaders);
+//        if ($resp === false) {
+//            return [false, '系统错误'];
+//        } else {
+//            Log::record($resp, Log::DEBUG);
+//            $resp = json_decode($resp, true);
+//            if ($resp['state'] == 0) {
+//                return [true, $resp['data']];
+//            } else {
+//                return [false, $resp['msg']];
+//            }
+//        }
     }
 }

+ 1 - 17
helper/refill/lx/config.php

@@ -6,21 +6,5 @@ namespace refill\lx;
 
 class config
 {
-    const ORDER_URL = 'http://jiayouka.5800cc.com/kaOrder/createKaOrder.html';
-    const ORDER_QUERY_URL = 'http://jiayouka.5800cc.com/kaOrder/queryOrder.html';
-    const KEY = '7yDCLS6S2KzSAJQOUc3vsa';
-    const ORGID = 1590993600;
-    const NOTIFY_URL = BASE_SITE_URL . "/mobile/refill_suhc.php";
-    const STOREIDS = ['10280838',
-        '611127',
-        '10109062',
-        '10053330',
-        '10108936'
-//        '10114157',
-//        '10143029',
-//        '10109046',
-//        '10135551',
-//        '678278'
-        ];
-    const ExtHeaders = ['Content-Type: application/x-www-form-urlencoded' , 'Accept: application/json;charset=UTF-8'];
+
 }

+ 32 - 1
helper/vrorder_helper.php

@@ -8,9 +8,40 @@ class vrorder_helper
     //提供给商家管理后台.
     public static function extend_order_info($order)
     {
+        $order_id = $order['order_id'];
+        $refill_order = Model('refill_order');
+        $refill_info = $refill_order->getOrderInfo(['order_id' => $order_id]);
+
+        if(empty($refill_info)) {
+            return self::card_key_info($order);
+        } else {
+            return self::refill_info($refill_info);
+        }
+    }
+
+    private static function refill_info($refill_info)
+    {
+
+        if(empty($refill_info)) {
+            return [];
+        }
+        else {
+            $ret['接收卡'] = $refill_info['card_no'];
+            $ret['卡类别'] = mtopcard\scard_type($refill_info['card_type']);
+            $ret['身份证号码'] = $refill_info['idcard'];
+            $ret['身份证姓名'] = $refill_info['card_name'];
+//            $ret['卡号'] = $item['card_no'];
+//            $ret['卡密'] = $item['card_key'];
+
+            return $ret;
+
+        }
+    }
+
+    private static function card_key_info($order)
+    {
         global $config;
         $handlers = $config['vgoods_handlers'];
-
         $goods_id = $order['goods_id'];
         if(array_key_exists($goods_id,$handlers))
         {

+ 5 - 1
mobile/control/merchant_refill.php

@@ -88,6 +88,10 @@ class merchant_refillControl extends mbMerchantControl
         if(empty($card_no)){
             return self::outerr(errcode::ErrParamter, "卡号格式错误或未上传");
         }
+
+        $idcard = $params['idcard'] ?? '';
+        $card_name = $params['card_name'] ?? '';
+
         //成功个数、失败个数
         $success_no = $error_no = 0;
         $data = [];
@@ -104,7 +108,7 @@ class merchant_refillControl extends mbMerchantControl
             }
             else
             {
-                [$state,$err] = refill\RefillFactory::instance()->add($mchid,$merchant_info['admin_id'],$amount,$no,'','');
+                [$state, $err] = refill\RefillFactory::instance()->add($mchid, $merchant_info['admin_id'], $amount, $no, '', $idcard, $card_name, '');
                 $arr['state'] = $state;
                 $arr['err'] = $err;
                 if($state === true) {

+ 3 - 1
mobile/control/refill.php

@@ -82,8 +82,10 @@ class refillControl extends merchantControl
         $card_no = $_GET['cardno'];
         $notify_url = $_GET['notifyurl'];
         $mch_order = $_GET['order_sn']; //对方的order编号
+        $idcard = $_GET['idcard'] ?? '';
+        $card_name = $_GET['card_name'] ?? '';
 
-        [$state,$err] = refill\RefillFactory::instance()->add($this->mchid(),$this->adminid(),$amount,$card_no,$mch_order,$notify_url);
+        [$state, $err] = refill\RefillFactory::instance()->add($this->mchid(), $this->adminid(), $amount, $card_no, $mch_order, $idcard, $card_name, $notify_url);
         if($state === true) {
             return self::outsuccess(['state' => true]);
         }

+ 10 - 0
mobile/refill_inner.php

@@ -0,0 +1,10 @@
+<?php
+
+require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
+
+$channel_name = $_POST['channel_name'];
+
+refill\RefillFactory::instance()->notify($channel_name,$_POST);
+
+echo ('success');
+

+ 51 - 13
shop/control/store_vr_order.php

@@ -9,6 +9,8 @@
 
 defined('InShopNC') or exit('Access Invalid!');
 require_once(BASE_HELPER_PATH . '/vrorder_helper.php');
+require_once(BASE_CORE_PATH . '/framework/function/http.php');
+
 
 class store_vr_orderControl extends BaseSellerControl
 {
@@ -72,7 +74,8 @@ class store_vr_orderControl extends BaseSellerControl
 	 * 卖家订单详情
 	 *
 	 */
-	public function show_orderOp() {
+	public function show_orderOp()
+    {
 	    $order_id = intval($_GET['order_id']);
 	    if ($order_id <= 0) {
 	        showMessage(Language::get('wrong_argument'),'','html','error');
@@ -106,6 +109,7 @@ class store_vr_orderControl extends BaseSellerControl
         }
 
         Tpl::output('order_info',$order_info);
+        Tpl::output('order_info',$order_info);
 		Tpl::showpage('store_vr_order.show');
 	}
 
@@ -122,23 +126,57 @@ class store_vr_orderControl extends BaseSellerControl
         $extra_info = vrorder_helper::extend_order_info($order_info);
         $order_info['extend_order_info'] = $extra_info;
 
-	    if ($_GET['state_type'] == 'order_cancel') {
-	        $result = $this->_order_cancel($order_info,$_POST);
-	    }
-        elseif ($_GET['state_type'] == 'order_send') {
-            $result = $this->_order_send($order_info,$_POST);
+        $order_id = $order_info['order_id'];
+        $refill_order = Model('refill_order');
+        $refill_info = $refill_order->getOrderInfo(['order_id' => $order_id]);
+
+        $isRefill = empty($refill_info) ? false : true;
+
+        if($isRefill)
+        {
+            $state_type = $_GET['state_type'];
+            if($state_type == 'order_send') {
+                $result = $this->_order_send($order_info,$_POST);
+                if(!$result['state']) {
+                    showDialog($result['msg'],'','error');
+                } else {
+                    showDialog($result['msg'],'reload','js');
+                }
+            }
+            else {
+                $order_id = $order_info['order_id'];
+                $params = ['state_type' => $state_type,'order_id' => $order_id,'channel_name' => $refill_info['channel_name']];
+                $resp = http_request(BASE_SITE_URL . '/mobile/refill_inner.php',$params,'POST');
+                if($resp !== 'success') {
+                    showDialog("失败",'','error');
+                } else {
+                    showDialog("成功",'reload','js');
+                }
+            }
         }
-        elseif ($_GET['state_type'] == 'order_success') {
-            $result = $this->_order_success($order_info,$_POST);
+        else
+        {
+            if ($_GET['state_type'] == 'order_cancel') {
+                $result = $this->_order_cancel($order_info,$_POST);
+            }
+            elseif ($_GET['state_type'] == 'order_send') {
+                $result = $this->_order_send($order_info,$_POST);
+            }
+            elseif ($_GET['state_type'] == 'order_success') {
+                $result = $this->_order_success($order_info,$_POST);
+            }
+
+            if(!$result['state']) {
+                showDialog($result['msg'],'','error');
+            } else {
+                showDialog($result['msg'],'reload','js');
+            }
         }
 
-	    if(!$result['state']) {
-	        showDialog($result['msg'],'','error');
-	    } else {
-	        showDialog($result['msg'],'reload','js');
-	    }
+
 	}
 
+
 	/**
 	 * 取消订单
 	 * @param arrty $order_info

+ 11 - 2
shop/templates/default/seller/store_vr_order.show.php

@@ -48,6 +48,8 @@
                 $uri = '';
             }
 
+            $cancel_uri = "index.php?act=store_vr_order&op=change_state&state_type=order_cancel&order_id={$order_id}&order_sn={$order_sn}";
+
             if(!empty($output['order_info']['extend_order_info'])) { ?>
               <dl class="line">
                   <dt>附加信息:</dt>
@@ -66,7 +68,7 @@
                  dialog_title="已经处理尚未到账订单"
                  dialog_id="buyer_order_send_order"
                  uri=<?php echo($uri) ?>
-                 id="order_action_success">订单已经处理了</a>
+                 id="order_action_success">开始处理订单</a>
               </dd>
              <?php } elseif ($output['order_info']['order_state'] == ORDER_STATE_SEND){ ?>
                  <a href="javascript:void(0)" class="ncsc-btn-mini" nc_type="dialog" dialog_width="480"
@@ -75,9 +77,16 @@
                     uri=<?php echo($uri) ?>
                     id="order_action_success">订单处理完成了</a>
                  </dd>
+                 <dd>
+                     <a href="javascript:void(0)" class="ncsc-btn-mini" nc_type="dialog" dialog_width="480"
+                        dialog_title="已经处理尚未到账订单"
+                        dialog_id="buyer_order_send_order"
+                        uri=<?php echo($cancel_uri) ?>
+                        id="order_action_success">取消订单</a>
+                 </dd>
              <?php }?>
-          </dl>
 
+          </dl>
           <?php } ?>
       </div>
     </div>

+ 1 - 0
test/TestRBridge.php

@@ -129,4 +129,5 @@ class TestRBridge extends TestCase
 
         return $sign;
     }
+
 }

+ 28 - 5
test/TestRefill.php

@@ -17,13 +17,13 @@ require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
 const LocalTest = 1;
 const NetTest = 2;
 
-const CurrentTest = NetTest;
+const CurrentTest = LocalTest;
 
 class TestRefill extends TestCase
 {
-    private $mReqHost = '';
-    private $mKey = '';
-    private $mMchid = 0;
+    private $mReqHost;
+    private $mKey;
+    private $mMchid;
 
     public function __construct(?string $name = null, array $data = [], $dataName = '')
     {
@@ -366,7 +366,6 @@ class TestRefill extends TestCase
     {
         $body = $this->body($params);
         $body .= "&key={$this->mKey}";
-//        $body .= "&key=ZhongFKJZhongFKJZhongFKJ";
         $params['sign'] = md5($body);
 
         $resp = http_request($url, $params, 'POST');
@@ -451,4 +450,28 @@ class TestRefill extends TestCase
         $ipwhitelist = unserialize($merchant_info['ip_white_list']);
         $res = json_encode($ipwhitelist);
     }
+
+    //测试向内部店提交订单,可先屏蔽其它充值通道
+    public function testAddoilToInnerStore()
+    {
+        $url = $this->mReqHost . "/mobile/index.php";
+        $notifyurl = BASE_SITE_URL . '/mobile/signature.php';
+        $params = ['mchid' => 1,
+            'cardno' => '1000111100020445281',
+            'amount' => "1000",
+            "act" => "refill",
+            "op" => "add",
+            'card_name' => '江海苗',
+            'order_sn' => $this->make_sn(),
+            'notifyurl' => $notifyurl];
+
+        $resp = $this->send_md5($url, $params);
+        Log::record($resp, Log::DEBUG);
+    }
+
+    public function testRefillInnerCB()
+    {
+        $params = ['state_type' => 'order_cancel','order_id' => 311,'channel_name' => 'lx'];
+        $resp = http_request(BASE_SITE_URL . '/mobile/refill_inner.php',$params,'POST');
+    }
 }