91 lines
2.5 KiB
PHP
Executable File
91 lines
2.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Enums\BoolEnum;
|
|
use App\Enums\LottState;
|
|
use App\Enums\LottType;
|
|
use App\Enums\OrderType;
|
|
use App\Events\OrderWinedEvent;
|
|
use App\Jobs\RefreshOrderCtzqBqcResult;
|
|
use App\Jobs\RefreshOrderCtzqJqcResult;
|
|
use App\Jobs\RefreshOrderJclqResult;
|
|
use App\Jobs\RefreshOrderJczqResult;
|
|
use App\Model\Config;
|
|
use App\Model\Customer\Customer;
|
|
use App\Model\Lq\JclqResult;
|
|
use App\Model\Order;
|
|
use App\Model\OrderBjdcResult;
|
|
use App\Model\OrderBjdcZuhe;
|
|
use App\Model\OrderJclqResult;
|
|
use App\Model\OrderLqZuhe;
|
|
use App\Model\Zq\BjdcResult;
|
|
use App\Service\External\AlStatService;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Arr;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class SumCustomerGendanNum extends Command
|
|
{
|
|
/**
|
|
* 这个就是命令名称
|
|
*/
|
|
protected $signature = 'customer:sum_gendan_num';
|
|
|
|
/**
|
|
* 命令的说明描述
|
|
* @var string
|
|
*/
|
|
protected $description = '';
|
|
|
|
/**
|
|
* 创建命令的构造方法。
|
|
* @param string $words 传入的字符参数
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
$orders = Order::select([
|
|
'customer_id',
|
|
DB::raw('count(*) as c')
|
|
])
|
|
->where('type', OrderType::FADAN)
|
|
->whereIn('lottery_state', [LottState::WIN, LottState::SEND])
|
|
->groupBy('customer_id')
|
|
->get();
|
|
|
|
$customerIds = collect($orders)->pluck('customer_id')->toArray();
|
|
if (!$customerIds) {
|
|
dd('not found customer');
|
|
return ;
|
|
}
|
|
|
|
$customers = Customer::whereIn('id', $customerIds)->get();
|
|
|
|
foreach ($customers as $customer) {
|
|
$orderIds = Order::where('type', OrderType::FADAN)
|
|
->whereIn('lottery_state', [LottState::WIN, LottState::SEND])
|
|
->where('customer_id', $customer->id)
|
|
->pluck('id')->toArray();
|
|
if (!$orderIds) {
|
|
dump('customer:'.$customer->id. ' not found fadan');
|
|
continue;
|
|
}
|
|
|
|
$gendanNum = Order::whereIn('pid', $orderIds)
|
|
->whereIn('lottery_state', [LottState::WIN, LottState::SEND, LottState::LOSS])
|
|
->count();
|
|
Customer::where('id', $customer->id)
|
|
->update([
|
|
'gendan_num' => $gendanNum
|
|
]);
|
|
}
|
|
}
|
|
}
|