Template.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace app\admin\model\sms;
  3. use think\Model;
  4. /**
  5. * Template
  6. * @controllerUrl 'smsTemplate'
  7. */
  8. class Template extends Model
  9. {
  10. // 表名
  11. protected $name = 'sms_template';
  12. // 自动写入时间戳字段
  13. protected $autoWriteTimestamp = 'int';
  14. protected $createTime = 'createtime';
  15. protected $updateTime = 'updatetime';
  16. protected $append = [
  17. 'variable_text',
  18. ];
  19. public function setVariablesAttr($value, $row)
  20. {
  21. if ($value && is_array($value)) {
  22. return implode(',', $value);
  23. }
  24. return $value ? $value : '';
  25. }
  26. public function getVariablesAttr($value, $row)
  27. {
  28. if ($value == '') {
  29. return [];
  30. }
  31. if (!is_array($value)) {
  32. return explode(',', $value);
  33. }
  34. return $value;
  35. }
  36. public function getVariableTextAttr($value, $row): array
  37. {
  38. if (!$row['variables']) {
  39. return [];
  40. }
  41. return Variable::whereIn('id', $row['variables'])->column('title');
  42. }
  43. }