GoodsModel.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Models;
  12. /**
  13. * 商品管理-模型
  14. * @author laravel开发员
  15. * @since 2020/11/11
  16. * @package App\Models
  17. */
  18. class GoodsModel extends BaseModel
  19. {
  20. // 设置数据表
  21. protected $table = 'goods';
  22. protected $appends = ['type_name'];
  23. // 封面图
  24. public function getThumbAttribute($value)
  25. {
  26. $thumb = $value ? get_image_url($value) : get_image_url('/images/goods/goods.jpeg');
  27. return $thumb;
  28. }
  29. public function setThumbAttribute($value)
  30. {
  31. return $value ? get_image_path($value) : '';
  32. }
  33. /**
  34. * 图册
  35. * @param $value
  36. * @return array|string
  37. */
  38. public function getAlbumsAttribute($value)
  39. {
  40. $value = $value? get_images_preview($value,'url',2) : [];
  41. return $value;
  42. }
  43. public function getTypeNameAttribute()
  44. {
  45. $types = [0=>'未选',1=>'自营品专区',2=>'延时专区',3=>'深度体验',4=>'男神玩具',5=>'女神玩具',6=>'私密养护',7=>'情趣服饰(香水)',8=>'SM房趣(套装)',9=>'体感娃娃',10=>'周边产品'];
  46. return isset($types[$this->type]) ? $types[$this->type] : '';
  47. }
  48. public function getInfo($id)
  49. {
  50. $info = parent::getInfo($id); // TODO: Change the autogenerated stub
  51. return $info;
  52. }
  53. /**
  54. * 关联商品分类
  55. */
  56. public function category()
  57. {
  58. return $this->hasOne(GoodsCategoryModel::class, 'id', 'category_id')
  59. ->select(['id', 'name', 'icon', 'status']);
  60. }
  61. /**
  62. * SKU
  63. */
  64. public function sku()
  65. {
  66. return $this->hasOne(GoodsSkuModel::class, 'id', 'sku_id')
  67. ->where(['mark' => 1]);
  68. }
  69. /**
  70. * 关联商品规格(多规格)
  71. */
  72. public function skus()
  73. {
  74. return $this->hasMany(GoodsSkuModel::class, 'goods_id', 'id')
  75. ->where(['mark' => 1, 'status' => 1])
  76. ->orderBy('sort', 'desc');
  77. }
  78. }