同步发货状态

This commit is contained in:
杨建炊 2024-11-25 13:51:50 +08:00
parent 34aae9e275
commit 92eba2d461
6 changed files with 106 additions and 0 deletions

View File

@ -0,0 +1,62 @@
<?php
namespace App\Console\Commands;
use App\Http\Enum\BusinessOrderShippingStatus;
use App\Models\BusinessOrder;
use App\Models\Shop;
use App\Services\Business\BusinessFactory;
use Carbon\Carbon;
use Illuminate\Console\Command;
class KttOrderSyncStatus extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'ktt:order_sync_status';
/**
* The console command description.
*
* @var string
*/
protected $description = '快团团同步发货状态';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
* @throws \Exception
*/
public function handle()
{
$startTime = Carbon::now()->subDays(15)->getPreciseTimestamp(3);
$shops = Shop::query()->where('plat_id', Shop::$PLAT_KTT)->where('status', Shop::$STATUS_AUTHORIZED)->get();
BusinessOrder::query()->where('confirm_at', '>=', $startTime)
->where('shipping_status',BusinessOrderShippingStatus::UNSHIP)
->where('cancel_status',0)
->chunk(200, function ($orders) use ($shops) {
foreach ($orders as $order) {
$shop = $shops->where('id',$order['shop_id'])->first();
if(!empty($shop)){
BusinessFactory::init()->make($shop->plat_id)->setShop($shop)->queryStatusAndSync($order);
usleep(10);
}
}
});
}
}

View File

@ -8,6 +8,7 @@ use App\Console\Commands\DailySalesReport;
use App\Console\Commands\GoodsSkuDailyReport; use App\Console\Commands\GoodsSkuDailyReport;
use App\Console\Commands\Inventory; use App\Console\Commands\Inventory;
use App\Console\Commands\KttOrderAfterSaleQuery; use App\Console\Commands\KttOrderAfterSaleQuery;
use App\Console\Commands\KttOrderSyncStatus;
use Illuminate\Console\Scheduling\Schedule; use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use App\Console\Commands\KttOrderQuery; use App\Console\Commands\KttOrderQuery;
@ -57,6 +58,9 @@ class Kernel extends ConsoleKernel
//同步售卖信息和报损相关数据 //同步售卖信息和报损相关数据
$schedule->command(GoodsSkuDailyReport::class)->dailyAt('03:30'); $schedule->command(GoodsSkuDailyReport::class)->dailyAt('03:30');
//新增价格校验
$schedule->command(KttOrderSyncStatus::class)->everyTenMinutes();
} }
/** /**

View File

@ -0,0 +1,17 @@
<?php
namespace App\Http\Enum;
class BusinessOrderShippingStatus
{
const UNSHIP = 0;
const SHIPPED = 1;//已发货
const SHIPPING = 2;//部分发货
const RECEIVED = 3;//已收货
const SHIPPED_MAP = [
self::SHIPPED, self::SHIPPING, self::RECEIVED,
];
}

View File

@ -40,6 +40,8 @@ abstract class BusinessClient
abstract public function downloadAfterSaleOrdersAndSave($beginTime, $endTime, $page = 1); abstract public function downloadAfterSaleOrdersAndSave($beginTime, $endTime, $page = 1);
abstract public function queryStatusAndSync($order);
public function saveOrders($orders) public function saveOrders($orders)
{ {
$shopId = $this->getShop()->id; $shopId = $this->getShop()->id;

View File

@ -175,6 +175,23 @@ class KuaiTuanTuan extends BusinessClient
} }
} }
public function queryStatusAndSync($order)
{
[$type, $appendParams] = Order::getOrderInfo($order->order_sn);
$responseName = 'ktt_order_get_response';
$res = $this->doRequest($type, $appendParams);
if (!isset($res[$responseName]['order_info'])) {
return;
}
$queryOrder = $res[$responseName]['order_info'];
if ($order->shipping_status != $queryOrder['shipping_status']) {
$order->shipping_status = $queryOrder['shipping_status'];
$order->save();
}
}
public function getOrderInfo($orderSn) public function getOrderInfo($orderSn)
{ {
[$type, $appendParams] = Order::getOrderInfo($orderSn); [$type, $appendParams] = Order::getOrderInfo($orderSn);

View File

@ -37,6 +37,10 @@ class MiaoXuan extends BusinessClient
} }
public function queryStatusAndSync($order){
}
public function batchIncrQuantity($businessGoodsSkus, $num, $incremental) public function batchIncrQuantity($businessGoodsSkus, $num, $incremental)
{ {
$batchAppendParams = []; $batchAppendParams = [];