JuShuiTan.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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\JuShuiTanService;
  24. use GuzzleHttp\Psr7\Request;
  25. use app\common\model\ImportList;
  26. //抖音
  27. class JuShuiTan extends Command
  28. {
  29. //抖音请求地址
  30. protected $url = 'https://innerapi.scm121.com/api/inner/supOrder/getErpNormalOrders';
  31. //抖音请求头部
  32. protected $headers = [
  33. //'Host' => 'fsdy2.fengsutb.com',
  34. 'Accept' => 'application/json, text/plain, */*',
  35. 'Authorization' => 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiIyMTk0MzA5MSIsInJvbGVJZHMiOltdLCJ1c2VyX25hbWUiOiIxODE4MjY2OTkzNSIsImNvSWQiOiIxNDc5MjIyMiIsImV4cGlyYXRpb24iOjE3NjYyMTg0NDM1MzQsInVzZXIiOnsiY29JZCI6IjE0NzkyMjIyIiwiY29OYW1lIjoi5LqR5Y2X5LmQ55Wq55Sw5L6b5bqU6ZO-5pyJ6ZmQ5YWs5Y-4IiwibG9naW5OYW1lIjoiMTgxODI2Njk5MzUiLCJsb2dpbldheSI6IlVTRVJOQU1FIiwibmlja05hbWUiOiLmnY4iLCJyb2xlSWRzIjoiMTEsMTIsMTMsMTQsMTUsMTYsMTcsMTgsMjIsMjMsMjcsMjgsMjksMzAsMzEsMzIsMzMsMzQsMzUsMzYsMzksNDAsNDEsNTIsNTMsNTQsNjEsNjIsNjMsNjQsNjUsNjYsNjcsNzAsNzEsNzIsNzMsNzYsOTAsMTAxLDEwMiwxMDMsMTA0LDEwNSwxMDYsMTA3LDEwOCwxMDkiLCJ1aWQiOiIyMTk0MzA5MSJ9LCJhdXRob3JpdGllcyI6WyJKU1QtY2hhbm5lbCIsIm11bHRpTG9naW4iLCJKU1Qtc3VwcGxpZXIiXSwiY2xpZW50X2lkIjoicGMiLCJqdGkiOiIxYjNhZjA4OC04ZDhiLTRhNzMtYjcwNC1lYzhhY2QwNzU1ODUiLCJleHAiOjE3NjYyMTg0NDN9.fXIP-yUlJDIfd49QgxjTQXUlRka2gpw0NrfY7lB50sU',
  36. 'Content-Type' => 'application/json',
  37. // 'platform' => 'dy',
  38. ];
  39. // 打单平台 1:风速 2:聚水潭
  40. protected $type_id=2;
  41. // 指令配置
  42. protected function configure()
  43. {
  44. $this->setName('ju_shui_tan')->setDescription('the task command');
  45. }
  46. //根据shop_id
  47. protected function execute(Input $input, Output $output)
  48. {
  49. $output->writeln('开始同步聚水潭订单');
  50. $resquet = $this->getOrderList('dy');
  51. if($resquet['success']){
  52. if(count($resquet['data']) > 0){
  53. $list = $resquet['data'];
  54. // dump($list);
  55. // return;
  56. $this->insertOrder($list);
  57. //dump($resquet);
  58. }else{
  59. $output->writeln('没有数据');
  60. }
  61. }else{
  62. $output->writeln('接口错误: ' .$resquet['message']);
  63. }
  64. $output->writeln('ok');
  65. }
  66. public function getOrderList($platform = 'dy')
  67. {
  68. $client = new \GuzzleHttp\Client([
  69. 'verify' => false,
  70. // 或指定证书路径
  71. // 'verify' => '/path/to/cacert.pem'
  72. ]);
  73. $headers = [
  74. 'Accept' => ' application/json, text/plain, */*',
  75. 'Authorization' =>site_config('addonsd.ju_shui_tan_authorization_toke'),
  76. 'Content-Type' => ' application/json'
  77. ];
  78. $todayTime=date("Y-m-d");
  79. $startTime = strtotime($todayTime . ' 00:00:00');
  80. $startTime=date('Y-m-d H:i:s', $startTime);
  81. // $startTime='2025-01-01 08:59:21';
  82. $endTime = strtotime($todayTime . ' 23:59:59');
  83. $endTime=date('Y-m-d H:i:s', $endTime);
  84. $body = '{
  85. "startTime": "'.$startTime.'",
  86. "endTime": "'.$endTime.'",
  87. "dateQueryType": "DeliveryDate",
  88. "coId": "14792222",
  89. "uid": "21943091",
  90. "upSendFailed": false,
  91. "isExceptAddress": "Except",
  92. "pageNum": 1,
  93. "pageSize": 50,
  94. "searchType": 1,
  95. "orderStatus": [
  96. "Sent"
  97. ]
  98. }';
  99. // "orderFrom":"PINDUODUO"
  100. //"trackNo":"@SF3278427215674"
  101. $request = new Request('POST', 'https://innerapi.scm121.com/api/inner/supOrder/getErpNormalOrders', $headers, $body);
  102. $res = $client->sendAsync($request)->wait();
  103. $json = [];
  104. if($res->getStatusCode() == 200) {
  105. $json = json_decode($res->getBody()->getContents(), true);
  106. }else{
  107. dump($res->getStatusCode(), '接口返回结果');
  108. }
  109. return $json;
  110. }
  111. public function insertOrder($order_list)
  112. {
  113. if(!(count($order_list) > 0)){
  114. return false;
  115. }
  116. $queue = [];
  117. $shopList = new ShopList();
  118. $fengsuSku = new FengsuSku();
  119. $productConfig = new ProductConfig();
  120. $shopDelivery = new ShopDelivery();
  121. $customerSpec = new CustomerSpec();
  122. usort($order_list, function($a, $b) {
  123. // 将create_time转换为时间戳比较(支持字符串时间戳)
  124. $timeA = strtotime($a['deliveryDate']);
  125. $timeB = strtotime($b['deliveryDate']);
  126. // 降序排序(从新到旧)
  127. // return $timeB - $timeA;
  128. // 升序排序(从旧到新)可改为:
  129. return $timeA - $timeB;
  130. });
  131. foreach($order_list as $item) {
  132. // dump($item['shopId'], '店铺id');
  133. // 防止重复记录,订单号+快递单号
  134. $goods_id=$item['disInnerOrderGoodsViewList'][0]['shopIid'];
  135. $oid=$item['oid'];
  136. $waybill_no=ltrim($item['trackNo'], '@');
  137. $add_status = JuShuiTanService::prevent_duplicate_additions($oid,$waybill_no);
  138. if($add_status) continue;
  139. $status = JuShuiTanService::getAdditionalPrice( $shopList, $fengsuSku, $productConfig, $shopDelivery, $customerSpec, $item);
  140. $queue[] = [
  141. 'type_id' => $this->type_id,
  142. 'shop_id' => $item['shopId'],
  143. 'order_id' => $oid,
  144. 'trade_from' => $item['orderFrom'],
  145. 'province' => $item['receiverState'],
  146. 'city' => $item['receiverCity'],
  147. 'company_name' => $item['expressCompany'],
  148. 'waybill_no' => $waybill_no,
  149. 'consign_time' => $item['deliveryDate'],
  150. 'goods_id' => $goods_id,
  151. 'sku_id' => $item['disInnerOrderGoodsViewList'][0]['shopSkuId'],
  152. 'num' => $item['disInnerOrderGoodsViewList'][0]['itemCount'],
  153. 'goods_title' => $item['disInnerOrderGoodsViewList'][0]['itemName'],
  154. 'goods_info' => $item['disInnerOrderGoodsViewList'][0]['properties'],
  155. 'weigh' => $item['weight'],
  156. 'price' => bcdiv((string)$item['disInnerOrderGoodsViewList'][0]['price'], '1', 2),
  157. 'status' => $status,
  158. ];
  159. }
  160. // 保存到数据库
  161. (new ImportList())->saveAll($queue);
  162. // 更新最后执行时间
  163. CrontabLog::create(['type_id' => 2,'last_time' => date('Y-m-d H:i:s')]);
  164. }
  165. }