Prechádzať zdrojové kódy

Merge branch 'develop'

xielin 5 rokov pred
rodič
commit
e79a558ad9
100 zmenil súbory, kde vykonal 5937 pridanie a 124 odobranie
  1. 1 0
      .gitignore
  2. 42 0
      app/Console/Commands/CommunityMemberStatistics.php
  3. 91 0
      app/Console/Commands/Downloads.php
  4. 88 0
      app/Console/Commands/MusicImport.php
  5. 70 0
      app/Console/Commands/PostCollectBean.php
  6. 70 0
      app/Console/Commands/PostCreateBean.php
  7. 144 0
      app/Console/Commands/PostStatistics.php
  8. 69 0
      app/Console/Commands/PostYesterday.php
  9. 211 0
      app/Console/Commands/VirusAdd.php
  10. 41 2
      app/Console/Kernel.php
  11. 64 4
      app/Helper/helper.php
  12. 81 0
      app/Http/Controllers/AliYunVodController.php
  13. 170 0
      app/Http/Controllers/Behavior/BehaviorController.php
  14. 80 0
      app/Http/Controllers/Behavior/CommentRecordController.php
  15. 81 0
      app/Http/Controllers/Behavior/GeneralRecordController.php
  16. 52 0
      app/Http/Controllers/Behavior/LogController.php
  17. 78 0
      app/Http/Controllers/Behavior/RegisteredRecordController.php
  18. 74 0
      app/Http/Controllers/Behavior/ReleaseRecordController.php
  19. 71 1
      app/Http/Controllers/ConfigController.php
  20. 67 0
      app/Http/Controllers/DownloadController.php
  21. 37 0
      app/Http/Controllers/MemberStatisticsController.php
  22. 133 8
      app/Http/Controllers/Post/PostController.php
  23. 101 0
      app/Http/Controllers/Topic/CategoryController.php
  24. 140 0
      app/Http/Controllers/Topic/TopicController.php
  25. 45 0
      app/Models/Behavior.php
  26. 23 0
      app/Models/BehaviorOperationLog.php
  27. 5 0
      app/Models/Category.php
  28. 10 0
      app/Models/CategoryTopic.php
  29. 22 0
      app/Models/CommentRecord.php
  30. 17 0
      app/Models/CommunityMemberStatistics.php
  31. 16 0
      app/Models/Download.php
  32. 23 0
      app/Models/GeneralRecord.php
  33. 20 0
      app/Models/PostMusic.php
  34. 20 0
      app/Models/PostMusicCategory.php
  35. 19 0
      app/Models/PostMusicCategoryRel.php
  36. 17 0
      app/Models/PostStatistics.php
  37. 23 0
      app/Models/RegisteredRecord.php
  38. 22 0
      app/Models/ReleaseRecord.php
  39. 5 0
      app/Models/Topic.php
  40. 39 0
      app/Repositories/Behavior/BehaviorLogRepository.php
  41. 432 0
      app/Repositories/Behavior/BehaviorRepository.php
  42. 57 0
      app/Repositories/Behavior/CommentRecordRepository.php
  43. 63 0
      app/Repositories/Behavior/GenaralRecordRepository.php
  44. 51 0
      app/Repositories/Behavior/RegisteredRecordRepository.php
  45. 51 0
      app/Repositories/Behavior/ReleaseRecordRepository.php
  46. 145 0
      app/Repositories/CategoryRepository.php
  47. 207 0
      app/Repositories/CommunityMemberStatisticsRepository.php
  48. 96 0
      app/Repositories/DownloadRepository.php
  49. 638 101
      app/Repositories/Post/PostRepository.php
  50. 215 0
      app/Repositories/TopicRepository.php
  51. 44 0
      app/Service/AliYunVodService.php
  52. 39 0
      app/Traits/UserTrait.php
  53. 26 0
      app/Transformers/Behavior/BehaviorLogTransformer.php
  54. 42 0
      app/Transformers/Behavior/BehaviorTransformer.php
  55. 40 0
      app/Transformers/Behavior/CommentRecordTransformer.php
  56. 39 0
      app/Transformers/Behavior/GeneralRecordTransformer.php
  57. 36 0
      app/Transformers/Behavior/RegisteredRecordTransformer.php
  58. 37 0
      app/Transformers/Behavior/ReleaseRecordTransformer.php
  59. 31 0
      app/Transformers/CategoryTransformer.php
  60. 30 0
      app/Transformers/CommunityMemberStatisticsTransformer.php
  61. 34 0
      app/Transformers/DetailCategoryTransformer.php
  62. 36 0
      app/Transformers/DetailTopicTransformer.php
  63. 28 0
      app/Transformers/DownloadTransformer.php
  64. 9 1
      app/Transformers/Post/CommentTransformer.php
  65. 1 0
      app/Transformers/Post/DetailTransformer.php
  66. 39 0
      app/Transformers/Post/LogTransformer.php
  67. 38 0
      app/Transformers/TopicTransformer.php
  68. 2 0
      bootstrap/app.php
  69. 10 7
      composer.json
  70. 20 0
      config/aliyunvod.php
  71. 11 0
      config/constants.php
  72. 3 0
      config/customer.tpl
  73. 36 0
      database/migrations/2019_06_01_062519_create_behavior_operation_log_table.php
  74. 49 0
      database/migrations/2019_06_01_074135_create_behavior_table.php
  75. 41 0
      database/migrations/2019_06_03_011812_create_registered_accounts_record_table.php
  76. 42 0
      database/migrations/2019_06_03_021228_create_comment_account_record_table.php
  77. 41 0
      database/migrations/2019_06_03_024134_create_general_ledger_record_table.php
  78. 40 0
      database/migrations/2019_06_04_011501_create_release_record_table.php
  79. 55 0
      database/migrations/2019_06_11_095634_create_table_downloads.php
  80. 30 0
      database/migrations/2019_06_11_163708_modify_download_status_to_table_download.php
  81. 32 0
      database/migrations/2019_06_13_143624_update_behavior_action_id_to_behavior_table.php
  82. 33 0
      database/migrations/2019_06_13_160051_update_behavior_id_to_behavior_operation_log_table.php
  83. 33 0
      database/migrations/2019_06_13_174844_add_comment_id_to_comment_account_record_table.php
  84. 30 0
      database/migrations/2019_06_14_090938_drop_comment_real_count_from_post_data.php
  85. 40 0
      database/migrations/2019_06_14_092948_add_reply_uid_to_table_post_comment.php
  86. 59 0
      database/migrations/2019_06_14_155026_create_table_feed.php
  87. 33 0
      database/migrations/2019_06_14_164201_add_behavior_value_to_general_ledger_record_table.php
  88. 38 0
      database/migrations/2019_06_14_192326_create_table_collect.php
  89. 38 0
      database/migrations/2019_06_14_192526_create_table_post_like.php
  90. 32 0
      database/migrations/2019_06_15_111834_add_grant_rainbow_beans_to_behavior_table.php
  91. 38 0
      database/migrations/2019_06_15_160843_create_table_post_dislike.php
  92. 32 0
      database/migrations/2019_06_15_181745_update_upper_trigger_time_to_comment_account_record_table.php
  93. 32 0
      database/migrations/2019_06_15_182120_update_trigger_time_to_general_ledger_record_table.php
  94. 32 0
      database/migrations/2019_06_15_182225_update_trigger_time_to_registered_accounts_record_table.php
  95. 32 0
      database/migrations/2019_06_15_182306_update_trigger_time_to_release_record_table.php
  96. 33 0
      database/migrations/2019_06_15_182526_update_behavioral_cycle_start_time_to_behavior_table.php
  97. 33 0
      database/migrations/2019_06_17_182656_create_member_follow_topic_table.php
  98. 38 0
      database/migrations/2019_06_18_100826_create_table_post_share.php
  99. 33 0
      database/migrations/2019_06_18_180725_update_grant_rainbow_beans_to_behavior_table.php
  100. 0 0
      database/migrations/2019_06_18_181621_update_rainbow_beans_to_behavior_table.php

+ 1 - 0
.gitignore

@@ -6,3 +6,4 @@ Homestead.yaml
 composer.lock
 /storage/*
 /config/customer.php
+/public/export/*

+ 42 - 0
app/Console/Commands/CommunityMemberStatistics.php

@@ -0,0 +1,42 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019-06-25
+ * Time: 9:58
+ */
+
+namespace App\Console\Commands;
+
+use App\Repositories\CommunityMemberStatisticsRepository;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Log;
+
+
+class CommunityMemberStatistics extends Command{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'member:statistics';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '用户行为统计';
+
+    public function __construct(CommunityMemberStatisticsRepository $communityMemberStatisticsRepository)
+    {
+        parent::__construct();
+        $this->communityMemberStatisticsRepository = $communityMemberStatisticsRepository;
+    }
+    //统计
+    public function handle(){
+        $this->line("统计用户行为数据");
+        $this->communityMemberStatisticsRepository->statistics();
+        $this->line("结束统计用户行为数据");
+    }
+}

+ 91 - 0
app/Console/Commands/Downloads.php

@@ -0,0 +1,91 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/11
+ * Time: 13:39
+ */
+
+namespace App\Console\Commands;
+
+use App\Repositories\Post\PostRepository;
+use Illuminate\Console\Command;
+use App\Models\Download;
+use Illuminate\Support\Carbon;
+
+class Downloads extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'download:download';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '处理下载';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct(Download $download, PostRepository $postRepository)
+    {
+        parent::__construct();
+        $this->download = $download;
+        $this->postRepository = $postRepository;
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $this->line("开始检索生成中下载");
+
+        $fileDir = 'export/';
+        $path = public_path($fileDir);
+        if(!file_exists($path)){
+            mkdir($path, 0775);
+        }
+
+        $download = $this->download->where('download_status', 0)->orderBy('id', 'desc')->first();
+        if(!$download) exit;
+
+        if($download->download_type == 'post'){
+            $filePath = $fileDir .$download->username.'内容-'.Carbon::now()->format('Y-m-d') .'_' .uniqid() .'.csv';
+        }elseif($download->download_type == 'post_waste'){
+            $filePath = $fileDir .$download->username.'回收站内容-'.Carbon::now()->format('Y-m-d') .'_' .uniqid() .'.csv';
+        }elseif($download->download_type == 'registered_record'){
+            $filePath = $fileDir .$download->username.'新用户注册账本-'.Carbon::now()->format('Y-m-d') .'_' .uniqid() .'.csv';
+        }elseif($download->download_type == 'comment_record'){
+            $filePath = $fileDir .$download->username.'评论账本-'.Carbon::now()->format('Y-m-d') .'_' .uniqid() .'.csv';
+        }elseif($download->download_type == 'release_record'){
+            $filePath = $fileDir .$download->username.'发布账本-'.Carbon::now()->format('Y-m-d') .'_' .uniqid() .'.csv';
+        }elseif($download->download_type == 'general_record'){
+            $filePath = $fileDir .$download->username.'唯一/普通行为账本-'.Carbon::now()->format('Y-m-d') .'_' .uniqid() .'.csv';
+        }else{
+            exit;
+        }
+        $download->download_status = 1;
+        $download->save();
+
+        try {
+            $this->postRepository->download($filePath, $download->download_type, json_decode($download->params, true));
+            $download->url = $filePath;
+            $download->download_status = 2;
+            $download->save();
+        } catch (\Exception $e) {
+            $download->download_status = 3;
+            $download->url = $e->getMessage();
+            $download->save();
+        }
+    }
+}

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 88 - 0
app/Console/Commands/MusicImport.php


+ 70 - 0
app/Console/Commands/PostCollectBean.php

@@ -0,0 +1,70 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/7/2
+ * Time: 15:58
+ */
+namespace App\Console\Commands;
+
+
+use App\Models\PostData;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Redis;
+
+class PostCollectBean extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'post:collect_bean';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '内容领取彩虹豆';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct(PostData $postData)
+    {
+        parent::__construct();
+        $this->postData = $postData;
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $this->line("开始更新内容领取彩虹豆");
+
+        $key = 'post_author_collect_bean';
+        $ids = Redis::ZRANGE($key, 0 , -1, 'WITHSCORES');
+        foreach($ids as $postId => $val){
+            try{
+                $value = Redis::ZSCORE($key, $postId);
+                Redis::ZREM ($key, $postId);
+                $this->postData->where('post_id', $postId)->increment('collect_bean', $value);
+                Log::debug('更新内容领取彩虹豆成功'.$postId.'-'.$value);
+            }catch (\Exception $exception){
+                Log::error('更新内容领取彩虹豆失败'.$postId.'-'.$val.$exception->getMessage());
+            }
+            usleep(10000);
+        }
+
+
+        $this->line("更新内容领取彩虹豆结束");
+
+    }
+}

+ 70 - 0
app/Console/Commands/PostCreateBean.php

@@ -0,0 +1,70 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/7/2
+ * Time: 14:49
+ */
+namespace App\Console\Commands;
+
+
+use App\Models\PostData;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Redis;
+
+class PostCreateBean extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'post:create_bean';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '内容生成彩虹豆';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct(PostData $postData)
+    {
+        parent::__construct();
+        $this->postData = $postData;
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $this->line("开始更新内容生成彩虹豆");
+
+        $key = 'post_create_bean';
+        $ids = Redis::ZRANGE($key, 0 , -1, 'WITHSCORES');
+        foreach($ids as $postId => $val){
+            try{
+                $value = Redis::ZSCORE($key, $postId);
+                Redis::ZREM ($key, $postId);
+                $this->postData->where('post_id', $postId)->increment('create_bean', $value);
+                Log::debug('更新内容生成彩虹豆成功'.$postId.'-'.$value);
+            }catch (\Exception $exception){
+                Log::error('更新内容生成彩虹豆失败'.$postId.'-'.$val.$exception->getMessage());
+            }
+            usleep(10000);
+        }
+
+
+        $this->line("更新内容生成彩虹豆结束");
+
+    }
+}

+ 144 - 0
app/Console/Commands/PostStatistics.php

@@ -0,0 +1,144 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/12
+ * Time: 16:32
+ */
+
+namespace App\Console\Commands;
+
+
+use App\Models\Behavior;
+use App\Models\CommentRecord;
+use App\Models\GeneralRecord;
+use App\Models\PostLog;
+use App\Models\ReleaseRecord;
+use Illuminate\Console\Command;
+use Illuminate\Support\Carbon;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Redis;
+
+class PostStatistics extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'post:statistics';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '全部内容统计';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct(\App\Models\PostStatistics $postStatistics,
+                                GeneralRecord $generalRecord,
+                                ReleaseRecord $releaseRecord,
+                                CommentRecord $commentRecord,
+                                PostLog $postLog,
+                                Behavior $behavior)
+    {
+        parent::__construct();
+        $this->postStatistics = $postStatistics;
+        $this->generalRecord = $generalRecord;
+        $this->releaseRecord = $releaseRecord;
+        $this->commentRecord = $commentRecord;
+        $this->postLog = $postLog;
+        $this->behavior = $behavior;
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $this->line("开始统计所有内容");
+        $yesterdayStart = Carbon::yesterday()->startOfDay()->toDateTimeString();
+        $yesterdayEnd = Carbon::yesterday()->endOfDay()->toDateTimeString();
+        $post = $this->releaseRecord
+            ->where([['created_at', '>=', $yesterdayStart], ['created_at', '<=', $yesterdayEnd]])
+            ->select(DB::raw('count(*) as post_count'))
+            ->first();
+        $comment = $this->commentRecord
+            ->where([['created_at', '>=', $yesterdayStart], ['created_at', '<=', $yesterdayEnd]])
+            ->select(DB::raw('count(*) as comment_count'))
+            ->first();
+        $behaviors = $this->behavior->whereIn('behavior_identification', ['read', 'like', 'share', 'collect'])->get()->toArray();
+        $postCount = $post->post_count;
+        $commentCount = $comment->comment_count;
+        $readCount = 0;
+        $likeCount = 0;
+        $shareCount = 0;
+        $collectCount = 0;
+        foreach ($behaviors as $behavior) {
+            $behaviorId = $behavior['virus_behavior_id'];
+            if ($behavior['behavior_identification'] == 'read') {
+                $read = $this->generalRecord
+                    ->where([['created_at', '>=', $yesterdayStart], ['created_at', '<=', $yesterdayEnd], ['virus_behavior_id', $behaviorId]])
+                    ->select(DB::raw('count(*) as read_count'))
+                    ->first();
+                $readCount = $read->read_count;
+            } elseif ($behavior['behavior_identification'] == 'like') {
+                $like = $this->generalRecord
+                    ->where([['created_at', '>=', $yesterdayStart], ['created_at', '<=', $yesterdayEnd], ['virus_behavior_id', $behaviorId]])
+                    ->select(DB::raw('count(*) as like_count'))
+                    ->first();
+                $likeCount = $like->like_count;
+            } elseif ($behavior['behavior_identification'] == 'share') {
+                $share = $this->generalRecord
+                    ->where([['created_at', '>=', $yesterdayStart], ['created_at', '<=', $yesterdayEnd], ['virus_behavior_id', $behaviorId]])
+                    ->select(DB::raw('count(*) as share_count'))
+                    ->first();
+                $shareCount = $share->share_count;
+            } elseif ($behavior['behavior_identification'] == 'collect') {
+                $collect = $this->generalRecord
+                    ->where([['created_at', '>=', $yesterdayStart], ['created_at', '<=', $yesterdayEnd], ['virus_behavior_id', $behaviorId]])
+                    ->select(DB::raw('count(*) as collect_count'))
+                    ->first();
+                $collectCount = $collect->collect_count;
+            }
+        }
+        Log::info(date('Y-m-d H:i:s').'统计'.$yesterdayStart.',帖子数:'.$postCount.'评论数:'.$commentCount.'阅读数:'.$readCount.'点赞数:'.$likeCount.'收藏数:'.$collectCount.'分享数:'.$shareCount);
+        $postLog = $this->postLog
+            ->where([['created_at', '>=', $yesterdayStart], ['created_at', '<=', $yesterdayEnd]])
+            ->select('content')
+            ->get()->toArray();
+        foreach ($postLog as $log){
+            $logContent = json_decode($log['content'],true);
+            if(isset($logContent['add_pv']) && $logContent['add_pv']){
+                $readCount -= $logContent['add_pv'];
+            }
+            if(isset($logContent['add_praise_count']) && $logContent['add_praise_count']){
+                $likeCount -= $logContent['add_praise_count'];
+            }
+            if(isset($logContent['add_collect_count']) && $logContent['add_collect_count']){
+                $collectCount -= $logContent['add_collect_count'];
+            }
+            if(isset($logContent['add_collect_count']) && $logContent['add_collect_count']){
+                $shareCount -= $logContent['add_collect_count'];
+            }
+            Log::debug(date('Y-m-d H:i:s').'统计虚拟数'.$yesterdayStart.',阅读数:'.$logContent['add_pv'].'点赞数:'.$logContent['add_praise_count'].'收藏数:'.$logContent['add_collect_count'].'分享数:'.$logContent['add_collect_count']);
+        }
+        $data['post_count'] = $postCount;
+        $data['read_count'] = $readCount;
+        $data['share_count'] = $shareCount;
+        $data['like_count'] = $likeCount;
+        $data['collect_count'] = $collectCount;
+        $data['comment_count'] = $commentCount;
+        $data['created_at'] = Carbon::yesterday()->toDateTimeString();
+        $this->postStatistics->create($data);
+        Log::info(date('Y-m-d H:i:s').'统计'.$yesterdayStart.'最终记录数据:'.json_encode($data));
+    }
+}

+ 69 - 0
app/Console/Commands/PostYesterday.php

@@ -0,0 +1,69 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/12
+ * Time: 16:32
+ */
+
+namespace App\Console\Commands;
+
+
+use App\Models\PostData;
+use Illuminate\Console\Command;
+use Illuminate\Support\Carbon;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Redis;
+
+class PostYesterday extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'post:yesterday';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '昨日内容统计';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct(PostData $postData)
+    {
+        parent::__construct();
+        $this->postData = $postData;
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $this->line("开始统计昨日内容");
+
+        $postData = $this->postData
+            ->where('created_at', '>=', Carbon::yesterday()->startOfDay()->toDateTimeString())
+            ->where('created_at', '<=', Carbon::yesterday()->endOfDay()->toDateTimeString())
+            ->select(DB::raw('count(*) as count'), DB::raw('sum(create_bean) as bean'))
+            ->first();
+        Log::info('统计昨日内容'.json_encode($postData));
+        Log::debug('统计昨日内容'.json_encode($postData));
+
+        Redis::set('yesterday_post_count', $postData->count);
+        Redis::set('yesterday_post_create_bean', $postData->bean);
+
+        $this->line("统计昨日内容结束");
+
+    }
+}

+ 211 - 0
app/Console/Commands/VirusAdd.php

@@ -0,0 +1,211 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/24
+ * Time: 9:52
+ */
+namespace App\Console\Commands;
+
+
+use GuzzleHttp\Exception\RequestException;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Log;
+use PhpAmqpLib\Connection\AMQPStreamConnection;
+use GuzzleHttp\Client;
+
+class VirusAdd extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'virus:add';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'virus添加数据';
+
+    protected $channel;
+    protected $connection;
+
+    protected $queue = 'virus_add';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+        $this->connection = $this->getConnection();
+        $this->channel = $this->connection->channel();
+        $this->channel->exchange_declare($this->queue, 'fanout', false, true, false);
+
+    }
+
+    public function getConnection()
+    {
+        $conn = false;
+        if ($this->connection) {
+            return $this->connection;
+        }
+        for ($i = 0; $i < 3; $i++) {
+            $connection = $this->createConn();
+            if ($connection) {
+                $conn = $connection;
+                break;
+            }
+            Log::info("create amqp conn retry=" . $i);
+        }
+        return $conn;
+    }
+
+    public function createConn()
+    {
+        try {
+            $connection = new AMQPStreamConnection(env('MQ_HOST'), env('MQ_PORT'), env('MQ_USERNAME'), env('MQ_PWD'), env('MQ_VHOST'));
+        } catch (\Exception $exception) {
+            Log::info("AMQP connection Error" . $exception->getMessage());
+            $connection = false;
+        }
+        return $connection;
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $queue_name = $this->queue;
+        $this->channel->queue_declare($queue_name, false, true, false, false);
+        $this->channel->queue_bind($queue_name, $this->queue);
+        $callback = function ($msg) {
+            $this->line(date('Y-m-d H:i:S').$msg->body);
+            $data = \GuzzleHttp\json_decode($msg->body, true);
+            $this->line('接收一条消息收到数据' . $msg->body);
+            $res = $this->send($data);
+            if ($res) {
+                $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
+            }
+        };
+        $this->channel->basic_consume($queue_name, '', false, false, false, false, $callback);
+
+        while (count($this->channel->callbacks)) {
+            $this->channel->wait();
+        }
+        $this->channel->close();
+        $this->connection->close();
+
+
+    }
+
+    private function send($data)
+    {
+        // 初始化virus域名
+        $client = new Client([
+            'timeout' => 3
+        ]);
+        try {
+            // 签名设置
+            $signKey = [
+                'app_id' => config('customer.VIRUS_APP_ID'),
+                'behavior_id' => $data['behavior_id'],
+                'target_id' => (string) $data['target_id'],
+                'action_id' => (string) $data['action_id'],
+                'behavior_flag' => $data['behavior_flag']
+            ];
+            ksort($signKey);
+            $signKey = urldecode(http_build_query($signKey));
+            $sign = md5(config('customer.VIRUS_APP_SECRET') . $signKey);
+            Log::debug('签名:'.$sign);
+            $json = [];
+            if($data['behavior_flag'] == 'publish'){
+                $json = [
+                    'sign' => $sign,
+                    'app_id' => config('customer.VIRUS_APP_ID'),
+                    'behavior_id' => $data['behavior_id'],
+                    'behavior_flag' => $data['behavior_flag'],
+                    'post_id' => $data['post_id'],
+                    'post_type' => $data['post_type'],
+                    'post_desc' => $data['post_desc'],
+                    'post_cover' => $data['post_cover'],
+                    'target_id' => (string) $data['target_id'],
+                    'action_id' => (string) $data['action_id'],
+                    'extra' => [],
+                ];
+            }elseif($data['behavior_flag'] == 'comment'){
+                $json = [
+                    'sign' => $sign,
+                    'app_id' => config('customer.VIRUS_APP_ID'),
+                    'behavior_id' => $data['behavior_id'],
+                    'behavior_flag' => $data['behavior_flag'],
+                    'post_id' => $data['post_id'],
+                    'post_type' => $data['post_type'],
+                    'post_author_uid' => $data['post_author_uid'],
+                    'post_desc' => $data['post_desc'],
+                    'post_cover' => $data['post_cover'],
+                    'comment_id' => $data['comment_id'],
+                    'comment_content' => $data['comment_content'],
+                    'parent_comment_id' => $data['parent_comment_id'],
+                    'parent_comment_content' => $data['parent_comment_content'],
+                    'parent_comment_uid' => $data['parent_comment_uid'],
+                    'parent_comment_time' => $data['parent_comment_time'],
+                    'reply_uid' => $data['reply_uid'],
+                    'reply_username' => $data['reply_username'],
+                    'target_id' => (string) $data['target_id'],
+                    'action_id' => (string) $data['action_id'],
+                    'extra' => [],
+                ];
+            }elseif(in_array($data['behavior_flag'], ['read', 'like', 'collect', 'forward'])){
+                $json = [
+                    'sign' => $sign,
+                    'app_id' => config('customer.VIRUS_APP_ID'),
+                    'behavior_id' => $data['behavior_id'],
+                    'behavior_flag' => $data['behavior_flag'],
+                    'behavior_value' => $data['behavior_value'],
+                    'post_id' => $data['post_id'],
+                    'post_type' => $data['post_type'],
+                    'post_author_uid' => $data['post_author_uid'],
+                    'post_desc' => $data['post_desc'],
+                    'post_cover' => $data['post_cover'],
+                    'target_id' => (string) $data['target_id'],
+                    'action_id' => (string) $data['action_id'],
+                    'extra' => [],
+                ];
+            }elseif($data['behavior_flag'] == 'register'){
+                $json = [
+                    'sign' => $sign,
+                    'app_id' => config('customer.VIRUS_APP_ID'),
+                    'behavior_id' => $data['behavior_id'],
+                    'behavior_flag' => $data['behavior_flag'],
+                    'source_id' => $data['source_id'],
+                    'target_id' => (string) $data['target_id'],
+                    'action_id' => (string) $data['action_id'],
+                    'extra' => [],
+                ];
+            }else{
+                Log::debug('行为类型错误'.json_encode($data));
+                return true;
+            }
+
+            $response = $client->request('POST', config('customer.VIRUS_URL').'/v2/record/add', [
+                'headers' => [
+                    'Content-Type' => 'application/json'
+                ],
+                'json' => $json
+            ]);
+            Log::debug('virus添加数据成功:'.$response->getBody()->getContents());
+            return true;
+        } catch (RequestException $e) {
+            Log::debug('virus添加数据失败:'.$e->getMessage());
+        }
+    }
+}

+ 41 - 2
app/Console/Kernel.php

@@ -3,6 +3,14 @@
 namespace App\Console;
 
 use App\Console\Commands\Apollo;
+use App\Console\Commands\CommunityMemberStatistics;
+use App\Console\Commands\Downloads;
+use App\Console\Commands\MusicImport;
+use App\Console\Commands\PostCollectBean;
+use App\Console\Commands\PostCreateBean;
+use App\Console\Commands\PostStatistics;
+use App\Console\Commands\PostYesterday;
+use App\Console\Commands\VirusAdd;
 use Illuminate\Console\Scheduling\Schedule;
 use Laravel\Lumen\Console\Kernel as ConsoleKernel;
 
@@ -14,7 +22,15 @@ class Kernel extends ConsoleKernel
      * @var array
      */
     protected $commands = [
-        Apollo::class
+        Apollo::class,
+        PostYesterday::class,
+        Downloads::class,
+        VirusAdd::class,
+        PostStatistics::class,
+        PostCreateBean::class,
+        PostCollectBean::class,
+        CommunityMemberStatistics::class,
+        MusicImport::class
     ];
 
     /**
@@ -25,6 +41,29 @@ class Kernel extends ConsoleKernel
      */
     protected function schedule(Schedule $schedule)
     {
-        //
+        $path = storage_path('logs/'.date('Y-m-d').'-schedule.log');
+
+        $schedule->command('download:download')
+            ->everyMinute()
+            ->withoutOverlapping()->appendOutputTo($path);
+
+        $schedule->command('post:yesterday')
+            ->dailyAt('00:10')
+            ->withoutOverlapping()->appendOutputTo($path);
+        $schedule->command('post:statistics')
+            ->dailyAt('00:20')
+            ->withoutOverlapping()->appendOutputTo($path);
+        //统计前一天用户行为累加
+        $schedule->command('member:statistics')
+            ->dailyAt('00:05')
+            ->withoutOverlapping()->appendOutputTo($path);
+        //内容生成彩虹豆
+        $schedule->command('post:create_bean')
+            ->everyFiveMinutes()
+            ->withoutOverlapping()->appendOutputTo($path);
+        //内容收取彩虹豆
+        $schedule->command('post:collect_bean')
+            ->everyFiveMinutes()
+            ->withoutOverlapping()->appendOutputTo($path);
     }
 }

+ 64 - 4
app/Helper/helper.php

@@ -15,13 +15,73 @@ if ( ! function_exists('config_path'))
     {
         return app()->basePath() . '/config' . ($path ? '/' . $path : $path);
     }
+}
 
-    function subtext($text, $length)
+if (! function_exists('public_path')) {
+    /**
+     * Get the path to the public folder.
+     *
+     * @param  string  $path
+     * @return string
+     */
+    function public_path($path = '')
     {
-        if(mb_strlen($text, 'utf8') > $length) {
-            return mb_substr($text, 0, $length, 'utf8').'...';
-        } else {
+        return app()->basePath() . '/public' . ($path ? '/' . $path : $path);
+    }
+}
+
+function subtext($text, $length)
+{
+    if(mb_strlen($text, 'utf8') > $length) {
+        return mb_substr($text, 0, $length, 'utf8').'...';
+    } else {
         return $text;
     }
 }
+
+
+function http($url, $param, $isCheck = true, $method = 'post')
+{
+    try {
+        $client = new \GuzzleHttp\Client();
+        $response = $client->request($method, $url, $param);
+        $result = json_decode($response->getBody()->getContents(), true);
+        \Illuminate\Support\Facades\Log::debug('url:'.$url.'param:'.json_encode($param).'response:'.json_encode($result));
+        if ($isCheck == true) {
+            if ($result['code'] == 0) {
+                return $result['data'];
+            } else {
+                return [];
+            }
+        } else {
+            return $result;
+        }
+
+    } catch (\Exception $exception) {
+        \Illuminate\Support\Facades\Log::debug('http-exception:'.$exception->getMessage());
+        return [];
+    }
+}
+
+
+function generateSign(array $params, $secret_key)
+{
+    unset($params['sign']);
+    // 将删除参数组中所有等值为FALSE的参数(包括:NULL, 空字符串,0, false)
+    $params = array_filter($params);
+
+    // 按照键名对参数数组进行升序排序
+    ksort($params);
+
+    // 给参数数组追加密钥,键名为 key, 值为签名配置中配置的 secret_key 的值
+    $params['chxq_key'] = $secret_key;
+    \Illuminate\Support\Facades\Log::debug($params);
+    // 生成 URL-encode 之后的请求字符串
+    $str = http_build_query($params);
+    $str = urldecode($str);
+    \Illuminate\Support\Facades\Log::debug($str);
+    //$str = "address=计算机啊手机壳阿看见手机卡&address_type=1&area_id=2&area_name=西安市&city_id=2&city_name=西安市&contact_mobile
+    //=18458881890&contact_name=刘德华&province_id=1&province_name=陕西省&uid=0&zipcode=1000000";
+    // 将请求字符串使用MD5加密后,再转换成大写,并返回
+    return strtoupper(MD5($str));
 }

+ 81 - 0
app/Http/Controllers/AliYunVodController.php

@@ -0,0 +1,81 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019-06-15
+ * Time: 10:53
+ */
+
+namespace App\Http\Controllers;
+
+
+use App\Service\AliYunVodService;
+use function GuzzleHttp\Psr7\str;
+use Illuminate\Http\Request;
+use Illuminate\Http\Response;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Validator;
+use ShaoZeMing\AliVod\SDK\GetPlayInfoRequest;
+use ShaoZeMing\AliVod\Services\UploadService;
+use ShaoZeMing\Aliyun\Core\DefaultAcsClient;
+use ShaoZeMing\Aliyun\Core\Profile\DefaultProfile;
+
+class AliYunVodController extends Controller
+{
+    public function __construct(AliYunVodService $aliYunVodService)
+    {
+        $this->aliYunVodService = $aliYunVodService;
+    }
+
+    /**
+     * 获取视频上传凭证信息
+     * @param Request $request
+     * @return array
+     * @throws \ShaoZeMing\Aliyun\Core\Exception\ClientException
+     * @throws \ShaoZeMing\Aliyun\Core\Exception\ServerException
+     */
+    public function getVodUploadAuth(Request $request)
+    {
+        $request = $request->all();
+        $validator = Validator::make($request, [
+            'title' => 'required',
+            'filename' => 'required'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(),500);
+        }
+        $instance = new UploadService(config('aliyunvod'));
+        $title = $request['title'];
+        $filename = $request['filename'];
+        $coverUrl = isset($request['cover_url']) ?$request['cover_url']:'';
+        try {
+            $result = $instance->createUploadVideo($title, $filename, '', $coverUrl);  //获取视频上传地址和凭证
+            $authInfo['UploadAddress'] = $result->UploadAddress;
+            $authInfo['VideoId'] = $result->VideoId;
+            $authInfo['RequestId'] = $result->RequestId;
+            $authInfo['UploadAuth'] = $result->UploadAuth;
+            return $authInfo;
+        } catch (\Exception $e) {
+            return $this->response->error('获取上传凭证失败' . $e->getMessage(),500);
+        }
+    }
+
+    /**
+     * //根据videoId获取播放地址
+     * @param Request $request
+     * @return array|void
+     */
+    public function getPlayUrlByVideoId(Request $request)
+    {
+        $request = $request->all();
+        $validator = Validator::make($request, [
+            'video_id' => 'required'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(),500);
+        }
+        $videoId = $request['video_id'];
+        $url = $this->aliYunVodService->getPlayUrlByVideoId($videoId);
+        return ['url'=>$url];
+    }
+}

+ 170 - 0
app/Http/Controllers/Behavior/BehaviorController.php

@@ -0,0 +1,170 @@
+<?php
+namespace App\Http\Controllers\Behavior;
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/12
+ * Time: 上午11:09
+ */
+use App\Http\Controllers\Controller;
+use App\Models\Behavior;
+use App\Repositories\Behavior\BehaviorRepository;
+use App\Transformers\Behavior\BehaviorTransformer;
+use Illuminate\Http\Request;
+use Illuminate\Validation\Rule;
+use Illuminate\Support\Facades\Validator;
+use League\Fractal\Manager;
+use League\Fractal\Pagination\IlluminatePaginatorAdapter;
+use League\Fractal\Resource\Collection;
+
+class BehaviorController extends Controller
+{
+    public function __construct(BehaviorRepository $behaviorRepository)
+    {
+        $this->behaviorRepository = $behaviorRepository;
+    }
+
+    /**
+     * 行为列表
+     */
+    public function index(Request $request)
+    {
+        $behavior_list = $this->behaviorRepository->lists($request->all());
+        if (count($behavior_list)>0){
+            foreach ($behavior_list as $k=>$v){
+                if (isset($behavior_list[$k]['_id']) || isset($behavior_list[$k]['behavior_name'])){
+                    $behavior_list[$k]['_id'] = $v['_id'];
+                    $behavior_list[$k]['behavior_name'] = $v['behavior_name'];
+                    $behavior_list[$k]['virus_behavior_id'] = $v['_id'];
+                    $behavior_list[$k]['name'] = $v['behavior_name'];
+                    unset($behavior_list[$k]['_id']);
+                    unset($behavior_list[$k]['behavior_name']);
+                }
+            }
+        }
+        $data['data'] = $behavior_list;
+        $data['extra'] = [
+            'filters' => [
+                'virus_behavior_id',
+                'behavior_status',
+                'name',
+            ],
+            'columns' => [
+                'id',
+                'virus_behavior_id',
+                'name',
+                'behavior_level',
+                'behavior_cycle_type',
+                'behavior_cycle',
+                'physical_strength',
+                'rainbow_beans',
+                'remarks',
+                'is_open',
+                'created_at',
+                'behavioral_cycle_start_time',
+                'behavioral_cycle_end_time'
+            ]
+        ];
+        return $data;
+    }
+
+
+    //登记行为
+    public function create(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'virus_behavior_id' => 'required',
+            'rainbow_beans' => 'required',
+            'name' => 'required|string',
+            'behavior_level' => ['required',Rule::in(0, 1)],
+            'behavior_cycle_type' => ['required',Rule::in(0, 1)],
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->behaviorRepository->create($request->all());
+    }
+
+    //编辑行为
+    public function edit(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|exists:behavior',
+            'virus_behavior_id' => 'required',
+            'name' => 'required|string',
+            'behavior_level' => 'required|integer',
+            'behavior_cycle_type' => ['required',Rule::in(0, 1)],
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->behaviorRepository->edit($request->all());
+
+    }
+
+    //行为管理
+    public function editStatus(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|exists:behavior',
+            'is_open' => ['required', Rule::in(0,1)],
+        ]);
+
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->behaviorRepository->editStatus($request->all());
+    }
+
+    //行为数据列表
+    public function behaviorData(Request $request)
+    {
+        $behavior_list = $this->behaviorRepository->dataList($request->all());
+
+        $fractal = new Manager();
+        $resource = new Collection($behavior_list, new BehaviorTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($behavior_list));
+        $data = $fractal->createData($resource)->toArray();
+        $data['extra'] = [
+            'filters' => [
+                'id',
+                'is_open',
+                'behavior_level',
+                'name',
+                'sort',
+                'search'
+            ],
+            'columns' => [
+                'id',
+                'virus_behavior_id',
+                'name',
+                'behavior_level',
+                'behavior_cycle_type',
+                'behavior_action_id',
+                'behavior_cycle',
+                'behavior_binding_users',
+                'physical_strength',
+                'rainbow_beans',
+                'remarks',
+                'is_open',
+                'behavioral_cycle_start_time',
+                'behavioral_cycle_end_time',
+                'allotted_quantity_rule',
+                'behavior_identification',
+                'trigger_times',
+                'effective_trigger',
+                'relative_series',
+                'absolute_progression',
+                'grant_rainbow_beans',
+                'created_at',
+                'updated_at',
+                'all_is_open',
+                'all_effective_trigger',
+                'all_rainbow_beans',
+                'all_grant_beans'
+            ]
+        ];
+        return $data;
+    }
+
+}

+ 80 - 0
app/Http/Controllers/Behavior/CommentRecordController.php

@@ -0,0 +1,80 @@
+<?php
+
+namespace App\Http\Controllers\Behavior;
+
+use App\Http\Controllers\Controller;
+use App\Models\CommentRecord;
+use App\Repositories\Behavior\CommentRecordRepository;
+use App\Transformers\Behavior\CommentRecordTransformer;
+use Illuminate\Http\Request;
+use League\Fractal\Manager;
+use League\Fractal\Pagination\IlluminatePaginatorAdapter;
+use League\Fractal\Resource\Collection;
+
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/14
+ * Time: 下午6:06
+ */
+class CommentRecordController extends Controller
+{
+    public function __construct(CommentRecordRepository $commentRecordRepository)
+    {
+        $this->commentRecordRepository = $commentRecordRepository;
+    }
+
+    /**
+     * 评论账本列表
+     */
+    public function index(Request $request)
+    {
+        $commentList = $this->commentRecordRepository->lists($request->all());
+
+        $behavior_trigger_times = CommentRecord::select('trigger_type')->where('trigger_type', '!=', null)->count();//总触发数
+        $behavior_effective_trigger = CommentRecord::select('trigger_type')->where('trigger_type', 1)->count();//有效触发数
+        $physical_exertion = CommentRecord::select('physical_exertion')->sum('physical_exertion');//总消耗体力值
+        $generation_quantity = CommentRecord::select('generation_quantity')->sum('generation_quantity');//总生成彩虹豆
+        $quantity_issued = CommentRecord::select('quantity_issued')->sum('quantity_issued');//总发放彩虹豆
+
+        $fractal = new Manager();
+        $resource = new Collection($commentList, new CommentRecordTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($commentList));
+        $data = $fractal->createData($resource)->toArray();
+        $data['extra'] = [
+            'statistics' => [
+                'all_trigger_times' => $behavior_trigger_times,
+                'all_effective_trigger' => $behavior_effective_trigger,
+                'physical_exertion' => intval($physical_exertion),
+                'generation_quantity' => intval($generation_quantity),
+                'quantity_issued' => intval($quantity_issued)
+            ],
+            'filters' => [
+                'id',
+                'uid',
+                'created_at',
+                'trigger_type',
+                'content_author_id',
+                'related_content_id',
+                'superior_commentator_id',
+                'virus_behavior_id'
+            ],
+            'columns' => [
+                'id',
+                'created_at',
+                'uid',
+                'related_content_id',
+                'content_author_id',
+                'superior_commentator_id',
+                'physical_exertion',
+                'trigger_type',
+                'generation_type',
+                'superior_uid',
+                'release_status',
+                'generation_quantity',
+                'quantity_issued',
+            ]
+        ];
+        return $data;
+    }
+}

+ 81 - 0
app/Http/Controllers/Behavior/GeneralRecordController.php

@@ -0,0 +1,81 @@
+<?php
+
+namespace App\Http\Controllers\Behavior;
+
+use App\Http\Controllers\Controller;
+use App\Models\GeneralRecord;
+use App\Models\ReleaseRecord;
+use App\Repositories\Behavior\GenaralRecordRepository;
+use App\Repositories\Behavior\ReleaseRecordRepository;
+use App\Transformers\Behavior\GeneralRecordTransformer;
+use App\Transformers\Behavior\ReleaseRecordTransformer;
+use Illuminate\Http\Request;
+use League\Fractal\Manager;
+use League\Fractal\Pagination\IlluminatePaginatorAdapter;
+use League\Fractal\Resource\Collection;
+
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/14
+ * Time: 下午8:40
+ */
+class GeneralRecordController extends Controller
+{
+    public function __construct(GenaralRecordRepository $genaralRecordRepository)
+    {
+        $this->genaralRecordRepository = $genaralRecordRepository;
+    }
+
+    /**
+     * 普通行为账本列表
+     */
+    public function index(Request $request)
+    {
+        $genaralList = $this->genaralRecordRepository->lists($request->all());
+
+        $behavior_trigger_times = GeneralRecord::select('trigger_type')->where('trigger_type', '!=', null)->count();//总触发数
+        $behavior_effective_trigger = GeneralRecord::select('trigger_type')->where('trigger_type', 1)->count();//有效触发数
+        $physical_exertion = GeneralRecord::select('physical_exertion')->sum('physical_exertion');//总消耗体力值
+        $generation_quantity = GeneralRecord::select('generation_quantity')->sum('generation_quantity');//总生成彩虹豆
+        $quantity_issued = GeneralRecord::select('quantity_issued')->sum('quantity_issued');//总发放彩虹豆
+
+        $fractal = new Manager();
+        $resource = new Collection($genaralList, new GeneralRecordTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($genaralList));
+        $data = $fractal->createData($resource)->toArray();
+        $data['extra'] = [
+            'statistics' => [
+                'all_trigger_times' => $behavior_trigger_times,
+                'all_effective_trigger' => $behavior_effective_trigger,
+                'physical_exertion' => intval($physical_exertion),
+                'generation_quantity' => intval($generation_quantity),
+                'quantity_issued' => intval($quantity_issued)
+            ],
+            'filters' => [
+                'id',
+                'uid',
+                'created_at',
+                'trigger_type',
+                'content_author_id',
+                'related_content_id',
+                'behavior_identification',
+                'virus_behavior_id'
+            ],
+            'columns' => [
+                'id',
+                'created_at',
+                'uid',
+                'related_content_id',
+                'content_author_id',
+                'physical_exertion',
+                'trigger_type',
+                'generation_type',
+                'release_status',
+                'generation_quantity',
+                'quantity_issued',
+            ]
+        ];
+        return $data;
+    }
+}

+ 52 - 0
app/Http/Controllers/Behavior/LogController.php

@@ -0,0 +1,52 @@
+<?php
+namespace App\Http\Controllers\Behavior;
+use App\Http\Controllers\Controller;
+use App\Repositories\Behavior\BehaviorLogRepository;
+use App\Transformers\Behavior\BehaviorLogTransformer;
+use Illuminate\Http\Request;
+use League\Fractal\Manager;
+use League\Fractal\Pagination\IlluminatePaginatorAdapter;
+use League\Fractal\Resource\Collection;
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/13
+ * Time: 下午7:01
+ */
+
+class LogController extends Controller
+{
+    public function __construct(BehaviorLogRepository $behaviorLogRepository)
+    {
+        $this->behaviorLogRepository = $behaviorLogRepository;
+    }
+
+    //日志列表
+    public function index(Request $request)
+    {
+        $logList = $this->behaviorLogRepository->log($request->all());
+        $fractal = new Manager();
+        $resource = new Collection($logList, new BehaviorLogTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($logList));
+        $data = $fractal->createData($resource)->toArray();
+
+        $data['extra'] = [
+            'filters' => [
+                'type',
+                'created_at',
+            ],
+            'columns' => [
+                'id',
+                'username',
+                'behavior_id',
+                'operator_id',
+                'type',
+                'created_at',
+                'content',
+            ]
+        ];
+        return $data;
+
+    }
+
+}

+ 78 - 0
app/Http/Controllers/Behavior/RegisteredRecordController.php

@@ -0,0 +1,78 @@
+<?php
+
+namespace App\Http\Controllers\Behavior;
+
+use App\Http\Controllers\Controller;
+use App\Models\RegisteredRecord;
+use App\Repositories\Behavior\RegisteredRecordRepository;
+use App\Transformers\Behavior\RegisteredRecordTransformer;
+use League\Fractal\Manager;
+use League\Fractal\Pagination\IlluminatePaginatorAdapter;
+use League\Fractal\Resource\Collection;
+use Illuminate\Http\Request;
+
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/14
+ * Time: 上午11:30
+ */
+class RegisteredRecordController extends Controller
+{
+    public function __construct(RegisteredRecordRepository $registeredRecordRepository)
+    {
+        $this->registeredRecordRepository = $registeredRecordRepository;
+    }
+
+    /**
+     * 新用户注册账本列表
+     */
+    public function index(Request $request)
+    {
+        $registeredList = $this->registeredRecordRepository->lists($request->all());
+
+        $behavior_absolute_progression = RegisteredRecord::select('absolute_progression')->orderBy('id', 'DESC')->first();//行为绝对级数
+        $behavior_trigger_times = RegisteredRecord::select('trigger_type')->where('trigger_type', '!=', null)->count();//总触发数
+        $behavior_effective_trigger = RegisteredRecord::select('trigger_type')->where('trigger_type', 1)->count();//有效触发数
+        $physical_exertion = RegisteredRecord::select('physical_exertion')->sum('physical_exertion');//总消耗体力值
+        $generation_quantity = RegisteredRecord::select('generation_quantity')->sum('generation_quantity');//总生成彩虹豆
+        $quantity_issued = RegisteredRecord::select('quantity_issued')->sum('quantity_issued');//总发放彩虹豆
+
+        $fractal = new Manager();
+        $resource = new Collection($registeredList, new RegisteredRecordTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($registeredList));
+        $data = $fractal->createData($resource)->toArray();
+        $data['extra'] = [
+            'statistics' => [
+                'all_absolute_progression' => $behavior_absolute_progression->absolute_progression ?? 0,
+                'all_trigger_times' => $behavior_trigger_times,
+                'all_effective_trigger' => $behavior_effective_trigger,
+                'physical_exertion' => intval($physical_exertion),
+                'generation_quantity' => intval($generation_quantity),
+                'quantity_issued' => intval($quantity_issued)
+            ],
+            'filters' => [
+                'id',
+                'uid',
+                'created_at',
+                'absolute_progression',
+                'trigger_type',
+                'virus_behavior_id'
+            ],
+            'columns' => [
+                'id',
+                'created_at',
+                'uid',
+                'physical_exertion',
+                'trigger_type',
+                'generation_type',
+                'absolute_progression',
+                'superior_uid',
+                'release_status',
+                'generation_quantity',
+                'quantity_issued',
+            ]
+        ];
+        return $data;
+    }
+}

+ 74 - 0
app/Http/Controllers/Behavior/ReleaseRecordController.php

@@ -0,0 +1,74 @@
+<?php
+
+namespace App\Http\Controllers\Behavior;
+
+use App\Http\Controllers\Controller;
+use App\Models\ReleaseRecord;
+use App\Repositories\Behavior\ReleaseRecordRepository;
+use App\Transformers\Behavior\ReleaseRecordTransformer;
+use Illuminate\Http\Request;
+use League\Fractal\Manager;
+use League\Fractal\Pagination\IlluminatePaginatorAdapter;
+use League\Fractal\Resource\Collection;
+
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/14
+ * Time: 下午8:17
+ */
+class ReleaseRecordController extends Controller
+{
+    public function __construct(ReleaseRecordRepository $releaseRecordRepository)
+    {
+        $this->releaseRecordRepository = $releaseRecordRepository;
+    }
+
+    /**
+     * 发布账本列表
+     */
+    public function index(Request $request)
+    {
+        $releaseList = $this->releaseRecordRepository->lists($request->all());
+
+        $behavior_trigger_times = ReleaseRecord::select('trigger_type')->where('trigger_type', '!=', null)->count();//总触发数
+        $behavior_effective_trigger = ReleaseRecord::select('trigger_type')->where('trigger_type', 1)->count();//有效触发数
+        $physical_exertion = ReleaseRecord::select('physical_exertion')->sum('physical_exertion');//总消耗体力值
+        $generation_quantity = ReleaseRecord::select('generation_quantity')->sum('generation_quantity');//总生成彩虹豆
+        $quantity_issued = ReleaseRecord::select('quantity_issued')->sum('quantity_issued');//总发放彩虹豆
+
+        $fractal = new Manager();
+        $resource = new Collection($releaseList, new ReleaseRecordTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($releaseList));
+        $data = $fractal->createData($resource)->toArray();
+        $data['extra'] = [
+            'statistics' => [
+                'all_trigger_times' => $behavior_trigger_times,
+                'all_effective_trigger' => $behavior_effective_trigger,
+                'physical_exertion' => intval($physical_exertion),
+                'generation_quantity' => intval($generation_quantity),
+                'quantity_issued' => intval($quantity_issued)
+            ],
+            'filters' => [
+                'id',
+                'uid',
+                'created_at',
+                'trigger_type',
+                'related_content_id'
+            ],
+            'columns' => [
+                'id',
+                'created_at',
+                'uid',
+                'related_content_id',
+                'physical_exertion',
+                'trigger_type',
+                'generation_type',
+                'release_status',
+                'generation_quantity',
+                'quantity_issued',
+            ]
+        ];
+        return $data;
+    }
+}

+ 71 - 1
app/Http/Controllers/ConfigController.php

@@ -27,6 +27,14 @@ class ConfigController extends Controller
                 'video' => '视频',
                 'html' => '富文本',
             ],
+            //内容排序
+            'sort' => [
+                'praise_count' => '点赞数',
+                'share_count' => '分享数',
+                'pv' => '浏览量',
+                'comment_count' => '评论数',
+                'create_bean' => '彩虹豆数',
+            ],
             //日志类型
             'log_type' => [
                 'add_data' => '增加数据',
@@ -56,7 +64,69 @@ class ConfigController extends Controller
                 '1' => '是',
                 '0' => '否',
             ],
-
+            //下载类型
+            'download_type' => [
+                'post' => '内容',
+                'post_waste' => '内容回收站',
+                'registered_record' => '新用户注册账本',
+                'comment_record' => '评论账本',
+                'release_record' => '发布账本',
+                'general_record' => '普通/唯一行为账本'
+            ],
+            //下载状态
+            'download_status' => [
+                '1' => '生成中',
+                '0' => '待处理',
+                '2' => '成功',
+                '3' => '失败',
+            ],
+            'topic_status'=>[
+                'is_suggest'=>'推荐话题',
+                'is_hot'=>'热门话题',
+                'is_open'=>'开启',
+                'is_close'=>'关闭',
+            ],
+            'banner_type'=>[
+                0=>'纯展示',
+                1=>'内容',
+                2=>'用户',
+                3=>'活动',
+                4=>'话题',
+            ],
+            'floor_type'=>[
+                0=>'banner',
+                1=>'推荐关注',
+                2=>'热门视频',
+                3=>'推荐话题',
+             ],
+            'behavior_status'=>[
+                '1' => '已登记行为',
+                '0' => '未登记行为'
+            ],
+            //行为级别
+            'behavior_level'=>[
+                '1'=>'多级行为',
+                '0'=>'唯一/基础行为'
+            ],
+            //行为周期类型
+            'behavior_cycle_type'=>[
+                '1'=>'长期',
+                '0'=>'普通/短期'
+            ],
+            //触发类型
+            'trigger_type'=>[
+                '1'=>'有效触发',
+                '0'=>'无效触发'
+            ],
+            //发放状态
+            'release_status'=>[
+                '1'=>'正常',
+                '0'=>'异常'
+            ],
+            //行为绑定用户
+            'behavior_binding_users'=>[
+                0=>'所有用户'
+            ]
         ];
     }
 }

+ 67 - 0
app/Http/Controllers/DownloadController.php

@@ -0,0 +1,67 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/11
+ * Time: 10:39
+ */
+
+namespace App\Http\Controllers;
+
+use App\Repositories\DownloadRepository;
+use App\Transformers\DownloadTransformer;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Validator;
+use League\Fractal\Manager;
+use League\Fractal\Pagination\IlluminatePaginatorAdapter;
+use League\Fractal\Resource\Collection;
+use Illuminate\Validation\Rule;
+
+
+class DownloadController extends Controller
+{
+    public function __construct(DownloadRepository $downloadRepository)
+    {
+        $this->downloadRepository = $downloadRepository;
+    }
+
+    /**
+     * 下载列表
+     */
+    public function index(Request $request)
+    {
+        $productList = $this->downloadRepository->lists($request->all());
+        $fractal = new Manager();
+        $resource = new Collection($productList, new DownloadTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($productList));
+        $data = $fractal->createData($resource)->toArray();
+        $data['extra'] = [
+            'filters' => [
+                'download_type'
+            ],
+            'columns' => [
+                'id',
+                'username',
+                'download_type',
+                'download_status',
+                'url',
+                'created_at'
+            ]
+        ];
+        return $data;
+    }
+
+    /**
+     * 添加下载
+     */
+    public function create(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'download_type' => ['required',Rule::in('post', 'post_waste','registered_record','comment_record','release_record','general_record')],
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->downloadRepository->create($request->all());
+    }
+}

+ 37 - 0
app/Http/Controllers/MemberStatisticsController.php

@@ -0,0 +1,37 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019-06-26
+ * Time: 9:43
+ */
+namespace App\Http\Controllers;
+
+use App\Transformers\CommunityMemberStatisticsTransformer;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Validator;
+
+use App\Repositories\CommunityMemberStatisticsRepository;
+
+class MemberStatisticsController extends Controller {
+    public function __construct(CommunityMemberStatisticsRepository $memberStatistics) {
+        $this->memberStatistics = $memberStatistics;
+    }
+    //测试
+    public function index(){
+        $this->memberStatistics->statistics();
+    }
+    public function view(Request $request){
+        $data = $request->only('uid');
+        $validator = Validator::make($data, [
+            'uid' => 'required|integer',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        $info = $this->memberStatistics->view($data['uid']);
+        if($info){
+            return $this->response->item($info, new CommunityMemberStatisticsTransformer());
+        }
+    }
+}

+ 133 - 8
app/Http/Controllers/Post/PostController.php

@@ -11,7 +11,9 @@ namespace App\Http\Controllers\Post;
 use App\Repositories\Post\PostRepository;
 use App\Transformers\Post\CommentTransformer;
 use App\Transformers\Post\DetailTransformer;
+use App\Transformers\Post\LogTransformer;
 use App\Transformers\Post\PostTransformer;
+use Carbon\Carbon;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Validator;
 use App\Http\Controllers\Controller;
@@ -54,7 +56,6 @@ class PostController extends Controller
                 'created_at',
                 'uid',
                 'topic',
-                'content',
                 'location',
                 'pv',
                 'praise_count',
@@ -69,6 +70,45 @@ class PostController extends Controller
         return $data;
     }
 
+    /**
+     * 回收站列表
+     */
+    public function waste(Request $request)
+    {
+        $params = $request->all();
+        $params['waste'] = 1;
+        $productList = $this->postRepository->lists($params);
+        $fractal = new Manager();
+        $resource = new Collection($productList, new PostTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($productList));
+        $data = $fractal->createData($resource)->toArray();
+        $data['extra'] = [
+            'filters' => [
+                'content',
+                'topic_ids',
+                'category_ids',
+                'created_at',
+                'sort'
+            ],
+            'columns' => [
+                'id',
+                'created_at',
+                'uid',
+                'topic',
+                'content',
+                'location',
+                'pv',
+                'praise_count',
+                'share_count',
+                'comment_count',
+                'collect_count',
+                'create_bean',
+                'is_suggest',
+            ]
+        ];
+        return $data;
+    }
+
     /**
      * 内容详情
      */
@@ -81,16 +121,35 @@ class PostController extends Controller
             return $this->response->error($validator->errors()->first(), 500);
         }
 
+        $post = $this->postRepository->detail($request->all());
+        return $this->response->item($post, new DetailTransformer());
+    }
+
+    /**
+     * 评论列表
+     */
+    public function commentList(Request $request)
+    {
         $commentList = $this->postRepository->commentList($request->all());
         $fractal = new Manager();
         $resource = new Collection($commentList, new CommentTransformer());
         $resource->setPaginator(new IlluminatePaginatorAdapter($commentList));
         $data = $fractal->createData($resource)->toArray();
 
-        $post = $this->postRepository->detail($request->all());
-        $base = new Item($post, new DetailTransformer());
-        $base = $fractal->createData($base)->toArray();
-        $data['extra'] = $base['data'];
+        $data['extra'] = [
+            'filters' => [
+
+            ],
+            'columns' => [
+                'id',
+                'post_id',
+                'parent_id',
+                'uid',
+                'content',
+                'created_at',
+                'is_delete',
+            ]
+        ];
         return $data;
     }
 
@@ -105,10 +164,11 @@ class PostController extends Controller
             'is_suggest' => ['required',Rule::in(0, 1)],
             'img' => 'required|url',
             'video' => 'required_if:type,video|string|url',
+            'video_id' => 'required_if:type,video|string',
             'topic_ids' => 'required|string|max:64',
-            'title' => 'nullable|string|max:20',
-            'content' => 'required|string|max:1000',
-            'location' => 'required|string',
+            'title' => 'required_if:type,html|string|max:20',
+            'content' => 'required|string',
+            'location' => 'nullable|string|max:20',
             'imgs' => 'required_if:type,image|array|max:9',
             'imgs.*' => 'required|url',
         ]);
@@ -134,6 +194,24 @@ class PostController extends Controller
         return  $this->postRepository->comment($request->all());
     }
 
+    /**
+     * 增加数据
+     */
+    public function addData(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'post_id' => 'required|exists:post,id',
+            'add_pv' => 'required|integer|min:0',
+            'add_praise_count' => 'required|integer|min:0',
+            'add_collect_count' => 'required|integer|min:0',
+            'add_share_count' => 'required|integer|min:0',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->postRepository->addData($request->all());
+    }
+
     /**
      * 推荐内容
      */
@@ -162,6 +240,20 @@ class PostController extends Controller
         return  $this->postRepository->delete($request->all());
     }
 
+    /**
+     * 复原内容
+     */
+    public function restore(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|integer',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->postRepository->restore($request->all());
+    }
+
     /**
      * 删除评论
      */
@@ -190,4 +282,37 @@ class PostController extends Controller
         return  $this->postRepository->hide($request->all());
     }
 
+    /**
+     * 日志列表
+     */
+    public function log(Request $request)
+    {
+        $commentList = $this->postRepository->log($request->all());
+        $fractal = new Manager();
+        $resource = new Collection($commentList, new LogTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($commentList));
+        $data = $fractal->createData($resource)->toArray();
+
+        $data['extra'] = [
+            'filters' => [
+                'log_type',
+                'created_at',
+            ],
+            'columns' => [
+                'id',
+                'username',
+                'log_type',
+                'created_at',
+                'content',
+            ]
+        ];
+        return $data;
+    }
+
+    public function statistics(Request $request){
+        $request = $request->all();
+        $start = Carbon::parse(!empty($request['start']) ? Carbon::parse($request['start'])->startOfDay()->toDateTimeString() : Carbon::yesterday())->startOfDay()->toDateTimeString();
+        $end = Carbon::parse(!empty($request['end']) ? Carbon::parse($request['end'])->endOfDay()->toDateTimeString() : Carbon::yesterday())->endOfDay()->toDateTimeString();
+        return $this->postRepository->statistics($start,$end);
+    }
 }

+ 101 - 0
app/Http/Controllers/Topic/CategoryController.php

@@ -0,0 +1,101 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019-06-10
+ * Time: 17:38
+ */
+
+namespace App\Http\Controllers\Topic;
+
+use App\Repositories\CategoryRepository;
+use App\Transformers\CategoryTransformer;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Validator;
+use Illuminate\Validation\Rule;
+use App\Transformers\DetailCategoryTransformer;
+use League\Fractal\Manager;
+use League\Fractal\Pagination\IlluminatePaginatorAdapter;
+use League\Fractal\Resource\Collection;
+use League\Fractal\Resource\Item;
+use App\Http\Controllers\Controller;
+
+class CategoryController extends Controller {
+
+    public function __construct(CategoryRepository $categoryRepository)
+    {
+        $this->categroupRepository = $categoryRepository;
+    }
+    //创建
+    public function create(Request $request){
+      $validator = Validator::make($request->all(), [
+          'name' => 'required|string|max:12',
+          'img' => 'required|url',
+          'desc' => 'required|string|max:100',
+          'topic_ids' => 'string',
+      ]);
+      if ($validator->fails()) {
+          return $this->response->error($validator->errors()->first(), 500);
+      }
+      return  $this->categroupRepository->create($request->all());
+    }
+    //创建
+    public function edit(Request $request){
+        $validator = Validator::make($request->all(), [
+            'id'=>'required|integer',
+            'name' => 'required|string|max:12',
+            'img' => 'required|url',
+            'desc' => 'required|string|max:100',
+            'topic_ids' => 'string',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->categroupRepository->edit($request->all());
+    }
+    //列表
+    public function index(Request $request){
+        $categroup = $this->categroupRepository->index($request->all());
+        $fractal = new Manager();
+        $resource = new Collection($categroup, new CategoryTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($categroup));
+        $data = $fractal->createData($resource)->toArray();
+        $data['extra'] = [
+            'filters' => [
+                'name',
+            ],
+            'columns' => [
+                'id',
+                'name',
+                'img',
+                'created_at',
+                'is_suggest',
+                'topic_count'
+            ]
+        ];
+        return $data;
+    }
+    public function view(Request $request){
+        $data = $request->only('id');
+        $validator = Validator::make($data, [
+            'id' => 'required|integer',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        $categroup = $this->categroupRepository->view($data);
+        return $this->response->item($categroup, new DetailCategoryTransformer());
+    }
+    //设置推荐
+    public function isSuggest(Request $request){
+        $data = $request->only('id','is_suggest');
+        $validator = Validator::make($data, [
+            'id' => 'required|integer',
+            'is_suggest' => ['required',Rule::in(0, 1)],
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->categroupRepository->update($data);
+    }
+}

+ 140 - 0
app/Http/Controllers/Topic/TopicController.php

@@ -0,0 +1,140 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019-06-10
+ * Time: 18:09
+ */
+
+namespace App\Http\Controllers\Topic;
+
+use App\Models\Topic;
+use App\Repositories\CategoryRepository;
+use App\Repositories\TopicRepository;
+use App\Transformers\DetailTopicTransformer;
+use App\Transformers\TopicTransformer;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Validator;
+use League\Fractal\Manager;
+use League\Fractal\Pagination\IlluminatePaginatorAdapter;
+use League\Fractal\Resource\Collection;
+use League\Fractal\Resource\Item;
+use Illuminate\Validation\Rule;
+use App\Http\Controllers\Controller;
+
+
+
+class TopicController extends Controller {
+
+    public function __construct(CategoryRepository $categoryRepository,TopicRepository $topicRepository)
+    {
+        $this->categroupRepository = $categoryRepository;
+        $this->topicRepository = $topicRepository;
+    }
+    //列表
+    public function index(Request $request){
+        $topic= $this->topicRepository->index($request->all());
+        $fractal = new Manager();
+        $resource = new Collection($topic, new TopicTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($topic));
+        $data = $fractal->createData($resource)->toArray();
+        $data['extra'] = [
+            'filters' => [
+                'name',
+                'topic_status',
+            ],
+            'columns' => [
+                'id',
+                'name',
+                'category_list',
+                'img',
+                'post_count',
+                'follow_count',
+                'page_count',
+                'created_at',
+                'is_suggest',
+                'is_hot',
+                'is_open',
+            ]
+        ];
+        return $data;
+    }
+    //详情
+    public function view(Request $request){
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|integer|max:12',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        $topic = $this->topicRepository->view($request->all());
+        return $this->response->item($topic, new DetailTopicTransformer());
+    }
+    //添加
+    public function create(Request $request){
+        $validator = Validator::make($request->all(), [
+            'name' => 'required|string|max:10',
+            'img' => 'required|url',
+            'desc' => 'required|string|max:100',
+            'category_ids' => 'required|string',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->topicRepository->create($request->all());
+    }
+    //编辑
+    public function edit(Request $request){
+        $validator = Validator::make($request->all(), [
+            'id'=>'integer|required',
+            'name' => 'required|string|max:10',
+            'img' => 'required|url',
+            'desc' => 'required|string|max:100',
+            'category_ids' => 'required|string',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->topicRepository->edit($request->all());
+    }
+    //开启
+    public function isOpen(Request $request) {
+        $validator = Validator::make($request->all(), [
+            'id' => 'integer|required',
+            'is_open' => ['required', Rule::in(0, 1)]
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->topicRepository->update($request->all());
+    }
+    //开启
+    public function setStatus(Request $request) {
+        $validator = Validator::make($request->all(), [
+            'id' => 'integer|required',
+            'type'=>['required', Rule::in(1, 2)],
+            'status' => ['required', Rule::in(0, 1)],
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->topicRepository->update($request->all());
+    }
+    //获取多个话题
+    public function getTopic(Request $request){
+        $validator = Validator::make($request->all(), [
+            'ids' => 'required',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->topicRepository->getTopics($request['ids']);
+    }
+
+    /**
+     * 重置话题redis
+     */
+    public function resetRedis(){
+        return  $this->topicRepository->resetRedis();
+    }
+}

+ 45 - 0
app/Models/Behavior.php

@@ -0,0 +1,45 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/10
+ * Time: 11:22
+ */
+
+namespace App\Models;
+use Illuminate\Database\Eloquent\Model;
+
+class Behavior extends Model
+{
+    protected $table = 'behavior';
+    protected $guarded = [];
+    /**
+     * 可被批量赋值的字段
+     * @var array
+     */
+    protected $fillable =
+        ['virus_behavior_id','name','behavior_level','behavior_cycle_type','behavior_action_id','behavior_cycle','is_open','behavior_binding_users','physical_strength',
+        'rainbow_beans','remarks','behavioral_cycle_start_time','behavioral_cycle_end_time','allotted_quantity_rule','behavior_identification','relative_series','trigger_times',
+         'effective_trigger', 'absolute_progression','grant_rainbow_beans'
+        ];
+
+    public function RegisteredRecord()
+    {
+        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');
+    }
+}

+ 23 - 0
app/Models/BehaviorOperationLog.php

@@ -0,0 +1,23 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/13
+ * Time: 15:22
+ */
+
+namespace App\Models;
+use Illuminate\Database\Eloquent\Model;
+
+class BehaviorOperationLog extends Model
+{
+    protected $table = 'behavior_operation_log';
+    protected $guarded = [];
+
+    /**
+     * 可被批量赋值的字段
+     * @var array
+     */
+    protected $fillable = ['operator_id','behavior_id','username','type','content'];
+
+}

+ 5 - 0
app/Models/Category.php

@@ -13,4 +13,9 @@ class Category extends Model
     //
     protected $table = 'category';
     protected $guarded = [];
+
+    public function ct()
+    {
+        return $this->hasMany('App\Models\CategoryTopic','category_id','id');
+    }
 }

+ 10 - 0
app/Models/CategoryTopic.php

@@ -13,4 +13,14 @@ class CategoryTopic extends Model
     //
     protected $table = 'category_topic';
     protected $guarded = [];
+    //话题
+    public function topic()
+    {
+        return $this->hasOne('App\Models\Topic', 'id', 'topic_id');
+    }
+    //分类
+    public function category()
+    {
+        return $this->hasOne('App\Models\Category', 'id', 'category_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');
+    }
+}

+ 17 - 0
app/Models/CommunityMemberStatistics.php

@@ -0,0 +1,17 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019-06-21
+ * Time: 17:34
+ */
+
+namespace App\Models;
+
+
+use Illuminate\Database\Eloquent\Model;
+
+class CommunityMemberStatistics extends Model {
+    protected $table = 'community_member_statistics';
+    protected $guarded = [];
+}

+ 16 - 0
app/Models/Download.php

@@ -0,0 +1,16 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/11
+ * Time: 10:35
+ */
+
+namespace App\Models;
+use Illuminate\Database\Eloquent\Model;
+
+class Download extends Model
+{
+    protected $table = 'downloads';
+    protected $guarded = [];
+}

+ 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');
+    }
+
+}

+ 20 - 0
app/Models/PostMusic.php

@@ -0,0 +1,20 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/5
+ * Time: 16:24
+ */
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class PostMusic extends Model
+{
+    //
+    use SoftDeletes;
+    protected $table = 'post_music';
+    protected $guarded = [];
+
+}

+ 20 - 0
app/Models/PostMusicCategory.php

@@ -0,0 +1,20 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/5
+ * Time: 16:24
+ */
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class PostMusicCategory extends Model
+{
+    //
+    use SoftDeletes;
+    protected $table = 'post_music_category';
+    protected $guarded = [];
+    
+}

+ 19 - 0
app/Models/PostMusicCategoryRel.php

@@ -0,0 +1,19 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/5
+ * Time: 16:24
+ */
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class PostMusicCategoryRel extends Model
+{
+    //
+    protected $table = 'post_music_category_rel';
+    protected $guarded = [];
+    
+}

+ 17 - 0
app/Models/PostStatistics.php

@@ -0,0 +1,17 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/6
+ * Time: 11:21
+ */
+
+namespace App\Models;
+use Illuminate\Database\Eloquent\Model;
+
+class PostStatistics extends Model
+{
+//
+    protected $table = 'community_statistics';
+    protected $guarded = [];
+}

+ 23 - 0
app/Models/RegisteredRecord.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 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');
+    }
+}

+ 5 - 0
app/Models/Topic.php

@@ -14,4 +14,9 @@ class Topic extends Model
     //
     protected $table = 'topic';
     protected $guarded = [];
+
+    public function ct()
+    {
+        return $this->hasMany('App\Models\CategoryTopic','topic_id','id');
+    }
 }

+ 39 - 0
app/Repositories/Behavior/BehaviorLogRepository.php

@@ -0,0 +1,39 @@
+<?php
+namespace App\Repositories\Behavior;
+use App\Models\BehaviorOperationLog;
+
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/13
+ * Time: 下午7:11
+ */
+
+class BehaviorLogRepository
+{
+    public function __construct(BehaviorOperationLog $behaviorOperationLog)
+    {
+        $this->behaviorOperationLog = $behaviorOperationLog;
+    }
+
+    public function log($request)
+    {
+        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+        $where = [];
+        if(isset($request['type'])){
+            $where[] = ['type', $request['type']];
+        }
+
+        return $this->behaviorOperationLog
+            ->where($where)
+            ->where(function($query) use ($request){
+                if(isset($request['created_at'])){
+                    $time = explode('_', $request['created_at']);
+                    $query->whereBetween('created_at', $time);
+                }
+            })
+            ->orderBy('id','desc')
+            ->paginate($perPage);
+    }
+
+}

+ 432 - 0
app/Repositories/Behavior/BehaviorRepository.php

@@ -0,0 +1,432 @@
+<?php
+namespace App\Repositories\Behavior;
+use App\Models\Behavior;
+use App\Models\BehaviorOperationLog;
+use App\Models\CommentRecord;
+use App\Models\GeneralRecord;
+use App\Models\Post;
+use App\Models\RegisteredRecord;
+use App\Models\ReleaseRecord;
+use GuzzleHttp\Client;
+use GuzzleHttp\Exception\RequestException;
+use Illuminate\Support\Carbon;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
+use Tymon\JWTAuth\Facades\JWTAuth;
+use Dingo\Api\Http\Response;
+use Symfony\Component\HttpKernel\Exception\HttpException;
+use Illuminate\Database\QueryException;
+
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/10
+ * Time: 上午11:11
+ */
+
+class BehaviorRepository
+{
+    public function __construct(Behavior $behavior, BehaviorOperationLog $behaviorOperationLog,
+                                RegisteredRecord $registeredRecord, CommentRecord $commentRecord,
+                                GeneralRecord $generalRecord, ReleaseRecord $releaseRecord)
+    {
+        $this->behavior = $behavior;
+        $this->behaviorOperationLog = $behaviorOperationLog;
+        $this->registeredRecord = $registeredRecord;
+        $this->commentRecord = $commentRecord;
+        $this->generalRecord = $generalRecord;
+        $this->releaseRecord = $releaseRecord;
+        //初始化virus域名
+        $this->client = new Client([
+            'base_uri' => config('constants.VIRUS_URL'),
+            'timeout' => 3
+        ]);
+    }
+
+    public function lists($request)
+    {
+        try {
+            $signKey = [
+                'app' => config('constants.VIRUS_APP_ID')
+            ];
+            ksort($signKey);
+            $signKey = urldecode(http_build_query($signKey));
+            $sign = md5(config('constants.VIRUS_APP_SECRET') . $signKey);
+
+            $response = $this->client->request('GET', 'behaviorList', [
+                'headers' => [
+                    'Content-Type' => 'application/json',
+                    'app' => config('constants.VIRUS_APP_ID'),
+                    'sign' => $sign
+                ]
+            ]);
+            $res = json_decode($response->getBody()->getContents(), true);
+            $res = $res ? $res['behaviors'] : [];
+        } catch (RequestException $exception) {
+            $res = [
+                'returnCode' => '-1',
+                'errMsg' => '网络超时' . $exception->getMessage()
+            ];
+            Log::debug('获取virus行为列表:' . $exception->getMessage());
+        }
+        //已登记行为
+        $registered_bahavior = $this->behavior->get();
+        $registered_bahaviors = $registered_bahavior->toArray();
+
+        foreach ($registered_bahaviors as $key => $val) {
+            $registered_bahaviors[$key]['behavior_status'] = 1;//已登记
+            unset($registered_bahaviors[$key]['behavior_action_id']);
+        }
+        $virus_behavior_id = array_column($registered_bahaviors, 'virus_behavior_id');
+
+        $new_res = [];
+        //行为列表去重
+        foreach ($res as $k => $v) {
+            if (isset($v['_id']) && !empty($virus_behavior_id)) {
+                $res[$k]['behavior_status'] = 0;//未登记
+                $res[$k]['behavior_flag'] = $v['behavior_flag'];
+                $res[$k]['behavior_identification'] = $v['behavior_flag'];
+                unset($res[$k]['behavior_flag']);
+                if (in_array($v['_id'], $virus_behavior_id)) {
+                    unset($res[$k]);
+                }
+                $new_res = array_merge($res, $registered_bahaviors);
+
+            } elseif (!isset($v['_id']) && $virus_behavior_id) {
+                $new_res = $registered_bahaviors;
+            } elseif (isset($v['_id']) && empty($virus_behavior_id)) {
+                $res[$k]['behavior_status'] = 0;//未登记
+                $res[$k]['behavior_flag'] = $v['behavior_flag'];
+                $res[$k]['behavior_identification'] = $v['behavior_flag'];
+                unset($res[$k]['behavior_flag']);
+                $new_res = $res;
+            }
+        }
+        $new_re = [];
+        //根据行为ID筛选
+        if (isset($request['virus_behavior_id'])) {
+            foreach ($new_res as $k => $v) {
+                if (isset($v['id']) && $v['id'] != $request['virus_behavior_id']) {
+                    unset($new_res[$k]);
+                    $new_re = array_merge($new_res);
+                } elseif (isset($v['_id']) && $v['_id'] != $request['virus_behavior_id']) {
+                    unset($new_res[$k]);
+                    $new_re = array_merge($new_res);
+                }
+            }
+            return $new_re;
+        }
+        //根据行为状态(类型)筛选
+        if (isset($request['behavior_status'])) {
+            foreach ($new_res as $kk => $vv) {
+                if (isset($vv['behavior_status']) && $vv['behavior_status'] != $request['behavior_status']) {
+                    unset($new_res[$kk]);
+                    $new_re = array_merge($new_res);
+                }
+            }
+            return $new_re;
+        }
+        //根据绑定的动作ID筛选(暂时取消)
+//        if (isset($request['behavior_action_id'])){
+//            foreach ($new_res as $key=>$val) {
+//                if (isset($val['behavior_action_id']) && ($val['behavior_action_id'] != $request['behavior_action_id'])) {
+//                    unset($new_res[$key]);
+////                    $new_re = array_merge($new_res);
+//                } elseif (!isset($val['behavior_action_id'])) {
+//                    unset($new_res[$key]);
+////                    $new_re = array_merge($new_res);
+//                }
+//            }
+//            return $new_re;
+//        }
+        //根据行为名称筛选
+        if (isset($request['name'])) {
+            foreach ($new_res as $key => $val) {
+                if (isset($val['name']) && strpos($val['name'], $request['name']) !== false) {
+                    $new_re[] = $new_res[$key];
+                }
+                if (isset($val['behavior_name']) && strpos($val['behavior_name'], $request['name']) !== false) {
+                    $new_re[] = $new_res[$key];
+                }
+            }
+            return $new_re;
+        }
+        return $new_res;
+    }
+
+    public function create($request)
+    {
+        $behavior_name = $this->behavior->where(['name' => $request['name']])->first();
+        if ($behavior_name) {
+            throw new HttpException(500, '该行为已存在');
+        }
+
+        if (isset($request['allotted_quantity_rule']) && isset($request['rainbow_beans'])) {
+            $rule = $request['allotted_quantity_rule'];
+            $rainbow_beans = $request['rainbow_beans'];
+            $count = 0;
+            if (count($rule) == count($rule, 1)) {
+                $count = array_sum($rule);
+                $request['allotted_quantity_rule'] = array_map('intval', $request['allotted_quantity_rule']);
+                if ($count > $rainbow_beans) {
+                    throw new HttpException(500, '唯一行为-分配总数不能大于行为生成彩虹豆总数');
+                }
+            } else {
+                foreach ($request['allotted_quantity_rule'] as $key => $value) {
+                    $count += $value['bean'];
+                    $request['allotted_quantity_rule'][$key] = array_map('intval', $value);
+
+                }
+                if ($count > $rainbow_beans) {
+                    throw new HttpException(500, '多级行为-分配总数不能大于行为生成彩虹豆总数');
+                }
+            }
+        }
+
+        $data = [
+            'virus_behavior_id' => $request['virus_behavior_id'],
+            'name' => $request['name'],
+            'behavior_level' => $request['behavior_level'],
+            'behavior_cycle_type' => $request['behavior_cycle_type'],
+            'is_open' => 0,
+            'behavior_action_id' => isset($request['behavior_action_id']) ? $request['behavior_action_id'] : '',
+            'behavior_cycle' => isset($request['behavior_cycle']) ? $request['behavior_cycle'] : '',
+            'behavior_binding_users' => isset($request['behavior_binding_users']) ? $request['behavior_binding_users'] : 0,
+            'physical_strength' => isset($request['physical_strength']) ? $request['physical_strength'] : 0,
+            'rainbow_beans' => isset($request['rainbow_beans']) ? $request['rainbow_beans'] : 0,
+            'grant_rainbow_beans' => isset($request['grant_rainbow_beans']) ? $request['grant_rainbow_beans'] : 0,
+            'remarks' => isset($request['remarks']) ? $request['remarks'] : '',
+            'behavioral_cycle_start_time' => isset($request['behavioral_cycle_start_time']) ? $request['behavioral_cycle_start_time'] : null,
+            'behavioral_cycle_end_time' => isset($request['behavioral_cycle_end_time']) ? $request['behavioral_cycle_end_time'] : null,
+            'allotted_quantity_rule' => isset($request['allotted_quantity_rule']) ? json_encode($request['allotted_quantity_rule']) : '',
+            'behavior_identification' => isset($request['behavior_identification']) ? $request['behavior_identification'] : '',
+            'trigger_times' => isset($request['trigger_times']) ? $request['trigger_times'] : 0,
+            'effective_trigger' => isset($request['effective_trigger']) ? $request['effective_trigger'] : 0,
+            'relative_series' => isset($request['relative_series']) ? $request['relative_series'] : 0,
+            'absolute_progression' => isset($request['absolute_progression']) ? $request['absolute_progression'] : 0,
+        ];
+        DB::beginTransaction();
+        try {
+            $res = $this->behavior->create($data);
+            if ($res) {
+                $token = JWTAuth::decode(JWTAuth::getToken());
+                $uid = $token['user']->id;
+                $username = $token['user']->username;
+                $cerate_bahavior_data = [
+                    'operator_id' => $uid,
+                    'behavior_id' => $res['id'],
+                    'username' => $username,
+                    'content' => '创建' . $request['name'] . '行为',
+                    'type' => 0,
+                    'created_at' => date('Y-m-d H:i:s'),
+                    'updated_at' => date('Y-m-d H:i:s')
+                ];
+                $result = $this->behaviorOperationLog->insert($cerate_bahavior_data);
+                if (!$result) {
+                    throw new HttpException(500, '操作日志记录失败');
+                }
+            }
+            DB::commit();
+            return Response::create();
+
+        } catch (QueryException $exception) {
+            DB::rollBack();
+            Log::debug('注册行为:' . $exception->getMessage());
+            return Response::create([
+                'message' => '添加失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code' => 500
+            ]);
+        }
+    }
+
+    public function edit($request)
+    {
+        $behavior_id = $this->behavior->find($request['id']);
+        if ($behavior_id->is_open == 1) {
+            throw new HttpException(500, '无法编辑已经在记录的行为');
+        }
+        if (isset($request['allotted_quantity_rule']) && isset($request['rainbow_beans'])) {
+
+            $rule = $request['allotted_quantity_rule'];
+            $rainbow_beans = $request['rainbow_beans'];
+            $count = 0;
+            if (count($rule) == count($rule, 1)) {
+                $count = array_sum($rule);
+                $request['allotted_quantity_rule'] = array_map('intval', $request['allotted_quantity_rule']);
+                if ($count > $rainbow_beans) {
+                    throw new HttpException(500, '唯一行为-分配总数不能大于行为生成彩虹豆总数');
+                }
+            } else {
+                foreach ($request['allotted_quantity_rule'] as $key => $value) {
+                    $count += $value['bean'];
+                    $request['allotted_quantity_rule'][$key] = array_map('intval', $value);
+
+                }
+                if ($count > $rainbow_beans) {
+                    throw new HttpException(500, '多级行为-分配总数不能大于行为生成彩虹豆总数');
+                }
+            }
+        }
+
+
+        $update_bahavior = [
+            'virus_behavior_id' => $request['virus_behavior_id'],
+            'name' => $request['name'],
+            'behavior_level' => $request['behavior_level'],
+            'behavior_cycle_type' => $request['behavior_cycle_type'],
+            'is_open' => 0,
+            'behavior_cycle' => isset($request['behavior_cycle']) ? $request['behavior_cycle'] : '',
+            'behavior_binding_users' => isset($request['behavior_binding_users']) ? $request['behavior_binding_users'] : 0,
+            'physical_strength' => isset($request['physical_strength']) ? $request['physical_strength'] : 0,
+            'rainbow_beans' => isset($request['rainbow_beans']) ? $request['rainbow_beans'] : 0,
+            'grant_rainbow_beans' => isset($request['grant_rainbow_beans']) ? $request['grant_rainbow_beans'] : 0,
+            'remarks' => isset($request['remarks']) ? $request['remarks'] : '',
+            'behavioral_cycle_start_time' => isset($request['behavioral_cycle_start_time']) ? $request['behavioral_cycle_start_time'] : null,
+            'behavioral_cycle_end_time' => isset($request['behavioral_cycle_end_time']) ? $request['behavioral_cycle_end_time'] : null,
+            'allotted_quantity_rule' => isset($request['allotted_quantity_rule']) ? json_encode($request['allotted_quantity_rule']) : '',
+            'behavior_identification' => isset($request['behavior_identification']) ? $request['behavior_identification'] : '',
+            'trigger_times' => isset($request['trigger_times']) ? $request['trigger_times'] : 0,
+            'effective_trigger' => isset($request['effective_trigger']) ? $request['effective_trigger'] : 0,
+            'relative_series' => isset($request['relative_series']) ? $request['relative_series'] : 0,
+            'absolute_progression' => isset($request['absolute_progression']) ? $request['absolute_progression'] : 0,
+            'updated_at' => date('Y-m-d H:i:s')
+        ];
+        DB::beginTransaction();
+        try {
+            $res = $this->behavior->where('id', $request['id'])->update($update_bahavior);
+            if ($res) {
+                $token = JWTAuth::decode(JWTAuth::getToken());
+                $uid = $token['user']->id;
+                $username = $token['user']->username;
+                $cerate_bahavior_data = [
+                    'operator_id' => $uid,
+                    'behavior_id' => $request['id'],
+                    'username' => $username,
+                    'content' => json_encode($update_bahavior),
+                    'type' => 1,
+                    'created_at' => date('Y-m-d H:i:s'),
+                    'updated_at' => date('Y-m-d H:i:s')
+                ];
+                $result = $this->behaviorOperationLog->insert($cerate_bahavior_data);
+                if (!$result) {
+                    throw new HttpException(500, '操作日志记录失败');
+                }
+            }
+            DB::commit();
+            return Response::create();
+
+        } catch (QueryException $exception) {
+            DB::rollBack();
+            Log::debug('编辑行为:' . $exception->getMessage());
+            return Response::create([
+                'message' => '编辑失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code' => 500
+            ]);
+        }
+    }
+
+    public function editStatus($request)
+    {
+        $behavior = $this->behavior->find($request['id']);
+
+        $behavior_array = [
+            'is_open' => $request['is_open'],
+            'updated_at' => date('Y-m-d H:i:s')
+        ];
+        if ($request['is_open'] == 0) {
+            $is_open = '关闭';
+        } else {
+            $is_open = '开启';
+        }
+        $behavior_name = $behavior->name;
+
+        DB::beginTransaction();
+        try {
+            $res = $behavior->where('id', $request['id'])->update($behavior_array);
+            if ($res) {
+                $token = JWTAuth::decode(JWTAuth::getToken());
+                $uid = $token['user']->id;
+                $username = $token['user']->username;
+                $cerate_bahavior_data = [
+                    'operator_id' => $uid,
+                    'behavior_id' => $request['id'],
+                    'username' => $username,
+                    'content' => $is_open . '了' . $behavior_name . '行为',
+                    'type' => 2,
+                    'created_at' => date('Y-m-d H:i:s'),
+                    'updated_at' => date('Y-m-d H:i:s')
+                ];
+                $result = $this->behaviorOperationLog->insert($cerate_bahavior_data);
+                if (!$result) {
+                    throw new HttpException(500, '操作日志记录失败');
+                }
+            }
+            DB::commit();
+            return Response::create();
+
+        } catch (QueryException $exception) {
+            DB::rollBack();
+            Log::debug('修改状态行为:' . $exception->getMessage());
+            return Response::create([
+                'message' => '修改状态失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code' => 500
+            ]);
+        }
+    }
+
+    public function dataList($request)
+    {
+        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+        $where = [];
+        if(isset($request['id'])){
+            $where[] = ['id',$request['id']];
+        }
+        if(isset($request['is_open'])){
+            $where[] = ['is_open',$request['is_open']];
+        }
+        //行为级别唯一/多级筛选
+        if(isset($request['behavior_level'])){
+            $where[] = ['behavior_level',$request['behavior_level']];
+        }
+        if(isset($request['name'])){
+            $where[] = ['name', 'like', "%{$request['name']}%"];
+        }
+
+        $sort = 'desc';
+        $filed = 'id';
+        if(isset($request['search']) && isset($request['sort'])){
+                $filed = $this->check_search($request['search']);
+                $sort = $request['sort']   == 0 ? 'desc' : 'asc';
+        }
+
+        return $this->behavior->where($where)->orderBy($filed,$sort)->paginate($perPage);
+    }
+
+    private function check_search($search)
+    {
+        $result = "";
+        switch ($search) {
+            case 'trigger_times':
+                $result = $search;
+                break;
+            case 'effective_trigger':
+                $result = $search;
+                break;
+            case 'absolute_progression':
+                $result = $search;
+                break;
+            case 'physical_strength':
+                $result = $search;
+                break;
+            case 'grant_rainbow_beans':
+                $result = $search;
+                break;
+        }
+        return $result;
+    }
+
+}
+

+ 57 - 0
app/Repositories/Behavior/CommentRecordRepository.php

@@ -0,0 +1,57 @@
+<?php
+namespace App\Repositories\Behavior;
+use App\Models\CommentRecord;
+
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/14
+ * Time: 下午18:18
+ */
+
+class CommentRecordRepository
+{
+    public function __construct(CommentRecord $commentRecord)
+    {
+        $this->commentRecord = $commentRecord;
+    }
+
+    public function lists($request)
+    {
+        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+        $where = [];
+        if(isset($request['id'])){
+            $where[] = ['id', $request['id']];
+        }
+        if(isset($request['uid'])){
+            $where[] = ['uid', $request['uid']];
+        }
+        if(isset($request['trigger_type'])){
+            $where[] = ['trigger_type', $request['trigger_type']];
+        }
+        if(isset($request['virus_behavior_id'])){
+            $where[] = ['virus_behavior_id', $request['virus_behavior_id']];
+        }
+        if(isset($request['content_author_id'])){
+            $where[] = ['content_author_id', $request['content_author_id']];
+        }
+        if(isset($request['related_content_id'])){
+            $where[] = ['related_content_id', $request['related_content_id']];
+        }
+        if(isset($request['superior_commentator_id'])){
+            $where[] = ['superior_commentator_id', $request['superior_commentator_id']];
+        }
+
+        return $this->commentRecord
+            ->where($where)
+            ->where(function($query) use ($request){
+                if(isset($request['created_at'])){
+                    $time = explode('_', $request['created_at']);
+                    $query->whereBetween('created_at', $time);
+                }
+            })
+            ->orderBy('id','desc')
+            ->paginate($perPage);
+    }
+
+}

+ 63 - 0
app/Repositories/Behavior/GenaralRecordRepository.php

@@ -0,0 +1,63 @@
+<?php
+namespace App\Repositories\Behavior;
+use App\Models\Behavior;
+use App\Models\GeneralRecord;
+
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/14
+ * Time: 下午8:45
+ */
+
+class GenaralRecordRepository
+{
+    public function __construct(GeneralRecord $generalRecord,Behavior $behavior)
+    {
+        $this->generalRecord = $generalRecord;
+        $this->behavior = $behavior;
+    }
+
+    public function lists($request)
+    {
+        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+        $where = [];
+        if(isset($request['id'])){
+            $where[] = ['id', $request['id']];
+        }
+        if(isset($request['uid'])){
+            $where[] = ['uid', $request['uid']];
+        }
+        if(isset($request['trigger_type'])){
+            $where[] = ['trigger_type', $request['trigger_type']];
+        }
+        if(isset($request['virus_behavior_id'])){
+            $where[] = ['virus_behavior_id', $request['virus_behavior_id']];
+        }
+        if(isset($request['content_author_id'])){
+            $where[] = ['content_author_id', $request['content_author_id']];
+        }
+        if(isset($request['related_content_id'])){
+            $where[] = ['related_content_id', $request['related_content_id']];
+        }
+
+        if(isset($request['behavior_identification'])){
+            $virus_id = $this->behavior->select('virus_behavior_id')->where('behavior_identification',$request['behavior_identification'])->first();
+            if ($virus_id){
+                $where[] = ['virus_behavior_id', $virus_id->virus_behavior_id];
+            }
+        }
+
+        return $this->generalRecord
+            ->where($where)
+            ->where(function($query) use ($request){
+                if(isset($request['created_at'])){
+                    $time = explode('_', $request['created_at']);
+                    $query->whereBetween('created_at', $time);
+                }
+            })
+            ->orderBy('id','desc')
+            ->paginate($perPage);
+    }
+
+}

+ 51 - 0
app/Repositories/Behavior/RegisteredRecordRepository.php

@@ -0,0 +1,51 @@
+<?php
+namespace App\Repositories\Behavior;
+use App\Models\RegisteredRecord;
+
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/14
+ * Time: 下午1:58
+ */
+
+class RegisteredRecordRepository
+{
+    public function __construct(RegisteredRecord $registeredRecord)
+    {
+        $this->registeredRecord = $registeredRecord;
+    }
+
+    public function lists($request)
+    {
+        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+        $where = [];
+        if(isset($request['id'])){
+            $where[] = ['id', $request['id']];
+        }
+        if(isset($request['uid'])){
+            $where[] = ['uid', $request['uid']];
+        }
+        if(isset($request['absolute_progression'])){
+            $where[] = ['absolute_progression', $request['absolute_progression']];
+        }
+        if(isset($request['trigger_type'])){
+            $where[] = ['trigger_type', $request['trigger_type']];
+        }
+        if(isset($request['virus_behavior_id'])){
+            $where[] = ['virus_behavior_id', $request['virus_behavior_id']];
+        }
+
+        return $this->registeredRecord
+            ->where($where)
+            ->where(function($query) use ($request){
+                if(isset($request['created_at'])){
+                    $time = explode('_', $request['created_at']);
+                    $query->whereBetween('created_at', $time);
+                }
+            })
+            ->orderBy('id','desc')
+            ->paginate($perPage);
+    }
+
+}

+ 51 - 0
app/Repositories/Behavior/ReleaseRecordRepository.php

@@ -0,0 +1,51 @@
+<?php
+namespace App\Repositories\Behavior;
+use App\Models\ReleaseRecord;
+
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/14
+ * Time: 下午8:18
+ */
+
+class ReleaseRecordRepository
+{
+    public function __construct(ReleaseRecord $releaseRecord)
+    {
+        $this->releaseRecord = $releaseRecord;
+    }
+
+    public function lists($request)
+    {
+        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+        $where = [];
+        if(isset($request['id'])){
+            $where[] = ['id', $request['id']];
+        }
+        if(isset($request['uid'])){
+            $where[] = ['uid', $request['uid']];
+        }
+        if(isset($request['trigger_type'])){
+            $where[] = ['trigger_type', $request['trigger_type']];
+        }
+        if(isset($request['virus_behavior_id'])){
+            $where[] = ['virus_behavior_id', $request['virus_behavior_id']];
+        }
+        if(isset($request['related_content_id'])){
+            $where[] = ['related_content_id', $request['related_content_id']];
+        }
+
+        return $this->releaseRecord
+            ->where($where)
+            ->where(function($query) use ($request){
+                if(isset($request['created_at'])){
+                    $time = explode('_', $request['created_at']);
+                    $query->whereBetween('created_at', $time);
+                }
+            })
+            ->orderBy('id','desc')
+            ->paginate($perPage);
+    }
+
+}

+ 145 - 0
app/Repositories/CategoryRepository.php

@@ -0,0 +1,145 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019-06-10
+ * Time: 17:40
+ */
+namespace App\Repositories;
+
+use App\Models\Category;
+use App\Models\CategoryTopic;
+use Dingo\Api\Http\Response;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Database\QueryException;
+use Illuminate\Support\Facades\Log;
+
+class CategoryRepository {
+    public function __construct(Category $category,CategoryTopic $categoryTopic){
+        $this->category = $category;
+        $this->categoryTopic = $categoryTopic;
+    }
+    //列表
+    public function index($request){
+        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+        $where = [];
+        if(isset($request['name'])){
+            $where[] = ['name', 'like', "%{$request['name']}%"];
+        }
+        return $this->category->where($where)->paginate($perPage);
+    }
+    //详情
+    public function view($request){
+        return $this->category->where(['id'=>$request['id']])->first();
+    }
+    //创建
+    public function create($request){
+        $category = $this->category->where(['name'=>$request['name']])->first();
+        if($category){
+            return Response::create([
+                'message'  => '该分类已存在',
+                'status_code'   => 500
+            ]);
+        }
+        $data = [
+            'name' => $request['name'],
+            'img' => $request['img'],
+            //'is_suggest' => $request['is_suggest'],
+            'desc' => $request['desc'],
+        ];
+        $topic_ids = '';
+        if(!empty($request['topic_ids'])){
+            $topic_ids = explode(',', $request['topic_ids']);
+        }
+        DB::beginTransaction();
+        try{
+            $categoryInfo = $this->category->create($data);
+            if($categoryInfo){
+                if(!empty($topic_ids)){
+                    $category_topic_data = [];
+                    foreach($topic_ids as $value){
+                        $category_topic_data[] = [
+                            'category_id' => $categoryInfo->id,
+                            'topic_id' => $value,
+                        ];
+                    }
+                    $this->categoryTopic->insert($category_topic_data);
+                }
+            }
+            DB::commit();
+            return Response::create();
+        }catch (QueryException $exception){
+            DB::rollBack();
+            Log::debug('新增话题分组:'.$exception->getMessage());
+            return Response::create([
+                'message'  => '新增话题失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code'   => 500
+            ]);
+        }
+    }
+    //编辑
+    public function edit($request){
+        $category = $this->category->where(['id'=>$request['id']])->first();
+        if(!$category){
+            return Response::create([
+                'message'  => '该分类不存在',
+                'status_code'   => 500
+            ]);
+        }
+        $_category = $this->category->where(['name'=>$request['name']])->where('id','<>',$category->id)->first();
+        if($_category){
+            return Response::create([
+                'message'  => '该分类已存在',
+                'status_code'   => 500
+            ]);
+        }
+        $category->name = $request['name'];
+        $category->img = $request['img'];
+        $category->desc = $request['desc'];
+        $topic_ids = [];
+        if(!empty($request['topic_ids'])){
+            $topic_ids = explode(',', $request['topic_ids']);
+        }
+        DB::beginTransaction();
+        try{
+
+            $categoryInfo = $category->save();
+            if($categoryInfo){
+                //删除
+                $this->categoryTopic->where(['category_id'=>$category->id])->delete();
+                if($topic_ids){
+                    $category_topic_data = [];
+                    foreach($topic_ids as $value){
+                        $category_topic_data[] = [
+                            'category_id' => $category->id,
+                            'topic_id' => $value,
+                        ];
+                    }
+                    $this->categoryTopic->insert($category_topic_data);
+                }
+            }
+            DB::commit();
+            return Response::create();
+        }catch (QueryException $exception){
+            DB::rollBack();
+            Log::debug('新增话题分组:'.$exception->getMessage());
+            return Response::create([
+                'message'  => '新增话题失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code'   => 500
+            ]);
+        }
+    }
+    //修改
+    public function update($request){
+        $category = $this->category->where('id', $request['id'])->first();
+        if(isset($request['is_suggest']) && $request['is_suggest'] !== null){
+            $category->is_suggest = $request['is_suggest'];
+        }
+        $res = $category->save();
+        if($res){
+            return Response::create();
+        }
+    }
+}

+ 207 - 0
app/Repositories/CommunityMemberStatisticsRepository.php

@@ -0,0 +1,207 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019-06-21
+ * Time: 17:34
+ */
+
+namespace App\Repositories;
+
+
+use App\Models\Behavior;
+use App\Models\CommentRecord;
+use App\Models\CommunityMemberStatistics;
+use App\Models\GeneralRecord;
+use App\Models\ReleaseRecord;
+use Illuminate\Support\Carbon;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Database\QueryException;
+use Illuminate\Support\Facades\Log;
+
+class CommunityMemberStatisticsRepository {
+    public function __construct(CommunityMemberStatistics $communityMemberStatistics,
+                                CommentRecord $commentRecord,
+                                GeneralRecord $generalRecord,
+                                ReleaseRecord $releaseRecord,
+                                Behavior $behavior) {
+        $this->communityMemberStatistics = $communityMemberStatistics;
+        $this->commentRecord = $commentRecord;
+        $this->generalRecord = $generalRecord;
+        $this->releaseRecord = $releaseRecord;
+        $this->behavior = $behavior;
+    }
+
+    //统计前一天数据
+    public function statistics() {
+        $yesterdayStart = Carbon::yesterday()->startOfDay()->toDateTimeString();
+        $yesterdayEnd = Carbon::yesterday()->endOfDay()->toDateTimeString();
+        $sData = [
+            'post_count' => 0,
+            'read_count' => 0,
+            'share_count' => 0,
+            'like_count' => 0,
+            'unlike_count' => 0,
+            'collect_count' => 0,
+            'comment_count' => 0,
+        ];
+        Log::debug('统计用户行为开始');
+        $statisticsData = [];
+        //评论行为
+        $commentAccountRecord = $this->commentRecord
+            ->where([['created_at', '>=', $yesterdayStart], ['created_at', '<=', $yesterdayEnd]])
+            ->get();
+        //统计评论行为
+        if($commentAccountRecord){
+            $comment_count = [];
+            foreach ($commentAccountRecord as $k=>$v){
+                if(!isset($comment_count[$v['uid']])){
+                    $comment_count[$v['uid']] = 0;
+                }
+                $statisticsData[$v['uid']] = $sData;
+                $statisticsData[$v['uid']]['comment_count'] = ++$comment_count[$v['uid']];
+
+            }
+        }
+        //行为 read阅读 like点赞 unlike不喜欢 forward分享 collect收藏
+        $statisticsData = $this->getBehavior($statisticsData,$sData);
+        //发布行为
+        $releaseRecordData = $this->releaseRecord
+            ->where([['created_at', '>=', $yesterdayStart], ['created_at', '<=', $yesterdayEnd]])
+            ->get();
+        if($releaseRecordData){
+            $post_count = [];
+            foreach ($releaseRecordData as $kk=>$vv){
+                if(!isset($post_count[$vv['uid']])){
+                    $post_count[$vv['uid']] = 0;
+                }
+                if(empty($statisticsData[$vv['uid']])){
+                    $statisticsData[$vv['uid']] = $sData;
+                }
+                $statisticsData[$vv['uid']]['post_count'] = ++$post_count[$vv['uid']];
+            }
+        }
+        //得到数据查询是否有,有修改,没有添加
+        if(!empty($statisticsData)){
+            DB::beginTransaction();
+            Log::info('统计用户行为内容'.json_encode($statisticsData));
+            try{
+                foreach ($statisticsData as $key => $value){
+                    $statisticsInfo = $this->communityMemberStatistics->where('uid',$key)->first();
+                    if($statisticsInfo){
+                        $upData = [
+                            'post_count' => ($statisticsInfo->post_count+$value['post_count']),
+                            'read_count' => ($statisticsInfo->read_count+$value['read_count']),
+                            'share_count' => ($statisticsInfo->share_count+$value['share_count']),
+                            'like_count' => ($statisticsInfo->like_count+$value['like_count']),
+                            'unlike_count' => ($statisticsInfo->unlike_count+$value['unlike_count']),
+                            'collect_count' => ($statisticsInfo->collect_count+$value['collect_count']),
+                            'comment_count' => ($statisticsInfo->comment_count+$value['comment_count']),
+                        ];
+                        $this->communityMemberStatistics
+                            ->where('id',$statisticsInfo->id)
+                            ->update($upData);
+                    }else{
+                        $value['uid'] = $key;
+                        $this->communityMemberStatistics->create($value);
+                    }
+                    DB::commit();
+                }
+            }catch (QueryException $exception){
+                DB::rollBack();
+                Log::debug('统计用户行为出错:'.$exception->getMessage());
+            }
+            Log::debug('统计用户行为结束');
+        }
+    }
+    //普通行为
+    public function getBehavior($statisticsData,$sData){
+        $yesterdayStart = Carbon::yesterday()->startOfDay()->toDateTimeString();
+        $yesterdayEnd = Carbon::yesterday()->endOfDay()->toDateTimeString();
+        //行为 read阅读 like点赞 unlike不喜欢 forward分享 collect收藏
+        $behavior = $this
+            ->behavior
+            ->whereIN('behavior_identification',['read','like','unlike','forward','collect'])
+            ->select('virus_behavior_id','behavior_identification')
+            ->get();
+        if($behavior){
+            foreach ($behavior as $key=>$value){
+                //普通行为
+                $generalLedgerRecord = $this->generalRecord
+                    ->where([['created_at', '>=', $yesterdayStart], ['created_at', '<=', $yesterdayEnd]])
+                    ->where('virus_behavior_id',$value['virus_behavior_id'])
+                    ->get();
+                //阅读数
+                if($generalLedgerRecord){
+                    if($value['behavior_identification'] == 'like'){
+                        //喜欢数
+                        $like_count = [];
+                        foreach ($generalLedgerRecord as $kk=>$vv){
+                            if(!isset($like_count[$vv['uid']])){
+                                $like_count[$vv['uid']] = 0;
+                            }
+                            if(empty($statisticsData[$vv['uid']])){
+                                $statisticsData[$vv['uid']] = $sData;
+                            }
+                            $statisticsData[$vv['uid']]['like_count'] = ++$like_count[$vv['uid']];
+                        }
+                    }elseif ($value['behavior_identification'] == 'read'){
+                        //阅读数
+                        $read_count = [];
+                        foreach ($generalLedgerRecord as $kk=>$vv){
+                            if(!isset($read_count[$vv['uid']])){
+                                $read_count[$vv['uid']] = 0;
+                            }
+                            if(empty($statisticsData[$vv['uid']])){
+                                $statisticsData[$vv['uid']] = $sData;
+                            }
+                            $statisticsData[$vv['uid']]['read_count'] = ++$read_count[$vv['uid']];
+                        }
+                    }elseif ($value['behavior_identification'] == 'unlike'){
+                        //不喜欢
+                        $unlike_count = [];
+                        foreach ($generalLedgerRecord as $kk=>$vv){
+                            if(!isset($unlike_count[$vv['uid']])){
+                                $unlike_count[$vv['uid']] = 0;
+                            }
+                            if(empty($statisticsData[$vv['uid']])){
+                                $statisticsData[$vv['uid']] = $sData;
+                            }
+                            $statisticsData[$vv['uid']]['unlike_count'] = ++$unlike_count[$vv['uid']];
+                        }
+                    }elseif ($value['behavior_identification'] == 'forward'){
+                        //分享
+                        $share_count = [];
+                        foreach ($generalLedgerRecord as $kk=>$vv){
+                            if(!isset($share_count[$vv['uid']])){
+                                $share_count[$vv['uid']] = 0;
+                            }
+                            if(empty($statisticsData[$vv['uid']])){
+                                $statisticsData[$vv['uid']] = $sData;
+                            }
+                            $statisticsData[$vv['uid']]['share_count'] = ++$share_count[$vv['uid']];
+                        }
+                    }elseif ($value['behavior_identification'] == 'collect'){
+                        //收藏
+                        $collect_count = [];
+                        foreach ($generalLedgerRecord as $kk=>$vv){
+                            if(!isset($collect_count[$vv['uid']])){
+                                $collect_count[$vv['uid']] = 0;
+                            }
+                            if(empty($statisticsData[$vv['uid']])){
+                                $statisticsData[$vv['uid']] = $sData;
+                            }
+                            $statisticsData[$vv['uid']]['collect_count'] = ++$collect_count[$vv['uid']];
+                        }
+                    }
+                }
+
+            }
+        }
+        return $statisticsData;
+    }
+    //用户详情
+    public function view($uid){
+        return $this->communityMemberStatistics->where('uid',$uid)->first();
+    }
+}

+ 96 - 0
app/Repositories/DownloadRepository.php

@@ -0,0 +1,96 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/11
+ * Time: 10:45
+ */
+namespace App\Repositories;
+
+use App\Models\Download;
+use Illuminate\Database\QueryException;
+use Dingo\Api\Http\Response;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
+use Symfony\Component\HttpKernel\Exception\HttpException;
+use Tymon\JWTAuth\Facades\JWTAuth;
+class DownloadRepository
+{
+    public function __construct(Download $download)
+    {
+        $this->download = $download;
+    }
+
+    /**
+     * 下载列表
+     */
+    public function lists($request)
+    {
+        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+        $where = [];
+        if(isset($request['content'])){
+            $where[] = ['content', 'like', "%{$request['content']}%"];
+        }
+        if(isset($request['download_type'])){
+            $where[] = ['download_type', $request['download_type']];
+        }
+
+        return $this->download
+            ->where($where)
+            ->orderBy('id','desc')
+            ->paginate($perPage);
+    }
+
+    /**
+     * 添加下载
+     */
+    public function create($request)
+    {
+        $token =  JWTAuth::decode(JWTAuth::getToken());
+        if(!$token || $token['type'] != 1){
+            return Response::create([
+                'message'  => '获取登陆信息失败',
+                'status_code'   => 500
+            ]);
+        }
+        $uid = $token['user']->id;
+        $username = $token['user']->username;
+
+        //下载中
+        if($this->download->where('uid', $uid)->where('download_status', 0)->where('download_type', $request['download_type'])->exists()){
+            return Response::create([
+                'message'  => '当前有任务未完成,请等待',
+                'status_code'   => 500
+            ]);
+        }
+
+        $data = [
+            'uid' => $uid,
+            'username' => $username,
+            'download_type' => $request['download_type'],
+            'download_status' => 0,
+            'params' => json_encode($request),
+            'url' => ''
+        ];
+
+
+
+        DB::beginTransaction();
+        try{
+            $this->download->create($data);
+
+            DB::commit();
+            return Response::create();
+
+        }catch (QueryException $exception){
+            DB::rollBack();
+            Log::debug('生成下载内容:'.$exception->getMessage());
+            return Response::create([
+                'message'  => '操作失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code'   => 500
+            ]);
+        }
+    }
+}

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 638 - 101
app/Repositories/Post/PostRepository.php


+ 215 - 0
app/Repositories/TopicRepository.php

@@ -0,0 +1,215 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019-06-10
+ * Time: 18:12
+ */
+
+namespace App\Repositories;
+
+use App\Models\Category;
+use App\Models\CategoryTopic;
+use App\Models\Topic;
+use Dingo\Api\Http\Response;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Database\QueryException;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Redis;
+
+class TopicRepository {
+    public function __construct(Topic $topic,CategoryTopic $categoryTopic){
+        $this->topic = $topic;
+        $this->categoryTopic = $categoryTopic;
+    }
+    //列表
+    public function index($request){
+        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+        $where = [];
+        if(isset($request['name'])){
+            $where[] = ['name', 'like', "%{$request['name']}%"];
+        }
+        if(isset($request['topic_status'])){
+            if($request['topic_status'] == 'is_suggest'){
+                $where[] = ['is_suggest', 1];
+            }
+            if( $request['topic_status'] == 'is_hot'){
+                $where[] = ['is_hot', 1];
+            }
+            if($request['topic_status'] == 'is_open'){
+                $where[] = ['is_open', 1];
+            }
+            if($request['topic_status'] == 'is_close'){
+                $where[] = ['is_open', 0];
+            }
+        }
+
+        return $this->topic->where($where)->paginate($perPage);
+    }
+    //新增
+    public function create($request){
+        $topic = $this->topic->where(['name'=>$request['name']])->first();
+        if($topic){
+            return Response::create([
+                'message'  => '该话题已存在',
+                'status_code'   => 500
+            ]);
+        }
+
+        $data = [
+            'name' => $request['name'],
+            'img' => $request['img'],
+            'desc' => $request['desc'],
+        ];
+        if(isset($request['category_ids'])){
+            $category_ids = explode(',', $request['category_ids']);
+        }
+        DB::beginTransaction();
+        try{
+            $topicInfo = $this->topic->create($data);
+            if($topicInfo){
+                if($category_ids){
+                    $category_topic_data = [];
+                    foreach($category_ids as $value){
+                        $category_topic_data[] = [
+                            'category_id' => $value,
+                            'topic_id' => $topicInfo->id,
+                        ];
+                    }
+                    $this->categoryTopic->insert($category_topic_data);
+                }
+            }
+            DB::commit();
+            Redis::zadd('topic.name', $topicInfo->id, $topicInfo->name);
+            return Response::create();
+        }catch (QueryException $exception){
+            DB::rollBack();
+            Log::debug('新增话题:'.$exception->getMessage());
+            return Response::create([
+                'message'  => '新增话题,请重试',
+                'error' => $exception->getMessage(),
+                'status_code'   => 500
+            ]);
+        }
+    }
+
+    public function edit($request){
+        $topic = $this->topic->where(['id'=>$request['id']])->first();
+        if(!$topic){
+            return Response::create([
+                'message'  => '该话题不存在',
+                'status_code'   => 500
+            ]);
+        }
+        $oldName = $topic->name;
+        $_topic = $this->topic->where(['name'=>$request['name']])->where('id','<>',$topic->id)->first();
+        if($_topic){
+            return Response::create([
+                'message'  => '该话题已存在',
+                'status_code'   => 500
+            ]);
+        }
+
+        $topic->name = $request['name'];
+        $topic->img = $request['img'];
+        $topic->desc = $request['desc'];
+        $category_ids = [];
+        if(!empty($request['category_ids'])){
+            $category_ids = explode(',', $request['category_ids']);
+        }
+        DB::beginTransaction();
+        try{
+            //保存
+            $topicInfo = $topic->save();
+            //删除原来关联关系
+            $this->categoryTopic->where(['topic_id'=>$topic->id])->delete();
+            if($topicInfo){
+                if($category_ids){
+                    $category_topic_data = [];
+                    foreach($category_ids as $value){
+                        $category_topic_data[] = [
+                            'category_id' => $value,
+                            'topic_id' => $topic->id,
+                        ];
+                    }
+                    $this->categoryTopic->insert($category_topic_data);
+                }
+            }
+            DB::commit();
+            if($oldName != $topic->name){
+                Redis::zrem('topic.name', $oldName);
+                Redis::zadd('topic.name', $topic->id, $topic->name);
+            }
+            return Response::create();
+        }catch (QueryException $exception){
+            DB::rollBack();
+            Log::debug('编辑话题:'.$exception->getMessage());
+            return Response::create([
+                'message'  => '编辑话题,请重试',
+                'error' => $exception->getMessage(),
+                'status_code'   => 500
+            ]);
+        }
+    }
+    //修改
+    public function update($request){
+        $topic = $this->topic->where('id', $request['id'])->first();
+        if(!$topic){
+            return Response::create([
+                'message'  => '该话题不存在',
+                'status_code'   => 500
+            ]);
+        }
+        if(isset($request['is_open']) && $request['is_open'] !== null){
+            $topic->is_open = $request['is_open'];
+        }
+        if(!empty($request['type'])){
+            if($topic->is_open == 0){
+                return Response::create([
+                    'message'  => '该话题未开启',
+                    'status_code'   => 500
+                ]);
+            }
+            if(isset($request['type']) && $request['type'] == 1){
+                $topic->is_suggest = $request['status'];
+            }
+            if(isset($request['type']) && $request['type'] == 2){
+                $topic->is_hot = $request['status'];
+            }
+        }
+
+        $res = $topic->save();
+        if($res){
+            return Response::create();
+        }
+    }
+    //详情
+    public function view($request){
+        return $this->topic->where('id', $request['id'])->first();
+    }
+    //获取多个话题
+    public function getTopics($ids = []){
+        return $this->topic->whereIn('id', $ids)->select('id','name')->get();
+    }
+
+    /**
+     * 重置话题redis
+     */
+    public function resetRedis()
+    {
+        $TopicName = $this->topic->pluck('id', 'name')->toArray();
+
+        $res = Redis::zadd('topic.name', $TopicName);
+        if($res){
+            return Response::create([
+                'message'  => '重置话题成功',
+                'status_code'   => 500
+            ]);
+        }else{
+            return Response::create([
+                'message'  => '重置话题失败',
+                'status_code'   => 500
+            ]);
+        }
+    }
+}

+ 44 - 0
app/Service/AliYunVodService.php

@@ -0,0 +1,44 @@
+<?php
+namespace App\Service;
+
+
+use Illuminate\Support\Facades\Log;
+use ShaoZeMing\AliVod\SDK\GetPlayInfoRequest;
+use ShaoZeMing\Aliyun\Core\DefaultAcsClient;
+use ShaoZeMing\Aliyun\Core\Profile\DefaultProfile;
+
+class AliYunVodService
+{
+    public function getPlayUrlByVideoId($videoId)
+    {
+        try {
+            $client = $this->initVodClient(config('aliyunvod.vod.AccessKeyID'), config('aliyunvod.vod.AccessKeySecret'));
+            $playInfo = $this->getPlayInfo($client, $videoId);
+            if($playInfo && is_object($playInfo)){
+                return $playInfo->PlayInfoList->PlayInfo[0]->PlayURL;
+            }else{
+                return '';
+            }
+        } catch (\Exception $e) {
+            Log::debug('获取视频地址失败:' . $e->getMessage());
+            return '';
+        }
+    }
+
+    private function initVodClient($accessKeyId, $accessKeySecret)
+    {
+        $regionId = 'cn-shanghai';  // 点播服务接入区域
+        $profile = DefaultProfile::getProfile($regionId, $accessKeyId, $accessKeySecret);
+        return new DefaultAcsClient($profile);
+    }
+
+    private function getPlayInfo($client, $videoId)
+    {
+        $request = new GetPlayInfoRequest();
+        $request->setVideoId($videoId);
+        $request->setAcceptFormat('JSON');
+        $playConfig = ['PlayDomain' => 'http://oss.caihongxingqiu.net/'];
+        $request->setPlayConfig(json_encode($playConfig));
+        return $client->getAcsResponse($request);
+    }
+}

+ 39 - 0
app/Traits/UserTrait.php

@@ -0,0 +1,39 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/11
+ * Time: 17:50
+ */
+
+namespace App\Traits;
+use Tymon\JWTAuth\Facades\JWTAuth;
+
+trait UserTrait
+{
+    public function getUserInfo($uid) {
+        try {
+            $url = config("customer.manage_service_url").'/user/memberView';
+            $array = [
+                'json' => ['uid' => $uid], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
+            ];
+            return http($url,$array, true, 'get');
+        } catch (\Exception $e) {
+            return [];
+        }
+
+    }
+
+    public function getSystemMember($number) {
+        try {
+            $url = config("customer.manage_service_url").'/user/member/getSystemMember';
+            $array = [
+                'json' => ['number' => $number], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
+            ];
+            return http($url,$array, false, 'get');
+        } catch (\Exception $e) {
+            return [];
+        }
+
+    }
+}

+ 26 - 0
app/Transformers/Behavior/BehaviorLogTransformer.php

@@ -0,0 +1,26 @@
+<?php
+namespace App\Transformers\Behavior;
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/13
+ * Time: 下午7:26
+ */
+use App\Models\BehaviorOperationLog;
+use League\Fractal\TransformerAbstract;
+
+class BehaviorLogTransformer extends TransformerAbstract
+{
+    public function transform(BehaviorOperationLog $logList)
+    {
+        return [
+            'id' => $logList['id'],
+            'username' => $logList['username'],
+            'behavior_id' => $logList['behavior_id'],
+            'operator_id' => $logList['operator_id'],
+            'type' => $logList['type'],
+            'created_at' => date($logList['created_at']),
+            'content' => $logList['content']
+        ];
+    }
+}

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

@@ -0,0 +1,42 @@
+<?php
+namespace App\Transformers\Behavior;
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/15
+ * Time: 下午14:39
+ */
+use App\Models\Behavior;
+use League\Fractal\TransformerAbstract;
+
+class BehaviorTransformer extends TransformerAbstract
+{
+    public function transform(Behavior $behavior_list)
+    {
+        return [
+            'id' => $behavior_list['id'],
+            'name' => $behavior_list['name'],
+            'virus_behavior_id' => $behavior_list['virus_behavior_id'],
+            'behavior_level' => $behavior_list['behavior_level'],
+            'behavior_cycle_type' => $behavior_list['behavior_cycle_type'],
+            'behavior_action_id' => $behavior_list['behavior_action_id'],
+            'behavior_cycle' => $behavior_list['behavior_cycle'],
+            'behavior_binding_users' => $behavior_list['behavior_binding_users'],
+            'physical_strength' => $behavior_list['physical_strength'],
+            'rainbow_beans' => $behavior_list['rainbow_beans'],
+            'remarks' => $behavior_list['remarks'],
+            'is_open' => $behavior_list['is_open'],
+            'behavioral_cycle_start_time' => $behavior_list['behavioral_cycle_start_time'],
+            'behavioral_cycle_end_time' => $behavior_list['behavioral_cycle_end_time'],
+            'allotted_quantity_rule' => $behavior_list['allotted_quantity_rule'],
+            'behavior_identification' => $behavior_list['behavior_identification'],
+            'trigger_times' => $behavior_list['trigger_times'],
+            'effective_trigger' => $behavior_list['effective_trigger'],
+            'relative_series' => $behavior_list['relative_series'],
+            'absolute_progression' => $behavior_list['absolute_progression'],
+            'grant_rainbow_beans' => $behavior_list['grant_rainbow_beans'],
+            'created_at' => date($behavior_list['created_at']),
+            'updated_at' => date($behavior_list['updated_at']),
+        ];
+    }
+}

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

@@ -0,0 +1,40 @@
+<?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),
+        ];
+    }
+}

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

@@ -0,0 +1,39 @@
+<?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' => intval($genaralList['trigger_type']),
+            'generation_type' => intval($genaralList['generation_type']),
+            'release_status' => intval($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),
+        ];
+    }
+}

+ 36 - 0
app/Transformers/Behavior/RegisteredRecordTransformer.php

@@ -0,0 +1,36 @@
+<?php
+namespace App\Transformers\Behavior;
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/14
+ * Time: 上午11:34
+ */
+use App\Models\RegisteredRecord;
+use League\Fractal\TransformerAbstract;
+
+class RegisteredRecordTransformer extends TransformerAbstract
+{
+    public function transform(RegisteredRecord $registeredList)
+    {
+        return [
+            'id' => $registeredList['id'],
+            'created_at' => date($registeredList['created_at']),
+            'virus_behavior_id' => $registeredList['virus_behavior_id'],
+            'uid' => $registeredList['uid'],
+            'trigger_time' => $registeredList['trigger_time'],
+            'physical_exertion' => $registeredList['physical_exertion'],
+            'trigger_type' => $registeredList['trigger_type'],
+            'absolute_progression' => $registeredList['absolute_progression'],
+            'superior_uid' => $registeredList['superior_uid'],
+            'release_status' => $registeredList['release_status'],
+            'generation_quantity' => $registeredList['generation_quantity'],
+            'quantity_issued' => $registeredList['quantity_issued'],
+            'behavior_cycle_type' => $registeredList->Behavior->behavior_cycle_type,
+            'name' => $registeredList->Behavior->name,
+            'relative_series' => $registeredList->Behavior->relative_series,
+            'is_open' => $registeredList->Behavior->is_open,
+            'bahavior_created_at' => date($registeredList->Behavior->created_at),
+        ];
+    }
+}

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

@@ -0,0 +1,37 @@
+<?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),
+        ];
+    }
+}

+ 31 - 0
app/Transformers/CategoryTransformer.php

@@ -0,0 +1,31 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019-06-10
+ * Time: 18:47
+ */
+namespace App\Transformers;
+use App\Models\Category;
+use League\Fractal\TransformerAbstract;
+use Illuminate\Support\Carbon;
+
+class CategoryTransformer extends TransformerAbstract{
+    public function transform(Category $category)
+    {
+        $topic = [];
+        foreach ($category->ct as $key=>$value){
+            $topic[] = $value->topic;
+        }
+        return [
+            'id' => $category['id'],
+            'name' => $category['name'],
+            'img' => $category['img'],
+            'is_suggest' => $category['is_suggest'],
+            'desc' => $category['desc'],
+            'created_at' => Carbon::parse($category['created_at'])->toDateTimeString(),
+            'topic_list'=>$topic,
+            'topic_count'=>count($topic)
+        ];
+    }
+}

+ 30 - 0
app/Transformers/CommunityMemberStatisticsTransformer.php

@@ -0,0 +1,30 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019-06-26
+ * Time: 15:14
+ */
+
+namespace App\Transformers;
+
+
+use App\Models\CommunityMemberStatistics;
+use League\Fractal\TransformerAbstract;
+
+class CommunityMemberStatisticsTransformer extends TransformerAbstract {
+    public function transform(CommunityMemberStatistics $communityMemberStatistics)
+    {
+
+        return [
+            'uid' => $communityMemberStatistics['uid'],
+            'post_count' => $communityMemberStatistics['post_count'],
+            'read_count' => $communityMemberStatistics['read_count'],
+            'share_count' => $communityMemberStatistics['share_count'],
+            'like_count' => $communityMemberStatistics['like_count'],
+            'unlike_count' => $communityMemberStatistics['unlike_count'],
+            'collect_count' => $communityMemberStatistics['collect_count'],
+            'comment_count' => $communityMemberStatistics['comment_count'],
+        ];
+    }
+}

+ 34 - 0
app/Transformers/DetailCategoryTransformer.php

@@ -0,0 +1,34 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019-06-10
+ * Time: 19:06
+ */
+
+namespace App\Transformers;
+
+use League\Fractal\TransformerAbstract;
+use App\Models\Category;
+use Illuminate\Support\Carbon;
+
+class DetailCategoryTransformer extends TransformerAbstract{
+
+    public function transform(Category $category)
+    {
+        $topic = [];
+        foreach ($category->ct as $key=>$value){
+            $topic[] = $value->topic;
+        }
+        return [
+            'id' => $category['id'],
+            'name' => $category['name'],
+            'img' => $category['img'],
+            'is_suggest' => $category['is_suggest'],
+            'desc' => $category['desc'],
+            'created_at' => Carbon::parse($category['created_at'])->toDateTimeString(),
+            'topic_list'=>$topic,
+            'topic_count'=>count($topic)
+        ];
+    }
+}

+ 36 - 0
app/Transformers/DetailTopicTransformer.php

@@ -0,0 +1,36 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019-06-10
+ * Time: 18:47
+ */
+namespace App\Transformers;
+use App\Models\Topic;
+use League\Fractal\TransformerAbstract;
+use Illuminate\Support\Carbon;
+
+class DetailTopicTransformer extends TransformerAbstract{
+
+    public function transform(Topic $topic)
+    {
+        $category = [];
+        foreach ($topic->ct as $key=>$value){
+                $category[] = $value->category;
+        }
+        return [
+            'id' => $topic['id'],
+            'name' => $topic['name'],
+            'img' => $topic['img'],
+            'is_suggest' => $topic['is_suggest'],
+            'is_hot' => $topic['is_hot'],
+            'is_open' => $topic['is_open'],
+            'desc' => $topic['desc'],
+            'post_count' => 0,
+            'follow_count' => 0,
+            'page_count' => 0,
+            'created_at' => Carbon::parse($topic['created_at'])->toDateTimeString(),
+            'category_list'=>$category,
+        ];
+    }
+}

+ 28 - 0
app/Transformers/DownloadTransformer.php

@@ -0,0 +1,28 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/11
+ * Time: 10:48
+ */
+namespace App\Transformers;
+
+use App\Models\Download;
+use Carbon\Carbon;
+use League\Fractal\TransformerAbstract;
+
+class DownloadTransformer extends TransformerAbstract
+{
+    public function transform(Download $download)
+    {
+        return [
+            'id' => $download['id'],
+            'username' => $download['username'],
+            'download_type' => $download['download_type'],
+            'download_status' => $download['download_status'],
+            'url' => $download['url'],
+            'created_at' => Carbon::parse($download['created_at'])->toDateTimeString(),
+        ];
+    }
+}

+ 9 - 1
app/Transformers/Post/CommentTransformer.php

@@ -15,13 +15,21 @@ class CommentTransformer extends TransformerAbstract
 {
     public function transform(PostComment $postComment)
     {
+        if($postComment['is_delete']){
+            $content = '该评论已被删除';
+        }elseif($postComment['reply_username']){
+            $content = '回复 @'.subtext($postComment['reply_username'], 6).': '.$postComment['content'];
+        }else{
+            $content = $postComment['content'];
+        }
         return [
             'id' => $postComment['id'],
+            'post_id' => $postComment['post_id'],
             'parent_id' => $postComment['parent_id'],
             'uid' => $postComment['uid'],
             'username' => $postComment['username'],
             'avatar' => $postComment['avatar'],
-            'content' => $postComment['is_delete'] == 1 ? '该评论已被删除' : $postComment['content'],
+            'content' => $content,
             'created_at' => Carbon::parse($postComment['created_at'])->toDateTimeString(),
             'is_delete' => $postComment['is_delete'],
         ];

+ 1 - 0
app/Transformers/Post/DetailTransformer.php

@@ -28,6 +28,7 @@ class DetailTransformer extends  TransformerAbstract
             'topic' => $post->topic(),
             'title' => $post['title'],
             'content' => $post['content'],
+            'type' => $post['type'],
             'img' => $post['img'],
             'video' => $post['video'],
             'imgs' => $imgs,

+ 39 - 0
app/Transformers/Post/LogTransformer.php

@@ -0,0 +1,39 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/10
+ * Time: 17:21
+ */
+
+namespace App\Transformers\Post;
+use App\Models\PostLog;
+use Illuminate\Support\Carbon;
+use League\Fractal\TransformerAbstract;
+
+class LogTransformer extends TransformerAbstract
+{
+    public function transform(PostLog $postLog)
+    {
+        $type = [
+            'add_pv' => '增加浏览量:',
+            'add_praise_count' => '增加点赞数:',
+            'add_collect_count' => '增加收藏数:',
+            'add_share_count' => '增加分享数:',
+        ];
+        $data = json_decode($postLog['content']);
+        $content = '';
+        foreach($data as $key => $val){
+            if(!$val) continue;
+            $content .= $type[$key] . $val .'、';
+        }
+        $content = rtrim($content, '、');
+        return [
+            'id' => $postLog['id'],
+            'username' => $postLog['username'],
+            'log_type' => $postLog['log_type'],
+            'created_at' => Carbon::parse($postLog['created_at'])->toDateTimeString(),
+            'content' => $content,
+        ];
+    }
+}

+ 38 - 0
app/Transformers/TopicTransformer.php

@@ -0,0 +1,38 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019-06-10
+ * Time: 18:47
+ */
+namespace App\Transformers;
+use App\Models\Topic;
+use League\Fractal\TransformerAbstract;
+use Illuminate\Support\Carbon;
+
+class TopicTransformer extends TransformerAbstract{
+
+    public function transform(Topic $topic)
+    {
+        $category = [];
+        foreach ($topic->ct as $key=>$value){
+            if($key < 3){
+                $category[] = $value->category->name;
+            }
+        }
+        return [
+            'id' => $topic['id'],
+            'name' => $topic['name'],
+            'img' => $topic['img'],
+            'is_suggest' => $topic['is_suggest'],
+            'is_hot' => $topic['is_hot'],
+            'is_open' => $topic['is_open'],
+            'desc' => $topic['desc'],
+            'post_count' => 0,
+            'follow_count' => 0,
+            'page_count' => 0,
+            'created_at' => Carbon::parse($topic['created_at'])->toDateTimeString(),
+            'category_list'=>$category,
+        ];
+    }
+}

+ 2 - 0
bootstrap/app.php

@@ -30,6 +30,8 @@ $app->configure('auth');
 $app->configure('jwt');
 $app->configure('customer');
 $app->configure('database');
+$app->configure('constants');
+$app->configure('aliyunvod');
 
 /*
 |--------------------------------------------------------------------------

+ 10 - 7
composer.json

@@ -6,22 +6,25 @@
     "type": "project",
     "require": {
         "php": ">=7.1.3",
+        "cviebrock/laravel-elasticsearch": "^3.5",
         "dingo/api": "^2.2",
+        "doctrine/dbal": "^2.9",
         "guzzlehttp/guzzle": "^6.3",
-        "cviebrock/laravel-elasticsearch": "^3.5",
-        "php-amqplib/php-amqplib": "^2.9",
         "hhxsv5/laravel-s": "~3.4.0",
+        "illuminate/redis": "^5.8",
         "laravel/lumen-framework": "5.8.*",
-        "vlucas/phpdotenv": "^3.3",
+        "league/csv": "^9.1",
         "multilinguals/apollo-client": "^0.1.2",
-        "illuminate/redis": "^5.8",
+        "php-amqplib/php-amqplib": "^2.9",
         "predis/predis": "^1.1",
-        "tymon/jwt-auth": "1.0.0-rc.4.1"
+        "tymon/jwt-auth": "1.0.0-rc.4.1",
+        "shaozeming/aliyun-vod": "^2.0",
+        "vlucas/phpdotenv": "^3.3"
     },
     "require-dev": {
         "fzaninotto/faker": "^1.4",
-        "phpunit/phpunit": "^7.0",
-        "mockery/mockery": "^1.0"
+        "mockery/mockery": "^1.0",
+        "phpunit/phpunit": "^7.0"
     },
     "autoload": {
         "classmap": [

+ 20 - 0
config/aliyunvod.php

@@ -0,0 +1,20 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: shaozeming
+ * Date: 2019/3/9
+ * Time: 11:57 AM
+ */
+
+return [
+
+    /*点播配置*/
+    'vod' => [
+        'AccessKeyID' => 'LTAINdryz1AB0KpO',
+        'AccessKeySecret' => 'xjKm6yWIewMBQdJYC3H8CnuIOvBv8l',
+        'regionId' => 'cn-shanghai',   // 点播服务接入区域
+        'timeout' => '3600',  // 如果是获取签名有效时间为多少
+        'type' => 'access',  //类型:access|sts 如果是sts 实例化对象时候需要传入$securityToken
+        'acceptFormat' => 'JSON',  //返回数据格式
+    ],
+];

+ 11 - 0
config/constants.php

@@ -0,0 +1,11 @@
+<?php
+
+/**
+ * 常量配置
+ */
+
+return [
+    'VIRUS_APP_ID' => env('VIRUS_APP_ID', '5cfdcf97249e6a00082639d3'),
+    'VIRUS_APP_SECRET' => env('VIRUS_APP_SECRET', '4f2afc9c4099ee1f39c9f551123e54bd'),
+    'VIRUS_URL' => env('VIRUS_URL', 'https://api.dev.caihongxingqiu.com/virus/'),
+];

+ 3 - 0
config/customer.tpl

@@ -3,4 +3,7 @@
 return [
     'jwt_secret' => '{jwt_secret}',
     'manage_service_url' => '{manage_service_url}',
+    'VIRUS_URL' => '{VIRUS_URL}',
+    'VIRUS_APP_ID' => '{VIRUS_APP_ID}',
+    'VIRUS_APP_SECRET' => '{VIRUS_APP_SECRET}',
 ];

+ 36 - 0
database/migrations/2019_06_01_062519_create_behavior_operation_log_table.php

@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateBehaviorOperationLogTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('behavior_operation_log', function (Blueprint $table) {
+            $table->increments('id');
+            $table->integer('operator_id')->comment('操作人ID');
+            $table->integer('behavior_id')->comment('行为ID');
+            $table->string('username')->comment('用户名');
+            $table->tinyInteger('type')->nullable()->comment('操作类型:0.登记行为;1.编辑行为;2.开/关行为');
+            $table->string('content')->nullable()->comment('操作内容');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::drop('behavior_operation_log');
+    }
+}

+ 49 - 0
database/migrations/2019_06_01_074135_create_behavior_table.php

@@ -0,0 +1,49 @@
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateBehaviorTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('behavior', function (Blueprint $table) {
+            $table->increments('id');
+            $table->string('virus_behavior_id')->comment('virus对应行为ID');
+            $table->string('name')->comment('行为名称');
+            $table->tinyInteger('behavior_level')->default(0)->comment('行为级别:0.唯一/基础行为;1.多级行为');
+            $table->tinyInteger('behavior_cycle_type')->default(0)->comment('行为周期类型:0.普通/短期;1.长期');
+            $table->integer('behavior_action_id')->nullable()->comment('绑定的动作ID');
+            $table->string('behavior_cycle')->nullable()->comment('行为时间周期');
+            $table->integer('behavior_binding_users')->nullable()->comment('行为绑定用户:0.所有用户');
+            $table->string('physical_strength')->nullable()->comment('行为消耗体力值');
+            $table->string('rainbow_beans')->nullable()->comment('行为生成彩虹豆');
+            $table->string('remarks',100)->nullable()->comment('备注');
+            $table->tinyInteger('is_open')->comment('是否开启:0.关闭;1.开启');
+            $table->date('behavioral_cycle_start_time')->nullable()->comment('行为时间周期开始时间');
+            $table->date('behavioral_cycle_end_time')->nullable()->comment('行为时间周期结束时间');
+            $table->json('allotted_quantity_rule')->nullable()->comment('彩虹豆分配规则');
+            $table->string('behavior_identification')->nullable()->comment('行为标识');//英文的行为名称
+            $table->integer('trigger_times')->nullable()->comment('触发次数');
+            $table->integer('effective_trigger')->nullable()->comment('有效触发次数');
+            $table->integer('relative_series')->nullable()->comment('相对级数');
+            $table->integer('absolute_progression')->nullable()->comment('绝对级数');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::drop('behavior');
+    }
+}

+ 41 - 0
database/migrations/2019_06_03_011812_create_registered_accounts_record_table.php

@@ -0,0 +1,41 @@
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateRegisteredAccountsRecordTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('registered_accounts_record', function (Blueprint $table) {
+            $table->increments('id');
+            $table->string('virus_behavior_id')->comment('virus行为ID');
+            $table->integer('uid')->comment('用户ID');
+            $table->date('trigger_time')->comment('触发时间');
+            $table->string('physical_exertion')->nullable()->comment('消耗体力值');
+            $table->tinyInteger('trigger_type')->nullable()->comment('触发类型:0:无效触发;1.有效触发');
+            $table->tinyInteger('generation_type')->nullable()->comment('生成类型:1:彩虹豆');
+            $table->integer('absolute_progression')->nullable()->comment('绝对级数');
+            $table->integer('superior_uid')->nullable()->comment('上级用户ID');
+            $table->tinyInteger('release_status')->nullable()->comment('发放状态:0.异常;1.正常');
+            $table->integer('generation_quantity')->nullable()->comment('生成数量');
+            $table->integer('quantity_issued')->nullable()->comment('发放数量');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::drop('registered_accounts_record');
+    }
+}

+ 42 - 0
database/migrations/2019_06_03_021228_create_comment_account_record_table.php

@@ -0,0 +1,42 @@
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateCommentAccountRecordTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('comment_account_record', function (Blueprint $table) {
+            $table->increments('id');
+            $table->string('virus_behavior_id')->comment('virus行为ID');
+            $table->integer('uid')->comment('用户ID');
+            $table->date('upper_trigger_time')->comment('上级评论触发时间');
+            $table->integer('related_content_id')->comment('关联内容id');
+            $table->integer('content_author_id')->comment('内容作者id');
+            $table->integer('superior_commentator_id')->comment('上级评论者ID');
+            $table->string('physical_exertion')->nullable()->comment('消耗体力值');
+            $table->tinyInteger('trigger_type')->nullable()->comment('触发类型:0:无效触发;1.有效触发');
+            $table->tinyInteger('generation_type')->nullable()->comment('生成类型:1:彩虹豆');
+            $table->tinyInteger('release_status')->nullable()->comment('发放状态:0.异常;1.正常');
+            $table->integer('generation_quantity')->nullable()->comment('生成数量');
+            $table->integer('quantity_issued')->nullable()->comment('发放数量');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::drop('comment_account_record');
+    }
+}

+ 41 - 0
database/migrations/2019_06_03_024134_create_general_ledger_record_table.php

@@ -0,0 +1,41 @@
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateGeneralLedgerRecordTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('general_ledger_record', function (Blueprint $table) {
+            $table->increments('id');
+            $table->string('virus_behavior_id')->comment('virus行为ID');
+            $table->integer('uid')->comment('用户ID');
+            $table->date('trigger_time')->comment('触发时间');
+            $table->integer('related_content_id')->comment('关联内容id');
+            $table->integer('content_author_id')->comment('内容作者id');
+            $table->string('physical_exertion')->nullable()->comment('消耗体力值');
+            $table->tinyInteger('trigger_type')->nullable()->comment('触发类型:0:无效触发;1.有效触发');
+            $table->tinyInteger('generation_type')->nullable()->comment('生成类型:1:彩虹豆');
+            $table->tinyInteger('release_status')->nullable()->comment('发放状态:0.异常;1.正常');
+            $table->integer('generation_quantity')->nullable()->comment('生成数量');
+            $table->integer('quantity_issued')->nullable()->comment('发放数量');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::drop('general_ledger_record');
+    }
+}

+ 40 - 0
database/migrations/2019_06_04_011501_create_release_record_table.php

@@ -0,0 +1,40 @@
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateReleaseRecordTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('release_record', function (Blueprint $table) {
+            $table->increments('id');
+            $table->string('virus_behavior_id')->comment('virus行为ID');
+            $table->integer('uid')->comment('用户ID');
+            $table->date('trigger_time')->comment('触发时间');
+            $table->integer('related_content_id')->comment('关联内容id');
+            $table->string('physical_exertion')->nullable()->comment('消耗体力值');
+            $table->tinyInteger('trigger_type')->nullable()->comment('触发类型:0:无效触发;1.有效触发');
+            $table->tinyInteger('generation_type')->nullable()->comment('生成类型:1:彩虹豆');
+            $table->tinyInteger('release_status')->nullable()->comment('发放状态:0.异常;1.正常');
+            $table->integer('generation_quantity')->nullable()->comment('生成数量');
+            $table->integer('quantity_issued')->nullable()->comment('发放数量');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::drop('release_record');
+    }
+}

+ 55 - 0
database/migrations/2019_06_11_095634_create_table_downloads.php

@@ -0,0 +1,55 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateTableDownloads extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('downloads', function (Blueprint $table) {
+            $table->bigIncrements('id');
+
+            $table->integer('uid')
+                ->unsigned()
+                ->comment('用户uid');
+
+            $table->string('username', 32)
+                ->default('')
+                ->comment('用户昵称');
+
+            $table->string('download_type', 32)
+                ->default('post')
+                ->comment('类型:post内容,post_waste内容回收站');
+
+            $table->tinyInteger('download_status')
+                ->default(0)
+                ->comment('状态:0生成中,1成功,2失败');
+
+            $table->mediumText('params')
+                ->comment('参数');
+
+            $table->string('url', 255)
+                ->default('')
+                ->comment('下载地址');
+
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('downloads');
+    }
+}

+ 30 - 0
database/migrations/2019_06_11_163708_modify_download_status_to_table_download.php

@@ -0,0 +1,30 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class ModifyDownloadStatusToTableDownload extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        DB::statement("ALTER TABLE downloads MODIFY COLUMN download_status TINYINT (4) NOT NULL DEFAULT 0 COMMENT '下载状态:0待处理,1生成中,2成功,3失败'");
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('download', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 32 - 0
database/migrations/2019_06_13_143624_update_behavior_action_id_to_behavior_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class UpdateBehaviorActionIdToBehaviorTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('behavior', function (Blueprint $table) {
+            $table->string('behavior_action_id')->nullable()->change();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('behavior', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 33 - 0
database/migrations/2019_06_13_160051_update_behavior_id_to_behavior_operation_log_table.php

@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class UpdateBehaviorIdToBehaviorOperationLogTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('behavior_operation_log', function (Blueprint $table) {
+            $table->string('behavior_id')->nullable()->change();
+            $table->text('content')->nullable()->change();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('behavior_operation_log', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 33 - 0
database/migrations/2019_06_13_174844_add_comment_id_to_comment_account_record_table.php

@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddCommentIdToCommentAccountRecordTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('comment_account_record', function (Blueprint $table) {
+            $table->integer('current_comment_id')->nullable()->comment('当前评论ID');
+            $table->integer('superior_comment_id')->nullable()->comment('上级评论ID');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('comment_account_record', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 30 - 0
database/migrations/2019_06_14_090938_drop_comment_real_count_from_post_data.php

@@ -0,0 +1,30 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class DropCommentRealCountFromPostData extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        DB::statement("ALTER TABLE post_data DROP COLUMN comment_real_count");
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('post_data', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 40 - 0
database/migrations/2019_06_14_092948_add_reply_uid_to_table_post_comment.php

@@ -0,0 +1,40 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddReplyUidToTablePostComment extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('post_comment', function (Blueprint $table) {
+            $table->integer('reply_uid')
+                ->default(0)
+                ->after('username')
+                ->comment('回复对象uid');
+
+            $table->string('reply_username', 32)
+                ->default('')
+                ->after('reply_uid')
+                ->comment('回复对象昵称');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('post_data', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 59 - 0
database/migrations/2019_06_14_155026_create_table_feed.php

@@ -0,0 +1,59 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateTableFeed extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('feed', function (Blueprint $table) {
+            $table->bigIncrements('id');
+
+            $table->integer('uid')
+                ->index('uid')
+                ->comment('uid');
+
+            $table->integer('follow_uid')
+                ->comment('关注人uid');
+
+            $table->string('follow_username')
+                ->default('')
+                ->comment('关注人昵称');
+
+            $table->string('follow_avatar')
+                ->default('')
+                ->comment('关注人头像');
+
+            $table->string('type', 32)
+                ->default('post_create')
+                ->comment('类型');
+
+            $table->integer('relate_id')
+                ->default(0)
+                ->comment('相关id');
+
+            $table->string('content', 200)
+                ->default('')
+                ->comment('内容');
+
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('feed');
+    }
+}

+ 33 - 0
database/migrations/2019_06_14_164201_add_behavior_value_to_general_ledger_record_table.php

@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddBehaviorValueToGeneralLedgerRecordTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('general_ledger_record', function (Blueprint $table) {
+            $table->tinyInteger('behavior_value')->nullable()->comment('行为值:0:未点赞(收藏);1.已点赞(收藏)');
+
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('general_ledger_record', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 38 - 0
database/migrations/2019_06_14_192326_create_table_collect.php

@@ -0,0 +1,38 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateTableCollect extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('post_collect', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->integer('uid')
+                ->index('uid')
+                ->comment('用户ID');
+
+            $table->integer('post_id')
+                ->default(0)
+                ->comment('帖子id');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('post_collect');
+    }
+}

+ 38 - 0
database/migrations/2019_06_14_192526_create_table_post_like.php

@@ -0,0 +1,38 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateTablePostLike extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('post_like', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->integer('uid')
+                ->index('uid')
+                ->comment('用户ID');
+
+            $table->integer('post_id')
+                ->default(0)
+                ->comment('帖子id');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('post_like');
+    }
+}

+ 32 - 0
database/migrations/2019_06_15_111834_add_grant_rainbow_beans_to_behavior_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddGrantRainbowBeansToBehaviorTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('behavior', function (Blueprint $table) {
+            $table->string('grant_rainbow_beans')->nullable()->comment('行为发放彩虹豆');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('behavior', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 38 - 0
database/migrations/2019_06_15_160843_create_table_post_dislike.php

@@ -0,0 +1,38 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateTablePostDislike extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('post_dislike', function (Blueprint $table) {
+            $table->bigIncrements('id');
+
+            $table->integer('post_id')
+                ->comment('内容id');
+
+            $table->integer('uid')
+                ->comment('用户uid');
+
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('post_dislike');
+    }
+}

+ 32 - 0
database/migrations/2019_06_15_181745_update_upper_trigger_time_to_comment_account_record_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class UpdateUpperTriggerTimeToCommentAccountRecordTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('comment_account_record', function (Blueprint $table) {
+            $table->dateTime('upper_trigger_time')->nullable()->comment('上级评论触发时间')->change();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('comment_account_record', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 32 - 0
database/migrations/2019_06_15_182120_update_trigger_time_to_general_ledger_record_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class UpdateTriggerTimeToGeneralLedgerRecordTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('general_ledger_record', function (Blueprint $table) {
+            $table->dateTime('trigger_time')->nullable()->comment('触发时间')->change();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('general_ledger_record', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 32 - 0
database/migrations/2019_06_15_182225_update_trigger_time_to_registered_accounts_record_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class UpdateTriggerTimeToRegisteredAccountsRecordTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('registered_accounts_record', function (Blueprint $table) {
+            $table->dateTime('trigger_time')->nullable()->comment('触发时间')->change();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('registered_accounts_record', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 32 - 0
database/migrations/2019_06_15_182306_update_trigger_time_to_release_record_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class UpdateTriggerTimeToReleaseRecordTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('release_record', function (Blueprint $table) {
+            $table->dateTime('trigger_time')->nullable()->comment('触发时间')->change();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('release_record', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 33 - 0
database/migrations/2019_06_15_182526_update_behavioral_cycle_start_time_to_behavior_table.php

@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class UpdateBehavioralCycleStartTimeToBehaviorTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('behavior', function (Blueprint $table) {
+            $table->dateTime('behavioral_cycle_start_time')->nullable()->comment('行为时间周期开始时间')->change();
+            $table->dateTime('behavioral_cycle_end_time')->nullable()->comment('行为时间周期结束时间')->change();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('behavior', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 33 - 0
database/migrations/2019_06_17_182656_create_member_follow_topic_table.php

@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateMemberFollowTopicTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('member_follow_topic', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->integer('uid')->default(0)->comment('用户uid');
+            $table->integer('topic_id')->default(0)->comment('话题id');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('member_follow_topic');
+    }
+}

+ 38 - 0
database/migrations/2019_06_18_100826_create_table_post_share.php

@@ -0,0 +1,38 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateTablePostShare extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('post_share', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->integer('uid')
+                ->index('uid')
+                ->comment('用户ID');
+
+            $table->integer('post_id')
+                ->default(0)
+                ->comment('帖子id');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('post_share');
+    }
+}

+ 33 - 0
database/migrations/2019_06_18_180725_update_grant_rainbow_beans_to_behavior_table.php

@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class UpdateGrantRainbowBeansToBehaviorTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('behavior', function (Blueprint $table) {
+            $table->integer('rainbow_beans')->default(0)->comment('行为生成彩虹豆')->change();
+
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('behavior', function (Blueprint $table) {
+            //
+        });
+    }
+}

+ 0 - 0
database/migrations/2019_06_18_181621_update_rainbow_beans_to_behavior_table.php


Niektoré súbory nie sú zobrazené, pretože je v týchto rozdielových dátach zmenené mnoho súborov