123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace app\admin\model;
- use think\Model;
- class Userdecorate extends Model
- {
-
-
- // 表名
- protected $name = 'user_decorate';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'decorate_type_text',
- 'is_using_text',
- 'end_time_text'
- ];
-
-
- public function getDecorateTypeList()
- {
- return ['1' => __('Decorate_type 1'), '2' => __('Decorate_type 2'), '3' => __('Decorate_type 3'), '4' => __('Decorate_type 4')];
- }
- public function getIsUsingList()
- {
- return ['1' => __('Is_using 1'), '0' => __('Is_using 0')];
- }
- public function getDecorateTypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['decorate_type']) ? $data['decorate_type'] : '');
- $list = $this->getDecorateTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getIsUsingTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['is_using']) ? $data['is_using'] : '');
- $list = $this->getIsUsingList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getEndTimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['end_time']) ? $data['end_time'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- protected function setEndTimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- public function decorate()
- {
- return $this->belongsTo('Decorate', 'decorate_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- public function user()
- {
- return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- }
|