thinkphpの製品詳細

class spec extends Model 
{ 
    public function specValue(){ 
     return $this->hasMany(specValue::class,'spec_id','id'); 
    } 
}
class type extends Model 
{ 
    public function attr() 
    { 
        return $this->hasMany(Attribute::class,'type_id','id'); 
    }

}

/**

* 製品の詳細を取得する

* @param $id

* @return 配列

* @throws 例外

*/

パブリック静的関数 getInfo($id){

# 製品基本情報

$goodsInfo = \app\common\model\Goods::with(['category','brand','images','type'])->field('id,goods_name,goods_price,goods_logo,brand_id,cate_id, type_id')->find($id)->toArray();

# type_id はわかっています

$typeInfo = \app\common\model\Type::with(['spec','spec.specValue','attr'])->hidden(['create_time','delete_time','update_time'])- >find($goodsInfo['type_id'])->toArray();

$goodsInfo['type_info'] = $typeInfo;

$goodsInfo を返します。

}

おすすめ

転載: blog.csdn.net/QiZong__BK/article/details/123170060