1
0
Files
lkafu/app/Console/Commands/OrderPerfCommand.php
2020-08-06 14:45:56 +08:00

66 lines
1.6 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Bonus\AddPerf;
use Illuminate\Console\Command;
use RuLong\Order\Models\Order;
class OrderPerfCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rulong:OrderPerfCommand';
/**
* The console command description.
*
* @var string
*/
protected $description = '计算订单业绩';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$time = now()->subDays(7)->format('Y-m-d H:i:s');
//状态签收或完成
//是否完成业绩为0
//type会员商城商品
//物流签收时间7天后
$orders = Order::whereIn('state', ['SIGNED', 'COMPLETED'])
->where('type', 'MEMBER')
->where('isPerf', 0)
->whereHas('express', function ($query) {
$query->where('receive_at', '<=', $time);
})->get();
foreach ($orders as $key => $order) {
$source = [
'user_id' => $order->user->id,
'type' => 'Shop',
'order_id' => $order->id,
];
AddPerf::settlement($order->user, $order->amount, $source);
\App\Jobs\CityOrderProfit::dispatch($order->express);
$order->isPerf = 1;
$order->save();
}
}
}