mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-12-01 06:30:49 +00:00
commit
416cc2847d
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Events\StockUpdateEvent;
|
||||||
|
use App\Models\BusinessGoodsSku;
|
||||||
use App\Models\GoodsSku;
|
use App\Models\GoodsSku;
|
||||||
use App\Models\Log;
|
use App\Models\Log;
|
||||||
use App\Models\Shop;
|
use App\Models\Shop;
|
||||||
@ -9,6 +11,7 @@ use App\Services\Business\BusinessFactory;
|
|||||||
use App\Utils\DateTimeUtils;
|
use App\Utils\DateTimeUtils;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use App\Jobs\BusinessGoodsSkuIncrQuantity;
|
||||||
|
|
||||||
class Test extends Command
|
class Test extends Command
|
||||||
{
|
{
|
||||||
@ -43,6 +46,9 @@ class Test extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
$onSkuIds = [2823];
|
||||||
|
event(new StockUpdateEvent($onSkuIds));
|
||||||
|
exit();
|
||||||
$shop = Shop::query()->find(1);
|
$shop = Shop::query()->find(1);
|
||||||
$business = BusinessFactory::init()->make($shop->plat_id);
|
$business = BusinessFactory::init()->make($shop->plat_id);
|
||||||
$business->setShop($shop);
|
$business->setShop($shop);
|
||||||
@ -66,7 +72,7 @@ class Test extends Command
|
|||||||
// $business->incrQuantity(1);
|
// $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');
|
$endTime = DateTimeUtils::getMicroTime('2022-08-30 19:19:03');
|
||||||
$business->downloadOrdersAndSave($beginTime, $endTime);
|
$business->downloadOrdersAndSave($beginTime, $endTime);
|
||||||
|
|
||||||
|
|||||||
@ -41,6 +41,7 @@ class InventoryImport implements ToCollection, SkipsEmptyRows
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$goodsSku = GoodsSku::query()
|
$goodsSku = GoodsSku::query()
|
||||||
|
->select(['id', 'status', 'stock', 'cost'])
|
||||||
->where('goods_id', $hasGoods[$row[0]]['id'])
|
->where('goods_id', $hasGoods[$row[0]]['id'])
|
||||||
->where('sku_code', $row[4])
|
->where('sku_code', $row[4])
|
||||||
->first();
|
->first();
|
||||||
@ -67,7 +68,7 @@ class InventoryImport implements ToCollection, SkipsEmptyRows
|
|||||||
->toArray();
|
->toArray();
|
||||||
$downSkuIds = array_diff($onSkuIds, $updateIds);
|
$downSkuIds = array_diff($onSkuIds, $updateIds);
|
||||||
foreach ($downSkuIds as $downSkuId) {
|
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->yesterday_num -= $goodsSku->stock;
|
||||||
$goodsSku->stock = 0;
|
$goodsSku->stock = 0;
|
||||||
$goodsSku->save();
|
$goodsSku->save();
|
||||||
|
|||||||
@ -8,6 +8,7 @@ use App\Models\BusinessGoodsSku;
|
|||||||
use App\Models\Shop;
|
use App\Models\Shop;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use App\Services\Business\BusinessFactory;
|
||||||
|
|
||||||
class StockUpdateListener
|
class StockUpdateListener
|
||||||
{
|
{
|
||||||
@ -36,18 +37,24 @@ class StockUpdateListener
|
|||||||
foreach ($shops as $shop) {
|
foreach ($shops as $shop) {
|
||||||
if (isset($event->goodsSku)) {
|
if (isset($event->goodsSku)) {
|
||||||
$num = $event->goodsSku->stock;
|
$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();
|
$businessGoodsSkus = BusinessGoodsSku::query()
|
||||||
foreach ($businessGoodsSkus as $businessGoodsSku) {
|
->select(['goods_id', 'sku_id'])
|
||||||
BusinessGoodsSkuIncrQuantity::dispatch($shop, $businessGoodsSku->toArray(), $num, false);
|
->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)) {
|
if (isset($event->goodsSkus)) {
|
||||||
foreach ($event->goodsSkus as $goodsSku) {
|
foreach ($event->goodsSkus as $goodsSku) {
|
||||||
$num = $goodsSku->stock;
|
$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();
|
$businessGoodsSkus = BusinessGoodsSku::query()
|
||||||
foreach ($businessGoodsSkus as $businessGoodsSku) {
|
->select(['goods_id', 'sku_id'])
|
||||||
BusinessGoodsSkuIncrQuantity::dispatch($shop, $businessGoodsSku->toArray(), $num, false);
|
->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 App\Models\Shop;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use GuzzleHttp\Promise;
|
||||||
|
|
||||||
abstract class BusinessClient
|
abstract class BusinessClient
|
||||||
{
|
{
|
||||||
@ -159,4 +160,21 @@ abstract class BusinessClient
|
|||||||
|
|
||||||
return $res;
|
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);
|
$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)
|
public function downloadGoods($skuId)
|
||||||
{
|
{
|
||||||
// TODO: Implement downloadGoods() method.
|
// TODO: Implement downloadGoods() method.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user