Procházet zdrojové kódy

Merge branch 'develop'

xielin před 5 roky
rodič
revize
947d5010d2
38 změnil soubory, kde provedl 1387 přidání a 52 odebrání
  1. 1 1
      .rocketeer/config.php
  2. 1 1
      .rocketeer/scm.php
  3. 9 0
      app/Helper/helper.php
  4. 62 0
      app/Http/Controllers/ConfigController.php
  5. 2 1
      app/Http/Controllers/Controller.php
  6. 162 0
      app/Http/Controllers/Post/PostController.php
  7. 1 1
      app/Http/Controllers/V1/TestController.php
  8. 0 12
      app/Http/Controllers/V1/Controller.php
  9. 16 0
      app/Models/Category.php
  10. 16 0
      app/Models/CategoryTopic.php
  11. 35 0
      app/Models/Post.php
  12. 17 0
      app/Models/PostComment.php
  13. 17 0
      app/Models/PostData.php
  14. 19 0
      app/Models/PostImgs.php
  15. 17 0
      app/Models/PostLog.php
  16. 17 0
      app/Models/Topic.php
  17. 323 0
      app/Repositories/Post/PostRepository.php
  18. 34 0
      app/Traits/PostTrait.php
  19. 29 0
      app/Transformers/Post/CommentTransformer.php
  20. 44 0
      app/Transformers/Post/DetailTransformer.php
  21. 37 0
      app/Transformers/Post/PostTransformer.php
  22. 1 0
      bootstrap/app.php
  23. 3 7
      composer.json
  24. 36 0
      database/migrations/2019_06_03_094309_create_category_table.php
  25. 34 0
      database/migrations/2019_06_03_094426_create_category_topic_table.php
  26. 42 0
      database/migrations/2019_06_03_094442_create_topic_table.php
  27. 86 0
      database/migrations/2019_06_03_162324_create_table_post.php
  28. 96 0
      database/migrations/2019_06_03_162403_create_table_post_data.php
  29. 61 0
      database/migrations/2019_06_03_162449_create_table_post_comment.php
  30. 42 0
      database/migrations/2019_06_03_162527_crate_table_post_imgs.php
  31. 54 0
      database/migrations/2019_06_03_162603_crate_table_post_log.php
  32. 35 0
      database/migrations/2019_06_06_161402_add_create_bean_to_table_post_data.php
  33. 1 1
      deploy/nginx/conf.d/app.beta.conf
  34. 1 1
      deploy/nginx/conf.d/app.dev.conf
  35. 5 5
      docker-compose-beta.yml
  36. 4 4
      docker-compose-dev.yml
  37. 11 1
      resources/lang/zh-CN/validation.php
  38. 16 17
      routes/api.php

+ 1 - 1
.rocketeer/config.php

@@ -7,7 +7,7 @@ return [
     // The name of the application to deploy
     // This will create a folder of the same name in the root directory
     // configured above, so be careful about the characters used
-    'application_name' => 'order-manage',
+    'application_name' => 'community-manage',
 
     // Plugins
     ////////////////////////////////////////////////////////////////////

+ 1 - 1
.rocketeer/scm.php

@@ -10,7 +10,7 @@ return [
 
     // The SSH/HTTPS address to your repository
     // Example: https://github.com/vendor/website.git
-    'repository' => 'http://caihongxingqiu:Ch20151002@git.caihongxingqiu.net/rainbow/order-manage.git',
+    'repository' => 'http://caihongxingqiu:Ch20151002@git.caihongxingqiu.net/rainbow/community-manage.git',
 
     // The repository credentials : you can leave those empty
     // if you're using SSH or if your repository is public

+ 9 - 0
app/Helper/helper.php

@@ -15,4 +15,13 @@ if ( ! function_exists('config_path'))
     {
         return app()->basePath() . '/config' . ($path ? '/' . $path : $path);
     }
+
+    function subtext($text, $length)
+    {
+        if(mb_strlen($text, 'utf8') > $length) {
+            return mb_substr($text, 0, $length, 'utf8').'...';
+        } else {
+        return $text;
+    }
+}
 }

+ 62 - 0
app/Http/Controllers/ConfigController.php

@@ -0,0 +1,62 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: wangzhiqiang
+ * Date: 2019/4/24
+ * Time: 9:36
+ */
+namespace App\Http\Controllers;
+
+class ConfigController extends Controller
+{
+    /**
+     * Create a new controller instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        //
+    }
+    public function index()
+    {
+        return [
+            //内容类型
+            'type' => [
+                'image' => '图文',
+                'video' => '视频',
+                'html' => '富文本',
+            ],
+            //日志类型
+            'log_type' => [
+                'add_data' => '增加数据',
+            ],
+            //是否推荐
+            'is_suggest' => [
+                '1' => '是',
+                '0' => '否',
+            ],
+            //是否隐藏
+            'is_hide' => [
+                '1' => '是',
+                '0' => '否',
+            ],
+            //是否删除
+            'is_delete' => [
+                '1' => '是',
+                '0' => '否',
+            ],
+            //是否热门
+            'is_hot' => [
+                '1' => '是',
+                '0' => '否',
+            ],
+            //是否开启
+            'is_open' => [
+                '1' => '是',
+                '0' => '否',
+            ],
+
+        ];
+    }
+}

+ 2 - 1
app/Http/Controllers/Controller.php

@@ -3,8 +3,9 @@
 namespace App\Http\Controllers;
 
 use Illuminate\Routing\Controller as BaseController;
+use Dingo\Api\Routing\Helpers;
 
 class Controller extends BaseController
 {
-
+    use Helpers;
 }

+ 162 - 0
app/Http/Controllers/Post/PostController.php

@@ -0,0 +1,162 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/5
+ * Time: 15:58
+ */
+namespace App\Http\Controllers\Post;
+
+use App\Repositories\Post\PostRepository;
+use App\Transformers\Post\CommentTransformer;
+use App\Transformers\Post\DetailTransformer;
+use App\Transformers\Post\PostTransformer;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Validator;
+use App\Http\Controllers\Controller;
+use Illuminate\Validation\Rule;
+use League\Fractal\Manager;
+use League\Fractal\Pagination\IlluminatePaginatorAdapter;
+use League\Fractal\Resource\Collection;
+use League\Fractal\Resource\Item;
+
+class PostController extends Controller
+{
+    public function __construct(PostRepository $postRepository)
+    {
+        $this->postRepository = $postRepository;
+    }
+
+    /**
+     * 内容列表
+     */
+    public function index(Request $request)
+    {
+        $productList = $this->postRepository->lists($request->all());
+        $fractal = new Manager();
+        $resource = new Collection($productList, new PostTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($productList));
+        $data = $fractal->createData($resource)->toArray();
+        $data['extra'] = [
+            'filters' => [
+                'keyword',
+                'content',
+                'topic_ids',
+                'category_ids',
+                'is_suggest',
+                'created_at',
+                'type',
+                'sort'
+            ],
+            'columns' => [
+                'id',
+                'created_at',
+                'uid',
+                'topic',
+                'content',
+                'location',
+                'pv',
+                'praise_count',
+                'share_count',
+                'comment_count',
+                'collect_count',
+                'create_bean',
+                'is_suggest'
+            ]
+        ];
+        return $data;
+    }
+
+    /**
+     * 内容详情
+     */
+    public function detail(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|exists:post'
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+
+        $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'];
+        return $data;
+    }
+
+    /**
+     * 发布内容
+     */
+    public function create(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'uid' => 'required|integer',
+            'type' => ['required',Rule::in('image', 'video', 'html')],
+            'is_suggest' => ['required',Rule::in(0, 1)],
+            'img' => 'required|url',
+            'video' => 'required_if:type,video|string|url',
+            'topic_ids' => 'required|string|max:64',
+            'title' => 'nullable|string|max:20',
+            'content' => 'required|string|max:20',
+            'location' => 'required|string',
+            'imgs' => 'required_if:type,image|array|max:9',
+            'imgs.*' => 'required|url',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->postRepository->create($request->all());
+    }
+
+    /**
+     * 推荐内容
+     */
+    public function suggest(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|integer',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->postRepository->suggest($request->all());
+    }
+
+    /**
+     * 删除内容
+     */
+    public function delete(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|integer',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->postRepository->delete($request->all());
+    }
+
+    /**
+     * 隐藏内容
+     */
+    public function hide(Request $request)
+    {
+        $validator = Validator::make($request->all(), [
+            'id' => 'required|integer',
+        ]);
+        if ($validator->fails()) {
+            return $this->response->error($validator->errors()->first(), 500);
+        }
+        return  $this->postRepository->hide($request->all());
+    }
+
+}

+ 1 - 1
app/Http/Controllers/V1/TestController.php

@@ -6,7 +6,7 @@
  * Time: 14:36
  */
 
-namespace App\Http\Controllers\V1;
+namespace App\Http\Controllers;
 
 
 class TestController extends Controller

+ 0 - 12
app/Http/Controllers/V1/Controller.php

@@ -1,12 +0,0 @@
-<?php
-
-namespace App\Http\Controllers\V1;
-
-
-use Dingo\Api\Routing\Helpers;
-use App\Http\Controllers\Controller as BaseController;
-
-class Controller extends BaseController
-{
-    use Helpers;
-}

+ 16 - 0
app/Models/Category.php

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

+ 16 - 0
app/Models/CategoryTopic.php

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

+ 35 - 0
app/Models/Post.php

@@ -0,0 +1,35 @@
+<?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 Post extends Model
+{
+    //
+    use SoftDeletes;
+    protected $table = 'post';
+    protected $guarded = [];
+
+    public function imgs()
+    {
+        return $this->hasMany('App\Models\PostImgs', 'post_id', 'id');
+    }
+
+    public function data()
+    {
+        return $this->hasOne('App\Models\PostData', 'post_id', 'id');
+    }
+
+    public function topic()
+    {
+        return Topic::whereIn('id', explode(',', $this->topic_ids))->pluck('name', 'id');
+    }
+
+}

+ 17 - 0
app/Models/PostComment.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 PostComment extends Model
+{
+//
+    protected $table = 'post_comment';
+    protected $guarded = [];
+}

+ 17 - 0
app/Models/PostData.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 PostData extends Model
+{
+//
+    protected $table = 'post_data';
+    protected $guarded = [];
+}

+ 19 - 0
app/Models/PostImgs.php

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

+ 17 - 0
app/Models/PostLog.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 PostLog extends Model
+{
+//
+    protected $table = 'post_log';
+    protected $guarded = [];
+}

+ 17 - 0
app/Models/Topic.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 Topic extends Model
+{
+    //
+    protected $table = 'topic';
+    protected $guarded = [];
+}

+ 323 - 0
app/Repositories/Post/PostRepository.php

@@ -0,0 +1,323 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/5
+ * Time: 16:03
+ */
+namespace App\Repositories\Post;
+
+use App\Models\CategoryTopic;
+use App\Models\Post;
+use App\Models\PostComment;
+use App\Models\PostData;
+use App\Models\PostImgs;
+use App\Models\PostLog;
+use App\Models\Topic;
+use App\Traits\PostTrait;
+use Illuminate\Database\QueryException;
+use Dingo\Api\Http\Response;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Redis;
+use Symfony\Component\HttpKernel\Exception\HttpException;
+use Tymon\JWTAuth\Facades\JWTAuth;
+
+class PostRepository
+{
+    use PostTrait;
+
+    public function __construct(Post $post,
+                                PostData $postData,
+                                PostComment $postComment,
+                                PostImgs $postImgs,
+                                PostLog $postLog,
+                                CategoryTopic $categoryTopic,
+                                Topic $topic)
+    {
+        $this->post = $post;
+        $this->postData = $postData;
+        $this->postComment = $postComment;
+        $this->postImgs = $postImgs;
+        $this->postLog = $postLog;
+        $this->categoryTopic = $categoryTopic;
+        $this->topic = $topic;
+    }
+
+    /**
+     * 发布内容
+     */
+    public function create($request)
+    {
+        //验证小号
+
+        //验证话题
+        $topicIds = $this->topic->whereIn('id', explode(',', $request['topic_ids']))->pluck('id')->toArray();
+        $topicCount = count($topicIds);
+        if($topicCount == 0 || $topicCount >= 5){
+            return Response::create([
+                'message'  => '所选话题必须1-5个',
+                'status_code'   => 500
+            ]);
+        }
+        $topicIds = implode(',', $topicIds);
+
+        $data = [
+            'uid' => $request['uid'],
+            'username' => '暂无',
+            'mobile' => '暂无',
+            'avatar' => '暂无',
+            'type' => $request['type'],
+            'img' => $request['img'],
+            'video' => $request['video']??'',
+            'topic_ids' => $topicIds,
+            'title' => $request['title']??'',
+            'content' => $request['content'],
+            'location' => $request['location']??'',
+            'is_suggest' => $request['is_suggest'],
+            'is_hide' => 0
+        ];
+
+        $date = date('Y-m-d H:i:s');
+
+
+        DB::beginTransaction();
+        try{
+            $post = $this->post->create($data);
+
+            $this->postData->create([
+                'post_id' => $post->id,
+                'pv' => 0,
+                'pv_real' => 0,
+                'dislike_count' => 0,
+                'praise_count' => 0,
+                'praise_real_count' => 0,
+                'share_count' => 0,
+                'share_real_count' => 0,
+                'comment_count' => 0,
+                'comment_real_count' => 0,
+                'collect_count' => 0,
+                'collect_real_count' => 0,
+                'available_bean' => $this->availableBean(),
+                'will_collect_bean' => rand(100, 200),
+                'collect_bean' => 0,
+                'weight' => 0
+            ]);
+
+            if(!empty($request['imgs']) && $request['type'] == 'image'){
+                $imgData = [];
+                foreach($request['imgs'] as $img){
+                    $imgData[] = [
+                        'post_id' => $post->id,
+                        'img' => $img,
+                        'created_at' => $date,
+                        'updated_at' => $date
+                    ];
+                }
+                $this->postImgs->insert($imgData);
+            }
+
+            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 lists($request)
+    {
+        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+        $where = [];
+        if(isset($request['content'])){
+            $where[] = ['content', 'like', "%{$request['content']}%"];
+        }
+        if(isset($request['is_suggest'])){
+            $where[] = ['is_suggest', $request['is_suggest']];
+        }
+        if(isset($request['type'])){
+            $where[] = ['type', $request['type']];
+        }
+
+        $sort = 'post.id';
+        if(isset($request['sort']) && in_array($request['sort'], ['praise_count', 'share_count', 'pv', 'comment_count', 'create_bean'])){
+            $sort = $request['sort'];
+        }
+
+        return $this->post
+            ->join('post_data', 'post_data.post_id', '=', 'post.id')
+            ->select('post.*')
+            ->where($where)
+            ->where(function($query) use ($request){
+                if(isset($request['keyword'])){
+                    $query->where('uid', '=', $request['keyword'])
+                        ->orWhere('username', 'like', "%{$request['keyword']}%")
+                        ->orWhere('mobile', 'like', "%{$request['keyword']}%");
+                }
+            })
+            ->where(function($query) use ($request){
+                if(isset($request['created_at'])){
+                    $time = explode('_', $request['created_at']);
+                    $query->whereBetween('post.created_at', $time);
+                }
+            })
+            ->where(function ($query) use ($request){
+                if(isset($request['category_ids']) || isset($request['topic_ids'])){
+                    $ids = [];
+                    if (isset($request['category_ids'])) {
+                        $categoryIds = explode('_', $request['category_ids']);
+                        $ids = $this->categoryTopic->whereIn('category_id', $categoryIds)->pluck('topic_id')->toArray();
+                    }
+                    if (isset($request['topic_ids'])) {
+                        $ids = array_merge($ids, explode('_', $request['topic_ids']));
+                    }
+                    foreach ($ids as $key=>$id) {
+                        if ($key==0) {
+                            $query = $query->whereRaw('FIND_IN_SET('.$id.',topic_ids)');
+                        } else {
+                            $query = $query->orWhereRaw('FIND_IN_SET('.$id.',topic_ids)');
+                        }
+                    }
+                }
+            })
+            ->orderBy($sort,'desc')
+            ->paginate($perPage);
+    }
+
+    /**
+     * 内容详情
+     */
+    public function detail($request)
+    {
+        return $this->post->withTrashed()->find($request['id']);
+    }
+
+    /**
+     * 评论列表
+     */
+    public function commentList($request)
+    {
+        $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
+
+        return $this->postComment
+            ->where('post_id', $request['id'])
+            ->orderBy('id','desc')
+            ->paginate($perPage);
+    }
+
+    /**
+     * 推荐内容
+     */
+    public function suggest($request)
+    {
+        $post = $this->post->where('id', $request['id'])->first();
+        if(!$post){
+            return Response::create([
+                'message'  => '获取内容信息失败',
+                'status_code'   => 500
+            ]);
+        }
+
+        if($post->is_suggest == 1){
+            $post->is_suggest = 0;
+        }else{
+            $post->is_suggest = 1;
+        }
+
+        DB::beginTransaction();
+        try{
+            $post->save();
+
+            DB::commit();
+            return Response::create();
+
+        }catch (QueryException $exception){
+            DB::rollBack();
+            Log::debug('推荐内容:'.$request['id'].$exception->getMessage());
+            return Response::create([
+                'message'  => '操作失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code'   => 500
+            ]);
+        }
+    }
+
+    /**
+     * 删除内容
+     */
+    public function delete($request)
+    {
+        $post = $this->post->where('id', $request['id'])->first();
+        if(!$post){
+            return Response::create([
+                'message'  => '获取内容信息失败',
+                'status_code'   => 500
+            ]);
+        }
+
+        DB::beginTransaction();
+        try{
+            $post->delete();
+
+            DB::commit();
+            return Response::create();
+
+        }catch (QueryException $exception){
+            DB::rollBack();
+            Log::debug('删除内容:'.$request['id'].$exception->getMessage());
+            return Response::create([
+                'message'  => '操作失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code'   => 500
+            ]);
+        }
+    }
+
+    /**
+     * 隐藏内容
+     */
+    public function hide($request)
+    {
+        $post = $this->post->where('id', $request['id'])->first();
+        if(!$post){
+            return Response::create([
+                'message'  => '获取内容信息失败',
+                'status_code'   => 500
+            ]);
+        }
+
+        if($post->is_hide == 1){
+            $post->is_hide = 0;
+        }else{
+            $post->is_hide = 1;
+        }
+
+        DB::beginTransaction();
+        try{
+            $post->save();
+
+            DB::commit();
+            return Response::create();
+
+        }catch (QueryException $exception){
+            DB::rollBack();
+            Log::debug('隐藏内容:'.$request['id'].$exception->getMessage());
+            return Response::create([
+                'message'  => '操作失败,请重试',
+                'error' => $exception->getMessage(),
+                'status_code'   => 500
+            ]);
+        }
+    }
+
+}

+ 34 - 0
app/Traits/PostTrait.php

@@ -0,0 +1,34 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/6
+ * Time: 18:05
+ */
+namespace App\Traits;
+
+use Illuminate\Support\Facades\Redis;
+
+trait PostTrait
+{
+    //预计可获得彩虹豆数
+    public function availableBean()
+    {
+        $bean = Redis::get('yesterday_post_create_bean');
+        $count = Redis::get('yesterday_post_count');
+        $num = 1000;
+        if($bean && $count){
+            $num = $bean / $count;
+        }
+        $h = date('h');
+        $H = date('H');
+        $t = $h * 60 / 720 + 2;
+
+
+        if(in_array(intval($H), [9,10,11,12,17.18,19,20,21])){
+            $t += 0.5;
+        }
+        return intval($num * $t);
+    }
+}

+ 29 - 0
app/Transformers/Post/CommentTransformer.php

@@ -0,0 +1,29 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/10
+ * Time: 10:56
+ */
+
+namespace App\Transformers\Post;
+use App\Models\PostComment;
+use Illuminate\Support\Carbon;
+use League\Fractal\TransformerAbstract;
+
+class CommentTransformer extends TransformerAbstract
+{
+    public function transform(PostComment $postComment)
+    {
+        return [
+            'id' => $postComment['id'],
+            'parent_id' => $postComment['parent_id'],
+            'uid' => $postComment['uid'],
+            'username' => $postComment['username'],
+            'avatar' => $postComment['avatar'],
+            'content' => $postComment['is_delete'] == 1 ? '该评论已被删除' : $postComment['content'],
+            'created_at' => Carbon::parse($postComment['created_at'])->toDateTimeString(),
+            'is_delete' => $postComment['is_delete'],
+        ];
+    }
+}

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

@@ -0,0 +1,44 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/10
+ * Time: 9:17
+ */
+
+namespace App\Transformers\Post;
+use App\Models\Post;
+use Illuminate\Support\Carbon;
+use League\Fractal\TransformerAbstract;
+
+class DetailTransformer extends  TransformerAbstract
+{
+    public function transform(Post $post)
+    {
+        $imgs = [];
+        foreach($post->imgs as $img){
+            $imgs[] = $img->img;
+        }
+        return [
+            'id' => $post['id'],
+            'created_at' => Carbon::parse($post['created_at'])->toDateTimeString(),
+            'uid' => $post['uid'],
+            'username' => $post['username'],
+            'avatar' => $post['avatar'],
+            'topic' => $post->topic(),
+            'title' => $post['title'],
+            'content' => $post['content'],
+            'img' => $post['img'],
+            'video' => $post['video'],
+            'imgs' => $imgs,
+            'location' => $post['location'],
+            'pv' => $post->data->pv_real.'/'.$post->data->pv,
+            'praise_count' => $post->data->praise_real_count.'/'.$post->data->praise_count,
+            'share_count' => $post->data->share_real_count.'/'.$post->data->share_count,
+            'comment_count' => $post->data->comment_count,
+            'collect_count' => $post->data->collect_real_count.'/'.$post->data->collect_count,
+            'create_bean' => $post->data->create_bean,
+            'is_suggest' => $post['is_suggest'],
+        ];
+    }
+}

+ 37 - 0
app/Transformers/Post/PostTransformer.php

@@ -0,0 +1,37 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/6
+ * Time: 14:08
+ */
+namespace App\Transformers\Post;
+
+use App\Models\Post;
+use Illuminate\Support\Carbon;
+use League\Fractal\TransformerAbstract;
+
+class PostTransformer extends TransformerAbstract
+{
+    public function transform(Post $post)
+    {
+        return [
+            'id' => $post['id'],
+            'created_at' => Carbon::parse($post['created_at'])->toDateTimeString(),
+            'uid' => $post['uid'],
+            'username' => $post['username'],
+            'avatar' => $post['avatar'],
+            'topic' => $post->topic(),
+            'content' => subtext($post['content'], 20),
+            'location' => $post['location'],
+            'pv' => $post->data->pv_real.'/'.$post->data->pv,
+            'praise_count' => $post->data->praise_real_count.'/'.$post->data->praise_count,
+            'share_count' => $post->data->share_real_count.'/'.$post->data->share_count,
+            'comment_count' => $post->data->comment_count,
+            'collect_count' => $post->data->collect_real_count.'/'.$post->data->collect_count,
+            'create_bean' => $post->data->create_bean,
+            'is_suggest' => $post['is_suggest'],
+        ];
+    }
+}

+ 1 - 0
bootstrap/app.php

@@ -88,6 +88,7 @@ $app->register(App\Providers\AuthServiceProvider::class);
 
 $app->register(Dingo\Api\Provider\LumenServiceProvider::class);
 $app->register(Tymon\JWTAuth\Providers\LumenServiceProvider::class);
+$app->register(\Illuminate\Redis\RedisServiceProvider::class);
 /*
 |--------------------------------------------------------------------------
 | Load The Application Routes

+ 3 - 7
composer.json

@@ -14,6 +14,8 @@
         "laravel/lumen-framework": "5.8.*",
         "vlucas/phpdotenv": "^3.3",
         "multilinguals/apollo-client": "^0.1.2",
+        "illuminate/redis": "^5.8",
+        "predis/predis": "^1.1",
         "tymon/jwt-auth": "1.0.0-rc.4.1"
     },
     "require-dev": {
@@ -49,11 +51,5 @@
         "optimize-autoloader": true
     },
     "minimum-stability": "dev",
-    "prefer-stable": true,
-    "repositories": {
-        "packagist": {
-            "type": "composer",
-            "url": "https://packagist.laravel-china.org"
-        }
-    }
+    "prefer-stable": true
 }

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

@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateCategoryTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('category', function (Blueprint $table) {
+            $table->bigIncrements('id')->comment('表ID');
+            $table->string('name')->nullable()->comment('分类名称');
+            $table->string('img')->nullable()->comment('分类图片');
+            $table->tinyInteger('is_suggest')->default(0)->comment('是否推荐');
+            $table->text('desc')->comment('描述');
+            $table->softDeletes();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('category');
+    }
+}

+ 34 - 0
database/migrations/2019_06_03_094426_create_category_topic_table.php

@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateCategoryTopicTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('category_topic', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->integer('category_id')->nullable()->comment('分类ID');
+            $table->integer('topic_id')->nullable()->comment('话题ID');
+            $table->softDeletes();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('category_topic');
+    }
+}

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

@@ -0,0 +1,42 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateTopicTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('topic', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->string('name')->nullable()->comment('话题名称');
+            $table->string('img')->nullable()->comment('话题图片');
+            //$table->integer('post_num')->default(0)->comment('内容数');
+            //$table->integer('follow_num')->default(0)->comment('关注数');
+           // $table->integer('praise_num')->default(0)->comment('点赞数');
+           // $table->integer('pv_num')->default(0)->comment('浏览数');
+            $table->tinyInteger('is_suggest')->default(0)->comment('是否推荐');
+            $table->tinyInteger('is_hot')->default(0)->comment('是否热门');
+            $table->tinyInteger('is_open')->default(0)->comment('是否开启');
+            $table->string('desc')->comment('描述');
+            $table->softDeletes();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('topic');
+    }
+}

+ 86 - 0
database/migrations/2019_06_03_162324_create_table_post.php

@@ -0,0 +1,86 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateTablePost extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('post', function (Blueprint $table) {
+            $table->bigIncrements('id');
+
+            $table->integer('uid')
+                ->index('uid')
+                ->unsigned()
+                ->comment('uid');
+
+            $table->string('username', 32)
+                ->default('')
+                ->comment('昵称');
+
+            $table->string('mobile', 16)
+                ->default('')
+                ->comment('电话');
+
+            $table->string('avatar', 255)
+                ->default('')
+                ->comment('头像');
+
+            $table->string('type', 16)
+                ->default('image')
+                ->comment('类型:image图文,video视频,html富文本');
+
+            $table->string('img', 255)
+                ->comment('主图');
+
+            $table->string('video', 255)
+                ->default('')
+                ->comment('视频');
+
+            $table->string('topic_ids', 64)
+                ->default('')
+                ->comment('话题ids');
+
+            $table->string('title', 64)
+                ->default('')
+                ->comment('标题');
+
+            $table->text('content')
+                ->nullable()
+                ->comment('内容');
+
+            $table->string('location', 32)
+                ->default('')
+                ->comment('定位');
+
+            $table->tinyInteger('is_suggest')
+                ->default(0)
+                ->comment('是否推荐:0否,1是');
+
+            $table->tinyInteger('is_hide')
+                ->default(0)
+                ->comment('是否隐藏:0否,1是');
+            
+            $table->softDeletes();
+
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('post');
+    }
+}

+ 96 - 0
database/migrations/2019_06_03_162403_create_table_post_data.php

@@ -0,0 +1,96 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateTablePostData extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('post_data', function (Blueprint $table) {
+            $table->bigIncrements('id');
+
+            $table->integer('post_id')
+                ->index('post_id')
+                ->comment('帖子id');
+
+            $table->integer('pv')
+                ->default(0)
+                ->comment('pv');
+
+            $table->integer('pv_real')
+                ->default(0)
+                ->comment('实际pv');
+
+            $table->integer('dislike_count')
+                ->default(0)
+                ->comment('不喜欢数');
+
+            $table->integer('praise_count')
+                ->default(0)
+                ->comment('点赞数');
+
+            $table->integer('praise_real_count')
+                ->default(0)
+                ->comment('实际点赞数');
+
+            $table->integer('share_count')
+                ->default(0)
+                ->comment('分享数');
+
+            $table->integer('share_real_count')
+                ->default(0)
+                ->comment('实际分享数');
+
+            $table->integer('comment_count')
+                ->default(0)
+                ->comment('评论数');
+
+            $table->integer('comment_real_count')
+                ->default(0)
+                ->comment('实际评论数');
+
+            $table->integer('collect_count')
+                ->default(0)
+                ->comment('收藏数');
+
+            $table->integer('collect_real_count')
+                ->default(0)
+                ->comment('实际收藏数');
+
+            $table->integer('available_bean')
+                ->default(0)
+                ->comment('预计可获得彩虹豆数');
+
+            $table->integer('will_collect_bean')
+                ->default(0)
+                ->comment('待收获彩虹豆数');
+
+            $table->integer('collect_bean')
+                ->default(0)
+                ->comment('领取彩虹豆');
+
+            $table->decimal('weight', 8, 2)
+                ->default(0)
+                ->comment('权重');
+
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('post_data');
+    }
+}

+ 61 - 0
database/migrations/2019_06_03_162449_create_table_post_comment.php

@@ -0,0 +1,61 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateTablePostComment extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('post_comment', function (Blueprint $table) {
+            $table->bigIncrements('id');
+
+            $table->integer('post_id')
+                ->index('post_id')
+                ->comment('帖子id');
+
+            $table->integer('parent_id')
+                ->default(0)
+                ->comment('评论id');
+
+            $table->integer('uid')
+                ->index('uid')
+                ->unsigned()
+                ->comment('uid');
+
+            $table->string('username', 32)
+                ->default('')
+                ->comment('昵称');
+
+            $table->string('avatar', 255)
+                ->default('')
+                ->comment('头像');
+
+            $table->string('content', 200)
+                ->default('')
+                ->comment('评论内容');
+            
+            $table->tinyInteger('is_delete')
+                ->default(0)
+                ->comment('是否删除:0否,1是');
+            
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('post_comment');
+    }
+}

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

@@ -0,0 +1,42 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CrateTablePostImgs extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('post_imgs', function (Blueprint $table) {
+            $table->bigIncrements('id');
+
+            $table->integer('post_id')
+                ->index('post_id')
+                ->comment('内容id');
+
+            $table->string('img', 255)
+                ->default('')
+                ->comment('图片');
+
+            $table->softDeletes();
+            
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('post_imgs');
+    }
+}

+ 54 - 0
database/migrations/2019_06_03_162603_crate_table_post_log.php

@@ -0,0 +1,54 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CrateTablePostLog extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('post_log', function (Blueprint $table) {
+            $table->bigIncrements('id');
+
+            $table->integer('uid')
+                ->index('uid')
+                ->unsigned()
+                ->comment('uid');
+
+            $table->integer('post_id')
+                ->index('post_id')
+                ->comment('内容id');
+
+            $table->string('username', 32)
+                ->default('')
+                ->comment('操作人');
+
+            $table->string('log_type', 32)
+                ->default('add_data')
+                ->comment('类型:add_data增加数据');
+            
+            $table->string('content', 500)
+                ->default('')
+                ->comment('内容');
+
+
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('post_log');
+    }
+}

+ 35 - 0
database/migrations/2019_06_06_161402_add_create_bean_to_table_post_data.php

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

+ 1 - 1
deploy/nginx/conf.d/app.beta.conf

@@ -7,7 +7,7 @@ server {
     location ~ \.php$ {
         try_files $uri =404;
         fastcgi_split_path_info ^(.+\.php)(/.+)$;
-        fastcgi_pass app_order_manage_beta:9000;
+        fastcgi_pass app_community_manage_beta:9000;
         fastcgi_index index.php;
         include fastcgi_params;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

+ 1 - 1
deploy/nginx/conf.d/app.dev.conf

@@ -7,7 +7,7 @@ server {
     location ~ \.php$ {
         try_files $uri =404;
         fastcgi_split_path_info ^(.+\.php)(/.+)$;
-        fastcgi_pass app_order_manage_dev:9000;
+        fastcgi_pass app_community_manage_dev:9000;
         fastcgi_index index.php;
         include fastcgi_params;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

+ 5 - 5
docker-compose-beta.yml

@@ -1,24 +1,24 @@
 version: '3'
 
 services:
-  app_order_manage_beta:
+  app_community_manage_dev:
     image: harbor.caihongxingqiu.com:9401/library/php:latest
     tty: true
     working_dir: /var/www
     volumes:
       - ./:/var/www
       - ./deploy/php/local.ini:/usr/local/etc/php/conf.d/local.ini
-      - /data/wwwroot/beta/order-manage:/data/wwwroot/beta/order-manage
+      - /data/wwwroot/beta/community-manage:/data/wwwroot/beta/community-manage
     networks:
       - chxq
 
-  server_order_manage_beta:
+  server_community_manage_beta:
     image: harbor.caihongxingqiu.com:9401/library/nginx:latest
     tty: true
     depends_on:
-      - app_order_manage_beta
+      - app_community_manage_dev
     ports:
-      - "28214:80"
+      - "28218:80"
     volumes:
       - ./:/var/www
       - ./deploy/nginx/conf.d/app.beta.conf:/etc/nginx/conf.d/app.beta.conf

+ 4 - 4
docker-compose-dev.yml

@@ -1,7 +1,7 @@
 version: '3'
 
 services:
-  app_order_manage_dev:
+  app_community_manage_dev:
     image: harbor.caihongxingqiu.com:9401/library/php:latest
     tty: true
     working_dir: /var/www
@@ -11,13 +11,13 @@ services:
     networks:
       - chxq
 
-  server_order_manage_dev:
+  server_community_manage_dev:
     image: harbor.caihongxingqiu.com:9401/library/nginx:latest
     tty: true
     depends_on:
-      - app_order_manage_dev
+      - app_community_manage_dev
     ports:
-      - "18214:80"
+      - "18218:80"
     volumes:
       - ./:/var/www
       - ./deploy/nginx/conf.d/app.dev.conf:/etc/nginx/conf.d/app.dev.conf

+ 11 - 1
resources/lang/zh-CN/validation.php

@@ -100,7 +100,17 @@ return [
     */
 
     'attributes' => [
-        'id' => 'id',
+        'uid' => '用户uid',
+        'type' => '类型',
+        'is_suggest' => '是否推荐',
+        'img' => '图片',
+        'video' => '视频',
+        'topic_ids' => '话题id',
+        'title' => '标题',
+        'content' => '内容',
+        'location' => '位置',
+        'imgs' => '图组',
+        'imgs.*' => '图集',
     ],
 
 ];

+ 16 - 17
routes/api.php

@@ -14,27 +14,26 @@
 $api = app('Dingo\Api\Routing\Router');
 
 $api->version('v1', [
-    'namespace' => 'App\Http\Controllers\V1',
+    'namespace' => 'App\Http\Controllers',
 ], function ($api) {
-    //登录
+    $api->group(['namespace' => 'Post'], function ($api) {
+        //发布内容
+        $api->post('post', 'PostController@create');
+        //内容列表
+        $api->get('post', 'PostController@index');
+        //内容详情
+        $api->get('post/detail', 'PostController@detail');
+        //推荐内容
+        $api->put('post/suggest', 'PostController@suggest');
+        //删除内容
+        $api->delete('post/delete', 'PostController@delete');
+        //隐藏内容
+        $api->put('post/hide', 'PostController@hide');
 
-    $api->post('login', 'AuthController@authenticate');
-
-
-
-    $api->group(['middleware' => 'auth:api'], function ($api) {
-        //注册
-        $api->post('reg', 'AuthController@register');
-        //登出
-        $api->post('logout', 'AuthController@logout');
-        //刷新身份令牌
-        $api->post('refresh', 'AuthController@refresh');
     });
 
-    //测试
-    $api->get('test', 'TestController@index');
-
     $api->group(['middleware' => 'jwt.chxq_auth'], function ($api) {
-
+        //配置
+        $api->get('config', 'ConfigController@index');
     });
 });