Task.php 13 KB

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