WwhCultureCard.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class WwhCultureCard extends Model
  5. {
  6. // 表名
  7. protected $name = 'wwh_culture_card';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. // 追加属性
  14. protected $append = [
  15. 'card_type_text',
  16. 'list_type_text',
  17. 'status_text',
  18. 'lang_text'
  19. ];
  20. protected static function init()
  21. {
  22. self::afterInsert(function ($row) {
  23. $pk = $row->getPk();
  24. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  25. });
  26. }
  27. public function getCardTypeList()
  28. {
  29. return ['normal' => __('图片在上'), 'reverse' => __('内容在上')];
  30. }
  31. public function getListTypeList()
  32. {
  33. return ['single' => __('单列布局'), 'double' => __('双列布局')];
  34. }
  35. public function getStatusList()
  36. {
  37. return ['0' => __('禁用'), '1' => __('启用')];
  38. }
  39. public function getLangList()
  40. {
  41. return ['1' => __('简体中文'), '2' => __('English')];
  42. }
  43. public function getCardTypeTextAttr($value, $data)
  44. {
  45. $value = $value ? $value : (isset($data['card_type']) ? $data['card_type'] : '');
  46. $list = $this->getCardTypeList();
  47. return isset($list[$value]) ? $list[$value] : '';
  48. }
  49. public function getListTypeTextAttr($value, $data)
  50. {
  51. $value = $value ? $value : (isset($data['list_type']) ? $data['list_type'] : '');
  52. $list = $this->getListTypeList();
  53. return isset($list[$value]) ? $list[$value] : '';
  54. }
  55. public function getStatusTextAttr($value, $data)
  56. {
  57. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  58. $list = $this->getStatusList();
  59. return isset($list[$value]) ? $list[$value] : '';
  60. }
  61. public function getLangTextAttr($value, $data)
  62. {
  63. $value = $value ? $value : (isset($data['lang']) ? $data['lang'] : '');
  64. $list = $this->getLangList();
  65. return isset($list[$value]) ? $list[$value] : '';
  66. }
  67. protected function setContentItemsAttr($value)
  68. {
  69. return is_array($value) ? json_encode($value, JSON_UNESCAPED_UNICODE) : $value;
  70. }
  71. protected function getContentItemsAttr($value)
  72. {
  73. return $value ? json_decode($value, true) : [];
  74. }
  75. }