朋友圈自动同步
This commit is contained in:
52
Server/application/cunkebao/model/ContentItem.php
Normal file
52
Server/application/cunkebao/model/ContentItem.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace app\cunkebao\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class ContentItem extends Model
|
||||
{
|
||||
protected $pk = 'id';
|
||||
protected $name = 'content_items';
|
||||
|
||||
// 内容类型
|
||||
const TYPE_TEXT = 1; // 文本
|
||||
const TYPE_IMAGE = 2; // 图片
|
||||
const TYPE_VIDEO = 3; // 视频
|
||||
const TYPE_LINK = 4; // 链接
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
|
||||
// 定义关联的内容库
|
||||
public function library()
|
||||
{
|
||||
return $this->belongsTo('ContentLibrary', 'libraryId', 'id');
|
||||
}
|
||||
|
||||
// 内容类型获取器
|
||||
public function getTypeTextAttr($value, $data)
|
||||
{
|
||||
$types = [
|
||||
self::TYPE_TEXT => '文本',
|
||||
self::TYPE_IMAGE => '图片',
|
||||
self::TYPE_VIDEO => '视频',
|
||||
self::TYPE_LINK => '链接'
|
||||
];
|
||||
return isset($types[$data['type']]) ? $types[$data['type']] : '未知';
|
||||
}
|
||||
|
||||
// 内容数据获取器
|
||||
public function getContentDataAttr($value)
|
||||
{
|
||||
return json_decode($value, true);
|
||||
}
|
||||
|
||||
// 内容数据修改器
|
||||
public function setContentDataAttr($value)
|
||||
{
|
||||
return is_array($value) ? json_encode($value) : $value;
|
||||
}
|
||||
}
|
||||
38
Server/application/cunkebao/model/ContentLibrary.php
Normal file
38
Server/application/cunkebao/model/ContentLibrary.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace app\cunkebao\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class ContentLibrary extends Model
|
||||
{
|
||||
protected $pk = 'id';
|
||||
protected $name = 'content_library';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
protected $updateTime = 'updateTime';
|
||||
|
||||
// 定义关联的用户
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('User', 'userId', 'id');
|
||||
}
|
||||
|
||||
// 定义关联的内容项目
|
||||
public function items()
|
||||
{
|
||||
return $this->hasMany('ContentItem', 'libraryId', 'id');
|
||||
}
|
||||
|
||||
// 根据ID数组获取内容库列表
|
||||
public static function getByIds($ids)
|
||||
{
|
||||
if (empty($ids)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return self::where('id', 'in', $ids)->select();
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,12 @@ class WorkbenchMomentsSync extends Model
|
||||
protected $pk = 'id';
|
||||
protected $name = 'workbench_moments_sync';
|
||||
|
||||
// 同步类型
|
||||
const SYNC_TYPE_TEXT = 1; // 文本
|
||||
const SYNC_TYPE_IMAGE = 2; // 图片
|
||||
const SYNC_TYPE_VIDEO = 3; // 视频
|
||||
const SYNC_TYPE_LINK = 4; // 链接
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'createTime';
|
||||
@@ -19,4 +25,34 @@ class WorkbenchMomentsSync extends Model
|
||||
{
|
||||
return $this->belongsTo('Workbench', 'workbenchId', 'id');
|
||||
}
|
||||
|
||||
// 定义关联的内容库
|
||||
public function contentLibraries()
|
||||
{
|
||||
return $this->belongsToMany('ContentLibrary', 'workbench_content_relation', 'contentLibraryId', 'workbenchId');
|
||||
}
|
||||
|
||||
// 开始时间获取器
|
||||
public function getStartTimeAttr($value)
|
||||
{
|
||||
return $value ? date('H:i', strtotime($value)) : '';
|
||||
}
|
||||
|
||||
// 结束时间获取器
|
||||
public function getEndTimeAttr($value)
|
||||
{
|
||||
return $value ? date('H:i', strtotime($value)) : '';
|
||||
}
|
||||
|
||||
// 同步类型获取器
|
||||
public function getSyncTypeTextAttr($value, $data)
|
||||
{
|
||||
$types = [
|
||||
self::SYNC_TYPE_TEXT => '文本',
|
||||
self::SYNC_TYPE_IMAGE => '图片',
|
||||
self::SYNC_TYPE_VIDEO => '视频',
|
||||
self::SYNC_TYPE_LINK => '链接'
|
||||
];
|
||||
return isset($types[$data['syncType']]) ? $types[$data['syncType']] : '未知';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user