visuddhinanda 3 lat temu
rodzic
commit
e000c1b3b4

+ 83 - 0
app/Http/Controllers/GrammarGuideController.php

@@ -0,0 +1,83 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Models\DhammaTerm;
+use App\Http\Api\ChannelApi;
+use Illuminate\Http\Request;
+
+class GrammarGuideController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index()
+    {
+        //
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(Request $request)
+    {
+        //
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  \App\Models\DhammaTerm  $dhammaTerm
+     * @return \Illuminate\Http\Response
+     */
+    public function show(string $id)
+    {
+        //
+        $param = explode('_',$id);
+
+        $localTermChannel = ChannelApi::getSysChannel(
+            "_System_Grammar_Term_".strtolower($param[1])."_",
+            "_System_Grammar_Term_en_"
+        );
+        if(!$localTermChannel){
+            return $this->error('no term channel');
+        }
+        $result = DhammaTerm::where('word',$param[0])
+                    ->where('channal',$localTermChannel)->first();
+
+        if($result){
+            return $this->ok("# {$result->meaning}\n {$result->note}");
+        }else{
+            return $this->ok("# {$id}\n no record");
+        }
+
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \App\Models\DhammaTerm  $dhammaTerm
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, DhammaTerm $dhammaTerm)
+    {
+        //
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\Models\DhammaTerm  $dhammaTerm
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(DhammaTerm $dhammaTerm)
+    {
+        //
+    }
+}

+ 42 - 0
app/Http/Resources/UserDictResource.php

@@ -0,0 +1,42 @@
+<?php
+
+namespace App\Http\Resources;
+
+use Illuminate\Http\Resources\Json\JsonResource;
+use App\Http\Api\UserApi;
+use App\Models\UserOperationDaily;
+
+class UserDictResource extends JsonResource
+{
+    /**
+     * Transform the resource into an array.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
+     */
+    public function toArray($request)
+    {
+        $data = [
+		 'id'=>$this->id,
+         'word'=>$this->word,
+         'type'=>$this->type,
+         'grammar'=>$this->grammar,
+         'mean'=>$this->mean,
+         'parent'=>$this->parent,
+         'note'=>$this->note,
+         'factors'=>$this->factors,
+         'confidence'=>$this->confidence,
+         'updated_at'=>$this->updated_at,
+         'creator_id'=>$this->creator_id,
+        ];
+        if($request->get('view')==='community'){
+            $data['editor'] = UserApi::getById($this->creator_id);
+            //毫秒计算的经验值
+            $exp = UserOperationDaily::where('user_id',$this->creator_id)
+                                                ->where('date_int','<=',date_timestamp_get(date_create($this->updated_at))*1000)
+                                                ->sum('duration');
+            $data['exp'] = (int)($exp/1000);
+        }
+        return $data;
+    }
+}