作者 何书鹏

代码优化

... ... @@ -35,12 +35,16 @@ class Cart extends Model
])->order('createtime desc')->select();
// 删除失效数据
$newCartData = [];
foreach ($cartData as $v){
if(!$v->goods || !$v->sku_price){
$v->delete();
}else{
$v['sku_price'] = \addons\shopro\model\Goods::operActivitySkuPrice($v['goods'], [$v['sku_price']])['sku_price'][0];
$newCartData[] = $v;
}
}
return $cartData;
return $newCartData;
}
public static function add($goodsList)
... ...
... ... @@ -83,9 +83,6 @@ class Cart extends Base
public function index()
{
$data = CartModel::info();
foreach ($data as $key => $v) {
$data[$key]['sku_price'] = \addons\shopro\model\Goods::operActivitySkuPrice($v['goods'], [$v['sku_price']])['sku_price'][0];
}
$this->success('我的购物车', $data);
}
... ...