退货规则修改

This commit is contained in:
邓皓元 2019-08-22 09:41:08 +08:00
parent c9e5d157e9
commit e4fd8bbac6

View File

@ -14,6 +14,8 @@ class RefundSync extends Command
protected $companies; protected $companies;
protected $subMonths = 1;
public function handle() public function handle()
{ {
$datetime = $this->getDateTime(); $datetime = $this->getDateTime();
@ -21,12 +23,12 @@ class RefundSync extends Command
$starttime = $datetime->copy()->startOfMonth()->startOfDay(); $starttime = $datetime->copy()->startOfMonth()->startOfDay();
$endtime = $datetime->copy()->endOfMonth()->endOfDay(); $endtime = $datetime->copy()->endOfMonth()->endOfDay();
$lasttime = $starttime->copy()->subMonth()->startOfMonth();
$refunds = DB::connection('real')->table('jxc_back_card') $refunds = DB::connection('real')->table('jxc_back_card')
->select(['sim', 'create_time']) ->select(['sim', 'create_time'])
->where('status', 2) ->where('status', 2)
->where('create_time', '>=', $lasttime) ->where('create_time', '>=', $starttime)
->where('create_time', '<=', $endtime) ->where('create_time', '<=', $endtime)
->get(); ->get();
@ -38,12 +40,14 @@ class RefundSync extends Command
}); });
// 最早退货的时间 // 最早退货的时间
DB::transaction(function () use ($refunds, $lasttime) { DB::transaction(function () use ($refunds) {
foreach ($refunds as $item) { foreach ($refunds as $item) {
$lastTime = Carbon::parse($item->create_time)->subMonths($this->subMonths)->startOfMonth();
DB::table('real_order_cards') DB::table('real_order_cards')
->whereIn('sim', $item->sim) ->whereIn('sim', $item->sim)
->where('created_at', '<=', $item->create_time) ->where('created_at', '<=', $item->create_time)
->where('created_at', '>=', $lasttime) ->where('created_at', '>=', $lastTime)
->update(['refunded_at' => $item->create_time]); ->update(['refunded_at' => $item->create_time]);
$simArrayText = implode(',', $item->sim); $simArrayText = implode(',', $item->sim);
@ -58,7 +62,7 @@ class RefundSync extends Command
AND v.created_at >= '%s' AND v.created_at >= '%s'
"; ";
DB::update(sprintf($sql, $item->create_time, $simArrayText, $item->create_time, $lasttime)); DB::update(sprintf($sql, $item->create_time, $simArrayText, $item->create_time, $lastTime));
} }
}); });