Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pay
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bp
pay
Commits
7b8dfc0b
Commit
7b8dfc0b
authored
Jul 06, 2021
by
wanjilong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add: 提交守护进程
parent
2867ef0b
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
141 additions
and
128 deletions
+141
-128
BootstrapCli.php
application/BootstrapCli.php
+20
-3
RefundException.php
application/exception/custom/RefundException.php
+1
-0
Daemon.php
application/modules/Cli/controllers/Daemon.php
+1
-1
PayService.php
application/services/pay/PayService.php
+52
-76
PingxxService.php
application/services/pingxx/PingxxService.php
+8
-5
RefundService.php
application/services/refund/RefundService.php
+7
-27
Wallet.php
daemon/Wallet.php
+44
-0
cli.php
public/cli.php
+8
-16
No files found.
application/BootstrapCli.php
View file @
7b8dfc0b
<?php
use
Yaf\Dispatcher
;
class
Bootstrap
extends
Yaf\Bootstrap_Abstract
{
/**
* 项目基本初始化操作.
*/
public
function
_initProject
()
{
date_default_timezone_set
(
'PRC'
);
}
/**
* 初始化配置文件
* 全局配置文件 ,环境配置文件 错误码配置文件等
...
...
@@ -12,10 +22,17 @@ class Bootstrap extends Yaf\Bootstrap_Abstract{
Yaf\Registry
::
set
(
'cliConfig'
,
$globalConfig
);
}
/**
* 禁用视图
* autoload.
*
* @param Dispatcher $dispatcher
*/
public
function
_initView
(
\Yaf\Dispatcher
$dispatcher
)
{
$dispatcher
->
disableView
();
public
function
_initLoader
(
Dispatcher
$dispatcher
)
{
$loader
=
Yaf\Loader
::
getInstance
();
$loader
->
import
(
ROOT_PATH
.
'/vendor/autoload.php'
);
$loader
->
import
(
APP_PATH
.
'/library/helper.php'
);
}
}
application/exception/custom/RefundException.php
View file @
7b8dfc0b
...
...
@@ -18,5 +18,6 @@ class RefundException extends BaseException
4
=>
'目前仅支持支付后的订单退款,请核对'
,
5
=>
'该订单不允许退款,请核对'
,
6
=>
'该退款单核对ping++状态为未支付,请稍后重试!'
,
7
=>
'已核销计算订单不支持退款!'
,
];
}
application/modules/Cli/controllers/Daemon.php
View file @
7b8dfc0b
...
...
@@ -27,7 +27,7 @@ class DaemonController extends Cli
if
(
empty
(
$task_name
)){
echo
<<<EOD
usage: php cli.php daemon run "t=
[string]&n=[int|default:4]&j=[string]
"
usage: php cli.php daemon run "t=
wallet&n=2&j=sync_wallet
"
t daemo 脚本类名
n 进程数
j 进程别名,默认同脚本类名
...
...
application/services/pay/PayService.php
View file @
7b8dfc0b
...
...
@@ -34,7 +34,6 @@ class PayService
public
function
do_pay
(
$order_id
,
$user_id
)
{
// 获取订单信息
$data
=
OrderService
::
getFullOrderData
(
$order_id
,
$user_id
);
if
(
empty
(
$data
[
'result'
]))
{
...
...
@@ -56,7 +55,8 @@ class PayService
}
// 判断是否存在有效订单
$expire_time
=
time
()
+
30
*
60
;
$max_expire_time
=
config
(
'pay'
,
'pay.expire_time'
)
??
1800
;
$expire_time
=
time
()
+
$max_expire_time
;
$pay_order_id
=
$this
->
gen_pay_order_id
(
$user_id
);
$pay_order
=
[
'pay_order_id'
=>
$pay_order_id
,
...
...
@@ -155,13 +155,13 @@ class PayService
throw
new
PayException
([
'cus'
=>
5
]);
}
if
(
$cnt
==
0
&&
$pay_order
[
'pay_order_status'
]
==
Dictionary
::
O_PAY_STATUS_PAYED
)
{
//保持幂等返回成功
if
(
$cnt
==
0
&&
$pay_order
[
'pay_order_status'
]
==
Dictionary
::
O_PAY_STATUS_PAYED
)
{
return
[
'pay_order_id'
=>
$pay_order_id
];
}
//获取订单 + 子单 + 分销信息
$ret
=
OrderService
::
getFullOrderData
(
$
this
->
pay_order
[
'order_id'
],
$this
->
pay_order
[
'user_id'
]);
$ret
=
OrderService
::
getFullOrderData
(
$
pay_order
[
'order_id'
],
$
pay_order
[
'user_id'
]);
if
(
empty
(
$ret
[
'result'
][
'order_info'
]))
{
throw
new
PayException
([
'cus'
=>
1
]);
}
...
...
@@ -170,6 +170,8 @@ class PayService
// 生成支付清分单
$this
->
make_order_clearing
(
$ret
[
'result'
]);
return
[
'pay_order_id'
=>
$pay_order_id
];
}
/**
...
...
@@ -184,8 +186,10 @@ class PayService
try
{
PayOrderItem
::
beginTransaction
();
$cnt
=
PayOrderItem
::
update
([
'notify_account_status'
=>
1
,
],
[
'order_item_id'
=>
$order_item_id
,
'notify_account_status'
=>
0
]);
'notify_account_status'
=>
0
,
'can_notify_account'
=>
1
,
'can_notify_account_time'
=>
date
(
'Y-m-d H:i:s'
),
],
[
'order_item_id'
=>
$order_item_id
,
'can_notify_account'
=>
0
]);
$refund
=
RefundOrder
::
getMaster
(
'*'
,
[
'order_item_id'
=>
$order_item_id
]);
if
(
!
empty
(
$refund
))
{
...
...
@@ -212,12 +216,35 @@ class PayService
return
[
'order_item_id'
=>
$order_item_id
];
}
return
[
'order_item_id'
=>
$order_item_id
];
}
/**
* @param $order_item_id
* @throws \App\Exception\custom\CodeSpecialException
* 同步钱包处理
*/
public
function
sync_account_wallet
(
$order_item_id
)
{
$cnt
=
PayOrderItem
::
update
([
'notify_account_status'
=>
1
,
'notify_account_success_time'
=>
date
(
'Y-m-d H:i:s'
)
],
[
'order_item_id'
=>
$order_item_id
,
'can_notify_account'
=>
1
,
'notify_account_status'
=>
0
]);
if
(
$cnt
==
0
)
{
//乐观锁,不满足条件不处理
return
true
;
}
$clearing_items
=
PayOrderClearingItem
::
select
(
'*'
,
[
'order_item_id'
=>
$
item
[
'order_item_id'
]
]
[
'order_item_id'
=>
$
order_item_id
]
);
$wallet_list
=
[];
foreach
(
$clearing_items
as
$row
)
{
if
(
$row
[
'pay_amount'
]
<=
0
)
{
continue
;
}
$wallet_list
[]
=
[
'user_id'
=>
$row
[
'account_id'
],
'service_name'
=>
10
,
...
...
@@ -225,24 +252,30 @@ class PayService
'amount'
=>
$row
[
'pay_amount'
],
'third_order_id'
=>
$row
[
'pay_order_clearing_item_id'
],
'third_order_id_type'
=>
1
,
'third_order_desc'
=>
'
核销
收入'
,
'third_order_desc'
=>
'
订单
收入'
,
];
}
if
(
$wallet_list
)
{
$ret
=
WalletService
::
send
(
$wallet_list
);
if
(
$ret
)
{
if
(
$ret
)
{
//同步成功,返回结果
PayOrderItem
::
update
([
'notify_account_status'
=>
2
,
'notify_account_success_time'
=>
date
(
'Y-m-d H:i:s'
)
],
[
'order_item_id'
=>
$order_item_id
,
'
notify_account_status
'
=>
1
]);
],
[
'order_item_id'
=>
$order_item_id
,
'
can_notify_account
'
=>
1
]);
}
else
{
//补偿处理
PayOrderItem
::
update
([
'notify_account_status'
=>
0
,
],
[
'order_item_id'
=>
$order_item_id
,
'can_notify_account'
=>
1
]);
}
}
else
{
//没有需要同步的,显示处理
PayOrderItem
::
update
([
'notify_account_status'
=>
2
,
'notify_account_success_time'
=>
date
(
'Y-m-d H:i:s'
)
],
[
'order_item_id'
=>
$order_item_id
,
'can_notify_account'
=>
1
]);
}
return
[
'order_item_id'
=>
$order_item_id
];
}
/**
...
...
@@ -292,15 +325,14 @@ class PayService
throw
new
PayException
([
'cut'
=>
5
]);
}
if
(
$this
->
wallet_list
)
{
$ret
=
WalletService
::
send
(
$this
->
wallet_list
);
if
(
$ret
)
{
//如果是分销子单,则需进入结算队列
foreach
(
$this
->
order_items
as
$r
)
{
// 收集直接到账信息
if
(
$r
[
'marketing_type'
]
==
1
)
{
PayOrderItem
::
update
([
'notify_account_status'
=>
2
,
'notify_account_success_time'
=>
date
(
'Y-m-d H:i:s'
)
],
[
'pay_order_id'
=>
$this
->
pay_order
[
'order_id'
],
'notify_account_status'
=>
1
]);
}
else
{
//todo 补偿处理
'can_notify_account'
=>
1
,
'can_notify_account_time'
=>
date
(
'Y-m-d H:i:s'
)
],
[
'order_item_id'
=>
$r
[
'order_item_id'
]]);
}
}
}
...
...
@@ -333,49 +365,6 @@ class PayService
return
$total_tip
;
}
/**
* 计算平台运营补贴
*/
private
function
make_platform_subsidy_clearing
()
{
return
0
;
//本期不做平台补贴
$account
=
$this
->
get_marketing_subsidy
();
$total_tip
=
$account
[
'amount'
];
if
(
empty
(
$total_tip
))
{
return
0
;
}
$account
[
'account_type'
]
=
Dictionary
::
ACCOUNT_TYPE_SS
;
$account
[
'pay_type'
]
=
Dictionary
::
PAY_TYPE_OUT
;
$account
[
'pay_sub_type'
]
=
Dictionary
::
PAY_SUB_TYPE_SYS_OUT
;
$account
[
'need_recorded'
]
=
Dictionary
::
NO
;
$this
->
do_clearing_data
(
$account
,
$total_tip
,
false
);
return
$total_tip
;
}
/**
* 计算商户运营补贴
*/
private
function
make_merchant_subsidy_clearing
()
{
return
0
;
// 本期不做商户补贴
$account
=
$this
->
get_marketing_subsidy
();
$total_tip
=
$account
[
'amount'
];
if
(
empty
(
$total_tip
))
{
return
0
;
}
$account
[
'account_type'
]
=
Dictionary
::
ACCOUNT_TYPE_M
;
$account
[
'pay_type'
]
=
Dictionary
::
PAY_TYPE_OUT
;
$account
[
'pay_sub_type'
]
=
Dictionary
::
PAY_SUB_TYPE_M_OUT
;
$account
[
'need_recorded'
]
=
Dictionary
::
NO
;
$this
->
do_clearing_data
(
$account
,
$total_tip
,
false
);
return
$total_tip
;
}
/**
* @param $total
* @return false|float
...
...
@@ -534,19 +523,6 @@ class PayService
'need_recorded'
=>
$account
[
'need_recorded'
],
];
// 收集直接到账信息
if
(
$r
[
'marketing_type'
]
==
1
&&
$current_tip
>
0
)
{
$this
->
wallet_list
[]
=
[
'user_id'
=>
$account
[
'account_id'
],
'service_name'
=>
10
,
'source_name'
=>
1
,
'amount'
=>
$current_tip
,
'third_order_id'
=>
$id
,
'third_order_id_type'
=>
1
,
'third_order_desc'
=>
'订单收入'
,
];
}
$cleared_amount
+=
$r
[
'payment'
];
$cleared_tip
+=
$current_tip
;
}
...
...
application/services/pingxx/PingxxService.php
View file @
7b8dfc0b
...
...
@@ -56,10 +56,9 @@ class PingxxService
'refund_mode'
=>
'to_source'
,
//退款模式。原路退回:to_source,退至余额:to_balance。默认为原路返回。
]
);
FileLog
::
info
(
'ping++:'
.
'退款订单返回'
,
json_encode
([
'res'
=>
$ret
]));
$response
=
json_decode
(
$ret
,
true
);
return
$response
[
'data'
]
;
return
$response
;
/*
{
...
...
@@ -91,12 +90,16 @@ class PingxxService
*/
}
catch
(
\Pingpp\Error\Base
$e
)
{
//throw new $e;
if
(
$e
->
getHttpStatus
()
!=
null
)
{
header
(
'Status: '
.
$e
->
getHttpStatus
());
echo
$e
->
getHttpBody
();
$msg
=
$e
->
getHttpBody
();
}
else
{
echo
$e
->
getMessage
();
$msg
=
$e
->
getMessage
();
}
exit
(
$msg
);
throw
new
\Exception
(
$msg
,
'2001'
);
}
}
...
...
application/services/refund/RefundService.php
View file @
7b8dfc0b
...
...
@@ -8,6 +8,7 @@ use App\Models\Dictionary;
use
App\Models\order\mysql\PayOrder
;
use
App\Models\order\mysql\PayOrderClearing
;
use
App\Models\order\mysql\PayOrderClearingItem
;
use
App\Models\order\mysql\PayOrderItem
;
use
App\Models\order\mysql\RefundOrder
;
use
App\Services\order\OrderService
;
...
...
@@ -105,21 +106,6 @@ class RefundService
//不用搞清分核算,是否需要平台记账?
$this
->
make_refund_clear
(
$refund_order_id
);
/*
try{
$ret = $this->send_wallet();
if($ret) {
$edit = ['notify_account_success_time'=>date('Y-m-d H:i:s')];
} else {
$edit = ['notify_account_status'=>Dictionary::SEND_ACCOUNT_STATUS_UNDO];
}
}catch (WalletException $e) {
$edit = ['notify_account_status'=>Dictionary::SEND_ACCOUNT_STATUS_UNDO];
}
//状态确认或回退,回退交给补偿服务处理
RefundOrder::update($edit, $refund_order_id);
*/
}
/**
...
...
@@ -137,15 +123,13 @@ class RefundService
try
{
RefundOrder
::
beginTransaction
();
$pay_order
=
PayOrder
::
getMaster
(
'*'
,
[
'order_id'
=>
$where
[
'order_id'
],
'pay_order_status'
=>
Dictionary
::
O_PAY_STATUS_PAYED
]);
if
(
empty
(
$pay_order
))
{
$pay_order
_item
=
PayOrderItem
::
getMaster
(
'*'
,
[
'order_item_id'
=>
$where
[
'order_item_id'
]
]);
if
(
empty
(
$pay_order
_item
))
{
throw
new
RefundException
([
'cus'
=>
4
]);
}
/* 子单是否已经结算分润
if($pay_order['can_refund']) {
throw new RefundException(['cus' => 5]);
if
(
$pay_order_item
[
'can_notify_account'
]
==
1
)
{
throw
new
RefundException
([
'cus'
=>
7
]);
}
*/
$refund_order
=
RefundOrder
::
getMaster
(
'*'
,
[
'order_item_id'
=>
$where
[
'order_item_id'
]]);
if
(
!
empty
(
$refund_order
))
{
...
...
@@ -170,9 +154,10 @@ class RefundService
//重新计算微信手续费
$cleared_amount
=
$cleared_tip
=
0
;
$pay_order
=
PayOrder
::
getMaster
(
'*'
,
[
'order_id'
=>
$where
[
'order_id'
]]);
// 总共手续费
$wx_tip
=
PayOrderClearing
::
getMaster
(
'*'
,
[
'order_id'
=>
$
pay_order
[
'order_id'
],
'order_id'
=>
$
where
[
'order_id'
],
'pay_order_id'
=>
$pay_order
[
'pay_order_id'
],
'pay_type'
=>
Dictionary
::
PAY_TYPE_IN
]
);
...
...
@@ -251,12 +236,7 @@ class RefundService
}
private
function
make_refund_clear
()
{
return
true
;
$this
->
refund_order
;
$pay_order
=
PayOrder
::
get
(
'*'
,
[
'order_id'
=>
$this
->
refund_order
[
'order_id'
],
'pay_order_status'
=>
Dictionary
::
O_PAY_STATUS_PAYED
]);
$list
=
PayOrderClearingItem
::
get
(
'*'
,
[
'order_item_id'
=>
$this
->
refund_order
[
'order_item_id'
],
'pay_order_id'
=>
$pay_order
[
'pay_order_id'
]]);
//仅处理WX手续费,平台补贴,商户补贴
}
...
...
daemon/Wallet.php
0 → 100644
View file @
7b8dfc0b
<?php
namespace
Daemon
;
use
Api\PhpServices\Daemon\DaemonServiceInterface
;
use
Api\PhpUtils\Log\FileLog
;
use
App\Models\order\mysql\PayOrderItem
;
use
App\Services\pay\PayService
;
class
Wallet
implements
DaemonServiceInterface
{
/**
* 核销、支付后直接到钱包补偿任务
*/
public
function
run
()
{
FileLog
::
info
(
'Daemon:'
,
'start'
);
if
(
!
empty
(
$data
[
'LIMIT'
]))
{
$where
[
'LIMIT'
]
=
$data
[
'LIMIT'
];
}
if
(
!
empty
(
$data
[
'ORDER'
]))
{
$where
[
'ORDER'
]
=
'can_notify_account_time ASC'
;
}
$where
[
'can_notify_account'
]
=
1
;
$where
[
'ORDER'
]
=
'can_notify_account_time ASC'
;
$where
[
'LIMIT'
]
=
[
0
,
10
];
$list
=
PayOrderItem
::
selectMaster
(
'*'
,
$where
);
$payService
=
new
PayService
();
foreach
(
$list
as
$row
)
{
$payService
->
sync_account_wallet
(
$row
[
'order_item_id'
]);
}
if
(
empty
(
$list
))
{
sleep
(
10
);
}
}
}
\ No newline at end of file
public/cli.php
View file @
7b8dfc0b
...
...
@@ -14,9 +14,12 @@ if( !substr(php_sapi_name(), 0, 3) == 'cli' ) {
die
;
}
define
(
'ROOT_PATH'
,
realpath
(
__DIR__
.
'/../'
));
define
(
'APPLICATION_PATH'
,
realpath
(
__DIR__
.
'/../'
));
require
APPLICATION_PATH
.
'/vendor/autoload.php'
;
$application
=
new
Yaf\Application
(
APPLICATION_PATH
.
"/conf/cli.ini"
);
define
(
'APP_PATH'
,
realpath
(
__DIR__
.
'/../application'
));
require
ROOT_PATH
.
'/vendor/autoload.php'
;
$application
=
new
Yaf\Application
(
ROOT_PATH
.
"/conf/cli.ini"
);
/**
* 获取模块/控制器/方法
...
...
@@ -24,21 +27,10 @@ $application = new Yaf\Application( APPLICATION_PATH . "/conf/cli.ini");
$module
=
"cli"
;
$controller
=
$argv
[
1
]
??
""
;
$method
=
$argv
[
2
]
??
""
;
$param
=
$argv
[
3
]
??
[];
if
(
$param
)
$param
=
[];
if
(
!
empty
(
$argv
[
3
])
)
{
$param
=
convertUrlQuery
(
$param
);
parse_str
(
$argv
[
3
],
$param
);
}
$application
->
bootstrap
()
->
getDispatcher
()
->
dispatch
(
new
Yaf\Request\Simple
(
""
,
$module
,
$controller
,
$method
,
$param
)
);
function
convertUrlQuery
(
$query
)
{
$queryParts
=
explode
(
'&'
,
$query
);
$params
=
array
();
foreach
(
$queryParts
as
$param
)
{
$item
=
explode
(
'='
,
$param
);
$params
[
$item
[
0
]]
=
$item
[
1
];
}
return
$params
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment