virtual_order_optional_package_cards

This commit is contained in:
邓皓元 2019-03-15 20:40:56 +08:00
parent f62c71a512
commit e9b2c38179

View File

@ -83,17 +83,19 @@ class AddedOrderSync extends Command
$virtualTable = str_replace('real_', 'virtual_', $table);
$starttime = $this->datetime->copy()->startOfMonth()->startOfDay();
$endtime = $this->datetime->copy()->endOfMonth()->endOfDay();
if (!in_array($virtualTable, ['virtual_order_optional_package_cards', 'virtual_order_additional_package_cards'])) {
$starttime = $this->datetime->copy()->startOfMonth()->startOfDay();
$endtime = $this->datetime->copy()->endOfMonth()->endOfDay();
$orders = DB::table($virtualTable)->selectRaw('sim,MAX(order_id)')
->where('created_at', '>=', $starttime)
->where('created_at', '<=', $endtime)
->whereIn('sim', array_pluck($data, 'sim'))
->groupBy('sim')->get()->pluck('order_id', 'sim');
$orders = DB::table($virtualTable)->selectRaw('sim,MAX(order_id)')
->where('created_at', '>=', $starttime)
->where('created_at', '<=', $endtime)
->whereIn('sim', array_pluck($data, 'sim'))
->groupBy('sim')->get()->pluck('order_id', 'sim');
foreach ($data as &$value) {
$value['virtual_order_id'] = $orders[$value['sim']] ?? 0;
foreach ($data as &$value) {
$value['virtual_order_id'] = $orders[$value['sim']] ?? 0;
}
}
DB::table($table)->upsert($data, ['sim', 'order_id'], true);