| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- <?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 app\common\model\CrontabLog;
- use app\common\model\ImportSku;
- use app\common\model\ShopList;
- use app\common\model\ProductConfig;
- use app\common\model\ShopDelivery;
- use app\common\model\CustomerSpec;
- use app\admin\service\FengsuService;
- use GuzzleHttp\Psr7\Request;
- use app\common\model\ImportList;
- use app\admin\service\JuShuiTanService;
- use think\facade\Cache;
- use app\common\controller\Http;
- use app\admin\command\FengSu;
- //拼多多
- class TaskPdd extends Command
- {
- //拼多多请求地址
- protected $url = 'https://fsfxpdd.fengsutb.com/amount/ship-list-new';
- //拼多多请求头部
- protected $headers = [
- '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',
- ];
- protected $platform='pdd';
- // 打单平台 1:风速 2:聚水潭
- protected $type_id = 1;
- //时间间隔
- protected $start_end_space_time = 10 * 60;
- //下一次时间间隔
- protected $next_time_space = 7 * 60;
- protected $fengSu_command=null;
- // 指令配置
- protected function configure()
- {
-
- $this->setName('task_'.$this->platform)->setDescription('the task command');
- }
- //根据shop_id
- protected function execute(Input $input, Output $output)
- {
- $output->writeln('开始同步订单');
- $this->fengSu_command=new FengSu();
- $resquet = $this->getOrderList('');
- if ($resquet['code'] == 0) {
- $fengsu = [];
- $fengsu = Cache::get('fengsu_'.$this->platform);
- if ($resquet['data']['list'] != null && !empty($resquet['data']['list'])) {
- $fengsu_pageNum = $fengsu['pageNum'];
- $fengsu_pageNum = $fengsu_pageNum + 1;
- $fengsu = [
- 'startTime' => $fengsu['startTime'],
- 'endTime' => $fengsu['endTime'],
- 'pageNum' => $fengsu_pageNum,
- 'next_time_space' => $fengsu['next_time_space']
- ];
- Cache::set('fengsu_'.$this->platform, $fengsu);
- $list = $resquet['data']['list'];
- // dump($list);
- // return;
- $this->fengSu_command->insertOrder($list);
- //dump($resquet);
- } else {
- $now_time = time();
- if ($fengsu['startTime'] >= $now_time || ($now_time - $fengsu['startTime']) < ($this->next_time_space)) {
- // dump("超时了");
- $pre_time_stamp = $this->next_time_space;
- $startTime_stamp = $now_time - $pre_time_stamp;
- $endTime_stamp = $startTime_stamp + $this->start_end_space_time;
- $fengsu = [
- 'startTime' => $startTime_stamp,
- 'endTime' => $endTime_stamp,
- 'pageNum' => 1,
- 'next_time_space' => $fengsu['next_time_space']
- ];
- } else {
- $fengsu = [
- 'startTime' => $fengsu['startTime'] + $fengsu['next_time_space'],
- 'endTime' => $fengsu['endTime'] + $fengsu['next_time_space'],
- 'pageNum' => 1,
- 'next_time_space' => $fengsu['next_time_space']
- ];
- }
- Cache::set('fengsu_'.$this->platform, $fengsu);
- $output->writeln('没有数据');
- }
- } else {
- $output->writeln('接口错误: ' . $resquet['message']);
- }
- $output->writeln('ok');
- }
- public function getOrderList($platform = 'pdd')
- {
- $client = new \GuzzleHttp\Client([
- 'verify' => false,
- // 或指定证书路径
- // 'verify' => '/path/to/cacert.pem'
- ]);
-
- $this->headers['Authorization']=site_config("addonsd.authorization_token");
- //时间间隔
- // $start_end_space_time=10*60;
- //下一次时间间隔
- // $next_time_space=7*60;
- //将查询分为,"2026-01-05 00:00:00~2026-01-05 00:05:00",查询该区间的订单,但是该时间区间单独数量可能超过50条,为了性能又不能一次性查询太多,从而进行分页查询,
- //查询不到数据,就往下一个时间区间查询
- $todayTime = date("Y-m-d");
- $startTime_stamp = strtotime($todayTime . ' 00:00:00');
- // $startTime_stamp = strtotime($todayTime . ' 07:20:00');
- $endTime_stamp = $startTime_stamp + $this->start_end_space_time;
- $pageNum = 1;
- $fengsu = [
- 'startTime' => $startTime_stamp,
- 'endTime' => $endTime_stamp,
- 'pageNum' => $pageNum,
- 'next_time_space' => $this->next_time_space
- ];
- $fengsu_cache_data = Cache::get('fengsu_'.$this->platform);
- if (empty($fengsu_cache_data) || $fengsu_cache_data == null) {
- Cache::set('fengsu_'.$this->platform, $fengsu);
- }
- $fengsu = Cache::get('fengsu_'.$this->platform);
- // 无数据时,获取数据的开始时间会大于现在的时间,这是一个错误的,会导致一直无法获取数据,开始时间一直往后
- //当开始时间大于现在时间,将开始时间向前调整3分钟
- $now_time = time();
- if ($fengsu['startTime'] >= $now_time || ($now_time - $fengsu['startTime']) < ($this->start_end_space_time - $this->next_time_space)) {
- // dump("超时了");
- $pre_time_stamp = $this->next_time_space;
- $startTime_stamp = $now_time - $pre_time_stamp;
- $endTime_stamp = $startTime_stamp + $this->start_end_space_time;
- $fengsu = [
- 'startTime' => $startTime_stamp,
- 'endTime' => $endTime_stamp,
- 'pageNum' => 1,
- 'next_time_space' => $this->next_time_space
- ];
- }
- Cache::set('fengsu_'.$this->platform, $fengsu);
- $startTime = date('Y-m-d H:i:s', $fengsu['startTime']);
- $endTime = date('Y-m-d H:i:s', $fengsu['endTime']);
- $pageNum = (int)$fengsu['pageNum'];
- // dump($startTime);
- $body = [
- 'startTime' => $startTime,
- 'endTime' => $endTime,
- 'current' => $pageNum,
- 'goodType' => 2,
- 'goodsFlag' => 1,
- 'orderPrefixSelect' => 'waybillNos',
- 'prepareShip' => 0,
- 'size' => 100,
- 'sort' => 'CONSIGN_TIME',
- 'sortAsc' => true,
- 'timeType' => 2,
- 'tradeStatus' => 2,
- 'skuOuterIdExact' => false,
- 'skuPropExact' => false,
- 'tradeSources' => []
- ];
- // 'waybillNos' => ['73589756512463']
- $body = json_encode($body);
- $request = new Request('POST', $this->url, $this->headers, $body);
- try {
- $res = $client->sendAsync($request)->wait();
- $json = [];
- if ($res->getStatusCode() == 200) {
- $json = json_decode($res->getBody()->getContents(), true);
- } else {
- dump($res->getStatusCode(), '接口返回结果');
- }
- return $json;
- } catch (\Exception $e) {
- $errorStr = $e->getMessage();
- // 定位response:位置
- $pos = strpos($errorStr, 'response:');
- if ($pos !== false) {
- // 从response:后开始截取
- $jsonPart = substr($errorStr, $pos + strlen('response:'));
- // 清理空白字符
- $jsonPart = preg_replace('/^\s+|\s+$/', '', $jsonPart);
- $jsonPart = json_decode($jsonPart, true);
- if (!empty($jsonPart)) {
- if ($jsonPart['code'] == 401 && $jsonPart['message'] == 'token失效') {
- $this->fengSu_command->set_fengsu_Authorization($client);
- }
- }
- }
- var_dump($e->getMessage());
- return null;
- }
- }
-
-
- }
|