| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- declare(strict_types=1);
- namespace SixDec\Message\Entity;
- use think\Model;
- /**
- * 消息模板实体类
- */
- class MessageTemplateEntity extends Model
- {
- // 设置表名
- protected $name = 'message_templates';
-
- // 设置字段信息
- protected $schema = [
- 'id' => 'int',
- 'code' => 'string',
- 'name' => 'string',
- 'title' => 'string',
- 'content' => 'string',
- 'type' => 'int',
- 'status' => 'int',
- 'create_time' => 'int',
- 'update_time' => 'int',
- ];
-
- // 自动时间戳
- protected $autoWriteTimestamp = true;
-
- /**
- * 获取模板类型文本
- */
- public function getTypeTextAttr()
- {
- $types = [
- 1 => '系统通知',
- 2 => '活动通知',
- 3 => '订单通知',
- 4 => '物流通知',
- 5 => '私信',
- 6 => '其他',
- ];
-
- return $types[$this->type] ?? '未知类型';
- }
-
- /**
- * 获取状态文本
- */
- public function getStatusTextAttr()
- {
- $statuses = [
- 0 => '禁用',
- 1 => '启用',
- ];
-
- return $statuses[$this->status] ?? '未知状态';
- }
-
- /**
- * 解析模板内容
- *
- * @param array $data 替换数据
- * @return array 解析后的标题和内容
- */
- public function parse(array $data)
- {
- $title = $this->title;
- $content = $this->content;
-
- // 替换变量
- foreach ($data as $key => $value) {
- $title = str_replace('{' . $key . '}', $value, $title);
- $content = str_replace('{' . $key . '}', $value, $content);
- }
-
- return [
- 'title' => $title,
- 'content' => $content,
- ];
- }
- }
|