1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace app\common\model;
- use think\Model;
- class WwhCultureCard extends Model
- {
- // 表名
- protected $name = 'wwh_culture_card';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
-
- // 追加属性
- protected $append = [
- 'card_type_text',
- 'list_type_text',
- 'status_text',
- 'lang_text'
- ];
-
- protected static function init()
- {
- self::afterInsert(function ($row) {
- $pk = $row->getPk();
- $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
- });
- }
-
- public function getCardTypeList()
- {
- return ['normal' => __('图片在上'), 'reverse' => __('内容在上')];
- }
- public function getListTypeList()
- {
- return ['single' => __('单列布局'), 'double' => __('双列布局')];
- }
- public function getStatusList()
- {
- return ['0' => __('禁用'), '1' => __('启用')];
- }
- public function getLangList()
- {
- return ['1' => __('简体中文'), '2' => __('English')];
- }
- public function getCardTypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['card_type']) ? $data['card_type'] : '');
- $list = $this->getCardTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getListTypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['list_type']) ? $data['list_type'] : '');
- $list = $this->getListTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
- $list = $this->getStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getLangTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['lang']) ? $data['lang'] : '');
- $list = $this->getLangList();
- return isset($list[$value]) ? $list[$value] : '';
- }
-
- protected function setContentItemsAttr($value)
- {
- return is_array($value) ? json_encode($value, JSON_UNESCAPED_UNICODE) : $value;
- }
- protected function getContentItemsAttr($value)
- {
- return $value ? json_decode($value, true) : [];
- }
- }
|