startOfMonth

This commit is contained in:
邓皓元 2019-08-22 09:37:26 +08:00
parent 6fd8e00470
commit c9e5d157e9

View File

@ -21,10 +21,12 @@ class RefundSync extends Command
$starttime = $datetime->copy()->startOfMonth()->startOfDay();
$endtime = $datetime->copy()->endOfMonth()->endOfDay();
$lasttime = $starttime->copy()->subMonth()->startOfMonth();
$refunds = DB::connection('real')->table('jxc_back_card')
->select(['sim', 'create_time'])
->where('status', 2)
->where('create_time', '>=', $starttime)
->where('create_time', '>=', $lasttime)
->where('create_time', '<=', $endtime)
->get();
@ -36,12 +38,12 @@ class RefundSync extends Command
});
// 最早退货的时间
DB::transaction(function () use ($refunds, $starttime) {
DB::transaction(function () use ($refunds, $lasttime) {
foreach ($refunds as $item) {
DB::table('real_order_cards')
->whereIn('sim', $item->sim)
->where('created_at', '<=', $item->create_time)
->where('created_at', '>=', $starttime)
->where('created_at', '>=', $lasttime)
->update(['refunded_at' => $item->create_time]);
$simArrayText = implode(',', $item->sim);
@ -56,7 +58,7 @@ class RefundSync extends Command
AND v.created_at >= '%s'
";
DB::update(sprintf($sql, $item->create_time, $simArrayText, $item->create_time, $starttime));
DB::update(sprintf($sql, $item->create_time, $simArrayText, $item->create_time, $lasttime));
}
});