mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-12-01 14:40:44 +00:00
feat: #10000 快团团请求优化
This commit is contained in:
parent
1b9bd4bdf9
commit
15d95f0e9f
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Events\StockUpdateEvent;
|
||||
use App\Models\BusinessGoodsSku;
|
||||
use App\Models\GoodsSku;
|
||||
use App\Models\Log;
|
||||
use App\Models\Shop;
|
||||
@ -9,6 +11,7 @@ use App\Services\Business\BusinessFactory;
|
||||
use App\Utils\DateTimeUtils;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Jobs\BusinessGoodsSkuIncrQuantity;
|
||||
|
||||
class Test extends Command
|
||||
{
|
||||
@ -43,6 +46,9 @@ class Test extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$onSkuIds = [2823];
|
||||
event(new StockUpdateEvent($onSkuIds));
|
||||
exit();
|
||||
$shop = Shop::query()->find(1);
|
||||
$business = BusinessFactory::init()->make($shop->plat_id);
|
||||
$business->setShop($shop);
|
||||
@ -66,7 +72,7 @@ class Test extends Command
|
||||
// $business->incrQuantity(1);
|
||||
|
||||
// 订单下载
|
||||
$beginTime = DateTimeUtils::getMicroTime('2022-08-30 19:17:03');
|
||||
$beginTime = DateTimeUtils::getMicroTime('2022-08-30 19:17:03');
|
||||
$endTime = DateTimeUtils::getMicroTime('2022-08-30 19:19:03');
|
||||
$business->downloadOrdersAndSave($beginTime, $endTime);
|
||||
|
||||
|
||||
@ -41,6 +41,7 @@ class InventoryImport implements ToCollection, SkipsEmptyRows
|
||||
continue;
|
||||
}
|
||||
$goodsSku = GoodsSku::query()
|
||||
->select(['id', 'status', 'stock', 'cost'])
|
||||
->where('goods_id', $hasGoods[$row[0]]['id'])
|
||||
->where('sku_code', $row[4])
|
||||
->first();
|
||||
@ -67,7 +68,7 @@ class InventoryImport implements ToCollection, SkipsEmptyRows
|
||||
->toArray();
|
||||
$downSkuIds = array_diff($onSkuIds, $updateIds);
|
||||
foreach ($downSkuIds as $downSkuId) {
|
||||
$goodsSku = GoodsSku::query()->find($downSkuId);
|
||||
$goodsSku = GoodsSku::query()->select(['id', 'yesterday_num', 'stock'])->find($downSkuId);
|
||||
$goodsSku->yesterday_num -= $goodsSku->stock;
|
||||
$goodsSku->stock = 0;
|
||||
$goodsSku->save();
|
||||
|
||||
@ -8,6 +8,7 @@ use App\Models\BusinessGoodsSku;
|
||||
use App\Models\Shop;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use App\Services\Business\BusinessFactory;
|
||||
|
||||
class StockUpdateListener
|
||||
{
|
||||
@ -36,18 +37,24 @@ class StockUpdateListener
|
||||
foreach ($shops as $shop) {
|
||||
if (isset($event->goodsSku)) {
|
||||
$num = $event->goodsSku->stock;
|
||||
$businessGoodsSkus = BusinessGoodsSku::query()->where('shop_id', $shop->id)->where('is_sync', 1)->where('external_sku_id', $event->goodsSku->goods['goods_code'] . '_' . $event->goodsSku->sku_code)->get();
|
||||
foreach ($businessGoodsSkus as $businessGoodsSku) {
|
||||
BusinessGoodsSkuIncrQuantity::dispatch($shop, $businessGoodsSku->toArray(), $num, false);
|
||||
}
|
||||
$businessGoodsSkus = BusinessGoodsSku::query()
|
||||
->select(['goods_id', 'sku_id'])
|
||||
->where('shop_id', $shop->id)
|
||||
->where('is_sync', 1)
|
||||
->where('external_sku_id', $event->goodsSku->goods['goods_code'] . '_' . $event->goodsSku->sku_code)
|
||||
->get();
|
||||
BusinessFactory::init()->make($shop['plat_id'])->setShopWithId($shop['id'])->batchIncrQuantity($businessGoodsSkus->toArray(), $num, false);
|
||||
}
|
||||
if (isset($event->goodsSkus)) {
|
||||
foreach ($event->goodsSkus as $goodsSku) {
|
||||
$num = $goodsSku->stock;
|
||||
$businessGoodsSkus = BusinessGoodsSku::query()->where('shop_id', $shop->id)->where('is_sync', 1)->where('external_sku_id', $goodsSku->goods['goods_code'] . '_' . $goodsSku->sku_code)->get();
|
||||
foreach ($businessGoodsSkus as $businessGoodsSku) {
|
||||
BusinessGoodsSkuIncrQuantity::dispatch($shop, $businessGoodsSku->toArray(), $num, false);
|
||||
}
|
||||
$businessGoodsSkus = BusinessGoodsSku::query()
|
||||
->select(['goods_id', 'sku_id'])
|
||||
->where('shop_id', $shop->id)
|
||||
->where('is_sync', 1)
|
||||
->where('external_sku_id', $goodsSku->goods['goods_code'] . '_' . $goodsSku->sku_code)
|
||||
->get();
|
||||
BusinessFactory::init()->make($shop['plat_id'])->setShopWithId($shop['id'])->batchIncrQuantity($businessGoodsSkus->toArray(), $num, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ use App\Models\Log;
|
||||
use App\Models\Shop;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use GuzzleHttp\Promise;
|
||||
|
||||
abstract class BusinessClient
|
||||
{
|
||||
@ -159,4 +160,21 @@ abstract class BusinessClient
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function batchAsyncPostRequest($url, $batchParams)
|
||||
{
|
||||
$client = new Client();
|
||||
$promises = [];
|
||||
foreach ($batchParams as $param) {
|
||||
$options = [
|
||||
'headers' => ['Content-type' => 'application/x-www-form-urlencoded;'],
|
||||
'form_params' => $param
|
||||
];
|
||||
$promises[] = $client->postAsync($url, $options);
|
||||
}
|
||||
// $res = Promise\Utils::unwrap($promises);
|
||||
// foreach ($res as $item) {
|
||||
// var_dump($item->getBody()->getContents());
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,6 +63,21 @@ class KuaiTuanTuan extends BusinessClient
|
||||
$this->doRequest($type, $appendParams);
|
||||
}
|
||||
|
||||
public function batchIncrQuantity($businessGoodsSkus, $num, $incremental)
|
||||
{
|
||||
$batchAppendParams = [];
|
||||
foreach ($businessGoodsSkus as $businessGoodsSku) {
|
||||
[$type, $appendParams] = Goods::incrQuantity($businessGoodsSku['goods_id'], $businessGoodsSku['sku_id'], $num, $incremental ? 1 : 2);
|
||||
$appendParams['type'] = $type;
|
||||
$appendParams['client_id'] = $this->clientId;
|
||||
$appendParams['timestamp'] = time();
|
||||
$appendParams['access_token'] = $this->getShop()->access_token;
|
||||
$appendParams['sign'] = $this->getSign($appendParams);
|
||||
$batchAppendParams[] = $appendParams;
|
||||
}
|
||||
$this->batchAsyncPostRequest('https://gw-api.pinduoduo.com/api/router', $batchAppendParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载订单
|
||||
*
|
||||
|
||||
@ -33,6 +33,10 @@ class MiaoXuan extends BusinessClient
|
||||
{
|
||||
}
|
||||
|
||||
public function batchIncrQuantity($businessGoodsSkus, $num, $incremental)
|
||||
{
|
||||
}
|
||||
|
||||
public function downloadGoods($skuId)
|
||||
{
|
||||
// TODO: Implement downloadGoods() method.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user