root 1 year ago
parent
commit
2eb7cea698

+ 3 - 1
database/account.php

@@ -316,7 +316,9 @@ return array
         ),
         'list_button' => array
         (
-        	'list' => array('商户列表', '"yspay_merchant&search_option_account_id={id}&oper_table=account"', '"{type}" == "yspay"'),
+        	'list' => array('主体列表', '"yspay_main&search_option_account_id={id}&parent=account"', '"{type}" == "yspay"'),
+
+        	//'list' => array('商户列表', '"yspay_merchant&search_option_account_id={id}&oper_table=account"', '"{type}" == "yspay"'),
 
 			//'list1' => array('资管', '"yspay_sign&search_option_account_id={id}&oper_table=account"', '"{type}" == "yspay"'),
         ),

+ 27 - 27
database/yspay.php

@@ -55,6 +55,16 @@ return array
 			'update'	=> 'text',
 		),
 
+		'cash_jy_per'		=> array
+		(
+			'type' 		=> 'varchar-11',
+			'name' 		=> '平台交易手续费百分比-如输入10,就是从总支付金额中收取10%手续费,这个会自动扣掉,输入0.1就是千分之1',
+			'default' 	=> '',
+			'desc' 		=> '平台交易手续费百分比',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+		),
+
 		'sign_key'		=> array
 		(
 			'type' 		=> 'varchar-150',
@@ -130,76 +140,66 @@ return array
 		'cash_groupid'		=> array
 		(
 			'type' 		=> 'varchar-200',
-			'name' 		=> '平台分账集团号',
+			'name' 		=> '集团号',
 			'default' 	=> '',
-			'desc' 		=> '平台分账集团号',
+			'desc' 		=> '集团号',
 			'match' 	=> 'is_string',
 			'update'	=> 'text',
 			'show'		=> 'type=2',
 		),
 
-		'cash_jy_per'		=> array
-		(
-			'type' 		=> 'varchar-11',
-			'name' 		=> '平台交易手续费百分比-如输入10,就是从总支付金额中收取10%手续费,这个会自动扣掉,输入0.1就是千分之1',
-			'default' 	=> '',
-			'desc' 		=> '平台交易手续费百分比',
-			'match' 	=> 'is_numeric',
-			'update'	=> 'text',
-		),
-
 		'cash_per'		=> array
 		(
 			'type' 		=> 'int-11',
-			'name' 		=> '平台分账百分比-如输入10,就是从总支付金额中分账10%',
+			'name' 		=> '主体分账百分比-如输入10,就是从总支付金额中分账10%',
 			'default' 	=> '10',
-			'desc' 		=> '平台分账百分比',
+			'desc' 		=> '主体分账百分比',
 			'match' 	=> 'is_numeric',
-			'update'	=> 'text',
+			//'update'	=> 'text',
 			'show'		=> 'type=2',
 		),
 
 		'cash_type'		=> array
 		(
 			'type' 		=> 'tinyint-1',
-			'name' 		=> '平台分账类型',
+			'name' 		=> '主体分账类型',
 			'default' 	=> '1',
-			'desc' 		=> '平台分账类型',
+			'desc' 		=> '主体分账类型',
 			'match' 	=> 'is_string',
-			'update'	=> 'radio',
+			//'update'	=> 'radio',
 			'option'	=> $cash_type,
 		),
 
 		'cash_mid'		=> array
 		(
 			'type' 		=> 'varchar-200',
-			'name' 		=> '平台分账商户号',
+			'name' 		=> '主体分账商户号',
 			'default' 	=> '',
-			'desc' 		=> '平台分账商户号',
+			'desc' 		=> '主体分账商户号',
 			'match' 	=> 'is_string',
-			'update'	=> 'text',
+			//'update'	=> 'text',
 			'show'		=> 'type=2',
 		),
 
 		'cash_merno'		=> array
 		(
 			'type' 		=> 'varchar-200',
-			'name' 		=> '平台分账企业用户号',
+			'name' 		=> '主体分账企业用户号',
 			'default' 	=> '',
-			'desc' 		=> '平台分账企业用户号',
+			'desc' 		=> '主体分账企业用户号',
 			'match' 	=> 'is_string',
-			'update'	=> 'text',
+			//'update'	=> 'text',
 			'show'		=> 'type=2',
 		),
 
 		'cash_card'		=> array
 		(
 			'type' 		=> 'varchar-150',
-			'name' 		=> '平台分账卡号',
+			'name' 		=> '主体分账卡号',
 			'default' 	=> '',
-			'desc' 		=> '平台分账卡号',
+			'desc' 		=> '主体分账卡号',
 			'match' 	=> 'is_string',
-			'update'	=> 'text',
+			//'update'	=> 'text',
 			'show'		=> 'type=2',
 		),
 

+ 22 - 8
database/yspay_cash_log.php

@@ -41,6 +41,18 @@ return array
             //'list'        => true,
         ),
 
+        'yspay_main_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '主体id',
+            'default'   => '1',
+            'desc'      => '主体id',
+            'match'     => 'option',
+            'update'    => 'hidden',
+            'search'    => 'hidden',
+            'value'     => Dever::input('search_option_yspay_main_id'),
+        ),
+
         'merchant_id'      => array
         (
             'type'      => 'int-11',
@@ -49,6 +61,7 @@ return array
             'desc'      => '商户id',
             'match'     => 'option',
             'update'    => 'hidden',
+            'search'    => 'hidden',
             'value'     => Dever::input('search_option_merchant_id'),
             'list_name' => '商户名称',
             'list'      => 'Dever::load("pay/yspay_merchant-one#name", "{merchant_id}")',
@@ -63,7 +76,7 @@ return array
             'match'     => 'option',
             'update'    => 'text',
             'searchs'    => 'fulltext',
-            'list'		=> true,
+            //'list'		=> true,
         ),
 
         'order_num'      => array
@@ -86,14 +99,15 @@ return array
             'match'     => 'is_numeric',
             'update'    => 'text',
             'option'    => $type,
+            'search'    => 'hidden',
         ),
 
         'cash'      => array
         (
             'type'      => 'int-11',
-            'name'      => '提现金额',
+            'name'      => '金额',
             'default'   => '0',
-            'desc'      => '提现金额',
+            'desc'      => '金额',
             'match'     => 'option',
             'update'    => 'text',
             'list'      => 'round({cash}/100, 2)',
@@ -102,7 +116,7 @@ return array
         'tdate'     => array
         (
             'type'      => 'int-11',
-            'name'      => '提现时间',
+            'name'      => '时间',
             'default'   => '',
             'match'     => 'is_numeric',
             'desc'      => '',
@@ -124,9 +138,9 @@ return array
         'status'        => array
         (
             'type'      => 'tinyint-1',
-            'name'      => '提现状态',
+            'name'      => '状态',
             'default'   => '1',
-            'desc'      => '提现状态',
+            'desc'      => '状态',
             'match'     => 'is_numeric',
             'option'    => $status,
             //'search'    => 'select',
@@ -136,9 +150,9 @@ return array
         'error'      => array
         (
             'type'      => 'varchar-800',
-            'name'      => '提现错误信息',
+            'name'      => '错误信息',
             'default'   => '',
-            'desc'      => '提现错误信息',
+            'desc'      => '错误信息',
             'match'     => 'is_string',
             'update'    => 'text',
         ),

+ 122 - 0
database/yspay_main.php

@@ -0,0 +1,122 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'yspay_main',
+	# 显示给用户看的名称
+	'lang' => '银商主体配置',
+	'order' => 10,
+	'menu' => false,
+	# 数据结构
+	'struct' => array
+	(
+	
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'search'	=> 'order',
+			'list'		=> true,
+		),
+
+		'account_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '所属账户',
+			'default' 	=> '1',
+			'desc' 		=> '所属账户',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'hidden',
+			'search'    => 'hidden',
+			'value'		=> Dever::input('search_option_account_id'),
+		),
+
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-60',
+			'name' 		=> '主体名称',
+			'default' 	=> '',
+			'desc' 		=> '主体名称',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'cash_mid'		=> array
+		(
+			'type' 		=> 'varchar-200',
+			'name' 		=> '主体商户号',
+			'default' 	=> '',
+			'desc' 		=> '主体商户号',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'cash_merno'		=> array
+		(
+			'type' 		=> 'varchar-200',
+			'name' 		=> '主体企业用户号',
+			'default' 	=> '',
+			'desc' 		=> '主体企业用户号',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'cash_card'		=> array
+		(
+			'type' 		=> 'varchar-150',
+			'name' 		=> '主体银行卡号',
+			'default' 	=> '',
+			'desc' 		=> '主体银行卡号',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+		),
+
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			'search'	=> 'date',
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+
+	'manage' => array
+	(
+		'insert' => false,
+        'edit' => false,
+
+        # 自定义快捷新增和编辑
+        'button' => array
+        (
+            '新增' => array('fast'),
+        ),
+
+		'list_button' => array
+        (
+        	'edit' => array('编辑'),
+        	'list' => array('商户列表', '"yspay_merchant&search_option_account_id={account_id}&search_option_yspay_main_id={id}&parent=account.yspay_main"'),
+        	'list1' => array('分账日志', '"yspay_cash_log&search_option_yspay_main_id={id}&search_option_type=2&parent=account.yspay_main"'),
+        ),
+	),
+);

+ 18 - 5
database/yspay_merchant.php

@@ -13,7 +13,7 @@ $project = function()
 {
 	return Dever::db('pay/yspay_project')->state();
 };
-
+$yspay_main_id = Dever::input('search_option_yspay_main_id');
 $account_id = Dever::input('search_option_account_id');
 $yspay_type = 1;
 if ($account_id) {
@@ -25,7 +25,7 @@ $list_button = array
 (
     'edit' => array('编辑'),
 
-    'add' => array('签约资料', '"yspay_sign&search_option_merchant_id={id}&search_option_account_id={account_id}&where_id={id}&oper_table=account&oper_save_table=yspay_merchant"', '{status} == 2'),
+    'add' => array('签约资料', '"yspay_sign&search_option_merchant_id={id}&search_option_account_id={account_id}&where_id={id}&parent=account.yspay_main.yspay_merchant"', '{status} == 2'),
 
     'oper' => array('签约提审', 'pay/yspay/sign.handle?sign_id={id}', '"{pay/yspay_sign-one#step}" == -1 && {status} == 2'),
     'fast' => array('签约打款', '"yspay_sign&where_id={id}&col=cash"', '"{pay/yspay_sign-one#step}" == 2 && {status} == 2'),
@@ -33,14 +33,14 @@ $list_button = array
 );
 
 if ($yspay_type == 2) {
-    $list_button['list3'] = array('资金流水', '"yspay_cash&search_option_merchant_id={id}&search_option_account_id={account_id}&oper_table=yspay_merchant&top_table=account"', '{status} == 1');
+    $list_button['list3'] = array('资金流水', '"yspay_cash&search_option_merchant_id={id}&search_option_account_id={account_id}&parent=account.yspay_main.yspay_merchant"', '{status} == 1');
 }
 
 if ($yspay_type == 1) {
-    $list_button['list2'] = array('提现管理', '"yspay_tixian&search_option_merchant_id={id}&search_option_account_id={account_id}&oper_table=yspay_merchant&top_table=account"', '{status} == 1');
+    $list_button['list2'] = array('提现管理', '"yspay_tixian&search_option_merchant_id={id}&search_option_account_id={account_id}&parent=account.yspay_main.yspay_merchant"', '{status} == 1');
 }
 
-$list_button['list1'] = array('签约日志', '"yspay_sign_log&search_option_account_id={account_id}&search_option_merchant_id={id}&oper_table=yspay_merchant&top_table=account"');
+$list_button['list1'] = array('签约日志', '"yspay_sign_log&search_option_account_id={account_id}&search_option_merchant_id={id}&parent=account.yspay_main.yspay_merchant"');
 
 return array
 (
@@ -75,9 +75,22 @@ return array
             'desc'      => '账户id',
             'match'     => 'option',
             'update'    => 'hidden',
+            'search'    => 'hidden',
             'value'     => $account_id,
         ),
 
+        'yspay_main_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '主体id',
+            'default'   => '1',
+            'desc'      => '主体id',
+            'match'     => 'option',
+            'update'    => 'hidden',
+            'search'    => 'hidden',
+            'value'     => $yspay_main_id,
+        ),
+
         'name'      => array
         (
             'type'      => 'varchar-300',

+ 1 - 0
database/yspay_merchant_log.php

@@ -64,6 +64,7 @@ return array
             'desc'      => '商户id',
             'match'     => 'option',
             'update'    => 'hidden',
+            'search'    => 'hidden',
             'value'     => Dever::input('search_option_merchant_id'),
             'list_name' => '商户名称',
             'list'      => 'Dever::load("pay/yspay_merchant-one#name", "{merchant_id}")',

+ 1 - 0
database/yspay_sign_log.php

@@ -48,6 +48,7 @@ return array
             'desc'      => '商户id',
             'match'     => 'option',
             'update'    => 'hidden',
+            'search'    => 'hidden',
             'value'     => Dever::input('search_option_merchant_id'),
             'list_name' => '商户名称',
             'list'      => 'Dever::load("pay/yspay_merchant-one#name", "{merchant_id}")',

+ 1 - 0
database/yspay_tixian_apply.php

@@ -41,6 +41,7 @@ return array
             'desc'      => '商户id',
             'match'     => 'option',
             'update'    => 'hidden',
+            'search'    => 'hidden',
             'value'     => Dever::input('search_option_merchant_id'),
             'list_name' => '商户名称',
             'list'      => 'Dever::load("pay/yspay_merchant-one#name", "{merchant_id}")',

+ 1 - 0
database/yspay_tixian_log.php

@@ -43,6 +43,7 @@ return array
             'desc'      => '商户id',
             'match'     => 'option',
             'update'    => 'hidden',
+            'search'    => 'hidden',
             'value'     => Dever::input('search_option_merchant_id'),
             'list_name' => '商户名称',
             'list'      => 'Dever::load("pay/yspay_merchant-one#name", "{merchant_id}")',

+ 9 - 3
lib/Yspay.php

@@ -166,6 +166,10 @@ class Yspay extends Core
 			if (!isset($other[0])) {
 				$other = array($other);
 			}
+			$yspay_main_id = 1;
+			if (isset($other[0]['yspay_main_id'])) {
+				$yspay_main_id = $other[0]['yspay_main_id'];
+			}
 			$request['originalAmount'] = $request['totalAmount'];
 			$request['platformAmount'] = $request['totalAmount'];
 			$request['subOrders'] = array();
@@ -200,7 +204,7 @@ class Yspay extends Core
 			if ($request['subOrders']) {
 				$request['divisionFlag'] = true;
 				if ($request['platformAmount'] > 0) {
-					$merchant = Dever::load('pay/yspay/cash')->getMid($this->config['id']);
+					$merchant = Dever::load('pay/yspay/cash')->getMid($this->config['id'], $yspay_main_id);
 					if ($merchant) {
 						$subOrders = array
 						(
@@ -215,6 +219,8 @@ class Yspay extends Core
 				}
 			}
 		}
+
+		/* 已废弃,根据前台逻辑进行分账吧,否则都支付给主商户
 		if (isset($request['divisionFlag']) && $request['divisionFlag']) {
 			
 		} else {
@@ -223,7 +229,7 @@ class Yspay extends Core
 				$request['platformAmount'] = 0;
 				Dever::load('pay/yspay/cash')->add($merchant['id'], $request['totalAmount'], $request['merOrderId'], $order_id);
 			}
-		}
+		}*/
 		if (!$openid) {
 			# 测试的openid
 			$request['subOpenId'] = 'ofBUV0RUoy_8C4VctZjrSDGzhUfY';
@@ -313,7 +319,7 @@ class Yspay extends Core
 					$v['per'] = $v['per'] && $v['per'] >= 0 ? $v['per'] : 0;
 					$v['per'] = $v['per']/100;
 					$request['platformAmount'] = round($request['refundAmount'] * $v['per'], 2);
-					$subOrders['totalAmount'] = round($request['totalAmount'] - $request['platformAmount'], 2);
+					$subOrders['totalAmount'] = round($request['refundAmount'] - $request['platformAmount'], 2);
 				} else {
 					continue;
 				}

+ 17 - 5
yspay/Cash.php

@@ -138,8 +138,8 @@ class Cash
     		$cash_jy_per = $yspay['cash_jy_per']/100;
 
         	$data['ycash'] = $amount;
-        	$data['yl_cash'] = floor($data['ycash'] * $per);
-        	$data['pt_cash'] = floor($data['ycash'] * $cash_jy_per);
+        	$data['yl_cash'] = round($data['ycash'] * $per);
+        	$data['pt_cash'] = round($data['ycash'] * $cash_jy_per);
 	        $data['cash'] = $data['ycash'] - $data['yl_cash'] - $data['pt_cash'];
 
 	        /*
@@ -179,7 +179,8 @@ class Cash
     	if ($merchant) {
     		$config = Dever::db('pay/yspay')->one(array('account_id' => $merchant['account_id']));
     		if ($config) {
-    			return Dever::load('pay/yspay/multi')->fenzhang($config, $merchant, $info);
+    			$yspay_main = Dever::db('pay/yspay_main')->one($merchant['yspay_main_id']);
+    			return Dever::load('pay/yspay/multi')->fenzhang($config, $yspay_main, $merchant, $info);
     		}
     	}
 
@@ -286,9 +287,9 @@ class Cash
     }
 
     # 随机获取平台商户
-    public function getMid($account_id)
+    public function getMid($account_id, $yspay_main_id = 1)
     {
-    	$merchant = Dever::db('pay/yspay_merchant')->select(array('type' => 2, 'account_id' => $account_id, 'status' => 1));
+    	$merchant = Dever::db('pay/yspay_merchant')->select(array('type' => 2, 'account_id' => $account_id, 'yspay_main_id' => $yspay_main_id, 'status' => 1));
 
     	if ($merchant) {
     		$key = array_rand($merchant);
@@ -331,4 +332,15 @@ class Cash
 			Dever::load('pay/yspay/merchant')->log($merchant['id'], $merchant['account_id'], 3, $cash, $name);
 		}
     }
+
+    public function total_api()
+    {
+    	$merchant_id = Dever::input('mid');
+    	$total = Dever::db('pay/yspay_cash')->getTotal(array('status' => 2, 'merchant_id' => $merchant_id));
+		if ($total) {
+			Dever::db('pay/yspay_merchant')->update(array('where_id' => $merchant_id, 'cash' => $total['cash'], 'hf_cash' => $total['hf_cash'], 'fz_cash' => $total['fz_cash']));
+		}
+
+		return 'ok';
+    }
 }

+ 10 - 7
yspay/Merchant.php

@@ -41,10 +41,11 @@ class Merchant
         return Dever::search($project['table'], $where);
     }
 
-    public function up($account_id, $project_id, $id, $name)
+    public function up($account_id, $yspay_main_id, $project_id, $id, $name)
     {
         $data = array();
         $data['account_id'] = $account_id;
+        $data['yspay_main_id'] = $yspay_main_id;
         $data['project_id'] = $project_id;
         $data['relate_id'] = $id;
         $info = Dever::db('pay/yspay_merchant')->find($data);
@@ -57,28 +58,29 @@ class Merchant
         return false;
     }
 
-    public function getOther($account_id, $table, $relate_id, $order_num, $cash, $fenzhang = 0)
+    public function getOther($account_id, $yspay_main_id, $relate, $relate_id, $order_num, $cash, $fenzhang = 0)
     {
         $result = array();
         $yspay = Dever::db('pay/yspay')->find(array('account_id' => $account_id));
         if ($cash && $cash > 0 && $yspay && $yspay['type'] == 2) {
             # 分账拆单
             $merchant = array();
-            if ($table == 2) {
-                $merchant = Dever::db('pay/yspay_merchant')->find(array('account_id' => $account_id, 'type' => 2));
+            if ($relate == 2) {
+                $merchant = Dever::db('pay/yspay_merchant')->find(array('account_id' => $account_id, 'yspay_main_id' => $yspay_main_id, 'type' => 2));
                 if (strstr($order_num, '_')) {
                     $temp = explode('_', $order_num);
                     $order_num = $temp[0];
                 }
                 $order_num .= '_O';
             } else {
-                $project = Dever::db('pay/yspay_project')->find(array('table' => $table));
+                $project = Dever::db('pay/yspay_project')->find(array('table' => $relate));
                 if ($project) {
-                    $merchant = Dever::db('pay/yspay_merchant')->find(array('account_id' => $account_id, 'project_id' => $project['id'], 'relate_id' => $relate_id));
+                    $merchant = Dever::db('pay/yspay_merchant')->find(array('account_id' => $account_id, 'yspay_main_id' => $yspay_main_id, 'project_id' => $project['id'], 'relate_id' => $relate_id));
                 }
             }
             if ($merchant && $merchant['mid']) {
                 $result = array(
+                    'yspay_main_id' => $merchant['yspay_main_id'],
                     'merchant_id' => $merchant['id'],
                     'mid' => $merchant['mid'],
                     'order_id' => $order_num,
@@ -91,11 +93,12 @@ class Merchant
         return $result;
     }
 
-    public function getInfo($account_id, $project_id, $id, $parent, $array = false)
+    public function getInfo($account_id, $yspay_main_id, $project_id, $id, $parent, $array = false)
     {
         list($project, $table) = explode('/', $parent);
         $where = array();
         $where['account_id'] = $account_id;
+        $data['yspay_main_id'] = $yspay_main_id;
         $where['project_id'] = $project_id;
         $where['relate_id'] = $id;
         $data = Dever::db('pay/yspay_merchant')->find($where);

+ 5 - 5
yspay/Multi.php

@@ -43,7 +43,7 @@ class Multi
         	$data['status'] = 3;
         	$data['error'] = $result; 
         }
-
+        $data['yspay_main_id'] = $merchant['yspay_main_id'];
         $data['merchant_id'] = $merchant['id'];
         $data['mid'] = $mid;
         $data['order_num'] = $order_num;
@@ -58,11 +58,11 @@ class Multi
     }
 
     # 分账
-    public function fenzhang($config, $merchant, $info, $auto = 1)
+    public function fenzhang($config, $yspay_main, $merchant, $info, $auto = 1)
     {
     	$this->config = $config;
 
-    	$mid = $this->config['cash_mid'];
+    	$mid = $yspay_main['cash_mid'];
     	$cash = $info['fz_cash'] + $info['pt_cash'];
     	if (!$cash || $cash <= 0) {
     		return false;
@@ -74,7 +74,7 @@ class Multi
             'merNo' => $merchant['merno'],
             //'merOrderNo' => $order_num,
             'payAmt' => (string) $cash,
-            'cardNo' => hash("sha256", $this->config['cash_card']),
+            'cardNo' => hash("sha256", $yspay_main['cash_card']),
             'ps' => $info['order_num'],
         ];
         
@@ -87,7 +87,7 @@ class Multi
         	$data['status'] = 3;
         	$data['error'] = $result; 
         }
-
+        $data['yspay_main_id'] = $merchant['yspay_main_id'];
         $data['merchant_id'] = $merchant['id'];
         $data['mid'] = $mid;
         $data['order_num'] = $order_num;