完善抖店品牌获取
This commit is contained in:
parent
de65f46aa9
commit
efaf0b0ef9
@ -33,12 +33,17 @@ const ONE_SPEC_WEIGHT = 00001;
|
||||
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 = 4463798;
|
||||
private static $shopId = SHOP_ID;
|
||||
private static $specName = array(
|
||||
'颜色' => '颜色分类',
|
||||
'尺寸' => '尺码大小'
|
||||
@ -201,10 +206,10 @@ class DouDianServer
|
||||
$param = new \ProductAddV2Param();
|
||||
$request->setParam($param);
|
||||
|
||||
if (isset($goods['base']['code'])) {
|
||||
// 自己的后台商品编码
|
||||
$param->outer_product_id = $goods['base']['code'] + 2;
|
||||
}
|
||||
// if (isset($goods['base']['code'])) {
|
||||
// // 自己的后台商品编码
|
||||
// $param->outer_product_id = $goods['base']['code'] + 6;
|
||||
// }
|
||||
|
||||
$param->name = $goods['base']['name'];
|
||||
|
||||
@ -214,6 +219,9 @@ class DouDianServer
|
||||
// 叶子类目ID通过/shop/getShopCategory接口获取
|
||||
$param->category_leaf_id = 28227;
|
||||
|
||||
// 获取商品品牌,泰宇品牌ID:1804083496
|
||||
// $this->getBrand($param->category_leaf_id);
|
||||
|
||||
// 获取商品发布规则
|
||||
// $rule = $this->getProductRule($param->category_leaf_id);
|
||||
|
||||
@ -253,7 +261,7 @@ class DouDianServer
|
||||
$param->mobile = "400123456";
|
||||
$param->commit = true; #false仅保存草稿,true保存+提审
|
||||
|
||||
/* 这个是商品属性规格 对应的接口为 getCateProperty*/
|
||||
/* 这个是商品属性规格 对应的接口为 getCateProperty, 以下必填项可以参考抖店商家类目数据*/
|
||||
$product_format_new = array(
|
||||
2685 => [
|
||||
[
|
||||
@ -368,7 +376,7 @@ class DouDianServer
|
||||
$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']);
|
||||
$spec_prices_v2[$k]['price'] = floatval($v['price']) * 100;
|
||||
}
|
||||
}
|
||||
|
||||
@ -376,7 +384,6 @@ class DouDianServer
|
||||
$goods_spec = [];
|
||||
foreach ($goods['spec'] as $v) {
|
||||
foreach ($v['values'] as $k2 => $v2) {
|
||||
dump($v2);
|
||||
$goods_spec[$k2] = array(
|
||||
'value_name' => str_replace('茶油', ' ', $v2['value']),
|
||||
'value_id' => 0
|
||||
@ -403,52 +410,21 @@ class DouDianServer
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
// $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
|
||||
// ]
|
||||
// ];
|
||||
// dump($spec_prices_v2);
|
||||
}
|
||||
$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);
|
||||
try {
|
||||
GoodsLogic::updateDouDianData($goods_id, json_encode($response->data));
|
||||
return $response->code;
|
||||
} catch (\Exception $e) {
|
||||
throw new \think\Exception($e->getMessage());
|
||||
}
|
||||
} else {
|
||||
dump($response);
|
||||
die;
|
||||
throw new \think\Exception($response->sub_msg);
|
||||
}
|
||||
}
|
||||
@ -797,6 +773,21 @@ class DouDianServer
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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();
|
||||
|
||||
@ -68,7 +68,9 @@ class Goods extends ShopBase
|
||||
$cate_list = MallCategoryLogic::categoryTreeeTree();
|
||||
$shop_cate_list = ShopCategoryLogic::listAll($this->shop_id);
|
||||
$statistics = GoodsLogic::statistics($this->shop_id);
|
||||
|
||||
return view('', [
|
||||
'shop_id' => $this->shop_id,
|
||||
'statistics' => $statistics,
|
||||
'cate_list' => $cate_list, //平台分类
|
||||
'shop_cate_list' => $shop_cate_list, //商家分类
|
||||
@ -385,51 +387,33 @@ class Goods extends ShopBase
|
||||
return JsonServer::error(GoodsLogic::getError());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 同步到抖店
|
||||
*/
|
||||
public function syncDouDian()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$goods_id = $this->request->post('id');
|
||||
// 目前仅限于泰宇店
|
||||
if ($this->shop_id === 4) {
|
||||
try {
|
||||
$doudian = new DouDianServer();
|
||||
if ($doudian->camelliaProduct($goods_id) == 10000) {
|
||||
return JsonServer::success('同步成功');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return JsonServer::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 导出Excel
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
// $goods = GoodsLogic::info(733);
|
||||
// $spec = [];
|
||||
// foreach ($goods['spec'] as $k => $v) {
|
||||
// $spec['spec_values'][$k]['property_name'] = $v['name'];
|
||||
// $spec['spec_values'][$k]['property_id'] = $v['id'];
|
||||
// foreach ($v['values'] as $k2 => $v2) {
|
||||
// $spec['spec_values'][$k]['values'][$k2] = array(
|
||||
// 'values' => array(
|
||||
// 'value_name' => $v2['value'],
|
||||
// 'value_id' => $v2['id']
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// $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' => 733])->select();
|
||||
// $spec_list[$k]['sell_properties'][$k2]['value_name'] = $v2;
|
||||
// $spec_list[$k]['sell_properties'][$k2]['property_name'] = $res[$k2]['name'];
|
||||
// $spec_list[$k]['stock_num'] = $v['stock'];
|
||||
// $spec_list[$k]['price'] = $v['price'];
|
||||
// }
|
||||
// }
|
||||
// dump($spec);
|
||||
// dump($spec_list);
|
||||
// die;
|
||||
try {
|
||||
$doudian = new DouDianServer();
|
||||
// $result = $doudian->productAdd(736);
|
||||
// $result = $doudian->productAddOne(13);
|
||||
// $result = $doudian->camelliaProduct(13);
|
||||
$result = $doudian->camelliaProduct(27);
|
||||
} catch (Exception $e) {
|
||||
return JsonServer::error($e->getMessage());
|
||||
}
|
||||
// $doudian->testProductAdd();
|
||||
die;
|
||||
$result = GoodsLogic::exportData($this->shop_id);
|
||||
if(false === $result) {
|
||||
return JsonServer::error(OrderLogic::getError() ?: '导出失败');
|
||||
|
||||
@ -1283,4 +1283,23 @@ class GoodsLogic extends Logic
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @note 抖店上传成功的数据同步到数据表里面
|
||||
*/
|
||||
public static function updateDouDianData($goods_id, $data)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
Goods::where(['id' => $goods_id])->update([
|
||||
'doudian_data' => $data
|
||||
]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,6 +107,11 @@
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="goods-operation">
|
||||
{if condition="$shop_id eq 4"}
|
||||
{{# if( d.del != 2 ){ }}
|
||||
<a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="sync_doudian">同步抖店</a>
|
||||
{{# } }}
|
||||
{/if}
|
||||
{{# if( d.del != 2 ){ }}
|
||||
<a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="edit">编辑</a>
|
||||
{{# } }}
|
||||
@ -274,6 +279,32 @@
|
||||
table.on('tool(goods-lists)', function(obj){
|
||||
var id = obj.data.id;
|
||||
var name = obj.data.name;
|
||||
|
||||
//商品同步到抖店
|
||||
if (obj.event === 'sync_doudian') {
|
||||
layer.confirm('是否同步到抖店', function(){
|
||||
like.ajax({
|
||||
url:'{:url("goods.goods/syncDouDian")}',
|
||||
data:{id:id},
|
||||
type:'post',
|
||||
dataType:'json',
|
||||
success:function (res) {
|
||||
if(res.code == 1) {
|
||||
console.log(res)
|
||||
layui.layer.msg(res.msg, {
|
||||
offset: '15px'
|
||||
, icon: 1
|
||||
, time: 2000
|
||||
}, function () {
|
||||
// updateTabNumber();
|
||||
// table.reload('goods-lists');
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
//上下架
|
||||
if(obj.event === 'status'){
|
||||
var tips = '确定上架当前商品:'+'<span style="color: red">'+name+'</span>';
|
||||
@ -450,7 +481,7 @@
|
||||
,{field: 'audit_remark', width: 180, title: '审核说明', align: 'center'}
|
||||
,{field: 'sort',width: 80, title:'排序', align: 'center'}
|
||||
,{field: 'create_time',width:160, title:'发布日期', align: 'center'}
|
||||
,{fixed: 'right', title: '操作', width:250, align: 'center', toolbar: '#goods-operation'}
|
||||
,{fixed: 'right', title: '操作', width:350, align: 'center', toolbar: '#goods-operation'}
|
||||
]);
|
||||
// if(type == 6) { // 审核未通过,显示审核说明列(注意计时器时间控制,先让动态表格渲染完成,再去移除layui-hide)
|
||||
// setTimeout(function() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user