123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- namespace app\admin\model;
- use think\Model;
- use think\Db;
- class AttireBack extends Model
- {
-
-
- // 表名
- protected $name = 'attire_back';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'type_text',
- 'duetime_text',
- 'is_use_text',
- 'is_using_text'
- ];
- protected static function init()
- {
- self::beforeInsert(function ($row) {
- $attireInfo = Db::name('attire')->where('id',$row['attire_id'])->find();
- $row["attire_name"] = $attireInfo["title"];
- $row["price"] = $attireInfo["price"];
- $row["file_image"] = $attireInfo["file_image"];
- $row["android_image"] = $attireInfo["android_image"];
- $row["gif_image"] = $attireInfo["gif_image"];
- $row["limit_day"] = $attireInfo["limit_day"];
- $row["type"] = $attireInfo["type"];
- });
- }
-
- public function getTypeList()
- {
- return ['1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3'), '4' => __('Type 4')];
- }
- public function getIsUseList()
- {
- return ['1' => __('Is_use 1'), '0' => __('Is_use 0')];
- }
- public function getIsUsingList()
- {
- return ['1' => __('Is_using 1'), '0' => __('Is_using 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 getDuetimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['duetime']) ? $data['duetime'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- public function getIsUseTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['is_use']) ? $data['is_use'] : '');
- $list = $this->getIsUseList();
- 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] : '';
- }
- protected function setDuetimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- public function user()
- {
- return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- }
|