Browse Source

账单模型与transformers

durong 5 years ago
parent
commit
bc7d8a8e89

+ 15 - 0
app/Models/Behavior.php

@@ -23,4 +23,19 @@ class Behavior extends Model
     {
         return $this->hasMany('App\Models\RegisteredRecord','virus_behavior_id','virus_behavior_id');
     }
+
+    public function CommentRecord()
+    {
+        return $this->hasMany('App\Models\CommentRecord','virus_behavior_id','virus_behavior_id');
+    }
+
+    public function ReleaseRecord()
+    {
+        return $this->hasMany('App\Models\ReleaseRecord','virus_behavior_id','virus_behavior_id');
+    }
+
+    public function GeneralRecord()
+    {
+        return $this->hasMany('App\Models\GeneralRecord','virus_behavior_id','virus_behavior_id');
+    }
 }

+ 22 - 0
app/Models/CommentRecord.php

@@ -0,0 +1,22 @@
+<?php
+namespace App\Models;
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/14
+ * Time: 下午6:01
+ */
+
+class CommentRecord extends Model
+{
+    //评论账本
+    protected $table = 'comment_account_record';
+    protected $guarded = [];
+
+    public function Behavior()
+    {
+        return $this->belongsTo('App\Models\Behavior','virus_behavior_id','virus_behavior_id');
+    }
+}

+ 23 - 0
app/Models/GeneralRecord.php

@@ -0,0 +1,23 @@
+<?php
+namespace App\Models;
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/14
+ * Time: 上午11:25
+ */
+
+class GeneralRecord extends Model
+{
+    //分享、收藏等普通行为账本表
+    protected $table = 'general_ledger_record';
+    protected $guarded = [];
+
+    public function Behavior()
+    {
+        return $this->belongsTo('App\Models\Behavior','virus_behavior_id','virus_behavior_id');
+    }
+
+}

+ 0 - 1
app/Models/RegisteredRecord.php

@@ -15,7 +15,6 @@ class RegisteredRecord extends Model
     protected $table = 'registered_accounts_record';
     protected $guarded = [];
 
-    //
     public function Behavior()
     {
         return $this->belongsTo('App\Models\Behavior','virus_behavior_id','virus_behavior_id');

+ 22 - 0
app/Models/ReleaseRecord.php

@@ -0,0 +1,22 @@
+<?php
+namespace App\Models;
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/14
+ * Time: 下午8:15
+ */
+
+class ReleaseRecord extends Model
+{
+    //发布账本
+    protected $table = 'release_record';
+    protected $guarded = [];
+
+    public function Behavior()
+    {
+        return $this->belongsTo('App\Models\Behavior','virus_behavior_id','virus_behavior_id');
+    }
+}

+ 45 - 0
app/Transformers/Behavior/CommentRecordTransformer.php

@@ -0,0 +1,45 @@
+<?php
+namespace App\Transformers\Behavior;
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/14
+ * Time: 下午18:34
+ */
+use App\Models\CommentRecord;
+use League\Fractal\TransformerAbstract;
+
+class CommentRecordTransformer extends TransformerAbstract
+{
+    public function transform(CommentRecord $commentList)
+    {
+        return [
+            'id' => $commentList['id'],
+            'created_at' => date($commentList['created_at']),
+            'virus_behavior_id' => $commentList['virus_behavior_id'],
+            'uid' => $commentList['uid'],
+            'upper_trigger_time' => $commentList['upper_trigger_time'],
+            'related_content_id' => $commentList['related_content_id'],
+            'content_author_id' => $commentList['content_author_id'],
+            'superior_commentator_id' => $commentList['superior_commentator_id'],
+            'physical_exertion' => $commentList['physical_exertion'],
+            'trigger_type' => $commentList['trigger_type'],
+            'generation_type' => $commentList['generation_type'],
+            'release_status' => $commentList['release_status'],
+            'generation_quantity' => $commentList['generation_quantity'],
+            'quantity_issued' => $commentList['quantity_issued'],
+            'current_comment_id' => $commentList['current_comment_id'],
+            'superior_comment_id' => $commentList['superior_comment_id'],
+            'behavior_cycle_type' => $commentList->Behavior->behavior_cycle_type,
+            'name' => $commentList->Behavior->name,
+            'relative_series' => $commentList->Behavior->relative_series,
+            'is_open' => $commentList->Behavior->is_open,
+            'bahavior_created_at' => date($commentList->Behavior->created_at),
+            'all_trigger_times' => $commentList['all_trigger_times'],//总触发数
+            'all_effective_trigger' => $commentList['all_effective_trigger'],//有效触发数
+            'all_physical_exertion' => $commentList['physical_exertion'],//总消耗体力值
+            'all_generation_quantity' => $commentList['generation_quantity'],//总生成彩虹豆
+            'all_quantity_issued' => $commentList['quantity_issued'],//总发放彩虹豆
+        ];
+    }
+}

+ 44 - 0
app/Transformers/Behavior/GeneralRecordTransformer.php

@@ -0,0 +1,44 @@
+<?php
+namespace App\Transformers\Behavior;
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/14
+ * Time: 下午8:59
+ */
+use App\Models\CommentRecord;
+use App\Models\GeneralRecord;
+use App\Models\ReleaseRecord;
+use League\Fractal\TransformerAbstract;
+
+class GeneralRecordTransformer extends TransformerAbstract
+{
+    public function transform(GeneralRecord $genaralList)
+    {
+        return [
+            'id' => $genaralList['id'],
+            'created_at' => date($genaralList['created_at']),
+            'virus_behavior_id' => $genaralList['virus_behavior_id'],
+            'uid' => $genaralList['uid'],
+            'trigger_time' => $genaralList['trigger_time'],
+            'related_content_id' => $genaralList['related_content_id'],
+            'content_author_id' => $genaralList['content_author_id'],
+            'physical_exertion' => $genaralList['physical_exertion'],
+            'trigger_type' => $genaralList['trigger_type'],
+            'generation_type' => $genaralList['generation_type'],
+            'release_status' => $genaralList['release_status'],
+            'generation_quantity' => $genaralList['generation_quantity'],
+            'quantity_issued' => $genaralList['quantity_issued'],
+            'behavior_cycle_type' => $genaralList->Behavior->behavior_cycle_type,
+            'name' => $genaralList->Behavior->name,
+            'relative_series' => $genaralList->Behavior->relative_series,
+            'is_open' => $genaralList->Behavior->is_open,
+            'bahavior_created_at' => date($genaralList->Behavior->created_at),
+            'all_trigger_times' => $genaralList['all_trigger_times'],//总触发数
+            'all_effective_trigger' => $genaralList['all_effective_trigger'],//有效触发数
+            'all_physical_exertion' => $genaralList['physical_exertion'],//总消耗体力值
+            'all_generation_quantity' => $genaralList['generation_quantity'],//总生成彩虹豆
+            'all_quantity_issued' => $genaralList['quantity_issued'],//总发放彩虹豆
+        ];
+    }
+}

+ 6 - 1
app/Transformers/Behavior/RegisteredRecordTransformer.php

@@ -31,7 +31,12 @@ class RegisteredRecordTransformer extends TransformerAbstract
             'relative_series' => $registeredList->Behavior->relative_series,
             'is_open' => $registeredList->Behavior->is_open,
             'bahavior_created_at' => date($registeredList->Behavior->created_at),
-            'behavior_absolute_progression' => $registeredList['behavior_absolute_progression'],//行为绝对级数
+            'all_absolute_progression' => $registeredList['all_absolute_progression'],//行为绝对级数
+            'all_trigger_times' => $registeredList['all_trigger_times'],//总触发数
+            'all_effective_trigger' => $registeredList['all_effective_trigger'],//有效触发数
+            'all_physical_exertion' => $registeredList['physical_exertion'],//总消耗体力值
+            'all_generation_quantity' => $registeredList['generation_quantity'],//总生成彩虹豆
+            'all_quantity_issued' => $registeredList['quantity_issued'],//总发放彩虹豆
         ];
     }
 }

+ 42 - 0
app/Transformers/Behavior/ReleaseRecordTransformer.php

@@ -0,0 +1,42 @@
+<?php
+namespace App\Transformers\Behavior;
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/14
+ * Time: 下午8:30
+ */
+use App\Models\CommentRecord;
+use App\Models\ReleaseRecord;
+use League\Fractal\TransformerAbstract;
+
+class ReleaseRecordTransformer extends TransformerAbstract
+{
+    public function transform(ReleaseRecord $releaseRecord)
+    {
+        return [
+            'id' => $releaseRecord['id'],
+            'created_at' => date($releaseRecord['created_at']),
+            'virus_behavior_id' => $releaseRecord['virus_behavior_id'],
+            'uid' => $releaseRecord['uid'],
+            'trigger_time' => $releaseRecord['trigger_time'],
+            'related_content_id' => $releaseRecord['related_content_id'],
+            'physical_exertion' => $releaseRecord['physical_exertion'],
+            'trigger_type' => $releaseRecord['trigger_type'],
+            'generation_type' => $releaseRecord['generation_type'],
+            'release_status' => $releaseRecord['release_status'],
+            'generation_quantity' => $releaseRecord['generation_quantity'],
+            'quantity_issued' => $releaseRecord['quantity_issued'],
+            'behavior_cycle_type' => $releaseRecord->Behavior->behavior_cycle_type,
+            'name' => $releaseRecord->Behavior->name,
+            'relative_series' => $releaseRecord->Behavior->relative_series,
+            'is_open' => $releaseRecord->Behavior->is_open,
+            'bahavior_created_at' => date($releaseRecord->Behavior->created_at),
+            'all_trigger_times' => $releaseRecord['all_trigger_times'],//总触发数
+            'all_effective_trigger' => $releaseRecord['all_effective_trigger'],//有效触发数
+            'all_physical_exertion' => $releaseRecord['physical_exertion'],//总消耗体力值
+            'all_generation_quantity' => $releaseRecord['generation_quantity'],//总生成彩虹豆
+            'all_quantity_issued' => $releaseRecord['quantity_issued'],//总发放彩虹豆
+        ];
+    }
+}

+ 23 - 15
routes/api.php

@@ -86,23 +86,31 @@ $api->version('v1', [
             $api->get('topic/getTopic', 'TopicController@getTopic');
         });
 
-    });
-    //行为
-    $api->group(['namespace' => 'Behavior'], function ($api) {
-        //行为列表
-        $api->get('behavior/list', 'BehaviorController@index');
-        //登记/注册行为
-        $api->post('behavior/create', 'BehaviorController@create');
-        //编辑行为
-        $api->put('behavior/edit', 'BehaviorController@edit');
-        //列表修改行为状态(行为管理)
-        $api->post('behavior/editStatus', 'BehaviorController@editStatus');
+        //行为
+        $api->group(['namespace' => 'Behavior'], function ($api) {
+            //行为列表
+            $api->get('behavior/list', 'BehaviorController@index');
+            //登记/注册行为
+            $api->post('behavior/create', 'BehaviorController@create');
+            //编辑行为
+            $api->put('behavior/edit', 'BehaviorController@edit');
+            //列表修改行为状态(行为管理)
+            $api->post('behavior/editStatus', 'BehaviorController@editStatus');
 
-        //行为日志列表
-        $api->get('behavior/log', 'LogController@index');
+            //行为日志列表
+            $api->get('behavior/log', 'LogController@index');
 
-        //用户注册账单列表
-        $api->get('registeredRecord/list', 'RegisteredRecordController@index');
+            //用户注册账单列表
+            $api->get('registeredRecord/list', 'RegisteredRecordController@index');
+            //行为数据列表
+            $api->get('registeredRecord/behavior_data', 'RegisteredRecordController@behavior_data');
+            //评论账本列表
+            $api->get('CommentRecord/list', 'CommentRecordController@index');
+            //发布账本列表
+            $api->get('ReleaseRecord/list', 'ReleaseRecordController@index');
+            //阅读/分享/收藏等首次行为账单
+            $api->get('generalRecord/list', 'GeneralRecordController@index');
+        });
     });
 
 });