init: import production code mss.nahaichuan.com (exclude Runtime/Uploads/backups/logs)
这个提交包含在:
@@ -0,0 +1,250 @@
|
||||
<?php
|
||||
|
||||
namespace Common\Model;
|
||||
|
||||
use Think\Model;
|
||||
|
||||
//[1.5.66]
|
||||
|
||||
/**
|
||||
* 支付设置
|
||||
* Class RetailPaySetModel
|
||||
* @package Common\Model
|
||||
*/
|
||||
class RetailPaySetModel extends BaseModel
|
||||
{
|
||||
protected $tableName = 'retail_payset';
|
||||
const ID = 'id';
|
||||
const WX_APPID = 'wx_appid';//varchar(32) DEFAULT '' COMMENT '商户appid',
|
||||
const WX_SECRET_KEY = 'wx_secret_key';//varchar(255) DEFAULT NULL COMMENT '商户密钥',
|
||||
const WX_MCH_ID = 'wx_mch_id';//int(11) DEFAULT NULL COMMENT '商户号',
|
||||
const BALANCE_STATE = 'balance';//tinyint(3) DEFAULT '1' COMMENT '余额支付状态:1:开启 0:关闭',
|
||||
const MERCHANT_ID = 'merchantid';//int(11) DEFAULT NULL COMMENT '商户id',
|
||||
const ADD_TIME = 'addtime';//varchar(18) DEFAULT '' COMMENT '创建时间',
|
||||
const AL_PUB_KEY = 'alipay_public_key';//varchar(3000) COMMENT '支付宝公钥',
|
||||
const AL_PRI_KEY = 'alipay_private_key';//varchar(6000) COMMENT '支付宝商户私钥',
|
||||
const AL_APPID = 'alipay_appid';//varchar(30) DEFAULT '' COMMENT '支付宝应用ID',
|
||||
const AL_SELLER_ID = 'alipay_sellerid';//varchar(30) DEFAULT '' COMMENT '卖家支付宝账号ID',
|
||||
const XCX_APPID = 'xcx_appid';//varchar(128) DEFAULT NULL COMMENT '小程序appid',
|
||||
const XCX_MCH_ID = 'xcx_mer_id';//varchar(255) DEFAULT NULL COMMENT '小程序商户号',
|
||||
const XCX_SECRET_KEY = 'xcx_secret_key';//varchar(255) DEFAULT NULL COMMENT '小程序商户密钥',
|
||||
const WX_AC_CERT = 'apiclient_cert';//varchar(255) DEFAULT NULL COMMENT '微信apiclient_cert证书路径',
|
||||
const WX_AC_KEY = 'apiclient_key';//varchar(255) DEFAULT NULL COMMENT 'apiclient_key证书路径',
|
||||
const WX_APP_SECRET = 'wx_appsecret';//varchar(50) DEFAULT NULL COMMENT '商户appsecret',
|
||||
const WX_SUB_APPID = 'wx_sub_appid'; //varchar(32) DEFAULT NULL COMMENT '微信服务商模式appid',
|
||||
const WX_SUB_MCH_ID = 'wx_sub_mchid';//varchar(12) DEFAULT NULL COMMENT '微信服务商模式子商户id',
|
||||
const AL_TOKEN = 'alipay_token';//varchar(255) DEFAULT NULL COMMENT '支付宝应用token值',
|
||||
const XCX_AC_CERT = 'xcx_apiclient_cert';//varchar(255) DEFAULT NULL COMMENT '小程序apiclient_cert证书路径',
|
||||
const XCX_AC_KEY = 'xcx_apiclient_key';//varchar(255) DEFAULT NULL COMMENT '小程序apiclient_key证书路径',
|
||||
const WX_PAY_STATE = 'wx_pay_state';//tinyint(1) DEFAULT '0' COMMENT '微信模式 0关闭 1普通商户 2服务商',
|
||||
const AL_PAY_STATE = 'al_pay_state';//tinyint(1) DEFAULT '0' COMMENT '支付宝支付模式 0关闭 1普通商户 2服务商',
|
||||
const XCX_PAY_STATE = 'xcx_pay_state';//tinyint(1) DEFAULT '0' COMMENT '小程序支付 0关闭 1普通 2服务商',
|
||||
const XCX_SUB_MCH_ID = 'xcx_sub_mchid';//varchar(30) DEFAULT NULL COMMENT '小程序子商户号',
|
||||
const XCX_SUB_APPID = 'xcx_sub_appid';//varchar(30) DEFAULT NULL COMMENT '小程序子商户appid',
|
||||
const CLOUD_MER_ID = 'cloud_mer_id';// 云闪付商户号
|
||||
const CLOUD_XCX_APPID = 'cloud_xcx_appid';// 云闪付小程序appid
|
||||
const CLOUD_SUB_APPID = 'cloud_sub_appid';// 云闪付公众号appid
|
||||
const WX_XCX_SERIAL_NO = 'wx_xcx_serial_no'; //微信小程序配置的普通商户证书序列号
|
||||
const WX_SERIAL_NO = 'wx_serial_no'; //微信公众号配置的普通商户证书序列号
|
||||
|
||||
|
||||
/**
|
||||
* 获取商户支付配置与合伙人配置
|
||||
* @param $merchant_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFindMerchantPaySet($merchant_id)
|
||||
{
|
||||
try {
|
||||
$paySet = $this->getFind(array($this::MERCHANT_ID => $merchant_id));
|
||||
if ($paySet) {
|
||||
$SystemConfigModel = D('SystemConfig');
|
||||
$AgentModel = D('RetailAgent');
|
||||
$MerchantModel = D('RetailMerchant');
|
||||
$mMap = array(
|
||||
$MerchantModel::ID => $merchant_id
|
||||
);
|
||||
$agent_id = $MerchantModel->getFindField($mMap, $MerchantModel::AGENT_ID);
|
||||
$aMap = array(
|
||||
$AgentModel::ID => $agent_id
|
||||
);
|
||||
$aFields = array(
|
||||
$AgentModel::SET_SERVER_PAY,
|
||||
$AgentModel::SERVER_PAY_STATE,
|
||||
);
|
||||
$agentPaySet = $AgentModel->getFind($aMap, $aFields);
|
||||
if ($agentPaySet[$AgentModel::SET_SERVER_PAY] == 1 && $agentPaySet[$AgentModel::SERVER_PAY_STATE] == 1) {
|
||||
$AgentPayConfigModel = D('AgentPayConfig');
|
||||
$map = array(
|
||||
$AgentPayConfigModel::AGENT_ID => $agent_id
|
||||
);
|
||||
$paySet['systemConfig'] = $AgentPayConfigModel->getFind($map);
|
||||
} else {
|
||||
$paySet['systemConfig'] = $SystemConfigModel->getFind();
|
||||
}
|
||||
$res['config'] = $paySet;
|
||||
$res['status'] = 1;
|
||||
} else {
|
||||
$res['status'] = 0;
|
||||
$res['msg'] = '商户未配置支付';
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$res['status'] = 0;
|
||||
$res['msg'] = '商户未配置支付';
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商户支付模式及权限
|
||||
* @param $merchant_id 商户id
|
||||
* @param $pay_type 支付方式 1微信 2支付宝 3微信小程序
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFindMerchantConfig($merchant_id, $pay_type, $store_id = 0)
|
||||
{
|
||||
$store_id = is_numeric($store_id) ? $store_id : 0;
|
||||
$paySet = $this->getFind(array($this::MERCHANT_ID => $merchant_id, 'storeid' => $store_id));
|
||||
if ($paySet) {
|
||||
//判断支付方式
|
||||
switch ($pay_type) {
|
||||
case '1':
|
||||
//微信
|
||||
$pay_name = '微信';
|
||||
$pay_state = $paySet[$this::WX_PAY_STATE];
|
||||
break;
|
||||
case '2':
|
||||
//支付宝
|
||||
$pay_name = '支付宝';
|
||||
$pay_state = $paySet[$this::AL_PAY_STATE];
|
||||
break;
|
||||
case '3':
|
||||
//微信小程序
|
||||
$pay_name = '微信小程序';
|
||||
$pay_state = $paySet[$this::XCX_PAY_STATE];
|
||||
}
|
||||
if ($pay_state == 0) {
|
||||
$res['status'] = 0;
|
||||
$res['msg'] = '商户未开启' . $pay_name . '支付';
|
||||
return $res;
|
||||
}
|
||||
$MerchantModel = D('RetailMerchant');
|
||||
$merchant = $MerchantModel->getFind(array($MerchantModel::ID => $merchant_id), $MerchantModel::AGENT_ID); //获取代理商id
|
||||
$PayPatternModel = D('PayPattern');
|
||||
$agentPayAuth = $PayPatternModel->getAgentPattern($merchant[$MerchantModel::AGENT_ID]); // 获取代理商支付权限
|
||||
if (!$agentPayAuth) {
|
||||
$res['status'] = 0;
|
||||
$res['msg'] = '代理商无线上支付权限';
|
||||
return $res;
|
||||
}
|
||||
//判断代理商支付权限
|
||||
switch ($pay_state) {
|
||||
case '1':
|
||||
//普通商户
|
||||
if ($agentPayAuth[$PayPatternModel::GENERAL_PAY] != 1) {
|
||||
$res['status'] = 0;
|
||||
$res['msg'] = '代理商无普通商户支付模式权限';
|
||||
return $res;
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
//服务商
|
||||
if ($agentPayAuth[$PayPatternModel::SERVICE_PAY] != 1) {
|
||||
$res['status'] = 0;
|
||||
$res['msg'] = '代理商无服务商支付模式权限';
|
||||
return $res;
|
||||
}
|
||||
break;
|
||||
case '3':
|
||||
//新大陆
|
||||
if ($agentPayAuth[$PayPatternModel::CONTINENT_PAY] != 1) {
|
||||
$res['status'] = 0;
|
||||
$res['msg'] = '代理商无新大陆支付模式权限';
|
||||
return $res;
|
||||
}
|
||||
break;
|
||||
case '4':
|
||||
//云闪付
|
||||
if ($agentPayAuth[$PayPatternModel::CLOUD_PAY] != 1) {
|
||||
$res['status'] = 0;
|
||||
$res['msg'] = '代理商无云闪付支付模式权限';
|
||||
return $res;
|
||||
}
|
||||
break;
|
||||
}
|
||||
$MerchantPayAuthModel = new MerchantPayAuthModel();
|
||||
$merchantPayAuth = $MerchantPayAuthModel->getFind(array($MerchantPayAuthModel::MERCHANT_ID => $merchant_id));//商户支付权限
|
||||
//判断商户支付权限
|
||||
switch ($pay_state) {
|
||||
case '1':
|
||||
//普通商户
|
||||
if ($merchantPayAuth[$MerchantPayAuthModel::GENERAL_PAY] != 1) {
|
||||
$res['status'] = 0;
|
||||
$res['msg'] = '商户无普通商户支付模式权限';
|
||||
return $res;
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
//服务商
|
||||
if ($merchantPayAuth[$MerchantPayAuthModel::SERVICE_PAY] != 1) {
|
||||
$res['status'] = 0;
|
||||
$res['msg'] = '商户无服务商支付模式权限';
|
||||
return $res;
|
||||
}
|
||||
break;
|
||||
case '3':
|
||||
//新大陆
|
||||
if ($merchantPayAuth[$MerchantPayAuthModel::CONTINENT_PAY] != 1) {
|
||||
$res['status'] = 0;
|
||||
$res['msg'] = '商户无新大陆支付模式权限';
|
||||
return $res;
|
||||
}
|
||||
break;
|
||||
case '4':
|
||||
//云闪付
|
||||
if ($merchantPayAuth[$MerchantPayAuthModel::CLOUD_PAY] != 1) {
|
||||
$res['status'] = 0;
|
||||
$res['msg'] = '商户无云闪付支付模式权限';
|
||||
return $res;
|
||||
}
|
||||
break;
|
||||
}
|
||||
$res['status'] = 1;
|
||||
$res['m_pay_type'] = $pay_state;
|
||||
if ($pay_state == 2) {
|
||||
//服务商支付模式:判断服务商是取代理商配置还是合伙人配置
|
||||
$SystemConfigModel = new SystemConfigModel();
|
||||
$agent_id = $merchant[$MerchantModel::AGENT_ID];
|
||||
$AgentModel = D('RetailAgent');
|
||||
$aMap = array(
|
||||
$AgentModel::ID => $agent_id
|
||||
);
|
||||
$aFields = array(
|
||||
$AgentModel::SET_SERVER_PAY,
|
||||
$AgentModel::SERVER_PAY_STATE,
|
||||
);
|
||||
$agentPaySet = $AgentModel->getFind($aMap, $aFields);
|
||||
if ($agentPaySet[$AgentModel::SET_SERVER_PAY] == 1 && $agentPaySet[$AgentModel::SERVER_PAY_STATE] == 1) {
|
||||
//开启代理商配置支付服务商
|
||||
$AgentPayConfigModel = D('AgentPayConfig');
|
||||
$map = array(
|
||||
$AgentPayConfigModel::AGENT_ID => $agent_id
|
||||
);
|
||||
$paySet['systemConfig'] = $AgentPayConfigModel->getFind($map);
|
||||
} else {
|
||||
$paySet['systemConfig'] = $SystemConfigModel->getFind();
|
||||
}
|
||||
} else if ($pay_state == 4) {
|
||||
// 云闪付服务商配置
|
||||
$SystemConfigModel = new SystemConfigModel();
|
||||
$paySet['systemConfig'] = $SystemConfigModel->getFind();
|
||||
}
|
||||
$paySet['name'] = $merchant['name'];
|
||||
$res['config'] = $paySet;
|
||||
} else {
|
||||
$res['status'] = 0;
|
||||
$res['msg'] = '商户未配置支付';
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户