From 67272befaa51c84f8ffb5ea2026d94264ec5b24f Mon Sep 17 00:00:00 2001 From: zyh Date: Mon, 21 Oct 2024 11:25:38 +0800 Subject: [PATCH 1/4] 123 --- app/common/service/Jd.php | 73 +++++++++++++++++++++++----------- app/store/controller/Goods.php | 15 +++++++ 2 files changed, 64 insertions(+), 24 deletions(-) diff --git a/app/common/service/Jd.php b/app/common/service/Jd.php index 7367ddab..1c16d490 100644 --- a/app/common/service/Jd.php +++ b/app/common/service/Jd.php @@ -1,4 +1,5 @@ $provinceId, 'cityId' => $cityId, @@ -33,18 +36,18 @@ class Jd extends BaseService { //exit(); $curl = curl_init(); curl_setopt_array($curl, array( - CURLOPT_URL => 'https://vapi.jd.com/index/sku/getAsynDetail?'.http_build_query($data), - CURLOPT_RETURNTRANSFER => true, - CURLOPT_ENCODING => '', - CURLOPT_MAXREDIRS => 10, - CURLOPT_TIMEOUT => 0, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, - CURLOPT_CUSTOMREQUEST => 'GET', - CURLOPT_HTTPHEADER => array( - 'Host: vapi.jd.com', - 'Referer: https://bpro.jd.com/' - ), + CURLOPT_URL => 'https://vapi.jd.com/index/sku/getAsynDetail?' . http_build_query($data), + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_HTTPHEADER => array( + 'Host: vapi.jd.com', + 'Referer: https://bpro.jd.com/' + ), )); $response = curl_exec($curl); @@ -65,9 +68,10 @@ class Jd extends BaseService { * @param [type] $skuId [description] * @return [type] [description] */ - public function getGoodsMainImageAndDetail($skuId){ + public function getGoodsMainImageAndDetail($skuId) + { //$url = "http://47.98.251.206:8811/api/goods/info/v2?sku=".$skuId."&areaId="; - $url = "http://8.130.98.31:8811/api/goods/info/v2?sku=".$skuId."&areaId="; + $url = "http://8.130.98.31:8811/api/goods/info/v2?sku=" . $skuId . "&areaId="; $res = httpRequest($url); if ($res && $res['code'] == 0 && isset($res['data'])) { return $res['data']; @@ -81,9 +85,10 @@ class Jd extends BaseService { * @param [type] $skuId [description] * @return [type] [description] */ - public function getJdShortLink($skuId){ + public function getJdShortLink($skuId) + { //$url = "http://47.98.251.206:8811/api/goods/info/v2?sku=".$skuId."&areaId="; - $url = "http://8.130.98.31:8811/api/link?sku=".$skuId; + $url = "http://8.130.98.31:8811/api/link?sku=" . $skuId; $res = httpRequest($url); if ($res && $res['code'] == 0 && isset($res['data'])) { return $res['data']; @@ -91,13 +96,33 @@ class Jd extends BaseService { return ""; } + /** + * 获取京东短链接 + * [getJdShortLink description] + * @param [type] $skuId [description] + * @return [type] [description] + */ + public function getJdShortLinks($skuData) + { + //$url = "http://47.98.251.206:8811/api/goods/info/v2?sku=".$skuId."&areaId="; + // 确保 $skuData 是一个数组,并且包含 'ids' 键 + if (is_array($skuData) && isset($skuData['goods_on']) && is_array($skuData['goods_on'])) { + $skuIds = $skuData['goods_on']; + } else { + // 如果传入的不是一个有效的数组,返回错误信息或抛出异常 + return "无效的输入数据"; + } + // 将数组转换为逗号分隔的字符串 + $skuIdStr = implode(',', $skuIds); + // 构建 URL + $url = "http://8.130.98.31:8811/api/link?sku=" . urlencode($skuIdStr); - - - - - - + $res = httpRequest($url); + if ($res && $res['code'] == 0 && isset($res['data'])) { + return $res['data']; + } + return ""; + } } diff --git a/app/store/controller/Goods.php b/app/store/controller/Goods.php index 22d64f04..2af11818 100644 --- a/app/store/controller/Goods.php +++ b/app/store/controller/Goods.php @@ -627,4 +627,19 @@ class Goods extends Controller return $this->renderSuccess('操作成功'); } + + public function selectSku() + { + $model = new jd(); + $list = $model->getJdShortLinks($this->postForm()); + return $this->renderSuccess(compact('list')); + + } + + public function JDShortLinks() + { + $detail = ModelTipoff::where('id',$this->request->param('id'))->select()->toArry(); + $JdModel = new jd(); + } + } From 742bb974cbf772b1dba009f2478609f23e6ebb50 Mon Sep 17 00:00:00 2001 From: zyh Date: Mon, 21 Oct 2024 17:46:20 +0800 Subject: [PATCH 2/4] 123 --- app/common/model/Tipoff.php | 5 ++ app/common/service/Jd.php | 14 ++--- app/store/controller/Goods.php | 99 +++++++++++++++++++++++++++++++++- 3 files changed, 106 insertions(+), 12 deletions(-) diff --git a/app/common/model/Tipoff.php b/app/common/model/Tipoff.php index 3e066bee..cc35b4e0 100644 --- a/app/common/model/Tipoff.php +++ b/app/common/model/Tipoff.php @@ -88,5 +88,10 @@ class Tipoff extends BaseModel } + public function addGoods(int $id ,array $data) + { + + return $this->where('id', $id)->update($data); + } } diff --git a/app/common/service/Jd.php b/app/common/service/Jd.php index 1c16d490..e7a35cfc 100644 --- a/app/common/service/Jd.php +++ b/app/common/service/Jd.php @@ -102,24 +102,16 @@ class Jd extends BaseService * @param [type] $skuId [description] * @return [type] [description] */ - public function getJdShortLinks($skuData) + public function getJdShortLinks($skuIds) { //$url = "http://47.98.251.206:8811/api/goods/info/v2?sku=".$skuId."&areaId="; // 确保 $skuData 是一个数组,并且包含 'ids' 键 - if (is_array($skuData) && isset($skuData['goods_on']) && is_array($skuData['goods_on'])) { - $skuIds = $skuData['goods_on']; - } else { - // 如果传入的不是一个有效的数组,返回错误信息或抛出异常 - return "无效的输入数据"; - } - // 将数组转换为逗号分隔的字符串 $skuIdStr = implode(',', $skuIds); - // 构建 URL - $url = "http://8.130.98.31:8811/api/link?sku=" . urlencode($skuIdStr); + $url = "http://8.130.98.31:8811/api/link?sku=" . $skuIdStr; - $res = httpRequest($url); + $res = httpRequest($url, 'GET', null, [], false, 100); if ($res && $res['code'] == 0 && isset($res['data'])) { return $res['data']; } diff --git a/app/store/controller/Goods.php b/app/store/controller/Goods.php index 100aab53..f4e248fa 100644 --- a/app/store/controller/Goods.php +++ b/app/store/controller/Goods.php @@ -26,6 +26,7 @@ use app\job\controller\goods\StoreGoodsDelete as StoreGoodsDeleteJob; use app\common\service\Jd; use app\common\model\wxapp\Setting as WxappSettingModel; use EasyWeChat\Factory; +use app\common\model\PriceSet; /** * 商品管理控制器 @@ -640,10 +641,106 @@ class Goods extends Controller } + + /** + * 线报预览 + */ public function JDShortLinks() { - $detail = ModelTipoff::where('id',$this->request->param('id'))->select()->toArry(); + $id = $this->request->param('id'); + $detail = ModelTipoff::where('id',$id)->find(); + $goodsList = GoodsModel::whereIn("goods_id",$detail['goods_id'])->field('goods_id,goods_name,goods_price_min,cost_price_min,goods_no')->select(); + $goods_no = []; + $JdModel = new jd(); + + $goods_no = array_column($goodsList->toArray(), 'goods_no'); + + $jd_url = $JdModel->getJdShortLinks($goods_no); + $jd_url = array_column($jd_url, null, 'sku'); + + foreach ($goodsList as $key => &$value) { + $cates = GoodsCategoryRel::where('goods_id', $value['goods_id'])->select()->toArray(); + $value['jd_short_url'] = $jd_url[$value['goods_no']]['link'] ?? ""; + //分类 + if ($cates) { + //会员价 + $value['membership_price'] = \app\common\model\PriceSet::membershipPrice($value['goods_price_min'], $value['cost_price_min'], array_column($cates, 'category_id')); + } + } + + + return $this->renderSuccess(compact('goodsList')); + } + + /** + * 数据回显 + */ + public function getGoodsTipoff() + { + $id = $this->request->param('id'); + $detail = ModelTipoff::where('id',$id)->find(); + if(empty($detail)){ + return $this->renderError('暂无线报商品'); + } + + $goodsList = GoodsModel::whereIn("goods_id",$detail['goods_id'])->select(); + return $this->renderSuccess(compact('goodsList')); + } + + /** + * 一键添加商品 + * @return Json + * @throws BaseException + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function addGoodsTipoff(int $id) + { + + $model = new ModelTipoff; + + if (!$model->addGoods($id,$this->postForm())) { + return $this->renderError($model->getError()); + } + return $this->renderSuccess('成功添加线报商品'); + + } + + /** + * 清除线报商品 + */ + public function clearTipoffGoods(int $id): Json + { + + $result = ModelTipoff::where('id', $id)->update(['goods_id' => null]); + + if ($result > 0) { + return $this->renderSuccess('清除成功'); + } else { + return $this->renderError('清除失败,没有找到对应的记录'); + } } + /** + * 一键添加商品 + * @return Json + * @throws BaseException + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function updateGoodsTipoff(int $id) + { + + $model = new ModelTipoff; + + if (!$model->addGoods($id,$this->postForm())) { + return $this->renderError($model->getError()); + } + return $this->renderSuccess('成功添加线报商品'); + + } + } From 33683c3d6df6171bf5b9bd2848f610f6385cb5ae Mon Sep 17 00:00:00 2001 From: zyh Date: Mon, 21 Oct 2024 17:49:06 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E7=BA=BF=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/Goods.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index 9e3f126b..3cb04b32 100644 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -544,4 +544,19 @@ class Goods extends Controller } + /** + * 数据回显 + */ + public function getGoodsTipoff() + { + $id = $this->request->param('id'); + $detail = ModelTipoff::where('id',$id)->find(); + if(empty($detail)){ + return $this->renderError('暂无线报商品'); + } + + $goodsList = GoodsModel::whereIn("goods_id",$detail['goods_id'])->select(); + return $this->renderSuccess(compact('goodsList')); + } + } From 14c4ebd8eb0ed2cfcf9bfc4c36bfd487797b6a26 Mon Sep 17 00:00:00 2001 From: zengyyh Date: Mon, 21 Oct 2024 16:42:54 +0800 Subject: [PATCH 4/4] 123 --- app/api/controller/Goods.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index 3cb04b32..437003f8 100644 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -21,6 +21,7 @@ use app\api\service\Setting as SettingService; use app\common\service\GoodsCateEs; use app\common\service\Jd; use app\common\model\Tipoff as ModelTipoff; +use app\common\model\GoodsCategoryRel; /** * 商品控制器 @@ -559,4 +560,32 @@ class Goods extends Controller return $this->renderSuccess(compact('goodsList')); } + public function JDShortLinks() + { + $id = $this->request->param('id'); + $detail = ModelTipoff::where('id',$id)->find(); + $goodsList = GoodsModel::whereIn("goods_id",$detail['goods_id'])->field('goods_id,goods_name,goods_price_min,cost_price_min,goods_no')->select(); + $goods_no = []; + + $JdModel = new jd(); + + $goods_no = array_column($goodsList->toArray(), 'goods_no'); + + $jd_url = $JdModel->getJdShortLinks($goods_no); + $jd_url = array_column($jd_url, null, 'sku'); + + foreach ($goodsList as $key => &$value) { + $cates = GoodsCategoryRel::where('goods_id', $value['goods_id'])->select()->toArray(); + $value['jd_short_url'] = $jd_url[$value['goods_no']]['link'] ?? ""; + //分类 + if ($cates) { + //会员价 + $value['membership_price'] = \app\common\model\PriceSet::membershipPrice($value['goods_price_min'], $value['cost_price_min'], array_column($cates, 'category_id')); + } + } + + + return $this->renderSuccess(compact('goodsList')); + } + }