Browse Source

add task exception 新增任务异常捕获

fly 4 years ago
parent
commit
e1419d6027
1 changed files with 12 additions and 7 deletions
  1. 12 7
      app/Modules/UserTask/Services/SingleTask.php

+ 12 - 7
app/Modules/UserTask/Services/SingleTask.php

@@ -3,6 +3,7 @@
 namespace App\Modules\UserTask\Services;
 
 use App\Modules\UserTask\Models\UserTask;
+use Exception;
 
 /**
  * 单次任务
@@ -16,13 +17,17 @@ class SingleTask extends BaseTask
 
     public function addUserTask()
     {
-        UserTask::create([
-            'uid' => $this->uid,
-            'task_id' => $this->task->id,
-            'status' => self::up_status,
-            'type' => $this->task->reward_type,
-            'value' => $this->task->value,
-        ]);
+        try {
+            UserTask::create([
+                'uid' => $this->uid,
+                'task_id' => $this->task->id,
+                'status' => self::up_status,
+                'type' => $this->task->reward_type,
+                'value' => $this->task->value,
+            ]);
+        } catch (Exception $e) {
+            myLog('add_task')->error($e->getMessage());
+        }
     }
 
     public function findUserTask(int $status)