Commit f7d0c024 by 朱继来

temp2

parent 7cfa8a62
......@@ -13,87 +13,4 @@ use Symfony\Component\HttpKernel\Exception\HttpException;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
/**
* 防止表单重复提交的key前缀
* @var string
*/
private $formResubmitPrefix = 'f_';
/**
* 将key加个前缀
* @param unknown $key
* @return string
*/
private function formResubmitKeyProcess($key)
{
if (empty($key)) {
$route = Route::current()->getActionName();
$action_name = explode('@', $route)[1];
return $this->formResubmitPrefix.$action_name.'_'.md5(microtime(true)); //默认使用当前方法名为key
} else {
return $this->formResubmitPrefix.$key.'_'.md5(microtime(true));
}
}
/**
* 在初始化表单前调用
* @param unknown $key
*/
protected function formInit($key = null)
{
$key = $this->formResubmitKeyProcess($key);
dd($key);
Session::put($key, time());
}
/**
* 在处理表单提交的方法中调用
* @param string $message
* @param unknown $key
* @throws HttpException
*/
protected function formSubmited($key = null, string $message = '请忽重复提交!')
{
$key = $this->formResubmitKeyProcess($key);
if (Session::has($key) && Session::get($key) !== null) {
Session::forget($key);
} else {
throw new HttpException(403, $message);
}
}
/**
* 在处理表单提交的方法中调用,该方法方便自定义重复提交时的提示页面,可以在子类中if判断一下,如果发生重复提交,响应自定义的界面
* @param string $message
* @param unknown $key
*/
protected function formSubmitIsRepetition($key = null, string $message = '请勿重复提交!')
{
$key = $this->formResubmitKeyProcess($key);
if (Session::has($key)) {
Session::forget($key);
return false;
} else {
return response()->view('errors.403', ['message'=>$message], 403);
}
}
/**
* 该方法用于ajax请求,返回的数据是数组
* @param string $message
* @param unknown $key
*/
protected function formSubmitedForAjax($key = null, string $message = '请勿重复提交!')
{
$key = $this->formResubmitKeyProcess($key);
if (Session::has($key)) {
Session::forget($key);
return false;
} else {
return ['result'=>'fail','message'=>$message];
}
}
}
......@@ -798,11 +798,8 @@ Class OrderController extends Controller
if($request->isMethod('post')){
$order_id = $request->input('order_id', '');
if (!$order_id) {
errorLog(Error::E_PARAM, '订单参数有误');
return array('errcode'=>Error::E_PARAM, 'errmsg'=>'订单参数有误!');
}
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', '');
......@@ -811,43 +808,43 @@ Class OrderController extends Controller
} else {
$pay_time_limit = $request->input('pay_time_limit');
}
$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']);
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']);
}
}
......@@ -877,32 +874,31 @@ Class OrderController extends Controller
public function sendSales(Request $request, $id='')
{
if ($request->isMethod('post')) {
$form_token = $request->input('form_token', '');
$order_id = $request->input('order_id', '');
$sale_id = $request->input('sale_id', '');
$send_remark = $request->input('send_remark', '');
$operator_id = $request->user->userId;
if (empty($order_id) || empty($sale_id)) {
errorLog(Error::E_NOT_EXISTS, '参数不存在');
return array('errcode'=>Error::E_NOT_EXISTS, 'errmsg'=>'参数不存在');
}
if (!$form_token || !$order_id || !$sale_id) return ['errcode'=>Error::E_NOT_EXISTS, 'errmsg'=>'参数不存在'];
$res = validFormToken($form_token);
if ($res === false) return ['errcode'=>Error::E_FORM_RESUBMIT, 'errmsg'=>'请勿重复提交'];
$res = $this->formSubmited('sendsales');
dump(Session::get('f_sendsales'));
dd($res);
$url = Config('website.api_domain').'order/sendSales';
$check['k1'] = time();
$check['k2'] = md5(md5($check['k1']).'fh6y5t4rr351d2c3bryi');
$resData = array(
"order_id"=>$order_id,
"sale_id"=>$sale_id,
'operator_id'=>$operator_id,
'send_remark'=>$send_remark,
"pf"=>1,
"k1"=>$check['k1'],
"k2"=>$check['k2']
"order_id" => $order_id,
"sale_id" => $sale_id,
'operator_id' => $operator_id,
'send_remark' => $send_remark,
"pf" => 1,
"k1" => $check['k1'],
"k2" => $check['k2']
);
$temp = json_decode(curlApi($url, $resData, "POST"), true);
......@@ -910,8 +906,6 @@ dd($res);
return array('errcode'=>$temp['err_code'],'errmsg'=>$temp['err_msg']);
}
$this->formInit('sendsales');
dump(Session::get('f_sendsales'));
$info = $this->orderDetail($request, $id);
$this->pageHeader($request, $info, '推送业务员', ["title" => '推送业务员', "href" => '#']);
......
......@@ -19,4 +19,5 @@ class Error
const E_UPDATE_FAILED = -10012; // 更新失败
const E_IMPORT_TEMP_ERR = -10013; // 导入模板错误
const E_IMPORT_VALID_FAILED = -10014; // 导入验证失败
const E_FORM_RESUBMIT = -10015; // 表单重复提交
};
<?php
/** 公用函数 */
use Illuminate\Support\Facades\Redis;
//导出数据
//导出数据
......@@ -407,3 +408,40 @@ function Autograph(){
UploadImgUrl="'.$url.'"
</script>';
}
/**
* 生成表单token
* @param [type] $key [表单名,默认为空]
* @param string $prefix [项目名]
* @return [type] [token]
*/
// function getFormToken($key = null, $prefix='order_')
// {
// if (empty($key)) {
// $token = $prefix.md5(microtime(true).rand(10000, 99999));
// } else {
// $token = $prefix.$key.'_'.md5(microtime(true).rand(10000, 99999));
// }
// // Session::put($token, $token); // 连续点击按钮,并发快的情况下,session里的token删除不及时,会导致多次并发请求
// Redis::setex($token, 3600, $token); // 缓存一小时
// return $token;
// }
// // 验证表单token,防止重复提交
// function validFormToken($token)
// {
// $lock = Redis::set("lock", 1, "nx", "ex", 10);
// if (Redis::connection('read')->get($token) != $token || !$lock) return false;
// Redis::del($token);
// Redis::del("lock");
// return true;
// // if (Session::get($token) != $token) return false;
// // Session::forget($token); // 验证完毕后删除token
// // return true;
// }
\ No newline at end of file
......@@ -27,7 +27,8 @@ class Kernel extends HttpKernel
\App\Http\Middleware\JsonpCallback::class,
\App\Http\Middleware\CheckLogin::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class
\Illuminate\Session\Middleware\StartSession::class,
\App\Http\Middleware\CheckRequest::class,
],
'api' => [
......
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Redis;
use Cookie;
class CheckRequest
{
static public $redis;
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
// 对AJAX POST请求添加Redis锁,防止重复提交
if ($request->ajax() && $request->isMethod('post')) {
$key = $this->getFormKey($request);
// if (!self::$redis) self::$redis = new Redis;
Redis::incr($key); // 计数器
$count = Redis::get($key);
dump($count);
if ($count > 1) return abort(501, '请勿重新提交!'); // 501服务器不支持当前请求
// $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);
// Redis::del('lock'.Cookie::get('uuid'));
// Redis::del($key);
return $response;
}
return $next($request);
}
public function terminate($request, $response)
{
$key = $this->getFormKey($request);
dump('响应信息');
// Redis::del($key);
}
public function getFormKey($request)
{
$action = $request->route()->getAction(); // 获取路由信息
$controller = '@';
if (isset($action['controller'])) {
$controller = class_basename($action['controller']);
}
list($routeControllerName, $routeActionName) = explode('@', $controller);
$referer = $_SERVER['HTTP_REFERER']; // 来源页面
$sale_id = $request->user->userId; // 操作人ID
$key = $routeActionName.'_'.md5($referer.'/'.$sale_id);
return $key;
}
}
......@@ -1397,6 +1397,8 @@
console.log(res);
}
})
layer.msg('订单推送中...', {icon: 16, time: 0, shade: 0.3}); // 阻止重复提交
},
btn2: function(index, layero){
layer.close(index);
......@@ -1953,7 +1955,9 @@
location.href = url;
}, 1000);
} else {
layer.alert(resp.errmsg || '网络异常');
layer.alert(resp.errmsg || '网络异常', function() {
location.reload();
});
}
},
......@@ -1962,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);
......
......@@ -6,7 +6,8 @@
@endif
<form id="sendSalesForm" class="form-horizontal table-responsive">
<input type="hidden" name="order_id" value="{{$order_info['order_id']}}">
<input type="hidden" name="form_token" value="{{ getFormToken('sendsales') }}">
<input type="hidden" name="order_id" value="{{ $order_info['order_id'] }}">
<table class="table table-bordered table-hover check-table" style="min-height:150px;">
@if (!empty($joint_manager))
......
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>订单系统 | 501 Error</title>
<link href="/css/bootstrap.min.css" rel="stylesheet">
<link href="/font-awesome/css/font-awesome.css" rel="stylesheet">
<link href="/css/animate.css" rel="stylesheet">
<link href="/css/style.css" rel="stylesheet">
</head>
<body class="gray-bg">
<div class="middle-box text-center animated fadeInDown">
<h1>501</h1>
<h3 class="font-bold">{{ $exception->getMessage() }}</h3>
</div>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment