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
a963c378
Commit
a963c378
authored
Jul 04, 2021
by
wanjilong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add: init post
parent
9b9c9981
Changes
32
Hide whitespace changes
Inline
Side-by-side
Showing
32 changed files
with
847 additions
and
1811 deletions
+847
-1811
Index.php
application/controllers/Index.php
+18
-1
Code.php
application/exception/custom/Code.php
+2
-0
CodeSpecialException.php
application/exception/custom/CodeSpecialException.php
+31
-0
OrderException.php
application/exception/custom/OrderException.php
+22
-0
PayException.php
application/exception/custom/PayException.php
+3
-2
RefundException.php
application/exception/custom/RefundException.php
+1
-0
WalletException.php
application/exception/custom/WalletException.php
+22
-0
Sdk.php
application/library/Helpers/Sdk.php
+35
-0
helper.php
application/library/helper.php
+1
-1
Dictionary.php
application/models/Dictionary.php
+3
-0
PayOrder.php
application/models/order/mysql/PayOrder.php
+0
-1
PayOrderItem.php
application/models/order/mysql/PayOrderItem.php
+23
-0
Account.php
application/modules/Pay/controllers/Account.php
+0
-250
Callback.php
application/modules/Pay/controllers/Callback.php
+47
-0
Order.php
application/modules/Pay/controllers/Order.php
+47
-0
Recruit.php
application/modules/Pay/controllers/Recruit.php
+0
-147
Mongo.php
application/modules/Test/controllers/Mongo.php
+0
-55
Mysql.php
application/modules/Test/controllers/Mysql.php
+0
-85
Request.php
application/modules/Test/controllers/Request.php
+0
-90
Session.php
application/modules/Test/controllers/Session.php
+0
-216
Test.php
application/modules/Test/controllers/Test.php
+0
-13
Ttt.php
application/modules/Test/controllers/Ttt.php
+0
-590
Hook.php
application/plugins/Hook.php
+1
-1
MongoService.php
application/services/demo/MongoService.php
+0
-75
MysqlService.php
application/services/demo/MysqlService.php
+0
-130
OrderService.php
application/services/order/OrderService.php
+23
-64
PayService.php
application/services/pay/PayService.php
+222
-40
PingxxService.php
application/services/pingxx/PingxxService.php
+192
-0
RefundService.php
application/services/refund/RefundService.php
+119
-50
WalletService.php
application/services/wallet/WalletService.php
+29
-0
demo.php
public/demo.php
+4
-0
index.php
public/index.php
+2
-0
No files found.
application/controllers/Index.php
View file @
a963c378
<?php
<?php
use
Api\PhpServices\Idgen\Idgen
;
use
Yaf\Controller_Abstract
;
use
Yaf\Controller_Abstract
;
/**
/**
...
@@ -10,6 +11,22 @@ class IndexController extends Controller_Abstract
...
@@ -10,6 +11,22 @@ class IndexController extends Controller_Abstract
use
\Helpers\ApiResponse
;
use
\Helpers\ApiResponse
;
public
function
IndexAction
()
{
public
function
IndexAction
()
{
$this
->
success
();
$res
=
Idgen
::
get
(
appConfig
(
'idgen.partner'
),
appConfig
(
'idgen.key'
),
[],
[[
"type"
=>
"55c768"
,
'number'
=>
12
,
"count"
=>
1
]]);
$id
=
$res
[
'id_datetime'
][
'55c768'
]
??
[];
$this
->
success
([
'id'
=>
$id
]);
}
public
function
orderAction
()
{
$ret
=
[
'id'
=>
'aa'
,
];
$this
->
success
(
$ret
);
}
}
}
}
application/exception/custom/Code.php
View file @
a963c378
...
@@ -13,4 +13,6 @@ class Code
...
@@ -13,4 +13,6 @@ class Code
{
{
const
PAY
=
101000
;
const
PAY
=
101000
;
const
REFUND
=
102000
;
const
REFUND
=
102000
;
const
ORDER
=
103000
;
const
WALLET
=
104000
;
}
}
\ No newline at end of file
application/exception/custom/CodeSpecialException.php
0 → 100644
View file @
a963c378
<?php
namespace
App\Exception\custom
;
use
App\Exception\BaseException
;
/**
* Class TestException
* @package App\Exception\custom
*/
class
CodeSpecialException
extends
BaseException
{
public
function
__construct
(
$err
,
$re_msg
=
""
)
{
$params
=
[];
$code
=
\Yaconf
::
get
(
"errorcode.common.code."
.
$err
);
$msg
=
$re_msg
??
\Yaconf
::
get
(
"errorcode.common.msg."
.
$err
);
if
(
strlen
(
$code
)
&&
strlen
(
$msg
)){
$params
=
[
'code'
=>
$code
,
'msg'
=>
$msg
];
}
parent
::
__construct
(
$params
);
}
}
\ No newline at end of file
application/exception/custom/OrderException.php
0 → 100644
View file @
a963c378
<?php
namespace
App\Exception\custom
;
use
App\Exception\BaseException
;
class
OrderException
extends
BaseException
{
protected
$base_code
=
Code
::
ORDER
;
protected
$cus
=
[
0
=>
'系统异常请联系管理员'
,
1
=>
'订单信息不存在,请核对'
,
2
=>
'退款已经成功操作,请核对'
,
3
=>
'退款进行中,请稍等'
,
4
=>
'目前仅支持支付后的订单退款,请核对'
,
5
=>
'该订单不允许退款,请核对'
,
6
=>
'该退款单核对ping++状态为未支付,请稍后重试!'
,
];
}
application/exception/custom/PayException.php
View file @
a963c378
...
@@ -11,8 +11,9 @@ class PayException extends BaseException
...
@@ -11,8 +11,9 @@ class PayException extends BaseException
protected
$base_code
=
Code
::
PAY
;
protected
$base_code
=
Code
::
PAY
;
protected
$cus
=
[
protected
$cus
=
[
0
=>
'
用户已通过个人认证,无需重复认证
'
,
0
=>
'
系统错误,请稍收重试
'
,
1
=>
'企业已通过认证,无需重复认证
'
,
3
=>
'该订单已经支付,请刷新确认
'
,
4
=>
'费率计算错误,费率分母为0'
,
4
=>
'费率计算错误,费率分母为0'
,
5
=>
'支付回调失败,请核对订单'
,
];
];
}
}
application/exception/custom/RefundException.php
View file @
a963c378
...
@@ -17,5 +17,6 @@ class RefundException extends BaseException
...
@@ -17,5 +17,6 @@ class RefundException extends BaseException
3
=>
'退款进行中,请稍等'
,
3
=>
'退款进行中,请稍等'
,
4
=>
'目前仅支持支付后的订单退款,请核对'
,
4
=>
'目前仅支持支付后的订单退款,请核对'
,
5
=>
'该订单不允许退款,请核对'
,
5
=>
'该订单不允许退款,请核对'
,
6
=>
'该退款单核对ping++状态为未支付,请稍后重试!'
,
];
];
}
}
application/exception/custom/WalletException.php
0 → 100644
View file @
a963c378
<?php
namespace
App\Exception\custom
;
use
App\Exception\BaseException
;
class
WalletException
extends
BaseException
{
protected
$base_code
=
Code
::
WALLET
;
protected
$cus
=
[
0
=>
'系统异常请联系管理员'
,
1
=>
'订单信息不存在,请核对'
,
2
=>
'退款已经成功操作,请核对'
,
3
=>
'退款进行中,请稍等'
,
4
=>
'目前仅支持支付后的订单退款,请核对'
,
5
=>
'该订单不允许退款,请核对'
,
6
=>
'该退款单核对ping++状态为未支付,请稍后重试!'
,
];
}
application/library/Helpers/Sdk.php
0 → 100644
View file @
a963c378
<?php
namespace
Helpers
;
use
Helpers\Logger
;
use
Api\PhpUtils\Common\TimeOut
;
/**
* Sdk 获取接口
*/
class
Sdk
{
/**
* @param $current_amount
* @param $total_amount
* @param $cleared_amount
* @param $total_tip
* @param $cleared_tip
* 计算微信手续费公式,计算单位是分
*/
public
static
function
call
(
$url
,
$params
,
$headers
=
[])
{
$header
=
[
'X-REQUEST-ID'
=>
Logger
::
getTraceId
(),
'Content-type'
=>
'application/json'
,
];
$headers
=
array_merge
(
$headers
,
$header
);
Logger
::
info
(
'api request'
,
[
'url'
=>
$url
,
'params'
=>
$params
]);
$data
=
(
new
TimeOut
())
->
runPost
(
$url
,
$params
,
$headers
);
Logger
::
info
(
'api request'
,
[
'ret'
=>
$data
]);
return
$data
;
}
}
\ No newline at end of file
application/library/helper.php
View file @
a963c378
...
@@ -16,7 +16,7 @@ if (!function_exists('config')) {
...
@@ -16,7 +16,7 @@ if (!function_exists('config')) {
*/
*/
function
config
(
$file
,
$param
=
''
){
function
config
(
$file
,
$param
=
''
){
if
(
empty
(
$file
)
||
!
file_exists
(
ROOT_PATH
.
"/yaconf/"
.
$file
.
".ini"
)){
if
(
empty
(
$file
)
||
!
file_exists
(
ROOT_PATH
.
"/yaconf/"
.
$file
.
".ini"
)){
return
""
;
//
return "";
}
}
$env
=
Application
::
app
()
->
environ
()
??
"test"
;
$env
=
Application
::
app
()
->
environ
()
??
"test"
;
...
...
application/models/Dictionary.php
View file @
a963c378
...
@@ -46,4 +46,7 @@ class Dictionary
...
@@ -46,4 +46,7 @@ class Dictionary
public
const
REFUND_ORDER_STATUS_SEND
=
1
;
//待确认
public
const
REFUND_ORDER_STATUS_SEND
=
1
;
//待确认
public
const
REFUND_ORDER_STATUS_OK
=
2
;
//已退款
public
const
REFUND_ORDER_STATUS_OK
=
2
;
//已退款
public
const
SEND_ACCOUNT_STATUS_UNDO
=
0
;
//未通知
public
const
SEND_ACCOUNT_STATUS_DONE
=
1
;
//已通知
}
}
application/models/order/mysql/PayOrder.php
View file @
a963c378
...
@@ -42,7 +42,6 @@ class PayOrder extends MysqlBase
...
@@ -42,7 +42,6 @@ class PayOrder extends MysqlBase
)
->
fetch
();
)
->
fetch
();
if
(
empty
(
$order
))
{
if
(
empty
(
$order
))
{
$new
[
'order_id'
]
=
$order_id
;
$link
->
insert
(
self
::
getTableName
(),
$pay_order
);
$link
->
insert
(
self
::
getTableName
(),
$pay_order
);
$order
=
$link
->
query
(
$order
=
$link
->
query
(
$sql
,
[
$sql
,
[
...
...
application/models/order/mysql/PayOrderItem.php
0 → 100644
View file @
a963c378
<?php
namespace
App\Models\order\mysql
;
use
Api\PhpUtils\Mysql\MysqlBase
;
class
PayOrderItem
extends
MysqlBase
{
protected
static
$write
;
protected
static
$read
;
protected
static
$db_config_index
=
'metro'
;
protected
function
getTableName
()
{
return
'pay_order_item'
;
}
protected
function
getPKey
()
{
return
'pay_order_item_id'
;
}
}
application/modules/Pay/controllers/Account.php
deleted
100644 → 0
View file @
9b9c9981
<?php
use
App\Base\Base
;
use
App\Exception\custom\LifeAccountException
;
use
App\Exception\custom\LifeAccountRoleException
;
use
App\Models\auth\mysql\Merchant
;
use
App\Models\auth\mysql\LifeAccountRole
;
use
App\Services\lifeaccount\LifeAccountService
;
use
Validate\UserPhoneValidate
;
use
App\Models\auth\mysql\LifeAccount
;
use
App\Exception\custom\MerchantException
;
use
App\Exception\custom\AuthException
;
use
Helpers\Aes
;
use
Api\PhpUtils\Http\Request
;
use
App\Exception\custom\DataException
;
use
App\Models\auth\mysql\PersionalAuthRecord
;
use
App\Models\auth\mysql\EnterpriseAuthRecord
;
use
Api\PhpUtils\Cache\CacheUtil
;
use
Api\PhpUtils\Redis\RedisUtil
;
use
Api\PhpUtils\Log\FileLog
;
class
AccountController
extends
Base
{
/**
* 创建未认证的个人生活号
*/
public
function
createAction
()
{
// 获取手机号
(
new
UserPhoneValidate
())
->
validate
();
$params
=
$this
->
params
;
$uid
=
$params
[
'user_id'
];
$mobile
=
$params
[
'mobile'
];
// 查询是否有创建资格
if
(
!
LifeAccountService
::
permission
(
$uid
)[
'personal'
])
{
throw
new
LifeAccountException
([
'cus'
=>
3
]);
}
try
{
Merchant
::
beginTransaction
();
LifeAccountService
::
unauth_account
(
$uid
,
$mobile
);
Merchant
::
commit
();
}
catch
(
\Exception
$exception
)
{
Merchant
::
rollback
();
throw
$exception
;
}
$this
->
success
();
}
/**
* 获取生活号详情
*
*/
public
function
get_account_infoAction
()
{
$params
=
$this
->
params
;
$data
[
'account_id'
]
=
$params
[
'account_id'
];
//当前用户ID
$data
[
'followed_id'
]
=
$params
[
'followed_id'
];
// 被关注用户ID
$data
[
'account_type'
]
=
1
;
$data
[
'followed_type'
]
=
1
;
//拿粉丝、关注、赞数和是否关注
$url
=
config
(
'interface'
,
'interaction.index.life_detail'
);
if
(
empty
(
$url
))
{
throw
new
DataException
([
'cus'
=>
0
]);
}
$res
=
(
new
Request
())
->
get
(
$url
,
$data
);
var_dump
(
$res
);
exit
;
if
(
$res
[
'code'
]
==
0
&&
isset
(
$res
[
'response'
]))
{
$this
->
returnResponse
(
$res
[
'response'
]);
return
;
}
//获取生活号角色
$LifeAccountRole
=
LifeAccountRole
::
getRecord
([
'user_id'
=>
$user_id
],
"*"
);
if
(
$LifeAccountRole
===
false
||
empty
(
$LifeAccountRole
))
{
throw
new
LifeAccountRoleException
([
'cus'
=>
7
]);
}
// 查生活号与商户信息
$lifeAccountInfo
=
LifeAccount
::
get
(
'*'
,
[
'life_account_id'
=>
$LifeAccountRole
[
'life_account_id'
]]);
if
(
$lifeAccountInfo
===
false
||
empty
(
$lifeAccountInfo
))
{
throw
new
LifeAccountException
([
'cus'
=>
2
]);
}
//tab
if
(
$user_id
==
$lifeAccountInfo
[
'life_account_admin_id'
])
{
//主态
$tab
=
array
(
1
=>
'服务'
,
2
=>
'招聘'
,
3
=>
'发布'
,
4
=>
'参与'
,
5
=>
'推荐'
);
}
else
{
//客态
$tab
=
array
(
1
=>
'服务'
,
2
=>
'招聘'
,
3
=>
'发布'
,
4
=>
'参与'
,
5
=>
'推荐'
);
}
$retLifeAccount
[
'life_account_id'
]
=
(
string
)
$lifeAccountInfo
[
'life_account_id'
];
$retLifeAccount
[
'life_account_name'
]
=
$lifeAccountInfo
[
'life_account_name'
];
$retLifeAccount
[
'life_account_icon'
]
=
$lifeAccountInfo
[
'life_account_icon'
];
$retLifeAccount
[
'life_account_admin_id'
]
=
$lifeAccountInfo
[
'life_account_admin_id'
];
$retLifeAccount
[
'life_account_auth_status'
]
=
$lifeAccountInfo
[
'life_account_auth_status'
];
$retLifeAccount
[
'life_account_status'
]
=
$lifeAccountInfo
[
'life_account_status'
];
$retLifeAccount
[
'enterprise_auth_record_status'
]
=
$lifeAccountInfo
[
'enterprise_auth_record_status'
];
$retLifeAccount
[
'enterprise_auth_record_id'
]
=
$lifeAccountInfo
[
'enterprise_auth_record_id'
];
$retLifeAccount
[
'update_time'
]
=
$lifeAccountInfo
[
'update_time'
];
$retLifeAccount
[
'create_time'
]
=
$lifeAccountInfo
[
'create_time'
];
$retLifeAccount
[
'role_type'
]
=
$LifeAccountRole
[
'role_type'
];
$retLifeAccount
[
'tab'
]
=
$tab
;
$this
->
success
([
'result'
=>
$retLifeAccount
]);
}
/**
* 根据生活号id获取认证信息
* 1、生活号所有字段
* 2、职业标签(个人生活号)
* 3、姓名、身份证号码、公司名称、统一社会信用代码、生活号类型(是个体还是普通企业)
*/
public
function
get_account_by_lidAction
()
{
$params
=
$this
->
params
;
$lid
=
$params
[
'life_account_id'
];
// 查生活号与商户信息
$lifeAccountInfo
=
LifeAccount
::
get
([
'life_account_id'
,
'life_account_name'
,
'life_account_type'
,
'merchant_id'
,
'life_account_admin_id'
,
'life_account_auth_status'
,
'life_account_status'
,
'enterprise_auth_record_id'
,
'update_time'
,
'create_time'
],
[
'life_account_id'
=>
$lid
]);
if
(
$lifeAccountInfo
===
false
||
empty
(
$lifeAccountInfo
))
{
throw
new
LifeAccountException
([
'cus'
=>
2
]);
}
// $this->cache = CacheUtil::getInstance('cache');
// $key = sprintf("life_account_info|%d",$lid);
// $redis_ret = $this->cache->set($key,json_encode($lifeAccountInfo),200);
// $redis_get = $this->cache->get($key);
//根据商户id 查询个人认证记录id
$merchant
=
Merchant
::
get
([
'owner_id'
,
'merchant_type'
],
[
'merchant_id'
=>
$lifeAccountInfo
[
'merchant_id'
]]);
if
(
$merchant
===
false
||
empty
(
$merchant
))
{
throw
new
MerchantException
([
'cus'
=>
3
]);
}
if
(
$lifeAccountInfo
[
'enterprise_auth_record_id'
]
==
0
)
{
//个人生活号
if
(
$merchant
[
'merchant_type'
]
==
1
)
{
$where
=
[
'user_id'
=>
$merchant
[
'owner_id'
]];
}
else
{
$where
=
[
'persional_auth_record_id'
=>
$merchant
[
'owner_id'
]];
}
//根据个人认证记录id查询个人认证详情
$personalInfo
=
PersionalAuthRecord
::
get
([
'full_name'
,
'occupation'
,
'id_card'
],
$where
);
if
(
$personalInfo
===
false
||
empty
(
$personalInfo
))
{
throw
new
AuthException
([
'cus'
=>
23
]);
}
$lifeAccountInfo
[
'legal_person'
]
=
$personalInfo
[
'full_name'
];
$lifeAccountInfo
[
'occupation'
]
=
$personalInfo
[
'occupation'
];
$lifeAccountInfo
[
'id_card'
]
=
Aes
::
decrypt
(
$personalInfo
[
'id_card'
]);
$lifeAccountInfo
[
'id_type'
]
=
0
;
//个人
}
else
{
//企业生活号
$enterpriseInfo
=
EnterpriseAuthRecord
::
get
([
'legal_person'
,
'code'
,
'legal_id_card'
,
'name'
,
'data_type'
,
'audit_status'
,
'mobile'
],
[
'life_account_id'
=>
$lid
]);
if
(
$enterpriseInfo
===
false
||
empty
(
$enterpriseInfo
))
{
throw
new
AuthException
([
'cus'
=>
23
]);
}
$lifeAccountInfo
[
'legal_person'
]
=
$enterpriseInfo
[
'legal_person'
];
$lifeAccountInfo
[
'code'
]
=
$enterpriseInfo
[
'code'
];
$lifeAccountInfo
[
'name'
]
=
$enterpriseInfo
[
'name'
];
$lifeAccountInfo
[
'audit_status'
]
=
$enterpriseInfo
[
'audit_status'
];
$lifeAccountInfo
[
'mobile'
]
=
$enterpriseInfo
[
'mobile'
];
$lifeAccountInfo
[
'id_type'
]
=
$enterpriseInfo
[
'data_type'
]
==
1
?
1
:
2
;
//2:个体工商户; 3:普通企业
$lifeAccountInfo
[
'id_card'
]
=
Aes
::
decrypt
(
$enterpriseInfo
[
'legal_id_card'
]);
}
$lifeTag
=
LifeAccountService
::
getLifeAccountTag
(
$lifeAccountInfo
[
'life_account_id'
]);
$lifeAccountInfo
[
'tag'
]
=
$lifeTag
[
'life_account_tag'
]
??
''
;
$lifeAccountInfo
[
'life_account_id'
]
=
(
string
)
$lifeAccountInfo
[
'life_account_id'
];
$this
->
success
([
'result'
=>
$lifeAccountInfo
]);
}
/*
* 批量获取生活号角色表数据
*/
public
function
get_role_listAction
()
{
$params
=
$this
->
params
;
$params
[
'page'
]
=
!
empty
(
$params
[
'page'
])
?
$params
[
'page'
]
:
1
;
$role_id
=
$params
[
'role_id'
]
??
0
;
$limit
=
!
empty
(
$params
[
'page_size'
])
?
$params
[
'page_size'
]
:
50
;
$page
=
(
$params
[
'page'
]
-
1
)
*
$limit
;
$data
[
'role_id[>]'
]
=
$role_id
;
$data
[
'role_type'
]
=
1
;
$data
[
'LIMIT'
]
=
[
$page
,
$limit
];
$list
=
LifeAccountRole
::
getRecordList
(
$data
);
//var_dump(LifeAccountRole::log());exit;
unset
(
$data
[
'LIMIT'
]);
$count
=
LifeAccountRole
::
getCount
(
$data
);
$this
->
success
([
'result'
=>
[
'data'
=>
$list
,
'count'
=>
$count
]]);
}
/*
* 批量获取管理员对应的生活号
*/
public
function
get_life_listAction
()
{
$params
=
$this
->
params
;
$list
=
[];
if
(
$params
)
{
$list
=
LifeAccountRole
::
getRecordList
([
'user_id'
=>
$params
,
'role_type'
=>
1
],
[
'role_id'
,
'user_id'
,
'life_account_id'
]);
}
$this
->
success
([
'result'
=>
$list
]);
}
/*
* 批量获取生活号对应的管理员
*/
public
function
get_user_listAction
()
{
$params
=
$this
->
params
;
$list
=
[];
if
(
$params
)
{
$list
=
LifeAccount
::
getRecords
([
'life_account_id'
=>
$params
],
[
'life_account_id'
,
'life_account_admin_id'
,
'life_account_name'
]);
//FileLog::info('get_user_list', json_encode(LifeAccount::log()));
}
$this
->
success
([
'result'
=>
$list
]);
}
/**
* 根据uid获取生活号id
*/
public
function
get_lid_by_uidAction
()
{
$params
=
$this
->
params
;
$uid
=
$params
[
'uid'
];
$list
=
[];
if
(
$params
)
{
$list
=
LifeAccountRole
::
getRecordList
([
'user_id'
=>
$uid
],
[
'life_account_id'
]);
}
$this
->
success
([
'result'
=>
$list
]);
}
}
application/modules/Pay/controllers/Callback.php
0 → 100644
View file @
a963c378
<?php
use
App\Base\Base
;
use
App\Services\pay\PayService
;
use
App\Services\refund\RefundService
;
class
CallbackController
extends
Base
{
/**
* 创建支付订单,返回前端ping++的支付信息
*/
public
function
payAction
()
{
try
{
$raw_data
=
file_get_contents
(
'php://input'
);
$paySrv
=
new
PayService
();
$ret
=
$paySrv
->
call_back
(
$raw_data
);
$this
->
success
([
'result'
=>
$ret
]);
}
catch
(
Exception
$e
)
{
http_response_code
(
500
);
$this
->
failed
(
'500'
);
}
}
public
function
refundAction
()
{
try
{
$raw_data
=
file_get_contents
(
'php://input'
);
$refundSrv
=
new
RefundService
();
$ret
=
$refundSrv
->
call_back
(
$raw_data
);
$this
->
success
([
'result'
=>
$ret
]);
}
catch
(
Exception
$e
)
{
http_response_code
(
500
);
$this
->
failed
(
'500'
);
}
}
}
application/modules/Pay/controllers/Order.php
0 → 100644
View file @
a963c378
<?php
use
App\Base\Base
;
use
App\Services\pay\PayService
;
use
App\Services\refund\RefundService
;
class
OrderController
extends
Base
{
/**
* 创建支付订单,返回前端ping++的支付信息
*/
public
function
payAction
()
{
$params
=
$this
->
params
;
$user_id
=
$params
[
'user_id'
];
$order_id
=
$params
[
'order_id'
];
$paySrv
=
new
PayService
();
$ret
=
$paySrv
->
do_pay
(
$order_id
,
$user_id
);
$this
->
success
([
'result'
=>
$ret
]);
}
public
function
refundAction
()
{
$params
=
$this
->
params
;
$user_id
=
$params
[
'user_id'
];
$order_item_id
=
$params
[
'order_item_id'
];
$refundSrv
=
new
RefundService
();
$ret
=
$refundSrv
->
do_refund
(
$order_item_id
,
$user_id
);
$this
->
success
([
'result'
=>
$ret
]);
}
public
function
write_offAction
()
{
$params
=
$this
->
params
;
$user_id
=
$params
[
'user_id'
];
$order_item_id
=
$params
[
'order_item_id'
];
$refundSrv
=
new
PayService
();
$ret
=
$refundSrv
->
write_off
(
$order_item_id
,
$user_id
);
$this
->
success
([
'result'
=>
$ret
]);
}
}
application/modules/Pay/controllers/Recruit.php
deleted
100644 → 0
View file @
9b9c9981
<?php
use
App\Base\Base
;
use
App\Exception\custom\LifeAccountException
;
use
App\Models\auth\mysql\LifeAccount
;
use
App\Models\auth\mysql\Merchant
;
use
App\Services\lifeaccount\LifeAccountService
;
use
Validate\RecruitValidate
;
use
App\Models\auth\mysql\RecruitAccount
;
use
App\Exception\custom\DataException
;
use
App\Models\auth\mysql\EnterpriseAuthRecord
;
use
Api\PhpServices\JwUser\JwUser
;
class
RecruitController
extends
Base
{
/**
* 创建招聘个人生活号
*/
public
function
create_recruitAction
(){
// 验证参数
(
new
RecruitValidate
())
->
validate
();
$params
=
$this
->
params
;
$uid
=
$params
[
'ownerId'
];
$name
=
$params
[
'name'
];
if
(
!
isset
(
$uid
)
||
!
isset
(
$name
)){
//添加招聘表数据
$params
[
'lifeAccountId'
]
=
-
1
;
//uid、name为空 不具备创建生活号的条件
$recruit_id
=
RecruitAccount
::
insert
(
$params
);
if
(
!
$recruit_id
)
{
throw
new
DataException
([
'cus'
=>
1
]);
}
$this
->
success
([
'result'
=>
[
'life_account_id'
=>
-
1
]]);
}
// 查询是否有创建资格
if
(
!
LifeAccountService
::
permission
(
$uid
)[
'personal'
]){
throw
new
LifeAccountException
([
'cus'
=>
3
]);
}
try
{
RecruitAccount
::
beginTransaction
();
//创建未认证的生活号
$life_account_id
=
LifeAccountService
::
unauth_account
(
$uid
,
$name
,
0
,
'merchant-c'
);
if
(
!
$life_account_id
)
{
throw
new
DataException
([
'cus'
=>
1
]);
}
//添加招聘表数据
$recruit_id
=
RecruitAccount
::
insert
(
$params
);
if
(
!
$recruit_id
)
{
throw
new
DataException
([
'cus'
=>
1
]);
}
RecruitAccount
::
commit
();
}
catch
(
\Exception
$exception
)
{
RecruitAccount
::
rollback
();
throw
$exception
;
}
$this
->
success
([
'result'
=>
[
'life_account_id'
=>
$life_account_id
]]);
}
/**
* 更新招聘个人生活号
*/
public
function
update_recruitAction
(){
// 验证参数
(
new
RecruitValidate
())
->
scene
(
'ent'
)
->
validate
();
$params
=
$this
->
params
;
$uid
=
$params
[
'ownerId'
];
$res
=
RecruitAccount
::
update
(
$params
,
[
'ownerId'
=>
$uid
]);
if
(
$res
===
false
)
{
throw
new
DataException
([
'cus'
=>
1
]);
}
$this
->
success
();
}
/**
* 查看招聘个人生活号
*/
public
function
get_recruitAction
(){
// 验证参数
(
new
RecruitValidate
())
->
scene
(
'ent'
)
->
validate
();
$params
=
$this
->
params
;
$uid
=
$params
[
'ownerId'
];
$recruit_ret
=
RecruitAccount
::
get
(
'*'
,
[
'ownerId'
=>
$uid
]);
if
(
empty
(
$recruit_ret
))
{
throw
new
DataException
([
'cus'
=>
0
]);
}
foreach
(
$recruit_ret
as
$key
=>
$val
){
if
(
$val
===
'NULL'
){
unset
(
$recruit_ret
[
$key
]);
}
}
$this
->
success
([
'result'
=>
$recruit_ret
]);
}
/**
* 检测未绑定招聘个人生活号,并创建个人未认证生活号 并绑定
*/
public
function
check_recruitAction
(){
$recruit_ret
=
RecruitAccount
::
select
(
'*'
,
[
'lifeAccountId '
=>
0
]);
if
(
empty
(
$recruit_ret
))
{
throw
new
DataException
([
'cus'
=>
0
]);
}
foreach
(
$recruit_ret
as
$key
=>
$val
){
//获取简网用户信息
$jwUser
=
new
JwUser
();
$user_info
=
$jwUser
->
getUserByUserId
([
'user_id'
=>
$val
[
'ownerId'
]]);
$avatar
=
$user_info
[
'data'
][
'avatar'
]
??
'http://qn.jwshq.cn/profile_unknown_2019_1'
;
// 查询是否有创建资格
if
(
!
LifeAccountService
::
permission
(
$val
[
'ownerId'
])[
'personal'
]){
throw
new
LifeAccountException
([
'cus'
=>
3
]);
}
try
{
RecruitAccount
::
beginTransaction
();
//查询是否有重复的生活号名称,有重复的加一个随机数
$lifeInfo
=
LifeAccount
::
getRecord
([
'life_account_name'
=>
$val
[
'name'
]]);
if
(
!
empty
(
$lifeInfo
)){
$rand_num
=
mt_rand
(
0
,
99
);
$val
[
'name'
]
=
$val
[
'name'
]
.
$rand_num
;
}
//创建未认证的生活号
$life_account_id
=
LifeAccountService
::
unauth_account
(
$val
[
'ownerId'
],
$val
[
'name'
],
0
,
'batch'
,
$avatar
);
if
(
!
$life_account_id
)
{
throw
new
DataException
([
'cus'
=>
1
]);
}
//更新招聘表数据生活号ID
$res
=
RecruitAccount
::
update
([
'lifeAccountId'
=>
$life_account_id
],
[
'ownerId'
=>
$val
[
'ownerId'
]]);
if
(
$res
===
false
)
{
throw
new
DataException
([
'cus'
=>
1
]);
}
RecruitAccount
::
commit
();
}
catch
(
\Exception
$exception
)
{
RecruitAccount
::
rollback
();
throw
$exception
;
}
sleep
(
1
);
}
$this
->
success
([
'result'
=>
[
'life_account_id'
=>
$life_account_id
]]);
}
}
\ No newline at end of file
application/modules/Test/controllers/Mongo.php
deleted
100644 → 0
View file @
9b9c9981
<?php
use
App\Base\Base
;
use
App\Services\demo\MongoService
;
class
MongoController
extends
Base
{
public
function
addAction
()
{
$mongo_service
=
new
MongoService
();
$ret
=
$mongo_service
->
addUser
();
var_dump
(
$ret
);
exit
;
}
public
function
addManyAction
()
{
$mongo_service
=
new
MongoService
();
$ret
=
$mongo_service
->
addManyUser
();
var_dump
(
$ret
);
exit
;
}
public
function
deleteAction
()
{
$mongo_service
=
new
MongoService
();
$ret
=
$mongo_service
->
deleteUser
();
var_dump
(
$ret
);
exit
;
}
public
function
updateAction
()
{
$mongo_service
=
new
MongoService
();
$ret
=
$mongo_service
->
updateUser
();
var_dump
(
$ret
);
exit
;
}
public
function
getAction
()
{
$mongo_service
=
new
MongoService
();
$ret
=
$mongo_service
->
getUser
();
var_dump
(
$ret
);
exit
;
}
public
function
getManyAction
()
{
$mongo_service
=
new
MongoService
();
$ret
=
$mongo_service
->
getManyUser
();
var_dump
(
$ret
);
exit
;
}
}
application/modules/Test/controllers/Mysql.php
deleted
100644 → 0
View file @
9b9c9981
<?php
use
App\Base\Base
;
use
App\Services\demo\MysqlService
;
class
MysqlController
extends
Base
{
public
function
addAction
(){
$mysql_service
=
new
MysqlService
();
$ret
=
$mysql_service
->
addUser
();
var_dump
(
$ret
);
exit
;
}
public
function
addManyAction
(){
$mysql_service
=
new
MysqlService
();
$ret
=
$mysql_service
->
addManyUser
();
var_dump
(
$ret
);
exit
;
}
public
function
deleteAction
(){
$mysql_service
=
new
MysqlService
();
$ret
=
$mysql_service
->
deleteUser
();
var_dump
(
$ret
);
exit
;
}
public
function
updateAction
(){
$mysql_service
=
new
MysqlService
();
$ret
=
$mysql_service
->
updateUser
();
var_dump
(
$ret
);
exit
;
}
public
function
getAction
()
{
$mysql_service
=
new
MysqlService
();
$ret
=
$mysql_service
->
getUser
();
var_dump
(
$ret
);
exit
;
}
public
function
getManyAction
(){
$mysql_service
=
new
MysqlService
();
$ret
=
$mysql_service
->
getManyUser
();
var_dump
(
$ret
);
exit
;
}
public
function
countAction
(){
$mysql_service
=
new
MysqlService
();
$ret
=
$mysql_service
->
countUser
();
var_dump
(
$ret
);
exit
;
}
public
function
maxAction
(){
$mysql_service
=
new
MysqlService
();
$ret
=
$mysql_service
->
maxUser
();
var_dump
(
$ret
);
exit
;
}
public
function
minAction
(){
$mysql_service
=
new
MysqlService
();
$ret
=
$mysql_service
->
minUser
();
var_dump
(
$ret
);
exit
;
}
public
function
avgAction
(){
$mysql_service
=
new
MysqlService
();
$ret
=
$mysql_service
->
avgUser
();
var_dump
(
$ret
);
exit
;
}
public
function
sumAction
(){
$mysql_service
=
new
MysqlService
();
$ret
=
$mysql_service
->
sumUser
();
var_dump
(
$ret
);
exit
;
}
}
application/modules/Test/controllers/Request.php
deleted
100644 → 0
View file @
9b9c9981
<?php
use
App\Base\Base
;
use
Api\PhpUtils\Http\Request
;
class
RequestController
extends
Base
{
public
function
GetAction
()
{
$url
=
'http://10.103.17.132:8007/adserver/goodsAds'
;
$options
=
[
'query'
=>
[
'docIdList'
=>
'0SQ0d3dH'
,
'appId'
=>
'pro'
,
'platform'
=>
0
],
'timeout'
=>
0.5
//自定义超时秒数,覆盖默认值
];
$request
=
new
Request
();
$ret
=
$request
->
get
(
$url
,
$options
);
var_dump
(
$ret
);
exit
;
}
public
function
PostAction
(){
$url
=
'http://sso.dengwei4378.com/api/master/getInfoByMasterName'
;
$options
=
[
'form_params'
=>
[
"masterName"
=>
'dengwei4378'
,
"system"
=>
'rbac'
],
'timeout'
=>
1
//自定义超时秒数,覆盖默认值
];
$request
=
new
Request
();
$post_ret
=
$request
->
post
(
$url
,
$options
);
var_dump
(
$post_ret
);
exit
;
}
/**
* 并发GET
*/
public
function
ConGetAction
(){
$params
=
[
0
=>
[
'url'
=>
'http://sso.dengwei4378.com'
,
'timeout'
=>
3
//自定义超时秒数,覆盖默认值
],
1
=>
[
'url'
=>
'https://api.github.com/'
,
'timeout'
=>
3
//自定义超时秒数,覆盖默认值
],
];
$request
=
new
Request
();
$ret
=
$request
->
concurrencyGet
(
$params
);
var_dump
(
$ret
);
exit
;
}
public
function
ConPostAction
(){
$params
=
[
0
=>
[
'url'
=>
'http://lock-screen-push.int.yidian-inc.com/lock-screen/list'
,
'headers'
=>
[
'Content-type'
=>
'application/json'
,
'User-Agent'
=>
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3100.0 Safari/537.36'
],
'json'
=>
[
//json格式
"bizid"
=>
"YDZX"
,
"uid"
=>
"765073697"
,
"platform"
=>
"1"
,
"appid"
=>
"hipu"
],
'timeout'
=>
0.1
//自定义超时秒数,覆盖默认值
],
1
=>
[
'url'
=>
'http://sso.dengwei4378.com/api/master/getInfoByMasterName'
,
'form_params'
=>
[
//表单格式
"masterName"
=>
'dengwei4378'
,
"system"
=>
'rbac'
],
'timeout'
=>
0.2
//自定义超时秒数,覆盖默认值
],
];
$request
=
new
Request
();
$ret
=
$request
->
concurrencyPost
(
$params
);
var_dump
(
$ret
);
exit
;
}
}
application/modules/Test/controllers/Session.php
deleted
100644 → 0
View file @
9b9c9981
<?php
use
App\Base\Base
;
use
Helpers\Aes
;
use
Api\PhpUtils\Http\Request
;
use
Api\PhpServices\Session\SessionManager
;
use
App\Exception\BaseException
;
class
SessionController
extends
Base
{
public
function
StartAction
()
{
// $key = 'asdfasdfasdfasdf';
// $iv = 'fdsafdsafdsafdsa';
// $salt = "12341/5";
// var_dump(base64_encode($salt));
// var_dump(strtolower(str_replace(array('+','/','='), array(''), base64_encode($salt))));
// var_dump($data = openssl_encrypt($salt, "AES-128-CBC", $key, 0, $iv));
// var_dump(openssl_decrypt($data, "AES-128-CBC", $key, 0, $iv));
// exit;
// $result = (new Request())->get('http://10.126.171.30:18080/topom', [], 1);
// // $proxy = $result['stats']['proxy'];
// $server = $result['stats']['group']['models'];
// $arr = [];
// foreach ($server as $item) {
// $arr[] = $item['servers'][1]['server'];
// }
// print_r($arr);
// exit;
// print_r(\Yaconf::get('interface.test.service'));exit;
// echo $s = '{'.str_replace(array('+','/','='), array('-','_',''), base64_encode('12345')).'}';
// exit;
// $s = json_decode(json_encode(['a' =>'{MTIzNDU}e3eec597a5a3f9420b445c89d38a6fbc7c']),true);
// print_r($s);exit;
// phpinfo();exit;
// $key = 'interface.test.service.session.get';
// echo \Yaconf::get($key);
// exit;
$ret
=
SessionManager
::
start
();
// print_r($_SERVER);
// print_r($_COOKIE);
var_dump
(
$ret
);
print_r
(
$_SESSION
);
// $ret1 = SessionManager::destroy();
// // print_r($_SERVER);
// // print_r($_COOKIE);
// var_dump($ret1);
// print_r($_SESSION);
// var_dump($ret);
}
public
function
CreateAction
()
{
$ret
=
SessionManager
::
set
(
'metro'
,
'12345'
,
true
,
[
'a'
=>
'aaa'
,
'b'
=>
'bbb'
,
'c'
=>
'ccc'
,
'd'
=>
'ddd'
],
1
);
var_dump
(
$ret
);
print_r
(
$_SESSION
);
exit
;
}
public
function
DestroyAction
()
{
$ret
=
SessionManager
::
destroy
();
// print_r($_SERVER);
// print_r($_COOKIE);
var_dump
(
$ret
);
print_r
(
$_SESSION
);
}
public
function
GetAction
()
{
print_r
(
$request
=
$this
->
getRequest
()
->
getRequest
());
$sessionid
=
$request
[
'sid'
]
??
'aedcc37ea232aade90037716ddab1debe6'
;
$url
=
$this
->
getBaseUri
()
.
'/get-session'
;
$query
=
[
'sessionid'
=>
$sessionid
];
// $query = ['sessionid' => 'jssionidtest'];
$result
=
(
new
Request
())
->
get
(
$url
,
$query
,
3000
);
print_r
(
$result
);
exit
;
if
(
isset
(
$result
[
'code'
])
&&
$result
[
'code'
]
==
0
)
{
return
true
;
}
return
false
;
}
public
function
SetAction
()
{
$url
=
$this
->
getBaseUri
()
.
'/set-session'
;
$sessionData
=
[
'id'
=>
123
,
'name'
=>
'test'
];
$params
=
[
'sessionid'
=>
'jssionidtest11'
,
'data'
=>
(
$sessionData
),
'expire'
=>
600
,
'key'
=>
'c071f6e5923a648a5ef88f32b6f738e1'
];
$result
=
(
new
Request
())
->
post
(
$url
,
$params
,
1000
,
'json'
);
print_r
(
$result
);
}
public
function
DelAction
()
{
$url
=
$this
->
getBaseUri
()
.
'/delete-session'
;
$query
=
[
'sessionid'
=>
[
'jssionidtest1'
,
'jssionidtest'
],
'key'
=>
'c071f6e5923a648a5ef88f32b6f738e1'
];
$result
=
(
new
Request
())
->
get
(
$url
,
$query
,
1000
);
print_r
(
$result
);
}
public
function
MgetAction
()
{
$url
=
$this
->
getBaseUri
()
.
'/get-many-session'
;
$query
=
[
'sessionid'
=>
[
'YPZQISU1Tjxg3wJLFWJmVA'
,
'E4vo3R5EfaPS-pnyDzia3Q'
]];
$result
=
(
new
Request
())
->
get
(
$url
,
$query
,
2000
);
print_r
(
$result
);
exit
;
$url
=
$this
->
getBaseUri
()
.
'/get-many-session'
;
$query
=
[
'sessionid'
=>
[
'jssionidtest2'
,
'jssionidtest1'
]];
$result
=
(
new
Request
())
->
get
(
$url
,
$query
,
2000
);
print_r
(
$result
);
exit
;
// $validSessionIds[] = 'a';
// $validSessionIds[] = 'b';
// $validSessionIds[] = 'c';
// echo $validSessionIds[rand(0, count($validSessionIds) - 1)];
// exit;
// // todo 请求接口读redis
// echo $url = $this->getBaseUri() . '/get-session1';
// $query = ['sessionid' => 'jssionidtest'];
// $result = (new Request())->get($url, $query, 1000);
// if (isset($result['code']) && $result['code'] == 0 && isset($result['result'])) {
// $data = $result['result'];
// print_r($data);
// }else {
// print_r($result);
// }
// exit;
// $r = \Api\PhpUtils\Common\IP::find('114.114.114.114');
// print_r($r);
// exit;
// $_SESSION['abc'] = 'ttt';
// echo $_SESSION['abc'];
// echo $_SESSION['abc'];
// echo $_SESSION['abc'];
// echo $_SESSION['abc'];
// exit;
// $abc = '123'. "\x7F" . 456;
// var_dump($abc);exit;//string(7) "123456" 不可见字任作为分隔符
// $a = base64_encode('6543211111dasfsdfasdf1111asdfasdfs1111');
// var_dump($a);
// var_dump(sha1($a));
// var_dump(substr(sha1($a), -2));
// $a = $a . substr(sha1($a), -2);
// var_dump($a);
// var_dump(substr($a, 0, -2));
// $a = substr($a, 0, -2);
// var_dump($a);
// var_dump(sha1($a));
// var_dump(substr(sha1($a), -2));
// exit;
// var_dump(strlen($a));
// var_dump($a);exit;
// var_dump($this->response);
// var_dump(Yaf\Dispatcher::getInstance()->getResponse());
// exit;
// $data = ['appid'=> 'appid', 'verison'=>'023200', 'reqid'=>'11adddddddfasdfasdfasdfasdfdsafwerqwersfasfasdvasdfsdfffs1', 'platform'=>'1', 'ts' => ceil(microtime(true) * 1000)];
// echo $sign = Aes::createSign($data);
// exit;
// $data = ['appid'=> 'appid', 'verison'=>'023200', 'reqid'=>'111', 'platform'=>'1'];
// $data['sign'] = 'l4lBCE3B_v-ODFeuoxFksl0IUY9ehBnjN_FtU3ESdrn_bMPDsEIxA8IUw0pDJ_kX06P6OOw23in46acBucgceSBE2Vx3Ew52w3FfmRn8IhE';
// $sign = Aes::checkSign($data);
// var_dump($sign);
// exit;
// $obj = new App\Models\User();
// print_r($obj->getUserData());//Array ( [name] => zhangsan [age] => 18 )
// exit;
// $http = $this->getRequest()->getRequest();
// var_dump($http);
// var_dump(file_get_contents("php://input"));
// var_dump($this->requestAll());yaf
// exit;
$res
=
[
"userid"
=>
'user'
,
"code"
=>
0
];
// print_r($this->failed(-1,'reason'));
$this
->
success
(
$res
);
}
/**
* get uri
* @return string
*/
public
function
getBaseUri
()
{
$env
=
\Yaf\Application
::
app
()
->
environ
()
??
"dev1"
;
if
(
$env
==
'product'
)
{
$this
->
baseUri
=
'http://a4.go2yd.com/Website/session'
;
}
elseif
(
$env
==
'dev'
)
{
$this
->
baseUri
=
'http://127.0.0.1/Website/session'
;
}
else
{
$this
->
baseUri
=
'http://a4-1.go2yd.com/Website/session'
;
}
return
$this
->
baseUri
;
}
}
\ No newline at end of file
application/modules/Test/controllers/Test.php
deleted
100644 → 0
View file @
9b9c9981
<?php
use
App\Base\Base
;
class
TestController
extends
Base
{
public
function
indexAction
()
{
$this
->
success
();
}
}
application/modules/Test/controllers/Ttt.php
deleted
100644 → 0
View file @
9b9c9981
<?php
use
App\Base\Base
;
use
Helpers\Aes
;
use
Api\PhpUtils\Http\Request
;
use
Api\PhpUtils\Redis\RedisUtil
;
use
App\Models\demo\mongo\Test
;
use
Api\PhpUtils\Common\Rsa
;
use
Api\PhpServices\Session\SessionManager
;
use
Helpers\DebugLog
;
use
Api\PhpUtils\Kafka\KafkaUtil
;
use
Api\PhpUtils\Cache\ApcuUtil
;
use
Api\PhpUtils\Cache\CacheUtil
;
use
Api\PhpServices\Doc\DocDynamic
;
use
App\Models\demo\mysql\TestMysql
;
class
TttController
extends
Base
{
/**
* @var Api\PhpUtils\Cache\CacheUtil;
*/
protected
$cache
;
public
function
mysqlAction
()
{
// $ret = TestMysql::getRecord(['life_account_id' => 8281925009833985]);
// $ret = TestMysql::getRecords(['life_account_id' => 8281925009833985]);
// $ret = TestMysql::duplicate([['id' => 4,'name' => 'test3'], ['id' => 5,'name' => 'test4']], ['name' => Api\PhpUtils\Mysql\Medoo::raw('VALUES(name)')]);
// $ret = TestMysql::selectForUpdate('*', ['id' => 5], ['max_execution_time' => 1]);
$ret
=
TestMysql
::
count
(
'*'
,
[
'id[>]'
=>
2
]);
var_dump
(
$ret
);
}
public
function
kafkaAction
()
{
$topicName
=
'topicA'
;
$setConfDrMsgCb
=
function
(
$kafka
,
\RdKafka\Message
$message
)
{
echo
'打印消息:'
.
"
\n
"
;
var_export
(
$message
);
echo
"
\n
"
;
if
(
$message
->
err
){
//@todo 生产失败的逻辑处理
}
else
{
//@todo 生产成功的逻辑处理
}
};
$setErrorCbCallback
=
function
(
$kafka
,
$err
,
$reason
)
{
echo
sprintf
(
"setErrorCb (error_ori:%s)(error: %s) (reason: %s)"
,
$err
,
rd_kafka_err2str
(
$err
),
$reason
);
};
// $kafka = KafkaUtil::getInstance('test', ['context' => ['contextArr']]);
// $ret = $kafka->produce('eee');
$brokers
=
'127.0.0.1:9092'
;
$kafka
=
KafkaUtil
::
getInstance
();
$ret
=
$kafka
->
setBrokers
(
$brokers
)
->
setTopicName
(
'topicA'
)
->
produce
(
'ccc'
);
var_dump
(
$ret
);
var_dump
(
$kafka
);
exit
;
//设置brokers-支持数组或者字符串
$kafka
->
setBrokers
(
$brokers
)
//设置topic
->
setTopicName
(
$topicName
)
//setConfDrMsgCb--设置生产消息失败与成功的回调,默认初始化时会调用该事件,如果自定义后就会覆盖底层的事件
->
setConfDrMsgCb
(
$setConfDrMsgCb
)
//setConfErrorCb--设置错误回调,如若不设置默认会走该逻辑进行:\RdKafkaSdk\Core\Conf::defaultInit
->
setConfErrorCb
(
$setErrorCbCallback
)
//支持连贯用法生产多条数据并且是不同的topic
->
run
(
'message111'
,
$topicName
);
/**
object(Api\PhpUtils\Kafka\KafkaUtil)#17 (12) {
["serverName":"Api\PhpUtils\Kafka\KafkaUtil":private]=>
string(0) ""
["producer":"Api\PhpUtils\Kafka\KafkaUtil":private]=>
object(RdKafka\Producer)#22 (2) {
["error_cb":"RdKafka":private]=>
NULL
["dr_cb":"RdKafka":private]=>
NULL
}
["conf":"Api\PhpUtils\Kafka\KafkaUtil":private]=>
object(RdKafka\Conf)#18 (0) {
}
["confSet":"Api\PhpUtils\Kafka\KafkaUtil":private]=>
array(8) {
["socket.timeout.ms"]=>
int(50)
["socket.blocking.max.ms"]=>
int(50)
["topic.metadata.refresh.sparse"]=>
bool(true)
["topic.metadata.refresh.interval.ms"]=>
int(600)
["socket.nagle.disable"]=>
bool(true)
["message.timeout.ms"]=>
int(50)
["log_level"]=>
int(4)
["internal.termination.signal"]=>
int(23)
}
["confFunction":"Api\PhpUtils\Kafka\KafkaUtil":private]=>
array(2) {
["setDrMsgCb"]=>
object(Closure)#20 (3) {
["static"]=>
array(1) {
["context"]=>
array(0) {
}
}
["this"]=>
*RECURSION*
["parameter"]=>
array(2) {
["$kafka"]=>
string(10) "<required>"
["$message"]=>
string(10) "<required>"
}
}
["setErrorCb"]=>
object(Closure)#21 (2) {
["this"]=>
*RECURSION*
["parameter"]=>
array(3) {
["$kafka"]=>
string(10) "<required>"
["$err"]=>
string(10) "<required>"
["$reason"]=>
string(10) "<required>"
}
}
}
["topicConf":"Api\PhpUtils\Kafka\KafkaUtil":private]=>
object(RdKafka\TopicConf)#19 (0) {
}
["topicConfSet":"Api\PhpUtils\Kafka\KafkaUtil":private]=>
array(1) {
["request.required.acks"]=>
int(1)
}
["topicConfFunction":"Api\PhpUtils\Kafka\KafkaUtil":private]=>
array(0) {
}
["brokers":"Api\PhpUtils\Kafka\KafkaUtil":private]=>
string(14) "127.0.0.1:9092"
["topicName":"Api\PhpUtils\Kafka\KafkaUtil":private]=>
string(6) "topicA"
["context":"Api\PhpUtils\Kafka\KafkaUtil":private]=>
array(0) {
}
["config":"Api\PhpUtils\Kafka\KafkaUtil":private]=>
array(3) {
["viewlog"]=>
array(2) {
["topic"]=>
string(16) "dw_metro_pb_view"
["broker_list"]=>
array(15) {
[0]=>
string(32) "c1-e14-120-24-23.yidian.com:9092"
[1]=>
string(32) "c1-e14-120-24-24.yidian.com:9092"
[2]=>
string(32) "c1-e14-120-24-25.yidian.com:9092"
[3]=>
string(32) "c1-e14-120-24-26.yidian.com:9092"
[4]=>
string(32) "c1-e14-120-24-27.yidian.com:9092"
[5]=>
string(31) "c1-e15-120-25-6.yidian.com:9092"
[6]=>
string(31) "c1-e15-120-25-7.yidian.com:9092"
[7]=>
string(31) "c1-e15-120-25-8.yidian.com:9092"
[8]=>
string(31) "c1-e15-120-25-9.yidian.com:9092"
[9]=>
string(32) "c1-e16-120-25-10.yidian.com:9092"
[10]=>
string(32) "c1-e16-120-25-17.yidian.com:9092"
[11]=>
string(32) "c1-e16-120-25-18.yidian.com:9092"
[12]=>
string(32) "c1-e17-120-25-19.yidian.com:9092"
[13]=>
string(32) "c1-e17-120-25-20.yidian.com:9092"
[14]=>
string(32) "c1-e17-120-25-21.yidian.com:9092"
}
}
["subscribe"]=>
array(2) {
["topic"]=>
string(15) "dw_metro_pb_api"
["broker_list"]=>
array(15) {
[0]=>
string(32) "c1-e14-120-24-23.yidian.com:9092"
[1]=>
string(32) "c1-e14-120-24-24.yidian.com:9092"
[2]=>
string(32) "c1-e14-120-24-25.yidian.com:9092"
[3]=>
string(32) "c1-e14-120-24-26.yidian.com:9092"
[4]=>
string(32) "c1-e14-120-24-27.yidian.com:9092"
[5]=>
string(31) "c1-e15-120-25-6.yidian.com:9092"
[6]=>
string(31) "c1-e15-120-25-7.yidian.com:9092"
[7]=>
string(31) "c1-e15-120-25-8.yidian.com:9092"
[8]=>
string(31) "c1-e15-120-25-9.yidian.com:9092"
[9]=>
string(32) "c1-e16-120-25-10.yidian.com:9092"
[10]=>
string(32) "c1-e16-120-25-17.yidian.com:9092"
[11]=>
string(32) "c1-e16-120-25-18.yidian.com:9092"
[12]=>
string(32) "c1-e17-120-25-19.yidian.com:9092"
[13]=>
string(32) "c1-e17-120-25-20.yidian.com:9092"
[14]=>
string(32) "c1-e17-120-25-21.yidian.com:9092"
}
}
["test"]=>
array(2) {
["topic"]=>
string(6) "topicA"
["broker_list"]=>
array(1) {
[0]=>
string(14) "localhost:9092"
}
}
}
}
*/
}
public
function
docAction
()
{
$obj
=
new
DocDynamic
(
true
);
$docs
=
array
(
'06No4hkp'
=>
array
(
'like'
=>
1
,
'down'
=>
2
),
'06No4hk1'
=>
array
(
'comment_count'
=>
3
,
'up'
=>
4
,
'comment_like'
=>
'7'
));
// $set = $obj->incrCommentCount('06No4hkp');
$set
=
$obj
->
setThumbsdown
(
'06No4hkp'
,
1
);
var_dump
(
$set
);
// $ret = $obj->get('08yidV11');
$ret
=
$obj
->
get
(
'06No4hkp'
);
// $ret = $obj->get('news_b428c553fcb900ba3624385a818f1368');
// $ret = $obj->gets(['news_b428c553fcb900ba3624385a818f1368']);
// var_dump($obj);
var_dump
(
$ret
);
exit
;
}
public
function
apcuAction
()
{
// $prefix_key = ApcuUtil::add_prefix('prefix', 'key1');
// var_dump($prefix_key);
// $ret = ApcuUtil::apcu_store_one('prefix', 'key1', 'value1', 10);
// $set = ApcuUtil::apcu_add_one('prefix', 'key1', 'value1', 3);
// $set = ApcuUtil::apcu_add_multi('prefix', ['key1' => 'value2', 'key2' => 'value3'], null, 10);
$set
=
ApcuUtil
::
apcu_store_multi
(
'prefix'
,
[
'key1'
=>
'value1'
,
'key2'
=>
'value2'
],
null
,
10
);
// $del = ApcuUtil::apcu_delete('prefix', 'key2');
$get
=
ApcuUtil
::
apcu_fetch
(
'prefix'
,
'key3'
,
$success
);
// $get = ApcuUtil::apcu_fetch('prefix', ['key1', 'key2'], $success);
var_dump
(
$set
);
// var_dump($del);
var_dump
(
$get
);
// var_dump($success);
exit
;
}
public
function
redisAction
()
{
// $arr = ['serverRegion'=> 'sh', 'serializer' => 'none', 'master'=> false];
// var_dump('abc'.serialize($arr));
// $str = 'abc'. json_encode($arr);
// var_dump($str);
// exit;
$redis
=
RedisUtil
::
getInstance
(
'api'
,
[
'serverRegion'
=>
'sh'
,
'serializer'
=>
'none'
,
'master'
=>
true
]);
$redis
=
RedisUtil
::
getInstance
(
'api'
,
[
'serverRegion'
=>
'sh'
,
'serializer'
=>
'none'
,
'master'
=>
true
]);
// var_dump($redis);
$get
=
$redis
->
hget
(
'07IqF'
,
'Vcc'
);
var_dump
(
$get
);
exit
;
// echo 123456;exit;
// codis
$redis
=
RedisUtil
::
getInstance
(
'redis'
,
[
'serverRegion'
=>
'wj'
,
'serializer'
=>
'none'
,
'master'
=>
true
]);
var_dump
(
$redis
);
exit
;
$set
=
$redis
->
setex
(
'ebbddse'
,
20
,
'value123'
);
// $redis = RedisUtil::getInstance('redis', ['serverRegion'=> 'wj', 'serializer' => 'igbinary', 'master'=> false]);
// $set = $redis->setex('ebbddse',200, ['value111', 'value222']);
// $set = $redis->del('ebbddse');
var_dump
(
$set
);
$get
=
$redis
->
get
(
'ebbddse'
);
// $get = $redis->get('myAppName:ebbddse');
var_dump
(
$get
);
// Sentinel
// $redis = RedisUtil::getInstance('sentinel', 'region2', true);
// $ret = $redis->set('bbdadfsdd', 'sentinel');
// $ret = $redis->get('bbdadfsdd');
// $ret = $redis->get('myAppName:ebbddse');
// var_dump($ret);
// Redis
// $redis = RedisUtil::getInstance('redis');
// $ret = $redis->setex('sdddadfeasdfsdaf', 5, "a".'["redis1", "redis2"]');
// $ret = $redis->set('sdddadfeasdfsdaf', 'redis');
// $ret = $redis->get('sdddadfeasdfsdaf');
// $ret = $redis->del('sdddadfeasdfsdaf');
// $ret = $redis->get('myAppName:sdddadfeasdfsdaf');
// var_dump($ret);
// print_r($redis);
// var_dump($redis);
exit
;
}
public
function
cacheAction
()
{
$this
->
cache
=
CacheUtil
::
getInstance
(
'redis'
,
[
'serializer'
=>
'none'
]);
$this
->
cache
->
get
(
'07IqF'
,
'Vcc'
);
$cache
=
CacheUtil
::
getInstance
(
'redis'
,
[
'serializer'
=>
'none'
]);
// var_dump($cache);exit;
// $set = $cache->setex('ebbddse',200, 'value123');
// $set = $cache->setex('ebbddse',20, ['value111', 'value222']);
// $set = $cache->del('ebbddse');
$set
=
$cache
->
sets
([
'k1'
=>
'v1'
,
'k2'
=>
'v2'
],
100
,
'p'
);
var_dump
(
$set
);
$get
=
$cache
->
get
(
'ebbddse'
);
$get
=
$cache
->
gets
([
'k1'
,
'k2'
,
'keykkk'
],
'p'
);
// $get = $cache->gets(['ebbddse','key1', 'keykkk']);
// $get = $cache->get('myAppName:ebbddse');
var_dump
(
$get
);
exit
;
}
public
function
debuglogAction
()
{
$sessionData
=
[
'id'
=>
123
,
'name'
=>
'test'
];
print_r
(
$sessionData
);
DebugLog
::
time
(
'1.php, start page'
);
sleep
(
1
);
DebugLog
::
time
(
'2.php, start page'
);
sleep
(
1
);
DebugLog
::
time
(
'3.php, start page'
);
DebugLog
::
log
(
'log1'
,
'log1_info'
);
exit
;
}
public
function
IndexAction
()
{
$ret
=
SessionManager
::
start
(
false
,
'yidian'
);
// print_r($_SERVER);
// print_r($_COOKIE);
var_dump
(
$ret
);
print_r
(
$_SESSION
);
$url
=
$this
->
getBaseUri
()
.
'/get-many-session'
;
$query
=
[
'sessionid'
=>
[
'YPZQISU1Tjxg3wJLFWJmVA'
,
'E4vo3R5EfaPS-pnyDzia3Q'
]];
$result
=
(
new
Request
())
->
get
(
$url
,
[
'query'
=>
$query
,
'timeout'
=>
1
]);
print_r
(
$result
);
exit
;
// $validSessionIds[] = 'a';
// $validSessionIds[] = 'b';
// $validSessionIds[] = 'c';
// echo $validSessionIds[rand(0, count($validSessionIds) - 1)];
// exit;
// todo 请求接口写redis
$url
=
$this
->
getBaseUri
()
.
'/set-session'
;
$sessionData
=
[
'id'
=>
123
,
'name'
=>
'test'
];
$params
=
[
'sessionid'
=>
'jssionidtest'
,
'data'
=>
(
$sessionData
),
'expire'
=>
600
,
'key'
=>
'c071f6e5923a648a5ef88f32b6f738e1'
];
$result
=
(
new
Request
())
->
post
(
$url
,
[
'form_params'
=>
$params
,
'timeout'
=>
1
]);
print_r
(
$result
);
// exit;
$url
=
$this
->
getBaseUri
()
.
'/get-many-session'
;
$query
=
[
'sessionid'
=>
[
'jssionidtest2'
,
'jssionidtest1'
]];
$result
=
(
new
Request
())
->
get
(
$url
,
[
'query'
=>
$query
,
'timeout'
=>
1
]);
print_r
(
$result
);
exit
;
$url
=
$this
->
getBaseUri
()
.
'/delete-session'
;
$query
=
[
'sessionid'
=>
[
'jssionidtest1'
,
'jssionidtest'
],
'key'
=>
'c071f6e5923a648a5ef88f32b6f738e1'
];
$result
=
(
new
Request
())
->
get
(
$url
,
[
'query'
=>
$query
,
'timeout'
=>
1
]);
print_r
(
$result
);
$url
=
$this
->
getBaseUri
()
.
'/get-session'
;
$query
=
[
'sessionid'
=>
'jssionidtest'
];
$result
=
(
new
Request
())
->
get
(
$url
,
[
'query'
=>
$query
,
'timeout'
=>
1
]);
print_r
(
$result
);
exit
;
if
(
isset
(
$result
[
'success'
][
'code'
])
&&
$result
[
'success'
][
'code'
]
==
0
)
{
return
true
;
}
return
false
;
// // todo 请求接口读redis
// echo $url = $this->getBaseUri() . '/get-session1';
// $query = ['sessionid' => 'jssionidtest'];
// $result = (new Request())->get($url, ['query' => $query, 'timeout' => 1]);
// if (isset($result['success']['code']) && $result['success']['code'] == 0 && isset($result['success']['result'])) {
// $data = $result['success']['result'];
// print_r($data);
// }else {
// print_r($result);
// }
// exit;
// $r = \Api\PhpUtils\Common\IP::find('114.114.114.114');
// print_r($r);
// exit;
// $_SESSION['abc'] = 'ttt';
// echo $_SESSION['abc'];
// echo $_SESSION['abc'];
// echo $_SESSION['abc'];
// echo $_SESSION['abc'];
// exit;
// $abc = '123'. "\x7F" . 456;
// var_dump($abc);exit;//string(7) "123456" 不可见字任作为分隔符
// $a = base64_encode('6543211111dasfsdfasdf1111asdfasdfs1111');
// var_dump($a);
// var_dump(sha1($a));
// var_dump(substr(sha1($a), -2));
// $a = $a . substr(sha1($a), -2);
// var_dump($a);
// var_dump(substr($a, 0, -2));
// $a = substr($a, 0, -2);
// var_dump($a);
// var_dump(sha1($a));
// var_dump(substr(sha1($a), -2));
// exit;
// var_dump(strlen($a));
// var_dump($a);exit;
// var_dump($this->response);
// var_dump(Yaf\Dispatcher::getInstance()->getResponse());
// exit;
// $data = ['appid'=> 'appid', 'verison'=>'023200', 'reqid'=>'11adddddddfasdfasdfasdfasdfdsafwerqwersfasfasdvasdfsdfffs1', 'platform'=>'1', 'ts' => ceil(microtime(true) * 1000)];
// echo $sign = Aes::createSign($data);
// exit;
// $data = ['appid'=> 'appid', 'verison'=>'023200', 'reqid'=>'111', 'platform'=>'1'];
// $data['sign'] = 'l4lBCE3B_v-ODFeuoxFksl0IUY9ehBnjN_FtU3ESdrn_bMPDsEIxA8IUw0pDJ_kX06P6OOw23in46acBucgceSBE2Vx3Ew52w3FfmRn8IhE';
// $sign = Aes::checkSign($data);
// var_dump($sign);
// exit;
// $obj = new App\Models\User();
// print_r($obj->getUserData());//Array ( [name] => zhangsan [age] => 18 )
// exit;
// $http = $this->getRequest()->getRequest();
// var_dump($http);
// var_dump(file_get_contents("php://input"));
// var_dump($this->requestAll());yaf
// exit;
$res
=
[
"userid"
=>
'user'
,
"code"
=>
0
];
// print_r($this->failed(-1,'reason'));
$this
->
success
(
$res
);
}
public
function
MongoAction
()
{
$ret
=
[];
$obj
=
Test
::
getInstance
();
$cursor
=
$obj
->
findOne
([
"_id"
=>
8
],
[
'projection'
=>
[
'name'
=>
1
,
'_id'
=>
0
]]);
print_r
(
$cursor
);
$ret
=
$obj
->
insertOne
([
"_id"
=>
8
,
"mobile"
=>
"17701340008"
]);
$ret
=
$obj
->
insertMany
([[
"_id"
=>
9
,
"mobile"
=>
"17701340008"
],
[
"_id"
=>
8
,
"mobile"
=>
"17701340009"
]]);
$ret
=
$obj
->
insertOne
([
"_id"
=>
8
,
"mobile"
=>
"17701340008"
]);
$ret
=
$obj
->
updateOne
([
"_id"
=>
8
],
[
'$set'
=>
[
"mobile"
=>
"177013400081"
]]);
$ret
=
$obj
->
updateMany
([
"_id"
=>
8
],
[
'$set'
=>
[
"mobile"
=>
"177013400081"
]]);
$ret
=
$obj
->
findOneAndUpdate
([
"_id"
=>
8
],
[
'$set'
=>
[
"mobile"
=>
"177013400081"
]]);
$ret
=
$obj
->
findOneAndDelete
([
"_id"
=>
9
]);
$ret
=
$obj
->
deleteMany
([
"_id"
=>
9
]);
echo
$ret
->
getDeletedCount
();
echo
$ret
->
getInsertedCount
();
echo
$ret
->
getInsertedId
();
print_r
(
$ret
->
getInsertedIds
());
echo
$ret
->
getMatchedCount
();
echo
$ret
->
getModifiedCount
();
echo
$ret
->
getUpsertedCount
();
echo
$ret
->
getUpsertedId
();
$cursor
=
$obj
->
find
();
foreach
(
$cursor
as
$k
=>
$document
)
{
// var_dump($document);exit;
$ret
[
$k
]
=
$document
;
}
$ret
=
$obj
->
countDocuments
();
print_r
(
$ret
);
exit
;
}
public
function
HttpAction
()
{
$http
=
$this
->
getRequest
()
->
getRequest
();
var_dump
(
$http
);
var_dump
(
file_get_contents
(
"php://input"
));
var_dump
(
$this
->
requestAll
());
exit
;
}
public
function
IpAction
()
{
$r
=
\Api\PhpUtils\Common\IP
::
find
(
'123.100.1.111'
);
print_r
(
$r
);
// exit;
$r
=
\Api\PhpUtils\Common\IP
::
find
(
'121.103.40.115'
);
print_r
(
$r
);
$r
=
\Api\PhpUtils\Common\IP
::
find
(
'122.103.40.115'
);
print_r
(
$r
);
$r
=
\Api\PhpUtils\Common\IP
::
find
(
'123.103.8.115'
);
print_r
(
$r
);
exit
;
}
public
function
RsaAction
()
{
$r
=
\Api\PhpUtils\Common\IP
::
find
(
'114.114.114.114'
);
print_r
(
$r
);
exit
;
}
public
function
AesAction
()
{
$data
[
'sign'
]
=
"Fcz71y9zBf4cYEHcg52ZzvfY3qIrv_6ydx08WTOQfg0xj-HepuW9v277GV72zFi-uJXg5YVgVbdxbi0QEUpL5g"
;
$sign
=
Aes
::
checkSign
(
$data
);
var_dump
(
$sign
);
exit
;
$data
=
[
'appid'
=>
'appid'
,
'verison'
=>
'023200'
,
'reqid'
=>
'11adddddddfasdfasdfasdfasdfdsafwerqwersfasfasdvasdfsdfffs1'
,
'platform'
=>
'1'
,
'ts'
=>
ceil
(
microtime
(
true
)
*
1000
)];
echo
$sign
=
Aes
::
createSign
(
$data
);
exit
;
$data
=
[
'appid'
=>
'appid'
,
'verison'
=>
'023200'
,
'reqid'
=>
'111'
,
'platform'
=>
'1'
];
$data
[
'sign'
]
=
'l4lBCE3B_v-ODFeuoxFksl0IUY9ehBnjN_FtU3ESdrn_bMPDsEIxA8IUw0pDJ_kX06P6OOw23in46acBucgceSBE2Vx3Ew52w3FfmRn8IhE'
;
$sign
=
Aes
::
checkSign
(
$data
);
var_dump
(
$sign
);
exit
;
}
/**
* get url
* @return string
*/
public
function
getBaseUri
()
{
$env
=
\Yaf\Application
::
app
()
->
environ
()
??
"dev"
;
if
(
$env
==
'product'
)
{
$this
->
baseUri
=
'http://a4.go2yd.com/Website/session'
;
}
elseif
(
$env
==
'dev'
)
{
$this
->
baseUri
=
'http://127.0.0.1/Website/session'
;
}
else
{
$this
->
baseUri
=
'http://a4-1.go2yd.com/Website/session'
;
}
return
$this
->
baseUri
;
}
}
\ No newline at end of file
application/plugins/Hook.php
View file @
a963c378
...
@@ -48,7 +48,7 @@ class Hook extends \Yaf\Plugin_Abstract {
...
@@ -48,7 +48,7 @@ class Hook extends \Yaf\Plugin_Abstract {
if
(
!
$_POST
&&
$request
->
isPost
()
if
(
!
$_POST
&&
$request
->
isPost
()
&&
$request
->
getServer
(
'CONTENT_TYPE'
)
==
'application/json'
)
{
&&
$request
->
getServer
(
'CONTENT_TYPE'
)
==
'application/json'
)
{
$jsonPost
=
file_get_contents
(
"php://input"
);
$jsonPost
=
file_get_contents
(
"php://input"
);
if
(
$jsonPost
)
{
if
(
false
&&
$jsonPost
)
{
$_POST
=
json_decode
(
$jsonPost
,
true
);
$_POST
=
json_decode
(
$jsonPost
,
true
);
$ini
=
ini_get
(
'request_order'
);
$ini
=
ini_get
(
'request_order'
);
if
(
$ini
)
{
if
(
$ini
)
{
...
...
application/services/demo/MongoService.php
deleted
100644 → 0
View file @
9b9c9981
<?php
namespace
App\Services\demo
;
use
App\Models\demo\mongo\User
;
class
MongoService
{
public
function
addUser
()
{
$user
=
User
::
getInstance
();
$data
=
[
'_id'
=>
4
,
'name'
=>
'dw04'
,
'mobile'
=>
'17701340004'
];
return
$user
->
add
(
$data
);
}
public
function
addManyUser
()
{
$user
=
User
::
getInstance
();
$data
=
[
[
'_id'
=>
5
,
'name'
=>
'dw05'
,
'mobile'
=>
'17701340005'
],
[
'_id'
=>
6
,
'name'
=>
'dw06'
,
'mobile'
=>
'17701340006'
]
];
return
$user
->
addMany
(
$data
);
}
public
function
deleteUser
()
{
$user
=
User
::
getInstance
();
$params
=
[
'name'
=>
'dw01'
];
return
$user
->
delete
(
$params
);
}
public
function
updateUser
()
{
$user
=
User
::
getInstance
();
$params
=
[
'name'
=>
'dw02'
];
$data
=
[
'mobile'
=>
'17701340002'
];
return
$user
->
update
(
$params
,
$data
);
}
public
function
getUser
()
{
$user
=
User
::
getInstance
();
$params
=
[
'name'
=>
'dw02'
];
return
$user
->
get
(
$params
);
}
public
function
getManyUser
()
{
$user
=
User
::
getInstance
();
$params
=
[
'name'
=>
'dw02'
];
return
$user
->
getMany
(
$params
);
}
}
application/services/demo/MysqlService.php
deleted
100644 → 0
View file @
9b9c9981
<?php
namespace
App\Services\demo
;
use
App\Models\demo\mysql\User
;
class
MysqlService
{
public
function
addUser
()
{
$user
=
User
::
getWriteInstance
();
$data
=
[
'name'
=>
'dw07'
,
'mobile'
=>
'17701340007'
];
return
$user
->
add
(
$data
);
}
public
function
addManyUser
()
{
$user
=
User
::
getWriteInstance
();
$data
=
[
[
'name'
=>
'dw08'
,
'mobile'
=>
'17701340008'
],
[
'name'
=>
'dw09'
,
'mobile'
=>
'17701340009'
]
];
return
$user
->
addMany
(
$data
);
}
public
function
deleteUser
()
{
$user
=
User
::
getWriteInstance
();
$params
=
[
'name'
=>
'dw08'
];
return
$user
->
delete
(
$params
);
}
public
function
updateUser
()
{
$user
=
User
::
getWriteInstance
();
$params
=
[
'name'
=>
'dw02'
];
$data
=
[
'mobile'
=>
'15030690002'
];
return
$user
->
update
(
$params
,
$data
);
}
public
function
getUser
()
{
$user
=
User
::
getInstance
();
$params
=
[
'name'
=>
'dw02'
];
$column
=
[
'name'
,
'mobile'
];
return
$user
->
get
(
$params
,
$column
);
}
public
function
getManyUser
()
{
$user
=
User
::
getInstance
();
$params
=
[
'id[>]'
=>
3
];
$column
=
[
'name'
,
'mobile'
];
return
$user
->
getMany
(
$params
,
$column
);
}
public
function
countUser
()
{
$user
=
User
::
getInstance
();
$params
=
[
'master_name'
=>
'dw04'
];
$column
=
'id'
;
return
$user
->
count
(
$params
,
$column
);
}
public
function
maxUser
()
{
$user
=
User
::
getInstance
();
$params
=
[
'id[>]'
=>
1
];
$column
=
'id'
;
return
$user
->
max
(
$params
,
$column
);
}
public
function
minUser
()
{
$user
=
User
::
getInstance
();
$params
=
[
'id[>]'
=>
1
];
$column
=
'id'
;
return
$user
->
min
(
$params
,
$column
);
}
public
function
avgUser
()
{
$user
=
User
::
getInstance
();
$params
=
[
'id[>]'
=>
1
];
$column
=
'id'
;
return
$user
->
avg
(
$params
,
$column
);
}
public
function
sumUser
()
{
$user
=
User
::
getInstance
();
$params
=
[
'id[>]'
=>
1
];
$column
=
'id'
;
return
$user
->
sum
(
$params
,
$column
);
}
}
application/services/order/OrderService.php
View file @
a963c378
...
@@ -3,83 +3,42 @@
...
@@ -3,83 +3,42 @@
namespace
App\Services\order
;
namespace
App\Services\order
;
use
App\Exception\custom\CodeSpecialException
;
use
Helpers\Sdk
;
class
OrderService
class
OrderService
{
{
public
static
function
get_idgen_id
(
$number
,
$count
=
1
){
$res
=
Idgen
::
get
(
appConfig
(
'idgen.partner'
),
appConfig
(
'idgen.key'
),
[],
[[
"type"
=>
"merchant_shop_id"
,
'number'
=>
$number
,
"count"
=>
$count
]]);
$id
=
$res
[
'id_datetime'
][
'merchant_shop_id'
]
??
[];
return
$id
;
}
/**
/**
* @param $orderId
* @param $orderId
* @param $userId
* @param $userId
* 调用内部服务获取用户订单、子单、分润信息
* 调用内部服务获取用户订单、子单、分润信息
*/
*/
public
static
function
getOrderData
(
$order_id
,
$user_id
)
{
public
static
function
getOrderData
(
$order_id
,
$user_id
)
{
return
self
::
getDemoData
(
$order_id
,
$user_id
);
}
public
static
function
getOrderItemData
(
$order_item_id
,
$user_id
)
{
return
[
'order_item_id'
=>
$order_item_id
,
'order_id'
=>
$order_item_id
.
'11'
,
'user_id'
=>
$user_id
,
'goods_spu_id'
=>
$order_item_id
.
'22'
,
'goods_sku_id'
=>
$order_item_id
.
'33'
,
'marketing_type'
=>
1
,
];
}
public
static
function
getDemoData
(
$orderId
,
$userId
)
{
$url
=
config
(
'interface'
,
'order.order.pay_order'
);
$order
=
[
if
(
!
$url
)
{
'order_id'
=>
$orderId
,
throw
new
CodeSpecialException
(
"failed"
);
'user_id'
=>
$userId
,
}
'life_account_id'
=>
2312
,
//'生活号id',
'shop_id'
=>
2312
,
//'店铺shop_id',
'order_type'
=>
1
,
//'1虚拟商品,2实体商品',
'payment'
=>
1
,
//'1虚拟商品,2实体商品',
'order_status'
=>
100
,
//'100 待付款',
];
$order_items
=
[
$params
=
[
'user_id'
=>
$user_id
,
'order_id'
=>
$order_id
];
[
return
Sdk
::
call
(
$url
,
$params
);
'order_item_id'
=>
$orderId
.
rand
(
100
,
999
),
}
'order_id'
=>
$orderId
,
'user_id'
=>
$userId
,
'goods_spu_id'
=>
$orderId
.
rand
(
100
,
999
),
'goods_sku_id'
=>
$orderId
.
rand
(
100
,
999
),
'marketing_type'
=>
1
,
],
[
'order_item_id'
=>
$orderId
.
rand
(
100
,
999
),
'order_id'
=>
$orderId
,
'user_id'
=>
$userId
,
'goods_spu_id'
=>
$orderId
.
rand
(
100
,
999
),
'goods_sku_id'
=>
$orderId
.
rand
(
100
,
999
),
'marketing_type'
=>
1
,
]
];
foreach
(
$order_items
as
$r
)
{
/**
$order_distribution
[]
=
[
* @param $order_item_id
'commission_mode'
=>
1
,
* @param $user_id
'distributor_user_id'
=>
122234
,
* @return bool|mixed
'distributor_commission_value'
=>
60
,
* @throws CodeSpecialException
'parent_user_id'
=>
122234
.
rand
(
111
,
999
),
* 获取订单子单信息
'parent_commission_value'
=>
60
,
*/
];
public
static
function
getOrderItemData
(
$order_item_id
,
$user_id
)
{
//merchant.account.get_role_list
$url
=
config
(
'interface'
,
'order.order.pay_order_item'
);
if
(
!
$url
)
{
throw
new
CodeSpecialException
(
"failed"
);
}
}
return
[
$params
=
[
'user_id'
=>
$user_id
,
'order_item_id'
=>
$order_item_id
];
'order'
=>
$order
,
return
Sdk
::
call
(
$url
,
$params
);
'order_items'
=>
$order_items
,
'order_distribution'
=>
$order_distribution
,
];
}
}
}
}
\ No newline at end of file
application/services/pay/PayService.php
View file @
a963c378
...
@@ -6,10 +6,13 @@ namespace App\Services\pay;
...
@@ -6,10 +6,13 @@ namespace App\Services\pay;
use
Api\PhpServices\Idgen\Idgen
;
use
Api\PhpServices\Idgen\Idgen
;
use
App\Models\Dictionary
;
use
App\Models\Dictionary
;
use
App\Models\order\mysql\PayOrder
;
use
App\Models\order\mysql\PayOrder
;
use
App\Models\order\mysql\PayOrderItem
;
use
App\Models\order\mysql\PayOrderClearing
;
use
App\Models\order\mysql\PayOrderClearing
;
use
App\Models\order\mysql\PayOrderClearingItem
;
use
App\Models\order\mysql\PayOrderClearingItem
;
use
App\Services\Order\OrderService
;
use
App\Services\Order\OrderService
;
use
App\Services\pingxx\PingxxService
;
use
App\Services\wallet\WalletService
;
use
Helpers\Strategy
;
use
Helpers\Strategy
;
use
Helpers\Logger
;
use
Helpers\Logger
;
...
@@ -25,6 +28,7 @@ class PayService
...
@@ -25,6 +28,7 @@ class PayService
private
$order_distribution
=
[];
private
$order_distribution
=
[];
private
$pay_order
=
[];
private
$pay_order
=
[];
private
$pay_order_items
=
[];
private
$clear_list
=
[];
private
$clear_list
=
[];
private
$clear_items_list
=
[];
private
$clear_items_list
=
[];
...
@@ -37,23 +41,8 @@ class PayService
...
@@ -37,23 +41,8 @@ class PayService
throw
new
PayException
([
'cus'
=>
1
]);
throw
new
PayException
([
'cus'
=>
1
]);
}
}
$order
=
$data
[
'order'
];
// 判断是否存在有效订单
// 判断是否存在有效订单
$pay_order
=
$this
->
exist_valid
(
$order_id
,
$data
[
'order'
]);
$this
->
make_order_clearing
(
$data
);
// 发送ping++ 创建支付订单
$this
->
send_pingxx
(
$pay_order
);
}
/**
* @param $order_id
* @param $user_id
* @throws PayException
* 判断是否有效订单,如果存在则调用三方判断订单状态
*/
private
function
exist_valid
(
$order_id
,
$order
)
{
$expire_time
=
time
()
+
30
*
60
;
$expire_time
=
time
()
+
30
*
60
;
$pay_order_id
=
$this
->
gen_pay_order_id
(
$order_id
);
$pay_order_id
=
$this
->
gen_pay_order_id
(
$order_id
);
$pay_order
=
[
$pay_order
=
[
...
@@ -62,7 +51,7 @@ class PayService
...
@@ -62,7 +51,7 @@ class PayService
'life_account_id'
=>
$order
[
'life_account_id'
],
'life_account_id'
=>
$order
[
'life_account_id'
],
'shop_id'
=>
$order
[
'shop_id'
],
'shop_id'
=>
$order
[
'shop_id'
],
'order_id'
=>
$order
[
'order_id'
],
'order_id'
=>
$order
[
'order_id'
],
'pay_order_status'
=>
Dictionary
::
O_PAY_STATUS_
INIT
,
'pay_order_status'
=>
Dictionary
::
O_PAY_STATUS_
UNPAY
,
'pay_amount'
=>
$order
[
'payment'
],
'pay_amount'
=>
$order
[
'payment'
],
'third_order_id'
=>
''
,
'third_order_id'
=>
''
,
'expire_time'
=>
$expire_time
,
'expire_time'
=>
$expire_time
,
...
@@ -72,24 +61,185 @@ class PayService
...
@@ -72,24 +61,185 @@ class PayService
'extra'
=>
json_encode
([]),
'extra'
=>
json_encode
([]),
];
];
//获取或创建支付订单
$order
=
PayOrder
::
get_valid_order
(
$order_id
,
$pay_order
);
$order
=
PayOrder
::
get_valid_order
(
$order_id
,
$pay_order
);
if
(
empty
(
$order
))
{
if
(
empty
(
$order
))
{
throw
new
PayException
([
'cus'
=>
2
]);
throw
new
PayException
([
'cus'
=>
0
]);
//$this->get_order_from_pingxx($order['third_order_id']);
}
}
//新创建直接返回
if
(
$order
[
'pay_order_status'
]
==
Dictionary
::
O_PAY_STATUS_PAYED
)
{
if
(
$order
[
'pay_order_id'
]
==
$pay_order_id
)
{
throw
new
PayException
([
'cus'
=>
3
]);
return
$order
;
}
}
//需要核对ping++ 支付状态
// 支持幂等,存在有效订单需要可以重复支付
if
(
!
empty
(
$order
[
'third_order_id'
]))
{
$ret
=
PingxxService
::
createOrder
(
$pay_order
);
$this
->
get_order_from_pingxx
(
$order
[
'third_order_id'
]);
if
(
$ret
[
"status"
]
==
'paid'
)
{
throw
new
PayException
([
'cus'
=>
3
]);
$edit
=
[
'pay_order_status'
=>
Dictionary
::
O_PAY_STATUS_PAYED
,
'third_order_id'
=>
$ret
[
'id'
],
//'pay_channel'=>$ret['charge_essentials']['channel'],
];
PayOrder
::
update
(
$edit
,
[
'pay_order_id'
=>
$order
[
'pay_order_id'
]]);
}
elseif
(
$ret
[
"status"
]
==
'created'
)
{
$edit
=
[
'pay_order_status'
=>
Dictionary
::
O_PAY_STATUS_WAIT
,
'third_order_id'
=>
$ret
[
'id'
],
];
PayOrder
::
update
(
$edit
,
[
'pay_order_id'
=>
$order
[
'pay_order_id'
]]);
}
elseif
(
$ret
[
"status"
]
==
'canceled'
)
{
$edit
=
[
'expire_time'
=>
date
(
'Y-m-d H:i:s'
),
];
PayOrder
::
update
(
$edit
,
[
'pay_order_id'
=>
$order
[
'pay_order_id'
]]);
}
else
{}
return
$ret
;
}
/**
* @throws PayException
* 回调订单支付
*/
public
function
call_back
(
$data
)
{
if
(
empty
(
$data
[
'data'
][
'object'
]))
{
Logger
::
error
(
'回调参数错误:'
,
$data
);
throw
new
PayException
([
'cus'
=>
5
]);
}
$object
=
$data
[
'data'
][
'object'
];
$ping_data
=
PingxxService
::
getOrder
(
$object
[
'id'
]);
if
(
$ping_data
[
'status'
]
!=
'paid'
)
{
throw
new
PayException
([
'cus'
=>
5
]);
}
//actual_amount 金额核对
// 修改状态,锁定业务
$pay_order_id
=
$ping_data
[
'merchant_order_no'
];
$this
->
lock_pay_order
(
$pay_order_id
);
//获取订单 + 子单 + 分销信息
$ret
=
OrderService
::
getOrderData
(
$this
->
pay_order
[
'order_id'
],
$this
->
pay_order
[
'user_id'
]);
if
(
empty
(
$ret
[
'order'
]))
{
throw
new
PayException
([
'cus'
=>
1
]);
}
// 生成支付清分单
$this
->
make_order_clearing
(
$ret
);
$this
->
make_order_clear
();
}
public
function
write_off
()
{
//锁定状态
}
/**
* @param $pay_order_id
* @throws PayException
* 锁定支付状 态
*/
private
function
lock_pay_order
(
$pay_order_id
)
{
try
{
PayOrder
::
beginTransaction
();
$pay_order
=
PayOrder
::
getMaster
(
'*'
,
[
'pay_order_id'
=>
$pay_order_id
]);
if
(
empty
(
$pay_order
))
{
throw
new
PayException
([
'cus'
=>
0
]);
}
$this
->
pay_order
=
$pay_order
;
// 如果已经支付,返回成功保持幂等。
if
(
$pay_order
[
'pay_order_status'
]
==
Dictionary
::
O_PAY_STATUS_PAYED
)
{
throw
new
RefundException
([
'cus'
=>
0
]);
}
$edit
=
[
'pay_order_status'
=>
Dictionary
::
O_PAY_STATUS_PAYED
,
'pingxx_callback_success_time'
=>
date
(
'Y-m-d H:i:s'
),
];
PayOrder
::
update
(
$edit
,
[
'pay_order_id'
=>
$pay_order_id
]);
PayOrder
::
commit
();
}
catch
(
Exception
$e
)
{
PayOrder
::
rollback
();
Logger
::
error
(
$e
->
getMessage
(),
$edit
);
throw
$e
;
}
}
/**
* @param $pay_order_id
* 处理清分
*/
private
function
make_order_clear
()
{
$this
->
wallet_list
=
[];
$data
=
OrderService
::
getOrderData
(
$this
->
pay_order
[
'order_id'
],
$this
->
pay_order
[
'user_id'
]);
//平台收入、团长、商户
foreach
(
$data
[
'order_item'
]
as
$item
)
{
if
(
$item
[
'marketing_type'
]
==
1
)
{
$this
->
make_order_item_clear
(
$item
);
}
}
if
(
$this
->
wallet_list
)
{
$ret
=
WalletService
::
send
(
$this
->
send_wallet
());
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
]);
}
}
/**
* @param $order_item
* 结算单个子单
*/
private
function
make_order_item_clear
(
$order_item
)
{
if
(
empty
(
$this
->
pay_order
))
{
throw
new
PayException
([
'cus'
=>
0
]);
}
}
return
$order
;
PayOrderItem
::
update
([
'notify_account_status'
=>
1
,
],
[
'order_item_id'
=>
$order_item
[
'order_item_id'
],
'notify_account_status'
=>
0
]);
$clearing_items
=
PayOrderClearingItem
::
select
(
'*'
,
[
'order_item_id'
=>
$order_item
[
'order_item_id'
],
'pay_order_id'
=>
$this
->
pay_order
[
'pay_order_id'
]]
);
foreach
(
$clearing_items
as
$row
)
{
$this
->
wallet_list
[]
=
[
'account_id'
=>
$row
[
'account_id'
],
'pay_amount'
=>
$row
[
'pay_amount'
],
'pay_type'
=>
$row
[
'pay_type'
],
'trade_id'
=>
$row
[
'pay_order_clearing_item_id'
],
];
}
}
/**
* @param $order_id
* @param $user_id
* @throws PayException
* 判断是否有效订单,如果存在则调用三方判断订单状态
*/
private
function
exist_valid
(
$order_id
,
$order
)
{
}
}
/**
/**
...
@@ -104,6 +254,17 @@ class PayService
...
@@ -104,6 +254,17 @@ class PayService
$this
->
clear_list
=
[];
$this
->
clear_list
=
[];
$this
->
clear_items_list
=
[];
$this
->
clear_items_list
=
[];
$this
->
pay_order_items
=
[];
foreach
(
$this
->
order_items
as
$r
)
{
$this
->
pay_order_items
[]
=
[
'pay_order_item_id'
=>
$this
->
gen_pay_order_item_id
(),
'pay_order_id'
=>
$this
->
order_info
[
'pay_order_id'
],
'order_id'
=>
$this
->
order_info
[
'order_id'
],
'order_item_id'
=>
$r
[
'order_item_id'
],
'user_id'
=>
$this
->
order_info
[
'user_id'
],
];
}
$wx_tip
=
$this
->
make_tip_clearing
();
//微信手续费
$wx_tip
=
$this
->
make_tip_clearing
();
//微信手续费
$subsidy_tip
=
$this
->
make_platform_subsidy_clearing
();
//系统补贴
$subsidy_tip
=
$this
->
make_platform_subsidy_clearing
();
//系统补贴
...
@@ -117,13 +278,16 @@ class PayService
...
@@ -117,13 +278,16 @@ class PayService
try
{
try
{
PayOrderClearing
::
beginTransaction
();
PayOrderClearing
::
beginTransaction
();
$cnt
=
PayOrderClearing
::
insert
(
$this
->
clear_list
,
[
'rowCount'
=>
true
]);
$i_cnt
=
PayOrderClearing
::
insert
(
$this
->
pay_order_items
,
[
'rowCount'
=>
true
]);
$items_cnt
=
PayOrderClearingItem
::
insert
(
$this
->
clear_items_list
,
[
'rowCount'
=>
true
]);
$c_cnt
=
PayOrderItem
::
insert
(
$this
->
clear_list
,
[
'rowCount'
=>
true
]);
$ci_cnt
=
PayOrderClearingItem
::
insert
(
$this
->
clear_items_list
,
[
'rowCount'
=>
true
]);
if
(
$
cnt
>
0
||
$items_cnt
>
0
)
{
if
(
$
i_cnt
*
$c_cnt
*
$ci_cnt
==
0
)
{
PayOrderClearing
::
commit
(
);
throw
new
PayException
([
'cus'
=>
0
]
);
}
}
}
catch
(
\PDOException
$e
)
{
PayOrderClearing
::
commit
();
}
catch
(
\Exception
$e
)
{
Logger
::
error
(
$e
->
getMessage
(),
[]);
Logger
::
error
(
$e
->
getMessage
(),
[]);
PayOrderClearing
::
rollback
();
PayOrderClearing
::
rollback
();
throw
new
PayException
([
'cut'
=>
5
]);
throw
new
PayException
([
'cut'
=>
5
]);
...
@@ -161,6 +325,8 @@ class PayService
...
@@ -161,6 +325,8 @@ class PayService
* 计算平台运营补贴
* 计算平台运营补贴
*/
*/
private
function
make_platform_subsidy_clearing
()
{
private
function
make_platform_subsidy_clearing
()
{
return
0
;
//本期不做平台补贴
$account
=
$this
->
get_marketing_subsidy
();
$account
=
$this
->
get_marketing_subsidy
();
$total_tip
=
$account
[
'amount'
];
$total_tip
=
$account
[
'amount'
];
if
(
empty
(
$total_tip
))
{
if
(
empty
(
$total_tip
))
{
...
@@ -180,6 +346,7 @@ class PayService
...
@@ -180,6 +346,7 @@ class PayService
* 计算商户运营补贴
* 计算商户运营补贴
*/
*/
private
function
make_merchant_subsidy_clearing
()
{
private
function
make_merchant_subsidy_clearing
()
{
return
0
;
// 本期不做商户补贴
$account
=
$this
->
get_marketing_subsidy
();
$account
=
$this
->
get_marketing_subsidy
();
$total_tip
=
$account
[
'amount'
];
$total_tip
=
$account
[
'amount'
];
if
(
empty
(
$total_tip
))
{
if
(
empty
(
$total_tip
))
{
...
@@ -229,7 +396,7 @@ class PayService
...
@@ -229,7 +396,7 @@ class PayService
private
function
make_distribution_clearing
()
{
private
function
make_distribution_clearing
()
{
if
(
$this
->
order_info
[
'is_distribution'
]
==
0
)
{
if
(
$this
->
order_info
[
'is_distribution'
]
==
0
)
{
return
false
;
return
0
;
}
}
/**
/**
...
@@ -283,8 +450,9 @@ class PayService
...
@@ -283,8 +450,9 @@ class PayService
*/
*/
private
function
make_merchant_clearing
(
$merchant_cash
)
{
private
function
make_merchant_clearing
(
$merchant_cash
)
{
$user_id
=
$this
->
get_life_account
(
$this
->
order_info
[
'life_account_id'
]);
$account
=
[
$account
=
[
'account_id'
=>
$
this
->
order_info
[
'life_account_id'
]
,
'account_id'
=>
$
user_id
,
'amount'
=>
$merchant_cash
,
'amount'
=>
$merchant_cash
,
'title'
=>
'商家订单收益'
,
'title'
=>
'商家订单收益'
,
];
];
...
@@ -372,31 +540,45 @@ class PayService
...
@@ -372,31 +540,45 @@ class PayService
];
];
}
}
private
function
gen_pay_order_id
(
$order_id
)
{
private
function
gen_pay_order_id
(
$user_id
)
{
$number
=
$order_id
;
$number
=
substr
(
$user_id
,
-
2
);
return
$this
->
get_idgen_id
(
$number
,
1
);
}
private
function
gen_pay_order_item_id
(
$user_id
)
{
$number
=
substr
(
$user_id
,
-
2
);
return
$this
->
get_idgen_id
(
$number
,
1
);
return
$this
->
get_idgen_id
(
$number
,
1
);
}
}
private
function
gen_pay_order_clearing_id
()
{
private
function
gen_pay_order_clearing_id
()
{
$number
=
$this
->
order_info
[
'order_id'
]
;
$number
=
substr
(
$this
->
order_info
[
'user_id'
],
-
2
)
;
return
$this
->
get_idgen_id
(
$number
,
1
);
return
$this
->
get_idgen_id
(
$number
,
1
);
}
}
private
function
gen_pay_order_clearing_item_id
()
{
private
function
gen_pay_order_clearing_item_id
()
{
$number
=
$this
->
order_info
[
'order_id'
]
;
$number
=
substr
(
$this
->
order_info
[
'user_id'
],
-
2
)
;
return
$this
->
get_idgen_id
(
$number
,
1
);
return
$this
->
get_idgen_id
(
$number
,
1
);
}
}
private
function
get_idgen_id
(
$number
,
$count
=
1
){
private
function
get_idgen_id
(
$number
,
$count
=
1
){
$res
=
Idgen
::
get
(
appConfig
(
'idgen.partner'
),
appConfig
(
'idgen.key'
),
[],
[[
$res
=
Idgen
::
get
(
appConfig
(
'idgen.partner'
),
appConfig
(
'idgen.key'
),
[],
[[
"type"
=>
"
merchant_shop_id
"
,
"type"
=>
"
55c768
"
,
'number'
=>
$number
,
'number'
=>
$number
,
"count"
=>
$count
]]);
"count"
=>
$count
]]);
$id
=
$res
[
'id_datetime'
][
'
merchant_shop_id
'
]
??
[];
$id
=
$res
[
'id_datetime'
][
'
55c768
'
]
??
[];
return
$id
;
return
$id
;
}
}
private
function
get_life_account
(
$life_account_id
)
{
$url
=
config
(
'interface'
,
'merchant.lifeaccount.get_life_account_by_id'
);
if
(
!
$url
)
{
throw
new
CodeSpecialException
(
"failed"
);
}
$params
=
[
'life_account_id'
=>
$life_account_id
];
return
Sdk
::
call
(
$url
,
$params
);
}
/**
/**
* @param $data
* @param $data
...
...
application/services/pingxx/PingxxService.php
0 → 100644
View file @
a963c378
<?php
namespace
App\Services\pingxx
;
use
Pingpp\Order
;
use
Pingpp\OrderRefund
;
use
Helpers\Logger
;
class
PingxxService
{
/**
* @param $order_item_id
* @param $user_id
* @throws RefundException
* 发起退款请求
*/
public
static
function
sendRefund
(
$refundData
,
$chargeId
)
{
try
{
Logger
::
info
(
'退款订单发起'
,
[
'chargeId'
=>
$chargeId
,
'refundData'
=>
$refundData
]);
$royalty_users
=
[];
$ret
=
OrderRefund
::
create
(
$refundData
[
'pay_order_id'
],
[
'charge'
=>
$chargeId
,
//在该订单中,需要退款的 charge 对象 ID,默认全部退款。
'charge_amount'
=>
$refundData
[
'refund_amount'
],
//charge 退款金额,默认为全额退款。必须和 charge 参数同时使用。单位:分。
'description'
=>
'用户申请退款'
,
//退款附加说明。
'metadata'
=>
[
'refund_order_id'
=>
$refundData
[
'refund_order_id'
],
'order_item_id'
=>
$refundData
[
'order_item_id'
],
'goods_sku_id'
=>
$refundData
[
'goods_sku_id'
]
??
''
],
'refund_mode'
=>
'to_source'
,
//退款模式。原路退回:to_source,退至余额:to_balance。默认为原路返回。
'royalty_users'
=>
$royalty_users
,
]
);
Logger
::
info
(
'退款订单返回'
,
[
'res'
=>
$ret
]);
$respose
=
json_decode
(
$ret
,
true
);
return
$respose
[
'data'
];
/*
{
"object": "list",
"url": "/v1/orders/2111608270000005209/order_refunds",
"has_more": false,
"data": [
{
"id": "re_y1u944PmfnrTHyvnL0nD0iD1",
"object": "refund",
"order_no": "y1u944PmfnrTHyvnL0nD0iD1",
"amount": 800,
"created": 1499930518,
"succeed": true,
"status": "succeeded",
"time_succeed": 1499930518,
"description": "Refund Description",
"failure_code": null,
"failure_msg": null,
"metadata": {},
"charge": "ch_8SCSCCn90ir1bb54m5fjbnX5",
"charge_order_no": "2017071102122327",
"transaction_no": "2004450349201512090096425284",
"extra": {}
}
]
}
*
*/
}
catch
(
\Pingpp\Error\Base
$e
)
{
if
(
$e
->
getHttpStatus
()
!=
null
)
{
header
(
'Status: '
.
$e
->
getHttpStatus
());
echo
$e
->
getHttpBody
();
}
else
{
echo
$e
->
getMessage
();
}
}
}
/**
* @param $orderId ping++ 支付订单ID
* @param $refundId ping++ 退款ID
* @return mixed
* 退款信息查询
*/
public
static
function
getRefund
(
$orderId
,
$refundId
)
{
try
{
Logger
::
info
(
'退款查询发起'
,
[
'orderId'
=>
$orderId
,
'refundId'
=>
$refundId
]);
$ret
=
OrderRefund
::
retrieve
(
$orderId
,
$refundId
);
Logger
::
info
(
'退款查询返回'
,
[
'res'
=>
$ret
]);
$respose
=
json_decode
(
$ret
,
true
);
return
$respose
;
}
catch
(
\Pingpp\Error\Base
$e
)
{
if
(
$e
->
getHttpStatus
()
!=
null
)
{
header
(
'Status: '
.
$e
->
getHttpStatus
());
echo
$e
->
getHttpBody
();
}
else
{
echo
$e
->
getMessage
();
}
}
}
/**
* @param $order
* @return mixed
* 创建订单
*/
public
static
function
createOrder
(
$order
)
{
try
{
Logger
::
info
(
'创建订单发起'
,
$order
);
$royalty_users
=
[];
$ret
=
Order
::
create
(
[
"amount"
=>
$order
[
'pay_amount'
],
"app"
=>
APP_ID
,
"merchant_order_no"
=>
$order
[
'pay_order_id'
],
"subject"
=>
"用户购买"
,
"currency"
=>
"cny"
,
"body"
=>
"购买商品"
,
"uid"
=>
$order
[
'user_id'
],
"client_ip"
=>
"192.168.0.101"
,
'receipt_app'
=>
APP_ID
,
// 收款方应用
'service_app'
=>
APP_ID
,
// 服务方应用
'royalty_users'
=>
$royalty_users
,
//'balance_settlement' => [ // 可选参数,余额结算信息。
// 'user' => 'user_001',
// 'user_fee' => 1
//]
]
);
Logger
::
info
(
'创建订单返回'
,
[
'res'
=>
$ret
]);
$respose
=
json_decode
(
$ret
,
true
);
return
$respose
;
}
catch
(
\Pingpp\Error\Base
$e
)
{
// 捕获报错信息
if
(
$e
->
getHttpStatus
()
!=
null
)
{
echo
$e
->
getHttpStatus
()
.
PHP_EOL
;
echo
$e
->
getHttpBody
()
.
PHP_EOL
;
}
else
{
echo
$e
->
getMessage
()
.
PHP_EOL
;
}
}
}
/**
* @param $orderId
* 订单查询
*/
public
static
function
getOrder
(
$orderId
)
{
try
{
Logger
::
info
(
'查询订单发起'
,
[
'orderId'
=>
$orderId
]);
$ret
=
Order
::
retrieve
(
$orderId
);
Logger
::
info
(
'查询订单返回'
,
[
'res'
=>
$ret
]);
$respose
=
json_decode
(
$ret
,
true
);
return
$respose
;
}
catch
(
\Pingpp\Error\Base
$e
)
{
if
(
$e
->
getHttpStatus
()
!=
null
)
{
header
(
'Status: '
.
$e
->
getHttpStatus
());
echo
$e
->
getHttpBody
();
}
else
{
echo
$e
->
getMessage
();
}
}
}
/**
* @param $raw
* @param $header
* @return int
* 校验回调是否合法
*/
public
static
function
verifySignature
(
$raw
,
$headers
)
{
$signature
=
isset
(
$headers
[
'X-Pingplusplus-Signature'
])
?
$headers
[
'X-Pingplusplus-Signature'
]
:
null
;
$pub_key_path
=
''
;
$pub_key_contents
=
file_get_contents
(
$pub_key_path
);
return
openssl_verify
(
$raw
,
base64_decode
(
$signature
),
$pub_key_contents
,
'sha256'
);
}
}
\ No newline at end of file
application/services/refund/RefundService.php
View file @
a963c378
...
@@ -11,14 +11,18 @@ use App\Models\order\mysql\PayOrderClearingItem;
...
@@ -11,14 +11,18 @@ use App\Models\order\mysql\PayOrderClearingItem;
use
App\Models\order\mysql\RefundOrder
;
use
App\Models\order\mysql\RefundOrder
;
use
App\Services\Order\OrderService
;
use
App\Services\Order\OrderService
;
use
App\Services\pingxx\PingxxService
;
use
Helpers\Strategy
;
use
Helpers\Strategy
;
use
Helpers\Logger
;
use
Helpers\Logger
;
use
App\Exception\custom\RefundException
;
use
App\Exception\custom\RefundException
;
use
App\Exception\custom\WalletException
;
class
RefundService
class
RefundService
{
{
private
$refund_order
=
[];
/**
/**
* @param $order_item_id
* @param $order_item_id
* @param $user_id
* @param $user_id
...
@@ -41,75 +45,73 @@ class RefundService
...
@@ -41,75 +45,73 @@ class RefundService
'refund_order_id'
=>
$this
->
gen_refund_order_id
(),
'refund_order_id'
=>
$this
->
gen_refund_order_id
(),
];
];
$refund_order
=
$this
->
can_refund
(
$where
,
$order_item
);
$data
=
$this
->
can_refund
(
$where
,
$order_item
);
// 发起ping++ 创建退款
// 构造退款数据
try
{
$refund
=
[
// 通过发起一次退款请求创建一个新的 refund 对象,只能对已经发生交易并且没有全额退款的 charge 对象发起退款
'charge'
=>
$data
[
'pay_order'
][
'third_order_id'
],
$re
=
\Pingpp\Refund
::
create
(
'charge_amount'
=>
$data
[
'refund_order'
][
'refund_amount'
],
$refund_order
[
'third_order_id'
],
'metadata'
=>
[
[
'refund_order_id'
=>
$data
[
'refund_order'
][
'refund_order_id'
],
'amount'
=>
$refund_order
[
'refund_amount'
],
'order_item_id'
=>
$data
[
'refund_order'
][
'order_item_id'
],
'description'
=>
'订单申请退款'
,
'goods_sku_id'
=>
$order_item
[
'goods_sku_id'
]
??
''
,
'metadata'
=>
[
'refund_order_id'
=>
$refund_order
[
'refund_order_id'
]]
],
]
];
);
try
{
$ret
=
PingxxService
::
sendRefund
(
$refund
);
$ret
=
json_decode
(
$re
,
true
);
if
(
!
empty
(
$ret
[
"data"
]))
{
if
(
!
empty
(
$ret
[
"data"
]))
{
$edit
=
[
$edit
=
[
'request_pingxx_success_time'
=>
date
(
'Y-m-d H:i:s'
)];
'request_pingxx_success_time'
=>
date
(
'Y-m-d H:i:s'
),
];
}
else
{
}
else
{
$edit
=
[
$edit
=
[
'refund_order_status'
=>
Dictionary
::
REFUND_ORDER_STATUS_UNDO
,];
'refund_order_status'
=>
Dictionary
::
REFUND_ORDER_STATUS_UNDO
,
];
}
}
}
catch
(
\Pingpp\Error\Base
$e
)
{
$edit
=
[
'refund_order_status'
=>
Dictionary
::
REFUND_ORDER_STATUS_UNDO
,
];
Logger
::
error
(
$e
->
getHttpBody
());
}
RefundOrder
::
update
(
$edit
,
[
'refund_order_id'
=>
$refund_order
[
'refund_order_id'
]]);
}
catch
(
\Exception
$e
)
{
$edit
=
[
'refund_order_status'
=>
Dictionary
::
REFUND_ORDER_STATUS_UNDO
,];
Logger
::
error
(
$e
->
getMessage
());
}
RefundOrder
::
update
(
$edit
,
[
'refund_order_id'
=>
$data
[
'refund_order'
][
'refund_order_id'
]]);
//返回信息
}
}
public
function
call_back
(
$data
)
{
public
function
call_back
(
$data
)
{
if
(
empty
(
$data
[
'data'
][
'object'
]))
{
if
(
empty
(
$data
[
'data'
][
'object'
]))
{
Logger
::
error
(
'回调参数错误:'
,
$data
);
Logger
::
error
(
'回调参数错误:'
,
$data
);
throw
new
RefundException
([
'cus'
=>
6
]);
}
}
$object
=
$data
[
'data'
][
'object'
];
if
(
empty
(
$object
[
'metadata'
][
'refund_order_id'
]))
{
if
(
empty
(
$object
[
'metadata'
][
'refund_order_id'
]))
{
throw
new
RefundException
([
'cus'
=>
0
]);
throw
new
RefundException
([
'cus'
=>
0
]);
}
}
$refund_order_id
=
$object
[
'metadata'
][
'refund_order_id'
];
// 获取退款回调信息,确认订单ID
$charge
=
$object
[
'charges'
][
'data'
][
0
];
$ping_refund
=
PingxxService
::
getRefund
(
$charge
[
'id'
],
$object
[
'id'
]);
if
(
$ping_refund
[
'status'
]
!=
'succeeded'
)
{
throw
new
RefundException
([
'cus'
=>
6
]);
}
// 修改状态,锁定业务
$refund_order_id
=
$object
[
'metadata'
][
'refund_order_id'
];
$this
->
lock_refund_clear
(
$refund_order_id
);
//不用搞清分核算,是否需要平台记账?
$this
->
make_refund_clear
(
$refund_order_id
);
try
{
/*
// 查询 refund 对象列表
try{
$re_list
=
\Pingpp\Refund
::
all
(
'ch_L8qn10mLmr1GS8e5OODmHaL4'
,
[
$ret = $this->send_wallet();
'limit'
=>
10
,
if($ret) {
]);
$edit = ['notify_account_success_time'=>date('Y-m-d H:i:s')];
echo
$re_list
;
// 输出 Ping++ 返回的 refund 对象列表
}
catch
(
\Pingpp\Error\Base
$e
)
{
if
(
$e
->
getHttpStatus
()
!=
null
)
{
header
(
'Status: '
.
$e
->
getHttpStatus
());
echo
$e
->
getHttpBody
();
} else {
} else {
echo
$e
->
getMessage
()
;
$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);
*/
}
}
/**
/**
...
@@ -185,9 +187,17 @@ class RefundService
...
@@ -185,9 +187,17 @@ class RefundService
'refund_amount'
=>
$order_item
[
'payment'
],
'refund_amount'
=>
$order_item
[
'payment'
],
'refund_wx_tip'
=>
$wx_tip
,
'refund_wx_tip'
=>
$wx_tip
,
];
];
RefundOrder
::
update
(
$edit
,
[
'refund_order_id'
=>
$refund_order
[
'refund_order_id'
]]);
$ret
=
RefundOrder
::
update
(
$edit
,
[
'refund_order_id'
=>
$refund_order
[
'refund_order_id'
]]);
if
(
!
$ret
)
{
throw
new
RefundException
([
'cus'
=>
0
]);
}
$refund_order
[
'third_order_id'
]
=
$pay_order
[
'third_order_id'
];
//重新获取
$refund_order
=
RefundOrder
::
getMaster
(
'*'
,
[
'refund_order_id'
=>
$refund_order
[
'refund_order_id'
]]);
$data
=
[
'refund_order'
=>
$refund_order
,
'pay_order'
=>
$pay_order
,
];
RefundOrder
::
commit
();
RefundOrder
::
commit
();
...
@@ -197,7 +207,66 @@ class RefundService
...
@@ -197,7 +207,66 @@ class RefundService
throw
new
RefundException
([
'cut'
=>
0
]);
throw
new
RefundException
([
'cut'
=>
0
]);
}
}
return
$refund_order
;
return
$data
;
}
private
function
lock_refund_clear
(
$refund_order_id
)
{
try
{
RefundOrder
::
beginTransaction
();
$refund_order
=
RefundOrder
::
get
(
'*'
,
[
'refund_order_id'
=>
$refund_order_id
]);
if
(
empty
(
$refund_order
))
{
throw
new
RefundException
([
'cus'
=>
0
]);
}
$this
->
refund_order
=
$refund_order
;
if
(
$refund_order
[
'refund_order_status'
]
==
Dictionary
::
REFUND_ORDER_STATUS_OK
)
{
throw
new
RefundException
([
'cus'
=>
0
]);
}
$edit
=
[
'refund_order_status'
=>
Dictionary
::
REFUND_ORDER_STATUS_OK
,
'pingxx_callback_success_time'
=>
date
(
'Y-m-d H:i:s'
),
'notify_account_status'
=>
Dictionary
::
SEND_ACCOUNT_STATUS_DONE
,
];
RefundOrder
::
update
(
$edit
,
[
'refund_order_id'
=>
$refund_order_id
]);
RefundOrder
::
commit
();
}
catch
(
\PDOException
$e
)
{
RefundOrder
::
rollback
();
Logger
::
error
(
$e
->
getMessage
(),
$edit
);
throw
$e
;
}
}
private
function
make_refund_clear
()
{
$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手续费,平台总帐,平台补贴,商户补贴
$platform_account_id
=
config
(
'pay'
,
'platform_account.account_id'
);
$wallet
[
'platform_account_id'
]
=
[
'account_id'
=>
$platform_account_id
,
'account_type'
=>
Dictionary
::
ACCOUNT_TYPE_ST
,
'pay_amount'
=>
0
,
'pay_type'
=>
Dictionary
::
PAY_TYPE_OUT
,
'pay_sub_type'
=>
1
,
];
foreach
(
$list
as
$r
)
{
if
(
$r
[
'pay_type'
]
==
Dictionary
::
PAY_TYPE_OUT
)
{
$wallet
[
'platform_account_id'
][
'pay_amount'
]
+=
$r
[
'pay_amount'
];
}
else
{
$wallet
[
'platform_account_id'
][
'pay_amount'
]
+=
$r
[
'pay_amount'
];
}
}
}
}
}
}
\ No newline at end of file
application/services/wallet/WalletService.php
0 → 100644
View file @
a963c378
<?php
namespace
App\Services\wallet
;
use
App\Exception\custom\CodeSpecialException
;
use
Helpers\Sdk
;
class
WalletService
{
/**
* @param $params
* @return bool|mixed
* @throws CodeSpecialException
* 钱包记录同步
*/
public
static
function
send
(
$params
)
{
$url
=
config
(
'interface'
,
'wallet.wallet.recharge'
);
if
(
!
$url
)
{
throw
new
CodeSpecialException
(
"failed"
);
}
return
Sdk
::
call
(
$url
,
$params
);
}
}
\ No newline at end of file
public/demo.php
0 → 100644
View file @
a963c378
<?php
var_dump
(
$_POST
);
public/index.php
View file @
a963c378
...
@@ -5,6 +5,7 @@ ini_set("display_errors", "On");
...
@@ -5,6 +5,7 @@ ini_set("display_errors", "On");
/* 定义这个常量是为了在application.ini中引用*/
/* 定义这个常量是为了在application.ini中引用*/
define
(
'ROOT_PATH'
,
realpath
(
__DIR__
.
'/../'
));
define
(
'ROOT_PATH'
,
realpath
(
__DIR__
.
'/../'
));
define
(
'APP_PATH'
,
realpath
(
__DIR__
.
'/../application'
));
define
(
'APP_PATH'
,
realpath
(
__DIR__
.
'/../application'
));
define
(
'LOG_PATH'
,
realpath
(
__DIR__
.
'/../logs'
)
.
'/'
);
define
(
'APP_START'
,
microtime
(
true
));
define
(
'APP_START'
,
microtime
(
true
));
// 调试参数 __debug 的值
// 调试参数 __debug 的值
...
@@ -17,3 +18,4 @@ define('_ERROR_LEVEL', E_ALL);
...
@@ -17,3 +18,4 @@ define('_ERROR_LEVEL', E_ALL);
$application
=
new
Yaf\Application
(
ROOT_PATH
.
"/conf/application.ini"
);
$application
=
new
Yaf\Application
(
ROOT_PATH
.
"/conf/application.ini"
);
$application
->
bootstrap
()
->
run
();
$application
->
bootstrap
()
->
run
();
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