php多规格处理

/**
 * 获取门店规格
 * name:caiwh
 */
public function getShopAttr($shop_id, $onsale=1){
    $map = [
        'goods_id'  => $this->id,
        'shop_id'   => $shop_id,
        'store_id'  => $this->store_id,
        //'status'    => 1,
        'is_delete' => 0
    ];
    if($onsale==1){
        $map['status'] =1;
    }
    $data = Inventory::find()
        ->where($map)->asArray()->all();
    $shop_attr = [];
    foreach ($data as $v){
        $attr = json_decode($v['attr'],true);
        $attr['num'] = $v['stock'];
        $attr['price'] = $v['price'];
        $attr['status'] = $v['status'];
        $shop_attr[] = $attr; //看他返回的格式是不是很有想法
    }
    return $shop_attr;
}

 

 

php多规格处理