|
@@ -52,19 +52,25 @@ class DynamicController extends Controller
|
|
DB::beginTransaction();
|
|
DB::beginTransaction();
|
|
try {
|
|
try {
|
|
$user = auth('api')->user();
|
|
$user = auth('api')->user();
|
|
- $dynamicParam = new DynamicParam();
|
|
|
|
- $dynamicParam->user_id = $user->id;
|
|
|
|
- $dynamicParam->content = htmlspecialchars($request->post('content'));
|
|
|
|
- $dynamicParam->img_url = $request->post('img_url');
|
|
|
|
- $dynamicParam->type = $request->post('type');
|
|
|
|
- $dynamicParam->status = 1;
|
|
|
|
- $dynamicParam->zan_num = 0;
|
|
|
|
- $dynamicParam->tag = $request->post('tag');
|
|
|
|
- $dynamicParam->city = $request->post('city');
|
|
|
|
- $dynamicParam->latitude = $request->post('latitude');
|
|
|
|
- $dynamicParam->longitude = $request->post('longitude');
|
|
|
|
- $this->dynamicService->release($dynamicParam);
|
|
|
|
- DB::commit();
|
|
|
|
|
|
+ $lock = Cache::lock('dynamic-release'.$user->id, 1);
|
|
|
|
+ if ($lock->get()) {
|
|
|
|
+ $dynamicParam = new DynamicParam();
|
|
|
|
+ $dynamicParam->user_id = $user->id;
|
|
|
|
+ $dynamicParam->content = htmlspecialchars($request->post('content'));
|
|
|
|
+ $dynamicParam->img_url = $request->post('img_url');
|
|
|
|
+ $dynamicParam->type = $request->post('type');
|
|
|
|
+ $dynamicParam->status = 1;
|
|
|
|
+ $dynamicParam->zan_num = 0;
|
|
|
|
+ $dynamicParam->tag = $request->post('tag');
|
|
|
|
+ $dynamicParam->city = $request->post('city');
|
|
|
|
+ $dynamicParam->latitude = $request->post('latitude');
|
|
|
|
+ $dynamicParam->longitude = $request->post('longitude');
|
|
|
|
+ $this->dynamicService->release($dynamicParam);
|
|
|
|
+ DB::commit();
|
|
|
|
+ $lock->release();
|
|
|
|
+ }else{
|
|
|
|
+ throw new Exception("请求太频繁");
|
|
|
|
+ }
|
|
}catch (\Exception $exception){
|
|
}catch (\Exception $exception){
|
|
DB::rollBack();
|
|
DB::rollBack();
|
|
return $this->response->errorForbidden($exception->getMessage());
|
|
return $this->response->errorForbidden($exception->getMessage());
|