Merge branch 'lszyh'

lszyh
zyh 1 month ago
commit f03594d6fe
  1. 44
      app/api/controller/Goods.php
  2. 5
      app/common/model/Tipoff.php
  3. 69
      app/common/service/Jd.php
  4. 112
      app/store/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;
/**
* 商品控制器
@ -544,4 +545,47 @@ 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'));
}
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'));
}
}

@ -88,5 +88,10 @@ class Tipoff extends BaseModel
}
public function addGoods(int $id ,array $data)
{
return $this->where('id', $id)->update($data);
}
}

@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace app\common\service;
@ -8,7 +9,8 @@ namespace app\common\service;
/**
* 京东服务
*/
class Jd extends BaseService {
class Jd extends BaseService
{
/**
* 获取京东商品库存
@ -20,7 +22,8 @@ class Jd extends BaseService {
* @param integer $skuNum [description]
* @return [type] [description]
*/
public function getGoodsStock($provinceId, $cityId, $countyId,$skuId, $skuNum = 1){
public function getGoodsStock($provinceId, $cityId, $countyId, $skuId, $skuNum = 1)
{
$data = [
'provinceId' => $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,25 @@ class Jd extends BaseService {
return "";
}
/**
* 获取京东短链接
* [getJdShortLink description]
* @param [type] $skuId [description]
* @return [type] [description]
*/
public function getJdShortLinks($skuIds)
{
//$url = "http://47.98.251.206:8811/api/goods/info/v2?sku=".$skuId."&areaId=";
// 确保 $skuData 是一个数组,并且包含 'ids' 键
// 将数组转换为逗号分隔的字符串
$skuIdStr = implode(',', $skuIds);
// 构建 URL
$url = "http://8.130.98.31:8811/api/link?sku=" . $skuIdStr;
$res = httpRequest($url, 'GET', null, [], false, 100);
if ($res && $res['code'] == 0 && isset($res['data'])) {
return $res['data'];
}
return "";
}
}

@ -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;
/**
* 商品管理控制器
@ -631,4 +632,115 @@ 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()
{
$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('成功添加线报商品');
}
}

Loading…
Cancel
Save