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('成功添加线报商品'); + + } + }