新增购物车模块

This commit is contained in:
2024-07-30 06:35:24 +08:00
parent 6c0f442c50
commit b0fbae6ac1
5 changed files with 738 additions and 0 deletions

106
src/api/shop/cart/index.ts Normal file
View File

@@ -0,0 +1,106 @@
import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
import type { Cart, CartParam } from './model';
import { MODULES_API_URL } from '@/config/setting';
/**
* 分页查询购物车
*/
export async function pageCart(params: CartParam) {
const res = await request.get<ApiResult<PageResult<Cart>>>(
MODULES_API_URL + '/shop/cart/page',
{
params
}
);
if (res.data.code === 0) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 查询购物车列表
*/
export async function listCart(params?: CartParam) {
const res = await request.get<ApiResult<Cart[]>>(
MODULES_API_URL + '/shop/cart',
{
params
}
);
if (res.data.code === 0 && res.data.data) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 添加购物车
*/
export async function addCart(data: Cart) {
const res = await request.post<ApiResult<unknown>>(
MODULES_API_URL + '/shop/cart',
data
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 修改购物车
*/
export async function updateCart(data: Cart) {
const res = await request.put<ApiResult<unknown>>(
MODULES_API_URL + '/shop/cart',
data
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 删除购物车
*/
export async function removeCart(id?: number) {
const res = await request.delete<ApiResult<unknown>>(
MODULES_API_URL + '/shop/cart/' + id
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 批量删除购物车
*/
export async function removeBatchCart(data: (number | undefined)[]) {
const res = await request.delete<ApiResult<unknown>>(
MODULES_API_URL + '/shop/cart/batch',
{
data
}
);
if (res.data.code === 0) {
return res.data.message;
}
return Promise.reject(new Error(res.data.message));
}
/**
* 根据id查询购物车
*/
export async function getCart(id: number) {
const res = await request.get<ApiResult<Cart>>(
MODULES_API_URL + '/shop/cart/' + id
);
if (res.data.code === 0 && res.data.data) {
return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}

View File

@@ -0,0 +1,45 @@
import type { PageParam } from '@/api';
/**
* 购物车
*/
export interface Cart {
// 购物车表ID
id?: string;
// 类型 0商城 1预定
type?: number;
// 商品ID
goodsId?: string;
// 商品属性
goodsAttrUnique?: string;
// 商品数量
cartNum?: number;
// 0 = 未购买 1 = 已购买
isPay?: string;
// 是否为立即购买
isNew?: string;
// 拼团id
combinationId?: number;
// 秒杀产品ID
seckillId?: number;
// 砍价id
bargainId?: number;
// 用户ID
userId?: string;
// 是否删除, 0否, 1是
deleted?: number;
// 租户id
tenantId?: number;
// 注册时间
createTime?: string;
// 修改时间
updateTime?: string;
}
/**
* 购物车搜索条件
*/
export interface CartParam extends PageParam {
id?: number;
keywords?: string;
}