thinkphp product details

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');
    }

}

/**

* Get product details

* @param $id

* @return array

* @throws Exception

*/

public static function getInfo($id){

# Basic product information

$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 is known

$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;

return $goodsInfo;

}

Guess you like

Origin blog.csdn.net/QiZong__BK/article/details/123170060