【发布时间】:2020-12-10 08:53:36
【问题描述】:
这是我的控制器
foreach ($dataOrder['items'] as $rowJubelio) {
DataOrderDetailEcommerce::firstOrCreate([
'order_id' => DataOrderEcommerce::firstOrCreate([
'orderid'=> $invoice,
'cust_name'=> ucwords($cust_name),
'province'=> $province,
'city'=> $city,
'district'=> $area,
'zipcode'=> $zipcode,
'phone'=>$phone,
'fleet_id'=> $fleet,
'ecommerce_id'=> $ecommerce,
'date_add'=>date('Y-m-d'),
'no_resi'=> $no_resi,
'email'=> $email,
'order_time'=> $transactionDate
])->orderid,
'sku_id'=> $rowJubelio['item_code'],
'qty'=> substr($rowJubelio['qty'], 0, -5),
'price'=> substr($rowJubelio['amount'], 0, -5)/$rowJubelio['qty']
]);
}
当我第一次调用控制器时,与 cerated_at 和 updated_at 一样,当我调用控制器 2、3、4 次时,我得到具有相同 order_id、sku_id 和价格的重复条目,但 created_at 和 updated_at 不同, ...
【问题讨论】:
-
可能价格有小数,数据库在搜索时找不到记录,所以插入并截断它们。试试
price => (int) substr($rowJubelio['amount'], 0, -5)/$rowJubelio['qty']