mall.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. type?: number;
  90. paidAmount?: number;
  91. totalAmount?: number;
  92. couponAmount?: number;
  93. paymentTimeoutTime?: string;
  94. }
  95. export interface OrderDetail extends OrderItem {
  96. address?: {
  97. contactName: string;
  98. contactNo: string;
  99. province: string;
  100. city: string;
  101. district: string;
  102. address: string;
  103. };
  104. }
  105. // 获取商品分类
  106. export const getCategories = async (limit = 5) => {
  107. const res = await get(apis.CATEGORY, { limit });
  108. return res.data;
  109. };
  110. // 获取商品列表
  111. export const getGoodsList = async (params: GoodsListParams) => {
  112. const res = await post<GoodsItem[]>(apis.LIST, params);
  113. return res.data || [];
  114. };
  115. // 获取商品详情
  116. export const getGoodsDetail = async (goodsId: string, subjectId?: string): Promise<GoodsDetail | null> => {
  117. const params: any = { goodsId };
  118. if (subjectId) params.subjectId = subjectId;
  119. const res = await get<GoodsDetail>(apis.DETAIL, params);
  120. return res.data;
  121. };
  122. // 通过 SPU ID 获取商品详情
  123. export const getGoodsDetailBySpu = async (spuId: string): Promise<GoodsDetail | null> => {
  124. const res = await get<GoodsDetail>(apis.DETAIL_BY_SPU, { goodsId: '', spuId });
  125. return res.data;
  126. };
  127. // 预提交订单(获取价格信息)
  128. export const previewSubmit = async (params: PreviewSubmitParams): Promise<PreviewSubmitResult | null> => {
  129. const res = await postL<PreviewSubmitResult>(apis.PREVIEW_SUBMIT, params);
  130. return res.data;
  131. };
  132. // 提交订单
  133. export const submitOrder = async (params: OrderSubmitParams) => {
  134. const res = await postL(apis.APPLY, params);
  135. return res.data;
  136. };
  137. // 获取订单列表
  138. export const getOrders = async (current: number, size: number, tab?: string) => {
  139. const res = await post<{ records: OrderItem[]; total: number }>(apis.ORDERS, { current, size, tab });
  140. return res.data;
  141. };
  142. // 获取订单详情
  143. export const getOrderDetail = async (tradeNo: string): Promise<OrderDetail | null> => {
  144. const res = await get<OrderDetail>(apis.ORDER_DETAIL, { tradeNo });
  145. return res.data;
  146. };
  147. // 订单支付
  148. export const payOrder = async (tradeNo: string, paymentType: string) => {
  149. const res = await postL(apis.ORDER_PAY, { tradeNo, paymentType });
  150. return res.data;
  151. };
  152. // 确认收货
  153. export const confirmReceive = async (tradeNo: string) => {
  154. const res = await postL(apis.RECEIVE, { tradeNo });
  155. return res.success;
  156. };
  157. // 获取包裹信息
  158. export const getPackages = async (tradeNo: string) => {
  159. const res = await get(apis.PACKAGES, { tradeNo });
  160. return res.data;
  161. };
  162. // 获取物流详情
  163. export const getExpress = async (tradeNo: string, packageId: string) => {
  164. const res = await get(apis.EXPRESS, { tradeNo, packageId });
  165. return res.data;
  166. };
  167. // 更新尾款提醒手机号
  168. export const updatePhone = async (params: { tradeNo: string; restNotifyMobile: string }) => {
  169. const res = await postL(apis.UPDATE_PHONE, params);
  170. return res;
  171. };
  172. // 获取秒杀商品列表
  173. export const getSpikeList = async (params: any) => {
  174. const res = await postL(apis.SPIKE_LIST, params);
  175. return res.data;
  176. };
  177. // 获取秒杀活动信息
  178. export const getSpikeTimer = async (subjectId: string) => {
  179. const res = await get(`${apis.SPIKE_TIMER}/${subjectId}`);
  180. return res.data;
  181. };
  182. export default {
  183. getCategories,
  184. getGoodsList,
  185. getGoodsDetail,
  186. getGoodsDetailBySpu,
  187. previewSubmit,
  188. submitOrder,
  189. getOrders,
  190. getOrderDetail,
  191. payOrder,
  192. confirmReceive,
  193. getPackages,
  194. getExpress,
  195. updatePhone,
  196. getSpikeList,
  197. getSpikeTimer,
  198. };