1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Console\Test;
- use App\Cache\UserCache;
- use App\Models\User\User;
- use Illuminate\Console\Command;
- class ChangeUserChannelId extends Command
- {
- /**
- * @var string
- */
- protected $signature = 'user:change:channel:id {uid} {channelId}';
- /**
- * The console command description.
- * php artisan Payment:BasePayment --bid='1'
- *
- * @var string
- */
- protected $description = '修改用户站点id';
- public function handle()
- {
- $uid = (int)$this->argument('uid');
- $channelId = (int)$this->argument('channelId');
- if ($uid < 1 || $channelId < 1) {
- dd('参数错误');
- }
- // 获取uid信息
- $user = User::where('id', $uid)->first();
- if (!getProp($user, 'id')) {
- dd('查询不到该用户');
- }
- // 执行更新
- $user->distribution_channel_id = $channelId;
- $user->save();
- // 获取用户缓存信息
- $token = getProp($user, 'token');
- $userCache = UserCache::getTokenData($token);
- if (empty($userCache)) {
- dd('查询不到用户token缓存');
- }
- // 更新用户缓存
- $userCache['distribution_channel_id'] = $channelId;
- UserCache::setTokenData($token, $userCache);
- }
- }
|