TaskKs.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * ----------------------------------------------------------------------------
  4. * 行到水穷处,坐看云起时
  5. * 开发软件,找贵阳云起信息科技,官网地址:https://www.56q7.com/
  6. * ----------------------------------------------------------------------------
  7. * Author: 老成
  8. * email:85556713@qq.com
  9. */
  10. declare(strict_types=1);
  11. namespace app\admin\command;
  12. use app\common\model\FengsuShip;
  13. use think\console\Command;
  14. use think\console\Input;
  15. use think\console\Output;
  16. use GuzzleHttp\Client;
  17. use app\common\model\CrontabLog;
  18. use app\common\model\FengsuSku;
  19. use app\common\model\ShopList;
  20. use app\common\model\ProductConfig;
  21. use app\common\model\ShopDelivery;
  22. use app\common\model\CustomerSpec;
  23. use app\admin\service\FengsuService;
  24. use GuzzleHttp\Psr7\Request;
  25. //快手
  26. class TaskKs extends Command
  27. {
  28. protected $url = 'https://fsks.fengsutb.com/amount/ship-list-new';
  29. protected $headers = [
  30. 'Accept'=> "application/json, text/plain, */*",
  31. 'Accept-Encoding'=> "gzip, deflate, br, zstd",
  32. 'Accept-Language'=> "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
  33. "Authorization"=> "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZmEiLCJuaWtlIjoi6Zi_5Y-R5rWL6YCfIiwiY3JlYXRlZCI6MTc1ODc5MDI4NDU3OSwiZHBJZCI6MTkxOTQwLCJleHAiOjE3NTkwNDk0ODQsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpbInpodXlvbmdodSJdLCJkcEFjY291bnRJZCI6MTc4MzU3fQ.TuHvPz7Jf0vuYsbrxX9VpyZ2oOrtZ0YzLQJafoX_RV8up1PmtPLfPATBE93_v_1Ig39nODadaTb4aePy3b0hsA",
  34. "Cache-Control"=> "no-cache",
  35. 'Connection' => 'keep-alive',
  36. "Content-Type"=> "application/json",
  37. "Host" => "fsks.fengsutb.com",
  38. "Origin" => "https://fx.fengsutb.com",
  39. "platform" => "ks",
  40. "Pragma"=> "no-cache",
  41. "Referer"=> "https://fx.fengsutb.com/",
  42. "Sec-ch-ua" => '"Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"',
  43. "Sec-ch-ua-Mobile"=> "?0",
  44. "Sec-ch-ua-platform"=> "Windows",
  45. "Sec-Fetch-Dest" => "empty",
  46. "Sec-Fetch-Mode" => "cors",
  47. "Sec-Fetch-Site" => "same-site",
  48. "User-Agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0"
  49. ];
  50. // 指令配置
  51. protected function configure()
  52. {
  53. $this->setName('task:ks')->setDescription('the task command');
  54. }
  55. //根据shop_id
  56. protected function execute(Input $input, Output $output)
  57. {
  58. $client = new Client([ 'verify' => false]);
  59. $last_time = CrontabLog::getLastRunTime(3);
  60. $body = '{
  61. "goodType": 2,
  62. "goodsFlag": 1,
  63. "current": 1,
  64. "size": 25,
  65. "startTime": "'.$last_time.'",
  66. "endTime": "'.date('Y-m-d H:i:s').'",
  67. "skuOuterIdExact": false,
  68. "skuPropExact": false,
  69. "sort": "CONSIGN_TIME",
  70. "sortAsc": false,
  71. "timeType": 2,
  72. "tradeStatus": 2
  73. }';
  74. $request = new Request('POST', $this->url, $this->headers, $body);
  75. $res = $client->sendAsync($request)->wait();
  76. if($res->getStatusCode() == 200) {
  77. $data = json_decode($res->getBody()->getContents(), true);
  78. $list = $data['data']['list'];
  79. if(empty($list)) {
  80. $output->writeln('无数据');
  81. return;
  82. }
  83. $queue = [];
  84. $shopList = new ShopList();
  85. $fengsuSku = new FengsuSku();
  86. $productConfig = new ProductConfig();
  87. $shopDelivery = new ShopDelivery();
  88. $customerSpec = new CustomerSpec();
  89. foreach($list as $item) {
  90. $status = FengsuService::getAdditionalPrice( $shopList, $fengsuSku, $productConfig, $shopDelivery, $customerSpec, $item);
  91. $queue[] = [
  92. 'shop_id' => $item['shopId'],
  93. 'trade_from' => $item['tradeFrom'],
  94. 'province' => $item['receiverProvince'],
  95. 'city' => $item['receiverCity'],
  96. 'company_name' => $item['tradeOrderPrintVos'][0]['companyName'],
  97. 'waybill_no' => $item['waybillNo'],
  98. 'consign_time' => $item['consignTime'],
  99. 'goods_id' => $item['tradeOrderPrintVos'][0]['goodsId'],
  100. 'sku_id' => $item['tradeOrderPrintVos'][0]['skuId'],
  101. 'num' => $item['tradeOrderPrintVos'][0]['total'],
  102. 'goods_title' => $item['tradeOrderPrintVos'][0]['goodsTitle'],
  103. 'weigh' => $item['tradeOrderPrintVos'][0]['weight'],
  104. 'price' => bcdiv((string)$item['payment'], '100', 2),
  105. 'status' => $status,
  106. ];
  107. }
  108. // 保存到数据库
  109. (new FengsuShip())->saveAll($queue);
  110. // 更新最后执行时间
  111. CrontabLog::create(['type_id' => 3,'last_time' => date('Y-m-d H:i:s')]);
  112. }
  113. // 指令输出
  114. $output->writeln('ok');
  115. }
  116. }