正在显示
1 个修改的文件
包含
11 行增加
和
3 行删除
| @@ -14,6 +14,7 @@ use App\Http\Logic\Bside\BaseLogic; | @@ -14,6 +14,7 @@ use App\Http\Logic\Bside\BaseLogic; | ||
| 14 | use App\Models\GoogleKeywordInsight\GoogleKeywordInsight; | 14 | use App\Models\GoogleKeywordInsight\GoogleKeywordInsight; |
| 15 | use App\Models\GoogleKeywordInsight\GoogleKeywordInsightDetail; | 15 | use App\Models\GoogleKeywordInsight\GoogleKeywordInsightDetail; |
| 16 | use App\Services\GoogleKeywordInsightService; | 16 | use App\Services\GoogleKeywordInsightService; |
| 17 | +use Illuminate\Support\Facades\DB; | ||
| 17 | 18 | ||
| 18 | class GoogleKeywordInsightLogic extends BaseLogic | 19 | class GoogleKeywordInsightLogic extends BaseLogic |
| 19 | { | 20 | { |
| @@ -39,10 +40,17 @@ class GoogleKeywordInsightLogic extends BaseLogic | @@ -39,10 +40,17 @@ class GoogleKeywordInsightLogic extends BaseLogic | ||
| 39 | $this->service = new GoogleKeywordInsightService(); | 40 | $this->service = new GoogleKeywordInsightService(); |
| 40 | $data = $this->service->requestUrl($this->param['keyword']); | 41 | $data = $this->service->requestUrl($this->param['keyword']); |
| 41 | if(!empty($data)){ | 42 | if(!empty($data)){ |
| 43 | + DB::beginTransaction(); | ||
| 42 | //保存数据库 | 44 | //保存数据库 |
| 43 | - $detailModel = new GoogleKeywordInsightDetail(); | ||
| 44 | - $this->model->saveInsight($this->user['project_id'],$this->param['keyword'],$data); | ||
| 45 | - $detailModel->saveInsightDetail($this->user['project_id'],$this->param['keyword'],$data); | 45 | + try { |
| 46 | + $detailModel = new GoogleKeywordInsightDetail(); | ||
| 47 | + $this->model->saveInsight($this->user['project_id'],$this->param['keyword'],$data); | ||
| 48 | + $detailModel->saveInsightDetail($this->user['project_id'],$this->param['keyword'],$data); | ||
| 49 | + DB::commit(); | ||
| 50 | + }catch (\Exception $e){ | ||
| 51 | + DB::rollBack(); | ||
| 52 | + $this->fail('保存失败,请联系管理员'); | ||
| 53 | + } | ||
| 46 | } | 54 | } |
| 47 | } | 55 | } |
| 48 | return $this->success($data); | 56 | return $this->success($data); |
-
请 注册 或 登录 后发表评论