api.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  1. /**
  2. * API 接口配置文件
  3. */
  4. // 开发环境和生产环境的 API 基础地址
  5. // 所有请求通过网关转发
  6. const BASE_URL = process.env.NODE_ENV === 'development'
  7. ? 'http://localhost:8083/api' // 开发环境 - 通过网关
  8. : 'https://your-domain.com/api' // 生产环境
  9. /**
  10. * 封装 uni.request
  11. */
  12. const request = (options) => {
  13. return new Promise((resolve, reject) => {
  14. const token = uni.getStorageSync('token')
  15. const headers = {
  16. 'Content-Type': 'application/json'
  17. }
  18. if (token) {
  19. headers['Authorization'] = token
  20. }
  21. uni.request({
  22. url: (/^https?:\/\//.test(options.url) ? options.url : (BASE_URL + options.url)),
  23. method: options.method || 'GET',
  24. data: options.data || {},
  25. header: headers,
  26. dataType: 'json',
  27. success: (res) => {
  28. console.log('API请求成功:', options.url, '状态码:', res.statusCode, '返回数据:', res.data)
  29. if (res.statusCode === 200) {
  30. // 根据后端约定的数据格式处理
  31. if (res.data.code === 200 || res.data.code === 0 || res.data.success) {
  32. resolve(res.data.data || res.data)
  33. } else {
  34. uni.showToast({
  35. title: res.data.message || res.data.msg || '请求失败',
  36. icon: 'none'
  37. })
  38. reject(res.data)
  39. }
  40. } else if (res.statusCode === 401) {
  41. // 未授权,跳转登录
  42. uni.navigateTo({
  43. url: '/pages/page3/page3'
  44. })
  45. reject(res)
  46. } else {
  47. uni.showToast({
  48. title: '网络请求失败',
  49. icon: 'none'
  50. })
  51. reject(res)
  52. }
  53. },
  54. fail: (err) => {
  55. console.error('API请求失败:', options.url, '错误信息:', err)
  56. uni.showToast({
  57. title: (err && err.errMsg) ? err.errMsg.replace('request:','') : '网络连接失败',
  58. icon: 'none'
  59. })
  60. reject(err)
  61. }
  62. })
  63. })
  64. }
  65. /**
  66. * API 接口列表
  67. */
  68. export default {
  69. // 地区
  70. area: {
  71. // 获取省份列表
  72. getProvinces: () => request({ url: '/recommend/area/provinces' }),
  73. // 获取城市列表(可选省份ID)
  74. getCities: (provinceId) => {
  75. const url = provinceId ? `/recommend/area/cities?provinceId=${provinceId}` : '/recommend/area/cities'
  76. return request({ url })
  77. },
  78. // 获取区域列表(根据城市ID)
  79. getAreas: (cityId) => request({ url: `/recommend/area/areas?cityId=${cityId}` })
  80. },
  81. // 用户相关
  82. user: {
  83. // 获取用户信息
  84. getInfo: () => request({ url: '/user/info' }),
  85. // 获取指定用户的详细信息(包含简介和照片)
  86. getDetailInfo: (userId) => request({
  87. url: `/user/info?userId=${userId}`
  88. }),
  89. // 获取今日匹配数
  90. getMatchCount: () => request({ url: '/user/match-count' }),
  91. // 更新用户基本信息(昵称、头像等)
  92. updateInfo: (data) => request({
  93. url: '/user/basic',
  94. method: 'PUT',
  95. data
  96. }),
  97. // 更新单个字段
  98. updateField: (userId, fieldName, fieldValue) => request({
  99. url: `/user/basic/field?userId=${userId}&fieldName=${fieldName}&fieldValue=${encodeURIComponent(fieldValue)}`,
  100. method: 'PUT'
  101. })
  102. },
  103. // 认证相关
  104. auth: {
  105. // 密码登录(手机号+密码)
  106. loginByPassword: (phone, password) => request({
  107. // 直连 login 服务(开发环境),避免网关未配置导致未路由
  108. url: 'http://localhost:8087/api/login/password',
  109. method: 'POST',
  110. data: { phone, password }
  111. }),
  112. // 发送登录验证码(走网关 -> 登录服务)
  113. sendCode: (phone) => request({
  114. url: '/login/send-code',
  115. method: 'POST',
  116. data: { phone }
  117. }),
  118. // 验证码登录(走网关 -> 登录服务)
  119. smsLogin: (phone, code) => request({
  120. url: '/login/sms-login',
  121. method: 'POST',
  122. data: { phone, code }
  123. }),
  124. // 微信登录(直连 login 服务)
  125. wechatLogin: (data) => request({
  126. url: 'http://localhost:8087/api/login/wechat/login',
  127. method: 'POST',
  128. data: data // ✅ 传递完整的登录数据对象(包含code, nickname, avatarUrl, phoneCode)
  129. }),
  130. // 获取微信手机号(直连 login 服务)
  131. wechatPhone: (code) => request({
  132. url: 'http://localhost:8087/api/login/wechat/phone',
  133. method: 'POST',
  134. data: { code }
  135. })
  136. },
  137. // 首页相关
  138. home: {
  139. // 获取轮播图
  140. getBanners: () => request({ url: '/home/banners' }),
  141. // 获取公告列表
  142. getNotices: () => request({ url: '/announcement/active' }),
  143. // 获取未读消息数
  144. getUnreadCount: () => request({ url: '/home/unread-count' })
  145. },
  146. // 成功案例
  147. successCase: {
  148. // 获取成功案例列表
  149. getList: (params) => request({
  150. url: '/success-case/list',
  151. method: 'GET',
  152. data: params
  153. }),
  154. // 获取成功案例详情
  155. getDetail: (caseNo) => request({
  156. url: `/success-case/detail/${caseNo}`,
  157. method: 'GET'
  158. }),
  159. // 获取案例时间线
  160. getTimeline: (caseNo) => request({
  161. url: `/success-case/timeline/${caseNo}`,
  162. method: 'GET'
  163. })
  164. },
  165. // 活动相关
  166. activity: {
  167. // 获取活动列表
  168. getList: (params) => request({
  169. url: '/activity/list',
  170. method: 'GET',
  171. data: params
  172. }),
  173. // 获取活动详情
  174. getDetail: (id) => request({
  175. url: `/activity/detail/${id}`,
  176. method: 'GET'
  177. }),
  178. // 报名活动
  179. register: (activityId, userId) => request({
  180. url: `/activity/register/${activityId}?userId=${userId}`,
  181. method: 'POST'
  182. }),
  183. // 取消报名
  184. cancelRegister: (activityId) => request({
  185. url: `/activity/cancel/${activityId}`,
  186. method: 'POST'
  187. })
  188. },
  189. // 课程相关
  190. course: {
  191. // 获取课程列表
  192. getList: (params) => request({
  193. url: '/course/list',
  194. method: 'GET',
  195. data: params
  196. }),
  197. // 获取课程详情(带学习进度)
  198. getDetail: (courseId, makerId) => request({
  199. url: `/course/detail/${courseId}${makerId ? '?makerId=' + makerId : ''}`,
  200. method: 'GET'
  201. }),
  202. // 更新学习进度
  203. updateProgress: (makerId, courseId, progress) => request({
  204. url: '/course/progress',
  205. method: 'POST',
  206. data: { makerId, courseId, progress }
  207. }),
  208. // 完成课程(领取积分)
  209. complete: (makerId, courseId) => request({
  210. url: '/course/complete',
  211. method: 'POST',
  212. data: { makerId, courseId }
  213. }),
  214. // 获取我的学习记录
  215. getMyProgress: (makerId) => request({
  216. url: `/course/my-progress?makerId=${makerId}`,
  217. method: 'GET'
  218. }),
  219. // 购买课程
  220. purchase: (courseId, data) => request({
  221. url: `/course/purchase/${courseId}`,
  222. method: 'POST',
  223. data
  224. })
  225. },
  226. // 红娘相关
  227. matchmaker: {
  228. // 获取红娘列表
  229. getList: (params) => request({
  230. url: '/matchmaker/list',
  231. method: 'POST',
  232. data: params
  233. }),
  234. // 获取全职红娘列表
  235. getFormalList: (pageNum, pageSize) => request({
  236. url: `/matchmaker/formal?pageNum=${pageNum}&pageSize=${pageSize}`
  237. }),
  238. // 获取红娘详情
  239. getDetail: (id) => request({
  240. url: `/matchmaker/detail/${id}`
  241. }),
  242. // 根据userId查询红娘信息
  243. getByUserId: (userId) => request({
  244. url: `/matchmaker/by-user/${userId}`
  245. }),
  246. // 预约红娘
  247. book: (matchmakerId, data) => request({
  248. url: `/matchmaker/book/${matchmakerId}`,
  249. method: 'POST',
  250. data
  251. }),
  252. // 提交红娘申请
  253. submitApply: (data) => request({
  254. url: '/matchmaker-apply/submit',
  255. method: 'POST',
  256. data
  257. }),
  258. // 工作台相关
  259. getWorkbenchData: () => request({ url: '/matchmaker/workbench/data' }),
  260. // 获取我的资源
  261. getMyResources: (params) => request({
  262. url: '/matchmaker/resources',
  263. method: 'GET',
  264. data: params
  265. }),
  266. // 获取排行榜数据(总排行榜)
  267. getRankingData: (params) => request({
  268. url: '/matchmaker/ranking',
  269. method: 'GET',
  270. data: params
  271. }),
  272. // 获取本周排行榜(按点赞数和成功人数平均数排名)
  273. getWeeklyRanking: (params) => request({
  274. url: '/matchmaker/weekly-ranking',
  275. method: 'GET',
  276. data: params
  277. }),
  278. // 给红娘点赞(一周只能给同一红娘点赞一次)
  279. likeMatchmaker: (userId, matchmakerId) => request({
  280. url: `/matchmaker/like?userId=${userId}&matchmakerId=${matchmakerId}`,
  281. method: 'POST'
  282. }),
  283. // 检查是否已点赞
  284. checkLikeStatus: (userId, matchmakerId) => request({
  285. url: `/matchmaker/check-like?userId=${userId}&matchmakerId=${matchmakerId}`,
  286. method: 'GET'
  287. }),
  288. // 签到相关
  289. checkinStatus: (makerId) => request({
  290. url: `/matchmaker/checkin/status?makerId=${makerId}`
  291. }),
  292. checkinStats: (makerId) => request({
  293. url: `/matchmaker/checkin/stats?makerId=${makerId}`
  294. }),
  295. doCheckin: (makerId) => request({
  296. url: `/matchmaker/checkin/do?makerId=${makerId}`,
  297. method: 'POST'
  298. }),
  299. // 更新红娘资料(编辑资料页使用)
  300. updateProfile: (matchmakerId, data) => request({
  301. url: `/matchmaker/update/${matchmakerId}`,
  302. method: 'PUT',
  303. data
  304. })
  305. },
  306. // 推荐相关
  307. recommend: {
  308. // 获取推荐用户列表(网关转发到推荐服务)
  309. getUsers: ({ userId, oppoOnly = 1, limit = 20, excludeIds }) => {
  310. let url = `/recommend/users?userId=${userId}&oppoOnly=${oppoOnly}&limit=${limit}`;
  311. if (excludeIds) {
  312. url += `&excludeIds=${excludeIds}`;
  313. }
  314. return request({ url });
  315. },
  316. // 行为反馈:like/dislike
  317. feedback: ({ userId, targetUserId, type }) => request({
  318. url: `/recommend/feedback?userId=${userId}&targetUserId=${targetUserId}&type=${type}`
  319. }),
  320. // 曝光上报
  321. exposure: ({ userId, shownUserIds }) => request({
  322. url: `/recommend/exposure?userId=${userId}&shownUserIds=${encodeURIComponent(shownUserIds)}`
  323. }),
  324. // 规则检索
  325. search: (query) => request({
  326. url: '/recommend/search',
  327. method: 'POST',
  328. data: query
  329. }),
  330. // 获取今日推荐
  331. getTodayRecommend: () => request({
  332. url: '/recommend/today'
  333. })
  334. },
  335. // 消息相关
  336. message: {
  337. // 获取消息列表
  338. getList: (params) => request({
  339. url: '/message/list',
  340. data: params
  341. }),
  342. // 获取会话列表
  343. getConversations: () => request({
  344. url: '/message/conversations'
  345. }),
  346. // 发送消息
  347. send: (data) => request({
  348. url: '/message/send',
  349. method: 'POST',
  350. data
  351. }),
  352. // ===== 系统消息 =====
  353. getSystemList: async (userId, pageNum = 1, pageSize = 20) => {
  354. const res = await request({ url: `/message/system/list?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}` })
  355. // 后端Result包装:{ code, data:{ list,total,page,pageSize } }
  356. return res.data || res
  357. },
  358. getSystemUnreadCount: async (userId) => {
  359. const res = await request({ url: `/message/system/unread-count?userId=${userId}` })
  360. return (typeof res.data === 'number') ? res.data : (res.data?.count || 0)
  361. },
  362. markSystemRead: (id) => request({
  363. url: `/message/system/read/${id}`,
  364. method: 'POST'
  365. }),
  366. getSystemDetail: async (id) => {
  367. const res = await request({ url: `/message/system/detail/${id}` })
  368. return res.data || res
  369. },
  370. markAllSystemRead: (userId) => request({
  371. url: `/message/system/read-all?userId=${userId}`,
  372. method: 'POST'
  373. })
  374. },
  375. // 动态相关
  376. dynamic: {
  377. // 获取推荐动态列表(广场)
  378. getRecommendList: (params) => request({
  379. url: '/dynamic/recommend',
  380. data: params
  381. }),
  382. // 获取动态列表
  383. getList: (params) => request({
  384. url: '/dynamic/list',
  385. data: params
  386. }),
  387. // 获取动态详情
  388. getDetail: (dynamicId, userId) => request({
  389. url: `/dynamic/detail/${dynamicId}`,
  390. data: { userId }
  391. }),
  392. // 发表评论
  393. addComment: (dynamicId, content, images, parentCommentId = 0) => request({
  394. url: `/dynamic/comment`,
  395. method: 'POST',
  396. data: { dynamicId, content, images, parentCommentId, userId: 1 },
  397. header: { 'Content-Type': 'application/json' }
  398. }),
  399. // 评论列表
  400. getComments: (dynamicId, pageNum = 1, pageSize = 10) => request({
  401. url: `/dynamic/comment/list/${dynamicId}`,
  402. data: { pageNum, pageSize }
  403. }),
  404. // 评论点赞/取消
  405. likeComment: (commentId, userId) => {
  406. // 如果没有传入userId,从本地存储获取
  407. if (!userId) {
  408. const userInfo = uni.getStorageSync('userInfo');
  409. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  410. }
  411. if (!userId) {
  412. return Promise.reject(new Error('用户未登录'));
  413. }
  414. return request({
  415. url: `/dynamic/comment/like?commentId=${commentId}&userId=${userId}`,
  416. method: 'POST'
  417. });
  418. },
  419. unlikeComment: (commentId, userId) => {
  420. // 如果没有传入userId,从本地存储获取
  421. if (!userId) {
  422. const userInfo = uni.getStorageSync('userInfo');
  423. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  424. }
  425. if (!userId) {
  426. return Promise.reject(new Error('用户未登录'));
  427. }
  428. return request({
  429. url: `/dynamic/comment/like/${commentId}?userId=${userId}`,
  430. method: 'DELETE'
  431. });
  432. },
  433. // 获取用户动态列表
  434. getUserDynamics: (userId, params) => {
  435. const { pageNum = 1, pageSize = 10, currentUserId = null } = params || {}
  436. let url = `/dynamic/user/${userId}?pageNum=${pageNum}&pageSize=${pageSize}`
  437. if (currentUserId) {
  438. url += `&currentUserId=${currentUserId}`
  439. }
  440. return request({
  441. url: url,
  442. method: 'GET'
  443. })
  444. },
  445. // 点赞动态
  446. like: (dynamicId, userId) => {
  447. // 如果没有传入userId,从本地存储获取
  448. if (!userId) {
  449. const userInfo = uni.getStorageSync('userInfo');
  450. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  451. }
  452. if (!userId) {
  453. return Promise.reject(new Error('用户未登录'));
  454. }
  455. return request({
  456. url: `/dynamic/like?dynamicId=${dynamicId}&userId=${userId}`,
  457. method: 'POST'
  458. });
  459. },
  460. // 取消点赞
  461. unlike: (dynamicId, userId) => {
  462. // 如果没有传入userId,从本地存储获取
  463. if (!userId) {
  464. const userInfo = uni.getStorageSync('userInfo');
  465. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  466. }
  467. if (!userId) {
  468. return Promise.reject(new Error('用户未登录'));
  469. }
  470. return request({
  471. url: `/dynamic/like/${dynamicId}?userId=${userId}`,
  472. method: 'DELETE'
  473. });
  474. },
  475. // 收藏动态
  476. favorite: (dynamicId, userId) => {
  477. // 如果没有传入userId,从本地存储获取
  478. if (!userId) {
  479. const userInfo = uni.getStorageSync('userInfo');
  480. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  481. }
  482. if (!userId) {
  483. return Promise.reject(new Error('用户未登录'));
  484. }
  485. return request({
  486. url: `/dynamic/favorite?dynamicId=${dynamicId}&userId=${userId}`,
  487. method: 'POST'
  488. });
  489. },
  490. // 取消收藏
  491. unfavorite: (dynamicId, userId) => {
  492. // 如果没有传入userId,从本地存储获取
  493. if (!userId) {
  494. const userInfo = uni.getStorageSync('userInfo');
  495. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  496. }
  497. if (!userId) {
  498. return Promise.reject(new Error('用户未登录'));
  499. }
  500. return request({
  501. url: `/dynamic/favorite/${dynamicId}?userId=${userId}`,
  502. method: 'DELETE'
  503. });
  504. },
  505. // 创建个人动态
  506. createUserDynamic: (payload) => request({
  507. url: '/dynamic/user',
  508. method: 'POST',
  509. data: payload,
  510. header: { 'Content-Type': 'application/json' }
  511. }),
  512. // 更新个人动态
  513. updateUserDynamic: (dynamicId, userId, payload) => request({
  514. url: `/dynamic/user/${dynamicId}?userId=${userId}`,
  515. method: 'PUT',
  516. data: payload,
  517. header: { 'Content-Type': 'application/json' }
  518. }),
  519. // 删除个人动态
  520. deleteUserDynamic: (dynamicId, userId) => request({
  521. url: `/dynamic/user/${dynamicId}?userId=${userId}`,
  522. method: 'DELETE'
  523. }),
  524. // 删除动态(旧接口,保留兼容)
  525. delete: (dynamicId) => request({
  526. url: `/dynamic/${dynamicId}`,
  527. method: 'DELETE'
  528. }),
  529. // 发布动态(文本或已存在的媒体URL列表)
  530. publish: (payload) => request({
  531. url: '/dynamic/publish',
  532. method: 'POST',
  533. data: payload,
  534. header: { 'Content-Type': 'application/json' }
  535. }),
  536. // 单个文件上传方法
  537. uploadSingle: (filePath) => {
  538. return new Promise((resolve, reject) => {
  539. console.log('开始上传文件:', filePath)
  540. console.log('上传URL:', BASE_URL + '/dynamic/publish/upload')
  541. uni.uploadFile({
  542. url: BASE_URL + '/dynamic/publish/upload',
  543. filePath: filePath,
  544. name: 'file',
  545. success: (res) => {
  546. console.log('上传响应:', res)
  547. try {
  548. const data = JSON.parse(res.data)
  549. console.log('解析后的响应数据:', data)
  550. if (data.code === 200 || data.code === 0 || data.success) {
  551. console.log('上传成功,返回URL:', data.data)
  552. resolve(data.data)
  553. } else {
  554. console.error('上传失败,服务器返回错误:', data)
  555. reject(new Error(data.message || '上传失败'))
  556. }
  557. } catch (e) {
  558. console.error('解析响应数据失败:', e, '原始响应:', res.data)
  559. reject(new Error('解析响应数据失败'))
  560. }
  561. },
  562. fail: (error) => {
  563. console.error('上传请求失败:', error)
  564. reject(new Error('上传请求失败: ' + (error.errMsg || '未知错误')))
  565. }
  566. })
  567. })
  568. },
  569. // 批量上传多个文件(遍历调用单个上传)
  570. uploadBatch: (filePaths) => {
  571. return new Promise(async (resolve, reject) => {
  572. const urls = []
  573. try {
  574. for (let filePath of filePaths) {
  575. const url = await new Promise((resolveUpload, rejectUpload) => {
  576. uni.uploadFile({
  577. url: BASE_URL + '/dynamic/publish/upload',
  578. filePath: filePath,
  579. name: 'file',
  580. success: (res) => {
  581. try {
  582. const data = JSON.parse(res.data)
  583. if (data.code === 200 || data.code === 0 || data.success) {
  584. resolveUpload(data.data)
  585. } else {
  586. rejectUpload(data)
  587. }
  588. } catch (e) {
  589. rejectUpload(e)
  590. }
  591. },
  592. fail: rejectUpload
  593. })
  594. })
  595. urls.push(url)
  596. }
  597. resolve(urls)
  598. } catch (e) {
  599. reject(new Error(`批量上传失败: ${e.message || '未知错误'}`))
  600. }
  601. })
  602. },
  603. // 提交举报
  604. submitReport: (data) => request({
  605. url: '/dynamic/report',
  606. method: 'POST',
  607. data
  608. }),
  609. // 获取用户收藏列表
  610. getFavoritesList: (userId, pageNum = 1, pageSize = 10) => request({
  611. url: `/dynamic/favorites?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  612. }),
  613. // 获取用户点赞列表
  614. getLikedList: (userId, pageNum = 1, pageSize = 10) => request({
  615. url: `/dynamic/likes?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  616. }),
  617. // 获取用户浏览记录列表
  618. getBrowseHistoryList: (userId, pageNum = 1, pageSize = 10) => request({
  619. url: `/dynamic/browse-history?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  620. }),
  621. // 清空用户浏览记录
  622. clearBrowseHistory: (userId) => request({
  623. url: `/dynamic/browse-history?userId=${userId}`,
  624. method: 'DELETE'
  625. })
  626. },
  627. // VIP相关
  628. vip: {
  629. // 获取VIP信息(状态、套餐等)
  630. getInfo: (userId) => request({
  631. url: `/vip/info?userId=${userId}`
  632. }),
  633. // 获取VIP套餐列表
  634. getPackages: () => request({
  635. url: '/vip/packages'
  636. }),
  637. // 购买VIP套餐(获取支付参数)
  638. purchase: (userId, packageId) => request({
  639. url: '/vip/purchase',
  640. method: 'POST',
  641. data: { userId, packageId }
  642. }),
  643. // 查询订单状态
  644. getOrderStatus: (orderNo) => request({
  645. url: `/vip/order/status?orderNo=${orderNo}`
  646. }),
  647. // 新增:查询支付状态(userId + packageId)
  648. checkPayStatus: (userId, packageId) => request({
  649. url: '/vip/checkPayStatus',
  650. method: 'GET',
  651. data: { userId, packageId }
  652. })
  653. },
  654. // 用户反馈
  655. feedback: {
  656. // 提交用户反馈
  657. submit: (data) => request({
  658. url: '/feedback/submit',
  659. method: 'POST',
  660. data
  661. }),
  662. // 上传反馈图片
  663. uploadImage: (filePath) => {
  664. return new Promise((resolve, reject) => {
  665. uni.uploadFile({
  666. url: BASE_URL + '/feedback/upload',
  667. filePath: filePath,
  668. name: 'file',
  669. success: (res) => {
  670. try {
  671. const data = JSON.parse(res.data)
  672. if (data.code === 200 || data.code === 0 || data.success) {
  673. resolve(data.data)
  674. } else {
  675. reject(new Error(data.message || '上传失败'))
  676. }
  677. } catch (e) {
  678. reject(new Error('解析响应数据失败'))
  679. }
  680. },
  681. fail: (error) => {
  682. reject(new Error('上传请求失败: ' + (error.errMsg || '未知错误')))
  683. }
  684. })
  685. })
  686. }
  687. },
  688. // 积分商城相关
  689. pointsMall: {
  690. // 获取商品列表
  691. getProducts: (params) => request({
  692. url: '/points/products',
  693. method: 'GET',
  694. data: params
  695. }),
  696. // 获取推荐商品
  697. getRecommendProducts: (limit = 10) => request({
  698. url: `/points/products/recommend?limit=${limit}`,
  699. method: 'GET'
  700. }),
  701. // 获取商品详情
  702. getProductDetail: (id) => request({
  703. url: `/points/products/${id}`,
  704. method: 'GET'
  705. }),
  706. // 获取积分余额
  707. getBalance: (makerId) => request({
  708. url: `/points/balance?makerId=${makerId}`,
  709. method: 'GET'
  710. }),
  711. // 获取积分明细
  712. getRecords: (makerId, pageNum = 1, pageSize = 20) => request({
  713. url: `/points/records?makerId=${makerId}&pageNum=${pageNum}&pageSize=${pageSize}`,
  714. method: 'GET'
  715. }),
  716. // 获取积分规则
  717. getRules: () => request({
  718. url: '/points/rules',
  719. method: 'GET'
  720. }),
  721. // 兑换商品
  722. exchange: (data) => request({
  723. url: '/points/exchange',
  724. method: 'POST',
  725. data
  726. }),
  727. // 获取订单列表
  728. getOrders: (makerId, status, pageNum = 1, pageSize = 10) => {
  729. let url = `/points/orders?makerId=${makerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  730. if (status !== undefined && status !== null) {
  731. url += `&status=${status}`
  732. }
  733. return request({ url, method: 'GET' })
  734. },
  735. // 获取订单详情
  736. getOrderDetail: (orderNo) => request({
  737. url: `/points/orders/${orderNo}`,
  738. method: 'GET'
  739. }),
  740. // 增加积分(签到等)
  741. addPoints: (makerId, ruleType, reason) => request({
  742. url: '/points/add',
  743. method: 'POST',
  744. data: { makerId, ruleType, reason }
  745. })
  746. }
  747. }
  748. // 导出 request 函数供其他模块使用
  749. export { request }