1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace app\common\model;
- use think\Model;
- use traits\model\SoftDelete;
- class Article extends Model{
- use SoftDelete;
- public function getTypeIdAttr($value,$data){
- return $data['type_3'] == 0?($data['type_2'] == 0?$data['type_1']:$data['type_2']):$data['type_3'];
- }
- public function getTypeCnameAttr($value,$data){
- $cname = '';
- if ($this['type1']) {
- $cname .= $this['type1']['cname'];
- if ($this['type2']) {
- $cname .= '->'.$this['type2']['cname'];
- if ($this['type3']) {
- $cname .= '->'.$this['type3']['cname'];
- }
- }
- }
- return $cname;
- }
- public function type1(){
- return $this->belongsTo('app\common\model\article\Type','type_1');
- }
- public function type2(){
- return $this->belongsTo('app\common\model\article\Type','type_2');
- }
- public function type3(){
- return $this->belongsTo('app\common\model\article\Type','type_3');
- }
- public function getStateTextAttr($value,$data){
- $state = $data['state'];
- $text = ['0'=>'草稿','1'=>'发布'];
- return $text[$state];
- }
- }
|