BrokerUserConfigCommand.php
2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace App\Console\Commands;
use App\Enums\BrokerPushLevelRecordStatusEnum;
use App\Jobs\BrokerPushLevelRecordSendJob;
use App\Models\BrokerPushLevelRecord;
use App\Models\BrokerUserConfig;
use App\Models\BrokerUserConfigItem;
use DB;
use Illuminate\Console\Command;
class BrokerUserConfigCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'broker:user-config {method}';
/**
* The console command description.
*
* @var string
*/
protected $description = '经纪人运营-用户配置';
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
$method = $this->argument('method');
switch ($method) {
case 'singer_num':
BrokerUserConfigItem::query()
->leftJoin('users', 'users.id', 'broker_user_config_items.user_id')
->where('config_id', BrokerUserConfig::query()->whereDate('begin_at', now()->toDateString())->value('id'))
->where('broker_user_config_items.status', 1)
->where('broker_user_config_items.is_sync', 0)
->update([
'users.business_singer_limit' => DB::raw('CASE WHEN broker_user_config_items.singer_num = "" THEN users.business_singer_limit ELSE broker_user_config_items.singer_num END'),
'broker_user_config_items.is_sync' => 1
]);
break;
case 'level_message':
BrokerPushLevelRecord::query()
->where('status', BrokerPushLevelRecordStatusEnum::WAITING)
->whereBetween('publish_at', [now()->subHour()->toDateTimeString(), now()->toDateTimeString()])
->eachById(fn(BrokerPushLevelRecord $record) => BrokerPushLevelRecordSendJob::dispatchSync($record));
break;
}
return self::SUCCESS;
}
}