Просмотр исходного кода

新建句子时,每个句子都进行权限判断

visuddhinanda 1 год назад
Родитель
Сommit
4a0dc4a214
1 измененных файлов с 240 добавлено и 200 удалено
  1. 240 200
      api-v8/app/Http/Controllers/SentenceController.php

+ 240 - 200
api-v8/app/Http/Controllers/SentenceController.php

@@ -19,10 +19,12 @@ use App\Http\Api\ShareApi;
 use App\Http\Api\ChannelApi;
 use App\Http\Api\ChannelApi;
 use App\Http\Api\PaliTextApi;
 use App\Http\Api\PaliTextApi;
 use App\Http\Api\Mq;
 use App\Http\Api\Mq;
-
+use App\Models\AccessToken;
 use App\Tools\RedisClusters;
 use App\Tools\RedisClusters;
 use App\Tools\OpsLog;
 use App\Tools\OpsLog;
 
 
+use Firebase\JWT\JWT;
+use Firebase\JWT\Key;
 
 
 class SentenceController extends Controller
 class SentenceController extends Controller
 {
 {
@@ -34,60 +36,73 @@ class SentenceController extends Controller
     public function index(Request $request)
     public function index(Request $request)
     {
     {
         $user = AuthApi::current($request);
         $user = AuthApi::current($request);
-        $result=false;
-		$indexCol = ['id','uid','book_id','paragraph',
-                    'word_start','word_end','content','content_type',
-                    'channel_uid','editor_uid','fork_at','acceptor_uid','pr_edit_at','updated_at'];
+        $result = false;
+        $indexCol = [
+            'id',
+            'uid',
+            'book_id',
+            'paragraph',
+            'word_start',
+            'word_end',
+            'content',
+            'content_type',
+            'channel_uid',
+            'editor_uid',
+            'fork_at',
+            'acceptor_uid',
+            'pr_edit_at',
+            'updated_at'
+        ];
 
 
-		switch ($request->get('view')) {
+        switch ($request->get('view')) {
             case 'public':
             case 'public':
                 //获取全部公开的译文
                 //获取全部公开的译文
                 //首先获取某个类型的 channel 列表
                 //首先获取某个类型的 channel 列表
                 $channels = [];
                 $channels = [];
-                $channel_type = $request->get('channel_type','translation');
-                if($channel_type === "original"){
+                $channel_type = $request->get('channel_type', 'translation');
+                if ($channel_type === "original") {
                     $pali_channel = ChannelApi::getSysChannel("_System_Pali_VRI_");
                     $pali_channel = ChannelApi::getSysChannel("_System_Pali_VRI_");
-                    if($pali_channel !== false){
+                    if ($pali_channel !== false) {
                         $channels[] = $pali_channel;
                         $channels[] = $pali_channel;
                     }
                     }
-                }else{
-                    $channelList = Channel::where('type',$channel_type)
-                                              ->where('status',30)
-                                              ->select('uid')->get();
+                } else {
+                    $channelList = Channel::where('type', $channel_type)
+                        ->where('status', 30)
+                        ->select('uid')->get();
                     foreach ($channelList as $channel) {
                     foreach ($channelList as $channel) {
                         # code...
                         # code...
                         $channels[] = $channel->uid;
                         $channels[] = $channel->uid;
                     }
                     }
                 }
                 }
                 $table = Sentence::select($indexCol)
                 $table = Sentence::select($indexCol)
-                                  ->whereIn('channel_uid',$channels)
-                                  ->where('updated_at','>',$request->get('updated_after','1970-1-1'));
+                    ->whereIn('channel_uid', $channels)
+                    ->where('updated_at', '>', $request->get('updated_after', '1970-1-1'));
                 break;
                 break;
             case 'fulltext':
             case 'fulltext':
-                if(isset($_COOKIE['user_uid'])){
+                if (isset($_COOKIE['user_uid'])) {
                     $userUid = $_COOKIE['user_uid'];
                     $userUid = $_COOKIE['user_uid'];
                 }
                 }
                 $key = $request->get('key');
                 $key = $request->get('key');
-                if(empty($key)){
-			        return $this->error("没有关键词");
+                if (empty($key)) {
+                    return $this->error("没有关键词");
                 }
                 }
                 $table = Sentence::select($indexCol)
                 $table = Sentence::select($indexCol)
-								  ->where('content','like', '%'.$key.'%')
-                                  ->where('editor_uid',$userUid);
+                    ->where('content', 'like', '%' . $key . '%')
+                    ->where('editor_uid', $userUid);
 
 
                 break;
                 break;
             case 'channel':
             case 'channel':
                 //句子编号列表在某个channel下的全部内容
                 //句子编号列表在某个channel下的全部内容
-                $sent = explode(',',$request->get('sentence')) ;
+                $sent = explode(',', $request->get('sentence'));
                 $query = [];
                 $query = [];
                 foreach ($sent as $value) {
                 foreach ($sent as $value) {
                     # code...
                     # code...
-                    $ids = explode('-',$value);
+                    $ids = explode('-', $value);
                     $query[] = $ids;
                     $query[] = $ids;
                 }
                 }
                 $table = Sentence::select($indexCol)
                 $table = Sentence::select($indexCol)
-                                ->where('channel_uid', $request->get('channel'))
-                                ->whereIns(['book_id','paragraph','word_start','word_end'],$query);
+                    ->where('channel_uid', $request->get('channel'))
+                    ->whereIns(['book_id', 'paragraph', 'word_start', 'word_end'], $query);
                 break;
                 break;
             case 'sent-can-read':
             case 'sent-can-read':
                 /**
                 /**
@@ -95,20 +110,20 @@ class SentenceController extends Controller
                  */
                  */
                 //获取用户有阅读权限的所有channel
                 //获取用户有阅读权限的所有channel
                 //全网公开
                 //全网公开
-                $type = $request->get('type','translation');
-                $channelTable = Channel::where("type",$type)->select(['uid','name']);
-                $channelPub = $channelTable->where('status',30)->get();
+                $type = $request->get('type', 'translation');
+                $channelTable = Channel::where("type", $type)->select(['uid', 'name']);
+                $channelPub = $channelTable->where('status', 30)->get();
 
 
                 $user = AuthApi::current($request);
                 $user = AuthApi::current($request);
-                $channelShare=array();
-                $channelMy=array();
-                if($user){
+                $channelShare = array();
+                $channelMy = array();
+                if ($user) {
                     //自己的
                     //自己的
-                    $channelMy = Channel::where('owner_uid',$user['user_uid'])
-                                        ->where('type',$type)
-                                        ->get();
+                    $channelMy = Channel::where('owner_uid', $user['user_uid'])
+                        ->where('type', $type)
+                        ->get();
                     //协作
                     //协作
-                    $channelShare = ShareApi::getResList($user['user_uid'],2);
+                    $channelShare = ShareApi::getResList($user['user_uid'], 2);
                 }
                 }
                 $channelCanRead = [];
                 $channelCanRead = [];
                 foreach ($channelPub as $key => $value) {
                 foreach ($channelPub as $key => $value) {
@@ -119,13 +134,13 @@ class SentenceController extends Controller
                     ];
                     ];
                 }
                 }
                 foreach ($channelShare as $key => $value) {
                 foreach ($channelShare as $key => $value) {
-                    if($value['type'] === $type){
+                    if ($value['type'] === $type) {
                         $channelCanRead[$value['res_id']] = [
                         $channelCanRead[$value['res_id']] = [
                             'id' => $value['res_id'],
                             'id' => $value['res_id'],
                             'role' => 'member',
                             'role' => 'member',
                             'name' => $value['res_title'],
                             'name' => $value['res_title'],
                         ];
                         ];
-                        if($value['power']>=20){
+                        if ($value['power'] >= 20) {
                             $channelCanRead[$value['res_id']]['role'] = "editor";
                             $channelCanRead[$value['res_id']]['role'] = "editor";
                         }
                         }
                     }
                     }
@@ -138,107 +153,110 @@ class SentenceController extends Controller
                     ];
                     ];
                 }
                 }
                 $channels = [];
                 $channels = [];
-                $excludeChannels = explode(',',$request->get('excludes')) ;
+                $excludeChannels = explode(',', $request->get('excludes'));
 
 
                 foreach ($channelCanRead as $key => $value) {
                 foreach ($channelCanRead as $key => $value) {
                     # code...
                     # code...
-                    if(!in_array($key,$excludeChannels)){
+                    if (!in_array($key, $excludeChannels)) {
                         $channels[] = $key;
                         $channels[] = $key;
                     }
                     }
                 }
                 }
-                $sent = explode('-',$request->get('sentence')) ;
+                $sent = explode('-', $request->get('sentence'));
                 $table = Sentence::select($indexCol)
                 $table = Sentence::select($indexCol)
-                                ->whereIn('channel_uid', $channels)
-                                ->where('ver','>',1)
-                                ->where('book_id',$sent[0])
-                                ->where('paragraph',$sent[1])
-                                ->where('word_start',$sent[2])
-                                ->where('word_end',$sent[3]);
+                    ->whereIn('channel_uid', $channels)
+                    ->where('ver', '>', 1)
+                    ->where('book_id', $sent[0])
+                    ->where('paragraph', $sent[1])
+                    ->where('word_start', $sent[2])
+                    ->where('word_end', $sent[3]);
                 break;
                 break;
             case 'chapter':
             case 'chapter':
-                $chapter =  PaliTextApi::getChapterStartEnd($request->get('book'),$request->get('para'));
-                $table = Sentence::where('ver','>',1)
-                                    ->where('book_id',$request->get('book'))
-                                    ->whereBetween('paragraph',$chapter)
-                                    ->whereIn('channel_uid',explode(',',$request->get('channels')));
+                $chapter =  PaliTextApi::getChapterStartEnd($request->get('book'), $request->get('para'));
+                $table = Sentence::where('ver', '>', 1)
+                    ->where('book_id', $request->get('book'))
+                    ->whereBetween('paragraph', $chapter)
+                    ->whereIn('channel_uid', explode(',', $request->get('channels')));
                 break;
                 break;
             case 'paragraph':
             case 'paragraph':
-                $table = Sentence::where('ver','>',1)
-                                    ->where('book_id',$request->get('book'))
-                                    ->whereIn('paragraph',explode(',',$request->get('para')))
-                                    ->whereIn('channel_uid',explode(',',$request->get('channels')))
-                                    ->orderBy('book_id')->orderBy('paragraph')->orderBy('word_start');
+                $table = Sentence::where('ver', '>', 1)
+                    ->where('book_id', $request->get('book'))
+                    ->whereIn('paragraph', explode(',', $request->get('para')))
+                    ->whereIn('channel_uid', explode(',', $request->get('channels')))
+                    ->orderBy('book_id')->orderBy('paragraph')->orderBy('word_start');
                 break;
                 break;
             case 'my-edit':
             case 'my-edit':
                 //我编辑的
                 //我编辑的
-                if(!$user){
-                    return $this->error(__('auth.failed'),401,401);
+                if (!$user) {
+                    return $this->error(__('auth.failed'), 401, 401);
                 }
                 }
-                $table = Sentence::where('editor_uid',$user['user_uid'])
-                                ->where('ver','>',1);
+                $table = Sentence::where('editor_uid', $user['user_uid'])
+                    ->where('ver', '>', 1);
+                break;
+            default:
+                # code...
                 break;
                 break;
-			default:
-				# code...
-				break;
-		}
-        if(!empty($request->get("key"))){
-            $table = $table->where('content','like', '%'.$request->get("key").'%');
+        }
+        if (!empty($request->get("key"))) {
+            $table = $table->where('content', 'like', '%' . $request->get("key") . '%');
         }
         }
 
 
         $count = $table->count();
         $count = $table->count();
-        if($request->get('strlen',false)){
+        if ($request->get('strlen', false)) {
             $totalStrLen = $table->sum('strlen');
             $totalStrLen = $table->sum('strlen');
         }
         }
-        if($request->get('view') !== 'paragraph'){
-            $table = $table->orderBy($request->get('order','updated_at'),
-                                    $request->get('dir','desc'));
+        if ($request->get('view') !== 'paragraph') {
+            $table = $table->orderBy(
+                $request->get('order', 'updated_at'),
+                $request->get('dir', 'desc')
+            );
         }
         }
 
 
-        $table = $table->skip($request->get("offset",0))
-                       ->take($request->get('limit',1000));
+        $table = $table->skip($request->get("offset", 0))
+            ->take($request->get('limit', 1000));
         $result = $table->get();
         $result = $table->get();
 
 
-		if($result){
-            $output = ["count"=>$count];
-            if($request->get('view') === 'sent-can-read' ||
+        if ($result) {
+            $output = ["count" => $count];
+            if (
+                $request->get('view') === 'sent-can-read' ||
                 $request->get('view') === 'channel' ||
                 $request->get('view') === 'channel' ||
                 $request->get('view') === 'chapter' ||
                 $request->get('view') === 'chapter' ||
                 $request->get('view') === 'paragraph' ||
                 $request->get('view') === 'paragraph' ||
                 $request->get('view') === 'my-edit'
                 $request->get('view') === 'my-edit'
-                ){
+            ) {
                 $output["rows"] = SentResource::collection($result);
                 $output["rows"] = SentResource::collection($result);
-            }else{
+            } else {
                 $output["rows"] = $result;
                 $output["rows"] = $result;
             }
             }
-            if(isset($totalStrLen)){
+            if (isset($totalStrLen)) {
                 $output['total_strlen'] = $totalStrLen;
                 $output['total_strlen'] = $totalStrLen;
             }
             }
             return $this->ok($output);
             return $this->ok($output);
-
-		}else{
-			return $this->error("没有查询到数据");
-		}
+        } else {
+            return $this->error("没有查询到数据");
+        }
     }
     }
     /**
     /**
      * 用channel 和句子编号列表查询句子
      * 用channel 和句子编号列表查询句子
      */
      */
-    public function sent_in_channel(Request $request){
-        $sent = $request->get('sentences') ;
+    public function sent_in_channel(Request $request)
+    {
+        $sent = $request->get('sentences');
         $query = [];
         $query = [];
         foreach ($sent as $value) {
         foreach ($sent as $value) {
             # code...
             # code...
-            $ids = explode('-',$value);
-            if(count($ids)===4){
+            $ids = explode('-', $value);
+            if (count($ids) === 4) {
                 $query[] = $ids;
                 $query[] = $ids;
             }
             }
         }
         }
-        $table = Sentence::select(['id','book_id','paragraph','word_start','word_end','content','channel_uid','updated_at'])
-                        ->where('channel_uid', $request->get('channel'))
-                        ->whereIns(['book_id','paragraph','word_start','word_end'],$query);
+        $table = Sentence::select(['id', 'book_id', 'paragraph', 'word_start', 'word_end', 'content', 'channel_uid', 'updated_at'])
+            ->where('channel_uid', $request->get('channel'))
+            ->whereIns(['book_id', 'paragraph', 'word_start', 'word_end'], $query);
         $result = $table->get();
         $result = $table->get();
-        if($result){
-            return $this->ok(["rows"=>$result,"count"=>count($result)]);
-        }else{
+        if ($result) {
+            return $this->ok(["rows" => $result, "count" => count($result)]);
+        } else {
             return $this->error("没有查询到数据");
             return $this->error("没有查询到数据");
         }
         }
     }
     }
@@ -262,113 +280,132 @@ class SentenceController extends Controller
     {
     {
         //鉴权
         //鉴权
         $user = AuthApi::current($request);
         $user = AuthApi::current($request);
-        if(!$user ){
+        if (!$user) {
             //未登录用户
             //未登录用户
-            return $this->error(__('auth.failed'),401,401);
-        }
-        $channel = Channel::where('uid',$request->get('channel'))->first();
-        if(!$channel){
-            return $this->error(__('auth.failed'),403,403);
+            return $this->error(__('auth.failed'), 401, 401);
         }
         }
-        if($channel->owner_uid !== $user["user_uid"]){
-            //判断是否为协作
-            $power = ShareApi::getResPower($user["user_uid"],$channel->uid,2);
-            if($power < 20){
-                return $this->error(__('auth.failed'),403,403);
-            }
+        if (!$request->has('sentences')) {
+            return $this->error('no date', 200, 200);
         }
         }
-        $sentFirst=null;
+
+        $sentFirst = null;
         $changedSent = [];
         $changedSent = [];
         foreach ($request->get('sentences') as $key => $sent) {
         foreach ($request->get('sentences') as $key => $sent) {
-            # code...
-            if($sentFirst === null){
+            # 权限
+            $channelId = $sent['channel_uid'];
+            $channel = Channel::where('uid', $channelId)->first();
+            if (!$channel) {
+                continue;
+            }
+            if ($channel->owner_uid !== $user["user_uid"]) {
+                //判断是否为协作
+                $power = ShareApi::getResPower($user["user_uid"], $channel->uid, 2);
+                if ($power < 20) {
+                    //判断token
+                    if (isset($sent['token'])) {
+                        $key = AccessToken::where('res_id', $channelId)->value('token');
+                        $jwt = JWT::decode($sent['token'], new Key($key, 'HS512'));
+                        if ($jwt->book !== $sent['book_id']) {
+                            continue;
+                        }
+                    } else {
+                        continue;
+                    }
+                }
+            }
+
+            if ($sentFirst === null) {
                 $sentFirst = $sent;
                 $sentFirst = $sent;
             }
             }
             $row = Sentence::firstOrNew([
             $row = Sentence::firstOrNew([
-                "book_id"=>$sent['book_id'],
-                "paragraph"=>$sent['paragraph'],
-                "word_start"=>$sent['word_start'],
-                "word_end"=>$sent['word_end'],
-                "channel_uid"=>$channel->uid,
-            ],[
-                "id"=>app('snowflake')->id(),
-                "uid"=>Str::uuid(),
+                "book_id" => $sent['book_id'],
+                "paragraph" => $sent['paragraph'],
+                "word_start" => $sent['word_start'],
+                "word_end" => $sent['word_end'],
+                "channel_uid" => $channel->uid,
+            ], [
+                "id" => app('snowflake')->id(),
+                "uid" => Str::uuid(),
             ]);
             ]);
             $row->content = $sent['content'];
             $row->content = $sent['content'];
-            if(isset($sent['content_type']) && !empty($sent['content_type'])){
+            if (isset($sent['content_type']) && !empty($sent['content_type'])) {
                 $row->content_type = $sent['content_type'];
                 $row->content_type = $sent['content_type'];
             }
             }
-            $row->strlen = mb_strlen($sent['content'],"UTF-8");
+            $row->strlen = mb_strlen($sent['content'], "UTF-8");
             $row->language = $channel->lang;
             $row->language = $channel->lang;
             $row->status = $channel->status;
             $row->status = $channel->status;
-            if($request->has('copy')){
+            if ($request->has('copy')) {
                 //复制句子,保留原作者信息
                 //复制句子,保留原作者信息
                 $row->editor_uid = $sent["editor_uid"];
                 $row->editor_uid = $sent["editor_uid"];
                 $row->acceptor_uid = $user["user_uid"];
                 $row->acceptor_uid = $user["user_uid"];
                 $row->pr_edit_at = $sent["updated_at"];
                 $row->pr_edit_at = $sent["updated_at"];
-                if($request->has('fork_from')){
+                if ($request->has('fork_from')) {
                     $row->fork_at = now();
                     $row->fork_at = now();
                 }
                 }
-            }else{
+            } else {
                 $row->editor_uid = $user["user_uid"];
                 $row->editor_uid = $user["user_uid"];
                 $row->acceptor_uid = null;
                 $row->acceptor_uid = null;
                 $row->pr_edit_at = null;
                 $row->pr_edit_at = null;
             }
             }
-            $row->create_time = time()*1000;
-            $row->modify_time = time()*1000;
+            $row->create_time = time() * 1000;
+            $row->modify_time = time() * 1000;
             $row->save();
             $row->save();
 
 
             $changedSent[] = $row->uid;
             $changedSent[] = $row->uid;
 
 
             //保存历史记录
             //保存历史记录
-            if($request->has('copy')){
-                $fork_from = $request->get('fork_from',null);
-                $this->saveHistory($row->uid,
-                                $sent["editor_uid"],
-                                $sent['content'],
-                                $user["user_uid"],
-                                $fork_from);
-            }else{
-                $this->saveHistory($row->uid,$user["user_uid"],$sent['content'],$user["user_uid"]);
+            if ($request->has('copy')) {
+                $fork_from = $request->get('fork_from', null);
+                $this->saveHistory(
+                    $row->uid,
+                    $sent["editor_uid"],
+                    $sent['content'],
+                    $user["user_uid"],
+                    $fork_from
+                );
+            } else {
+                $this->saveHistory($row->uid, $user["user_uid"], $sent['content'], $user["user_uid"]);
             }
             }
             //清除缓存
             //清除缓存
             $sentId = "{$sent['book_id']}-{$sent['paragraph']}-{$sent['word_start']}-{$sent['word_end']}";
             $sentId = "{$sent['book_id']}-{$sent['paragraph']}-{$sent['word_start']}-{$sent['word_end']}";
             $hKey = "/sentence/res-count/{$sentId}/";
             $hKey = "/sentence/res-count/{$sentId}/";
             Redis::del($hKey);
             Redis::del($hKey);
         }
         }
-        if($sentFirst !== null){
-            Mq::publish('progress',['book'=>$sentFirst['book_id'],
-                                'para'=>$sentFirst['paragraph'],
-                                'channel'=>$channel->uid,
-                                ]);
+        if ($sentFirst !== null) {
+            Mq::publish('progress', [
+                'book' => $sentFirst['book_id'],
+                'para' => $sentFirst['paragraph'],
+                'channel' => $channel->uid,
+            ]);
         }
         }
 
 
         $result = Sentence::whereIn('uid', $changedSent)->get();
         $result = Sentence::whereIn('uid', $changedSent)->get();
         return $this->ok([
         return $this->ok([
-            'rows'=>SentResource::collection($result),
-            'count'=>count($result)
+            'rows' => SentResource::collection($result),
+            'count' => count($result)
         ]);
         ]);
     }
     }
 
 
-    private function saveHistory($uid,$editor,$content,$user_uid=null,$fork_from=null,$pr_from=null){
+    private function saveHistory($uid, $editor, $content, $user_uid = null, $fork_from = null, $pr_from = null)
+    {
         $newHis = new SentHistory();
         $newHis = new SentHistory();
         $newHis->id = app('snowflake')->id();
         $newHis->id = app('snowflake')->id();
         $newHis->sent_uid = $uid;
         $newHis->sent_uid = $uid;
         $newHis->user_uid = $editor;
         $newHis->user_uid = $editor;
-        if(empty($content)){
+        if (empty($content)) {
             $newHis->content = "";
             $newHis->content = "";
-        }else{
+        } else {
             $newHis->content = $content;
             $newHis->content = $content;
         }
         }
-        if($fork_from){
+        if ($fork_from) {
             $newHis->fork_from = $fork_from;
             $newHis->fork_from = $fork_from;
             $newHis->accepter_uid = $user_uid;
             $newHis->accepter_uid = $user_uid;
         }
         }
-        if($pr_from){
+        if ($pr_from) {
             $newHis->pr_from = $pr_from;
             $newHis->pr_from = $pr_from;
             $newHis->accepter_uid = $user_uid;
             $newHis->accepter_uid = $user_uid;
         }
         }
-        $newHis->create_time = time()*1000;
+        $newHis->create_time = time() * 1000;
         $newHis->save();
         $newHis->save();
     }
     }
     /**
     /**
@@ -394,51 +431,51 @@ class SentenceController extends Controller
     public function update(Request $request,  $id)
     public function update(Request $request,  $id)
     {
     {
         //
         //
-        $param = \explode('_',$id);
+        $param = \explode('_', $id);
 
 
         //鉴权
         //鉴权
         $user = AuthApi::current($request);
         $user = AuthApi::current($request);
-        if(!$user){
+        if (!$user) {
             //未登录鉴权失败
             //未登录鉴权失败
-            return $this->error(__('auth.failed'),403,403);
+            return $this->error(__('auth.failed'), 403, 403);
         }
         }
-        $channel = Channel::where('uid',$param[4])->first();
-        if(!$channel){
+        $channel = Channel::where('uid', $param[4])->first();
+        if (!$channel) {
             return $this->error("not found channel");
             return $this->error("not found channel");
         }
         }
-        if($channel->owner_uid !== $user["user_uid"]){
+        if ($channel->owner_uid !== $user["user_uid"]) {
             // 判断是否为协作
             // 判断是否为协作
-            $power = ShareApi::getResPower($user["user_uid"],$channel->uid,2);
-            if($power < 20){
-                return $this->error(__('auth.failed'),403,403);
+            $power = ShareApi::getResPower($user["user_uid"], $channel->uid, 2);
+            if ($power < 20) {
+                return $this->error(__('auth.failed'), 403, 403);
             }
             }
         }
         }
 
 
         $sent = Sentence::firstOrNew([
         $sent = Sentence::firstOrNew([
-            "book_id"=>$param[0],
-            "paragraph"=>$param[1],
-            "word_start"=>$param[2],
-            "word_end"=>$param[3],
-            "channel_uid"=>$param[4],
-        ],[
-            "id"=>app('snowflake')->id(),
-            "uid"=>Str::orderedUuid(),
-            "create_time"=>time()*1000,
+            "book_id" => $param[0],
+            "paragraph" => $param[1],
+            "word_start" => $param[2],
+            "word_end" => $param[3],
+            "channel_uid" => $param[4],
+        ], [
+            "id" => app('snowflake')->id(),
+            "uid" => Str::orderedUuid(),
+            "create_time" => time() * 1000,
         ]);
         ]);
         $sent->content = $request->get('content');
         $sent->content = $request->get('content');
-        if($request->has('contentType')){
+        if ($request->has('contentType')) {
             $sent->content_type = $request->get('contentType');
             $sent->content_type = $request->get('contentType');
         }
         }
         $sent->language = $channel->lang;
         $sent->language = $channel->lang;
         $sent->status = $channel->status;
         $sent->status = $channel->status;
-        $sent->strlen = mb_strlen($request->get('content'),"UTF-8");
-        $sent->modify_time = time()*1000;
-        if($request->has('prEditor')){
+        $sent->strlen = mb_strlen($request->get('content'), "UTF-8");
+        $sent->modify_time = time() * 1000;
+        if ($request->has('prEditor')) {
             $realEditor = $request->get('prEditor');
             $realEditor = $request->get('prEditor');
             $sent->acceptor_uid = $user["user_uid"];
             $sent->acceptor_uid = $user["user_uid"];
             $sent->pr_edit_at = $request->get('prEditAt');
             $sent->pr_edit_at = $request->get('prEditAt');
             $sent->pr_id = $request->get('prId');
             $sent->pr_id = $request->get('prId');
-        }else{
+        } else {
             $realEditor = $user["user_uid"];
             $realEditor = $user["user_uid"];
             $sent->acceptor_uid = null;
             $sent->acceptor_uid = null;
             $sent->pr_edit_at = null;
             $sent->pr_edit_at = null;
@@ -451,33 +488,35 @@ class SentenceController extends Controller
         $sentId = "{$sent['book_id']}-{$sent['paragraph']}-{$sent['word_start']}-{$sent['word_end']}";
         $sentId = "{$sent['book_id']}-{$sent['paragraph']}-{$sent['word_start']}-{$sent['word_end']}";
         $hKey = "/sentence/res-count/{$sentId}/";
         $hKey = "/sentence/res-count/{$sentId}/";
         Redis::del($hKey);
         Redis::del($hKey);
-        OpsLog::debug($user["user_uid"],$sent);
+        OpsLog::debug($user["user_uid"], $sent);
 
 
         //清除cache
         //清除cache
         $channelId = $param[4];
         $channelId = $param[4];
         $currSentId = "{$param[0]}-{$param[1]}-{$param[2]}-{$param[3]}";
         $currSentId = "{$param[0]}-{$param[1]}-{$param[2]}-{$param[3]}";
         RedisClusters::forget("/sent/{$channelId}/{$currSentId}");
         RedisClusters::forget("/sent/{$channelId}/{$currSentId}");
         //保存历史记录
         //保存历史记录
-        if($request->has('prEditor')){
-            $this->saveHistory($sent->uid,
-                            $realEditor,
-                            $request->get('content'),
-                            $user["user_uid"],
-                            null,
-                            $request->get('prUuid'),
-                        );
-        }else{
-            $this->saveHistory($sent->uid,$realEditor,$request->get('content'));
+        if ($request->has('prEditor')) {
+            $this->saveHistory(
+                $sent->uid,
+                $realEditor,
+                $request->get('content'),
+                $user["user_uid"],
+                null,
+                $request->get('prUuid'),
+            );
+        } else {
+            $this->saveHistory($sent->uid, $realEditor, $request->get('content'));
         }
         }
 
 
-        Mq::publish('progress',['book'=>$param[0],
-                            'para'=>$param[1],
-                            'channel'=>$channelId,
-                            ]);
-        Mq::publish('content',new SentResource($sent));
+        Mq::publish('progress', [
+            'book' => $param[0],
+            'para' => $param[1],
+            'channel' => $channelId,
+        ]);
+        Mq::publish('content', new SentResource($sent));
 
 
-        if($channel->type === 'nissaya' && $sent->content_type === 'json'){
-            $this->updateWbwAnalyses($sent->content,$channel->lang,$user["user_id"]);
+        if ($channel->type === 'nissaya' && $sent->content_type === 'json') {
+            $this->updateWbwAnalyses($sent->content, $channel->lang, $user["user_id"]);
         }
         }
 
 
         return $this->ok(new SentResource($sent));
         return $this->ok(new SentResource($sent));
@@ -494,15 +533,16 @@ class SentenceController extends Controller
         //
         //
     }
     }
 
 
-    private function updateWbwAnalyses($data,$lang,$editorId){
+    private function updateWbwAnalyses($data, $lang, $editorId)
+    {
         $wbwData = json_decode($data);
         $wbwData = json_decode($data);
         $currWbwId = 0;
         $currWbwId = 0;
         $prefix = 'wbw-preference';
         $prefix = 'wbw-preference';
         foreach ($wbwData as $key => $word) {
         foreach ($wbwData as $key => $word) {
             # code...
             # code...
-            if(count($word->sn) === 1 ){
+            if (count($word->sn) === 1) {
                 $currWbwId = $word->uid;
                 $currWbwId = $word->uid;
-                WbwAnalysis::where('wbw_id',$word->uid)->delete();
+                WbwAnalysis::where('wbw_id', $word->uid)->delete();
             }
             }
             $newData = [
             $newData = [
                 'wbw_id' => $currWbwId,
                 'wbw_id' => $currWbwId,
@@ -514,29 +554,29 @@ class SentenceController extends Controller
                 'data' => '',
                 'data' => '',
                 'confidence' => 100,
                 'confidence' => 100,
                 'lang' => $lang,
                 'lang' => $lang,
-                'editor_id'=>$editorId,
-                'created_at'=>now(),
-                'updated_at'=>now()
+                'editor_id' => $editorId,
+                'created_at' => now(),
+                'updated_at' => now()
             ];
             ];
             $newData['type'] = 3;
             $newData['type'] = 3;
-            if(!empty($word->meaning->value)){
+            if (!empty($word->meaning->value)) {
                 $newData['data'] = $word->meaning->value;
                 $newData['data'] = $word->meaning->value;
                 WbwAnalysis::insert($newData);
                 WbwAnalysis::insert($newData);
-                RedisClusters::put("{$prefix}/{$word->real->value}/3/{$editorId}",$word->meaning->value);
-                RedisClusters::put("{$prefix}/{$word->real->value}/3/0",$word->meaning->value);
+                RedisClusters::put("{$prefix}/{$word->real->value}/3/{$editorId}", $word->meaning->value);
+                RedisClusters::put("{$prefix}/{$word->real->value}/3/0", $word->meaning->value);
             }
             }
-            if(isset($word->factors) && isset($word->factorMeaning)){
-                $factors = explode('+',str_replace('-','+',$word->factors->value));
-                $factorMeaning = explode('+',str_replace('-','+',$word->factorMeaning->value));
+            if (isset($word->factors) && isset($word->factorMeaning)) {
+                $factors = explode('+', str_replace('-', '+', $word->factors->value));
+                $factorMeaning = explode('+', str_replace('-', '+', $word->factorMeaning->value));
                 foreach ($factors as $key => $factor) {
                 foreach ($factors as $key => $factor) {
-                    if(isset($factorMeaning[$key])){
-                        if(!empty($factorMeaning[$key])){
+                    if (isset($factorMeaning[$key])) {
+                        if (!empty($factorMeaning[$key])) {
                             $newData['wbw_word'] = $factor;
                             $newData['wbw_word'] = $factor;
                             $newData['data'] = $factorMeaning[$key];
                             $newData['data'] = $factorMeaning[$key];
                             $newData['type'] = 5;
                             $newData['type'] = 5;
                             WbwAnalysis::insert($newData);
                             WbwAnalysis::insert($newData);
-                            RedisClusters::put("{$prefix}/{$factor}/5/{$editorId}",$factorMeaning[$key]);
-                            RedisClusters::put("{$prefix}/{$factor}/5/0",$factorMeaning[$key]);
+                            RedisClusters::put("{$prefix}/{$factor}/5/{$editorId}", $factorMeaning[$key]);
+                            RedisClusters::put("{$prefix}/{$factor}/5/0", $factorMeaning[$key]);
                         }
                         }
                     }
                     }
                 }
                 }