...
|
...
|
@@ -101,7 +101,7 @@ class Cart extends Api |
|
|
* @ApiMethod (GET)
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="cart_id", type="integer", required=true, description="购物车ID")
|
|
|
* @ApiParams (name="goods_style", type="object", required=true, sample="{'1':'11','5':'15','7':'2','14':'25','15':'\/uploads\/20200711\/3689359dcdf1146d234930cae4958110.jpg','13':'21','12':'18'}", description="商品规格 {'风格ID':'规格值'}")
|
|
|
* @ApiParams (name="goods_style", type="object", required=true, sample="{'1':'11','5':'15','7':'2','14':'25','15':'\/uploads\/20200711\/3689359dcdf1146d234930cae4958110.jpg','13':'21','12':'18'}", description="商品风格 {'风格ID':'规格值'}")
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
|
...
|
...
|
@@ -127,6 +127,38 @@ class Cart extends Api |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 购物车-修改规格
|
|
|
* @ApiMethod (GET)
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="cart_id", type="integer", required=true, description="购物车ID")
|
|
|
* @ApiParams (name="spec_sku_id", type="string", required=true, sample="1_5", description="商品规格")
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
|
|
|
* @ApiReturn ({
|
|
|
'code':'1',
|
|
|
'msg':'返回成功'
|
|
|
})
|
|
|
*/
|
|
|
public function editGoodsSpec(){
|
|
|
$cart_id = $this->request->request('cart_id',0);
|
|
|
$spec_sku_id = $this->request->request('spec_sku_id','');
|
|
|
$cart = $this->model->get($cart_id);
|
|
|
empty($cart) && $this->error(__('购物车信息不存在'));
|
|
|
empty($spec_sku_id) && $this->error(__('请选择规格'));
|
|
|
// 检查库存
|
|
|
$goods = Goods::get($cart['goods_id'],['spec_rel.spec']);
|
|
|
$goods_sku = $goods->getGoodsSku($spec_sku_id);
|
|
|
if($goods['ismake'] == '0' && $goods_sku['stock_num'] < $cart['goods_num']){
|
|
|
$this->error(__('商品库存不足'.$cart['goods_num'].'件'));
|
|
|
}
|
|
|
$cart->spec_sku_id = $spec_sku_id;
|
|
|
$cart->goods_price = $goods_sku['goods_price'];
|
|
|
$cart->save();
|
|
|
$this->success(__('成功'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 购物车-修改商品数量
|
|
|
* @ApiMethod (GET)
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
...
|
...
|
@@ -146,6 +178,11 @@ class Cart extends Api |
|
|
$cart = $this->model->get($cart_id);
|
|
|
empty($cart) && $this->error(__('购物车信息不存在'));
|
|
|
$goods_num < 1 && $this->error(__('商品数量不能小于1'));
|
|
|
$goods = Goods::get($cart['goods_id'],['spec_rel.spec']);
|
|
|
$goods_sku = $goods->getGoodsSku($cart['spec_sku_id']);
|
|
|
if($goods['ismake'] == '0' && $goods_sku['stock_num'] < $goods_num){
|
|
|
$this->error(__('商品库存不足'.$goods_num.'件'));
|
|
|
}
|
|
|
$cart->goods_num = $goods_num;
|
|
|
$cart->save();
|
|
|
$this->success(__('成功'));
|
...
|
...
|
|