TaskTb.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 TaskTb extends Command
  27. {
  28. //淘宝请求地址
  29. protected $url = 'https://fszntb.zhifeiyun.cn/amount/ship-list-new';
  30. //请求头部
  31. protected $headers = [
  32. 'Accept'=> "application/json, text/plain, */*",
  33. 'Accept-Encoding'=> "gzip, deflate, br, zstd",
  34. 'Accept-Language'=> "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
  35. "Authorization"=> "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZmEiLCJuaWtlIjoi6Zi_5Y-R5rWL6YCfIiwiY3JlYXRlZCI6MTc1ODc5MDI4NDU3OSwiZHBJZCI6MTkxOTQwLCJleHAiOjE3NTkwNDk0ODQsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpbInpodXlvbmdodSJdLCJkcEFjY291bnRJZCI6MTc4MzU3fQ.TuHvPz7Jf0vuYsbrxX9VpyZ2oOrtZ0YzLQJafoX_RV8up1PmtPLfPATBE93_v_1Ig39nODadaTb4aePy3b0hsA",
  36. "Cache-Control"=> "no-cache",
  37. "Content-Type"=> "application/json",
  38. "Origin"=> "https://fx.fengsutb.com",
  39. "platform" => "tb",
  40. "Pragma"=> "no-cache",
  41. "priority" => "u=1, i",
  42. "Referer"=> "https://fx.fengsutb.com/",
  43. "Sec-ch-ua" => '"Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"',
  44. "Sec-ch-ua-Mobile"=> "?0",
  45. "Sec-ch-ua-platform"=> "Windows",
  46. "Sec-Fetch-Dest" => "empty",
  47. "Sec-Fetch-Mode" => "cors",
  48. "Sec-Fetch-Site" => "same-site",
  49. "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"
  50. ];
  51. // 指令配置
  52. protected function configure()
  53. {
  54. $this->setName('task:tb')->setDescription('the task command');
  55. }
  56. //根据shop_id
  57. protected function execute(Input $input, Output $output)
  58. {
  59. $client = new Client([ 'verify' => false]);
  60. $last_time = CrontabLog::getLastRunTime(0);
  61. $body = '{
  62. "goodType": 2,
  63. "goodsFlag": 1,
  64. "current": 1,
  65. "size": 25,
  66. "startTime": "'.$last_time.'",
  67. "endTime": "'.date('Y-m-d H:i:s').'",
  68. "skuOuterIdExact": false,
  69. "skuPropExact": false,
  70. "sort": "CONSIGN_TIME",
  71. "sortAsc": false,
  72. "timeType": 2,
  73. "tradeStatus": 2
  74. }';
  75. $request = new Request('POST', $this->url, $this->headers, $body);
  76. $res = $client->sendAsync($request)->wait();
  77. if($res->getStatusCode() == 200) {
  78. $data = json_decode($res->getBody()->getContents(), true);
  79. $list = $data['data']['list'];
  80. if(empty($list)) {
  81. $output->writeln('无数据');
  82. return;
  83. }
  84. $queue = [];
  85. $shopList = new ShopList();
  86. $fengsuSku = new FengsuSku();
  87. $productConfig = new ProductConfig();
  88. $shopDelivery = new ShopDelivery();
  89. $customerSpec = new CustomerSpec();
  90. foreach($list as $item) {
  91. $status = FengsuService::getAdditionalPrice( $shopList, $fengsuSku, $productConfig, $shopDelivery, $customerSpec, $item);
  92. $queue[] = [
  93. 'shop_id' => $item['shopId'],
  94. 'trade_from' => $item['tradeFrom'],
  95. 'province' => $item['receiverProvince'],
  96. 'city' => $item['receiverCity'],
  97. 'company_name' => $item['tradeOrderPrintVos'][0]['companyName'],
  98. 'waybill_no' => $item['waybillNo'],
  99. 'consign_time' => $item['consignTime'],
  100. 'goods_id' => $item['tradeOrderPrintVos'][0]['goodsId'],
  101. 'sku_id' => $item['tradeOrderPrintVos'][0]['skuId'],
  102. 'num' => $item['tradeOrderPrintVos'][0]['total'],
  103. 'goods_title' => $item['tradeOrderPrintVos'][0]['goodsTitle'],
  104. 'weigh' => $item['tradeOrderPrintVos'][0]['weight'],
  105. 'price' => bcdiv((string)$item['payment'], '100', 2),
  106. 'status' => $status,
  107. ];
  108. }
  109. // 保存到数据库
  110. (new FengsuShip())->saveAll($queue);
  111. // 更新最后执行时间
  112. CrontabLog::create(['type_id' => 0,'last_time' => date('Y-m-d H:i:s')]);
  113. }
  114. // 指令输出
  115. $output->writeln('ok');
  116. }
  117. }