Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
朱继来
/
后台订单管理
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2d1635b8
authored
Jul 26, 2018
by
朱继来
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
添加错误日志
parent
d2d106f2
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
248 additions
and
12 deletions
app/Exceptions/Handler.php
app/Http/Controllers/OrderController.php
app/Http/Error.php
app/Http/Function.php
app/Http/Middleware/CheckLogin.php
bootstrap/autoload.php
vendor/logreport/LogReport.php
app/Exceptions/Handler.php
View file @
2d1635b8
...
...
@@ -34,6 +34,7 @@ class Handler extends ExceptionHandler
*/
public
function
report
(
Exception
$e
)
{
\LogReport
::
write
(
\LogReport
::
anlyError
(
$e
->
getMessage
()
,
$e
->
getFile
(),
$e
->
getLine
()));
return
parent
::
report
(
$e
);
}
...
...
app/Http/Controllers/OrderController.php
View file @
2d1635b8
...
...
@@ -10,6 +10,7 @@ use Cookie;
use
App\Http\Page
;
use
App\Http\Controllers\PermController
;
use
Illuminate\Support\Facades\Redis
;
use
App\Http\Error
;
function
CheckActive
(
$menus
,
&
$arr
,
$url
)
{
...
...
@@ -663,6 +664,7 @@ Class OrderController extends Controller
$xlslist
=
exportExcel
(
$xlsName
,
$xlsCell
,
$export
);
$this
->
$xlslist
;
}
else
{
errorLog
(
Error
::
E_NOT_EXISTS
,
'数据为空无法导出'
);
return
redirect
(
'/prompt'
)
->
with
([
'message'
=>
"数据为空无法导出!"
,
'url'
=>
$_SERVER
[
'HTTP_REFERER'
],
'jumpTime'
=>
3
,
'status'
=>
false
]);
}
}
...
...
@@ -793,7 +795,10 @@ Class OrderController extends Controller
$log
[
'create_time'
]
=
time
();
$actionLog
=
DB
::
connection
(
'order'
)
->
table
(
'lie_order_action_log'
)
->
insert
(
$log
);
if
(
!
$actionLog
)
return
[
'errcode'
=>-
1
,
'errmsg'
=>
'添加操作记录失败'
];
if
(
!
$actionLog
){
errorLog
(
Error
::
E_ADD_FAILED
,
'添加操作记录失败'
);
return
[
'errcode'
=>
Error
::
E_ADD_FAILED
,
'errmsg'
=>
'添加操作记录失败'
];
}
$apiUrl
=
Config
(
'website.api_domain'
);
$k1
=
time
();
...
...
@@ -860,7 +865,8 @@ Class OrderController extends Controller
}
if
(
!
$collert
[
'reason'
]){
return
array
(
'errcode'
=>
101
,
'errmsg'
=>
'请填写删除原因'
);
errorLog
(
Error
::
E_NOT_EXISTS
,
'请填写删除原因'
);
return
array
(
'errcode'
=>
Error
::
E_NOT_EXISTS
,
'errmsg'
=>
'请填写删除原因'
);
}
$url
=
Config
(
'website.api_domain'
)
.
'order/deleteGoods'
;
...
...
@@ -889,7 +895,8 @@ Class OrderController extends Controller
$order_id
=
$request
->
input
(
'order_id'
,
''
);
if
(
!
$order_id
)
{
return
array
(
'errcode'
=>
1
,
'errmsg'
=>
'订单参数有误!'
);
errorLog
(
Error
::
E_PARAM
,
'订单参数有误'
);
return
array
(
'errcode'
=>
Error
::
E_PARAM
,
'errmsg'
=>
'订单参数有误!'
);
}
// $order_info = DB::connection('order')->table('lie_order')->where('order_id', $order_id)->first();
...
...
@@ -950,7 +957,10 @@ Class OrderController extends Controller
// 调价失败临时表状态更改
$order_temp
=
DB
::
connection
(
'order'
)
->
table
(
'lie_order_extend'
)
->
where
([
'order_id'
=>
$order_id
])
->
update
([
'status'
=>
-
1
]);
if
(
!
$order_temp
)
return
array
(
'errcode'
=>-
1
,
'errmsg'
=>
'驳回失败'
);
if
(
!
$order_temp
)
{
errorLog
(
Error
::
E_UPDATE_FAILED
,
'驳回失败'
);
return
array
(
'errcode'
=>
Error
::
E_UPDATE_FAILED
,
'errmsg'
=>
'驳回失败'
);
}
// 操作记录
$log
[
'order_id'
]
=
$order_id
;
...
...
@@ -973,8 +983,10 @@ Class OrderController extends Controller
$sale_id
=
$request
->
input
(
'sale_id'
,
''
);
$operator_id
=
$request
->
user
->
userId
;
if
(
empty
(
$order_id
)
||
empty
(
$sale_id
))
return
array
(
'errcode'
=>
10003
,
'errmsg'
=>
'参数不存在'
);
if
(
empty
(
$order_id
)
||
empty
(
$sale_id
))
{
errorLog
(
Error
::
E_NOT_EXISTS
,
'参数不存在'
);
return
array
(
'errcode'
=>
Error
::
E_NOT_EXISTS
,
'errmsg'
=>
'参数不存在'
);
}
$url
=
Config
(
'website.api_domain'
)
.
'order/sendSales'
;
...
...
@@ -1036,6 +1048,7 @@ Class OrderController extends Controller
//总共允许2次调价(以点击审核按钮次数来统计)
if
(
$info
[
'order_info'
][
'adjust_count'
]
>=
2
)
{
errorLog
(
Error
::
E_FORBIDDEN
,
'该订单无法再进行调价操作'
);
return
redirect
(
'/prompt'
)
->
with
([
'message'
=>
"该订单无法再进行调价操作"
,
'url'
=>
'/details/'
.
$id
,
'jumpTime'
=>
3
,
'status'
=>
false
]);
}
...
...
@@ -1047,6 +1060,7 @@ Class OrderController extends Controller
$update
=
DB
::
connection
(
'order'
)
->
table
(
'lie_order'
)
->
where
(
'order_id'
,
$id
)
->
update
(
$data
);
if
(
!
$update
)
{
errorLog
(
Error
::
E_UPDATE_FAILED
,
'调价操作更新数据失败'
);
return
redirect
(
'/prompt'
)
->
with
([
'message'
=>
"调价操作更新数据失败!"
,
'url'
=>
'/details/'
.
$id
,
'jumpTime'
=>
3
,
'status'
=>
false
]);
}
...
...
@@ -1236,11 +1250,13 @@ Class OrderController extends Controller
$operator_id
=
$request
->
user
->
userId
;
if
(
!
$order_id
)
{
return
array
(
'errcode'
=>-
1
,
'errmsg'
=>
'订单不存在~'
);
errorLog
(
Error
::
E_NOT_EXISTS
,
'订单不存在'
);
return
array
(
'errcode'
=>
Error
::
E_NOT_EXISTS
,
'errmsg'
=>
'订单不存在~'
);
}
if
(
!
$cancel_reason
)
{
return
array
(
'errcode'
=>-
1
,
'errmsg'
=>
'取消订单的原因不可为空~'
);
errorLog
(
Error
::
E_NOT_EXISTS
,
'取消订单的原因不可为空'
);
return
array
(
'errcode'
=>
Error
::
E_NOT_EXISTS
,
'errmsg'
=>
'取消订单的原因不可为空~'
);
}
$url
=
Config
(
'website.api_domain'
)
.
'order/cancelPay'
;
...
...
@@ -1288,7 +1304,8 @@ Class OrderController extends Controller
if
(
$temp
[
'err_code'
]
==
0
)
{
return
array
(
'errcode'
=>
0
,
'errmsg'
=>
'操作成功'
);
}
else
{
return
array
(
'errcode'
=>-
1
,
'errmsg'
=>
'操作失败'
);
errorLog
(
Error
::
E_UPDATE_FAILED
,
'操作失败'
);
return
array
(
'errcode'
=>
Error
::
E_UPDATE_FAILED
,
'errmsg'
=>
'操作失败'
);
}
}
else
{
$payLog
[
'is_paid'
]
=
2
;
...
...
@@ -1304,10 +1321,12 @@ Class OrderController extends Controller
// 订单待付款状态可操作对账
if
(
$info
[
'order_info'
][
'order_pay_type'
]
==
1
)
{
// 全款
if
(
!
in_array
(
$info
[
'order_info'
][
'status'
],
array
(
2
,
4
)))
{
errorLog
(
Error
::
E_FORBIDDEN
,
'订单无法操作'
);
return
redirect
(
'/prompt'
)
->
with
([
'message'
=>
'订单无法操作'
,
'url'
=>
$_SERVER
[
'HTTP_REFERER'
],
'jumpTime'
=>
3
,
'status'
=>
false
]);
}
}
else
if
(
$info
[
'order_info'
][
'order_pay_type'
]
==
2
)
{
// 预付款
if
(
!
in_array
(
$info
[
'order_info'
][
'status'
],
array
(
2
,
3
,
4
)))
{
errorLog
(
Error
::
E_FORBIDDEN
,
'订单无法操作'
);
return
redirect
(
'/prompt'
)
->
with
([
'message'
=>
'订单无法操作'
,
'url'
=>
$_SERVER
[
'HTTP_REFERER'
],
'jumpTime'
=>
3
,
'status'
=>
false
]);
}
}
...
...
@@ -1333,6 +1352,7 @@ Class OrderController extends Controller
if
(
$update
[
'err_code'
]
==
0
)
{
return
array
(
'errcode'
=>
0
,
'errmsg'
=>
'操作成功'
);
}
else
{
errorLog
(
Error
::
E_UPDATE_FAILED
,
'操作失败'
);
return
array
(
'errcode'
=>-
1
,
'errmsg'
=>
'操作失败'
);
}
}
...
...
@@ -1340,6 +1360,7 @@ Class OrderController extends Controller
$info
=
$this
->
orderDetail
(
$request
,
$id
);
if
(
!
$info
[
'order_address_info'
])
{
errorLog
(
Error
::
E_NOT_EXISTS
,
'订单地址不存在'
);
return
redirect
(
'/prompt'
)
->
with
([
'message'
=>
'订单地址不存在!'
,
'url'
=>
$_SERVER
[
'HTTP_REFERER'
],
'jumpTime'
=>
3
,
'status'
=>
false
]);
}
...
...
@@ -1367,6 +1388,7 @@ Class OrderController extends Controller
if
(
$update
[
'err_code'
]
==
0
)
{
return
array
(
'errcode'
=>
0
,
'errmsg'
=>
'操作成功'
);
}
else
{
errorLog
(
Error
::
E_UPDATE_FAILED
,
'操作失败'
);
return
array
(
'errcode'
=>-
1
,
'errmsg'
=>
'操作失败'
);
}
}
...
...
@@ -1374,6 +1396,7 @@ Class OrderController extends Controller
$info
=
$this
->
orderDetail
(
$request
,
$id
);
if
(
!
$info
[
'order_invoice_info'
])
{
errorLog
(
Error
::
E_NOT_EXISTS
,
'发票不存在'
);
return
redirect
(
'/prompt'
)
->
with
([
'message'
=>
'发票不存在!'
,
'url'
=>
$_SERVER
[
'HTTP_REFERER'
],
'jumpTime'
=>
3
,
'status'
=>
false
]);
}
...
...
@@ -1426,6 +1449,7 @@ Class OrderController extends Controller
$operator_id
=
$request
->
user
->
userId
;
if
(
!
$data
[
'inv_shipping_no'
])
{
errorLog
(
Error
::
E_NOT_EXISTS
,
'发票物流单号不可为空'
);
return
redirect
(
'/prompt'
)
->
with
([
'message'
=>
'发票物流单号不可为空~'
,
'url'
=>
$_SERVER
[
'HTTP_REFERER'
],
'jumpTime'
=>
3
,
'status'
=>
false
]);
}
...
...
@@ -1735,7 +1759,10 @@ Class OrderController extends Controller
$delay_time
=
$request
->
input
(
'delay_time'
,
''
);
}
if
(
empty
(
$order_id
)
||
empty
(
$delay_time
))
return
[
'errcode'
=>
10003
,
'errmsg'
=>
'参数不存在'
];
if
(
empty
(
$order_id
)
||
empty
(
$delay_time
))
{
errorLog
(
Error
::
E_NOT_EXISTS
,
'参数不存在'
);
return
[
'errcode'
=>
Error
::
E_NOT_EXISTS
,
'errmsg'
=>
'参数不存在'
];
}
$order
=
DB
::
connection
(
'order'
)
->
table
(
'lie_order'
)
->
where
(
'order_id'
,
'='
,
$order_id
)
->
select
(
'pay_time'
)
->
first
();
...
...
@@ -1744,6 +1771,7 @@ Class OrderController extends Controller
$update
=
DB
::
connection
(
'order'
)
->
table
(
'lie_order'
)
->
where
(
'order_id'
,
'='
,
$order_id
)
->
update
([
'pay_time'
=>
$delay_time
]);
if
(
!
$update
)
{
errorLog
(
Error
::
E_UPDATE_FAILED
,
'延长失败'
);
return
[
'errcode'
=>
0
,
'errmsg'
=>
'延长失败'
];
}
...
...
app/Http/Error.php
View file @
2d1635b8
...
...
@@ -14,4 +14,7 @@ class Error
const
E_SERVER
=
-
10008
;
// 服务错误
const
E_NOT_EXISTS
=
-
10009
;
// 不存在
const
E_NO_ACCESS
=
-
10010
;
// 无权访问
const
E_ADD_FAILED
=
-
10011
;
// 添加失败
const
E_UPDATE_FAILED
=
-
10012
;
// 更新失败
};
app/Http/Function.php
View file @
2d1635b8
...
...
@@ -183,3 +183,15 @@
return
$ip
[
$type
];
}
// 记录错误日志
function
errorLog
(
$err_code
,
$err_msg
)
{
$near_trace
=
debug_backtrace
(
DEBUG_BACKTRACE_IGNORE_ARGS
,
2
);
$backtrace
=
array_pop
(
$near_trace
);
$file
=
!
empty
(
$near_trace
[
0
][
'file'
])
?
$near_trace
[
0
][
'file'
]
:
''
;
$line
=
!
empty
(
$near_trace
[
0
][
'line'
])
?
$near_trace
[
0
][
'line'
]
:
0
;
$method
=
!
empty
(
$backtrace
[
'function'
])
?
$backtrace
[
'function'
]
:
''
;
\LogReport
::
write
(
\LogReport
::
anlyError
(
$err_msg
,
$file
,
$line
,
$err_code
,
$method
));
}
\ No newline at end of file
app/Http/Middleware/CheckLogin.php
View file @
2d1635b8
...
...
@@ -28,8 +28,10 @@ class CheckLogin
$login
=
Config
::
get
(
'website.login'
);
if
(
!
$userId
||
!
$skey
||
(
string
)((
int
)
$userId
)
!=
$userId
||
!
preg_match
(
'/^[a-zA-Z0-9]+$/'
,
$skey
))
{
if
(
$isApi
)
if
(
$isApi
)
{
errorLog
(
Error
::
E_NOT_LOGIN
,
'not login'
);
return
Output
::
makeResult
(
$request
,
Error
::
E_NOT_LOGIN
,
"not login"
);
}
return
redirect
(
$login
[
'login'
]
.
'?redirect='
.
urlencode
(
$request
->
url
()));
}
...
...
@@ -43,8 +45,10 @@ class CheckLogin
if
(
$rsp
->
getStatusCode
()
!=
200
)
{
Log
::
error
(
"query
{
$login
[
'check'
]
}
failed: code "
.
$rsp
->
getStatusCode
());
if
(
$isApi
)
if
(
$isApi
)
{
errorLog
(
Error
::
E_SERVER
,
"login server error: status code = "
.
$rsp
->
getStatusCode
());
return
Output
::
makeResult
(
$request
,
Error
::
E_SERVER
,
"login server error: status code = "
.
$rsp
->
getStatusCode
());
}
abort
(
500
);
}
...
...
@@ -71,6 +75,7 @@ class CheckLogin
$access
=
json_decode
(
$this
->
checkAccessApi
(
$url
,
$data
),
true
);
if
(
$access
[
'retcode'
]
!=
0
)
{
errorLog
(
Error
::
E_NO_ACCESS
,
'no access'
);
return
view
(
'no_access'
,
[
'bid'
=>
$access
[
'data'
][
'bid'
]]);
// return Output::makeResult($request, Error::E_NO_ACCESS, 'You have not access to the Order System, please apply for the permission to PERM System!');
}
...
...
bootstrap/autoload.php
View file @
2d1635b8
...
...
@@ -17,6 +17,7 @@ define('LARAVEL_START', microtime(true));
require
__DIR__
.
'/../vendor/autoload.php'
;
require
__DIR__
.
'/../app/Http/Function.php'
;
require
__DIR__
.
'/../vendor/PHPExcel/PHPExcel.php'
;
require
__DIR__
.
'/../vendor/logreport/LogReport.php'
;
/*
|--------------------------------------------------------------------------
...
...
vendor/logreport/LogReport.php
0 → 100644
View file @
2d1635b8
<?php
//日志目录位置
defined
(
'REPORT_LOG_PATH'
)
or
define
(
'REPORT_LOG_PATH'
,
dirname
(
$_SERVER
[
'DOCUMENT_ROOT'
])
.
'/storage/logs/LogReport/'
);
//项目名
defined
(
'REPORT_APP_NAME'
)
or
define
(
'REPORT_APP_NAME'
,
'order'
);
//单日志文件大小限制
defined
(
'LOG_FILE_SIZE'
)
or
define
(
'LOG_FILE_SIZE'
,
2097152
);
//2MB
// 设定错误和异常处理
error_reporting
(
0
);
LogReport
::
auto
();
class
LogReport
{
static
$handler
=
[
'finally_except'
=>
[
'Think\Think'
,
'appException'
],
'finally_error'
=>
[
'Think\Think'
,
'appError'
],
];
static
$data
=
[
'msg'
=>
''
,
// 错误信息
'msgCode'
=>
''
,
// 自定义错误码 六位数字字符串 etc "100000"
'ts'
=>
''
,
// 10位整形 时间戳
'dateStr'
=>
''
,
// 日期 2018-06-28 21:24:09
'app'
=>
''
,
// 应用名称
'serverIp'
=>
''
,
// 服务器ip
'fileName'
=>
''
,
// 文件名
'lineNo'
=>
''
,
// 行数
'method'
=>
''
,
// 函数名
];
/**
* 自动注册
* @return [type] [description]
*/
static
function
auto
()
{
if
(
defined
(
'APP_PATH'
))
{
self
::
register
();
self
::
set
();
}
else
{
self
::
$handler
=
array_map
(
function
(
$v
){
return
[];
},
self
::
$handler
);
}
}
/**
* 注册致命错误
* @return [type] [description]
*/
static
function
register
()
{
register_shutdown_function
(
'LogReport::fatalError'
);
}
/**
* 设置处理方法
*/
static
function
set
()
{
set_error_handler
(
'LogReport::appError'
);
set_exception_handler
(
'LogReport::exception'
);
}
/**
* 错误数据格式
* @param string|array $e 错误内容|'message','file','line','code','method'
* @param string $file 错误文件
* @param string $line 错误行数
* @param string $code 错误码
* @param string $method 错误函数
* @return [type] [description]
*/
static
function
anlyError
(
$e
,
$file
=
null
,
$line
=
null
,
$code
=
null
,
$method
=
null
)
{
if
(
!
is_array
(
$e
))
{
$e
=
[
'message'
=>
$e
,
'file'
=>
!
is_null
(
$file
)
?
$file
:
''
,
'line'
=>
!
is_null
(
$line
)
?
$line
:
''
,
'code'
=>
!
is_null
(
$code
)
?
$code
:
''
,
'method'
=>
!
is_null
(
$method
)
?
$method
:
''
,
];
}
$data
=
self
::
$data
;
$data
[
'msg'
]
=
!
empty
(
$e
[
'message'
])
?
$e
[
'message'
]
:
''
;
$data
[
'msgCode'
]
=
str_pad
(
$e
[
'code'
],
6
,
'0'
,
STR_PAD_LEFT
);
$data
[
'ts'
]
=
time
();
$data
[
'dateStr'
]
=
date
(
'Y-m-d H:i:s'
);
$data
[
'app'
]
=
REPORT_APP_NAME
;
$data
[
'serverIp'
]
=
isset
(
$_SERVER
[
'REMOTE_ADDR'
])
?
$_SERVER
[
'REMOTE_ADDR'
]
:
'0.0.0.0'
;;
$data
[
'fileName'
]
=
!
empty
(
$e
[
'file'
])
?
$e
[
'file'
]
:
''
;
$data
[
'lineNo'
]
=
!
empty
(
$e
[
'line'
])
?
$e
[
'line'
]
:
''
;
$data
[
'method'
]
=
!
empty
(
$e
[
'method'
])
?
$e
[
'method'
]
:
''
;
return
$data
;
}
/**
* 致命错误处理
* @return [type] [description]
*/
static
function
fatalError
()
{
if
(
$e
=
error_get_last
())
{
switch
(
$e
[
'type'
])
{
case
E_ERROR
:
case
E_PARSE
:
case
E_CORE_ERROR
:
case
E_COMPILE_ERROR
:
case
E_USER_ERROR
:
ob_end_clean
();
self
::
write
(
self
::
anlyError
(
$e
));
break
;
}
}
// exit();
}
/**
* 一般错误处理
* @param [type] $errno [description]
* @param [type] $errstr [description]
* @param [type] $errfile [description]
* @param [type] $errline [description]
* @return [type] [description]
*/
static
function
appError
(
$errno
,
$errstr
,
$errfile
,
$errline
)
{
switch
(
$errno
)
{
case
E_ERROR
:
case
E_PARSE
:
case
E_CORE_ERROR
:
case
E_COMPILE_ERROR
:
case
E_USER_ERROR
:
self
::
write
(
self
::
anlyError
(
$errstr
,
$errfile
,
$errline
));
break
;
}
if
(
!
empty
(
self
::
$handler
[
'finally_error'
]))
{
call_user_func
(
self
::
$handler
[
'finally_error'
],
$errno
,
$errstr
,
$errfile
,
$errline
);
}
}
/**
* 异常处理
* @return [type] [description]
*/
static
function
exception
(
$e
)
{
self
::
write
(
self
::
anlyError
(
$e
->
getMessage
()
,
$e
->
getFile
(),
$e
->
getLine
()));
if
(
!
empty
(
self
::
$handler
[
'finally_except'
]))
{
call_user_func
(
self
::
$handler
[
'finally_except'
],
$e
);
}
}
/**
* 日志记录
* @param string $log 日志内容
* @return [type] [description]
*/
static
function
write
(
$log
)
{
if
(
is_array
(
$log
))
{
$log
=
json_encode
(
$log
);
}
if
(
empty
(
$log
))
{
return
false
;
}
// 自动创建日志目录
if
(
!
is_dir
(
REPORT_LOG_PATH
))
{
mkdir
(
REPORT_LOG_PATH
,
0755
,
true
);
}
$name
=
date
(
'Ymd'
);
$filename
=
REPORT_LOG_PATH
.
$name
.
'.log'
;
//检测日志文件大小,超过配置大小则备份日志文件重新生成
if
(
is_file
(
$filename
)
&&
floor
(
LOG_FILE_SIZE
)
<=
filesize
(
$filename
))
{
rename
(
$filename
,
dirname
(
$filename
)
.
'/'
.
$name
.
'-'
.
time
()
.
'.log'
);
}
$log
.=
PHP_EOL
;
return
file_put_contents
(
$filename
,
$log
,
FILE_APPEND
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment