add-api-sign_cache
This commit is contained in:
@@ -91,6 +91,7 @@ class Contract extends Wxapp{
|
||||
}
|
||||
|
||||
protected function post(){
|
||||
$uid = $this->session['uid'];
|
||||
$id = $this->input_param('id');
|
||||
$type = $this->input_param('type');
|
||||
$img = $this->input_param('img');
|
||||
@@ -101,6 +102,7 @@ class Contract extends Wxapp{
|
||||
if(!$row['file'] || !$img){
|
||||
throw new Exception('参数错误', API_CODE_INVILD_PARAM);
|
||||
}
|
||||
|
||||
if($row['status']==1){
|
||||
throw new Exception('已签名', API_CODE_INVILD_PARAM);
|
||||
}
|
||||
@@ -124,6 +126,13 @@ class Contract extends Wxapp{
|
||||
throw new Exception('签名失败,图片转换失败', API_CODE_INVILD_PARAM);
|
||||
}
|
||||
|
||||
$redis = load_cache('redis');
|
||||
$cache_key = "CONTRACT_{$id}_{$uid}_{$type}";
|
||||
if($redis->get($cache_key)){
|
||||
throw new Exception('请求太频繁,请刷新查看结果', API_CODE_INVILD_PARAM);
|
||||
}
|
||||
$redis->save($cache_key,1,60*1);
|
||||
|
||||
$this->load->library('receiver/sign_entity');
|
||||
$sign_entity = new Sign_entity(['comp_img'=>$img_seal]);
|
||||
switch($type){
|
||||
@@ -143,6 +152,7 @@ class Contract extends Wxapp{
|
||||
];
|
||||
$result = $this->contracts_model->update($update,['id'=>$row['id']]);
|
||||
if($result){
|
||||
$redis->delete($cache_key);
|
||||
throw new Exception('签名成功', API_CODE_SUCCESS);
|
||||
}else{
|
||||
throw new Exception('签名失败', API_CODE_INVILD_PARAM);
|
||||
@@ -169,6 +179,7 @@ class Contract extends Wxapp{
|
||||
if($result){
|
||||
$this->load->library('receiver/orders_entity');
|
||||
$this->orders_entity->sign_after($id,$this->app_id,$this->session);
|
||||
$redis->delete($cache_key);
|
||||
throw new Exception('签名成功', API_CODE_SUCCESS);
|
||||
}else{
|
||||
throw new Exception('签名失败', API_CODE_INVILD_PARAM);
|
||||
@@ -194,6 +205,7 @@ class Contract extends Wxapp{
|
||||
//生成支付订单
|
||||
$this->load->library('receiver/orders_entity');
|
||||
$this->orders_entity->check_finish($id,$this->app_id,$this->session);
|
||||
$redis->delete($cache_key);
|
||||
throw new Exception('签名成功', API_CODE_SUCCESS);
|
||||
}else{
|
||||
throw new Exception('签名失败', API_CODE_INVILD_PARAM);
|
||||
@@ -216,12 +228,14 @@ class Contract extends Wxapp{
|
||||
$result = $this->contracts_model->update($update,['id'=>$row['id']]);
|
||||
if($result){
|
||||
$this->deliverys_model->update(['status'=>1],['o_id'=>$id]);
|
||||
$redis->delete($cache_key);
|
||||
throw new Exception('签名成功', API_CODE_SUCCESS);
|
||||
}else{
|
||||
throw new Exception('签名失败', API_CODE_INVILD_PARAM);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$redis->delete($cache_key);
|
||||
throw new Exception('未知签名类型', API_CODE_INVILD_PARAM);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user