Article.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. use traits\model\SoftDelete;
  5. class Article extends Model{
  6. use SoftDelete;
  7. public function getTypeIdAttr($value,$data){
  8. return $data['type_3'] == 0?($data['type_2'] == 0?$data['type_1']:$data['type_2']):$data['type_3'];
  9. }
  10. public function getTypeCnameAttr($value,$data){
  11. $cname = '';
  12. if ($this['type1']) {
  13. $cname .= $this['type1']['cname'];
  14. if ($this['type2']) {
  15. $cname .= '->'.$this['type2']['cname'];
  16. if ($this['type3']) {
  17. $cname .= '->'.$this['type3']['cname'];
  18. }
  19. }
  20. }
  21. return $cname;
  22. }
  23. public function type1(){
  24. return $this->belongsTo('app\common\model\article\Type','type_1');
  25. }
  26. public function type2(){
  27. return $this->belongsTo('app\common\model\article\Type','type_2');
  28. }
  29. public function type3(){
  30. return $this->belongsTo('app\common\model\article\Type','type_3');
  31. }
  32. public function getStateTextAttr($value,$data){
  33. $state = $data['state'];
  34. $text = ['0'=>'草稿','1'=>'发布'];
  35. return $text[$state];
  36. }
  37. }