$goods_ids_in_A = DB::table(PddGoods::tableName)
->pluck('goods_id')
->toArray();
$data=json_decode($da,true);
$result = array_map(function ($item) {
return [
'goods_id' => $item['goods_id'],
'goods_name' => $item['goods_name']
];
}, $data);
// 过滤 B,保留不在 A 中的记录
$filtered_B = array_filter($result, function ($item) use ($goods_ids_in_A) {
return !in_array($item['goods_id'], $goods_ids_in_A);
});
// 如果需要重新索引数组(去掉键)
$filtered_B = array_values($filtered_B);
DB::table(PddGoods::tableName)->insertOrIgnore($filtered_B);
// 打印结果
dump($filtered_B);die;