{
"head": {
"code": 200,
"msg": "ok"
},
"body": [
{
"id": "80761",
"name": "这是一个商品型的测试",
"img_url": "/uploads/zhongshan/2/216593787b72633ab83a44992c511e5a.jpeg",
"specification": "607,608",
"attributes": "87,88",
"unit": "斤",
"label": "0",
"type": "1",
"inventory": "-1",
"category_id": "8689",
"category_name": "",
"c_name": "香锅类"
},
{
"id": "80762",
"name": "这是一个商品型的测试2",
"img_url": "/uploads/zhongshan/2/216593787b72633ab83a44992c511e5a.jpeg",
"specification": "609,610",
"attributes": "89,90",
"unit": "份",
"label": "0",
"type": "2",
"inventory": "-1",
"category_id": "8689",
"category_name": "",
"c_name": "香锅类"
},
{
"id": "80763",
"name": "这是一个商品型的测试2",
"img_url": "/uploads/zhongshan/2/216593787b72633ab83a44992c511e5a.jpeg",
"specification": "611,612",
"attributes": "91,92",
"unit": "份",
"label": "0",
"type": "2",
"inventory": "-1",
"category_id": "8689",
"category_name": "",
"c_name": "香锅类"
},
{
"id": "80764",
"name": "这是一个商品型的测试2",
"img_url": "/uploads/zhongshan/2/216593787b72633ab83a44992c511e5a.jpeg",
"specification": "613,614",
"attributes": "93,94",
"unit": "份",
"label": "0",
"type": "2",
"inventory": "-1",
"category_id": "8690",
"category_name": "",
"c_name": "选材类"
},
{
"id": "80765",
"name": "这是一个商品型的测试2",
"img_url": "/uploads/zhongshan/2/216593787b72633ab83a44992c511e5a.jpeg",
"specification": "615,616",
"attributes": "95,96",
"unit": "份",
"label": "0",
"type": "2",
"inventory": "-1",
"category_id": "8690",
"category_name": "",
"c_name": "选材类"
},
{
"id": "80766",
"name": "这是一个商品型的测试2",
"img_url": "/uploads/zhongshan/2/216593787b72633ab83a44992c511e5a.jpeg",
"specification": "617,618",
"attributes": "97,98",
"unit": "份",
"label": "0",
"type": "2",
"inventory": "-1",
"category_id": "8690",
"category_name": "",
"c_name": "选材类"
}
]
}
最终的样子:
{
"head": {
"code": 403,
"msg": "门店不存在"
},
"body": [
{
"cate_id": "8689",
"cate_name": "香锅类",
"info": [
{
"id": "80761",
"name": "这是一个商品型的测试",
"img_url": "/uploads/zhongshan/2/216593787b72633ab83a44992c511e5a.jpeg",
"specification": "607,608",
"attributes": "87,88",
"unit": "斤",
"label": "0",
"type": "1",
"inventory": "-1",
"category_id": "8689",
"category_name": "",
"c_name": "香锅类"
},
{
"id": "80762",
"name": "这是一个商品型的测试2",
"img_url": "/uploads/zhongshan/2/216593787b72633ab83a44992c511e5a.jpeg",
"specification": "609,610",
"attributes": "89,90",
"unit": "份",
"label": "0",
"type": "2",
"inventory": "-1",
"category_id": "8689",
"category_name": "",
"c_name": "香锅类"
},
{
"id": "80763",
"name": "这是一个商品型的测试2",
"img_url": "/uploads/zhongshan/2/216593787b72633ab83a44992c511e5a.jpeg",
"specification": "611,612",
"attributes": "91,92",
"unit": "份",
"label": "0",
"type": "2",
"inventory": "-1",
"category_id": "8689",
"category_name": "",
"c_name": "香锅类"
}
]
},
{
"cate_id": "8690",
"cate_name": "选材类",
"info": [
{
"id": "80764",
"name": "这是一个商品型的测试2",
"img_url": "/uploads/zhongshan/2/216593787b72633ab83a44992c511e5a.jpeg",
"specification": "613,614",
"attributes": "93,94",
"unit": "份",
"label": "0",
"type": "2",
"inventory": "-1",
"category_id": "8690",
"category_name": "",
"c_name": "选材类"
},
{
"id": "80765",
"name": "这是一个商品型的测试2",
"img_url": "/uploads/zhongshan/2/216593787b72633ab83a44992c511e5a.jpeg",
"specification": "615,616",
"attributes": "95,96",
"unit": "份",
"label": "0",
"type": "2",
"inventory": "-1",
"category_id": "8690",
"category_name": "",
"c_name": "选材类"
},
{
"id": "80766",
"name": "这是一个商品型的测试2",
"img_url": "/uploads/zhongshan/2/216593787b72633ab83a44992c511e5a.jpeg",
"specification": "617,618",
"attributes": "97,98",
"unit": "份",
"label": "0",
"type": "2",
"inventory": "-1",
"category_id": "8690",
"category_name": "",
"c_name": "选材类"
}
]
}
]
}
3 回答
牧羊人nacy
TA贡献1862条经验 获得超7个赞
$old_data = $old['body'];
foreach($old_data as $v){
if (!array_key_exists($v['category_id'],$new)){
$new[$v['category_id']]['cate_id'] = $v['category_id'];
$new[$v['category_id']]['cate_name']= $v['c_name'];
}
$new[$v['category_id']]['boby'][] = $v;
}
小怪兽爱吃肉
TA贡献1852条经验 获得超1个赞
$new_data = []; // 收集分类相同的数据
$cate_goods = []; // 收集分类和商品信息--最终数据
$cate = []; // 拼接分类 将分类单独提出来
if ( $result )
{
foreach ( $result as $key => $value )
{
$value['img_url'] = $this->img_url.$value['img_url'];
$new_data[$value['category_id']][] = $value;
}
// 将分类名称单独提出来
if ( $new_data )
{
foreach ( $new_data as $k => $v )
{
if ( $v )
{
$cate['cate_id'] = $v[0]['category_id'];
$cate['cate_name'] = $v[0]['c_name'];
$cate['info'] = $v;
$cate_goods[] = $cate;
}
}
}
}
- 3 回答
- 0 关注
- 426 浏览
添加回答
举报
0/150
提交
取消