Product.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Product extends Model
  5. {
  6. // 表名
  7. protected $table = 'product';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'is_show_text',
  17. 'is_recommend_text',
  18. 'jxtype_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 getIsShowList()
  28. {
  29. return ['1' => __('Is_show 1'), '0' => __('Is_show 0')];
  30. }
  31. public function getIsRecommendList()
  32. {
  33. return ['1' => __('Is_recommend 1'), '0' => __('Is_recommend 0')];
  34. }
  35. public function getJxtypeList()
  36. {
  37. return ['0' => __('Jxtype 0'), '1' => __('Jxtype 1')];
  38. }
  39. public function getIsShowTextAttr($value, $data)
  40. {
  41. $value = $value ? $value : (isset($data['is_show']) ? $data['is_show'] : '');
  42. $list = $this->getIsShowList();
  43. return isset($list[$value]) ? $list[$value] : '';
  44. }
  45. public function getIsRecommendTextAttr($value, $data)
  46. {
  47. $value = $value ? $value : (isset($data['is_recommend']) ? $data['is_recommend'] : '');
  48. $list = $this->getIsRecommendList();
  49. return isset($list[$value]) ? $list[$value] : '';
  50. }
  51. public function getJxtypeTextAttr($value, $data)
  52. {
  53. $value = $value ? $value : (isset($data['jxtype']) ? $data['jxtype'] : '');
  54. $list = $this->getJxtypeList();
  55. return isset($list[$value]) ? $list[$value] : '';
  56. }
  57. public function procate()
  58. {
  59. return $this->belongsTo('Procate', 'procate_id', 'id', [], 'LEFT')->setEagerlyType(0);
  60. }
  61. public function protag()
  62. {
  63. return $this->belongsTo('Protag', 'protag_id', 'id', [], 'LEFT')->setEagerlyType(0);
  64. }
  65. public function productxieyi()
  66. {
  67. return $this->belongsTo('Productxieyi', 'xieyi_id', 'id', [], 'LEFT')->setEagerlyType(0);
  68. }
  69. }