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