834 lines
34 KiB
PHP
834 lines
34 KiB
PHP
<?php
|
||
/**
|
||
* @package CipherSYS IM
|
||
* @author Xiaowei Wang <wangxiaowei@ciphersys.com>
|
||
* @copyright Copyright (c) 2022 - 2024, CipherSYS Co.,Ltd. (https://www.ciphersys.com/)
|
||
* @license CipherSYS Commercial License
|
||
* @link https://www.ciphersys.com
|
||
*/
|
||
|
||
namespace app\common\server\doudian;
|
||
|
||
use app\common\model\goods\GoodsSpec;
|
||
use app\shop\logic\goods\GoodsLogic;
|
||
use \think\facade\Cache;
|
||
use DOMDocument;
|
||
|
||
require "../vendor/doudian/src/autoload.php";
|
||
|
||
include "../vendor/doudian/src/open/api/materialgw/BinaryMaterialUploadAddressAuthParam.php";
|
||
include "../vendor/doudian/src/open/api/materialgw/BinaryMaterialUploadAddressAuthRequest.php";
|
||
include "../vendor/doudian/src/open/api/materialgw/BinaryMaterialUploadParam.php";
|
||
|
||
// ACCESS_TOKEN_CODE 工具型应用
|
||
const ACCESS_TOKEN_CODE = 1;
|
||
// ACCESS_TOKEN_SHOP_ID 自用型应用
|
||
const ACCESS_TOKEN_SHOP_ID = 2;
|
||
|
||
// 单规格 重量属性id
|
||
const ONE_SPEC_WEIGHT_TEXT = '重量';
|
||
const ONE_SPEC_WEIGHT = 00001;
|
||
|
||
// 单规格 体积属性id
|
||
const ONE_SPEC_SIZE_TEXT = '体积';
|
||
const ONE_SPCE_SIZE = 00002;
|
||
|
||
// 测试应用ID
|
||
const TEST_SHOP_ID = 4463798;
|
||
// 正式应用ID
|
||
const SHOP_ID = 133974293;
|
||
|
||
class DouDianServer
|
||
{
|
||
private static $cacheName = 'doudian@access_token';
|
||
private static $appKey = '7377352986936280614';
|
||
private static $appSecret = 'a4180703-743d-4dc0-a695-de213ee0d7b3';
|
||
private static $shopId = SHOP_ID;
|
||
private static $specName = array(
|
||
'颜色' => '颜色分类',
|
||
'尺寸' => '尺码大小'
|
||
);
|
||
|
||
private static $domain = '';
|
||
private $access_token = '';
|
||
|
||
// 食品生产许可证编号
|
||
private static $food_license = 'SC10243102300129';
|
||
// 有机食品认证编号
|
||
private static $organic_food_license = '115OP1900566';
|
||
|
||
public function __construct()
|
||
{
|
||
// $domain = input('server.REQUEST_SCHEME') . '://' . input('server.SERVER_NAME');
|
||
self::$domain = 'https://dlh.hainings.com';
|
||
\GlobalConfig::getGlobalConfig()->appKey = self::$appKey;
|
||
\GlobalConfig::getGlobalConfig()->appSecret = self::$appSecret;
|
||
if (Cache::get(self::$cacheName)) {
|
||
$this->access_token = Cache::get(self::$cacheName);
|
||
} else {
|
||
$result = \AccessTokenBuilder::build(self::$shopId, ACCESS_TOKEN_SHOP_ID);
|
||
if ($result->isSuccess()) {
|
||
Cache::set(self::$cacheName, $result, 30 * 60);
|
||
$this->access_token = $result;
|
||
} else {
|
||
throw new \think\Exception($result->getSubMsg());
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @note 发布商品,缺少一个统一规格的和多规格
|
||
*/
|
||
public function productAdd($goods_id = 0)
|
||
{
|
||
// $this->getShopCategory();
|
||
// $this->getCateProperty();
|
||
$goods = GoodsLogic::info($goods_id);
|
||
$request = new \ProductAddV2Request();
|
||
$param = new \ProductAddV2Param();
|
||
$request->setParam($param);
|
||
|
||
if (isset($goods['base']['code'])) {
|
||
// 自己的商品编码
|
||
$param->outer_product_id = $goods['base']['code'];
|
||
}
|
||
|
||
// 0-普通,3-虚拟
|
||
$param->product_type = $goods['base']['type'] == 0 ? 0 : 3;
|
||
|
||
// 叶子类目ID通过/shop/getShopCategory接口获取
|
||
$param->category_leaf_id = 20267;
|
||
|
||
// 商品名称
|
||
$param->name = $goods['base']['name'];
|
||
|
||
// 商家推荐语
|
||
if (isset($goods['recommend_remark'])) {
|
||
$param->recommend_remark = $goods['base']['remark'];
|
||
}
|
||
|
||
// 商品轮播图
|
||
$param->pic = implode('|', $this->batchUploadImage($goods['base']['goods_image']));
|
||
|
||
// 商品描述,目前只支持图片
|
||
$doc = new DOMDocument();
|
||
$doc->loadHTML($goods['base']['content']);
|
||
$images = $doc->getElementsByTagName('img');
|
||
$src = array();
|
||
foreach ($images as $k => $image) {
|
||
// $src[$k]['uri'] = str_replace('http://admin.dlh.com', 'https://dlh.hainings.com', $image->getAttribute('src'));
|
||
$src[$k]['uri'] = str_replace('http://admin.dlh.com', 'https://dlh.hainings.com', 'https://dlh.hainings.com/uploads/images/202311081656230c8308690.jpg');
|
||
$src[$k]['id'] = $goods_id . '_goods_detail_' . $k;
|
||
}
|
||
$param->description = implode('|', $this->batchUploadImage($src, true));
|
||
|
||
// 支付方式,0货到付款 1在线支付,2,货到付款+在线支付
|
||
$param->pay_type = 1;
|
||
// 减库存类型:1-拍下减库存 2-付款减库存
|
||
$param->reduce_type = 1;
|
||
// 运费模板id,传0表示包邮,通过/freightTemplate/list接口获取
|
||
$param->freight_id = 0;
|
||
// 承诺发货时间,具体规则用/product/getProductUpdateRule获取
|
||
$param->delivery_delay_day = 2;
|
||
// 发货模式,0-现货发货,1-预售发货,2-阶梯发货,默认0
|
||
$param->presell_type = 0;
|
||
$param->after_sale_service = "{\"supply_day_return_selector\":\"7-1\"}";
|
||
// 客服号码
|
||
$param->mobile = "400123456";
|
||
$param->commit = true; #false仅保存草稿,true保存+提审
|
||
|
||
$product_format_new = array(
|
||
697 => [
|
||
'diy_type' => 1,
|
||
'name' => '旅行箱捆绑带',
|
||
'value' => 27904
|
||
]
|
||
);
|
||
// dump(json_encode($product_format_new, JSON_UNESCAPED_UNICODE));
|
||
// die;
|
||
/**
|
||
* 697 代表的属性中的 property_id
|
||
* diy_type 代表的是属性中的 diy_type
|
||
* name 代表的属性中的 name
|
||
* value 代表的属性中的 value
|
||
*/
|
||
$param->product_format_new = "{\"697\":[{\"diy_type\":1,\"name\":\"旅行箱捆绑带\",\"value\":27904}]}";
|
||
// $param->product_format_new = "{\"241\":[{\"diy_type\":1,\"name\":\"常规款\",\"value\":17314}],\"631\":[{\"diy_type\":1,\"name\":\"东西南北风\",\"value\":0}],\"785\":[{\"measure_info\":{\"values\":[{\"module_id\":582,\"value\":\"亚麻\",\"unit_id\":0},{\"module_id\":583,\"unit_name\":\"%\",\"unit_id\":15,\"value\":\"100\"}],\"template_id\":252,\"value_name\":\"亚麻100%\"},\"diy_type\":1,\"name\":\"亚麻100%\",\"value\":0}],\"813\":[{\"diy_type\":1,\"name\":\"X型\",\"value\":8017}],\"981\":[{\"diy_type\":1,\"name\":\"蛋糕裙\",\"value\":22253}],\"1467\":[{\"diy_type\":0,\"name\":\"59%-69%(含)\",\"value\":168368}],\"1551\":[{\"diy_type\":1,\"name\":\"超短裙\",\"value\":22064}],\"1687\":[{\"diy_type\":0,\"name\":\"\",\"value\":0}],\"1878\":[{\"diy_type\":1,\"name\":\"高腰\",\"value\":16521}],\"2592\":[{\"diy_type\":1,\"name\":\"甜美风\",\"value\":192481}]}";
|
||
$param->standard_brand_id = 596120136; #品牌
|
||
# $param->presell_config_level = 2
|
||
//$param->size_info_template_id = 7119681499770667267; #尺码模板id https://op.jinritemai.com/docs/guide-docs/242/2094
|
||
|
||
$spec = [];
|
||
foreach ($goods['spec'] as $k => $v) {
|
||
$spec_text = self::$specName[$v['name']] ? self::$specName[$v['name']] : $v['name'];
|
||
$spec['spec_values'][$k]['property_name'] = $spec_text;
|
||
$spec['spec_values'][$k]['property_id'] = 0;
|
||
foreach ($v['values'] as $k2 => $v2) {
|
||
$spec['spec_values'][$k]['values'][$k2] = array(
|
||
'value_name' => str_replace('英寸', '码', $v2['value']),
|
||
'value_id' => 0
|
||
);
|
||
}
|
||
}
|
||
$param->spec_info = json_encode($spec, JSON_UNESCAPED_UNICODE);
|
||
|
||
$spec_list = [];
|
||
foreach ($goods['item'] as $k => $v) {
|
||
$spec_value_str = explode(',', $v['spec_value_str']);
|
||
foreach ($spec_value_str as $k2 => $v2) {
|
||
$res = GoodsSpec::where(['goods_id' => $goods_id])->select();
|
||
$spec_list[$k]['sell_properties'][$k2]['value_name'] = str_replace('英寸', '码', $v2);
|
||
$spec_list[$k]['sell_properties'][$k2]['property_name'] = self::$specName[$res[$k2]['name']];
|
||
$spec_list[$k]['stock_num'] = $v['stock'];
|
||
$spec_list[$k]['price'] = floatval($v['price']);
|
||
}
|
||
}
|
||
|
||
$param->spec_prices_v2 = json_encode($spec_list, JSON_UNESCAPED_UNICODE);
|
||
|
||
$response = $request->execute($this->access_token);
|
||
|
||
if ($response->code == 10000) {
|
||
dump($response);
|
||
} else {
|
||
dump($response->sub_msg);
|
||
throw new \think\Exception($response->sub_msg);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @note 山茶油上传
|
||
*/
|
||
public function camelliaProduct($goods_id = 0)
|
||
{
|
||
$goods = GoodsLogic::info($goods_id);
|
||
$request = new \ProductAddV2Request();
|
||
$param = new \ProductAddV2Param();
|
||
$request->setParam($param);
|
||
|
||
// if (isset($goods['base']['code'])) {
|
||
// // 自己的后台商品编码
|
||
// $param->outer_product_id = $goods['base']['code'] + 6;
|
||
// }
|
||
|
||
$param->name = $goods['base']['name'];
|
||
|
||
// 0-普通,3-虚拟
|
||
$param->product_type = $goods['base']['type'] == 0 ? 0 : 3;
|
||
|
||
// 叶子类目ID通过/shop/getShopCategory接口获取
|
||
$param->category_leaf_id = 28227;
|
||
|
||
// 获取商品品牌,泰宇品牌ID:1804083496
|
||
// $this->getBrand($param->category_leaf_id);
|
||
$param->standard_brand_id = 1804083496;
|
||
|
||
// 获取商品发布规则
|
||
// $rule = $this->getProductRule($param->category_leaf_id);
|
||
|
||
// 商品轮播图
|
||
$param->pic = implode('|', $this->batchUploadImage($goods['base']['goods_image']));
|
||
// $param->pic = 'https://p3-aio.ecombdimg.com/obj/ecom-shop-material/ALSUvYM_m_4aedee0c4d90d0488e6e8521a0555758_sx_107771_www800-800';
|
||
|
||
// 商品描述,目前只支持图片
|
||
$doc = new DOMDocument();
|
||
$doc->loadHTML($goods['base']['content']);
|
||
$images = $doc->getElementsByTagName('img');
|
||
$src = array();
|
||
foreach ($images as $k => $image) {
|
||
// src[$k]['uri'] = str_replace('http://admin.dlh.com', 'https://dlh.hainings.com', $image->getAttribute('src'));
|
||
$src[$k]['uri'] = str_replace('http://admin.dlh.com', 'https://dlh.hainings.com', 'https://dlh.hainings.com/uploads/images/20240528170003c16046671.jpg');
|
||
$src[$k]['id'] = $goods_id . '_goods_detail_' . $k;
|
||
}
|
||
$param->description = implode('|', $this->batchUploadImage($src, true));
|
||
// $param->description = 'https://p3-aio.ecombdimg.com/obj/ecom-shop-material/ALSUvYM_m_4aedee0c4d90d0488e6e8521a0555758_sx_107771_www800-800';
|
||
|
||
// 获取资质
|
||
$param->quality_list = $this->getQualificationConfig($param->category_leaf_id);
|
||
|
||
// 支付方式,0货到付款 1在线支付,2,货到付款+在线支付
|
||
$param->pay_type = 1;
|
||
// 减库存类型:1-拍下减库存 2-付款减库存
|
||
$param->reduce_type = 1;
|
||
// 运费模板id,传0表示包邮,通过/freightTemplate/list接口获取
|
||
$param->freight_id = 0;
|
||
// 承诺发货时间,具体规则用/product/getProductUpdateRule获取
|
||
$param->delivery_delay_day = 2;
|
||
// 发货模式,0-现货发货,1-预售发货,2-阶梯发货,默认0
|
||
$param->presell_type = 0;
|
||
|
||
$param->after_sale_service = "{\"supply_day_return_selector\":\"7-1\"}";
|
||
// 客服号码
|
||
$param->mobile = "400123456";
|
||
$param->commit = true; #false仅保存草稿,true保存+提审
|
||
|
||
/* 这个是商品属性规格 对应的接口为 getCateProperty, 以下必填项可以参考抖店商家类目数据*/
|
||
$product_format_new = array(
|
||
2685 => [
|
||
[
|
||
'diy_type' => 0,
|
||
'name' => '永兴泰宇茶油有限公司',
|
||
'value' => 0
|
||
]
|
||
],
|
||
4118 => [
|
||
[
|
||
'diy_type' => 0,
|
||
'name' => '常温',
|
||
'value' => 37269
|
||
]
|
||
],
|
||
58 => [
|
||
[
|
||
'diy_type' => 0,
|
||
'name' => '是',
|
||
'value' => 23964
|
||
]
|
||
],
|
||
1758 => [
|
||
[
|
||
'diy_type' => 1,
|
||
'name' => '包装',
|
||
'value' => 8197
|
||
]
|
||
],
|
||
1880 => [
|
||
[
|
||
'diy_type' => 0,
|
||
'name' => '中国大陆',
|
||
'value' => 13850
|
||
]
|
||
],
|
||
3999 => [
|
||
[
|
||
'diy_type' => 0,
|
||
'name' => self::$organic_food_license,
|
||
'value' => 0
|
||
]
|
||
],
|
||
4031 => [
|
||
[
|
||
'diy_type' => 0,
|
||
'name' => self::$food_license,
|
||
'value' => 0
|
||
]
|
||
],
|
||
2988 => [
|
||
[
|
||
'diy_type' => 0,
|
||
'name' => '18月',
|
||
'value' => 0
|
||
]
|
||
]
|
||
);
|
||
$param->product_format_new = json_encode($product_format_new, JSON_UNESCAPED_UNICODE);
|
||
|
||
// 统一规格 = 1; 多规格 = 2;
|
||
if ($goods['base']['spec_type'] == 1) {
|
||
// 在公司后台系统中有商品卖点,含有2L*2罐装(因为抖店后台有瓶数可以设置),先暂时将它添加为商品规格
|
||
$goods_spec = ($goods['item'][0]['weight'] * 2) . '斤*1瓶';
|
||
if ($goods['base']['remark']) {
|
||
$goods_spec = $goods['base']['remark'];
|
||
}
|
||
|
||
$spec = [
|
||
'spec_values' =>[
|
||
0 => [
|
||
'property_name' => '规格',
|
||
'property_id' => 0,
|
||
'values' => [
|
||
0 => [
|
||
'value_name' => $goods_spec,
|
||
'value_id' => 0
|
||
]
|
||
]
|
||
]
|
||
]
|
||
];
|
||
|
||
$spec_prices_v2 = [
|
||
0 => [
|
||
'sell_properties' => [
|
||
0 => [
|
||
'value_name' => $goods_spec,
|
||
'property_name' => '规格'
|
||
]
|
||
],
|
||
'stock_num' => $goods['item'][0]['stock'],
|
||
'price' => floatval($goods['item'][0]['price']) * 100
|
||
]
|
||
];
|
||
} else if($goods['base']['spec_type'] == 2) {
|
||
|
||
$spec_prices_v2 = [];
|
||
foreach ($goods['item'] as $k => $v) {
|
||
$spec_value_str = explode(',', $v['spec_value_str']);
|
||
// 如果产品规格向下面的规格值是多个的话
|
||
foreach ($spec_value_str as $k2 => $v2) {
|
||
// 获取spec的名称
|
||
$goods_spec_prices_v2 = ($v['weight'] * 2) . '斤*1瓶';
|
||
if ($goods['base']['remark']) {
|
||
$goods_spec_prices_v2 = $goods['base']['remark'];
|
||
}
|
||
|
||
// $res = GoodsSpec::where(['goods_id' => $goods_id]);
|
||
$spec_prices_v2[$k]['sell_properties'][0]['value_name'] = $goods_spec_prices_v2;
|
||
$spec_prices_v2[$k]['sell_properties'][0]['property_name'] = '规格'; // 先固定为口味分类(抖店后台设置了口味分类)
|
||
$spec_prices_v2[$k]['sell_properties'][1]['value_name'] = str_replace('茶油', ' ', $v2);
|
||
$spec_prices_v2[$k]['sell_properties'][1]['property_name'] = '口味分类'; // 先固定为口味分类(抖店后台设置了口味分类)
|
||
$spec_prices_v2[$k]['stock_num'] = $v['stock'];
|
||
$spec_prices_v2[$k]['price'] = floatval($v['price']) * 100;
|
||
}
|
||
}
|
||
|
||
|
||
$goods_spec = [];
|
||
foreach ($goods['spec'] as $v) {
|
||
foreach ($v['values'] as $k2 => $v2) {
|
||
$goods_spec[$k2] = array(
|
||
'value_name' => str_replace('茶油', ' ', $v2['value']),
|
||
'value_id' => 0
|
||
);
|
||
}
|
||
}
|
||
// 现有的商品中没有规格这一个规格项,所以value_name使用上面的$goods_spec_prices_v2
|
||
$spec = [
|
||
'spec_values' =>[
|
||
0 => [
|
||
'property_name' => '规格',
|
||
'property_id' => 0,
|
||
'values' => [
|
||
0 => [
|
||
'value_name' => $goods_spec_prices_v2,
|
||
'value_id' => 0
|
||
]
|
||
]
|
||
],
|
||
1 => [
|
||
'property_name' => '口味分类',
|
||
'property_id' => 0,
|
||
'values' => $goods_spec
|
||
]
|
||
]
|
||
];
|
||
}
|
||
$param->spec_info = json_encode($spec, JSON_UNESCAPED_UNICODE);
|
||
$param->spec_prices_v2 = json_encode($spec_prices_v2, JSON_UNESCAPED_UNICODE);
|
||
$param->standard_brand_id = 596120136; #品牌
|
||
|
||
$response = $request->execute($this->access_token);
|
||
|
||
if ($response->code == 10000) {
|
||
try {
|
||
GoodsLogic::updateDouDianData($goods_id, json_encode($response->data));
|
||
return $response->code;
|
||
} catch (\Exception $e) {
|
||
throw new \think\Exception($e->getMessage());
|
||
}
|
||
} else {
|
||
throw new \think\Exception($response->sub_msg);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @note 上传的商品是统一规格的
|
||
*/
|
||
public function productAddOne($goods_id)
|
||
{
|
||
// $this->getShopCategory();
|
||
// $this->getCateProperty();
|
||
// die;
|
||
$goods = GoodsLogic::info($goods_id);
|
||
$request = new \ProductAddV2Request();
|
||
$param = new \ProductAddV2Param();
|
||
$request->setParam($param);
|
||
|
||
if (isset($goods['base']['code'])) {
|
||
// 商品编码
|
||
$param->outer_product_id = $goods['base']['code'] . 20240614;
|
||
}
|
||
|
||
$param->name = $goods['base']['name'];
|
||
|
||
// 0-普通,3-虚拟,6玉石闪购,7云闪购
|
||
$param->product_type = $goods['base']['type'] == 0 ? 0 : 3;
|
||
|
||
// 叶子类目ID通过/shop/getShopCategory接口获取
|
||
$param->category_leaf_id = 28227;
|
||
|
||
// $rule = $this->getProductRule($param->category_leaf_id);
|
||
|
||
// 商品轮播图
|
||
// $param->pic = implode('|', $this->batchUploadImage($goods['base']['goods_image']));
|
||
$param->pic = 'https://p3-aio.ecombdimg.com/obj/ecom-shop-material/ALSUvYM_m_4aedee0c4d90d0488e6e8521a0555758_sx_107771_www800-800';
|
||
|
||
// 商品描述,目前只支持图片
|
||
// $doc = new DOMDocument();
|
||
// $doc->loadHTML($goods['base']['content']);
|
||
// $images = $doc->getElementsByTagName('img');
|
||
// $src = array();
|
||
// foreach ($images as $k => $image) {
|
||
//// $src[$k]['uri'] = str_replace('http://admin.dlh.com', 'https://dlh.hainings.com', $image->getAttribute('src'));
|
||
// $src[$k]['uri'] = str_replace('http://admin.dlh.com', 'https://dlh.hainings.com', 'https://dlh.hainings.com/uploads/images/20240528170003c16046671.jpg');
|
||
// $src[$k]['id'] = $goods_id . '_goods_detail_' . $k;
|
||
// }
|
||
// $param->description = implode('|', $this->batchUploadImage($src, true));
|
||
$param->description = 'https://p3-aio.ecombdimg.com/obj/ecom-shop-material/ALSUvYM_m_4aedee0c4d90d0488e6e8521a0555758_sx_107771_www800-800';
|
||
|
||
$param->quality_list = $this->getQualificationConfig($param->category_leaf_id);
|
||
|
||
// 支付方式,0货到付款 1在线支付,2,货到付款+在线支付
|
||
$param->pay_type = 1;
|
||
// 减库存类型:1-拍下减库存 2-付款减库存
|
||
$param->reduce_type = 1;
|
||
// 运费模板id,传0表示包邮,通过/freightTemplate/list接口获取
|
||
$param->freight_id = 0;
|
||
// 承诺发货时间,具体规则用/product/getProductUpdateRule获取
|
||
$param->delivery_delay_day = 2;
|
||
// 发货模式,0-现货发货,1-预售发货,2-阶梯发货,默认0
|
||
$param->presell_type = 0;
|
||
$param->after_sale_service = "{\"supply_day_return_selector\":\"7-1\"}";
|
||
// 客服号码
|
||
$param->mobile = "400123456";
|
||
$param->commit = true; #false仅保存草稿,true保存+提审
|
||
|
||
/* 这个是商品属性规格 对应的接口为 getCateProperty*/
|
||
$product_format_new = array(
|
||
2685 => [
|
||
[
|
||
'diy_type' => 0,
|
||
'name' => '永兴泰宇茶油有限公司',
|
||
'value' => 0
|
||
]
|
||
],
|
||
4118 => [
|
||
[
|
||
'diy_type' => 0,
|
||
'name' => '常温',
|
||
'value' => 37269
|
||
]
|
||
],
|
||
58 => [
|
||
[
|
||
'diy_type' => 0,
|
||
'name' => '是',
|
||
'value' => 23964
|
||
]
|
||
],
|
||
1758 => [
|
||
[
|
||
'diy_type' => 1,
|
||
'name' => '包装',
|
||
'value' => 8197
|
||
]
|
||
],
|
||
1880 => [
|
||
[
|
||
'diy_type' => 0,
|
||
'name' => '中国大陆',
|
||
'value' => 13850
|
||
]
|
||
],
|
||
3999 => [
|
||
[
|
||
'diy_type' => 0,
|
||
'name' => self::$organic_food_license,
|
||
'value' => 0
|
||
]
|
||
],
|
||
4031 => [
|
||
[
|
||
'diy_type' => 0,
|
||
'name' => self::$food_license,
|
||
'value' => 0
|
||
]
|
||
],
|
||
2988 => [
|
||
[
|
||
'diy_type' => 0,
|
||
'name' => '18月',
|
||
'value' => 0
|
||
]
|
||
]
|
||
);
|
||
// $param->product_format_new = "{\"697\":[{\"diy_type\":1,\"name\":\"旅行箱捆绑带\",\"value\":27904}]}";
|
||
$param->product_format_new = json_encode($product_format_new, JSON_UNESCAPED_UNICODE);
|
||
|
||
if ($goods['base']['spec_type'] == 1) {
|
||
// 如果商品是统一规格的话,则将重量和提交定义为规格
|
||
$spec = [
|
||
'spec_values' =>[
|
||
0 => [
|
||
'property_name' => '规格',
|
||
'property_id' => 0,
|
||
'values' => [
|
||
0 => [
|
||
'value_name' => '2L*1瓶',
|
||
'value_id' => 0
|
||
]
|
||
]
|
||
],
|
||
1 => [
|
||
'property_name' => '口味分类',
|
||
'property_id' => 0,
|
||
'values' => [
|
||
0 => [
|
||
'value_name' => '精炼',
|
||
'value_id' => 0
|
||
],
|
||
1 => [
|
||
'value_name' => '冷榨',
|
||
'value_id' => 0
|
||
],
|
||
]
|
||
]
|
||
]
|
||
];
|
||
|
||
$spec_prices_v2 = [
|
||
0 => [
|
||
'sell_properties' => [
|
||
0 => [
|
||
'value_name' => '2L*1瓶',
|
||
'property_name' => '规格'
|
||
],
|
||
1 => [
|
||
'value_name' => '精炼',
|
||
'property_name' => '口味分类'
|
||
]
|
||
],
|
||
'stock_num' => 11,
|
||
'price' => 1
|
||
],
|
||
1 => [
|
||
'sell_properties' => [
|
||
0 => [
|
||
'value_name' => '2L*1瓶',
|
||
'property_name' => '规格'
|
||
],
|
||
1 => [
|
||
'value_name' => '冷榨',
|
||
'property_name' => '口味分类'
|
||
]
|
||
],
|
||
'stock_num' => 111,
|
||
'price' => 1
|
||
]
|
||
];
|
||
}
|
||
|
||
$param->spec_info = json_encode($spec, JSON_UNESCAPED_UNICODE);
|
||
dump($param->spec_info);
|
||
$param->spec_prices_v2 = json_encode($spec_prices_v2, JSON_UNESCAPED_UNICODE);
|
||
dump($param->spec_prices_v2);
|
||
$param->standard_brand_id = 596120136; #品牌
|
||
|
||
$response = $request->execute($this->access_token);
|
||
|
||
if ($response->code == 10000) {
|
||
dump($response);
|
||
} else {
|
||
dump($response);
|
||
die;
|
||
throw new \think\Exception($response->sub_msg);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @note 批量上传图片, 图片需要按照 1:1 来上传,单张详情图高度不能超过 20000px
|
||
*/
|
||
public function batchUploadImage($data, $origin = false) {
|
||
$img = array();
|
||
foreach ($data as $k => $v) {
|
||
$img[$k]['request_id'] = $v['id'];
|
||
$img[$k]['folder_id'] = 0;
|
||
$img[$k]['name'] = pathinfo($v['uri'])['filename'];
|
||
$img[$k]['url'] = $origin ? $v['uri'] : self::$domain . '/' . $v['uri'];
|
||
$img[$k]['material_type'] = 'photo';
|
||
}
|
||
|
||
$request = new \MaterialBatchUploadImageSyncRequest();
|
||
$param = new \MaterialBatchUploadImageSyncParam();
|
||
$request->setParam($param);
|
||
$param->materials = $img;
|
||
$param->need_distinct = true;
|
||
$result = $request->execute($this->access_token);
|
||
|
||
$upload_image = [];
|
||
|
||
// 获取 byte_url
|
||
if ($result->code == 10000) {
|
||
sleep(1);
|
||
$request = new \MaterialQueryMaterialDetailRequest();
|
||
$param = new \MaterialQueryMaterialDetailParam();
|
||
$request->setParam($param);
|
||
foreach ($result->data->success_map as $v) {
|
||
$param->material_id = $v->MaterialId;
|
||
$response = $request->execute($this->access_token);
|
||
if ($response->code == 10000 && $response->data->material_info->audit_status == 3) {
|
||
$upload_image[] = $response->data->material_info->byte_url;
|
||
} else {
|
||
throw new \think\Exception($response->sub_msg);
|
||
}
|
||
}
|
||
} else {
|
||
throw new \think\Exception($result->sub_msg);
|
||
}
|
||
|
||
return $upload_image;
|
||
}
|
||
|
||
/**
|
||
* @note 获取商品类目,需要循环调用该接口获取数据
|
||
*/
|
||
private function getShopCategory($category = '粮油米面/南北干货/调味品')
|
||
{
|
||
$request = new \ShopGetShopCategoryRequest();
|
||
$param = new \ShopGetShopCategoryParam();
|
||
$request->setParam($param);
|
||
$param->cid = 0;
|
||
$response = $request->execute($this->access_token);
|
||
if ($response->code == 10000) {
|
||
// 暂时先测试箱包的类目,正常来说给到一个类目让用户选择
|
||
foreach ($response->data as $v) {
|
||
if ($v->name == $category) {
|
||
$param->cid = $v->id;
|
||
$response = $request->execute($this->access_token);
|
||
$param->cid = 21666;
|
||
$response = $request->execute($this->access_token);
|
||
dump($response);
|
||
}
|
||
}
|
||
} else {
|
||
throw new \think\Exception($response->sub_msg);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @note 获取商品类目属性列表
|
||
*/
|
||
private function getCateProperty()
|
||
{
|
||
$request = new \ProductGetCatePropertyV2Request();
|
||
$param = new \ProductGetCatePropertyV2Param();
|
||
$request->setParam($param);
|
||
// 箱包 -> 箱包配件
|
||
// $param->category_leaf_id = 23206;
|
||
// 女装 -> 半身裙
|
||
// $param->category_leaf_id = 20219;
|
||
// 28227
|
||
// 粮油米面/南北干货/调味品 > 食用油/调味油 > 山茶油
|
||
$param->category_leaf_id = 28227;
|
||
|
||
$response = $request->execute($this->access_token);
|
||
if ($response->code == 10000) {
|
||
// 输出商品类目属性
|
||
dump($response);
|
||
} else {
|
||
throw new \think\Exception($response->sub_msg);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @note 获取商品发布规则
|
||
*/
|
||
private function getProductRule($category_id)
|
||
{
|
||
$request = new \ProductGetProductUpdateRuleRequest();
|
||
$param = new \ProductGetProductUpdateRuleParam();
|
||
$request->setParam($param);
|
||
$param->category_id = $category_id;
|
||
$response = $request->execute($this->access_token);
|
||
dump($response);
|
||
die;
|
||
}
|
||
|
||
/**
|
||
* @note 获取商品资质
|
||
* 产品生产许可证和有机食品认证证书
|
||
*/
|
||
private function getQualificationConfig($category_id = 0)
|
||
{
|
||
$request = new \ProductQualificationConfigRequest();
|
||
$param = new \ProductQualificationConfigParam();
|
||
$request->setParam($param);
|
||
$param->category_id = $category_id;
|
||
$response = $request->execute($this->access_token);
|
||
if ($response->code == 10000) {
|
||
$quality[0]['quality_key'] = $response->data->config_list[0]->key;
|
||
$quality[0]['quality_name'] = $response->data->config_list[0]->name;
|
||
$quality[0]['quality_attachments'] = array(
|
||
'media_type' => 1,
|
||
'url' => 'https://p3-aio.ecombdimg.com/obj/ecom-shop-material/IHXLRhYg_m_313829285416363f56963d5a561e1c2c_sx_289105_www1996-1408'
|
||
);
|
||
|
||
$quality[1]['quality_key'] = $response->data->config_list[1]->key;
|
||
$quality[1]['quality_name'] = $response->data->config_list[1]->name;
|
||
$quality[1]['quality_attachments'] = array(
|
||
'media_type' => 1,
|
||
'url' => 'https://p3-aio.ecombdimg.com/obj/ecom-shop-material/IHXLRhYg_m_9fb63d4f266d7eed01bb97833da1ab25_sx_363931_www1433-2000'
|
||
);
|
||
return $quality;
|
||
} else {
|
||
throw new \think\Exception('资质证书获取失败');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @note 获取商家品牌列表
|
||
* 产品生产许可证和有机食品认证证书
|
||
*/
|
||
private function getBrand($category_id)
|
||
{
|
||
$request = new \BrandListRequest();
|
||
$param = new \BrandListParam();
|
||
$request->setParam($param);
|
||
$param->category_id = $category_id;
|
||
$response = $request->execute($this->access_token);
|
||
dump($response);
|
||
die;
|
||
}
|
||
|
||
public function testProductAdd()
|
||
{
|
||
$request = new \ProductAddV2Request();
|
||
$param = new \ProductAddV2Param();
|
||
$request->setParam($param);
|
||
$param->product_type = 0; #0-普通,3-虚拟
|
||
$param->category_leaf_id = 20219;
|
||
$param->name = "半身裙夏季时尚裙-标准sku-大田";
|
||
$param->pic = "https://p3-aio.ecombdimg.com/obj/ecom-shop-material/v1_ALSUvYM_70630259408755264040798_16991a88a61d1a1f4ab8bc526fcb7762_sx_388998_www800-800|https://p3-aio.ecombdimg.com/obj/ecom-shop-material/ALSUvYM_m_1ca7af9ff5adb5687879c18484d72777_sx_190683_www800-800|https://p3-aio.ecombdimg.com/obj/ecom-shop-material/v1_ALSUvYM_70526582776577067660798_51d5ff356da0f3664980f84a9029bedb_sx_24925_www800-800";
|
||
$param->description = "https://p3-aio.ecombdimg.com/obj/ecom-shop-material/v1_ALSUvYM_70526582776577067660798_51d5ff356da0f3664980f84a9029bedb_sx_24925_www800-800";
|
||
$param->pay_type = 1; #1在线支付
|
||
$param->reduce_type = 1;#减库存类型:1-拍下减库存 2-付款减库存
|
||
$param->freight_id = 0; #运费模板 通过/freightTemplate/list接口获取
|
||
$param->delivery_delay_day = 2; # 承诺发货时间,具体规则用/product/getProductUpdateRule获取
|
||
$param->presell_type = 0; #发货模式,0-现货发货,1-预售发货,2-阶梯发货,默认0
|
||
$param->after_sale_service = "{\"supply_day_return_selector\":\"7-1\"}";
|
||
$param->mobile = "400123456"; #抖店后台不展示,后续会考虑下线
|
||
$param->commit = "true"; #false仅保存草稿,true保存+提审
|
||
$param->product_format_new = "{\"241\":[{\"diy_type\":1,\"name\":\"常规款\",\"value\":17314}],\"631\":[{\"diy_type\":1,\"name\":\"东西南北风\",\"value\":0}],\"785\":[{\"measure_info\":{\"values\":[{\"module_id\":582,\"value\":\"亚麻\",\"unit_id\":0},{\"module_id\":583,\"unit_name\":\"%\",\"unit_id\":15,\"value\":\"100\"}],\"template_id\":252,\"value_name\":\"亚麻100%\"},\"diy_type\":1,\"name\":\"亚麻100%\",\"value\":0}],\"813\":[{\"diy_type\":1,\"name\":\"X型\",\"value\":8017}],\"981\":[{\"diy_type\":1,\"name\":\"蛋糕裙\",\"value\":22253}],\"1467\":[{\"diy_type\":0,\"name\":\"59%-69%(含)\",\"value\":168368}],\"1551\":[{\"diy_type\":1,\"name\":\"超短裙\",\"value\":22064}],\"1687\":[{\"diy_type\":0,\"name\":\"\",\"value\":0}],\"1878\":[{\"diy_type\":1,\"name\":\"高腰\",\"value\":16521}],\"2592\":[{\"diy_type\":1,\"name\":\"甜美风\",\"value\":192481}]}";
|
||
$param->standard_brand_id = 596120136; #品牌
|
||
# $param->presell_config_level = 2
|
||
$param->size_info_template_id = 7119681499770667267; #尺码模板id https://op.jinritemai.com/docs/guide-docs/242/2094
|
||
$param->spec_info = '{"spec_values":[{"property_name":"颜色分类","property_id":2752,"values":[{"value_name":"白色","value_id":35497}]},{"property_name":"尺码大小","property_id":4704,"values":[{"value_name":"M","value_id":0}]}]}';
|
||
$param->spec_prices_v2 ="[{\"sell_properties\":[{\"value_name\":\"白色\",\"property_name\":\"颜色分类\"},{\"value_name\":\"M\",\"property_name\":\"尺码大小\"}],\"stock_num\":11,\"price\":1,\"code\":\"这个就是抖店后台的sku商家编码\"}]";
|
||
$response = $request->execute($this->access_token);
|
||
dump($response);
|
||
}
|
||
|
||
/**
|
||
* @note 获取抖店access_token
|
||
*/
|
||
public function getToken()
|
||
{
|
||
return \AccessTokenBuilder::build(self::$shopId, ACCESS_TOKEN_SHOP_ID);
|
||
}
|
||
|
||
/**
|
||
* @note 刷新抖店access_token
|
||
*/
|
||
public function refreshToken($token) {
|
||
return \AccessTokenBuilder::refresh($token);
|
||
}
|
||
} |