product.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import {axios} from '../utils/request'
  2. import {PRODUCT_MODULE} from './_prefix'
  3. type ProductInfo = {
  4. storeId: number,
  5. name: string,
  6. category: string,
  7. price: number,
  8. photoUrlList: [string]
  9. }
  10. // 创建商品
  11. export const createProduct = (productInfo: ProductInfo) => {
  12. return axios.post(`${PRODUCT_MODULE}/`, productInfo,
  13. {headers: {'Content-Type': 'application/json'}})
  14. .then(res => {
  15. return res
  16. })
  17. }
  18. // 获取商店下所有商品
  19. export const getProductsByStoreId = (storeId: number) => {
  20. return axios.get(`${PRODUCT_MODULE}/?storeId=${storeId}`)
  21. .then(res => {
  22. return res
  23. })
  24. }
  25. // 根据商品Id获取商品信息
  26. export const getProductById = (productId: number) => {
  27. return axios.get(`${PRODUCT_MODULE}/${productId}`)
  28. .then(res => {
  29. return res;
  30. })
  31. }
  32. // 添加库存
  33. export const addStock = (id: number, number: number) => {
  34. return axios.post(`${PRODUCT_MODULE}/${id}/stock?number=${number}`)
  35. .then(res => {
  36. return res;
  37. })
  38. }