Videocate.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Videocate extends Model
  5. {
  6. // 表名
  7. protected $name = 'video_cate';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'status_text',
  17. 'showtype_text',
  18. 'is_zhuanti_text'
  19. ];
  20. protected static function init()
  21. {
  22. self::afterInsert(function ($row) {
  23. $pk = $row->getPk();
  24. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  25. });
  26. }
  27. public function getStatusList()
  28. {
  29. return ['0' => __('Status 0'), '1' => __('Status 1')];
  30. }
  31. public function getShowtypeList()
  32. {
  33. return ['1' => __('Showtype 1'), '2' => __('Showtype 2'), '3' => __('Showtype 3'), '4' => __('Showtype 4'), '5' => __('Showtype 5'), '6' => __('Showtype 6'), '7' => __('Showtype 7'), '8' => __('Showtype 8'), '9' => __('Showtype 9')];
  34. }
  35. public function getIsZhuantiList()
  36. {
  37. return ['1' => __('Is_zhuanti 1'), '0' => __('Is_zhuanti 0')];
  38. }
  39. public function getStatusTextAttr($value, $data)
  40. {
  41. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  42. $list = $this->getStatusList();
  43. return isset($list[$value]) ? $list[$value] : '';
  44. }
  45. public function getShowtypeTextAttr($value, $data)
  46. {
  47. $value = $value ? $value : (isset($data['showtype']) ? $data['showtype'] : '');
  48. $list = $this->getShowtypeList();
  49. return isset($list[$value]) ? $list[$value] : '';
  50. }
  51. public function getIsZhuantiTextAttr($value, $data)
  52. {
  53. $value = $value ? $value : (isset($data['is_zhuanti']) ? $data['is_zhuanti'] : '');
  54. $list = $this->getIsZhuantiList();
  55. return isset($list[$value]) ? $list[$value] : '';
  56. }
  57. }