12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace app\admin\model;
- use think\Model;
- use think\Db;
- class Jishuguifan extends Model
- {
-
-
- // 表名
- protected $table = 'jishuguifan';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'integer';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'ismenu_text'
- ];
-
- protected static function init()
- {
- //设置顶级tid
- self::afterInsert(function ($row){
- $tid = Db::name('jishuguifan')->where('id',$row['pid'])->value('tid');
- Db::name('jishuguifan')->where('id',$row['id'])->update(['tid'=>$tid]);
- });
- self::beforeUpdate(function ($row) {
- $tid = Db::name('jishuguifan')->where('id',$row['pid'])->value('tid');
- Db::name('jishuguifan')->where('id',$row['id'])->update(['tid'=>$tid]);
- });
- }
-
- public function getIsmenuList()
- {
- return ['1' => __('Ismenu 1'), '0' => __('Ismenu 0')];
- }
- public function getIsmenuTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['ismenu']) ? $data['ismenu'] : '');
- $list = $this->getIsmenuList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function company()
- {
- return $this->belongsTo('Company', 'company_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- }
|