12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace app\admin\model;
- use think\Model;
- class Banner extends Model
- {
-
-
- // 表名
- protected $name = 'banner';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = false;
- // 定义时间戳字段名
- protected $createTime = false;
- protected $updateTime = false;
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'opentype_text',
- 'place_text',
- 'status_text'
- ];
-
- protected static function init()
- {
- self::afterInsert(function ($row) {
- $pk = $row->getPk();
- $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
- });
- }
-
- public function getOpentypeList()
- {
- return ['1' => __('Opentype 1'), '2' => __('Opentype 2')];
- }
- public function getPlaceList()
- {
- return ['1' => __('Place 1'), '2' => __('Place 2'), '3' => __('Place 3'), '4' => __('Place 4'), '5' => __('Place 5'), '6' => __('Place 6')];
- }
- public function getStatusList()
- {
- return ['1' => __('Status 1'), '0' => __('Status 0')];
- }
- public function getOpentypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['opentype']) ? $data['opentype'] : '');
- $list = $this->getOpentypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getPlaceTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['place']) ? $data['place'] : '');
- $list = $this->getPlaceList();
- 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] : '';
- }
- }
|