feat: #10000 对接快团团测试修改

This commit is contained in:
赵世界 2022-08-08 18:53:38 +08:00
parent 8c3d717561
commit 942d46f7a9
6 changed files with 66 additions and 23 deletions

View File

@ -2,6 +2,7 @@
namespace App\Console\Commands;
use App\Models\GoodsSku;
use App\Models\Shop;
use App\Services\Business\BusinessFactory;
use Illuminate\Console\Command;
@ -42,7 +43,12 @@ class Test extends Command
$shop = Shop::query()->find(2);
$business = BusinessFactory::init()->make($shop->plat_id);
$business->setShop($shop);
$res = $business->downloadGoods();
var_dump($res);
// 下载商品
$business->downloadGoods(1);
// 库存修改
// $business->incrQuantity(1);
$this->info('执行测试成功');
}
}

View File

@ -1,6 +1,7 @@
<?php
namespace App\Services\Business;
use App\Models\Log;
use App\Models\Shop;
use GuzzleHttp\Client;
@ -14,7 +15,9 @@ abstract class BusinessClient
abstract public function auth();
abstract public function downloadGoods();
abstract public function downloadGoodsList();
abstract public function downloadGoods($skuId);
abstract public function bindGoods($goods);
@ -84,6 +87,12 @@ abstract class BusinessClient
];
$res = (new Client())->request('POST', $url, $headers);
$res = json_decode($res->getBody()->getContents(), true);
$disableLogType = [
'pdd.ktt.goods.query.list',
'pdd.ktt.order.list',
'pdd.ktt.increment.order.query'
];
if (!in_array($params['type'], $disableLogType, true)) {
$log = new Log();
$log->module = 'plat';
$log->action = 'POST';
@ -93,6 +102,8 @@ abstract class BusinessClient
$log->user_id = 1;
$log->message = json_encode($res, 256);
$log->save();
}
if (isset($res['error_response'])) {
throw new \Exception($res['error_response']['error_msg'], $res['error_response']['error_code']);
}

View File

@ -10,7 +10,7 @@ class Goods
{
$type = 'pdd.ktt.goods.query.list';
$appendParams = [
'activity_no' => $activityNo, // 非必填,团号(团号和创建时间只能传一个)
// 'activity_no' => $activityNo, // 非必填,团号(团号和创建时间只能传一个)
'page' => $page,
'size' => $size,
// 'update_time_end' => '', // 非必填,结束最后更新时间(毫秒级时间戳)
@ -27,6 +27,7 @@ class Goods
foreach ($goodsList as $businessGood) {
$skuList = $businessGood['sku_list'];
unset($businessGood['sku_list']);
$businessGood['goods_image_list'] = json_encode($businessGood['goods_image_list'], 256);
foreach ($skuList as $sku) {
$sku['spec_list'] = json_encode($sku['spec_list'], 256);
$data = array_merge($businessGood, $sku);
@ -38,12 +39,16 @@ class Goods
}
}
public function downloadSingle($goodsId)
public static function downloadSingle($goodsId)
{
$type = 'pdd.ktt.goods.query.single';
$appendParams = [
'goods_id' => $goodsId
'goods_id' => $goodsId,
'page' => 1,
'size' => 100,
];
return [$type, $appendParams];
}
public static function incrQuantity($goodsId, $quantity, $skuId, $modifyType = 2)

View File

@ -38,13 +38,13 @@ class KuaiTuanTuan extends BusinessClient
return $this->shop;
}
public function downloadGoods($page = 1)
public function downloadGoodsList($page = 1)
{
[$type, $appendParams] = Goods::downloadGoods($this->shop->owner_name, $page);
[$type, $appendParams] = Goods::downloadGoods($this->shop->owner_id, $page);
$res = $this->doRequest($type, $appendParams);
$goods = $res['ktt_goods_query_list_response']['goods_list'];
$this->bindGoods($goods);
$pageNum = ceil($res['total'] / $appendParams['size']);
$pageNum = ceil($res['ktt_goods_query_list_response']['total'] / $appendParams['size']);
if ($pageNum > $page && 10 >= $page) {
$this->downloadGoods($page + 1);
}
@ -57,9 +57,12 @@ class KuaiTuanTuan extends BusinessClient
public function incrQuantity($skuId)
{
$goodsSku = GoodsSku::query()->find($skuId);
$business = BusinessGoodsSku::query()->where('shop_id', $this->shop->id)->where('self_sku_id', $skuId)->first(['goods_id', 'sku_id']);
[$type, $appendParams] = Goods::incrQuantity($business->goodsId, $goodsSku->stock, $business->sku_id);
$goodsSku = GoodsSku::query()
->with(['goods:id,goods_code'])
->find($skuId);
$code = $goodsSku->goods->goods_code . '_' . $goodsSku->sku_code;
$business = BusinessGoodsSku::query()->where('shop_id', $this->shop->id)->where('external_sku_id', $code)->first(['goods_id', 'sku_id']);
[$type, $appendParams] = Goods::incrQuantity($business->goods_id, $goodsSku->stock, $business->sku_id);
$this->doRequest($type, $appendParams);
}
@ -124,4 +127,17 @@ class KuaiTuanTuan extends BusinessClient
return "https://oauth.pinduoduo.com/authorize/ktt?client_id={$this->clientId}&redirect_uri={$this->redirectUri}&state={$state}";
}
public function downloadGoods($skuId)
{
$goodsSku = GoodsSku::query()
->with(['goods:id,goods_code'])
->find($skuId);
$code = $goodsSku->goods->goods_code . '_' . $goodsSku->sku_code;
$business = BusinessGoodsSku::query()->where('shop_id', $this->shop->id)->where('external_sku_id', $code)->first(['goods_id', 'sku_id']);
[$type, $appendParams] = Goods::downloadSingle($business->goods_id);
$res = $this->doRequest($type, $appendParams);
$goods = $res['response']['result'];
$this->bindGoods([$goods]);
}
}

View File

@ -15,7 +15,7 @@ class MiaoXuan extends BusinessClient
// TODO: Implement auth() method.
}
public function downloadGoods()
public function downloadGoodsList()
{
}
@ -41,4 +41,9 @@ class MiaoXuan extends BusinessClient
{
Order::saveOrders($orders, $this->shop->id);
}
public function downloadGoods($skuId)
{
// TODO: Implement downloadGoods() method.
}
}

View File

@ -20,7 +20,7 @@ class CreateDailyStockRecordsTable extends Migration
$table->unsignedInteger('arrived_today_num')->default(0)->comment('今日到货');
$table->unsignedInteger('loss_num')->default(0)->comment('损耗');
$table->unsignedInteger('inventory')->default(0)->comment('库存盘点');
$table->unique('sku_id', 'day');
$table->unique(['sku_id', 'day']);
$table->timestamps();
});
}