企微短剧业务系统

SyncCapacityUser.php 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2023/4/7
  6. * Time: 17:55
  7. */
  8. namespace App\Console\Repair;
  9. use App\Log;
  10. use App\Models\CapacityUser;
  11. use App\Service\CapacityService;
  12. use Illuminate\Console\Command;
  13. use Illuminate\Support\Facades\DB;
  14. class SyncCapacityUser extends Command
  15. {
  16. protected $signature = 'SyncCapacityUser {date?}';
  17. protected $description = '获取容量平台订单';
  18. protected $page = 1;
  19. protected $limit = 100;
  20. protected $date;
  21. public function handle()
  22. {
  23. DB::connection()->disableQueryLog();
  24. $this->info(date('m-d H:i:s') . ' 开始更新');
  25. if(date('Y-m-d H:i:s') <= date('Y-m-d') . ' 00:00:50') {
  26. $this->date = $this->argument('date') ? $this->argument('date') : date('Y-m-d', strtotime('-1 days'));
  27. } else {
  28. $this->date = $this->argument('date') ? $this->argument('date') : date('Y-m-d');
  29. }
  30. $this->userList();
  31. $this->info(date('Y-m-d H:i:s') . ' 更新结束');
  32. }
  33. public function userList()
  34. {
  35. try {
  36. $this->page = 1;
  37. do{
  38. $params['timestamp'] = time();
  39. $params['method'] = 'user.list';
  40. $params['param'] = [
  41. 'date' => $this->date,
  42. 'pageNum' => $this->page,
  43. 'pageSize' => $this->limit
  44. ];
  45. $params['appId'] = config('capacity.app_id');
  46. $secret = config('capacity.app_secret');
  47. $params['signature'] = CapacityService::createSign($params['param'], $secret, $params['timestamp']);
  48. list($userList, $count) = CapacityService::orderList($params);
  49. Log::logInfo('容量平台用户信息', [$userList], 'CapacityUserList');
  50. # 用户信息入库
  51. foreach ($userList as $user) {
  52. CapacityUser::saveCapacityUser($user);
  53. }
  54. $this->page++;
  55. } while($this->page <= ceil($count / $this->limit));
  56. } catch (\Exception $e) {
  57. Log::logError('容量平台用户获取过程发生异常', [
  58. 'file' => $e->getFile(),
  59. 'line' => $e->getLine(),
  60. 'msg' => $e->getMessage(),
  61. 'trace' => $e->getTraceAsString()
  62. ], 'CapacityUserList-Exception');
  63. }
  64. }
  65. }