| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Models;
- /**
- * 商品管理-模型
- * @author laravel开发员
- * @since 2020/11/11
- * @package App\Models
- */
- class GoodsModel extends BaseModel
- {
- // 设置数据表
- protected $table = 'goods';
- // 封面图
- public function getThumbAttribute($value)
- {
- $thumb = $value ? get_image_url($value) : get_image_url('/images/goods/goods.jpeg');
- return $thumb;
- }
- public function setThumbAttribute($value)
- {
- return $value ? get_image_path($value) : '';
- }
- /**
- * 图册
- * @param $value
- * @return array|string
- */
- public function getAlbumsAttribute($value)
- {
- $value = $value? get_images_preview($value,'url',2) : [];
- return $value;
- }
- public function getInfo($id)
- {
- $info = parent::getInfo($id); // TODO: Change the autogenerated stub
- return $info;
- }
- /**
- * 商家店铺
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function store()
- {
- return $this->hasOne(StoreModel::class, 'id', 'store_id')
- ->select(['id','nickname','mobile','bonus_rate','status']);
- }
- /**
- * 关联商品分类
- */
- public function category()
- {
- return $this->hasOne(GoodsCategoryModel::class, 'id', 'category_id')
- ->select(['id', 'name', 'icon', 'status']);
- }
- /**
- * SKU
- */
- public function sku()
- {
- return $this->hasOne(GoodsSkuModel::class, 'id', 'sku_id')
- ->where(['mark' => 1]);
- }
- /**
- * 关联商品规格(多规格)
- */
- public function skus()
- {
- return $this->hasMany(GoodsSkuModel::class, 'goods_id', 'id')
- ->where(['mark' => 1, 'status' => 1])
- ->orderBy('sort', 'desc');
- }
- }
|