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