mall.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. // 商城服务 - 对应 supermart-mini/service/mall.js
  2. import { get, post, postL } from './http';
  3. const apis = {
  4. CATEGORY: '/api/spu/basic/listCategoryLimit',
  5. LIST: '/api/mallGoods',
  6. DETAIL: '/api/mallGoods/detail',
  7. DETAIL_BY_SPU: '/api/mallGoods/detailBySpuId',
  8. PREVIEW_SUBMIT: '/api/mallOrder/preSubmit',
  9. ORDERS: '/api/mallOrder/pageMy',
  10. ORDER_DETAIL: '/api/mallOrder/detail',
  11. APPLY: '/api/mallOrder/submit',
  12. ORDER_PAY: '/api/mallOrder/pay',
  13. RECEIVE: '/api/mallOrder/receive',
  14. PACKAGES: '/api/deliveryOrder/expressInfo',
  15. EXPRESS: '/api/deliveryOrder/expressDetail',
  16. UPDATE_PHONE: '/api/mallOrder/updateRestNotifyMobile',
  17. SPIKE_LIST: '/api/activity/mallSubject/subjectGoodsPage',
  18. SPIKE_TIMER: '/api/activity/mallSubject/subject',
  19. };
  20. export interface GoodsItem {
  21. id: string;
  22. name: string;
  23. price: number;
  24. cover: string;
  25. sellType?: number;
  26. worksId?: string;
  27. categoryId?: string;
  28. }
  29. export interface GoodsListParams {
  30. current: number;
  31. size: number;
  32. keyword?: string;
  33. worksId?: string;
  34. categoryId?: string;
  35. sellType?: string;
  36. }
  37. export interface GoodsDetail {
  38. id: string;
  39. name: string;
  40. price: number;
  41. cover: string;
  42. sellType?: number;
  43. sellFlag?: number;
  44. sellTime?: string;
  45. deposit?: number;
  46. subjectPrice?: number;
  47. spu: {
  48. id: string;
  49. name: string;
  50. cover: string;
  51. images?: string[];
  52. description?: string;
  53. };
  54. recommendedLuckPool?: any[];
  55. recommendedMallGoods?: GoodsItem[];
  56. }
  57. export interface PreviewSubmitParams {
  58. goodsId: string;
  59. quantity: number;
  60. subjectId?: string;
  61. }
  62. export interface PreviewSubmitResult {
  63. paymentAmount: number;
  64. depositAmount?: number;
  65. expressAmount?: number;
  66. couponAmount?: number;
  67. type?: number;
  68. cash?: {
  69. balance: number;
  70. };
  71. }
  72. export interface OrderSubmitParams {
  73. goodsId: string;
  74. paymentType: string;
  75. addressBookId: string;
  76. quantity: number;
  77. restNotifyMobile?: string;
  78. subjectId?: string;
  79. }
  80. export interface OrderItem {
  81. tradeNo: string;
  82. status: number;
  83. statusText: string;
  84. goodsName: string;
  85. goodsCover: string;
  86. quantity: number;
  87. paymentAmount: number;
  88. createTime: string;
  89. }
  90. export interface OrderDetail {
  91. tradeNo: string;
  92. status: number;
  93. statusText: string;
  94. goodsName: string;
  95. goodsCover: string;
  96. quantity: number;
  97. paymentAmount: number;
  98. createTime: string;
  99. address?: {
  100. contactName: string;
  101. contactNo: string;
  102. province: string;
  103. city: string;
  104. district: string;
  105. address: string;
  106. };
  107. }
  108. // 获取商品分类
  109. export const getCategories = async (limit = 5) => {
  110. const res = await get(apis.CATEGORY, { limit });
  111. return res.data;
  112. };
  113. // 获取商品列表
  114. export const getGoodsList = async (params: GoodsListParams) => {
  115. const res = await post<GoodsItem[]>(apis.LIST, params);
  116. return res.data || [];
  117. };
  118. // 获取商品详情
  119. export const getGoodsDetail = async (goodsId: string, subjectId?: string): Promise<GoodsDetail | null> => {
  120. const params: any = { goodsId };
  121. if (subjectId) params.subjectId = subjectId;
  122. const res = await get<GoodsDetail>(apis.DETAIL, params);
  123. return res.data;
  124. };
  125. // 通过 SPU ID 获取商品详情
  126. export const getGoodsDetailBySpu = async (spuId: string): Promise<GoodsDetail | null> => {
  127. const res = await get<GoodsDetail>(apis.DETAIL_BY_SPU, { goodsId: '', spuId });
  128. return res.data;
  129. };
  130. // 预提交订单(获取价格信息)
  131. export const previewSubmit = async (params: PreviewSubmitParams): Promise<PreviewSubmitResult | null> => {
  132. const res = await postL<PreviewSubmitResult>(apis.PREVIEW_SUBMIT, params);
  133. return res.data;
  134. };
  135. // 提交订单
  136. export const submitOrder = async (params: OrderSubmitParams) => {
  137. const res = await postL(apis.APPLY, params);
  138. return res.data;
  139. };
  140. // 获取订单列表
  141. export const getOrders = async (current: number, size: number, tab?: string) => {
  142. const res = await post<{ records: OrderItem[]; total: number }>(apis.ORDERS, { current, size, tab });
  143. return res.data;
  144. };
  145. // 获取订单详情
  146. export const getOrderDetail = async (tradeNo: string): Promise<OrderDetail | null> => {
  147. const res = await get<OrderDetail>(apis.ORDER_DETAIL, { tradeNo });
  148. return res.data;
  149. };
  150. // 订单支付
  151. export const payOrder = async (tradeNo: string, paymentType: string) => {
  152. const res = await postL(apis.ORDER_PAY, { tradeNo, paymentType });
  153. return res.data;
  154. };
  155. // 确认收货
  156. export const confirmReceive = async (tradeNo: string) => {
  157. const res = await postL(apis.RECEIVE, { tradeNo });
  158. return res.success;
  159. };
  160. // 获取包裹信息
  161. export const getPackages = async (tradeNo: string) => {
  162. const res = await get(apis.PACKAGES, { tradeNo });
  163. return res.data;
  164. };
  165. // 获取物流详情
  166. export const getExpress = async (tradeNo: string, packageId: string) => {
  167. const res = await get(apis.EXPRESS, { tradeNo, packageId });
  168. return res.data;
  169. };
  170. // 更新尾款提醒手机号
  171. export const updatePhone = async (params: { tradeNo: string; restNotifyMobile: string }) => {
  172. const res = await postL(apis.UPDATE_PHONE, params);
  173. return res;
  174. };
  175. // 获取秒杀商品列表
  176. export const getSpikeList = async (params: any) => {
  177. const res = await postL(apis.SPIKE_LIST, params);
  178. return res.data;
  179. };
  180. // 获取秒杀活动信息
  181. export const getSpikeTimer = async (subjectId: string) => {
  182. const res = await get(`${apis.SPIKE_TIMER}/${subjectId}`);
  183. return res.data;
  184. };
  185. export default {
  186. getCategories,
  187. getGoodsList,
  188. getGoodsDetail,
  189. getGoodsDetailBySpu,
  190. previewSubmit,
  191. submitOrder,
  192. getOrders,
  193. getOrderDetail,
  194. payOrder,
  195. confirmReceive,
  196. getPackages,
  197. getExpress,
  198. updatePhone,
  199. getSpikeList,
  200. getSpikeTimer,
  201. };