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
36871cc8
authored
Nov 14, 2019
by
朱继来
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
防止部分表单重复提交接口
parent
aa1960a7
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
79 additions
and
117 deletions
app/Http/Controllers/OrderController.php
app/Http/Kernel.php
app/Http/Middleware/Check.php
app/Http/Middleware/CheckRequest.php
config/config.php
public/js/order.js
app/Http/Controllers/OrderController.php
View file @
36871cc8
...
...
@@ -814,7 +814,7 @@ Class OrderController extends Controller
$order_id
=
$request
->
input
(
'order_id'
,
''
);
if
(
!
$order_id
)
return
array
(
'errcode'
=>
Error
::
E_PARAM
,
'errmsg'
=>
'订单参数有误!'
);
dump
(
'xxxx'
);
if
(
!
$request
->
input
(
'pay_time_limit'
))
{
$payTime
=
$request
->
input
(
'payTime'
,
''
);
$payTimeOther
=
$request
->
input
(
'payTimeOther'
,
''
);
...
...
@@ -823,43 +823,43 @@ dump('xxxx');
}
else
{
$pay_time_limit
=
$request
->
input
(
'pay_time_limit'
);
}
return
[
'err_code'
=>
1
,
'err_msg'
=>
'xxx'
];
//
$url = Config('website.api_domain').'order/changeOrder';
//
$check['k1'] = time();
//
$check['k2'] = md5(md5($check['k1']).'fh6y5t4rr351d2c3bryi');
//
$client_source = $request->input('client_source') == 1 ? $request->input('input-other-source') : $request->input('client_source');
//
$resData = [
//
"user_id" => $request->input('user_id', ''),
//
"cancel_reason" => $request->input('cancel_reason', ''),
//
"sale_id" => $request->input('sale_id', ''),
//
"order_pay_type" => $request->input('order_pay_type', '') ? $request->input('order_pay_type') : 1,
//
"status" => $request->input('order_status', '') ? $request->input('order_status') : 2,
//
"deposit_amount" => $request->input('deposit_amount', ''),
//
"goods_amount" => $request->input('goods_amount', ''),
//
"order_amount" => $request->input('order_amount', ''),
//
"extra_fee" => $request->input('extra_fee', ''),
//
"change_info" => $request->input('change_info', ''),
//
"pay_time_limit" => $pay_time_limit,
//
"check_failed" => $request->input('check_failed', ''),
//
"check_failed_info" => $request->input('check_failed_info', ''),
//
"change_pay_type" => $request->input('change_pay_type', ''),
//
"order_id" => $order_id,
//
'operator_id' => $request->user->userId,
//
"pf" => 1,
//
"k1" => $check['k1'],
//
"k2" => $check['k2'],
//
"client_source" => $client_source,
//
"change_extend_fee" => $request->input('change_extend_fee', ''),
//
"kefu_remark" => $request->input('kefu_remark', ''), // 客服备注
//
"freight_fee" => $request->input('freight_fee', ''), // 运费
//
];
//
//
dd(curlApi($url, $resData, "POST"));
//
$temp = json_decode(curlApi($url, $resData, "POST"), true);
//
return array('errcode'=>$temp['err_code'],'errmsg'=>$temp['err_msg']);
$url
=
Config
(
'website.api_domain'
)
.
'order/changeOrder'
;
$check
[
'k1'
]
=
time
();
$check
[
'k2'
]
=
md5
(
md5
(
$check
[
'k1'
])
.
'fh6y5t4rr351d2c3bryi'
);
$client_source
=
$request
->
input
(
'client_source'
)
==
1
?
$request
->
input
(
'input-other-source'
)
:
$request
->
input
(
'client_source'
);
$resData
=
[
"user_id"
=>
$request
->
input
(
'user_id'
,
''
),
"cancel_reason"
=>
$request
->
input
(
'cancel_reason'
,
''
),
"sale_id"
=>
$request
->
input
(
'sale_id'
,
''
),
"order_pay_type"
=>
$request
->
input
(
'order_pay_type'
,
''
)
?
$request
->
input
(
'order_pay_type'
)
:
1
,
"status"
=>
$request
->
input
(
'order_status'
,
''
)
?
$request
->
input
(
'order_status'
)
:
2
,
"deposit_amount"
=>
$request
->
input
(
'deposit_amount'
,
''
),
"goods_amount"
=>
$request
->
input
(
'goods_amount'
,
''
),
"order_amount"
=>
$request
->
input
(
'order_amount'
,
''
),
"extra_fee"
=>
$request
->
input
(
'extra_fee'
,
''
),
"change_info"
=>
$request
->
input
(
'change_info'
,
''
),
"pay_time_limit"
=>
$pay_time_limit
,
"check_failed"
=>
$request
->
input
(
'check_failed'
,
''
),
"check_failed_info"
=>
$request
->
input
(
'check_failed_info'
,
''
),
"change_pay_type"
=>
$request
->
input
(
'change_pay_type'
,
''
),
"order_id"
=>
$order_id
,
'operator_id'
=>
$request
->
user
->
userId
,
"pf"
=>
1
,
"k1"
=>
$check
[
'k1'
],
"k2"
=>
$check
[
'k2'
],
"client_source"
=>
$client_source
,
"change_extend_fee"
=>
$request
->
input
(
'change_extend_fee'
,
''
),
"kefu_remark"
=>
$request
->
input
(
'kefu_remark'
,
''
),
// 客服备注
"freight_fee"
=>
$request
->
input
(
'freight_fee'
,
''
),
// 运费
];
// dd(curlApi($url, $resData, "POST"));
$temp
=
json_decode
(
curlApi
(
$url
,
$resData
,
"POST"
),
true
);
return
array
(
'errcode'
=>
$temp
[
'err_code'
],
'errmsg'
=>
$temp
[
'err_msg'
]);
}
}
...
...
app/Http/Kernel.php
View file @
36871cc8
...
...
@@ -28,7 +28,6 @@ class Kernel extends HttpKernel
\App\Http\Middleware\CheckLogin
::
class
,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse
::
class
,
\Illuminate\Session\Middleware\StartSession
::
class
,
\App\Http\Middleware\Check
::
class
,
\App\Http\Middleware\CheckRequest
::
class
,
],
...
...
app/Http/Middleware/Check.php
deleted
100644 → 0
View file @
aa1960a7
<?php
namespace
App\Http\Middleware
;
use
Closure
;
use
Session
;
class
Check
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public
function
handle
(
$request
,
Closure
$next
)
{
Session
::
put
(
'pid'
,
uniqid
(
'order_'
,
true
));
// if ($request->ajax() && $request->isMethod('post')) {
// }
return
$next
(
$request
);
}
}
app/Http/Middleware/CheckRequest.php
View file @
36871cc8
...
...
@@ -4,13 +4,9 @@ namespace App\Http\Middleware;
use
Closure
;
use
Illuminate\Support\Facades\Redis
;
use
Cookie
;
use
Session
;
class
CheckRequest
{
static
public
$redis
;
/**
* Handle an incoming request.
*
...
...
@@ -20,56 +16,37 @@ class CheckRequest
*/
public
function
handle
(
$request
,
Closure
$next
)
{
// 对AJAX POST请求添加Redis锁,防止重复提交
if
(
$request
->
ajax
()
&&
$request
->
isMethod
(
'post'
))
{
$key
=
$this
->
getFormKey
(
$request
);
$action
=
$request
->
route
()
->
getAction
();
// 获取路由信息
$routeActionName
=
''
;
// if (!self::$redis) self::$redis = new Redis;
Redis
::
incr
(
$key
);
// 计数器
$count
=
Redis
::
get
(
$key
);
$pid
=
Session
::
get
(
'pid'
);
dump
(
$count
);
if
(
$count
>
1
)
return
abort
(
501
,
'请勿重新提交!'
);
// 501服务器不支持当前请求
if
(
isset
(
$action
[
'controller'
]))
{
$controller
=
class_basename
(
$action
[
'controller'
]);
list
(
$routeControllerName
,
$routeActionName
)
=
explode
(
'@'
,
$controller
);
}
// $lock = Redis::setnx('lock'.Cookie::get('uuid'), 1);
// $count = Redis::setnx(Cookie::get('uuid'),1);
// if(!$count) return abort(501, '请勿重新提交!');
// $lock = Redis::set('lock'.Cookie::get('uuid'), 1, "nx", "ex", 300);
// Redis::sadd("kkkkkk",'lock'.Cookie::get('uuid'));
// dump($lock);
// if (!$lock ) {
// Redis::del('lock'.Cookie::get('uuid'));
// return abort(501, '请勿重新提交!');
// }
$response
=
$next
(
$request
);
$prevent_resubmit
=
Config
(
'config.prevent_resubmit_api'
);
// 防止重复提交接口
// Redis::del('lock'.Cookie::get('uuid'));
// Redis::del($key);
// 对AJAX POST请求添加Redis锁,防止重复提交
if
(
in_array
(
$routeActionName
,
$prevent_resubmit
)
&&
$request
->
ajax
()
&&
$request
->
isMethod
(
'post'
))
{
$referer
=
$_SERVER
[
'HTTP_REFERER'
];
// 来源页面
$sale_id
=
$request
->
user
->
userId
;
// 操作人ID
$key
=
$routeActionName
.
'_'
.
md5
(
$referer
.
'/'
.
$sale_id
);
// 设置表单页面key
// Redis::incr($key); // 计数器
// $count = Redis::get($key);
return
$response
;
}
// if ($count > 1) return abort(501, '请勿重新提交!'); // 501服务器不支持当前请求
return
$next
(
$request
);
}
$lock
=
Redis
::
set
(
$key
,
1
,
"nx"
,
"ex"
,
5
);
// 5秒内重复点击提交按钮无效
public
function
getFormKey
(
$request
)
{
$action
=
$request
->
route
()
->
getAction
();
// 获取路由信息
$controller
=
'@'
;
if
(
!
$lock
)
return
abort
(
501
,
'请勿重新提交!'
);
if
(
isset
(
$action
[
'controller'
]))
{
$controller
=
class_basename
(
$action
[
'controller'
]);
}
list
(
$routeControllerName
,
$routeActionName
)
=
explode
(
'@'
,
$controller
);
$response
=
$next
(
$request
);
$referer
=
$_SERVER
[
'HTTP_REFERER'
];
// 来源页面
$sale_id
=
$request
->
user
->
userId
;
// 操作人ID
$key
=
$routeActionName
.
'_'
.
md5
(
$referer
.
'/'
.
$sale_id
);
return
$response
;
}
return
$
key
;
return
$
next
(
$request
)
;
}
}
config/config.php
0 → 100644
View file @
36871cc8
<?php
return
[
// 接口防重复提交
'prevent_resubmit_api'
=>
[
'ajaxSaveChange'
,
// 审单
'changeShipping'
,
// 修改物流地址
'changeInvoice'
,
// 修改发票
'express_set'
,
// 设置快递费用
'addCart'
,
// 添加到购物车
'changeNum'
,
// 修改数量
'create'
,
// 生成订单
'addGoods'
,
// 新增商品
'orderReturn'
,
// 订单退货
'orderReturnEdit'
,
// 订单退货编辑
],
];
public/js/order.js
View file @
36871cc8
...
...
@@ -1966,7 +1966,7 @@
}
})
//
layer.msg('审核提交中...', {icon: 16, time: 0, shade: 0.3}); // 阻止重复提交
layer
.
msg
(
'审核提交中...'
,
{
icon
:
16
,
time
:
0
,
shade
:
0.3
});
// 阻止重复提交
},
btn2
:
function
(
index
,
layero
){
layer
.
close
(
index
);
...
...
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