Material.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\admin\model\xmwechat\offiaccount;
  3. use think\Model;
  4. /**
  5. * Material
  6. */
  7. class Material extends Model
  8. {
  9. // 表名
  10. protected $name = 'wechat_offiaccount_material';
  11. // 自动写入时间戳字段
  12. protected $autoWriteTimestamp = true;
  13. protected $append = [
  14. 'url',
  15. 'title',
  16. 'image',
  17. ];
  18. public function getContentAttr($value, $row): string
  19. {
  20. if ($row['type'] == 'text'){
  21. return !$value ? '' : htmlspecialchars_decode($value);
  22. }elseif ($row['type'] == 'link'){
  23. $data = json_decode($row['content'],true);
  24. return $data['content'];
  25. }else{
  26. return '';
  27. }
  28. }
  29. public function getTitleAttr($value, $row): string
  30. {
  31. if ($row['type'] == 'link'){
  32. $data = json_decode($row['content'],true);
  33. return $data['title'];
  34. }else{
  35. return '';
  36. }
  37. }
  38. public function getImageAttr($value, $row): string
  39. {
  40. if ($row['type'] == 'link'){
  41. $data = json_decode($row['content'],true);
  42. return $data['image'];
  43. }else{
  44. return '';
  45. }
  46. }
  47. public function getUrlAttr($value, $row): string
  48. {
  49. if ($row['type'] == 'link'){
  50. $data = json_decode($row['content'],true);
  51. return $data['url'];
  52. }else{
  53. return '';
  54. }
  55. }
  56. }