|
|
@@ -1,4 +1,5 @@
|
|
|
<?php
|
|
|
+
|
|
|
/**
|
|
|
* ----------------------------------------------------------------------------
|
|
|
* 行到水穷处,坐看云起时
|
|
|
@@ -7,6 +8,7 @@
|
|
|
* Author: 老成
|
|
|
* email:85556713@qq.com
|
|
|
*/
|
|
|
+
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
namespace app\admin\command;
|
|
|
@@ -27,10 +29,13 @@ use app\admin\service\FengsuService;
|
|
|
use GuzzleHttp\Psr7\Request;
|
|
|
use app\common\model\ImportList;
|
|
|
use app\admin\service\JuShuiTanService;
|
|
|
+
|
|
|
+use think\facade\Cache;
|
|
|
+
|
|
|
//抖音
|
|
|
class FengSu extends Command
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
//抖音请求地址
|
|
|
protected $url = 'https://fsdy2.fengsutb.com/amount/ship-list-new';
|
|
|
|
|
|
@@ -44,7 +49,7 @@ class FengSu extends Command
|
|
|
];
|
|
|
|
|
|
// 打单平台 1:风速 2:聚水潭
|
|
|
- protected $type_id=1;
|
|
|
+ protected $type_id = 1;
|
|
|
// 指令配置
|
|
|
protected function configure()
|
|
|
{
|
|
|
@@ -57,18 +62,43 @@ class FengSu extends Command
|
|
|
$output->writeln('开始同步订单');
|
|
|
|
|
|
$resquet = $this->getOrderList('');
|
|
|
- if($resquet['code'] == 0){
|
|
|
- if($resquet['data']['total'] > 0){
|
|
|
+ if ($resquet['code'] == 0) {
|
|
|
+ $fengsu=[];
|
|
|
+ $fengsu=Cache::get('fengsu');
|
|
|
+
|
|
|
+ if ($resquet['data']['total'] > 0) {
|
|
|
+
|
|
|
+ $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',$fengsu);
|
|
|
+
|
|
|
+
|
|
|
$list = $resquet['data']['list'];
|
|
|
- // dump($list);
|
|
|
- // return;
|
|
|
+ dump($list);
|
|
|
+ return;
|
|
|
$this->insertOrder($list);
|
|
|
//dump($resquet);
|
|
|
- }else{
|
|
|
+ } 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',$fengsu);
|
|
|
+
|
|
|
+
|
|
|
$output->writeln('没有数据');
|
|
|
}
|
|
|
- }else{
|
|
|
- $output->writeln('接口错误: ' .$resquet['message']);
|
|
|
+ } else {
|
|
|
+ $output->writeln('接口错误: ' . $resquet['message']);
|
|
|
}
|
|
|
|
|
|
$output->writeln('ok');
|
|
|
@@ -89,29 +119,68 @@ class FengSu extends Command
|
|
|
'platform' => $platform,
|
|
|
'Content-Type' => ' application/json'
|
|
|
];
|
|
|
- $body = '{
|
|
|
- "sort": "CONSIGN_TIME",
|
|
|
- "sortAsc": false,
|
|
|
- "current": 1,
|
|
|
- "size": 50,
|
|
|
- "tradeStatus": 2,
|
|
|
- "fromAccountId": [],
|
|
|
- "goodType": 2,
|
|
|
- "goodsFlag": 2
|
|
|
- }';
|
|
|
+
|
|
|
+ //时间间隔
|
|
|
+ $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+$start_end_space_time;
|
|
|
+ $pageNum=1;
|
|
|
+
|
|
|
+ $fengsu=[
|
|
|
+ 'startTime'=>$startTime_stamp,
|
|
|
+ 'endTime'=>$endTime_stamp,
|
|
|
+ 'pageNum'=>$pageNum,
|
|
|
+ 'next_time_space'=>$next_time_space
|
|
|
+ ];
|
|
|
+
|
|
|
+ $fengsu_cache_data=Cache::get('fengsu');
|
|
|
+
|
|
|
+ if(empty($fengsu_cache_data)||$fengsu_cache_data==null){
|
|
|
+ Cache::set('fengsu',$fengsu);
|
|
|
+ }
|
|
|
+ $fengsu=Cache::get('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'];
|
|
|
+
|
|
|
+ $body = [
|
|
|
+ 'startTime' => $startTime,//时间区间
|
|
|
+ 'endTime' => $endTime,
|
|
|
+ 'sort' => 'CONSIGN_TIME',
|
|
|
+ 'sortAsc' => false,
|
|
|
+ 'current' => $pageNum,//页数
|
|
|
+ 'size' => 50,//每页多少条
|
|
|
+ 'tradeStatus' => 2,
|
|
|
+ 'fromAccountId' => [],
|
|
|
+ 'goodType' => 2,
|
|
|
+ 'goodsFlag' => 2,
|
|
|
+ 'waybillNos' => ['73589756512463']
|
|
|
+ ];
|
|
|
+ $body = json_encode($body);
|
|
|
+
|
|
|
$request = new Request('POST', 'https://fsdy2.fengsutb.com/amount/ship-list-new', $headers, $body);
|
|
|
$res = $client->sendAsync($request)->wait();
|
|
|
$json = [];
|
|
|
- if($res->getStatusCode() == 200) {
|
|
|
+ if ($res->getStatusCode() == 200) {
|
|
|
$json = json_decode($res->getBody()->getContents(), true);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
dump($res->getStatusCode(), '接口返回结果');
|
|
|
}
|
|
|
return $json;
|
|
|
}
|
|
|
public function insertOrder($order_list)
|
|
|
{
|
|
|
- if(!(count($order_list) > 0)){
|
|
|
+ if (!(count($order_list) > 0)) {
|
|
|
return false;
|
|
|
}
|
|
|
$queue = [];
|
|
|
@@ -120,32 +189,32 @@ class FengSu extends Command
|
|
|
$productConfig = new ProductConfig();
|
|
|
$shopDelivery = new ShopDelivery();
|
|
|
$customerSpec = new CustomerSpec();
|
|
|
- $shopDelivery_list=[];
|
|
|
-
|
|
|
- foreach($order_list as $item) {
|
|
|
- $goods_id=$item['tradeOrderPrintVos'][0]['goodsId'];
|
|
|
- $oid=$item['tradeOrderPrintVos'][0]['oid'];
|
|
|
- $sku_id=$item['tradeOrderPrintVos'][0]['skuId'];
|
|
|
- $waybill_no=$item['waybillNo'];
|
|
|
- if(empty($waybill_no)) continue;
|
|
|
- $add_status = JuShuiTanService::prevent_duplicate_additions($sku_id,$waybill_no);
|
|
|
- if($add_status) continue;
|
|
|
+ $shopDelivery_list = [];
|
|
|
+
|
|
|
+ foreach ($order_list as $item) {
|
|
|
+ $goods_id = $item['tradeOrderPrintVos'][0]['goodsId'];
|
|
|
+ $oid = $item['tradeOrderPrintVos'][0]['oid'];
|
|
|
+ $sku_id = $item['tradeOrderPrintVos'][0]['skuId'];
|
|
|
+ $waybill_no = $item['waybillNo'];
|
|
|
+ if (empty($waybill_no)) continue;
|
|
|
+ $add_status = JuShuiTanService::prevent_duplicate_additions($sku_id, $waybill_no);
|
|
|
+ if ($add_status) continue;
|
|
|
// $status = FengsuService::getAdditionalPrice( $shopList, $importSku, $productConfig, $shopDelivery, $customerSpec, $item);
|
|
|
-
|
|
|
+
|
|
|
$res = FengsuService::getAdditionalPrice($shopList, $importSku, $productConfig, $shopDelivery, $customerSpec, $item);
|
|
|
- $status=$res['status'];
|
|
|
- $shopDelivery_list[]=$res['shopDelivery'];
|
|
|
+ $status = $res['status'];
|
|
|
+ $shopDelivery_list[] = $res['shopDelivery'];
|
|
|
|
|
|
- $weight=$item['tradeOrderPrintVos'][0]['weight'];
|
|
|
- $weight=strval($weight);
|
|
|
- $weight=bcdiv($weight, '500', 2);
|
|
|
- $weight=(float)$weight;
|
|
|
- $price=$item['tradeOrderPrintVos'][0]['payment'];
|
|
|
- $price=strval($price);
|
|
|
- $price=bcdiv($price, '100', 2);
|
|
|
- $price=(float)$price;
|
|
|
+ $weight = $item['tradeOrderPrintVos'][0]['weight'];
|
|
|
+ $weight = strval($weight);
|
|
|
+ $weight = bcdiv($weight, '500', 2);
|
|
|
+ $weight = (float)$weight;
|
|
|
+ $price = $item['tradeOrderPrintVos'][0]['payment'];
|
|
|
+ $price = strval($price);
|
|
|
+ $price = bcdiv($price, '100', 2);
|
|
|
+ $price = (float)$price;
|
|
|
|
|
|
- $getPackSpecsFee = JuShuiTanService::getPackSpecsFee($importSku, $item['shopId'], $item['tradeOrderPrintVos'][0]['skuId'],$item['receiverProvince']);
|
|
|
+ $getPackSpecsFee = JuShuiTanService::getPackSpecsFee($importSku, $item['shopId'], $item['tradeOrderPrintVos'][0]['skuId'], $item['receiverProvince']);
|
|
|
|
|
|
$queue[] = [
|
|
|
'type_id' => $this->type_id,
|
|
|
@@ -162,21 +231,24 @@ class FengSu extends Command
|
|
|
'num' => $item['tradeOrderPrintVos'][0]['total'],
|
|
|
'goods_title' => $item['tradeOrderPrintVos'][0]['goodsTitle'],
|
|
|
'goods_info' => $item['tradeOrderPrintVos'][0]['skuProp'],
|
|
|
- 'weight' =>$weight,
|
|
|
+ 'weight' => $weight,
|
|
|
'price' => $price,
|
|
|
'status' => $status,
|
|
|
'specs_name' => $getPackSpecsFee['data']['title'],
|
|
|
'pack_specs_id' => $getPackSpecsFee['data']['id'],
|
|
|
'labor_cost_money' => $getPackSpecsFee['data']['labor_cost_money'],
|
|
|
'one_surcharge_money' => $getPackSpecsFee['one_surcharge_money'],
|
|
|
- 'two_surcharge_money' => $getPackSpecsFee['two_surcharge_money']
|
|
|
+ 'two_surcharge_money' => $getPackSpecsFee['two_surcharge_money'],
|
|
|
+ 'order_status' => $item['tradeOrderPrintVos'][0]['orderStatus']
|
|
|
+
|
|
|
+
|
|
|
];
|
|
|
}
|
|
|
// 保存到数据库
|
|
|
$shopDelivery->saveAll($shopDelivery_list);
|
|
|
(new ImportList())->saveAll($queue);
|
|
|
// 更新最后执行时间
|
|
|
- CrontabLog::create(['type_id' => 2,'last_time' => date('Y-m-d H:i:s')]);
|
|
|
+ CrontabLog::create(['type_id' => 2, 'last_time' => date('Y-m-d H:i:s')]);
|
|
|
}
|
|
|
}
|
|
|
//风速接口返回格式
|