LoadlogsCommand.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Repositories\Enums\Base\AdminTypeEnum;
  4. use App\Repositories\Enums\BikeManage\BindingOperateTypeEnum;
  5. use App\Repositories\Enums\BikeManage\BindingStatusEnum;
  6. use App\Repositories\Enums\Car\BillDisburseEnum;
  7. use App\Repositories\Enums\Car\OrderDrivingStatusEnum;
  8. use App\Repositories\Enums\Car\OrderPayTypeEnum;
  9. use App\Repositories\Enums\Check\StatusEnum;
  10. use App\Repositories\Enums\ModelStatusEnum;
  11. use App\Repositories\Models\Base\Admin;
  12. use App\Repositories\Models\Base\Department;
  13. use App\Repositories\Models\Base\User;
  14. use App\Repositories\Models\BikeManage\Bike;
  15. use App\Repositories\Models\BikeManage\Binding;
  16. use App\Repositories\Models\Car\Bill;
  17. use App\Repositories\Models\Car\Order;
  18. use App\Repositories\Models\Car\OrderLog;
  19. use Carbon\Carbon;
  20. use GuzzleHttp\Client;
  21. use GuzzleHttp\Cookie\CookieJar;
  22. use Illuminate\Console\Command;
  23. use Illuminate\Support\Facades\DB;
  24. use Illuminate\Support\Facades\Hash;
  25. use Illuminate\Support\Str;
  26. /**
  27. * Class PresenterCommand
  28. * @package Prettus\Repository\Generators\Commands
  29. * @author Anderson Andrade <contato@andersonandra.de>
  30. */
  31. class LoadlogsCommand extends Command
  32. {
  33. /**
  34. * The name of command.
  35. *
  36. * @var string
  37. */
  38. protected $name = 'load:logs';
  39. /**
  40. * The description of command.
  41. *
  42. * @var string
  43. */
  44. protected $description = 'test';
  45. /**
  46. * The type of class being generated.
  47. *
  48. * @var string
  49. */
  50. protected $type = 'permission';
  51. private $cookieJar = null;
  52. private $client = null;
  53. /**
  54. * Execute the command.
  55. *
  56. * @return void
  57. * @see fire()
  58. */
  59. public function handle()
  60. {
  61. $this->client = new Client();
  62. $cookie_str = 'HWWAFSESID=50dfc7357adc6e0919; HWWAFSESTIME=1710222167359; MOD_AUTH_CAS=ST-iap:1018617332602740:ST:7c922f18-b70a-4bbb-b6a3-9fb10dc9b97f:20240312134247';
  63. $cookie_arr = str2arr($cookie_str, '; ');
  64. $cookie = [];
  65. foreach ($cookie_arr as $v) {
  66. list($key, $val) = str2arr($v, '=');
  67. $cookie[$key] = $val;
  68. }
  69. $this->cookieJar = CookieJar::fromArray($cookie, 'hactcm.campusphere.net');
  70. $categories = $this->loadCategory();
  71. foreach ($categories as $category) {
  72. $da = $this->loadLogsData([
  73. 'dateType' => 5,
  74. 'dateStart' => '2024-02-01',
  75. 'dateEnd' => '2024-03-12',
  76. 'deptWid' => '73230',
  77. 'formWid' => $category['wid'],
  78. 'idOrName' => '',
  79. 'ownDeptWid' => '-1',
  80. 'pageNumber' => 1,
  81. 'pageSize' => 8,
  82. 'searchFillContent' => '',
  83. 'searchStuContent' => '',
  84. 'sortColumn' => '',
  85. 'sortOrder' => '',
  86. 'teacherUserWids' => [],
  87. ]);
  88. dd($da);
  89. }
  90. $this->line('ok');
  91. }
  92. public static function parseResult($result)
  93. {
  94. $result = js2php($result);
  95. if (!is_array($result)) return [];
  96. return $result['datas']['rows'];
  97. }
  98. public function loadCategory()
  99. {
  100. $response = $this->client->request('POST', 'https://hactcm.campusphere.net/wec-counselor-worklog-apps/worklog/template/listActiveTemplate', [
  101. 'cookies' => $this->cookieJar,
  102. 'headers' => [
  103. 'Content-Type' => 'application/json'
  104. ],
  105. 'json' => [
  106. 'status' => 1,
  107. ]
  108. ]);
  109. // 获取响应体
  110. $result = $response->getBody()->getContents();
  111. return self::parseResult($result);
  112. }
  113. public function loadLogsData($param)
  114. {
  115. $page = 1;
  116. $pre_page = 10;
  117. $total_page = 1;
  118. $data = [];
  119. $filed = [];
  120. do {
  121. $param['pageNumber'] = $page;
  122. $param['pageSize'] = $pre_page;
  123. $response = $this->client->request('POST', 'https://hactcm.campusphere.net/wec-counselor-worklog-apps/worklogSummary/queryWorkLogsInSummary', [
  124. 'cookies' => $this->cookieJar,
  125. 'headers' => [
  126. 'Content-Type' => 'application/json'
  127. ],
  128. 'json' => $param
  129. ]);
  130. // 获取响应体
  131. $result = $response->getBody()->getContents();
  132. $result = js2php($result);
  133. if (is_array($result) && !$result['code']) {
  134. $datas = $result['datas'];
  135. $total_page = $datas['totalSize'];
  136. if (!count($filed)) {
  137. foreach ($datas['summaryCols'] as $col) {
  138. $filed[$col['colName']] = $col['colTitle'];
  139. }
  140. }
  141. foreach ($datas['rows'] as $row) {
  142. $rowData = [];
  143. foreach ($row as $item) {
  144. $rowData[$item['colName']] = $item['value'];
  145. }
  146. $data[] = $rowData;
  147. }
  148. }
  149. $page++;
  150. } while ($page <= $total_page);
  151. return $data;
  152. }
  153. }