TaskDy.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. 'Accept' => 'application/json, text/plain, */*',
  34. 'Authorization' => 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxODYwNTQ1MTExNSIsImRhdGFfcGVybWlzc2lvbiI6InByb2R1Y3RDb3N0IiwibmlrZSI6IjE4NjA1NDUxMTE1IiwiY3JlYXRlZCI6MTc2NDEyNTQwMzQ0OSwiZHBJZCI6MTAwNjczLCJleHAiOjE3NjQ3MzAyMDMsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpbInpodXlvbmdodSJdLCJkcEFjY291bnRJZCI6MTAwNjczfQ.ihv6NRfD2hzU1NQoqttTaZ-mPxqAEXIUICM8MuxVx2tVLEPW9j-uPhHoFz4T3-lH07wTt2ORf1k_SPOQP4PuQg',
  35. 'Content-Type' => 'application/json',
  36. 'platform' => 'dy',
  37. ];
  38. // 指令配置
  39. protected function configure()
  40. {
  41. $this->setName('task:dy')->setDescription('the task command');
  42. }
  43. //根据shop_id
  44. protected function execute(Input $input, Output $output)
  45. {
  46. dump($this->url);
  47. $client = new Client([ 'verify' => false]);
  48. $last_time = CrontabLog::getLastRunTime(2);
  49. $body = '{
  50. "goodType": 2,
  51. "goodsFlag": 1,
  52. "current": 1,
  53. "size": 25,
  54. "startTime": "'.$last_time.'",
  55. "endTime": "'.date('Y-m-d H:i:s').'",
  56. "skuOuterIdExact": false,
  57. "skuPropExact": false,
  58. "sort": "CONSIGN_TIME",
  59. "sortAsc": false,
  60. "timeType": 2,
  61. "tradeStatus": 2
  62. }';
  63. //获取Token
  64. $this->headers['Authorization'] = site_config('addonsd.authorization_token');
  65. dump($this->headers['Authorization']);
  66. $request = new Request('POST', $this->url, $this->headers, $body);
  67. dump($request);
  68. $res = $client->sendAsync($request)->wait();
  69. if($res->getStatusCode() == 200) {
  70. $data = json_decode($res->getBody()->getContents(), true);
  71. $list = $data['data']['list'];
  72. if(empty($list)) {
  73. $output->writeln('无数据');
  74. return;
  75. }
  76. $queue = [];
  77. $shopList = new ShopList();
  78. $fengsuSku = new FengsuSku();
  79. $productConfig = new ProductConfig();
  80. $shopDelivery = new ShopDelivery();
  81. $customerSpec = new CustomerSpec();
  82. foreach($list as $item) {
  83. $status = FengsuService::getAdditionalPrice( $shopList, $fengsuSku, $productConfig, $shopDelivery, $customerSpec, $item);
  84. $queue[] = [
  85. 'shop_id' => $item['shopId'],
  86. 'trade_from' => $item['tradeFrom'],
  87. 'province' => $item['receiverProvince'],
  88. 'city' => $item['receiverCity'],
  89. 'company_name' => $item['tradeOrderPrintVos'][0]['companyName'],
  90. 'waybill_no' => $item['waybillNo'],
  91. 'consign_time' => $item['consignTime'],
  92. 'goods_id' => $item['tradeOrderPrintVos'][0]['goodsId'],
  93. 'sku_id' => $item['tradeOrderPrintVos'][0]['skuId'],
  94. 'num' => $item['tradeOrderPrintVos'][0]['total'],
  95. 'goods_title' => $item['tradeOrderPrintVos'][0]['goodsTitle'],
  96. 'weigh' => $item['tradeOrderPrintVos'][0]['weight'],
  97. 'price' => bcdiv((string)$item['payment'], '100', 2),
  98. 'status' => $status,
  99. ];
  100. }
  101. // 保存到数据库
  102. (new FengsuShip())->saveAll($queue);
  103. // 更新最后执行时间
  104. CrontabLog::create(['type_id' => 2,'last_time' => date('Y-m-d H:i:s')]);
  105. }
  106. // 指令输出
  107. $output->writeln('ok');
  108. }
  109. }