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

View File

@ -1,6 +1,7 @@
<?php <?php
namespace App\Services\Business; namespace App\Services\Business;
use App\Models\Log; use App\Models\Log;
use App\Models\Shop; use App\Models\Shop;
use GuzzleHttp\Client; use GuzzleHttp\Client;
@ -14,7 +15,9 @@ abstract class BusinessClient
abstract public function auth(); abstract public function auth();
abstract public function downloadGoods(); abstract public function downloadGoodsList();
abstract public function downloadGoods($skuId);
abstract public function bindGoods($goods); abstract public function bindGoods($goods);
@ -84,15 +87,23 @@ abstract class BusinessClient
]; ];
$res = (new Client())->request('POST', $url, $headers); $res = (new Client())->request('POST', $url, $headers);
$res = json_decode($res->getBody()->getContents(), true); $res = json_decode($res->getBody()->getContents(), true);
$log = new Log(); $disableLogType = [
$log->module = 'plat'; 'pdd.ktt.goods.query.list',
$log->action = 'POST'; 'pdd.ktt.order.list',
$log->target_type = $this->shop->plat_id; 'pdd.ktt.increment.order.query'
$log->target_id = $this->skuId; ];
$log->target_field = $params['type']; if (!in_array($params['type'], $disableLogType, true)) {
$log->user_id = 1; $log = new Log();
$log->message = json_encode($res, 256); $log->module = 'plat';
$log->save(); $log->action = 'POST';
$log->target_type = $this->shop->plat_id;
$log->target_id = $this->skuId;
$log->target_field = $params['type'];
$log->user_id = 1;
$log->message = json_encode($res, 256);
$log->save();
}
if (isset($res['error_response'])) { if (isset($res['error_response'])) {
throw new \Exception($res['error_response']['error_msg'], $res['error_response']['error_code']); 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'; $type = 'pdd.ktt.goods.query.list';
$appendParams = [ $appendParams = [
'activity_no' => $activityNo, // 非必填,团号(团号和创建时间只能传一个) // 'activity_no' => $activityNo, // 非必填,团号(团号和创建时间只能传一个)
'page' => $page, 'page' => $page,
'size' => $size, 'size' => $size,
// 'update_time_end' => '', // 非必填,结束最后更新时间(毫秒级时间戳) // 'update_time_end' => '', // 非必填,结束最后更新时间(毫秒级时间戳)
@ -27,6 +27,7 @@ class Goods
foreach ($goodsList as $businessGood) { foreach ($goodsList as $businessGood) {
$skuList = $businessGood['sku_list']; $skuList = $businessGood['sku_list'];
unset($businessGood['sku_list']); unset($businessGood['sku_list']);
$businessGood['goods_image_list'] = json_encode($businessGood['goods_image_list'], 256);
foreach ($skuList as $sku) { foreach ($skuList as $sku) {
$sku['spec_list'] = json_encode($sku['spec_list'], 256); $sku['spec_list'] = json_encode($sku['spec_list'], 256);
$data = array_merge($businessGood, $sku); $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'; $type = 'pdd.ktt.goods.query.single';
$appendParams = [ $appendParams = [
'goods_id' => $goodsId 'goods_id' => $goodsId,
'page' => 1,
'size' => 100,
]; ];
return [$type, $appendParams];
} }
public static function incrQuantity($goodsId, $quantity, $skuId, $modifyType = 2) public static function incrQuantity($goodsId, $quantity, $skuId, $modifyType = 2)

View File

@ -38,13 +38,13 @@ class KuaiTuanTuan extends BusinessClient
return $this->shop; 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); $res = $this->doRequest($type, $appendParams);
$goods = $res['ktt_goods_query_list_response']['goods_list']; $goods = $res['ktt_goods_query_list_response']['goods_list'];
$this->bindGoods($goods); $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) { if ($pageNum > $page && 10 >= $page) {
$this->downloadGoods($page + 1); $this->downloadGoods($page + 1);
} }
@ -57,9 +57,12 @@ class KuaiTuanTuan extends BusinessClient
public function incrQuantity($skuId) public function incrQuantity($skuId)
{ {
$goodsSku = GoodsSku::query()->find($skuId); $goodsSku = GoodsSku::query()
$business = BusinessGoodsSku::query()->where('shop_id', $this->shop->id)->where('self_sku_id', $skuId)->first(['goods_id', 'sku_id']); ->with(['goods:id,goods_code'])
[$type, $appendParams] = Goods::incrQuantity($business->goodsId, $goodsSku->stock, $business->sku_id); ->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); $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}"; 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. // TODO: Implement auth() method.
} }
public function downloadGoods() public function downloadGoodsList()
{ {
} }
@ -41,4 +41,9 @@ class MiaoXuan extends BusinessClient
{ {
Order::saveOrders($orders, $this->shop->id); 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('arrived_today_num')->default(0)->comment('今日到货');
$table->unsignedInteger('loss_num')->default(0)->comment('损耗'); $table->unsignedInteger('loss_num')->default(0)->comment('损耗');
$table->unsignedInteger('inventory')->default(0)->comment('库存盘点'); $table->unsignedInteger('inventory')->default(0)->comment('库存盘点');
$table->unique('sku_id', 'day'); $table->unique(['sku_id', 'day']);
$table->timestamps(); $table->timestamps();
}); });
} }