OMEGA\ericyh.huang před 1 rokem
rodič
revize
e08da1303d

+ 22
- 3
app/Http/Controllers/HealthyPassPortController.php Zobrazit soubor

@@ -13,6 +13,7 @@ use Illuminate\Support\Facades\Storage;
13 13
 class HealthyPassPortController extends Controller
14 14
 {
15 15
     private $api_header = array();
16
+    private $tag_set = array();
16 17
 
17 18
     public function __construct()
18 19
     {
@@ -27,7 +28,7 @@ class HealthyPassPortController extends Controller
27 28
 
28 29
     public function profile(Request $request){
29 30
         $profile = Survey::where('line_user_id',$request->lineUserId)->first();
30
-        $profile_tag_list = $profile->getTagList();
31
+        return response()->json(["data" => $profile] );
31 32
     }
32 33
 
33 34
     /**
@@ -46,7 +47,17 @@ class HealthyPassPortController extends Controller
46 47
         $healthNickname = $request->healthNickname; //暱稱
47 48
         $healthGender = $request->healthGender; //性別
48 49
         $healthGenderRole = $request->healthGenderRole;//性別 male or female
49
-
50
+        
51
+        $survey_fill_content = ["healthAction" => $healthAction, 
52
+                                "healthTopic" => $healthTopic,
53
+                                "healthStatus" => $healthStatus,
54
+                                "healthAdapt" => $healthAdapt,
55
+                                "healthThought" => $healthThought,
56
+                                "healthAge" => $healthAge,
57
+                                "healthGender" => $healthGender,
58
+        ];
59
+        
60
+        //準備將填寫內容過API寫入 botbonnie 後台
50 61
         $buildActions = [];
51 62
         array_push($buildActions, $this->buildActionsRequest("addTag", $healthAction));
52 63
         array_push($buildActions, $this->buildActionsRequest("addTag", $healthTopic));
@@ -55,7 +66,7 @@ class HealthyPassPortController extends Controller
55 66
         array_push($buildActions, $this->buildActionsRequest("addTag", $healthThought));
56 67
         array_push($buildActions, $this->buildActionsRequest("addTag", $healthAge));
57 68
         array_push($buildActions, $this->buildActionsRequest("addTag", $healthGender));
58
-        if($healthGenderRole != "")array_push($buildActions, $this->buildActionsRequest("saveParams", $healthGenderRole, "demographics", "gender"));
69
+        if($healthGenderRole != "")array_push($buildActions, $this->buildActionsRequest("saveParams", $healthGenderRole, "demographics", "gender"));       
59 70
 
60 71
         $statusCode = $this->botActionsSend($lineUserId,$buildActions);
61 72
         if($statusCode == 200){
@@ -64,6 +75,14 @@ class HealthyPassPortController extends Controller
64 75
             array_push($buildActions, $this->buildActionsRequest("addTag", config("botApi.doneSurvey")));
65 76
             array_push($buildActions, $this->buildActionsRequest("setMenu", config("botApi.setMenuDoneSurvey")));
66 77
             $this->botActionsSend($lineUserId,$buildActions);
78
+
79
+            //儲存填寫資料
80
+            $survey_data = new Survey();
81
+            $survey_data->line_user_id = $lineUserId;
82
+            $survey_data->head_sticker = $headSticker;
83
+            $survey_data->nickname = $healthNickname;
84
+            $survey_data->filler_content = json_encode($survey_fill_content);
85
+            $survey_data->save();
67 86
             return  response()->json(["result" => 'successed']);
68 87
         }else{
69 88
             return response()->json(["result" => 'failed'] );

+ 5
- 0
app/Models/Survey.php Zobrazit soubor

@@ -4,8 +4,13 @@ namespace App\Models;
4 4
 
5 5
 use Illuminate\Database\Eloquent\Factories\HasFactory;
6 6
 use Illuminate\Database\Eloquent\Model;
7
+use App\Models\SurveyHaveTag;
7 8
 
8 9
 class Survey extends Model
9 10
 {
10 11
     use HasFactory;
12
+
13
+    public function tags(){
14
+        return $this->belongsToMany(Tag::class);
15
+    }
11 16
 }

+ 2
- 0
app/Models/SurveyHaveTag.php Zobrazit soubor

@@ -4,6 +4,8 @@ namespace App\Models;
4 4
 
5 5
 use Illuminate\Database\Eloquent\Factories\HasFactory;
6 6
 use Illuminate\Database\Eloquent\Model;
7
+use App\Models\Tag;
8
+use App\Models\Survey;
7 9
 
8 10
 class SurveyHaveTag extends Model
9 11
 {

+ 6
- 0
app/Models/Tag.php Zobrazit soubor

@@ -4,8 +4,14 @@ namespace App\Models;
4 4
 
5 5
 use Illuminate\Database\Eloquent\Factories\HasFactory;
6 6
 use Illuminate\Database\Eloquent\Model;
7
+use App\Models\Survey;
7 8
 
8 9
 class Tag extends Model
9 10
 {
10 11
     use HasFactory;
12
+
13
+
14
+    public function survey(){
15
+        return $this->belongsToMany(Survey::class);
16
+    }
11 17
 }

+ 0
- 1
database/migrations/2023_09_27_035029_create_survey_have_tags_table.php Zobrazit soubor

@@ -15,7 +15,6 @@ return new class extends Migration
15 15
             $table->increments('id')->comment('PKey');
16 16
             $table->string("survey_id")->comment("填寫問卷ID");
17 17
             $table->string("tag_id")->comment("擁有標籤ID");
18
-            $table->string("bot_tag_id")->comment('bot 標籤ID');
19 18
             $table->timestamps();
20 19
         });
21 20
     }

+ 2
- 1
database/migrations/2023_09_27_035029_create_surveys_table.php Zobrazit soubor

@@ -15,7 +15,8 @@ return new class extends Migration
15 15
             $table->increments('id')->comment('PKey');
16 16
             $table->string("line_user_id")->comment("填寫人Line UID");
17 17
             $table->string("head_sticker")->comment("填寫人頭貼");
18
-            $table->json("fillter_content")->comment("問卷填寫內容");
18
+            $table->string("nickname")->comment("暱稱");
19
+            $table->string("filler_content")->comment("問卷填寫內容");
19 20
             $table->timestamps();
20 21
         });
21 22
     }

+ 28
- 0
database/migrations/2023_09_27_035205_create_tag_categories_table.php Zobrazit soubor

@@ -0,0 +1,28 @@
1
+<?php
2
+
3
+use Illuminate\Database\Migrations\Migration;
4
+use Illuminate\Database\Schema\Blueprint;
5
+use Illuminate\Support\Facades\Schema;
6
+
7
+return new class extends Migration
8
+{
9
+    /**
10
+     * Run the migrations.
11
+     */
12
+    public function up(): void
13
+    {
14
+        Schema::create('tag_categories', function (Blueprint $table) {
15
+            $table->increments('id')->comment('PKey');
16
+            $table->string("name")->comment('分類名稱');
17
+            $table->timestamps();
18
+        });
19
+    }
20
+
21
+    /**
22
+     * Reverse the migrations.
23
+     */
24
+    public function down(): void
25
+    {
26
+        Schema::dropIfExists('tags');
27
+    }
28
+};

+ 1
- 0
database/migrations/2023_09_27_035205_create_tags_table.php Zobrazit soubor

@@ -13,6 +13,7 @@ return new class extends Migration
13 13
     {
14 14
         Schema::create('tags', function (Blueprint $table) {
15 15
             $table->increments('id')->comment('PKey');
16
+            $table->int('tag_category_id')->comment('標籤分類');
16 17
             $table->string("bot_tag_id")->comment('bot 標籤ID');
17 18
             $table->string("tag_name")->comment('標籤名稱');
18 19
             $table->timestamps();