diff --git a/app/common/server/doudian/DouDianServer.php b/app/common/server/doudian/DouDianServer.php index d0a3e9ed..87dbe467 100644 --- a/app/common/server/doudian/DouDianServer.php +++ b/app/common/server/doudian/DouDianServer.php @@ -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(); diff --git a/app/shop/controller/goods/Goods.php b/app/shop/controller/goods/Goods.php index df9d0a1a..2b33823b 100644 --- a/app/shop/controller/goods/Goods.php +++ b/app/shop/controller/goods/Goods.php @@ -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() ?: '导出失败'); diff --git a/app/shop/logic/goods/GoodsLogic.php b/app/shop/logic/goods/GoodsLogic.php index 2cb41bc6..9d21d35b 100644 --- a/app/shop/logic/goods/GoodsLogic.php +++ b/app/shop/logic/goods/GoodsLogic.php @@ -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; + } + } } diff --git a/app/shop/view/goods/goods/lists.html b/app/shop/view/goods/goods/lists.html index a5a3b119..4e6e6e6f 100644 --- a/app/shop/view/goods/goods/lists.html +++ b/app/shop/view/goods/goods/lists.html @@ -107,6 +107,11 @@