ts_aimz/net/api/shop.js
2025-06-10 10:50:44 +08:00

118 lines
3.4 KiB
JavaScript

import {
request
} from "../http";
// 公共API
const proName = 'aiShop'
const apiPath = {
indexList: "/api/goodsonline/listpage", //上架的软著商品列表 GET
saveGoods: "/api/goods/save", //新增软著商品 POST
goodsDetail: "/api/goods/get/{goodsId}", //商品详情 GET
delGoods: "/api/goods/remove/{ids}", //删除商品 DELETE
updateGoods: "/api/goods/update/{goodsId}", //修改商品 PUT
doCheck: "/api/goods/sub-check/{goodsId}", //提交审核 PUT
onGoods: "/api/goods/publish/{goodsId}", //上架商品 PUT
offGoods: "/api/goods/no-publish/{goodsId}", //下架商品
// 0b00884a-f7a2-425f-93e5-599fbaad4bde 软著分类
// ce3ded65-68ed-4f42-89da-de1b813b8f7e 证件类型
goodsDics: "/api/data/listbyparentid/{dId}", //商品数据字典
areaList: "/api/area/listbyparentid/{pId}", //省市区树结构
saveOrder: '/api/order/save/{goodsId}', //新增订单
confirmOrder: '/api/order/confirm-pay/{orderId}', //确定付款
}
class Shop {
// 通用路径参数替换方法
static #replacePathParams(path, params) {
return Object.entries(params).reduce(
(acc, [key, value]) => acc.replace(`{${key}}`, value),
path
)
}
// 通用请求方法
static requestHandler(endpoint, method, data = null, pathParams = {}) {
const path = Object.keys(pathParams).length ?
this.#replacePathParams(endpoint, pathParams) :
endpoint
return request(path, method, data, proName)
}
// 获取上架的软著列表
static doGetIndexList(data) {
return this.requestHandler(apiPath.indexList, "GET", data)
}
// 软著类型
static doGetGoodsDic(id) {
return this.requestHandler(apiPath.goodsDics, "GET", null, {
dId: id
})
}
// 新增软件商品
static doSaveGoods(data) {
return this.requestHandler(apiPath.saveGoods, "POST", data)
}
// 商品详情
static doGetGoodsDetail(id) {
return this.requestHandler(apiPath.goodsDetail, "GET", null, {
goodsId: id
})
}
// 删除商品
static doDelGoods(id) {
return this.requestHandler(apiPath.delGoods, "DELETE", null, {
ids: id
})
}
// 更新商品
static doUpdateGoods(id, data) {
return this.requestHandler(apiPath.updateGoods, "PUT", data, {
goodsId: id
})
}
// 提交审核
static doSubCheck(id) {
return this.requestHandler(apiPath.doCheck, "PUT", null, {
goodsId: id
})
}
// 上架商品
static doOnGoods(id) {
return this.requestHandler(apiPath.onGoods, "PUT", null, {
goodsId: id
})
}
// 下架商品
static doOffGoods(id) {
return this.requestHandler(apiPath.offGoods, "PUT", null, {
goodsId: id
})
}
//获取地区
static doGetAreaList(id) {
return this.requestHandler(apiPath.areaList, "GET", null, {
pId: id
})
}
//新增订单
static doSaveOrder(id) {
return this.requestHandler(apiPath.saveOrder, "POST", null, {
goodsId: id
})
}
//确定付款
static doConfirmOrder(oId) {
return this.requestHandler(apiPath.confirmOrder, "PUT", null, {
orderId: oId
})
}
}
export default Shop;