From 5ab9f79914d9364ccfb8fef32ac230fa74117ab4 Mon Sep 17 00:00:00 2001 From: wangxiaowei Date: Fri, 1 Nov 2024 11:46:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B8=85=E9=99=A4=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E8=B4=AD=E7=89=A9=E8=BD=A6=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/LocalStoreGoods.php | 15 ++++++++++++++ app/api/logic/LocalStoreGoodsCartLogic.php | 23 ++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/app/api/controller/LocalStoreGoods.php b/app/api/controller/LocalStoreGoods.php index df951c92..190efbfe 100755 --- a/app/api/controller/LocalStoreGoods.php +++ b/app/api/controller/LocalStoreGoods.php @@ -145,4 +145,19 @@ class LocalStoreGoods extends Api return JsonServer::error($e->getMessage()); } } + + public function clearCart() + { + $form = $this->request->post(); + + try { + $result = LocalStoreGoodsCartLogic::clearCart($form, $this->user_id); + if ($result) { + return JsonServer::success('操作成功', $result); + } + return JsonServer::error('操作失败'); + } catch (\Exception $e) { + return JsonServer::error($e->getMessage()); + } + } } \ No newline at end of file diff --git a/app/api/logic/LocalStoreGoodsCartLogic.php b/app/api/logic/LocalStoreGoodsCartLogic.php index 13d4a20c..c4f04200 100644 --- a/app/api/logic/LocalStoreGoodsCartLogic.php +++ b/app/api/logic/LocalStoreGoodsCartLogic.php @@ -144,4 +144,27 @@ class LocalStoreGoodsCartLogic extends Logic return false; } } + + public static function clearCart($post, $user_id) + { + if ($post['cart_id'] > 0) { + // 清空购物车单独的商品 + LocalStoreGoodsCart::where([ + 'id' => $post['cart_id'], + 'user_id' => $user_id, + 'lstore_id' => $post['lstore_id'], + ])->update([ + 'is_delete' => 1, + 'delete_time' => time() + ]); + } else { + LocalStoreGoodsCart::where([ + 'user_id' => $user_id, + 'lstore_id' => $post['lstore_id'], + ])->update([ + 'is_delete' => 1, + 'delete_time' => time() + ]); + } + } } \ No newline at end of file