update only

This commit is contained in:
邓皓元 2019-04-29 11:37:59 +08:00
parent ed431e98c7
commit c05b1b9e06

View File

@ -99,12 +99,13 @@ class AddedOrderSync extends Command
$starttime = $this->datetime->copy()->startOfMonth()->startOfDay();
$endtime = $this->datetime->copy()->endOfMonth()->endOfDay();
$orders = DB::table($virtualTable)->selectRaw('sim, order_id')
$orders = DB::table($virtualTable)->selectRaw('sim, order_id, unit_price, counts')
->where('created_at', '>=', $starttime->format('Y-m-d H:i:s'))
->where('created_at', '<=', $endtime->format('Y-m-d H:i:s'))
->whereIn('sim', array_pluck($data, 'sim'))
->whereNull('deleted_at')
->orderBy('created_at')
->orderBy('sim')
->orderBy('unit_price')
->get()
->collect()
->groupBy('sim')->toArray();
@ -112,7 +113,17 @@ class AddedOrderSync extends Command
foreach ($data as &$value) {
$i = array_count_values($simArray)[$value['sim']] ?? 0;
array_push($simArray, $value['sim']);
$value['virtual_order_id'] = $orders[$value['sim']][$i]['order_id'] ?? 0;
$valueOrders = $orders[$value['sim']];
$value['virtual_order_id'] = 0;
foreach ($valueOrders as $key => $order) {
if ($order['counts'] === $value['counts'] && $order['unit_price'] === $value['unit_price']) {
$value['virtual_order_id'] = $valueOrders[0]['order_id'] ?? 0;
unset($valueOrders[$key]);
$orders[$value['sim']] = array_values($valueOrders);
}
}
}
$only = ['company_id', 'package_id', 'counts', 'unit_price'];