Pārlūkot izejas kodu

Merge branch 'master' of https://git.cecmartech.com/DC/Moderna-Survey

Sherry 2 gadus atpakaļ
vecāks
revīzija
4e264d4c6c

+ 41
- 6
src/be/app/Http/Controllers/HealthyPassPortController.php Parādīt failu

55
         $healthNickname = $request->healthNickname; //暱稱
55
         $healthNickname = $request->healthNickname; //暱稱
56
         $healthGender = $request->healthGender; //性別
56
         $healthGender = $request->healthGender; //性別
57
         $healthGenderRole = $request->healthGenderRole;//性別 male or female
57
         $healthGenderRole = $request->healthGenderRole;//性別 male or female
58
-        
59
-        $survey_fill_content = ["healthAction" => $healthAction, 
58
+
59
+        $survey_fill_content = ["healthAction" => $healthAction,
60
                                 "healthTopic" => $healthTopic,
60
                                 "healthTopic" => $healthTopic,
61
                                 "healthStatus" => $healthStatus,
61
                                 "healthStatus" => $healthStatus,
62
                                 "healthAdapt" => $healthAdapt,
62
                                 "healthAdapt" => $healthAdapt,
73
             }
73
             }
74
             $statusCode = $this->botActionsSend($lineUserId,$clearAction);
74
             $statusCode = $this->botActionsSend($lineUserId,$clearAction);
75
         }
75
         }
76
-        
76
+
77
         //準備將填寫內容過API寫入 botbonnie 後台
77
         //準備將填寫內容過API寫入 botbonnie 後台
78
         $buildActions = [];
78
         $buildActions = [];
79
         array_push($buildActions, $this->buildActionsRequest("addTag", $healthAction));
79
         array_push($buildActions, $this->buildActionsRequest("addTag", $healthAction));
83
         array_push($buildActions, $this->buildActionsRequest("addTag", $healthThought));
83
         array_push($buildActions, $this->buildActionsRequest("addTag", $healthThought));
84
         array_push($buildActions, $this->buildActionsRequest("addTag", $healthAge));
84
         array_push($buildActions, $this->buildActionsRequest("addTag", $healthAge));
85
         array_push($buildActions, $this->buildActionsRequest("addTag", $healthGender));
85
         array_push($buildActions, $this->buildActionsRequest("addTag", $healthGender));
86
-        if($healthGenderRole != "")array_push($buildActions, $this->buildActionsRequest("saveParams", $healthGenderRole, "demographics", "gender"));       
86
+        if($healthGenderRole != "")array_push($buildActions, $this->buildActionsRequest("saveParams", $healthGenderRole, "demographics", "gender"));
87
 
87
 
88
         $statusCode = $this->botActionsSend($lineUserId,$buildActions);
88
         $statusCode = $this->botActionsSend($lineUserId,$buildActions);
89
         if($statusCode == 200){
89
         if($statusCode == 200){
118
             }
118
             }
119
             array_push($clearAction, $this->buildActionsRequest("removeTag", config("botApi.doneSurvey")));
119
             array_push($clearAction, $this->buildActionsRequest("removeTag", config("botApi.doneSurvey")));
120
             array_push($clearAction, $this->buildActionsRequest("setMenu", "default"));
120
             array_push($clearAction, $this->buildActionsRequest("setMenu", "default"));
121
-            
121
+
122
             $statusCode = $this->botActionsSend($lineUserId,$clearAction);
122
             $statusCode = $this->botActionsSend($lineUserId,$clearAction);
123
             if($statusCode == 200){
123
             if($statusCode == 200){
124
                 $survey_data->delete();
124
                 $survey_data->delete();
157
         }
157
         }
158
     }
158
     }
159
 
159
 
160
-    function botActionsSend($lineUserId,$actions){
160
+    function botActionsSend($lineUserId, $actions){
161
+
162
+        $tagType = [];
163
+        foreach ($actions as $k => $action) {
164
+            if (!isset($tagType[$action['type']])) {
165
+                $tagType[$action['type']] = [];
166
+            }
167
+            switch ($action['type']) {
168
+                case "addTag":
169
+                case "removeTag":
170
+                    foreach ($action['value'] as $value) {
171
+                        $tagType[$action['type']]['value'][] = $value;
172
+                    }
173
+                    unset($actions[$k]);
174
+                    break;
175
+            }
176
+        }
177
+
178
+        $mergeData = [];
179
+        if (isset($tagType['addTag'])) {
180
+            $mergeData[] = [
181
+                'type' => 'addTag',
182
+                'value' => $tagType['addTag']['value']
183
+            ];
184
+        }
185
+        if (isset($tagType['removeTag'])) {
186
+            $mergeData[] = [
187
+                'type' => 'removeTag',
188
+                'value' => $tagType['removeTag']['value']
189
+            ];
190
+        }
191
+
192
+        $actions = array_merge($actions, $mergeData);
193
+
194
+        $actions = array_values($actions);
195
+
161
         $client = new Client();
196
         $client = new Client();
162
         $res_users = $client->request('POST', config('botApi.botActions'),[
197
         $res_users = $client->request('POST', config('botApi.botActions'),[
163
             'headers'=>$this->api_header,
198
             'headers'=>$this->api_header,