21,887
社区成员
发帖
与我相关
我的任务
分享
[{
"order_sn": "20191031030746713817",
"consignee": "易烊千玺",
"mobile": "15019252840",
"province": "北京",
"city": "北京市",
"area": "朝阳区",
"address": "牛皮",
"number": 30,
"price": 5500,
"total_amount": 165000,
"created_at": "2019-10-31 03:07:46"
}, {
"order_sn": "20191031031248713766",
"consignee": "王俊凯",
"mobile": "18834876789",
"province": "北京",
"city": "北京市",
"area": "朝阳区",
"address": "嘻嘻",
"number": 5,
"price": 5500,
"total_amount": 30250,
"created_at": "2019-10-31 03:12:48"
}, {
"order_sn": "20191031050229713346",
"consignee": "王俊凯",
"mobile": "18834876789",
"province": "北京",
"city": "北京市",
"area": "朝阳区",
"address": "嘻嘻",
"number": 90,
"price": 5500,
"total_amount": 544500,
"created_at": "2019-10-31 05:02:29"
}]
$data='[{
"order_sn": "20191031030746713817",
"consignee": "易烊千玺",
"mobile": "15019252840",
"province": "北京",
"city": "北京市",
"area": "朝阳区",
"address": "牛皮",
"number": 30,
"price": 5500,
"total_amount": 165000,
"created_at": "2019-10-31 03:07:46"
}, {
"order_sn": "20191031031248713766",
"consignee": "王俊凯",
"mobile": "18834876789",
"province": "北京",
"city": "北京市",
"area": "朝阳区",
"address": "嘻嘻",
"number": 5,
"price": 5500,
"total_amount": 30250,
"created_at": "2019-10-31 03:12:48"
}, {
"order_sn": "20191031050229713346",
"consignee": "王俊凯",
"mobile": "18834876789",
"province": "北京",
"city": "北京市",
"area": "朝阳区",
"address": "嘻嘻",
"number": 90,
"price": 5500,
"total_amount": 544500,
"created_at": "2019-10-31 05:02:29"
}]';
$data=json_decode($data,true);
$newData=[];
foreach($data as $k=>$v){
$key=md5($v['province'].$v['city'].$v['area'].$v['address'].$v['mobile'].$v['consignee']);
if(!isset($newData[$key])){
$newData[$key]=$data[$k];
}else{
$newData[$key]['order_sn'].=','.$v['order_sn'];
$newData[$key]['number']+=$v['number'];
$newData[$key]['total_amount']+=$v['total_amount'];
$newData[$key]['price'].=','.$v['price'];
}
}
print_r($newData);
exit;