first commit

This commit is contained in:
2025-11-28 10:08:12 +08:00
commit 09a14bf0a3
1088 changed files with 145132 additions and 0 deletions
+109
View File
@@ -0,0 +1,109 @@
<?php
namespace lib\ProfitSharing;
require_once PLUGIN_ROOT . 'adapay/inc/Build.class.php';
use Exception;
class Adapay implements IProfitSharing
{
static $paytype = 'adapay';
private $channel;
private $service;
function __construct($channel){
$this->channel = $channel;
$pay_config = require(PLUGIN_ROOT.$channel['plugin'].'/inc/config.php');
$this->service = \AdaPay::config($pay_config);
}
//请求分账
public function submit($trade_no, $api_trade_no, $account, $name, $money){
global $DB;
$order_money = $DB->findColumn('order', 'realmoney', ['trade_no'=>$trade_no]);
if(strpos($account, '|')){
$accounts = explode('|', $account);
$psorder = CommUtil::getOrder($trade_no);
$rates = explode('|', $psorder['rate']);
$div_members = [];
$allmoney = 0;
foreach($accounts as $i=>$account){
$rate = isset($rates[$i]) ? $rates[$i] : $rates[0];
$money = round($order_money * $rate / 100, 2);
$div_members[] = ['member_id'=>$account, 'amount' => sprintf('%.2f' , $money), 'fee_flag'=>$i==0?'Y':'N'];
$allmoney += $money;
}
if($order_money > $allmoney){
$psmoney2 = round($order_money-$allmoney, 2);
$div_members[] = ['member_id'=>'0', 'amount' => sprintf('%.2f' , $psmoney2), 'fee_flag'=>'N'];
}
}else{
$psmoney2 = round($order_money-$money, 2);
$div_members = [];
$div_members[] = ['member_id'=>$account, 'amount' => sprintf('%.2f' , $money), 'fee_flag'=>'Y'];
if($psmoney2 > 0){
$div_members[] = ['member_id'=>'0', 'amount' => sprintf('%.2f' , $psmoney2), 'fee_flag'=>'N'];
}
}
$params = [
'payment_id' => $api_trade_no,
'order_no' => date("YmdHis").rand(11111,99999),
'confirm_amt' => $order_money,
'div_members' => $div_members,
];
try{
$result = $this->service->createPaymentConfirm($params);
return ['code'=>1, 'msg'=>'分账成功', 'settle_no'=>$result['id']];
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
//查询分账结果
public function query($trade_no, $api_trade_no, $settle_no){
try{
$result = $this->service->queryPaymentConfirm($settle_no);
return ['code'=>0, 'status'=>1];
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
//解冻剩余资金
public function unfreeeze($trade_no, $api_trade_no){
global $DB;
$order_money = $DB->findColumn('order', 'realmoney', ['trade_no'=>$trade_no]);
$params = [
'payment_id' => $api_trade_no,
'order_no' => date("YmdHis").rand(11111,99999),
'reverse_amt' => $order_money,
];
try{
$result = $this->service->createPaymentReverse($params);
return ['code'=>0, 'msg'=>'解冻剩余资金成功', 'settle_no'=>$result['id']];
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
//分账回退
public function return($trade_no, $api_trade_no, $account, $money){
return ['code'=>-1,'msg'=>'不支持当前操作'];
}
//添加分账接收方
public function addReceiver($account, $name = null){
return ['code'=>0, 'msg'=>'添加分账接收方成功'];
}
//删除分账接收方
public function deleteReceiver($account){
return ['code'=>0, 'msg'=>'删除分账接收方成功'];
}
}
+159
View File
@@ -0,0 +1,159 @@
<?php
namespace lib\ProfitSharing;
use Exception;
class Alipay implements IProfitSharing
{
static $paytype = 'alipay';
private $channel;
private $service;
function __construct($channel){
$this->channel = $channel;
$alipay_config = require(PLUGIN_ROOT.$channel['plugin'].'/inc/config.php');
$this->service = new \Alipay\AlipaySettleService($alipay_config);
}
//请求分账
public function submit($trade_no, $api_trade_no, $account, $name, $money){
if(strpos($account, '|')){
global $DB;
$accounts = explode('|', $account);
$psorder = CommUtil::getOrder($trade_no);
$rates = explode('|', $psorder['rate']);
$order_money = $DB->findColumn('order', 'realmoney', ['trade_no'=>$trade_no]);
$receivers = [];
foreach($accounts as $i=>$account){
$rate = isset($rates[$i]) ? $rates[$i] : $rates[0];
$money = round($order_money * $rate / 100, 2);
$type = self::get_alipay_account_type($account);
$receivers[] = [
'trans_in_type' => $type,
'trans_in' => $account,
'amount' => $money
];
}
$bizContent = array(
'out_request_no' => date("YmdHis").rand(11111,99999),
'trade_no' => $api_trade_no,
'royalty_parameters' => $receivers,
'extend_params' => [
'royalty_finish' => 'true'
]
);
try{
$result = $this->service->aopExecute('alipay.trade.order.settle', $bizContent);
return ['code'=>1, 'msg'=>'分账成功', 'settle_no'=>$result['settle_no']];
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
$type = self::get_alipay_account_type($account);
try{
$result = $this->service->order_settle($api_trade_no, $type, $account, $money);
return ['code'=>1, 'msg'=>'分账成功', 'settle_no'=>$result['settle_no']];
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
//查询分账结果
public function query($trade_no, $api_trade_no, $settle_no){
try{
$result = $this->service->order_settle_query($settle_no);
$receiver = $result['royalty_detail_list'][0];
if($receiver['state'] == 'SUCCESS'){
return ['code'=>0, 'status'=>1];
}elseif($receiver['state'] == 'FAIL'){
return ['code'=>0, 'status'=>2, 'reason'=>'['.$receiver['error_code'].']'.$receiver['error_desc']];
}else{
return ['code'=>0, 'status'=>0];
}
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
//解冻剩余资金
public function unfreeeze($trade_no, $api_trade_no){
try{
$this->service->order_settle_unfreeze($api_trade_no);
return ['code'=>0, 'msg'=>'解冻剩余资金成功'];
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
//分账回退
public function return($trade_no, $api_trade_no, $account, $money){
$type = self::get_alipay_account_type($account);
try{
$this->service->order_settle_refund($api_trade_no, $type, $account, $money);
return ['code'=>0, 'msg'=>'退分账成功'];
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
//添加分账接收方
public function addReceiver($account, $name = null){
if(strpos($account, '|')){
$accounts = explode('|', $account);
$names = explode('|', $name);
foreach($accounts as $i => $account){
$type = self::get_alipay_account_type($account);
try{
$this->service->relation_bind($type, $account, $name ? $names[$i] : null);
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
return ['code'=>0, 'msg'=>'添加分账接收方成功'];
}
$type = self::get_alipay_account_type($account);
try{
$this->service->relation_bind($type, $account, $name);
return ['code'=>0, 'msg'=>'添加分账接收方成功'];
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
//删除分账接收方
public function deleteReceiver($account){
if(strpos($account, '|')){
$accounts = explode('|', $account);
foreach($accounts as $account){
$type = self::get_alipay_account_type($account);
try{
$this->service->relation_unbind($type, $account);
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
return ['code'=>0, 'msg'=>'删除分账接收方成功'];
}
$type = self::get_alipay_account_type($account);
try{
$this->service->relation_unbind($type, $account);
return ['code'=>0, 'msg'=>'删除分账接收方成功'];
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
private static function get_alipay_account_type($account){
if(is_numeric($account) && substr($account,0,4)=='2088' && strlen($account)==16)$type = 'userId';
else $type = 'loginName';
return $type;
}
}
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace lib\ProfitSharing;
use Exception;
class Chinaums implements IProfitSharing
{
static $paytype = 'chinaums';
private $channel;
private $service;
function __construct($channel){
$this->channel = $channel;
}
//请求分账
public function submit($trade_no, $api_trade_no, $account, $name, $money){
}
//查询分账结果
public function query($trade_no, $api_trade_no, $settle_no){
}
//解冻剩余资金
public function unfreeeze($trade_no, $api_trade_no){
}
//分账回退
public function return($trade_no, $api_trade_no, $account, $money){
}
//添加分账接收方
public function addReceiver($account, $name = null){
return ['code'=>0, 'msg'=>'添加分账接收方成功'];
}
//删除分账接收方
public function deleteReceiver($account){
return ['code'=>0, 'msg'=>'删除分账接收方成功'];
}
}
+104
View File
@@ -0,0 +1,104 @@
<?php
namespace lib\ProfitSharing;
use Exception;
class CommUtil
{
public static $plugins = ['alipay','alipaysl','alipayd','wxpayn','wxpaynp','yeepay','yseqt','chinaums','dinpay','adapay'];
public static $no_order_plugins = ['chinaums','dinpay'];
public static function getModel($channel){
if($channel['plugin'] == 'alipay' || $channel['plugin'] == 'alipaysl' || $channel['plugin'] == 'alipayd'){
return new Alipay($channel);
}elseif($channel['plugin'] == 'wxpayn' || $channel['plugin'] == 'wxpaynp'){
return new Wxpay($channel);
}elseif($channel['plugin'] == 'yeepay'){
return new Yeepay($channel);
}elseif($channel['plugin'] == 'yseqt'){
return new Yseqt($channel);
}elseif($channel['plugin'] == 'chinaums'){
return new Chinaums($channel);
}elseif($channel['plugin'] == 'dinpay'){
return new Dinpay($channel);
}elseif($channel['plugin'] == 'adapay'){
return new Adapay($channel);
}
return false;
}
public static function getReceiver($id){
global $DB;
return $DB->find('psreceiver', '*', ['id'=>$id]);
}
public static function getOrder($trade_no){
global $DB;
return $DB->getRow("SELECT A.*,B.channel,B.account,B.name,B.rate FROM pre_psorder A LEFT JOIN pre_psreceiver B ON A.rid=B.id WHERE A.trade_no=:trade_no", [':trade_no'=>$trade_no]);
}
//订单分账定时任务
public static function task(){
global $DB;
$limit = 10; //每次查询分账的订单数量
$list = $DB->getAll("SELECT A.*,B.channel,B.account,B.name,B.uid psuid,C.uid,C.subchannel FROM pre_psorder A INNER JOIN pre_psreceiver B ON B.id=A.rid LEFT JOIN pre_order C ON C.trade_no=A.trade_no WHERE A.status=1 ORDER BY A.id ASC LIMIT {$limit}");
foreach($list as $srow){
self::process_item($srow);
}
$limit = 10; //每次提交分账的订单数量
$list = $DB->getAll("SELECT A.*,B.channel,B.account,B.name,B.uid psuid,C.uid,C.subchannel FROM pre_psorder A INNER JOIN pre_psreceiver B ON B.id=A.rid LEFT JOIN pre_order C ON C.trade_no=A.trade_no WHERE A.status=0 AND (A.addtime<=DATE_SUB(NOW(), INTERVAL 60 SECOND) AND A.delay=0 OR A.addtime<=DATE_SUB(NOW(), INTERVAL 24 HOUR) AND A.delay=1) ORDER BY A.id ASC LIMIT {$limit}");
foreach($list as $srow){
self::process_item($srow);
}
}
//处理一个订单分账任务
public static function process_item($row){
global $DB;
$id = $row['id'];
$channel = $row['subchannel'] > 0 ? \lib\Channel::getSub($row['subchannel']) : \lib\Channel::get($row['channel'], $row['uid']?$DB->findColumn('user', 'channelinfo', ['uid'=>$row['uid']]):null);
if(!$channel) return;
$model = self::getModel($channel);
// status:0-待分账,1-已提交,2-成功,3-失败
if($row['status']==0){
if($row['money'] == 0){
$DB->update('psorder', ['status'=>3,'result'=>'分账金额为0'], ['id'=>$id]);
echo $row['trade_no'].' 分账金额为0<br/>';
return;
}
$result = $model->submit($row['trade_no'], $row['api_trade_no'], $row['account'], $row['name'], $row['money']);
if($result['code'] == 0){
$DB->update('psorder', ['status'=>1,'settle_no'=>$result['settle_no']], ['id'=>$id]);
}elseif($result['code'] == 1){
$DB->update('psorder', ['status'=>2,'settle_no'=>$result['settle_no']], ['id'=>$id]);
if(!empty($row['psuid']) && $channel['mode']==0){
changeUserMoney($row['psuid'], $row['money'], false, '订单分账', $row['trade_no']);
}
}elseif($result['code'] == -1){
$DB->update('psorder', ['status'=>3,'result'=>$result['msg']], ['id'=>$id]);
}
echo $row['trade_no'].' '.$result['msg'].'<br/>';
}elseif($row['status']==1){
$result = $model->query($row['trade_no'], $row['api_trade_no'], $row['settle_no']);
if($result['code']==0){
if($result['status']==1){
$DB->update('psorder', ['status'=>2], ['id'=>$id]);
if(!empty($row['psuid']) && $channel['mode']==0){
changeUserMoney($row['psuid'], $row['money'], false, '订单分账', $row['trade_no']);
}
$result = '分账成功';
}elseif($result['status']==2){
$DB->update('psorder', ['status'=>3,'result'=>$result['reason']], ['id'=>$id]);
$result = '分账失败:'.$result['reason'];
}else{
$result = '正在分账';
}
echo $row['trade_no'].' '.$result.'<br/>';
}else{
echo $row['trade_no'].' 查询失败:'.$result['msg'].'<br/>';
}
}
}
}
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace lib\ProfitSharing;
use Exception;
class Dinpay implements IProfitSharing
{
static $paytype = 'dinpay';
private $channel;
private $service;
function __construct($channel){
$this->channel = $channel;
}
//请求分账
public function submit($trade_no, $api_trade_no, $account, $name, $money){
}
//查询分账结果
public function query($trade_no, $api_trade_no, $settle_no){
}
//解冻剩余资金
public function unfreeeze($trade_no, $api_trade_no){
}
//分账回退
public function return($trade_no, $api_trade_no, $account, $money){
}
//添加分账接收方
public function addReceiver($account, $name = null){
return ['code'=>0, 'msg'=>'添加分账接收方成功'];
}
//删除分账接收方
public function deleteReceiver($account){
return ['code'=>0, 'msg'=>'删除分账接收方成功'];
}
}
@@ -0,0 +1,25 @@
<?php
namespace lib\ProfitSharing;
interface IProfitSharing
{
//请求分账
function submit($trade_no, $api_trade_no, $account, $name, $money);
//查询分账结果
function query($trade_no, $api_trade_no, $settle_no);
//解冻剩余资金
function unfreeeze($trade_no, $api_trade_no);
//分账回退
function return($trade_no, $api_trade_no, $account, $money);
//添加分账接收方
function addReceiver($account, $name = null);
//删除分账接收方
function deleteReceiver($account);
}
+219
View File
@@ -0,0 +1,219 @@
<?php
namespace lib\ProfitSharing;
use Exception;
class Wxpay implements IProfitSharing
{
static $paytype = 'wxpay';
private $channel;
private $service;
private $ecommerce;
function __construct($channel){
$this->channel = $channel;
$wechatpay_config = require(PLUGIN_ROOT.$channel['plugin'].'/inc/config.php');
$this->ecommerce = $wechatpay_config['ecommerce'];
$this->service = new \WeChatPay\V3\ProfitsharingService($wechatpay_config);
}
//请求分账
public function submit($trade_no, $api_trade_no, $account, $name, $money){
if(strpos($account, '|')){
global $DB;
$accounts = explode('|', $account);
$psorder = CommUtil::getOrder($trade_no);
$rates = explode('|', $psorder['rate']);
$order_money = $DB->findColumn('order', 'realmoney', ['trade_no'=>$trade_no]);
$receivers = [];
foreach($accounts as $i=>$account){
$rate = isset($rates[$i]) ? $rates[$i] : $rates[0];
$money = round($order_money * $rate / 100, 2);
$type = self::get_wxpay_account_type($account);
if($this->ecommerce){
$receivers[] = [
'type' => $type,
'receiver_account' => $account,
'amount' => intval(round($money*100)),
'description' => '订单分账'
];
}else{
$receivers[] = [
'type' => $type,
'account' => $account,
'amount' => intval(round($money*100)),
'description' => '订单分账'
];
}
}
if($this->ecommerce){
$param = [
'transaction_id' => $api_trade_no,
'out_order_no' => $trade_no,
'receivers' => $receivers,
'finish' => true,
];
}else{
$param = [
'transaction_id' => $api_trade_no,
'out_order_no' => $trade_no,
'receivers' => $receivers,
'unfreeze_unsplit' => true,
];
}
try{
$result = $this->service->submit($param);
return ['code'=>0, 'msg'=>'请求分账成功', 'settle_no'=>$result['order_id']];
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
$type = self::get_wxpay_account_type($account);
if($this->ecommerce){
$param = [
'transaction_id' => $api_trade_no,
'out_order_no' => $trade_no,
'receivers' => [
[
'type' => $type,
'receiver_account' => $account,
'amount' => intval(round($money*100)),
'description' => '订单分账'
]
],
'finish' => true,
];
}else{
$param = [
'transaction_id' => $api_trade_no,
'out_order_no' => $trade_no,
'receivers' => [
[
'type' => $type,
'account' => $account,
'amount' => intval(round($money*100)),
'description' => '订单分账'
]
],
'unfreeze_unsplit' => true,
];
}
try{
$result = $this->service->submit($param);
return ['code'=>0, 'msg'=>'请求分账成功', 'settle_no'=>$result['order_id']];
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
//查询分账结果
public function query($trade_no, $api_trade_no, $settle_no){
$reason_desc = ['ACCOUNT_ABNORMAL'=>'分账接收账户异常', 'NO_RELATION'=>'分账关系已解除', 'RECEIVER_HIGH_RISK'=>'高风险接收方', 'RECEIVER_REAL_NAME_NOT_VERIFIED'=>'接收方未实名', 'NO_AUTH'=>'分账权限已解除', 'RECEIVER_RECEIPT_LIMIT'=>'接收方已达收款限额', 'PAYER_ACCOUNT_ABNORMAL'=>'分出方账户异常', 'INVALID_REQUEST'=>'描述参数设置失败'];
try{
$result = $this->service->query($trade_no, $api_trade_no);
if(isset($result['state']) && $result['state'] == 'FINISHED' || isset($result['status']) && $result['status'] == 'FINISHED'){
$receiver = $result['receivers'][0];
if($receiver['result'] == 'SUCCESS'){
return ['code'=>0, 'status'=>1];
}elseif($receiver['result'] == 'CLOSED'){
return ['code'=>0, 'status'=>2, 'reason'=>'['.$receiver['fail_reason'].']'.$reason_desc[$receiver['fail_reason']]];
}else{
return ['code'=>0, 'status'=>0];
}
}else{
return ['code'=>0, 'status'=>0];
}
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
//解冻剩余资金
public function unfreeeze($trade_no, $api_trade_no){
try{
$this->service->unfreeze($trade_no, $api_trade_no);
return ['code'=>0, 'msg'=>'解冻剩余资金成功'];
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
//分账回退
public function return($trade_no, $api_trade_no, $account, $money){
$type = self::get_wxpay_account_type($account);
if($type == 'MERCHANT_ID'){
$params = [
'out_order_no' => $trade_no,
'out_return_no' => 'REF'.$trade_no,
'return_mchid' => $account,
'amount' => intval(round($money*100)),
'description' => '分账回退'
];
try{
$this->service->return($params);
return ['code'=>0, 'msg'=>'分账回退成功'];
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}else{
return ['code'=>-1,'msg'=>'分账到个人账户不支持回退'];
}
}
//添加分账接收方
public function addReceiver($account, $name = null){
if(strpos($account, '|')){
$accounts = explode('|', $account);
$names = explode('|', $name);
foreach($accounts as $i => $account){
$type = self::get_wxpay_account_type($account);
try{
$this->service->addReceiver($type, $account, $name ? $names[$i] : null);
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
return ['code'=>0, 'msg'=>'添加分账接收方成功'];
}
$type = self::get_wxpay_account_type($account);
try{
$this->service->addReceiver($type, $account, $name);
return ['code'=>0, 'msg'=>'添加分账接收方成功'];
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
//删除分账接收方
public function deleteReceiver($account){
if(strpos($account, '|')){
$accounts = explode('|', $account);
foreach($accounts as $account){
$type = self::get_wxpay_account_type($account);
try{
$this->service->deleteReceiver($type, $account);
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
return ['code'=>0, 'msg'=>'删除分账接收方成功'];
}
$type = self::get_wxpay_account_type($account);
try{
$this->service->deleteReceiver($type, $account);
return ['code'=>0, 'msg'=>'删除分账接收方成功'];
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
private static function get_wxpay_account_type($account){
if(is_numeric($account))$type = 'MERCHANT_ID';
else $type = 'PERSONAL_OPENID';
return $type;
}
}
+137
View File
@@ -0,0 +1,137 @@
<?php
namespace lib\ProfitSharing;
require(PLUGIN_ROOT.'yeepay/inc/YopClient.php');
use Exception;
class Yeepay implements IProfitSharing
{
static $paytype = 'yeepay';
private $channel;
private $service;
function __construct($channel){
$this->channel = $channel;
$this->service = new \Yeepay\YopClient($channel['appkey'], $channel['appsecret']);
}
//请求分账
public function submit($trade_no, $api_trade_no, $account, $name, $money){
$divideDetail = [
[
'ledgerNo' => $account,
'amount' => $money,
'ledgerType' => 'MERCHANT2MERCHANT',
]
];
$params = [
'parentMerchantNo' => $this->channel['appid'],
'merchantNo' => empty($this->channel['appmchid'])?$this->channel['appid']:$this->channel['appmchid'],
'orderId' => $trade_no,
'uniqueOrderNo' => $api_trade_no,
'divideRequestId' => 'F'.$trade_no,
'divideDetail' => json_encode($divideDetail),
'isUnfreezeResidualAmount' => 'TRUE',
];
try{
$result = $this->service->post('/rest/v1.0/divide/apply', $params);
if($result['code'] == 'OPR00000'){
if($result['status'] == 'SUCCESS'){
return ['code'=>1, 'msg'=>'分账成功', 'settle_no'=>$result['divideRequestId']];
}else{
return ['code'=>0, 'msg'=>'请求分账成功', 'settle_no'=>$result['divideRequestId']];
}
}else{
throw new Exception('['.$result['code'].']'.$result['message']);
}
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
//查询分账结果
public function query($trade_no, $api_trade_no, $settle_no){
$params = [
'parentMerchantNo' => $this->channel['appid'],
'merchantNo' => empty($this->channel['appmchid'])?$this->channel['appid']:$this->channel['appmchid'],
'divideRequestId' => $settle_no,
'orderId' => $trade_no,
'uniqueOrderNo' => $api_trade_no,
];
try{
$result = $this->service->get('/rest/v1.0/divide/query', $params);
if($result['code'] == 'OPR00000'){
if($result['status'] == 'SUCCESS'){
return ['code'=>0, 'status'=>1];
}elseif($result['status'] == 'FAIL'){
return ['code'=>0, 'status'=>2, 'reason'=>$result['message']];
}else{
return ['code'=>0, 'status'=>0];
}
}else{
throw new Exception('['.$result['code'].']'.$result['message']);
}
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
//解冻剩余资金
public function unfreeeze($trade_no, $api_trade_no){
$params = [
'parentMerchantNo' => $this->channel['appid'],
'merchantNo' => empty($this->channel['appmchid'])?$this->channel['appid']:$this->channel['appmchid'],
'divideRequestId' => 'C'.$trade_no,
'orderId' => $trade_no,
'uniqueOrderNo' => $api_trade_no,
];
try{
$result = $this->service->post('/rest/v1.0/divide/complete', $params);
if($result['code'] == 'OPR00000'){
return ['code'=>0, 'msg'=>'解冻剩余资金成功'];
}else{
throw new Exception('['.$result['code'].']'.$result['message']);
}
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
//分账回退
public function return($trade_no, $api_trade_no, $account, $money){
return ['code'=>-1, 'msg'=>'暂不支持分账回退'];
$params = [
'parentMerchantNo' => $this->channel['appid'],
'merchantNo' => empty($this->channel['appmchid'])?$this->channel['appid']:$this->channel['appmchid'],
'divideBackRequestId' => 'B'.$trade_no,
'divideRequestId' => $settle_no,
'orderId' => $trade_no,
'uniqueOrderNo' => $api_trade_no,
'divideBackDetail' => '',
];
try{
$result = $this->service->post('/rest/v1.0/divide/back', $params);
if($result['code'] == 'OPR00000'){
return ['code'=>0, 'msg'=>'退分账成功'];
}else{
throw new Exception('['.$result['code'].']'.$result['message']);
}
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
//添加分账接收方
public function addReceiver($account, $name = null){
return ['code'=>0, 'msg'=>'添加分账接收方成功'];
}
//删除分账接收方
public function deleteReceiver($account){
return ['code'=>0, 'msg'=>'删除分账接收方成功'];
}
}
+145
View File
@@ -0,0 +1,145 @@
<?php
namespace lib\ProfitSharing;
require(PLUGIN_ROOT.'yseqt/inc/YseqtClient.php');
use Exception;
class Yseqt implements IProfitSharing
{
static $paytype = 'yseqt';
private $channel;
private $service;
function __construct($channel){
$this->channel = $channel;
$this->service = new \YseqtClient($channel['appid'], $channel['appkey']);
}
//请求分账
public function submit($trade_no, $api_trade_no, $account, $name, $money){
global $DB;
$order_money = $DB->findColumn('order', 'realmoney', ['trade_no'=>$trade_no]);
$divisionList = [
[
'divisionMercId' => $account,
'isChargeFee' => 'N',
'divAmount' => $money,
],
[
'divisionMercId' => $this->channel['appmchid'],
'isChargeFee' => 'Y',
'divAmount' => round($order_money-$money, 2),
]
];
$requestNo = date('YmdHis').rand(1000,9999);
$params = [
'requestNo' => $requestNo,
'payeeMerchantNo' => $this->channel['appmchid'],
'origRequestNo' => $trade_no,
'amount' => $order_money,
'isDivision' => 'Y',
'divisionMode' => '02',
'divisionList' => $divisionList,
];
try{
$result = $this->service->execute('divisionRegister', $params);
if($result['subCode'] == 'COM000'){
if($result['state'] == 'SPLIT_SUCCESS'){
return ['code'=>1, 'msg'=>'预分账成功', 'settle_no'=>$result['requestNo']];
}elseif($result['state'] == 'SUCCESS'){
return ['code'=>1, 'msg'=>'分账成功', 'settle_no'=>$result['requestNo']];
}else{
return ['code'=>0, 'msg'=>'受理成功', 'settle_no'=>$result['requestNo']];
}
}else{
throw new Exception($result['subMsg']);
}
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
//查询分账结果
public function query($trade_no, $api_trade_no, $settle_no){
$params = [
'origRequestNo' => $trade_no,
];
try{
$result = $this->service->execute('divisionQuery', $params);
if($result['subCode'] == 'COM000'){
if($result['state'] == 'SPLIT_SUCCESS' || $result['state'] == 'SUCCESS'){
return ['code'=>0, 'status'=>1];
}elseif($result['state'] == 'FAILED'){
return ['code'=>0, 'status'=>2, 'reason'=>$result['note']];
}else{
return ['code'=>0, 'status'=>0];
}
}else{
throw new Exception($result['subMsg']);
}
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
//解冻剩余资金
public function unfreeeze($trade_no, $api_trade_no){
global $DB;
$requestNo = date('YmdHis').rand(1000,9999);
$order_money = $DB->findColumn('order', 'realmoney', ['trade_no'=>$trade_no]);
$params = [
'requestNo' => $requestNo,
'payeeMerchantNo' => $this->channel['appmchid'],
'origRequestNo' => $trade_no,
'amount' => $order_money,
'isDivision' => 'N',
'divisionMode' => '02',
];
try{
$result = $this->service->execute('divisionRegister', $params);
if($result['subCode'] == 'COM000'){
return ['code'=>0, 'msg'=>'解冻剩余资金成功'];
}else{
throw new Exception($result['subMsg']);
}
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
//分账回退
public function return($trade_no, $api_trade_no, $account, $money){
$requestNo = date('YmdHis').rand(1000,9999);
$params = [
'requestNo' => $requestNo,
'payeeMerchantNo' => $this->channel['appmchid'],
'origRequestNo' => $trade_no,
'divisionMercId' => $account,
'amount' => $money,
];
try{
$result = $this->service->execute('divisionBack', $params);
if($result['subCode'] == 'COM000'){
return ['code'=>0, 'msg'=>'退分账成功'];
}else{
throw new Exception($result['subMsg']);
}
} catch (Exception $e) {
return ['code'=>-1, 'msg'=>$e->getMessage()];
}
}
//添加分账接收方
public function addReceiver($account, $name = null){
return ['code'=>0, 'msg'=>'添加分账接收方成功'];
}
//删除分账接收方
public function deleteReceiver($account){
return ['code'=>0, 'msg'=>'删除分账接收方成功'];
}
}