2022-08-06 15:25:13 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Services\Business\KuaiTuanTuan;
|
|
|
|
|
|
|
2022-09-14 15:59:27 +08:00
|
|
|
|
use App\Events\BusinessOrdersUpdate;
|
2022-08-06 15:25:13 +08:00
|
|
|
|
use App\Models\BusinessGoodsSku;
|
2024-12-12 13:47:22 +08:00
|
|
|
|
use App\Models\GoodsSku;
|
2024-12-11 14:27:39 +08:00
|
|
|
|
use App\Services\Business\BusinessFactory;
|
2024-12-12 13:47:22 +08:00
|
|
|
|
use Illuminate\Support\Facades\Log;
|
2022-08-06 15:25:13 +08:00
|
|
|
|
|
|
|
|
|
|
class Goods
|
|
|
|
|
|
{
|
|
|
|
|
|
public static function downloadGoods($activityNo, $page = 1, $size = 100)
|
|
|
|
|
|
{
|
|
|
|
|
|
$type = 'pdd.ktt.goods.query.list';
|
|
|
|
|
|
$appendParams = [
|
2023-01-29 11:29:48 +08:00
|
|
|
|
'activity_no' => $activityNo, // 非必填,团号(团号和创建时间只能传一个)
|
2022-08-06 15:25:13 +08:00
|
|
|
|
'page' => $page,
|
|
|
|
|
|
'size' => $size,
|
|
|
|
|
|
// 'update_time_end' => '', // 非必填,结束最后更新时间(毫秒级时间戳)
|
|
|
|
|
|
// 'update_time_start' => '', // 非必填,起始最后更新时间(毫秒级时间戳)
|
|
|
|
|
|
// 'create_time_end' => '', // 非必填,开始时间结束(毫秒级时间戳)
|
|
|
|
|
|
// 'create_time_start' => '' // 非必填, 开始时间起始(毫秒级时间戳)
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
return [$type, $appendParams];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-29 14:03:58 +08:00
|
|
|
|
public static function bindGoods(array $goodsList, $shopId, $title = '')
|
2022-08-06 15:25:13 +08:00
|
|
|
|
{
|
|
|
|
|
|
foreach ($goodsList as $businessGood) {
|
|
|
|
|
|
$skuList = $businessGood['sku_list'];
|
|
|
|
|
|
unset($businessGood['sku_list']);
|
2022-08-08 18:53:38 +08:00
|
|
|
|
$businessGood['goods_image_list'] = json_encode($businessGood['goods_image_list'], 256);
|
2022-08-06 15:25:13 +08:00
|
|
|
|
foreach ($skuList as $sku) {
|
|
|
|
|
|
$sku['spec_list'] = json_encode($sku['spec_list'], 256);
|
2022-11-01 09:39:01 +08:00
|
|
|
|
if ((int)$sku['quantity_type']) {
|
|
|
|
|
|
$sku['is_sync'] = 0;
|
2022-10-31 14:14:51 +08:00
|
|
|
|
}
|
2022-08-06 15:25:13 +08:00
|
|
|
|
$data = array_merge($businessGood, $sku);
|
2023-01-29 14:03:58 +08:00
|
|
|
|
$data['title'] = $title;
|
2022-09-14 15:59:27 +08:00
|
|
|
|
$businessGoodSku = BusinessGoodsSku::firstOrNew(
|
2022-08-18 11:08:13 +08:00
|
|
|
|
['shop_id' => $shopId, 'goods_id' => $businessGood['goods_id'], 'sku_id' => $sku['sku_id']],
|
2022-08-06 15:25:13 +08:00
|
|
|
|
$data
|
|
|
|
|
|
);
|
2022-09-15 18:57:15 +08:00
|
|
|
|
if (empty($businessGoodSku->id)) {
|
2022-09-14 15:59:27 +08:00
|
|
|
|
$businessGoodSku->save();
|
2024-12-12 13:47:22 +08:00
|
|
|
|
if (!empty($businessGoodSku->external_sku_id)) {
|
|
|
|
|
|
$shop = $businessGoodSku->shop;
|
|
|
|
|
|
$sku = GoodsSku::query()
|
|
|
|
|
|
->where('external_sku_id', $businessGoodSku->external_sku_id)
|
|
|
|
|
|
->first();
|
|
|
|
|
|
Log::info("商品下载新增sku",[$businessGoodSku]);
|
|
|
|
|
|
if(!empty($sku)){
|
|
|
|
|
|
BusinessFactory::init()->make($shop['plat_id'])->setShopWithId($shop['id'])->incrQuantity($businessGoodSku, $sku->sale_stock, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-09-16 10:30:51 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
$businessGoodSku->update($data);
|
2022-09-14 15:59:27 +08:00
|
|
|
|
}
|
2022-08-06 15:25:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-08 18:53:38 +08:00
|
|
|
|
public static function downloadSingle($goodsId)
|
2022-08-06 15:25:13 +08:00
|
|
|
|
{
|
|
|
|
|
|
$type = 'pdd.ktt.goods.query.single';
|
|
|
|
|
|
$appendParams = [
|
2022-08-08 18:53:38 +08:00
|
|
|
|
'goods_id' => $goodsId,
|
|
|
|
|
|
'page' => 1,
|
|
|
|
|
|
'size' => 100,
|
2022-08-06 15:25:13 +08:00
|
|
|
|
];
|
2022-08-08 18:53:38 +08:00
|
|
|
|
|
|
|
|
|
|
return [$type, $appendParams];
|
2022-08-06 15:25:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-16 21:02:31 +08:00
|
|
|
|
public static function incrQuantity($goodsId, $skuId, $quantity, $modifyType = 2)
|
2022-08-06 15:25:13 +08:00
|
|
|
|
{
|
|
|
|
|
|
$type = 'pdd.ktt.goods.incr.quantity';
|
|
|
|
|
|
$appendParams = [
|
|
|
|
|
|
'goods_id' => $goodsId,
|
2022-11-24 14:27:12 +08:00
|
|
|
|
'quantity_delta' => max($quantity, 0),
|
2022-08-06 15:25:13 +08:00
|
|
|
|
'sku_id' => $skuId,
|
|
|
|
|
|
// 非必填
|
|
|
|
|
|
'modify_quantity_type' => $modifyType, // 修改库存的类型,不传或1代表增量修改,2代表全量修改
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
return [$type, $appendParams];
|
|
|
|
|
|
}
|
2022-10-12 15:26:38 +08:00
|
|
|
|
|
|
|
|
|
|
public static function createSpec()
|
|
|
|
|
|
{
|
|
|
|
|
|
$type = 'pdd.ktt.goods.create.spec';
|
|
|
|
|
|
$appendParams = [
|
|
|
|
|
|
'spec_map' => json_encode([
|
|
|
|
|
|
'字母' => ['A', 'B']
|
|
|
|
|
|
])
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
return [$type, $appendParams];
|
|
|
|
|
|
}
|
2022-10-26 10:50:43 +08:00
|
|
|
|
|
|
|
|
|
|
public static function uploadImage($url)
|
|
|
|
|
|
{
|
|
|
|
|
|
$type = 'pdd.ktt.goods.upload.image';
|
|
|
|
|
|
$appendParams = [
|
|
|
|
|
|
'url' => $url
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
return [$type, $appendParams];
|
|
|
|
|
|
}
|
2022-08-06 15:25:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|