Browse Source

Merge pull request #1922 from visuddhinanda/laravel

批量更新返回更新结果
visuddhinanda 2 years ago
parent
commit
9a0445f901

+ 7 - 3
app/Http/Controllers/CorpusController.php

@@ -307,7 +307,8 @@ class CorpusController extends Controller
 
 		#获取channel索引表
         $tranChannels = [];
-		$channelInfo = Channel::whereIn("uid",$channels)->select(['uid','type','name'])->get();
+		$channelInfo = Channel::whereIn("uid",$channels)
+                        ->select(['uid','type','name'])->get();
 		foreach ($channelInfo as $key => $value) {
 			# code...
             if($value->type==="translation" ){
@@ -320,7 +321,8 @@ class CorpusController extends Controller
         //目前默认的 wbw channel 是第一个translation channel
         foreach ($channels as $key => $value) {
             # code...
-            if($indexChannel[$value]->type==='translation'){
+            if(isset($indexChannel[$value]) &&
+                 $indexChannel[$value]->type==='translation'){
                 $this->wbwChannels[] = $value;
                 break;
             }
@@ -432,9 +434,11 @@ class CorpusController extends Controller
         $indexChannel = $this->getChannelIndex($channels);
         //获取wbw channel
         //目前默认的 wbw channel 是第一个translation channel
+        //TODO 处理不存在的channel id
         foreach ($channels as $key => $value) {
             # code...
-            if($indexChannel[$value]->type==='translation'){
+            if(isset($indexChannel[$value]) &&
+                $indexChannel[$value]->type==='translation'){
                 $this->wbwChannels[] = $value;
                 break;
             }

+ 9 - 1
app/Http/Controllers/SentenceController.php

@@ -254,6 +254,7 @@ class SentenceController extends Controller
             }
         }
         $sentFirst=null;
+        $changedSent = [];
         foreach ($request->get('sentences') as $key => $sent) {
             # code...
             if($sentFirst === null){
@@ -290,6 +291,8 @@ class SentenceController extends Controller
             $row->modify_time = time()*1000;
             $row->save();
 
+            $changedSent[] = $row->uid;
+
             //保存历史记录
             if($request->has('copy')){
                 $fork_from = $request->get('fork_from',null);
@@ -312,7 +315,12 @@ class SentenceController extends Controller
                                 'channel'=>$channel->uid,
                                 ]);
         }
-        return $this->ok(count($request->get('sentences')));
+
+        $result = Sentence::whereIn('uid', $changedSent)->get();
+        return $this->ok([
+            'rows'=>SentResource::collection($result),
+            'count'=>count($result)
+        ]);
     }
 
     private function saveHistory($uid,$editor,$content,$user_uid,$fork_from=null,$pr_from=null){

+ 6 - 0
app/Models/Sentence.php

@@ -17,4 +17,10 @@ class Sentence extends Model
         'uid' => 'string'
     ];
 
+    protected $dates = [
+        'created_at',
+        'updated_at',
+        'fork_at'
+    ];
+
 }