| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- <?php
- /**
- * ----------------------------------------------------------------------------
- * 行到水穷处,坐看云起时
- * 开发软件,找贵阳云起信息科技,官网地址:https://www.56q7.com/
- * ----------------------------------------------------------------------------
- * Author: 老成
- * email:85556713@qq.com
- */
- declare(strict_types=1);
- namespace app\admin\command;
- use app\common\model\FengsuShip;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use GuzzleHttp\Client;
- use GuzzleHttp\Psr7\Request;
- class Task extends Command
- {
- // 指令配置
- protected function configure()
- {
- $this->setName('task')->setDescription('the task command');
- }
- //根据shop_id
- protected function execute(Input $input, Output $output)
- {
- $client = new Client([ 'verify' => false]);
- $body = '{
- "goodType": 2,
- "goodsFlag": 1,
- "current": 1,
- "size": 25,
- "skuOuterIdExact": false,
- "skuPropExact": false,
- "sort": "CONSIGN_TIME",
- "sortAsc": false,
- "timeType": 2,
- "tradeStatus": 2
- }';
- $request = new Request('POST', $this->getUrl('xhs'), $this->getHeaders('xhs'), $body);
- $res = $client->sendAsync($request)->wait();
- if($res->getStatusCode() == 200) {
- $data = json_decode($res->getBody()->getContents(), true);
- $list = $data['data']['list'];
- if(empty($list)) {
- $output->writeln('无数据');
- return;
- }
- $queue = [];
- foreach($list as $item) {
- $queue[] = [
- 'shop_id' => $item['shopId'],
- 'trade_from' => $item['tradeFrom'],
- 'province' => $item['receiverProvince'],
- 'city' => $item['receiverCity'],
- 'company_name' => $item['tradeOrderPrintVos'][0]['companyName'],
- 'waybill_no' => $item['waybillNo'],
- 'consign_time' => $item['consignTime'],
- 'goods_id' => $item['tradeOrderPrintVos'][0]['goodsId'],
- 'sku_id' => $item['tradeOrderPrintVos'][0]['skuId'],
- 'num' => $item['tradeOrderPrintVos'][0]['total'],
- 'goods_title' => $item['tradeOrderPrintVos'][0]['goodsTitle'],
- 'weigh' => $item['tradeOrderPrintVos'][0]['weight'],
- 'price' => bcdiv((string)$item['payment'], '100', 2)
- ];
- }
-
- // 保存到数据库
- (new FengsuShip())->saveAll($queue);
- }
- // 指令输出
- $output->writeln('ok');
- }
- //获取请求url
- protected function getUrl(string $key):string
- {
- $url = [
- 'tb' => 'https://fszntb.zhifeiyun.cn/amount/ship-list-new', //淘宝
- 'pdd' => 'https://fsfxpdd.fengsutb.com/amount/ship-list-new', //拼多多
- 'dy' => 'https://fsdy2.fengsutb.com/amount/ship-list-new', //抖音
- 'ks' => 'https://fsks.fengsutb.com/amount/ship-list-new', //快手
- 'jd' => 'https://fsjd.fengsutb.com/amount/ship-list-new', //京东
- 'xhs' => 'https://fsxpt.fengsutb.com/amount/ship-list-new', //小红书
- ];
- return $url[$key] ?? $url['tb'];
- }
- //获取头部
- protected function getHeaders(string $key):array{
- $header = [
- 'tb' =>[
- 'Accept'=> "application/json, text/plain, */*",
- 'Accept-Encoding'=> "gzip, deflate, br, zstd",
- 'Accept-Language'=> "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
- "Authorization"=> "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZmEiLCJuaWtlIjoi6Zi_5Y-R5rWL6YCfIiwiY3JlYXRlZCI6MTc1ODc5MDI4NDU3OSwiZHBJZCI6MTkxOTQwLCJleHAiOjE3NTkwNDk0ODQsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpbInpodXlvbmdodSJdLCJkcEFjY291bnRJZCI6MTc4MzU3fQ.TuHvPz7Jf0vuYsbrxX9VpyZ2oOrtZ0YzLQJafoX_RV8up1PmtPLfPATBE93_v_1Ig39nODadaTb4aePy3b0hsA",
- "Cache-Control"=> "no-cache",
- "Content-Type"=> "application/json",
- "Origin"=> "https://fx.fengsutb.com",
- "platform" => "tb",
- "Pragma"=> "no-cache",
- "priority" => "u=1, i",
- "Referer"=> "https://fx.fengsutb.com/",
- "Sec-ch-ua" => '"Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"',
- "Sec-ch-ua-Mobile"=> "?0",
- "Sec-ch-ua-platform"=> "Windows",
- "Sec-Fetch-Dest" => "empty",
- "Sec-Fetch-Mode" => "cors",
- "Sec-Fetch-Site" => "same-site",
- "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"
- ],
- 'pdd' =>[
- 'Accept'=> "application/json, text/plain, */*",
- 'Accept-Encoding'=> "gzip, deflate, br, zstd",
- 'Accept-Language'=> "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
- "Authorization"=> "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZmEiLCJuaWtlIjoi6Zi_5Y-R5rWL6YCfIiwiY3JlYXRlZCI6MTc1ODc5MDI4NDU3OSwiZHBJZCI6MTkxOTQwLCJleHAiOjE3NTkwNDk0ODQsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpbInpodXlvbmdodSJdLCJkcEFjY291bnRJZCI6MTc4MzU3fQ.TuHvPz7Jf0vuYsbrxX9VpyZ2oOrtZ0YzLQJafoX_RV8up1PmtPLfPATBE93_v_1Ig39nODadaTb4aePy3b0hsA",
- "Cache-Control"=> "no-cache",
- "Content-Type"=> "application/json",
- "Origin"=> "https://fx.fengsutb.com",
- "platform" => "pdd",
- "Pragma"=> "no-cache",
- "priority" => "u=1, i",
- "Referer"=> "https://fx.fengsutb.com/",
- "Sec-ch-ua" => '"Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"',
- "Sec-ch-ua-Mobile"=> "?0",
- "Sec-ch-ua-platform"=> "Windows",
- "Sec-Fetch-Dest" => "empty",
- "Sec-Fetch-Mode" => "cors",
- "Sec-Fetch-Site" => "same-site",
- "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",
- 'X-Pdd-Pagecode' => '62f9d7a661b14717564e309aebbb4d47f8988f758f91',
- 'X-Pdd-Pati' => 'D08NxRGxLLD5hYKZU1nqgE2b9IVrGjdv',
- ],
- 'dy'=> [
- 'Host' => 'fsdy2.fengsutb.com',
- 'Connection' => 'keep-alive',
- 'sec-ch-ua-platform' => 'Windows',
- 'Authorization' => 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZmEiLCJuaWtlIjoi6Zi_5Y-R5rWL6YCfIiwiY3JlYXRlZCI6MTc1ODcwMzg4MzMyMSwiZHBJZCI6MTkxOTQwLCJleHAiOjE3NTg5NjMwODMsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpbInpodXlvbmdodSJdLCJkcEFjY291bnRJZCI6MTc4MzU3fQ.ZXaztcUDDlZDgepOqFwaQfzd4RcINNiIv54or0r-b7DJw9aKw7zjH8RmUIE7yqTcyQ_g6r7aGdpn9hf-hIukBg',
- 'sec-ch-ua' => '"Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"',
- 'sec-ch-ua-mobile' => '?0',
- 'doudian-event-id' => '1757940551000163',
- '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',
- 'Accept' => 'application/json, text/plain, */*',
- 'platform' => 'tb',
- 'Origin' => 'https://fx.fengsutb.com',
- 'Sec-Fetch-Site' => 'same-site',
- 'Sec-Fetch-Mode' => 'cors',
- 'Sec-Fetch-Dest' => 'empty',
- 'Referer' => 'https://fx.fengsutb.com/',
- 'Accept-Language' => 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
- 'Content-Type' => 'application/json',
- ],
- 'ks'=> [
- 'Accept'=> "application/json, text/plain, */*",
- 'Accept-Encoding'=> "gzip, deflate, br, zstd",
- 'Accept-Language'=> "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
- "Authorization"=> "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZmEiLCJuaWtlIjoi6Zi_5Y-R5rWL6YCfIiwiY3JlYXRlZCI6MTc1ODc5MDI4NDU3OSwiZHBJZCI6MTkxOTQwLCJleHAiOjE3NTkwNDk0ODQsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpbInpodXlvbmdodSJdLCJkcEFjY291bnRJZCI6MTc4MzU3fQ.TuHvPz7Jf0vuYsbrxX9VpyZ2oOrtZ0YzLQJafoX_RV8up1PmtPLfPATBE93_v_1Ig39nODadaTb4aePy3b0hsA",
- "Cache-Control"=> "no-cache",
- 'Connection' => 'keep-alive',
- "Content-Type"=> "application/json",
- "Host" => "fsks.fengsutb.com",
- "Origin" => "https://fx.fengsutb.com",
- "platform" => "ks",
- "Pragma"=> "no-cache",
- "Referer"=> "https://fx.fengsutb.com/",
- "Sec-ch-ua" => '"Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"',
- "Sec-ch-ua-Mobile"=> "?0",
- "Sec-ch-ua-platform"=> "Windows",
- "Sec-Fetch-Dest" => "empty",
- "Sec-Fetch-Mode" => "cors",
- "Sec-Fetch-Site" => "same-site",
- "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"
- ],
- 'jd' => [
- 'Accept'=> "application/json, text/plain, */*",
- 'Accept-Encoding'=> "gzip, deflate, br, zstd",
- 'Accept-Language'=> "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
- "Authorization"=> "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZmEiLCJuaWtlIjoi6Zi_5Y-R5rWL6YCfIiwiY3JlYXRlZCI6MTc1ODc5MDI4NDU3OSwiZHBJZCI6MTkxOTQwLCJleHAiOjE3NTkwNDk0ODQsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpbInpodXlvbmdodSJdLCJkcEFjY291bnRJZCI6MTc4MzU3fQ.TuHvPz7Jf0vuYsbrxX9VpyZ2oOrtZ0YzLQJafoX_RV8up1PmtPLfPATBE93_v_1Ig39nODadaTb4aePy3b0hsA",
- "Cache-Control"=> "no-cache",
- 'Connection' => 'keep-alive',
- "Content-Type"=> "application/json",
- "Host" => "fsjd.fengsutb.com",
- "Origin" => "https://fx.fengsutb.com",
- "platform" => "jd",
- "Pragma"=> "no-cache",
- "Referer"=> "https://fx.fengsutb.com/",
- "Sec-ch-ua" => '"Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"',
- "Sec-ch-ua-Mobile"=> "?0",
- "Sec-ch-ua-platform"=> "Windows",
- "Sec-Fetch-Dest" => "empty",
- "Sec-Fetch-Mode" => "cors",
- "Sec-Fetch-Site" => "same-site",
- "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"
- ],
- 'xhs' => [
- 'Accept'=> "application/json, text/plain, */*",
- 'Accept-Encoding'=> "gzip, deflate, br, zstd",
- 'Accept-Language'=> "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
- "Authorization"=> "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZmEiLCJuaWtlIjoi6Zi_5Y-R5rWL6YCfIiwiY3JlYXRlZCI6MTc1ODc5MDI4NDU3OSwiZHBJZCI6MTkxOTQwLCJleHAiOjE3NTkwNDk0ODQsImVuYWJsZWQiOnRydWUsImF1dGhvcml0aWVzIjpbInpodXlvbmdodSJdLCJkcEFjY291bnRJZCI6MTc4MzU3fQ.TuHvPz7Jf0vuYsbrxX9VpyZ2oOrtZ0YzLQJafoX_RV8up1PmtPLfPATBE93_v_1Ig39nODadaTb4aePy3b0hsA",
- "Cache-Control"=> "no-cache",
- 'Connection' => 'keep-alive',
- "Content-Type"=> "application/json",
- "Host" => "fsxpt.fengsutb.com",
- "Origin" => "https://fx.fengsutb.com",
- "platform" => "xhs",
- "Pragma" => "no-cache",
- "Referer" => "https://fx.fengsutb.com/",
- "Sec-ch-ua" => '"Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"',
- "Sec-ch-ua-Mobile"=> "?0",
- "Sec-ch-ua-platform"=> "Windows",
- "Sec-Fetch-Dest" => "empty",
- "Sec-Fetch-Mode" => "cors",
- "Sec-Fetch-Site" => "same-site",
- "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"
- ]
- ];
- return $header[$key] ?? [];
- }
- /**
- * 获取偏远地区加收费用
- * @param string $express 快递公司名称
- * @param string $area 省份
- * @param float $weight 重量
- * @param string $city 城市
- * @return float
- */
- protected function getRemoteAreaFee(string $express, float $weight, string $area, string $city = ''){
- $remote_area = config('app.remote_area_fee');
- $fee = 0;
- if($express == '顺丰快递'){
- if(in_array($area, $remote_area[0])) {
- if($weight >= 3.5) $fee = 5;
- if($weight >= 4.5) $fee = 6;
- };
- }else{
- //普通(广东省-深圳) -浙江-舟山
- if(in_array($area, $remote_area[0])) $fee = 1.5;
- if($area == '广东省' && $city == '深圳市') $fee = 1.5;
- if($area == '浙江省' && $city == '舟山市') $fee = 1.5;
- }
- return $fee;
- }
- }
|