TaskDy.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 TaskDy extends Command
  27. {
  28. //抖音请求地址
  29. protected $url = 'https://fsdy2.fengsutb.com/amount/ship-list-new';
  30. //抖音请求头部
  31. protected $headers = [
  32. 'Host' => 'fsdy2.fengsutb.com',
  33. 'Connection' => 'keep-alive',
  34. 'sec-ch-ua-platform' => 'Windows',
  35. 'Authorization' => 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZmEiLCJuaWtlIjoi6Zi_5Y-R5rWL6YCfIiwiY3JlYXRlZCI6MTc1ODk2NjM3NjU5MywiZHBJZCI6MTkxOTQwLCJleHAiOjE3NTkyMjU1NzYsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpbInpodXlvbmdodSJdLCJkcEFjY291bnRJZCI6MTc4MzU3fQ.S37D56hG2SwttUYy7OBFet-GOeG5wW6U7j1d2NF7UoFzHWlSpSA4IjwZU1d9Z33xD44Zyiib4zGa_QRxCO2imw',
  36. 'sec-ch-ua' => '"Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"',
  37. 'sec-ch-ua-mobile' => '?0',
  38. 'doudian-event-id' => '1757940551000163',
  39. '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',
  40. 'Accept' => 'application/json, text/plain, */*',
  41. 'platform' => 'dy',
  42. 'Origin' => 'https://fx.fengsutb.com',
  43. 'Sec-Fetch-Site' => 'same-site',
  44. 'Sec-Fetch-Mode' => 'cors',
  45. 'Sec-Fetch-Dest' => 'empty',
  46. 'Referer' => 'https://fx.fengsutb.com/',
  47. 'Accept-Language' => 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
  48. 'Content-Type' => 'application/json',
  49. ];
  50. // 指令配置
  51. protected function configure()
  52. {
  53. $this->setName('task:dy')->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(2);
  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. //获取Token
  75. $this->headers['Authorization'] = site_config('addonsd.authorization_token');
  76. $request = new Request('POST', $this->url, $this->headers, $body);
  77. $res = $client->sendAsync($request)->wait();
  78. if($res->getStatusCode() == 200) {
  79. $data = json_decode($res->getBody()->getContents(), true);
  80. $list = $data['data']['list'];
  81. if(empty($list)) {
  82. $output->writeln('无数据');
  83. return;
  84. }
  85. $queue = [];
  86. $shopList = new ShopList();
  87. $fengsuSku = new FengsuSku();
  88. $productConfig = new ProductConfig();
  89. $shopDelivery = new ShopDelivery();
  90. $customerSpec = new CustomerSpec();
  91. foreach($list as $item) {
  92. $status = FengsuService::getAdditionalPrice( $shopList, $fengsuSku, $productConfig, $shopDelivery, $customerSpec, $item);
  93. $queue[] = [
  94. 'shop_id' => $item['shopId'],
  95. 'trade_from' => $item['tradeFrom'],
  96. 'province' => $item['receiverProvince'],
  97. 'city' => $item['receiverCity'],
  98. 'company_name' => $item['tradeOrderPrintVos'][0]['companyName'],
  99. 'waybill_no' => $item['waybillNo'],
  100. 'consign_time' => $item['consignTime'],
  101. 'goods_id' => $item['tradeOrderPrintVos'][0]['goodsId'],
  102. 'sku_id' => $item['tradeOrderPrintVos'][0]['skuId'],
  103. 'num' => $item['tradeOrderPrintVos'][0]['total'],
  104. 'goods_title' => $item['tradeOrderPrintVos'][0]['goodsTitle'],
  105. 'weigh' => $item['tradeOrderPrintVos'][0]['weight'],
  106. 'price' => bcdiv((string)$item['payment'], '100', 2),
  107. 'status' => $status,
  108. ];
  109. }
  110. // 保存到数据库
  111. (new FengsuShip())->saveAll($queue);
  112. // 更新最后执行时间
  113. CrontabLog::create(['type_id' => 2,'last_time' => date('Y-m-d H:i:s')]);
  114. }
  115. // 指令输出
  116. $output->writeln('ok');
  117. }
  118. }