api.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  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. checkinStatus: (makerId) => request({
  274. url: `/matchmaker/checkin/status?makerId=${makerId}`
  275. }),
  276. checkinStats: (makerId) => request({
  277. url: `/matchmaker/checkin/stats?makerId=${makerId}`
  278. }),
  279. doCheckin: (makerId) => request({
  280. url: `/matchmaker/checkin/do?makerId=${makerId}`,
  281. method: 'POST'
  282. }),
  283. // 更新红娘资料(编辑资料页使用)
  284. updateProfile: (matchmakerId, data) => request({
  285. url: `/matchmaker/update/${matchmakerId}`,
  286. method: 'PUT',
  287. data
  288. })
  289. },
  290. // 推荐相关
  291. recommend: {
  292. // 获取推荐用户列表(网关转发到推荐服务)
  293. getUsers: ({ userId, oppoOnly = 1, limit = 20, excludeIds }) => {
  294. let url = `/recommend/users?userId=${userId}&oppoOnly=${oppoOnly}&limit=${limit}`;
  295. if (excludeIds) {
  296. url += `&excludeIds=${excludeIds}`;
  297. }
  298. return request({ url });
  299. },
  300. // 行为反馈:like/dislike
  301. feedback: ({ userId, targetUserId, type }) => request({
  302. url: `/recommend/feedback?userId=${userId}&targetUserId=${targetUserId}&type=${type}`
  303. }),
  304. // 曝光上报
  305. exposure: ({ userId, shownUserIds }) => request({
  306. url: `/recommend/exposure?userId=${userId}&shownUserIds=${encodeURIComponent(shownUserIds)}`
  307. }),
  308. // 规则检索
  309. search: (query) => request({
  310. url: '/recommend/search',
  311. method: 'POST',
  312. data: query
  313. }),
  314. // 获取今日推荐
  315. getTodayRecommend: () => request({
  316. url: '/recommend/today'
  317. })
  318. },
  319. // 消息相关
  320. message: {
  321. // 获取消息列表
  322. getList: (params) => request({
  323. url: '/message/list',
  324. data: params
  325. }),
  326. // 获取会话列表
  327. getConversations: () => request({
  328. url: '/message/conversations'
  329. }),
  330. // 发送消息
  331. send: (data) => request({
  332. url: '/message/send',
  333. method: 'POST',
  334. data
  335. }),
  336. // ===== 系统消息 =====
  337. getSystemList: async (userId, pageNum = 1, pageSize = 20) => {
  338. const res = await request({ url: `/message/system/list?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}` })
  339. // 后端Result包装:{ code, data:{ list,total,page,pageSize } }
  340. return res.data || res
  341. },
  342. getSystemUnreadCount: async (userId) => {
  343. const res = await request({ url: `/message/system/unread-count?userId=${userId}` })
  344. return (typeof res.data === 'number') ? res.data : (res.data?.count || 0)
  345. },
  346. markSystemRead: (id) => request({
  347. url: `/message/system/read/${id}`,
  348. method: 'POST'
  349. }),
  350. getSystemDetail: async (id) => {
  351. const res = await request({ url: `/message/system/detail/${id}` })
  352. return res.data || res
  353. },
  354. markAllSystemRead: (userId) => request({
  355. url: `/message/system/read-all?userId=${userId}`,
  356. method: 'POST'
  357. })
  358. },
  359. // 动态相关
  360. dynamic: {
  361. // 获取推荐动态列表(广场)
  362. getRecommendList: (params) => request({
  363. url: '/dynamic/recommend',
  364. data: params
  365. }),
  366. // 获取动态列表
  367. getList: (params) => request({
  368. url: '/dynamic/list',
  369. data: params
  370. }),
  371. // 获取动态详情
  372. getDetail: (dynamicId, userId) => request({
  373. url: `/dynamic/detail/${dynamicId}`,
  374. data: { userId }
  375. }),
  376. // 发表评论
  377. addComment: (dynamicId, content, images, parentCommentId = 0) => request({
  378. url: `/dynamic/comment`,
  379. method: 'POST',
  380. data: { dynamicId, content, images, parentCommentId, userId: 1 },
  381. header: { 'Content-Type': 'application/json' }
  382. }),
  383. // 评论列表
  384. getComments: (dynamicId, pageNum = 1, pageSize = 10) => request({
  385. url: `/dynamic/comment/list/${dynamicId}`,
  386. data: { pageNum, pageSize }
  387. }),
  388. // 评论点赞/取消
  389. likeComment: (commentId, userId) => {
  390. // 如果没有传入userId,从本地存储获取
  391. if (!userId) {
  392. const userInfo = uni.getStorageSync('userInfo');
  393. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  394. }
  395. if (!userId) {
  396. return Promise.reject(new Error('用户未登录'));
  397. }
  398. return request({
  399. url: `/dynamic/comment/like?commentId=${commentId}&userId=${userId}`,
  400. method: 'POST'
  401. });
  402. },
  403. unlikeComment: (commentId, userId) => {
  404. // 如果没有传入userId,从本地存储获取
  405. if (!userId) {
  406. const userInfo = uni.getStorageSync('userInfo');
  407. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  408. }
  409. if (!userId) {
  410. return Promise.reject(new Error('用户未登录'));
  411. }
  412. return request({
  413. url: `/dynamic/comment/like/${commentId}?userId=${userId}`,
  414. method: 'DELETE'
  415. });
  416. },
  417. // 获取用户动态列表
  418. getUserDynamics: (userId, params) => {
  419. const { pageNum = 1, pageSize = 10, currentUserId = null } = params || {}
  420. let url = `/dynamic/user/${userId}?pageNum=${pageNum}&pageSize=${pageSize}`
  421. if (currentUserId) {
  422. url += `&currentUserId=${currentUserId}`
  423. }
  424. return request({
  425. url: url,
  426. method: 'GET'
  427. })
  428. },
  429. // 点赞动态
  430. like: (dynamicId, userId) => {
  431. // 如果没有传入userId,从本地存储获取
  432. if (!userId) {
  433. const userInfo = uni.getStorageSync('userInfo');
  434. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  435. }
  436. if (!userId) {
  437. return Promise.reject(new Error('用户未登录'));
  438. }
  439. return request({
  440. url: `/dynamic/like?dynamicId=${dynamicId}&userId=${userId}`,
  441. method: 'POST'
  442. });
  443. },
  444. // 取消点赞
  445. unlike: (dynamicId, userId) => {
  446. // 如果没有传入userId,从本地存储获取
  447. if (!userId) {
  448. const userInfo = uni.getStorageSync('userInfo');
  449. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  450. }
  451. if (!userId) {
  452. return Promise.reject(new Error('用户未登录'));
  453. }
  454. return request({
  455. url: `/dynamic/like/${dynamicId}?userId=${userId}`,
  456. method: 'DELETE'
  457. });
  458. },
  459. // 收藏动态
  460. favorite: (dynamicId, userId) => {
  461. // 如果没有传入userId,从本地存储获取
  462. if (!userId) {
  463. const userInfo = uni.getStorageSync('userInfo');
  464. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  465. }
  466. if (!userId) {
  467. return Promise.reject(new Error('用户未登录'));
  468. }
  469. return request({
  470. url: `/dynamic/favorite?dynamicId=${dynamicId}&userId=${userId}`,
  471. method: 'POST'
  472. });
  473. },
  474. // 取消收藏
  475. unfavorite: (dynamicId, userId) => {
  476. // 如果没有传入userId,从本地存储获取
  477. if (!userId) {
  478. const userInfo = uni.getStorageSync('userInfo');
  479. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  480. }
  481. if (!userId) {
  482. return Promise.reject(new Error('用户未登录'));
  483. }
  484. return request({
  485. url: `/dynamic/favorite/${dynamicId}?userId=${userId}`,
  486. method: 'DELETE'
  487. });
  488. },
  489. // 创建个人动态
  490. createUserDynamic: (payload) => request({
  491. url: '/dynamic/user',
  492. method: 'POST',
  493. data: payload,
  494. header: { 'Content-Type': 'application/json' }
  495. }),
  496. // 更新个人动态
  497. updateUserDynamic: (dynamicId, userId, payload) => request({
  498. url: `/dynamic/user/${dynamicId}?userId=${userId}`,
  499. method: 'PUT',
  500. data: payload,
  501. header: { 'Content-Type': 'application/json' }
  502. }),
  503. // 删除个人动态
  504. deleteUserDynamic: (dynamicId, userId) => request({
  505. url: `/dynamic/user/${dynamicId}?userId=${userId}`,
  506. method: 'DELETE'
  507. }),
  508. // 删除动态(旧接口,保留兼容)
  509. delete: (dynamicId) => request({
  510. url: `/dynamic/${dynamicId}`,
  511. method: 'DELETE'
  512. }),
  513. // 发布动态(文本或已存在的媒体URL列表)
  514. publish: (payload) => request({
  515. url: '/dynamic/publish',
  516. method: 'POST',
  517. data: payload,
  518. header: { 'Content-Type': 'application/json' }
  519. }),
  520. // 单个文件上传方法
  521. uploadSingle: (filePath) => {
  522. return new Promise((resolve, reject) => {
  523. console.log('开始上传文件:', filePath)
  524. console.log('上传URL:', BASE_URL + '/dynamic/publish/upload')
  525. uni.uploadFile({
  526. url: BASE_URL + '/dynamic/publish/upload',
  527. filePath: filePath,
  528. name: 'file',
  529. success: (res) => {
  530. console.log('上传响应:', res)
  531. try {
  532. const data = JSON.parse(res.data)
  533. console.log('解析后的响应数据:', data)
  534. if (data.code === 200 || data.code === 0 || data.success) {
  535. console.log('上传成功,返回URL:', data.data)
  536. resolve(data.data)
  537. } else {
  538. console.error('上传失败,服务器返回错误:', data)
  539. reject(new Error(data.message || '上传失败'))
  540. }
  541. } catch (e) {
  542. console.error('解析响应数据失败:', e, '原始响应:', res.data)
  543. reject(new Error('解析响应数据失败'))
  544. }
  545. },
  546. fail: (error) => {
  547. console.error('上传请求失败:', error)
  548. reject(new Error('上传请求失败: ' + (error.errMsg || '未知错误')))
  549. }
  550. })
  551. })
  552. },
  553. // 批量上传多个文件(遍历调用单个上传)
  554. uploadBatch: (filePaths) => {
  555. return new Promise(async (resolve, reject) => {
  556. const urls = []
  557. try {
  558. for (let filePath of filePaths) {
  559. const url = await new Promise((resolveUpload, rejectUpload) => {
  560. uni.uploadFile({
  561. url: BASE_URL + '/dynamic/publish/upload',
  562. filePath: filePath,
  563. name: 'file',
  564. success: (res) => {
  565. try {
  566. const data = JSON.parse(res.data)
  567. if (data.code === 200 || data.code === 0 || data.success) {
  568. resolveUpload(data.data)
  569. } else {
  570. rejectUpload(data)
  571. }
  572. } catch (e) {
  573. rejectUpload(e)
  574. }
  575. },
  576. fail: rejectUpload
  577. })
  578. })
  579. urls.push(url)
  580. }
  581. resolve(urls)
  582. } catch (e) {
  583. reject(new Error(`批量上传失败: ${e.message || '未知错误'}`))
  584. }
  585. })
  586. },
  587. // 提交举报
  588. submitReport: (data) => request({
  589. url: '/dynamic/report',
  590. method: 'POST',
  591. data
  592. }),
  593. // 获取用户收藏列表
  594. getFavoritesList: (userId, pageNum = 1, pageSize = 10) => request({
  595. url: `/dynamic/favorites?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  596. }),
  597. // 获取用户点赞列表
  598. getLikedList: (userId, pageNum = 1, pageSize = 10) => request({
  599. url: `/dynamic/likes?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  600. }),
  601. // 获取用户浏览记录列表
  602. getBrowseHistoryList: (userId, pageNum = 1, pageSize = 10) => request({
  603. url: `/dynamic/browse-history?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  604. }),
  605. // 清空用户浏览记录
  606. clearBrowseHistory: (userId) => request({
  607. url: `/dynamic/browse-history?userId=${userId}`,
  608. method: 'DELETE'
  609. })
  610. },
  611. // VIP相关
  612. vip: {
  613. // 获取VIP信息(状态、套餐等)
  614. getInfo: (userId) => request({
  615. url: `/vip/info?userId=${userId}`
  616. }),
  617. // 获取VIP套餐列表
  618. getPackages: () => request({
  619. url: '/vip/packages'
  620. }),
  621. // 购买VIP套餐(获取支付参数)
  622. purchase: (userId, packageId) => request({
  623. url: '/vip/purchase',
  624. method: 'POST',
  625. data: { userId, packageId }
  626. }),
  627. // 查询订单状态
  628. getOrderStatus: (orderNo) => request({
  629. url: `/vip/order/status?orderNo=${orderNo}`
  630. }),
  631. // 新增:查询支付状态(userId + packageId)
  632. checkPayStatus: (userId, packageId) => request({
  633. url: '/vip/checkPayStatus',
  634. method: 'GET',
  635. data: { userId, packageId }
  636. })
  637. },
  638. // 用户反馈
  639. feedback: {
  640. // 提交用户反馈
  641. submit: (data) => request({
  642. url: '/feedback/submit',
  643. method: 'POST',
  644. data
  645. }),
  646. // 上传反馈图片
  647. uploadImage: (filePath) => {
  648. return new Promise((resolve, reject) => {
  649. uni.uploadFile({
  650. url: BASE_URL + '/feedback/upload',
  651. filePath: filePath,
  652. name: 'file',
  653. success: (res) => {
  654. try {
  655. const data = JSON.parse(res.data)
  656. if (data.code === 200 || data.code === 0 || data.success) {
  657. resolve(data.data)
  658. } else {
  659. reject(new Error(data.message || '上传失败'))
  660. }
  661. } catch (e) {
  662. reject(new Error('解析响应数据失败'))
  663. }
  664. },
  665. fail: (error) => {
  666. reject(new Error('上传请求失败: ' + (error.errMsg || '未知错误')))
  667. }
  668. })
  669. })
  670. }
  671. },
  672. // 积分商城相关
  673. pointsMall: {
  674. // 获取商品列表
  675. getProducts: (params) => request({
  676. url: '/points/products',
  677. method: 'GET',
  678. data: params
  679. }),
  680. // 获取推荐商品
  681. getRecommendProducts: (limit = 10) => request({
  682. url: `/points/products/recommend?limit=${limit}`,
  683. method: 'GET'
  684. }),
  685. // 获取商品详情
  686. getProductDetail: (id) => request({
  687. url: `/points/products/${id}`,
  688. method: 'GET'
  689. }),
  690. // 获取积分余额
  691. getBalance: (makerId) => request({
  692. url: `/points/balance?makerId=${makerId}`,
  693. method: 'GET'
  694. }),
  695. // 获取积分明细
  696. getRecords: (makerId, pageNum = 1, pageSize = 20) => request({
  697. url: `/points/records?makerId=${makerId}&pageNum=${pageNum}&pageSize=${pageSize}`,
  698. method: 'GET'
  699. }),
  700. // 获取积分规则
  701. getRules: () => request({
  702. url: '/points/rules',
  703. method: 'GET'
  704. }),
  705. // 兑换商品
  706. exchange: (data) => request({
  707. url: '/points/exchange',
  708. method: 'POST',
  709. data
  710. }),
  711. // 获取订单列表
  712. getOrders: (makerId, status, pageNum = 1, pageSize = 10) => {
  713. let url = `/points/orders?makerId=${makerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  714. if (status !== undefined && status !== null) {
  715. url += `&status=${status}`
  716. }
  717. return request({ url, method: 'GET' })
  718. },
  719. // 获取订单详情
  720. getOrderDetail: (orderNo) => request({
  721. url: `/points/orders/${orderNo}`,
  722. method: 'GET'
  723. }),
  724. // 增加积分(签到等)
  725. addPoints: (makerId, ruleType, reason) => request({
  726. url: '/points/add',
  727. method: 'POST',
  728. data: { makerId, ruleType, reason }
  729. })
  730. },
  731. // 我的资源相关(通过网关访问8081服务)
  732. myResource: {
  733. // 获取资源列表
  734. getList: (matchmakerId, keyword, pageNum = 1, pageSize = 10) => {
  735. let url = `/my-resource/list?matchmakerId=${matchmakerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  736. if (keyword) {
  737. url += `&keyword=${encodeURIComponent(keyword)}`
  738. }
  739. return request({ url })
  740. },
  741. // 搜索资源(按姓名或手机号)
  742. search: (matchmakerId, keyword, gender) => {
  743. let url = `/my-resource/search?matchmakerId=${matchmakerId}`
  744. if (keyword) {
  745. url += `&keyword=${encodeURIComponent(keyword)}`
  746. }
  747. if (gender) {
  748. url += `&gender=${gender}`
  749. }
  750. return request({ url })
  751. },
  752. // 获取资源下拉列表
  753. getDropdown: (matchmakerId, gender) => {
  754. let url = `/my-resource/dropdown?matchmakerId=${matchmakerId}`
  755. if (gender) {
  756. url += `&gender=${gender}`
  757. }
  758. return request({ url })
  759. },
  760. // 获取已注册用户的资源下拉列表(user_id不为空)
  761. getRegisteredDropdown: (matchmakerId, gender) => {
  762. let url = `/my-resource/registered-dropdown?matchmakerId=${matchmakerId}`
  763. if (gender) {
  764. url += `&gender=${gender}`
  765. }
  766. return request({ url })
  767. },
  768. // 搜索已注册用户的资源(user_id不为空)
  769. searchRegistered: (matchmakerId, keyword, gender) => {
  770. let url = `/my-resource/registered-search?matchmakerId=${matchmakerId}`
  771. if (keyword) {
  772. url += `&keyword=${encodeURIComponent(keyword)}`
  773. }
  774. if (gender) {
  775. url += `&gender=${gender}`
  776. }
  777. return request({ url })
  778. }
  779. },
  780. // 撮合成功案例上传相关(通过网关访问1004服务)
  781. successCaseUpload: {
  782. // 提交成功案例
  783. submit: (data) => request({
  784. url: '/success-case-upload/submit',
  785. method: 'POST',
  786. data
  787. }),
  788. // 获取成功案例列表
  789. getList: (matchmakerId, pageNum = 1, pageSize = 10) => request({
  790. url: `/success-case-upload/list?matchmakerId=${matchmakerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  791. }),
  792. // 获取审核记录列表
  793. getAuditRecords: (matchmakerId, auditStatus, pageNum = 1, pageSize = 20) => {
  794. let url = `/success-case-upload/audit-records?matchmakerId=${matchmakerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  795. if (auditStatus !== null && auditStatus !== undefined) {
  796. url += `&auditStatus=${auditStatus}`
  797. }
  798. return request({ url })
  799. },
  800. // 获取审核记录详情
  801. getAuditRecordDetail: (id) => request({
  802. url: `/success-case-upload/audit-records/${id}`
  803. }),
  804. // 标记审核记录为已读
  805. markAsRead: (id) => request({
  806. url: `/success-case-upload/audit-records/${id}/read`,
  807. method: 'POST'
  808. }),
  809. // 获取未读审核记录数量
  810. getUnreadCount: (matchmakerId) => request({
  811. url: `/success-case-upload/audit-records/unread-count?matchmakerId=${matchmakerId}`
  812. })
  813. }
  814. }
  815. // 导出 request 函数供其他模块使用
  816. export { request }