循环添加数据到数据库
$allnum = count($ret['data']);//总条数
$onenum = 20;//一次添加的条数
dd($ret['data']);
for($a=0;$a<$allnum;$a+=$onenum)
{
$retall = array_slice($ret['data'],$a,$onenum);
$res = $this->platGoodsBiz->add($retall,$endtime);
if($res['errcode'] == 0)
{
Log::error('添加到数据库的次数1');
continue;
}
else
{
dd('添加失败');
}
}
解析 platform_goods_id
$platform_goods_ids = function ($result_first) {
foreach ($result_first['data'] as $k => $v) {
yield $v['platform_goods_id'];
}
};
foreach ($platform_goods_ids($ret) as $key => $value) {
$data['platform_goods_id'][] = $value;
}
//排除相同的商品id
$res = $this->platGoodsBiz->getPlatGoodsIds($data['platform_goods_id']);
//添加获取的商品ID详细信息
for($i=0;$i<count($res['data']);$i++){
$item_info = $this->getItem($res['data'][$i],$endtime);
if($item_info){
continue;
}else{
dd('添加数据时返回了错误');
}
}
$site_international_data = array_map(function ($n) {
return [
'name' => $n['name'],
'value' => json_decode($n['shipping_info'],true),
];
}, $site_international_data);
// 请求失败
if ($result['Ack'] == 'Failure') {
$msg = "异常来源: {$function_name} \n";
array_map(function ($n) use (&$msg) {
$msg .= "异常信息: <" . $n['ShortMessage'] . "> \n";
}, $result['Errors']);
dump($result);
throw new \Exception($msg, '200');
}