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;
|
2021-01-10 02:25:31 +08:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2019-10-29 15:33:36 +08:00
|
|
|
|
|
|
|
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()
|
2020-05-03 23:17:55 +08:00
|
|
|
{
|
|
|
|
$this->autoCheck();
|
|
|
|
$this->autoPayCommission();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function autoCheck()
|
|
|
|
{
|
2020-05-04 20:08:43 +08:00
|
|
|
if ((int)config('v2board.commission_auto_check_enable', 1)) {
|
2020-05-03 23:17:55 +08:00
|
|
|
Order::where('commission_status', 0)
|
2020-11-26 15:07:47 +08:00
|
|
|
->where('invite_user_id', '!=', NULL)
|
2020-11-26 14:44:00 +08:00
|
|
|
->whereIn('status', [3, 4])
|
2020-05-07 18:54:18 +08:00
|
|
|
->where('updated_at', '<=', strtotime('-3 day', time()))
|
2020-05-03 23:17:55 +08:00
|
|
|
->update([
|
|
|
|
'commission_status' => 1
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function autoPayCommission()
|
2019-10-29 15:33:36 +08:00
|
|
|
{
|
2019-11-29 02:32:09 +08:00
|
|
|
$order = Order::where('commission_status', 1)
|
2020-11-26 15:07:47 +08:00
|
|
|
->where('invite_user_id', '!=', NULL)
|
2019-10-29 15:33:36 +08:00
|
|
|
->get();
|
|
|
|
foreach ($order as $item) {
|
2021-01-10 02:25:31 +08:00
|
|
|
DB::beginTransaction();
|
2020-11-26 15:07:47 +08:00
|
|
|
$inviter = User::find($item->invite_user_id);
|
|
|
|
if (!$inviter) continue;
|
|
|
|
$inviter->commission_balance = $inviter->commission_balance + $item->commission_balance;
|
2021-01-10 02:25:31 +08:00
|
|
|
if (!$inviter->save()) {
|
|
|
|
DB::rollBack();
|
|
|
|
continue;
|
2019-10-29 15:33:36 +08:00
|
|
|
}
|
2021-01-10 02:25:31 +08:00
|
|
|
$item->commission_status = 2;
|
|
|
|
if (!$item->save()){
|
|
|
|
DB::rollBack();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
DB::commit();
|
2019-10-29 15:33:36 +08:00
|
|
|
}
|
|
|
|
}
|
2020-01-11 13:36:52 +08:00
|
|
|
|
2019-10-29 15:33:36 +08:00
|
|
|
}
|