TaskPdd.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 TaskPdd extends Command
  27. {
  28. //拼多多请求地址
  29. protected $url = 'https://fsfxpdd.fengsutb.com/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" => "pdd",
  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. 'X-Pdd-Pagecode' => '62f9d7a661b14717564e309aebbb4d47f8988f758f91',
  51. 'X-Pdd-Pati' => 'D08NxRGxLLD5hYKZU1nqgE2b9IVrGjdv',
  52. ];
  53. // 指令配置
  54. protected function configure()
  55. {
  56. $this->setName('task:pdd')->setDescription('the task command');
  57. }
  58. //根据shop_id
  59. protected function execute(Input $input, Output $output)
  60. {
  61. $client = new Client([ 'verify' => false]);
  62. $last_time = CrontabLog::getLastRunTime(1);
  63. $body = '{
  64. "goodType": 2,
  65. "goodsFlag": 1,
  66. "current": 1,
  67. "size": 25,
  68. "startTime": "'.$last_time.'",
  69. "endTime": "'.date('Y-m-d H:i:s').'",
  70. "skuOuterIdExact": false,
  71. "skuPropExact": false,
  72. "sort": "CONSIGN_TIME",
  73. "sortAsc": false,
  74. "timeType": 2,
  75. "tradeStatus": 2
  76. }';
  77. //获取Token
  78. $this->headers['Authorization'] = site_config('addonsd.authorization_token');
  79. $request = new Request('POST', $this->url, $this->headers, $body);
  80. $res = $client->sendAsync($request)->wait();
  81. if($res->getStatusCode() == 200) {
  82. $data = json_decode($res->getBody()->getContents(), true);
  83. $list = $data['data']['list'];
  84. if(empty($list)) {
  85. $output->writeln('无数据');
  86. return;
  87. }
  88. $queue = [];
  89. $shopList = new ShopList();
  90. $fengsuSku = new FengsuSku();
  91. $productConfig = new ProductConfig();
  92. $shopDelivery = new ShopDelivery();
  93. $customerSpec = new CustomerSpec();
  94. foreach($list as $item) {
  95. $status = FengsuService::getAdditionalPrice( $shopList, $fengsuSku, $productConfig, $shopDelivery, $customerSpec, $item);
  96. $queue[] = [
  97. 'shop_id' => $item['shopId'],
  98. 'trade_from' => $item['tradeFrom'],
  99. 'province' => $item['receiverProvince'],
  100. 'city' => $item['receiverCity'],
  101. 'company_name' => $item['tradeOrderPrintVos'][0]['companyName'],
  102. 'waybill_no' => $item['waybillNo'],
  103. 'consign_time' => $item['consignTime'],
  104. 'goods_id' => $item['tradeOrderPrintVos'][0]['goodsId'],
  105. 'sku_id' => $item['tradeOrderPrintVos'][0]['skuId'],
  106. 'num' => $item['tradeOrderPrintVos'][0]['total'],
  107. 'goods_title' => $item['tradeOrderPrintVos'][0]['goodsTitle'],
  108. 'weigh' => $item['tradeOrderPrintVos'][0]['weight'],
  109. 'price' => bcdiv((string)$item['payment'], '100', 2),
  110. 'status' => $status,
  111. ];
  112. }
  113. // 保存到数据库
  114. (new FengsuShip())->saveAll($queue);
  115. // 更新最后执行时间
  116. CrontabLog::create(['type_id' => 1,'last_time' => date('Y-m-d H:i:s')]);
  117. }
  118. // 指令输出
  119. $output->writeln('ok');
  120. }
  121. }