作者 何书鹏
1 个管道 的构建 通过 耗费 1 秒

测试购物车

... ... @@ -191,12 +191,14 @@ class Cart extends Api
})
*/
public function editGoodsNum($cart_id,$goods_num){
halt($cart_id);
$cart = $this->model->get($cart_id);
empty($cart) && $this->error(__('购物车信息不存在'));
$goods_num < 1 && $this->error(__('商品数量不能小于1'));
halt($cart['spec']->toArray());
if($cart['goods']['ismake'] == '0' && $cart['spec']['stock_num'] < $goods_num){
// 检查库存
$goods = Goods::get($cart['goods_id'],['spec_rel.spec']);
$goods_sku = $goods->getGoodsSku($cart['spec_sku_id']);
halt($goods_sku);
if($goods['ismake'] == '0' && $goods_sku['stock_num'] < $goods_num){
$this->error(__('商品库存不足'.$goods_num.'件'));
}
$cart->goods_num = $goods_num;
... ...
... ... @@ -40,15 +40,6 @@ class Cart extends Model
}
/**
* 关联商品规格表
* @return \think\model\relation\BelongsTo
*/
public function spec()
{
return $this->belongsTo('GoodsSpec', 'spec_sku_id', 'spec_sku_id');
}
/**
* 定制项详情
*/
public function getGoodsStyleTextAttr($value,$data){
... ...
... ... @@ -371,14 +371,15 @@ class Order extends Model
*/
public function checkGoodsStatusFromOrder($goodsList)
{
foreach ($goodsList as $goods) {
foreach ($goodsList as $order_goods) {
$goods = Goods::get($order_goods['goods_id'],['spec_rel.spec']);
// 判断商品是否下架
if ($goods['goods']['issale'] != '1') {
if ($goods['issale'] != '1') {
$this->setError('很抱歉,商品 [' . $goods['goods_name'] . '] 已下架');
return false;
}
// 付款减库存
if ($goods['goods']['ismake'] == '0' && $goods['spec']['stock_num'] < 1) {
if ($goods['ismake'] == '0' && $goods->getGoodsSku($order_goods['spec_sku_id'])['stock_num'] < 1) {
$this->setError('很抱歉,商品 [' . $goods['goods_name'] . '] 库存不足');
return false;
}
... ...