listUserCart(); // 购物车有效商品 $cart_effective = []; // 购物车无效商品 $cart_invalid = []; // 拆分有效和无效商品 foreach ($cart_list as $k => $v) { unset($cart_list[$k]['freight_type']); unset($cart_list[$k]['freight_id']); unset($cart_list[$k]['freight_money']); unset($cart_list[$k]['weight']); unset($cart_list[$k]['product_is_publish']); unset($cart_list[$k]['product_delete_time']); if ($v['is_effective'] == 1) { $cart_effective[] = $v; } else { $cart_invalid[] = $v; } } return [ // 购物车有效产品 $cart_effective, // 购物车无效产品 $cart_invalid ]; } /** * 更新兑换车失效产品 * @param int $user_id 用户ID * @date 2022-11-15 */ public function updateInvalid($user_id) { $cart_model = new IntegralCart(); $cart = $cart_model->listUserCart($user_id); if (count($cart)) { $cart = $cart -> toArray(); foreach ($cart as $k => $v) { // 失效状态 1--有效 0--失效 $is_effective = 1; // 原产品删除或下架 if (empty($v['product_name']) || !empty($v['product_delete_time']) || $v['product_is_publish'] == 0) { $is_effective = 0; } // 之前没有规格,现在有规格了 // if ($v['is_product_spec_open'] == 0 && empty($v['product_sku_name'])) { // $is_effective = 0; // } // 之前有规格,现在没有规格了 或者 SKU更改 if ($v['is_product_spec_open'] == 1 && empty($v['product_sku_name'])) { $is_effective = 0; } // 库存不足 或者 之前没有规格,现在有规格了 if ($v['product_stock'] <= 0) { $is_effective = 0; } $data[] = [ 'id' => $v['id'], 'is_effective' => $is_effective ]; } return $cart_model->saveAll($data); } return true; } }