Goods.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\admin\model;
  3. use app\common\model\Category;
  4. use think\Model;
  5. use think\model\relation\HasMany;
  6. class Goods extends \app\common\model\Goods
  7. {
  8. // 追加属性
  9. protected $append = [
  10. 'create_time_text',
  11. 'update_time_text',
  12. ];
  13. public function getCreateTimeTextAttr($value, $data)
  14. {
  15. $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
  16. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  17. }
  18. public function getUpdateTimeTextAttr($value, $data)
  19. {
  20. $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
  21. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  22. }
  23. protected function setCreateTimeAttr($value)
  24. {
  25. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  26. }
  27. protected function setUpdateTimeAttr($value)
  28. {
  29. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  30. }
  31. /**
  32. * @return HasMany|GoodsViewFavCart
  33. */
  34. public function viewFavCart(){
  35. return $this->hasMany(GoodsViewFavCart::class);
  36. }
  37. public function category(){
  38. return $this->belongsTo(Category::class)->setEagerlyType(0);
  39. }
  40. }