Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
service
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
aimeiyue
service
Commits
a38e0337
Commit
a38e0337
authored
Mar 25, 2025
by
yink
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
对账单下载
parent
0abbcdec
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
147 additions
and
26 deletions
+147
-26
app/Admin/Controllers/HfBillDownController.php
+84
-24
app/Admin/routes.php
+2
-2
app/Command/Log.php
+44
-0
app/Command/Tools.php
+17
-0
No files found.
app/Admin/Controllers/
CategoryControllerTest
.php
→
app/Admin/Controllers/
HfBillDownController
.php
View file @
a38e0337
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
namespace
App\Admin\Controllers
;
namespace
App\Admin\Controllers
;
use
App\Models\Category
;
use
App\Models\Category
;
use
App\Command\Tools
;
use
App\Command\Log
;
use
Dcat\Admin\Form
;
use
Dcat\Admin\Form
;
use
Dcat\Admin\Grid
;
use
Dcat\Admin\Grid
;
use
Dcat\Admin\Show
;
use
Dcat\Admin\Show
;
...
@@ -12,7 +14,7 @@
...
@@ -12,7 +14,7 @@
use
Dcat\Admin\Http\Controllers\AdminController
;
use
Dcat\Admin\Http\Controllers\AdminController
;
use
NwVVVS\AdapaySdk\AdapayTools
;
use
NwVVVS\AdapaySdk\AdapayTools
;
class
CategoryControllerTest
extends
AdminController
class
HfBillDownController
extends
AdminController
{
{
public
function
index
(
Content
$content
)
public
function
index
(
Content
$content
)
...
@@ -24,31 +26,53 @@ public function index(Content $content)
...
@@ -24,31 +26,53 @@ public function index(Content $content)
// 这里可以添加你想要展示的内容,例如文本信息---
// 这里可以添加你想要展示的内容,例如文本信息---
//$row->column(12, '<p>这是对账单下载页面,请选择合适的操作。</p>');
//$row->column(12, '<p>这是对账单下载页面,请选择合适的操作。</p>');
// 添加时间选择控件和按钮
// 添加时间选择控件和按钮
$row
->
column
(
2
,
'<input type="date" class="form-control" id="download-date" />'
);
$row
->
column
(
3
,
'<input type="date" class="form-control" id="download-date" />'
);
$row
->
column
(
6
,
'<button id="download-button" class="btn btn-primary">下载</button>'
);
$row
->
column
(
6
,
'<button id="download-button" class="btn btn-primary">下载</button>'
);
$row
->
column
(
12
,
'<div><br></div>'
);
$row
->
column
(
12
,
'<div>下载文件为zip压缩包,解压后获取csv类型的文件,编码格式为UTF-8,若使用Excel打开可能会出现乱码,解决方案请参考 <a href="https://jingyan.baidu.com/article/7082dc1c359cbbe40a89bd3e.html" target="_blank" rel="noopener">Excel打开CSV文件</a> :</p></div>'
);
$row
->
column
(
12
,
'<p>Charge开头的文件为支付对账单,参考 <a href="https://cdn.cloudpnr.com/adapayresource/documents/Adapay%20Charge%E5%AF%B9%E8%B4%A6%E5%8D%95%E6%A8%A1%E7%89%88.csv" target="_blank" rel="noopener">支付对账单模版</a></p>'
);
$row
->
column
(
12
,
'<p>Refund开头的文件为退款对账单,参考 <a href="https://cdn.cloudpnr.com/adapayresource/documents/Adapay%20Refund%E5%AF%B9%E8%B4%A6%E5%8D%95%E6%A8%A1%E7%89%88.csv" target="_blank" rel="noopener">退款对账单模版</a></p>'
);
$row
->
column
(
12
,
'<p>PaymentConfirm开头的文件为支付确认对账单,参考 <a href="https://cdn.cloudpnr.com/adapayresource/documents/Adapay%20PaymentConfirm%E5%AF%B9%E8%B4%A6%E5%8D%95%E6%A8%A1%E7%89%88.csv" target="_blank" rel="noopener">支付确认对账单模版</a></p>'
);
$row
->
column
(
12
,
'<p>Div开头的文件为分账对账单,参考 <a href="https://cloudpnrcdn.oss-cn-shanghai.aliyuncs.com/adapayresource/Div对账单模版.csv" target="_blank" rel="noopener">分账对账单模版</a></p>'
);
$row
->
column
(
12
,
'<p>RefundDiv开头的文件为分账退款对账单,参考 <a href="https://cloudpnrcdn.oss-cn-shanghai.aliyuncs.com/adapayresource/RefundDiv对账单模版.csv" target="_blank" rel="noopener">分账退款对账单模版</a></p>'
);
// 添加 JavaScript 代码绑定点击事件
// 添加 JavaScript 代码绑定点击事件
$row
->
column
(
$row
->
column
(
12
,
12
,
<<<
HTML
<<<
HTML
<
script
>
<
script
>
document
.
getElementById
(
'download-button'
)
.
addEventListener
(
'click'
,
function
()
{
document
.
getElementById
(
'download-button'
)
.
addEventListener
(
'click'
,
function
()
{
var
date
=
document
.
getElementById
(
'download-date'
)
.
value
;
var
date
=
document
.
getElementById
(
'download-date'
)
.
value
;
if
(
date
)
{
if
(
date
)
{
fetch
(
'/category-download?date='
+
date
,
{
fetch
(
'/bill-down-download?date='
+
date
,
{
method
:
'GET'
method
:
'GET'
})
})
.
then
(
response
=>
response
.
json
())
.
then
(
response
=>
response
.
json
())
.
then
(
data
=>
{
.
then
(
data
=>
{
console
.
log
(
data
);
console
.
log
(
data
);
// 这里可以添加更多处理逻辑,例如显示提示信息
// 判断 code 是否为 200
});
if
(
data
.
code
===
200
)
{
}
else
{
// 创建一个隐藏的 a 标签
alert
(
'请选择日期'
);
var
a
=
document
.
createElement
(
'a'
);
}
a
.
href
=
data
.
data
.
url
;
});
a
.
download
=
'downloaded_file.zip'
;
// 可以根据需要修改文件名
</
script
>
a
.
style
.
display
=
'none'
;
HTML
document
.
body
.
appendChild
(
a
);
a
.
click
();
document
.
body
.
removeChild
(
a
);
}
else
{
alert
(
'下载失败:请查看日志 '
);
}
});
}
else
{
alert
(
'请选择日期'
);
}
});
</
script
>
HTML
);
);
});
});
}
}
...
@@ -59,13 +83,49 @@ public function index(Content $content)
...
@@ -59,13 +83,49 @@ public function index(Content $content)
public
function
download
()
public
function
download
()
{
{
$date
=
request
()
->
input
(
'date'
);
$date
=
request
()
->
input
(
'date'
);
$date
=
str_replace
(
'-'
,
''
,
$date
);
# 初始化对账单下载对象类
# 初始化对账单下载对象类
$bill
=
new
AdapayTools
;
$bill
=
new
AdapayTools
;
# 对账单下载
# 对账单下载
$bill
->
download
([
"bill_date"
=>
"20180808"
]);
$bill
->
download
(
strval
(
$date
));
return
response
()
->
json
([
'message'
=>
'下载请求已接收'
,
'date'
=>
$bill
]);
//Log::addByName('billDownloadUrl', $date);
// 检查 $bill->result 是否为数组
if
(
is_array
(
$bill
->
result
))
{
$responseData
=
$bill
->
result
;
}
else
{
$responseData
=
json_decode
(
$bill
->
result
,
true
);
}
// 解码第二个元素(是一个JSON字符串)
$resultData
=
json_decode
(
$responseData
[
1
],
true
);
// 提取data字段,并解码其中的JSON字符串
$data
=
json_decode
(
$resultData
[
'data'
],
true
);
// 初始化变量
$billDownloadUrl
=
''
;
// 检查响应数据是否存在且第一个元素是否为 200
if
(
isset
(
$responseData
[
0
])
&&
$responseData
[
0
]
==
200
)
{
// 获取bill_download_url的值
$billDownloadUrl
=
$data
[
'bill_download_url'
];
}
else
{
// 获取error_msg的值
$errorMsg
=
$data
[
'error_msg'
];
return
Tools
::
JsonResponse
([
'url'
=>
''
],
"下载失败,请查看日志:"
.
$errorMsg
,
501
);
}
if
(
$billDownloadUrl
==
''
){
Log
::
addByName
(
'billDownloadUrl'
,
$responseData
);
return
Tools
::
JsonResponse
([
'url'
=>
$billDownloadUrl
],
"下载失败,请查看日志"
,
501
);
}
return
Tools
::
JsonResponse
([
'url'
=>
$billDownloadUrl
]);
}
}
/**
/**
...
...
app/Admin/routes.php
View file @
a38e0337
...
@@ -44,8 +44,8 @@
...
@@ -44,8 +44,8 @@
$router
->
resource
(
'category'
,
'CategoryController'
);
//分类管理
$router
->
resource
(
'category'
,
'CategoryController'
);
//分类管理
$router
->
resource
(
'
category-test'
,
'CategoryControllerTest
'
);
//对账单下载-页面
$router
->
resource
(
'
bill-down'
,
'HfBillDownController
'
);
//对账单下载-页面
$router
->
get
(
'
category-download'
,
'CategoryControllerTest
@download'
);
//对账单下载-下载
$router
->
get
(
'
bill-down-download'
,
'HfBillDownController
@download'
);
//对账单下载-下载
$router
->
resource
(
'article'
,
'ArticleController'
);
//文章管理
$router
->
resource
(
'article'
,
'ArticleController'
);
//文章管理
...
...
app/Command/Log.php
View file @
a38e0337
...
@@ -47,6 +47,50 @@ static public function add(string $logKey, mixed $logInfo, ?Request $request = n
...
@@ -47,6 +47,50 @@ static public function add(string $logKey, mixed $logInfo, ?Request $request = n
}
}
}
}
static
public
function
addByName
(
string
$logKey
,
mixed
$logInfo
,
?
Request
$request
=
null
)
:
void
{
try
{
// 判断当天的日志文件是否存在
$logFileName
=
'runLog_'
.
$logKey
.
'.log'
;
$logPath
=
storage_path
(
"logs/"
.
$logFileName
);
// 检查日志目录是否存在,如果不存在则创建
if
(
!
is_dir
(
dirname
(
$logPath
)))
{
mkdir
(
dirname
(
$logPath
),
0777
,
true
);
}
// 拼接用户信息
if
(
$request
&&
$request
->
user
())
{
$userObj
=
$request
->
user
();
$userInfo
=
"【-----------用户信息----------】"
.
PHP_EOL
;
$userInfo
.=
"【用户ID】: "
.
$userObj
->
id
.
";"
.
PHP_EOL
;
$userInfo
.=
"【用户名称】: "
.
$userObj
->
name
.
";"
.
PHP_EOL
;
// 添加请求参数到日志信息
$requestParams
=
$request
->
all
();
$paramInfo
=
"【请求参数】: "
.
print_r
(
$requestParams
,
true
)
.
PHP_EOL
;
$userInfo
.=
$paramInfo
;
}
else
{
$userInfo
=
"【-----------用户信息----------】"
.
PHP_EOL
;
$userInfo
.=
"【未获取到用户信息】"
.
PHP_EOL
;
}
// 获取请求路径
$requestPath
=
$request
?
$request
->
getPathInfo
()
:
'N/A'
;
// 添加请求路径到日志信息
$logMessage
=
"--------------------"
.
str_repeat
(
"-"
,
20
)
.
PHP_EOL
;
$logMessage
.=
"【"
.
date
(
'Y-m-d H:i:s'
)
.
"】"
.
PHP_EOL
.
"【返回值:】"
.
$userInfo
.
"【请求路径】:
$requestPath
【"
.
$logKey
.
"】: "
.
print_r
(
$logInfo
,
true
)
.
PHP_EOL
;
$logMessage
.=
"--------------------"
.
str_repeat
(
"-"
,
20
)
.
PHP_EOL
.
PHP_EOL
;
// 添加换行符
file_put_contents
(
$logPath
,
$logMessage
,
FILE_APPEND
);
}
catch
(
\Exception
$e
)
{
// 记录异常信息到另一个日志文件
$errorLogPath
=
storage_path
(
"logs/error_log.log"
);
file_put_contents
(
$errorLogPath
,
"【"
.
date
(
'Y-m-d H:i:s'
)
.
"】【add日志 方法出错】: "
.
$e
->
getMessage
()
.
PHP_EOL
,
FILE_APPEND
);
}
}
}
}
app/Command/Tools.php
View file @
a38e0337
<?php
<?php
namespace
App\Command
;
namespace
App\Command
;
use
Illuminate\Http\Response
;
class
Tools
{
class
Tools
{
/**
* @param $data mixed 返回的数据
* @param $msg string 状态码
* @param $code int 返回的自定义信息
* @return Response
*/
public
static
function
JsonResponse
(
$data
,
string
$msg
=
'Success'
,
int
$code
=
200
)
:
Response
{
//组建返回结果
$result
=
[
'code'
=>
$code
,
'message'
=>
$msg
,
'data'
=>
$data
,
];
return
response
(
$result
,
200
);
}
// 计算俩地距离
// 计算俩地距离
function
get_two_point_distance
(
$lat1
,
$lng1
,
$lat2
,
$lng2
)
function
get_two_point_distance
(
$lat1
,
$lng1
,
$lat2
,
$lng2
)
...
...
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