123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace app\admin\model\gift;
- use think\Model;
- class Gift extends Model
- {
-
-
- // 表名
- protected $name = 'gift';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'is_big_text',
- 'complex_text',
- 'timelimit_text',
- 'is_show_text'
- ];
- protected static function init()
- {
- self::beforeInsert(function ($row) {
- //礼物价值=价格
- $row->value = $row->price;
- });
- self::beforeUpdate(function ($row) {
- //礼物价值=价格
- $row->value = $row->price;
- });
- }
-
- public function getIsBigList()
- {
- return ['0' => __('Is_big 0'), '1' => __('Is_big 1')];
- }
- public function getTypeList()
- {
- return ['0' => __('Type 0'), '1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3'), '4' => __('Type 4')];
- }
-
- public function getComplexList()
- {
- return ['1' => __('Complex 1'), '0' => __('Complex 0')];
- }
- public function getBoxtypeList()
- {
- return ['0' => __('非宝箱礼物'), '1' => __('青铜宝箱'), '2' => __('黄金宝箱'), '3' => __('荣耀黄金宝箱'), '4' => __('荣耀紫金宝箱')];
- }
- public function getTimelimitList()
- {
- return ['1' => __('Timelimit 1'), '0' => __('Timelimit 0')];
- }
- public function getIsShowList()
- {
- return ['1' => __('Is_show 1'), '0' => __('Is_show 0')];
- }
- public function getTypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
- $list = $this->getTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getIsBigTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['is_big']) ? $data['is_big'] : '');
- $list = $this->getIsBigList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getComplexTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['complex']) ? $data['complex'] : '');
- $list = $this->getComplexList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getTimelimitTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['timelimit']) ? $data['timelimit'] : '');
- $list = $this->getTimelimitList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function gifttype()
- {
- return $this->belongsTo('app\admin\model\gift\Type', 'type', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- public function getIsShowTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['is_show']) ? $data['is_show'] : '');
- $list = $this->getIsShowList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- }
|