76 lines
2.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Services\Business\KuaiTuanTuan;
use App\Events\BusinessOrdersUpdate;
use App\Models\BusinessGoodsSku;
class Goods
{
public static function downloadGoods($activityNo, $page = 1, $size = 100)
{
$type = 'pdd.ktt.goods.query.list';
$appendParams = [
// 'activity_no' => $activityNo, // 非必填,团号(团号和创建时间只能传一个)
'page' => $page,
'size' => $size,
// 'update_time_end' => '', // 非必填,结束最后更新时间(毫秒级时间戳)
// 'update_time_start' => '', // 非必填,起始最后更新时间(毫秒级时间戳)
// 'create_time_end' => '', // 非必填,开始时间结束(毫秒级时间戳)
// 'create_time_start' => '' // 非必填, 开始时间起始(毫秒级时间戳)
];
return [$type, $appendParams];
}
public static function bindGoods(array $goodsList, $shopId)
{
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);
$businessGoodSku = BusinessGoodsSku::firstOrNew(
['shop_id' => $shopId, 'goods_id' => $businessGood['goods_id'], 'sku_id' => $sku['sku_id']],
$data
);
if (empty($businessGoodSku->id)) {
$businessGoodSku->save();
if (!empty($businessGoodSku->external_sku_id)) {
event(new BusinessOrdersUpdate($businessGoodSku, 0));
}
}
}
}
}
public static function downloadSingle($goodsId)
{
$type = 'pdd.ktt.goods.query.single';
$appendParams = [
'goods_id' => $goodsId,
'page' => 1,
'size' => 100,
];
return [$type, $appendParams];
}
public static function incrQuantity($goodsId, $skuId, $quantity, $modifyType = 2)
{
$type = 'pdd.ktt.goods.incr.quantity';
$appendParams = [
'goods_id' => $goodsId,
'quantity_delta' => max($quantity, 0),
'sku_id' => $skuId,
// 非必填
'modify_quantity_type' => $modifyType, // 修改库存的类型不传或1代表增量修改2代表全量修改
];
return [$type, $appendParams];
}
}