stanley-king 1 năm trước cách đây
mục cha
commit
0f399fbae8

+ 1 - 1
admin/control/control.php

@@ -123,7 +123,7 @@ class SystemControl
 		if (in_array($act,$permission) || in_array("$act.$op",$permission)){
 			return true;
 		}else{
-			$extlimit = array('ajax','export_step1');
+			$extlimit = ['ajax','export_step1'];
 			if (in_array($op,$extlimit) && (in_array($act,$permission) || strpos(serialize($permission),'"'.$act.'.'))){
 				return true;
 			}

+ 61 - 0
admin/control/remote.php

@@ -0,0 +1,61 @@
+<?php
+
+require_once(BASE_PATH.'/control/signbase.php');
+include(BASE_CONFIG_PATH . CONFIG_PREFIX . '/refill.ini.php');
+
+class RemoteControl extends SignbaseControl
+{
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    public function merchantsOp()
+    {
+        $mod_merchant = Model('merchant');
+        $items = $mod_merchant->table('merchant')
+            ->field('mchid,name,company_name')
+            ->where(['merchant_state' => 1])->limit(0,1000)->select();
+
+        $result = [];
+        foreach ($items as $item) {
+            $mchid = $item['mchid'];
+            $name = $item['company_name'];
+            $result[$mchid] = $name;
+        }
+
+        return $this->success($result);
+    }
+
+    public function channelsOp()
+    {
+        $items = Model('')->table('refill_provider,store')
+            ->field('refill_provider.*,store.store_name')
+            ->join('inner')
+            ->on('store.store_id=refill_provider.store_id')
+            ->where(['opened' => 1])
+            ->limit(1000)
+            ->select();
+
+        $result = [];
+        foreach ($items as $item)
+        {
+            $store_id = $item['store_id'];
+            $store_name = $item['store_name'];
+            $result[$store_id] = $store_name;
+        }
+
+        return $this->success($result);
+    }
+
+    public function produceOp()
+    {
+//        try {
+//            $pcoder = new third_pcode($node);
+//            $pcoder->produce();
+//        }
+//        catch (Exception $ex) {
+//
+//        }
+    }
+}

+ 70 - 0
admin/control/signbase.php

@@ -0,0 +1,70 @@
+<?php
+
+class SignbaseControl
+{
+    private $mKey = 'a92e98ce82a9e104faa9ea1c7df4c9cd';
+    public function __construct()
+    {
+        $input = $_REQUEST;
+        if(!$this->verify($this->mKey,$input)) {
+            throw_exception('签名认证失败.');
+        }
+    }
+
+    public function success($data)
+    {
+        $out = ['code' => 200,'data' =>$data,'message' => 'success'];
+        echo(json_encode($out));
+        return true;
+    }
+    public function error($code = 201,$msg = 'fail')
+    {
+        $out = ['code' => $code,'data' => [],'message' => $msg];
+        echo(json_encode($out));
+        return true;
+    }
+
+
+    private function verify($key,$input)
+    {
+        $sign = $input['sign'];
+        unset($input['sign']);
+
+        $body = $this->body($input);
+        $body .= "&key=$key";
+
+        return ($sign == md5($body));
+    }
+
+    private function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
+    private function body($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}" . "=" . urlencode($v);
+                } else {
+                    $body .= "&" . "{$k}" . "=" . urlencode($v);
+                }
+                $i++;
+            }
+        }
+        return $body;
+    }
+}

+ 2 - 1
composer.json

@@ -2,6 +2,7 @@
     "require": {
         "phpoffice/phpspreadsheet": "^1.22",
       "ext-json": "*",
-      "ext-redis": "*"
+      "ext-redis": "*",
+      "ext-mysqli": "*"
     }
 }

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

@@ -56,14 +56,14 @@ if(SSH_TUNEL_PROD ==='local') {
     $config['db'][1]['dbport']       = '3306';
     $config['db'][1]['dbuser']       = 'root';
     $config['db'][1]['dbpwd']        = '55668899';
-    $config['db'][1]['dbname']       = 'ylshop';
+    $config['db'][1]['dbname']       = 'xyzshop';
     $config['db'][1]['dbcharset']    = 'UTF-8';
 
     $config['db']['slave'][0]['dbhost']     = SLAVE_DBHOST;
     $config['db']['slave'][0]['dbport']     = '3306';
     $config['db']['slave'][0]['dbuser']     = 'root';
     $config['db']['slave'][0]['dbpwd']      = '55668899';
-    $config['db']['slave'][0]['dbname']     = 'ylshop';
+    $config['db']['slave'][0]['dbname']     = 'xyzshop';
     $config['db']['slave'][0]['dbcharset']  = 'UTF-8';
 }
 if(SSH_TUNEL_PROD ==='workcuda') {

+ 1 - 1
docker/compose/homecuda/admin/docker-compose.yml

@@ -8,7 +8,7 @@ services:
     volumes:
       - ../../../../:/var/www/html
       - ../conf/etc/localtime:/etc/localtime:ro
-      - ../conf/php/php-debug.ini:/usr/local/etc/php/php.ini
+      - ../conf/php/php.ini:/usr/local/etc/php/php.ini
       - ../conf/php/mch-spwan-start:/usr/local/bin/docker-spwan-start
       - /mnt/upload:/var/www/html/data/upload
       - /mnt/shoplog:/var/www/html/data/log

+ 188 - 0
helper/refill/ops/third_pcode.php

@@ -0,0 +1,188 @@
+<?php
+
+namespace refill;
+
+use think\Model;
+use const mtopcard\ThirdOnlineProduct;
+use const mtopcard\ThirdRefillCard;
+use Exception;
+
+class third_pcode
+{
+    private $product_name;
+    private $product_amount;
+    private $plat_code;
+    private $mch_id;
+    private $mch_price;
+    private $store_code;
+    private $store_id;
+    private $store_price;
+
+    /**
+     * @throws Exception for node 数据有错误.
+     */
+    public function __construct($node)
+    {
+        if(!$this->check($node)) {
+            throw new Exception('');
+        }
+
+        $this->product_amount = intval($node['product_amount'] ?? 0);
+        $this->product_name = $node['product_name'];
+
+        $this->plat_code = $node['plat_code'];
+        $this->mch_id = intval($node['mch_id']);
+        $this->mch_price = ncPriceFormat($node['mch_price']);
+
+        $this->store_code = $node['store_code'];
+        $this->store_id = intval($node['store_id']);
+        $this->store_price = ncPriceFormat($node['store_price']);
+    }
+
+    private function check($node) : bool
+    {
+        if(empty($node['product_name'])) return false;
+        if(empty($node['plat_code'])) return false;
+        if(empty($node['store_code'])) return false;
+        if($node['product_amount'] <= 0) return false;
+        if($node['mch_id'] <= 0) return false;
+        if($node['store_id'] <= 0) return false;
+        if(empty($node['mch_price'])) return false;
+        if(empty($node['store_price'])) return false;
+
+        return true;
+    }
+
+    public function produce()
+    {
+        [$succ,$msg] = $this->mk_plat_code();
+        if(!$succ) {
+            return [false,$msg];
+        }
+
+        [$succ,$msg] = $this->mk_store_code();
+        if(!$succ) {
+            return [false,$msg];
+        }
+
+
+        [$succ,$msg] = $this->set_mch_price();
+        if(!$succ) {
+            return [false,$msg];
+        }
+    }
+
+    private function mk_plat_code()
+    {
+        $isExiter = function ($mod_third,$pcode) {
+            $item = $mod_third->findThirdProduct($pcode);
+            return empty($item);
+        };
+
+        $mod_third = Model('refill_third');
+
+        if($isExiter($mod_third,$this->plat_code)) {
+            return [false,'已经有这个产品编码'];
+        }
+
+        $val = [
+            'system_code' => $this->plat_code,
+            'product_name' => $this->product_name,
+            'refill_amount' => $this->product_amount,
+            'product_type' => ThirdOnlineProduct
+        ];
+        $ret = $mod_third->addThirdProduct($val);
+
+        return [true,$ret];
+    }
+
+    private function mk_store_code()
+    {
+        $channel_namer = function ($store_id)
+        {
+            $mod = Model('refill_provider');
+            $item = $mod->getProviderInfo(['store_id' => $store_id]);
+            if(empty($item)) {
+                return false;
+            } else {
+                return $item['name'];
+            }
+        };
+
+        $good_finder = function ($chname)
+        {
+            global $config;
+            $cfg_map = $config['third_providers'];
+            $goods_id = 0;
+            foreach ($cfg_map as $cfg) {
+                if($cfg['name'] != $chname) continue;
+                $goods_id = $cfg['cfg']['amount'][100][0]['goods_id'];
+            }
+
+            return $goods_id;
+        };
+
+        $store_product_add = function ($ch_name,$goods_id)
+        {
+            $mod = Model('refill_third');
+            $insert['channel_name'] = $ch_name;
+            $insert['store_id'] = $this->store_id;
+            $insert['channel_product_name'] = $this->product_name;
+            $insert['goods_id'] = $goods_id;
+
+            $insert['channel_code'] = $this->store_code;
+            $insert['channel_amount'] = $this->store_price;
+            $insert['recharge_type'] = 1; //直冲
+            $insert['system_code'] = $this->plat_code;
+            $insert['product_type'] = ThirdOnlineProduct;
+            $result = $mod->addProviderProduct($insert);
+
+            return $result;
+        };
+
+
+        $ch_name = $channel_namer($this->store_id);
+        if(empty($ch_name)) {
+            return [false,'无法找到通道名称.'];
+        }
+
+        $goods_id = $good_finder($ch_name);
+        if($goods_id == 0) {
+            return [false,'无法找到通道对应的goods id.'];
+        }
+
+        $ret = $store_product_add($ch_name,$goods_id);
+        return [true,$ret];
+    }
+
+    private function set_mch_price()
+    {
+        $isExist = function ($mchid,$pcode)
+        {
+            $item = Model('')->table('merchant_price')
+                ->where(['mchid' => $mchid, 'quality' => 1, 'pcode' => $this->plat_code])->find();
+            return !empty($item);
+        };
+
+        $model_merchant = Model('merchant');
+
+        $val['mchid'] = $this->mch_id;
+        $val['spec'] = $this->product_amount;
+        $val['price'] = $this->mch_price;
+        $val['card_types'] = ThirdRefillCard;
+        $val['quality'] = 1;
+        $val['pcode'] = $this->plat_code;
+
+        if (!$isExist($this->mch_id, $this->plat_code)) {
+            $ret = $model_merchant->table('merchant_price')->insert($val);
+        }
+        else
+        {
+            $ret = $model_merchant->table('merchant_price')
+                ->where(['mchid' => $this->mch_id, 'quality' => 1, 'pcode' => $this->plat_code])
+                ->update($val);
+        }
+
+        return [true,$ret];
+    }
+}

+ 0 - 3
test/TestFcode.php

@@ -23,9 +23,6 @@ class TestFcode extends PHPUnit_Framework_TestCase
     {
         Base::run_util();
     }
-
-
-
     public function testManager()
     {
         $manager = fcode\present_manager::instance();

+ 86 - 0
test/TestRemote.php

@@ -0,0 +1,86 @@
+<?php
+
+
+use PHPUnit\Framework\TestCase;
+
+define('APP_ID', 'test');
+define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
+
+require_once(BASE_ROOT_PATH . '/global.php');
+require_once(BASE_CORE_PATH . '/lrlz.php');
+require_once(BASE_ROOT_PATH . '/fooder.php');
+require_once(BASE_HELPER_PATH . '/refill/ops/third_pcode.php');
+
+
+use refill\third_pcode;
+
+class TestRemote extends TestCase
+{
+    public static function setUpBeforeClass(): void
+    {
+        Base::run_util();
+    }
+
+    public function testMerchants()
+    {
+        $mod_merchant = Model('merchant');
+        $items = $mod_merchant->table('merchant')
+            ->field('mchid,name,company_name')
+            ->where(['merchant_state' => 1])->limit(0,1000)->select();
+
+        $result = [];
+        foreach ($items as $item)
+        {
+            $mchid = $item['mchid'];
+            $name = $item['company_name'];
+            $result[$mchid] = $name;
+        }
+
+        $x = $result;
+    }
+
+    public function testProviders()
+    {
+        $items = Model('')->table('refill_provider,store')
+            ->field('refill_provider.*,store.store_name')
+            ->join('inner')
+            ->on('store.store_id=refill_provider.store_id')
+            ->where(['opened' => 1])
+            ->limit(1000)
+            ->select();
+
+        $result = [];
+        foreach ($items as $item)
+        {
+//            $data = [];
+//            $data['channel_name'] = $item['name'];
+//            $data['store_name'] = $item['store_name'];
+//            $data['provider_id'] = $item['provider_id'];
+//            $data['store_id'] = $item['store_id'];
+
+            $store_id = $item['store_id'];
+            $store_name = $item['store_name'];
+
+            $result[$store_id] = $store_name;
+        }
+
+        $x = $result;
+    }
+
+    public function testProduce()
+    {
+        $node = [
+            'mch_id' => 1092, 'mch_price' => 10000, 'plat_code' => 'YZBIG20230731',
+            'store_id' => 210, 'store_price' => 9900, 'store_code' => 'YLBIG20230731',
+            'product_name' => '大面额一万元', 'product_amount' => 10000
+        ];
+
+        try {
+            $pcoder = new third_pcode($node);
+            $pcoder->produce();
+        }
+        catch (Exception $ex) {
+            Log::record($ex->getMessage(),Log::ERR);
+        }
+    }
+}