|
|
@@ -32,95 +32,65 @@ class SentenceController extends Controller
|
|
|
$table = Sentence::select($indexCol)
|
|
|
->where('content','like', '%'.$key.'%')
|
|
|
->where('editor_uid',$userUid);
|
|
|
- if(!empty($request->get('order')) && !empty($request->get('dir'))){
|
|
|
- $table->orderBy($request->get('order'),$request->get('dir'));
|
|
|
- }else{
|
|
|
- $table->orderBy('updated_at','desc');
|
|
|
- }
|
|
|
- $count = $table->count();
|
|
|
- if(!empty($request->get('limit'))){
|
|
|
- $offset = 0;
|
|
|
- if(!empty($request->get("offset"))){
|
|
|
- $offset = $request->get("offset");
|
|
|
- }
|
|
|
- $table->skip($offset)->take($request->get('limit'));
|
|
|
- }
|
|
|
- $result = $table->get();
|
|
|
- break;
|
|
|
- case 'user':
|
|
|
- # code...
|
|
|
- $userUid = $_COOKIE['user_uid'];
|
|
|
- $search = $request->get('search');
|
|
|
- $table = Sentence::select($indexCol)
|
|
|
- ->where('owner', $userUid);
|
|
|
- if(!empty($search)){
|
|
|
- $table->where('word', 'like', $search."%")
|
|
|
- ->orWhere('word_en', 'like', $search."%")
|
|
|
- ->orWhere('meaning', 'like', "%".$search."%");
|
|
|
- }
|
|
|
- if(!empty($request->get('order')) && !empty($request->get('dir'))){
|
|
|
- $table->orderBy($request->get('order'),$request->get('dir'));
|
|
|
- }else{
|
|
|
- $table->orderBy('updated_at','desc');
|
|
|
- }
|
|
|
- $count = $table->count();
|
|
|
- if(!empty($request->get('limit'))){
|
|
|
- $offset = 0;
|
|
|
- if(!empty($request->get("offset"))){
|
|
|
- $offset = $request->get("offset");
|
|
|
- }
|
|
|
- $table->skip($offset)->take($request->get('limit'));
|
|
|
- }
|
|
|
- $result = $table->get();
|
|
|
- break;
|
|
|
- case 'word':
|
|
|
- $result = Sentence::select($indexCol)
|
|
|
- ->where('word', $request->get("word"))
|
|
|
- ->orderBy('created_at','desc')
|
|
|
- ->get();
|
|
|
- break;
|
|
|
- case 'hot-meaning':
|
|
|
- $key='term/hot_meaning';
|
|
|
- $value = Cache::get($key, function()use($request) {
|
|
|
- $hotMeaning=[];
|
|
|
- $words = Sentence::select('word')
|
|
|
- ->where('language',$request->get("language"))
|
|
|
- ->groupby('word')
|
|
|
- ->get();
|
|
|
|
|
|
- foreach ($words as $key => $word) {
|
|
|
- # code...
|
|
|
- $result = Sentence::select(DB::raw('count(*) as word_count, meaning'))
|
|
|
- ->where('language',$request->get("language"))
|
|
|
- ->where('word',$word['word'])
|
|
|
- ->groupby('meaning')
|
|
|
- ->orderby('word_count','desc')
|
|
|
- ->first();
|
|
|
- if($result){
|
|
|
- $hotMeaning[]=[
|
|
|
- 'word'=>$word['word'],
|
|
|
- 'meaning'=>$result['meaning'],
|
|
|
- 'language'=>$request->get("language"),
|
|
|
- 'owner'=>'',
|
|
|
- ];
|
|
|
- }
|
|
|
- }
|
|
|
- Cache::put($key, $hotMeaning, 3600);
|
|
|
- return $hotMeaning;
|
|
|
- });
|
|
|
- return $this->ok(["rows"=>$value,"count"=>count($value)]);
|
|
|
+ break;
|
|
|
+ case 'channel':
|
|
|
+ $sent = explode(',',$request->get('sentence')) ;
|
|
|
+ $query = [];
|
|
|
+ foreach ($sent as $value) {
|
|
|
+ # code...
|
|
|
+ $ids = explode('-',$value);
|
|
|
+ $query[] = $ids;
|
|
|
+ }
|
|
|
+ $table = Sentence::select($indexCol)
|
|
|
+ ->where('channel_uid', $request->get('channel'))
|
|
|
+ ->whereIns(['book_id','paragraph','word_start','word_end'],$query);
|
|
|
break;
|
|
|
default:
|
|
|
# code...
|
|
|
break;
|
|
|
}
|
|
|
+ if(!empty($request->get('order')) && !empty($request->get('dir'))){
|
|
|
+ $table->orderBy($request->get('order'),$request->get('dir'));
|
|
|
+ }else{
|
|
|
+ $table->orderBy('updated_at','desc');
|
|
|
+ }
|
|
|
+ $count = $table->count();
|
|
|
+ if(!empty($request->get('limit'))){
|
|
|
+ $offset = 0;
|
|
|
+ if(!empty($request->get("offset"))){
|
|
|
+ $offset = $request->get("offset");
|
|
|
+ }
|
|
|
+ $table->skip($offset)->take($request->get('limit'));
|
|
|
+ }
|
|
|
+ $result = $table->get();
|
|
|
if($result){
|
|
|
return $this->ok(["rows"=>$result,"count"=>$count]);
|
|
|
}else{
|
|
|
return $this->error("没有查询到数据");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 用channel 和句子编号列表查询句子
|
|
|
+ */
|
|
|
+ public function sent_in_channel(Request $request){
|
|
|
+ $sent = $request->get('sentences') ;
|
|
|
+ $query = [];
|
|
|
+ foreach ($sent as $value) {
|
|
|
+ # code...
|
|
|
+ $ids = explode('-',$value);
|
|
|
+ $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);
|
|
|
+ $result = $table->get();
|
|
|
+ if($result){
|
|
|
+ return $this->ok(["rows"=>$result,"count"=>count($result)]);
|
|
|
+ }else{
|
|
|
+ return $this->error("没有查询到数据");
|
|
|
+ }
|
|
|
+ }
|
|
|
/**
|
|
|
* Show the form for creating a new resource.
|
|
|
*
|
|
|
@@ -139,7 +109,45 @@ class SentenceController extends Controller
|
|
|
*/
|
|
|
public function store(Request $request)
|
|
|
{
|
|
|
- //
|
|
|
+ //鉴权
|
|
|
+ $user = \App\Http\Api\AuthApi::current($request);
|
|
|
+ if(!$user ){
|
|
|
+ //未登录用户
|
|
|
+ return $this->error(__('auth.failed'));
|
|
|
+ }
|
|
|
+ $channel = Channel::where('uid',$request->get('channel'))->first();
|
|
|
+ if(!$channel){
|
|
|
+ return $this->error(__('auth.failed'));
|
|
|
+ }
|
|
|
+ if($channel->owner_uid !== $user["user_uid"]){
|
|
|
+ //判断是否为协作
|
|
|
+ $power = ShareApi::getResPower($user["user_uid"],$channel->uid);
|
|
|
+ if($power<30){
|
|
|
+ return $this->error(__('auth.failed'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach ($request->get('sentences') as $key => $sent) {
|
|
|
+ # code...
|
|
|
+ $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::orderedUuid(),
|
|
|
+ ]);
|
|
|
+ $row->content = $sent['content'];
|
|
|
+ $row->strlen = mb_strlen($sent['content'],"UTF-8");
|
|
|
+ $row->language = $channel->lang;
|
|
|
+ $row->status = $channel->status;
|
|
|
+ $row->editor_uid = $user["user_uid"];
|
|
|
+ $row->create_time = time()*1000;
|
|
|
+ $row->modify_time = time()*1000;
|
|
|
+ $row->save();
|
|
|
+ }
|
|
|
+ return $this->ok(count($request->get('sentences')));
|
|
|
}
|
|
|
|
|
|
/**
|