<?php namespace app\admin\model; use think\Model; class Lessonpackage extends Model { // 表名 protected $table = 'lesson_package'; // 自动写入时间戳字段 protected $autoWriteTimestamp = false; // 定义时间戳字段名 protected $createTime = false; protected $updateTime = false; protected $deleteTime = false; // 追加属性 protected $append = [ 'is_show_text', 'buytimes_text', 'newuser_text', 'olduser_text' ]; protected static function init() { self::afterInsert(function ($row) { $pk = $row->getPk(); $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]); }); } public function getIsShowList() { return ['1' => __('Is_show 1'), '0' => __('Is_show 0')]; } public function getBuytimesList() { return ['0' => __('Buytimes 0'), '1' => __('Buytimes 1')]; } public function getNewuserList() { return ['0' => __('Newuser 0'), '1' => __('Newuser 1')]; } public function getOlduserList() { return ['0' => __('Olduser 0'), '1' => __('Olduser 1')]; } public function getTypeList() { return ['1' => __('Type 1'), '2' => __('Type 2')]; } public function getGiftTypeList() { return ['1' => __('Type 1'), '2' => __('Type 2')]; } public function getIsShowTextAttr($value, $data) { $value = $value ? $value : (isset($data['is_show']) ? $data['is_show'] : ''); $list = $this->getIsShowList(); return isset($list[$value]) ? $list[$value] : ''; } public function getBuytimesTextAttr($value, $data) { $value = $value ? $value : (isset($data['buytimes']) ? $data['buytimes'] : ''); $list = $this->getBuytimesList(); return isset($list[$value]) ? $list[$value] : ''; } public function getNewuserTextAttr($value, $data) { $value = $value ? $value : (isset($data['newuser']) ? $data['newuser'] : ''); $list = $this->getNewuserList(); return isset($list[$value]) ? $list[$value] : ''; } public function getOlduserTextAttr($value, $data) { $value = $value ? $value : (isset($data['olduser']) ? $data['olduser'] : ''); $list = $this->getOlduserList(); return isset($list[$value]) ? $list[$value] : ''; } public function getTypeTextAttr($value, $data) { $value = $value ? $value : (isset($data['type']) ? $data['type'] : ''); $list = $this->getTypeList(); return isset($list[$value]) ? $list[$value] : ''; } public function getGiftTypeTextAttr($value, $data) { $value = $value ? $value : (isset($data['gift_type']) ? $data['gift_type'] : ''); $list = $this->getGiftTypeList(); return isset($list[$value]) ? $list[$value] : ''; } /*public function lessona() { return $this->belongsTo('Lesson', 'lesson_ids', 'id', [], 'LEFT')->setEagerlyType(0); }*/ public function lessonb() { return $this->belongsTo('Lesson', 'gift_lesson_id', 'id', [], 'LEFT')->setEagerlyType(0); } }