У меня есть и Json данные из этого https://sheet.best/api/sheets/ca84f2d3-1219-461d-b07c-1cf6cfbbbed5/tabs/jd, выглядит так:
{
0: "1021131123",
1: "500607470,500619497,500689186,500689221,500734221,500764567,500764640,501072542,507511116,",
2: "10121,24465,10076,10115,10106,10027,10031,20426,20248,",
3: "15",
4: "Online Payment",
5: "2020/4/23 18:44",
6: "222800"
},
{
0: "1021131123",
1: "500607470,500619497,500689186,500689221,500734221,500764567,500764640,501072542,507511116,",
2: "10121,24465,10076,10115,10106,10027,10031,20426,20248,",
3: "15",
4: "Online Payment",
5: "2020/4/23 18:44",
6: "222800"
},
{
0: "1021131123",
1: "500607470,500619497,500689186,500689221,500734221,500764567,500764640,501072542,507511116,",
2: "10121,24465,10076,10115,10106,10027,10031,20426,20248,",
3: "15",
4: "Online Payment",
5: "2020/4/23 18:44",
6: "222800",...
}
У меня есть идентификатор заказа в массиве 0: "1021131123"
, который содержит детали sku в массиве нет 2:"10121,24465,10076,10115,10106,10027,10031,20426,20248,"
, но номера sku собраны в один массив, я хочу сначала разделить их перед тем, как поместить их в базу данных, выглядит так:
{
0: "1021131123",
1: "500607470,500619497,500689186,500689221,500734221,500764567,500764640,501072542,507511116,",
2: "10121",
3: "15",
4: "Online Payment",
5: "2020/4/23 18:44",
6: "222800"
},
{
0: "1021131123",
1: "500607470,500619497,500689186,500689221,500734221,500764567,500764640,501072542,507511116,",
2: "24465",
3: "15",
4: "Online Payment",
5: "2020/4/23 18:44",
6: "222800"
},
{
0: "1021131123",
1: "500607470,500619497,500689186,500689221,500734221,500764567,500764640,501072542,507511116,",
2: "10076",
3: "15",
4: "Online Payment",
5: "2020/4/23 18:44",
6: "222800",...
}
я просто получаю отделенный skuid, .. .
$data = "10121,24465,10076,10115,10106,10027,10031,20426,20248,";
$sku = explode(',', $data);
это мой контроллер, ..
$jd = "https://sheet.best/api/sheets/ca84f2d3-1219-461d-b07c-1cf6cfbbbed5/tabs/jd";
$data_json_jd = json_decode(file_get_contents($jd), true);
$fleet = 0;
$total_price = 0;
foreach ($data_json_jd as $key_jd) {
$data = DataOrderC::where('orderid', $key_jd['0'])
->get();
if($key_jd['0'] != '')
{
if($data)
{
OrderDetailC::firstOrCreate([
'order_id'=> $key_jd['0'],
'sku_id'=>$key_jd['2'],
'qty'=>$key_jd['31'],
]);
DataOrderC::firstOrCreate([
'orderid'=>$key_jd['0'],
'order_time'=>date('Y-m-d H:i:s', strtotime($key_jd['5'])),
'province'=>$key_jd['14'],
'city'=>$key_jd['15'],
'district'=>$key_jd['16'],
'address'=>$key_jd['17'],
'cust_name'=>ucwords($key_jd['10']),
'full_address'=>$key_jd['17'].', '.$key_jd['16'].', '.$key_jd['15'].', '.$key_jd['14'],
'phone'=>'62'.$key_jd['18'],
'fleet_id'=> 1,
'ecommerce_id'=> 2 //shopee
]);
}
else{
}
}
}