award.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. // 奖池服务 - 对应 supermart-mini/service/award.js
  2. import { get, post, postL } from './http';
  3. const apis = {
  4. INDEX: '/api/app/index/magicMartIndex',
  5. IP_LIST: '/api/spu/basic/listWorksLimit',
  6. MAGIC_INDEX: '/api/app/index/magicBoxIndex',
  7. LIST: '/api/luckPool/list',
  8. HORSE: '/api/luckPool/horseRaceLampByIndex',
  9. DETAIL: '/api/luckPool/detail',
  10. PRODUCTS: '/api/luckPool/prize',
  11. HORSE_DETAIL: '/api/luckPool/horseRaceLampByDetail',
  12. BUY_RECORD: '/api/luckPool/buyRecord',
  13. VERSION: '/api/luckPool/version',
  14. PREVIEW: '/api/luckOrder/preSubmit',
  15. APPLY: '/api/luckOrder/submit',
  16. APPLY_TRY: '/api/luckOrder/demo',
  17. APPLY_RESULT: '/api/luckOrder/luckResult',
  18. ORDERS: '/api/luckOrder/pageMy',
  19. STORE: '/api/luckInventory',
  20. STORE_MOVE_SAFE: '/api/luckInventory/addToSafe',
  21. STORE_OUT_SAFE: '/api/luckInventory/moveFromSafe',
  22. CONVERT_PREVIEW: '/api/luckExchangeOrder/preSubmit',
  23. CONVERT_APPLY: '/api/luckExchangeOrder/submit',
  24. CONVERT_LIST: '/api/luckExchangeOrder/pageMy',
  25. CONVERT_ALL_PREVIEW: '/api/luckExchangeOrder/preOneKeySubmit',
  26. CONVERT_ALL: '/api/luckExchangeOrder/oneKeySubmit',
  27. TAKE_PREVIEW: '/api/luckPickupOrder/preSubmit',
  28. TAKE_APPLY: '/api/luckPickupOrder/submit',
  29. TAKE_LIST: '/api/luckPickupOrder/pageMy',
  30. TAKE_PAY_ORDER: '/api/luckPickupOrder/pay',
  31. POOL_IN: '/api/luckPool/participate',
  32. POOL_OUT: '/api/luckPool/unparticipate',
  33. PACKAGES: '/api/luckPickupOrder/expressInfo',
  34. EXPRESS: '/api/luckPickupOrder/expressDetail',
  35. KING: '/api/luckKing/getTheLatestLuckKingRecord',
  36. KING_USER: '/api/luckKing/listBillboard',
  37. KING_GOODS: '/api/luckKing/listGoods',
  38. CHECK_PAYMENT_STATUS: '/api/luckOrder/checkPaymentStatus',
  39. GENERATE_PAYMENT_LINK: '/api/luckOrder/generatePaymentLink',
  40. KING_PRE: '/api/luckKing/getThePrev',
  41. BOX_LIST: '/api/luckBox',
  42. BOX_DETAIL: '/api/luckBox/detail',
  43. BOX_PRE: '/api/luckBox/getThePrev',
  44. BOX_NEXT: '/api/luckBox/getTheNext',
  45. UNAVAILABLE_SEAT_NUMBERS: '/api/luckBox/getUnavaliableSeatNumbers',
  46. BOX_LOCK: '/api/luckBox/lock',
  47. BOX_UN_LOCK: '/api/luckBox/unlock',
  48. FEEDBACK_LIST: '/api/app/feedback/list',
  49. FEEDBACK_SUBMIT: '/api/app/feedback/submit',
  50. MY_BOXES: '/api/luck/treasure-box/my-boxes',
  51. OPEN_BOX: '/api/luck/treasure-box/open',
  52. HARRY_EXCHANGE: '/api/redemptionCode/redeem',
  53. WIN_RECORDS: '/api/luck/treasure-box/win-records',
  54. COUNT_RECORDS: '/api/luckPool/countRecordsAfterLastLevel',
  55. };
  56. // ... (existing code)
  57. // 获取最后一次出奖后的记录数
  58. export const countRecordsAfterLastLevel = async (params: { levelEnumList: string[], poolId: string }) => {
  59. const res = await post<number>(apis.COUNT_RECORDS, params);
  60. return res;
  61. };
  62. export interface IPItem {
  63. id: string;
  64. name: string;
  65. cover?: string;
  66. }
  67. export interface PoolItem {
  68. id: string;
  69. name: string;
  70. cover: string;
  71. price: number;
  72. mode?: string;
  73. type?: number;
  74. status?: number;
  75. }
  76. // 获取首页数据
  77. export const getIndex = async (type = 0) => {
  78. const res = await get(apis.INDEX, { type });
  79. return res.data;
  80. };
  81. // 获取 IP 列表
  82. export const getIPList = async (limit = 200): Promise<IPItem[]> => {
  83. const res = await get<IPItem[]>(apis.IP_LIST, { limit });
  84. return res.data || [];
  85. };
  86. // 获取魔盒首页
  87. export const getMagicIndex = async () => {
  88. const res = await get(apis.MAGIC_INDEX);
  89. return res.data;
  90. };
  91. // 获取奖池列表
  92. export const getPoolList = async (params: {
  93. current: number;
  94. size: number;
  95. mode?: string;
  96. type?: number;
  97. worksId?: string;
  98. keyword?: string;
  99. priceMin?: number;
  100. priceMax?: number;
  101. priceSort?: number;
  102. }) => {
  103. // 处理 mode 参数
  104. let processedMode = params.mode;
  105. if (processedMode && processedMode.startsWith('UNLIMITED')) {
  106. processedMode = 'UNLIMITED';
  107. }
  108. const res = await post<PoolItem[]>(apis.LIST, { ...params, mode: processedMode });
  109. return res;
  110. };
  111. // 获取跑马灯数据
  112. export const getHorse = async () => {
  113. const res = await post(apis.HORSE);
  114. return res.success ? res.data : null;
  115. };
  116. // 获取奖池详情
  117. export const getPoolDetail = async (poolId: string) => {
  118. const res = await get(apis.DETAIL, { poolId });
  119. return res.data;
  120. };
  121. // 获取奖池商品
  122. export const getPoolProducts = async (poolId: string) => {
  123. const res = await get(apis.PRODUCTS, { poolId });
  124. return res.data;
  125. };
  126. // 获取详情跑马灯
  127. export const getDetailHorse = async (poolId: string, size = 50) => {
  128. const res = await post(apis.HORSE_DETAIL, { poolId, size });
  129. return res.success ? res.data : null;
  130. };
  131. // 获取购买记录
  132. export const getBuyRecord = async (poolId: string, lastId?: string, level?: number, size = 200) => {
  133. const res = await post(apis.BUY_RECORD, { poolId, lastId, level, size });
  134. return res.data;
  135. };
  136. // 获取版本信息
  137. export const getVersion = async (poolId: string, size = 20) => {
  138. const res = await post(apis.VERSION, { poolId, size });
  139. return res.data;
  140. };
  141. // 试玩
  142. export const tryDemo = async (poolId: string, quantity: number) => {
  143. const res = await postL(apis.APPLY_TRY, { poolId, quantity });
  144. return res.data;
  145. };
  146. // 预提交订单
  147. export const previewOrder = async (poolId: string, quantity?: number, boxNumber?: string, seatNumbers?: number[], packFlag?: boolean) => {
  148. const param: any = { poolId };
  149. if (quantity) param.quantity = quantity;
  150. if (boxNumber) param.boxNumber = boxNumber;
  151. if (seatNumbers && seatNumbers.length > 0) param.seatNumbers = seatNumbers;
  152. if (packFlag) param.packFlag = packFlag;
  153. const res = await postL(apis.PREVIEW, param);
  154. // http.ts 已经统一处理了错误提示,这里只返回数据
  155. if (!res.success) {
  156. return null;
  157. }
  158. return res.data;
  159. };
  160. // 提交订单
  161. export const applyOrder = async (poolId: string, quantity: number, paymentType: string, boxNumber?: string, seatNumbers?: number[], packFlag?: boolean) => {
  162. const param: any = { poolId, quantity, paymentType };
  163. if (boxNumber) param.boxNumber = boxNumber;
  164. if (seatNumbers && seatNumbers.length > 0) param.seatNumbers = seatNumbers;
  165. if (packFlag) param.packFlag = packFlag;
  166. const res = await postL(apis.APPLY, param);
  167. // http.ts 已经统一处理了错误提示,这里只返回数据
  168. if (!res.success) {
  169. return null;
  170. }
  171. return res.data;
  172. };
  173. // 获取抽奖结果
  174. export const getApplyResult = async (tradeNo: string) => {
  175. const res = await get(apis.APPLY_RESULT, { tradeNo });
  176. return res.data;
  177. };
  178. // 检查支付状态
  179. export const checkPaymentStatus = async (tradeNo: string) => {
  180. const res = await get(apis.CHECK_PAYMENT_STATUS, { tradeNo });
  181. return res.data;
  182. };
  183. // 获取盲盒订单列表
  184. export const getAwardOrders = async (current: number, size: number, tab?: string) => {
  185. const res = await post(apis.ORDERS, { current, size, tab });
  186. return res.data;
  187. };
  188. // 获取仓库列表
  189. export const getStore = async (current: number, size: number, safeFlag?: number, tab?: string, status: number = 0) => {
  190. const res = await post(apis.STORE, { current, size, status, tab, safeFlag });
  191. return res.data;
  192. };
  193. // 移入保险箱
  194. export const moveToSafeStore = async (inventoryIds: string[]) => {
  195. const res = await postL(apis.STORE_MOVE_SAFE, { inventoryIds });
  196. return res.success;
  197. };
  198. // 移出保险箱
  199. export const moveOutSafeStore = async (inventoryIds: string[]) => {
  200. const res = await postL(apis.STORE_OUT_SAFE, { inventoryIds });
  201. return res.success;
  202. };
  203. // 兑换预览
  204. export const convertPreview = async (inventoryIds: string[]) => {
  205. const res = await postL(apis.CONVERT_PREVIEW, { inventoryIds });
  206. return res;
  207. };
  208. // 兑换申请
  209. export const convertApply = async (inventoryIds: string[]) => {
  210. const res = await postL(apis.CONVERT_APPLY, { inventoryIds });
  211. return res.success;
  212. };
  213. // 兑换列表
  214. export const getConvertList = async (current: number, size: number) => {
  215. const res = await post(apis.CONVERT_LIST, { current, size });
  216. return res.data;
  217. };
  218. // 一键兑换预览
  219. export const convertAllPreview = async () => {
  220. const res = await postL(apis.CONVERT_ALL_PREVIEW);
  221. return res.data;
  222. };
  223. // 一键兑换
  224. export const convertAll = async (levels: number[]) => {
  225. const res = await postL(apis.CONVERT_ALL, { levels });
  226. return res.success;
  227. };
  228. // 提货预览
  229. export const takePreview = async (inventoryIds: string[], addressBookId: string) => {
  230. const res = await postL(apis.TAKE_PREVIEW, { inventoryIds, addressBookId });
  231. return res.data;
  232. };
  233. // 提货申请
  234. export const takeApply = async (inventoryIds: string[], addressBookId: string, paymentType: string) => {
  235. const res = await postL(apis.TAKE_APPLY, { inventoryIds, addressBookId, paymentType });
  236. return res.data;
  237. };
  238. // 提货列表
  239. export const getTakeList = async (current: number, size: number) => {
  240. const res = await post(apis.TAKE_LIST, { current, size });
  241. return res.data;
  242. };
  243. // 提货支付
  244. export const takePayOrder = async (inventoryIds: string[], addressBookId: string, paymentType: string, tradeNo?: string) => {
  245. const res = await postL(apis.TAKE_PAY_ORDER, { inventoryIds, addressBookId, paymentType, tradeNo });
  246. return res.data;
  247. };
  248. // 参与奖池
  249. export const poolIn = async (poolId: string) => {
  250. const res = await get(apis.POOL_IN, { poolId });
  251. return res.success;
  252. };
  253. // 退出奖池
  254. export const poolOut = async (poolId?: string) => {
  255. const param: any = {};
  256. if (poolId) param.poolId = poolId;
  257. const res = await get(apis.POOL_OUT, param);
  258. return res.success;
  259. };
  260. // 获取包裹信息
  261. export const getAwardPackages = async (tradeNo: string) => {
  262. const res = await get(apis.PACKAGES, { tradeNo });
  263. return res.data;
  264. };
  265. // 获取物流详情
  266. export const getAwardExpress = async (tradeNo: string, packageId: string) => {
  267. const res = await get(apis.EXPRESS, { tradeNo, packageId });
  268. return res.data;
  269. };
  270. // 获取欧皇信息
  271. export const getKing = async (poolId: string) => {
  272. const res = await get(apis.KING, { poolId });
  273. return res.success ? res.data : null;
  274. };
  275. // 获取欧皇榜单
  276. export const getKingUser = async (poolId: string) => {
  277. const res = await get(apis.KING_USER, { poolId });
  278. return res.data;
  279. };
  280. // 获取欧皇商品
  281. export const getKingGoods = async (poolId: string) => {
  282. const res = await get(apis.KING_GOODS, { poolId });
  283. return res.data;
  284. };
  285. // 获取上一期欧皇
  286. export const getPreKing = async (poolId: string) => {
  287. const res = await get(apis.KING_PRE, { poolId });
  288. return res.data;
  289. };
  290. // 获取盒子列表
  291. export const getBoxList = async (poolId: string, level?: number, current?: number, size?: number) => {
  292. const res = await post(apis.BOX_LIST, { poolId, current, size, level });
  293. return res.data;
  294. };
  295. // 获取盒子详情
  296. export const getBoxDetail = async (poolId: string, boxNumber?: string) => {
  297. const param: any = { poolId };
  298. if (boxNumber) param.boxNumber = boxNumber;
  299. const res = await get(apis.BOX_DETAIL, param);
  300. return res.data;
  301. };
  302. // 获取上一个盒子
  303. export const getPreBox = async (poolId: string, boxNumber: string) => {
  304. const res = await get(apis.BOX_PRE, { poolId, boxNumber });
  305. return res.data;
  306. };
  307. // 获取下一个盒子
  308. export const getNextBox = async (poolId: string, boxNumber: string) => {
  309. const res = await get(apis.BOX_NEXT, { poolId, boxNumber });
  310. return res.data;
  311. };
  312. // 锁定盒子
  313. export const lockBox = async (poolId: string, boxNumber: string) => {
  314. const res = await postL(apis.BOX_LOCK, { poolId, boxNumber });
  315. return res.success;
  316. };
  317. // 解锁盒子
  318. export const unlockBox = async (poolId: string, boxNumber: string) => {
  319. const res = await postL(apis.BOX_UN_LOCK, { poolId, boxNumber });
  320. return res.success;
  321. };
  322. // 获取不可用座位号
  323. export const getUnavailableSeatNumbers = async (poolId: string, boxNumber: string, startSeatNumber?: number, endSeatNumber?: number) => {
  324. const params: any = { poolId, boxNumber };
  325. if (startSeatNumber) params.startSeatNumber = startSeatNumber;
  326. if (endSeatNumber) params.endSeatNumber = endSeatNumber;
  327. const res = await post(apis.UNAVAILABLE_SEAT_NUMBERS, params);
  328. return res.data;
  329. };
  330. // 获取弹幕列表
  331. export const getFeedbackList = async () => {
  332. const res = await get(apis.FEEDBACK_LIST);
  333. return res;
  334. };
  335. // 发送弹幕
  336. export const submitFeedback = async (content: string) => {
  337. const res = await postL(apis.FEEDBACK_SUBMIT, { content });
  338. return res;
  339. };
  340. // 获取我的宝箱列表
  341. export const getMyBoxes = async () => {
  342. const res = await get(apis.MY_BOXES);
  343. return res.data;
  344. };
  345. // 开启宝箱
  346. export const openBox = async (params: { boxIds: string }) => {
  347. // 按照小程序的方式,boxIds 作为 query 参数
  348. const res = await post(`${apis.OPEN_BOX}?boxIds=${params.boxIds}`, {});
  349. return res;
  350. };
  351. // 获取仓库商品详情
  352. export const getLuckDetail = async (id: string) => {
  353. const res = await get('/api/luckInventory/detail', { id });
  354. return res.data;
  355. };
  356. // 获取仓库商品总数
  357. export const getSumInventory = async () => {
  358. const res = await get('/api/luckInventory');
  359. return res.data;
  360. };
  361. // 兑换码兑换
  362. export const harryExchange = async (params: { code: string }) => {
  363. const res = await post(apis.HARRY_EXCHANGE, params, { silent: true });
  364. return res;
  365. };
  366. // 获取中奖记录
  367. export const getWinRecords = async (poolId: string, boxNumber: string) => {
  368. const res = await get(apis.WIN_RECORDS, { poolId, boxNumber });
  369. return res.data;
  370. };
  371. export default {
  372. getIndex,
  373. getIPList,
  374. getMagicIndex,
  375. getPoolList,
  376. getHorse,
  377. getPoolDetail,
  378. getPoolProducts,
  379. getDetailHorse,
  380. getBuyRecord,
  381. getVersion,
  382. tryDemo,
  383. previewOrder,
  384. applyOrder,
  385. getApplyResult,
  386. checkPaymentStatus,
  387. getAwardOrders,
  388. getStore,
  389. moveToSafeStore,
  390. moveOutSafeStore,
  391. convertPreview,
  392. convertApply,
  393. getConvertList,
  394. convertAllPreview,
  395. convertAll,
  396. takePreview,
  397. takeApply,
  398. getTakeList,
  399. takePayOrder,
  400. poolIn,
  401. poolOut,
  402. getAwardPackages,
  403. getAwardExpress,
  404. getKing,
  405. getKingUser,
  406. getKingGoods,
  407. getPreKing,
  408. getBoxList,
  409. getBoxDetail,
  410. getPreBox,
  411. getNextBox,
  412. lockBox,
  413. unlockBox,
  414. getUnavailableSeatNumbers,
  415. getFeedbackList,
  416. submitFeedback,
  417. getLuckDetail,
  418. getSumInventory,
  419. harryExchange,
  420. getWinRecords,
  421. countRecordsAfterLastLevel,
  422. };