v2board/app/Console/Commands/CheckCommission.php

59 lines
1.2 KiB
PHP
Raw Normal View History

2019-10-29 15:33:36 +08:00
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\Order;
use App\Models\User;
class CheckCommission extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'check:commission';
/**
* 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()
{
2019-11-29 02:32:09 +08:00
$order = Order::where('commission_status', 1)
2019-10-29 15:33:36 +08:00
->where('status', 3)
->get();
foreach ($order as $item) {
2019-11-05 17:20:34 +08:00
if ($item->invite_user_id) {
2019-11-21 22:20:32 +08:00
$inviter = User::find($item->invite_user_id);
2019-10-29 15:33:36 +08:00
if (!$inviter) continue;
2019-11-28 13:55:45 +08:00
$inviter->commission_balance = $inviter->commission_balance + $item->commission_balance;
2019-10-29 15:33:36 +08:00
if ($inviter->save()) {
2019-11-29 02:32:09 +08:00
$item->commission_status = 2;
2019-10-29 15:33:36 +08:00
$item->save();
}
}
}
}
}