TaskXhs.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 TaskXhs extends Command
  27. {
  28. // 指令配置
  29. protected function configure()
  30. {
  31. $this->setName('task:xhs')->setDescription('the task command');
  32. }
  33. //根据shop_id
  34. protected function execute(Input $input, Output $output)
  35. {
  36. $client = new Client([ 'verify' => false]);
  37. $last_time = CrontabLog::getLastRunTime(0);
  38. $body = '{
  39. "goodType": 2,
  40. "goodsFlag": 1,
  41. "current": 1,
  42. "size": 25,
  43. "startTime": "'.$last_time.'",
  44. "endTime": "'.date('Y-m-d H:i:s').'",
  45. "skuOuterIdExact": false,
  46. "skuPropExact": false,
  47. "sort": "CONSIGN_TIME",
  48. "sortAsc": false,
  49. "timeType": 2,
  50. "tradeStatus": 2
  51. }';
  52. $request = new Request('POST', $this->getUrl('dy'), $this->getHeaders('dy'), $body);
  53. $res = $client->sendAsync($request)->wait();
  54. if($res->getStatusCode() == 200) {
  55. $data = json_decode($res->getBody()->getContents(), true);
  56. $list = $data['data']['list'];
  57. if(empty($list)) {
  58. $output->writeln('无数据');
  59. return;
  60. }
  61. $queue = [];
  62. $shopList = new ShopList();
  63. $fengsuSku = new FengsuSku();
  64. $productConfig = new ProductConfig();
  65. $shopDelivery = new ShopDelivery();
  66. $customerSpec = new CustomerSpec();
  67. foreach($list as $item) {
  68. $status = FengsuService::getAdditionalPrice( $shopList, $fengsuSku, $productConfig, $shopDelivery, $customerSpec, $item);
  69. $queue[] = [
  70. 'shop_id' => $item['shopId'],
  71. 'trade_from' => $item['tradeFrom'],
  72. 'province' => $item['receiverProvince'],
  73. 'city' => $item['receiverCity'],
  74. 'company_name' => $item['tradeOrderPrintVos'][0]['companyName'],
  75. 'waybill_no' => $item['waybillNo'],
  76. 'consign_time' => $item['consignTime'],
  77. 'goods_id' => $item['tradeOrderPrintVos'][0]['goodsId'],
  78. 'sku_id' => $item['tradeOrderPrintVos'][0]['skuId'],
  79. 'num' => $item['tradeOrderPrintVos'][0]['total'],
  80. 'goods_title' => $item['tradeOrderPrintVos'][0]['goodsTitle'],
  81. 'weigh' => $item['tradeOrderPrintVos'][0]['weight'],
  82. 'price' => bcdiv((string)$item['payment'], '100', 2),
  83. 'status' => $status,
  84. ];
  85. }
  86. // 保存到数据库
  87. (new FengsuShip())->saveAll($queue);
  88. // 更新最后执行时间
  89. CrontabLog::create([
  90. 'type_id' => 0,
  91. 'last_time' => date('Y-m-d H:i:s'),
  92. ]);
  93. }
  94. // 指令输出
  95. $output->writeln('ok');
  96. }
  97. //获取请求url
  98. protected function getUrl(string $key):string
  99. {
  100. $url = [
  101. 'tb' => 'https://fszntb.zhifeiyun.cn/amount/ship-list-new', //淘宝
  102. 'pdd' => 'https://fsfxpdd.fengsutb.com/amount/ship-list-new', //拼多多
  103. 'dy' => 'https://fsdy2.fengsutb.com/amount/ship-list-new', //抖音
  104. 'ks' => 'https://fsks.fengsutb.com/amount/ship-list-new', //快手
  105. 'jd' => 'https://fsjd.fengsutb.com/amount/ship-list-new', //京东
  106. 'xhs' => 'https://fsxpt.fengsutb.com/amount/ship-list-new', //小红书
  107. ];
  108. return $url[$key] ?? $url['tb'];
  109. }
  110. //获取头部
  111. protected function getHeaders(string $key):array{
  112. $header = [
  113. 'tb' =>[
  114. 'Accept'=> "application/json, text/plain, */*",
  115. 'Accept-Encoding'=> "gzip, deflate, br, zstd",
  116. 'Accept-Language'=> "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
  117. "Authorization"=> "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZmEiLCJuaWtlIjoi6Zi_5Y-R5rWL6YCfIiwiY3JlYXRlZCI6MTc1ODc5MDI4NDU3OSwiZHBJZCI6MTkxOTQwLCJleHAiOjE3NTkwNDk0ODQsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpbInpodXlvbmdodSJdLCJkcEFjY291bnRJZCI6MTc4MzU3fQ.TuHvPz7Jf0vuYsbrxX9VpyZ2oOrtZ0YzLQJafoX_RV8up1PmtPLfPATBE93_v_1Ig39nODadaTb4aePy3b0hsA",
  118. "Cache-Control"=> "no-cache",
  119. "Content-Type"=> "application/json",
  120. "Origin"=> "https://fx.fengsutb.com",
  121. "platform" => "tb",
  122. "Pragma"=> "no-cache",
  123. "priority" => "u=1, i",
  124. "Referer"=> "https://fx.fengsutb.com/",
  125. "Sec-ch-ua" => '"Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"',
  126. "Sec-ch-ua-Mobile"=> "?0",
  127. "Sec-ch-ua-platform"=> "Windows",
  128. "Sec-Fetch-Dest" => "empty",
  129. "Sec-Fetch-Mode" => "cors",
  130. "Sec-Fetch-Site" => "same-site",
  131. "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"
  132. ],
  133. 'pdd' =>[
  134. 'Accept'=> "application/json, text/plain, */*",
  135. 'Accept-Encoding'=> "gzip, deflate, br, zstd",
  136. 'Accept-Language'=> "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
  137. "Authorization"=> "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZmEiLCJuaWtlIjoi6Zi_5Y-R5rWL6YCfIiwiY3JlYXRlZCI6MTc1ODc5MDI4NDU3OSwiZHBJZCI6MTkxOTQwLCJleHAiOjE3NTkwNDk0ODQsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpbInpodXlvbmdodSJdLCJkcEFjY291bnRJZCI6MTc4MzU3fQ.TuHvPz7Jf0vuYsbrxX9VpyZ2oOrtZ0YzLQJafoX_RV8up1PmtPLfPATBE93_v_1Ig39nODadaTb4aePy3b0hsA",
  138. "Cache-Control"=> "no-cache",
  139. "Content-Type"=> "application/json",
  140. "Origin"=> "https://fx.fengsutb.com",
  141. "platform" => "pdd",
  142. "Pragma"=> "no-cache",
  143. "priority" => "u=1, i",
  144. "Referer"=> "https://fx.fengsutb.com/",
  145. "Sec-ch-ua" => '"Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"',
  146. "Sec-ch-ua-Mobile"=> "?0",
  147. "Sec-ch-ua-platform"=> "Windows",
  148. "Sec-Fetch-Dest" => "empty",
  149. "Sec-Fetch-Mode" => "cors",
  150. "Sec-Fetch-Site" => "same-site",
  151. "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",
  152. 'X-Pdd-Pagecode' => '62f9d7a661b14717564e309aebbb4d47f8988f758f91',
  153. 'X-Pdd-Pati' => 'D08NxRGxLLD5hYKZU1nqgE2b9IVrGjdv',
  154. ],
  155. 'dy'=> [
  156. 'Host' => 'fsdy2.fengsutb.com',
  157. 'Connection' => 'keep-alive',
  158. 'sec-ch-ua-platform' => 'Windows',
  159. 'Authorization' => 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZmEiLCJuaWtlIjoi6Zi_5Y-R5rWL6YCfIiwiY3JlYXRlZCI6MTc1ODcwMzg4MzMyMSwiZHBJZCI6MTkxOTQwLCJleHAiOjE3NTg5NjMwODMsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpbInpodXlvbmdodSJdLCJkcEFjY291bnRJZCI6MTc4MzU3fQ.ZXaztcUDDlZDgepOqFwaQfzd4RcINNiIv54or0r-b7DJw9aKw7zjH8RmUIE7yqTcyQ_g6r7aGdpn9hf-hIukBg',
  160. 'sec-ch-ua' => '"Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"',
  161. 'sec-ch-ua-mobile' => '?0',
  162. 'doudian-event-id' => '1757940551000163',
  163. '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',
  164. 'Accept' => 'application/json, text/plain, */*',
  165. 'platform' => 'dy',
  166. 'Origin' => 'https://fx.fengsutb.com',
  167. 'Sec-Fetch-Site' => 'same-site',
  168. 'Sec-Fetch-Mode' => 'cors',
  169. 'Sec-Fetch-Dest' => 'empty',
  170. 'Referer' => 'https://fx.fengsutb.com/',
  171. 'Accept-Language' => 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
  172. 'Content-Type' => 'application/json',
  173. ],
  174. 'ks'=> [
  175. 'Accept'=> "application/json, text/plain, */*",
  176. 'Accept-Encoding'=> "gzip, deflate, br, zstd",
  177. 'Accept-Language'=> "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
  178. "Authorization"=> "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZmEiLCJuaWtlIjoi6Zi_5Y-R5rWL6YCfIiwiY3JlYXRlZCI6MTc1ODc5MDI4NDU3OSwiZHBJZCI6MTkxOTQwLCJleHAiOjE3NTkwNDk0ODQsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpbInpodXlvbmdodSJdLCJkcEFjY291bnRJZCI6MTc4MzU3fQ.TuHvPz7Jf0vuYsbrxX9VpyZ2oOrtZ0YzLQJafoX_RV8up1PmtPLfPATBE93_v_1Ig39nODadaTb4aePy3b0hsA",
  179. "Cache-Control"=> "no-cache",
  180. 'Connection' => 'keep-alive',
  181. "Content-Type"=> "application/json",
  182. "Host" => "fsks.fengsutb.com",
  183. "Origin" => "https://fx.fengsutb.com",
  184. "platform" => "ks",
  185. "Pragma"=> "no-cache",
  186. "Referer"=> "https://fx.fengsutb.com/",
  187. "Sec-ch-ua" => '"Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"',
  188. "Sec-ch-ua-Mobile"=> "?0",
  189. "Sec-ch-ua-platform"=> "Windows",
  190. "Sec-Fetch-Dest" => "empty",
  191. "Sec-Fetch-Mode" => "cors",
  192. "Sec-Fetch-Site" => "same-site",
  193. "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"
  194. ],
  195. 'jd' => [
  196. 'Accept'=> "application/json, text/plain, */*",
  197. 'Accept-Encoding'=> "gzip, deflate, br, zstd",
  198. 'Accept-Language'=> "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
  199. "Authorization"=> "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZmEiLCJuaWtlIjoi6Zi_5Y-R5rWL6YCfIiwiY3JlYXRlZCI6MTc1ODc5MDI4NDU3OSwiZHBJZCI6MTkxOTQwLCJleHAiOjE3NTkwNDk0ODQsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpbInpodXlvbmdodSJdLCJkcEFjY291bnRJZCI6MTc4MzU3fQ.TuHvPz7Jf0vuYsbrxX9VpyZ2oOrtZ0YzLQJafoX_RV8up1PmtPLfPATBE93_v_1Ig39nODadaTb4aePy3b0hsA",
  200. "Cache-Control"=> "no-cache",
  201. 'Connection' => 'keep-alive',
  202. "Content-Type"=> "application/json",
  203. "Host" => "fsjd.fengsutb.com",
  204. "Origin" => "https://fx.fengsutb.com",
  205. "platform" => "jd",
  206. "Pragma"=> "no-cache",
  207. "Referer"=> "https://fx.fengsutb.com/",
  208. "Sec-ch-ua" => '"Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"',
  209. "Sec-ch-ua-Mobile"=> "?0",
  210. "Sec-ch-ua-platform"=> "Windows",
  211. "Sec-Fetch-Dest" => "empty",
  212. "Sec-Fetch-Mode" => "cors",
  213. "Sec-Fetch-Site" => "same-site",
  214. "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"
  215. ],
  216. 'xhs' => [
  217. 'Accept'=> "application/json, text/plain, */*",
  218. 'Accept-Encoding'=> "gzip, deflate, br, zstd",
  219. 'Accept-Language'=> "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
  220. "Authorization"=> "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZmEiLCJuaWtlIjoi6Zi_5Y-R5rWL6YCfIiwiY3JlYXRlZCI6MTc1ODc5MDI4NDU3OSwiZHBJZCI6MTkxOTQwLCJleHAiOjE3NTkwNDk0ODQsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpbInpodXlvbmdodSJdLCJkcEFjY291bnRJZCI6MTc4MzU3fQ.TuHvPz7Jf0vuYsbrxX9VpyZ2oOrtZ0YzLQJafoX_RV8up1PmtPLfPATBE93_v_1Ig39nODadaTb4aePy3b0hsA",
  221. "Cache-Control"=> "no-cache",
  222. 'Connection' => 'keep-alive',
  223. "Content-Type"=> "application/json",
  224. "Host" => "fsxpt.fengsutb.com",
  225. "Origin" => "https://fx.fengsutb.com",
  226. "platform" => "xhs",
  227. "Pragma" => "no-cache",
  228. "Referer" => "https://fx.fengsutb.com/",
  229. "Sec-ch-ua" => '"Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"',
  230. "Sec-ch-ua-Mobile"=> "?0",
  231. "Sec-ch-ua-platform"=> "Windows",
  232. "Sec-Fetch-Dest" => "empty",
  233. "Sec-Fetch-Mode" => "cors",
  234. "Sec-Fetch-Site" => "same-site",
  235. "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"
  236. ]
  237. ];
  238. return $header[$key] ?? [];
  239. }
  240. }