1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2023/4/7
- * Time: 17:55
- */
- namespace App\Console\Repair;
- use App\Log;
- use App\Models\CapacityUser;
- use App\Service\CapacityService;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- class SyncCapacityUser extends Command
- {
- protected $signature = 'SyncCapacityUser {date?}';
- protected $description = '获取容量平台订单';
- protected $page = 1;
- protected $limit = 100;
- protected $date;
- public function handle()
- {
- DB::connection()->disableQueryLog();
- $this->info(date('m-d H:i:s') . ' 开始更新');
- if(date('Y-m-d H:i:s') <= date('Y-m-d') . ' 00:00:50') {
- $this->date = $this->argument('date') ? $this->argument('date') : date('Y-m-d', strtotime('-1 days'));
- } else {
- $this->date = $this->argument('date') ? $this->argument('date') : date('Y-m-d');
- }
- $this->userList();
- $this->info(date('Y-m-d H:i:s') . ' 更新结束');
- }
- public function userList()
- {
- try {
- $this->page = 1;
- do{
- $params['timestamp'] = time();
- $params['method'] = 'user.list';
- $params['param'] = [
- 'date' => $this->date,
- 'pageNum' => $this->page,
- 'pageSize' => $this->limit
- ];
- $params['appId'] = config('capacity.app_id');
- $secret = config('capacity.app_secret');
- $params['signature'] = CapacityService::createSign($params['param'], $secret, $params['timestamp']);
- list($userList, $count) = CapacityService::orderList($params);
- Log::logInfo('容量平台用户信息', [$userList], 'CapacityUserList');
- # 用户信息入库
- foreach ($userList as $user) {
- CapacityUser::saveCapacityUser($user);
- }
- $this->page++;
- } while($this->page <= ceil($count / $this->limit));
- } catch (\Exception $e) {
- Log::logError('容量平台用户获取过程发生异常', [
- 'file' => $e->getFile(),
- 'line' => $e->getLine(),
- 'msg' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ], 'CapacityUserList-Exception');
- }
- }
- }
|