@ -77,48 +77,63 @@ class Goods extends Controller
{
// wmc商品详情
$params = $this->request->param();
$goods = GoodsModel::where('goods_id', $params['goods_id'])->find();
if (!$goods) {
return $this->renderError('商品不存在');
if (!$params['list'] || !$params['province'] || !$params['city'] || !$params['district']) {
return $this->renderError('参数错误!');
}
$return = [];
foreach ($params['list'] as $value) {
$res = "无货";
$goods = GoodsModel::where('goods_id', $value['goods_id'])->find();
switch ($goods->channel) {
case 'sn':
$city = Region::where('name',$params['city'])->where('level',2)->find();
$district = Region::where('name',$params['district'])->where('level',3)->find();
// var_dump($city);
// var_dump($district);
$suning = new \app\common\service\Suning();
$goods->num = $param['num'] ?? 1;
$ret = $suning->shoppingCartPrice([$goods->toArray()], $city->sn_code, $district->sn_code);
if ($ret & & $ret[0]['state'] == 1) {
$res = "有货";
}
$data = $suning->shoppingCartPrice([$goods->toArray()], $city->sn_code, $district->sn_code);
$data['goods_name'] = $goods['goods_name'];
$data['goods_id'] = $goods['goods_id'];
break;
case 'jd':
$province = Region::where('name',$params['province'])->where('level',1)->find();
$city = Region::where('name',$params['city'])->where('level',2)->find();
$district = Region::where('name',$params['district'])->where('level',3)->find();
$jd = new \app\common\service\Jd();
$goods->num = $params['num'] ?? 1;
$ret = $jd->getGoodsStock($province->jd_code, $city->jd_code, $district->jd_code, $goods['goods_no'], $params['num'] ?? 1);
$arr = [];
$ret = $jd->getGoodsStock($province->jd_code, $city->jd_code, $district->jd_code, $goods['goods_no'], $value['num'] ?? 1);
if ($ret) {
$res = $ret['stockResp']['desc'];
if (strpos($res, "无货") == true) {
if (strpos($res, "无货") !== fals e) {
$res = "无货";
} elseif (strpos($res, "有货") == tru e) {
} elseif (strpos($res, "有货") == fals e) {
$res = "有货";
}
// echo "< pre > ";
// print_r($ret);
// exit;
}
$data = [
'state'=> $res,
'goods_name'=> $goods['goods_name'],
'goods_id'=> $goods['goods_id'],
];
break;
default:
if ($goods->stock_total > ($params ['num'] ?? 1)) {
if ($goods->stock_total > ($value ['num'] ?? 1)) {
$res = "有货";
}
$data = [
'state'=> $res,
'goods_name'=> $goods['goods_name'],
'goods_id'=> $goods['goods_id'],
];
break;
}
return $this->renderSuccess(['stock' => $res]);
$return[] = $data;
}
return $this->renderSuccess($return);
}
public function browseLog(): Json
{