wesmiler 5 дней назад
Родитель
Сommit
b1f59aca79
2 измененных файлов с 105 добавлено и 0 удалено
  1. 61 0
      app/Models/PostModel.php
  2. 44 0
      app/Models/PostRecordModel.php

+ 61 - 0
app/Models/PostModel.php

@@ -0,0 +1,61 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Models;
+
+/**
+ * 笔记动态-模型
+ * @author laravel开发员
+ * @since 2020/11/11
+ * @package App\Models
+ */
+class PostModel extends BaseModel
+{
+    // 设置数据表
+    protected $table = 'posts';
+
+    protected $appends = ['time_text'];
+
+    public function getTimeTextAttribute()
+    {
+        return $this->create_time? datetime($this->create_time) : '';
+    }
+
+    /**
+     * 发布用户
+     * @return \Illuminate\Database\Eloquent\Relations\HasOne
+     */
+    public function user()
+    {
+        return $this->hasOne(MemberModel::class, 'id', 'user_id')
+            ->select(['id','openid', 'mobile', 'nickname','balance', 'realname', 'status']);
+    }
+
+    /**
+     * 评论记录
+     * @return \Illuminate\Database\Eloquent\Relations\hasMany
+     */
+    public function records()
+    {
+        return $this->hasMany(PostRecordModel::class, 'source_id', 'id')
+            ->where(['type'=>1,'status'=>1,'mark'=>1]);
+    }
+
+    /**
+     * 点赞记录
+     * @return \Illuminate\Database\Eloquent\Relations\hasMany
+     */
+    public function likes()
+    {
+        return $this->hasMany(PostRecordModel::class, 'source_id', 'id')
+            ->where(['type'=>2,'status'=>1,'mark'=>1]);
+    }
+}

+ 44 - 0
app/Models/PostRecordModel.php

@@ -0,0 +1,44 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Models;
+
+/**
+ * 笔记动态/点赞或评论记录-模型
+ * @author laravel开发员
+ * @since 2020/11/11
+ * @package App\Models
+ */
+class PostRecordModel extends BaseModel
+{
+    // 设置数据表
+    protected $table = 'posts_records';
+
+    /**
+     * 发布用户
+     * @return \Illuminate\Database\Eloquent\Relations\HasOne
+     */
+    public function user()
+    {
+        return $this->hasOne(MemberModel::class, 'id', 'user_id')
+            ->select(['id','openid', 'mobile', 'nickname','balance', 'realname', 'status']);
+    }
+
+    /**
+     * 笔记
+     * @return \Illuminate\Database\Eloquent\Relations\HasOne
+     */
+    public function posts()
+    {
+        return $this->hasOne(PostModel::class, 'id', 'source_id')
+            ->select(['id','title', 'thumb', 'type','user_id', 'tags','status']);
+    }
+}