user.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. // 用户服务 - 对应 supermart-mini/service/user.js
  2. import { get, postL, setToken } from './http';
  3. const apis = {
  4. LOGIN: '/api/account/login',
  5. USER_INFO: '/api/myProfile/get',
  6. UPDATE_INFO: '/api/myProfile/basicInfo/update',
  7. UPDATE_AVATAR: '/api/myProfile/avatar/update',
  8. UPDATE_NICKNAME: '/api/myProfile/nickname/update',
  9. REAL_NAME: '/api/authentication/submit',
  10. SEND_CODE: '/api/verifycode/send',
  11. PARAM_CONFIG: '/param/paramConfig',
  12. WALLET_AMOUNT: '/api/wallet/ranking/walletAmount',
  13. WALLET_INFO: '/api/wallet/info',
  14. LOGOFF: '/api/removeAccount/submit',
  15. GET_HIDE: '/api/luckOrder/hide',
  16. SIGN_IN: '/credit/signIn',
  17. CREDIT_RECORD: '/credit/selectCreditRecord',
  18. CREDIT_SHOW: '/credit_show',
  19. ISLAND_SIGN_IN: '/api/activity/activityIsland/signIn',
  20. DISPLAY_REWARDS: '/api/activity/activityIsland/displayRewards',
  21. ACTIVITY_TA_LIST: '/api/activity/activityTa/list',
  22. ACTIVITY_TA_LEVEL: '/api/activity/activityTa/level',
  23. CLAIM_DAILY_REWARD: '/api/wallet/recharge/claimDailyReward',
  24. NEW_USER_NUM: '/api/wallet/ranking/newUserNum',
  25. };
  26. export interface UserInfo {
  27. id: string;
  28. userId?: string;
  29. nickname: string;
  30. avatar: string;
  31. phone?: string;
  32. realName?: string;
  33. idNum?: string;
  34. balance?: number;
  35. }
  36. export interface LoginParams {
  37. loginWay: string;
  38. mobile: string;
  39. verifycode: string;
  40. }
  41. export interface ParamConfig {
  42. code: string;
  43. data: string;
  44. state: number;
  45. }
  46. export interface LoginResult {
  47. success: boolean;
  48. needInfo?: boolean;
  49. }
  50. // 账号登录
  51. export const login = async (params: LoginParams): Promise<LoginResult> => {
  52. const res = await postL<{ tokenInfo: { tokenValue: string }; needPerfectProfile?: boolean }>(apis.LOGIN, params);
  53. if (res.success && res.data?.tokenInfo?.tokenValue) {
  54. setToken(res.data.tokenInfo.tokenValue);
  55. return {
  56. success: true,
  57. needInfo: res.data.needPerfectProfile,
  58. };
  59. }
  60. return { success: false };
  61. };
  62. // 获取用户信息
  63. export const getUserInfo = async (): Promise<UserInfo | null> => {
  64. const res = await get<UserInfo>(apis.USER_INFO);
  65. return res.data;
  66. };
  67. // 更新用户信息
  68. export const updateUserInfo = async (params: Partial<UserInfo>): Promise<boolean> => {
  69. const res = await postL(apis.UPDATE_INFO, params);
  70. return res.success;
  71. };
  72. // 更新头像
  73. export const updateAvatar = async (avatar: string): Promise<boolean> => {
  74. const res = await postL(apis.UPDATE_AVATAR, { avatar });
  75. return res.success;
  76. };
  77. // 更新昵称
  78. export const updateNickname = async (nickname: string): Promise<boolean> => {
  79. const res = await postL(apis.UPDATE_NICKNAME, { nickname });
  80. return res.success;
  81. };
  82. // 实名认证
  83. export const realNameAuth = async (idName: string, idNum: string): Promise<boolean> => {
  84. const res = await postL(apis.REAL_NAME, { idName, idNum });
  85. return res.success;
  86. };
  87. // 发送验证码
  88. export const sendVerifyCode = async (mobile: string, scene = 'LOGIN'): Promise<boolean> => {
  89. const res = await postL(apis.SEND_CODE, { mobile, scene });
  90. return res.success;
  91. };
  92. // 获取参数配置
  93. export const getParamConfig = async (code: string): Promise<ParamConfig | null> => {
  94. const res = await get<ParamConfig>(apis.PARAM_CONFIG, { code });
  95. return res.data;
  96. };
  97. // 获取钱包余额
  98. export const getWalletAmount = async () => {
  99. const res = await get(apis.WALLET_AMOUNT);
  100. return res;
  101. };
  102. // 获取钱包信息(积分等)
  103. export const getWalletInfo = async (type: string) => {
  104. const res = await get(apis.WALLET_INFO, { type });
  105. return res.data;
  106. };
  107. // 注销账号
  108. export const logoff = async (): Promise<boolean> => {
  109. const res = await postL(apis.LOGOFF);
  110. return res.success;
  111. };
  112. // 获取隐藏状态 (1: 没消费,0: 消费)
  113. export const getHide = async () => {
  114. const res = await get(apis.GET_HIDE);
  115. return res.data;
  116. };
  117. // 签到
  118. export const signIn = async () => {
  119. const res = await postL(apis.SIGN_IN);
  120. return res;
  121. };
  122. // 岛屿签到
  123. export const islandSignIn = async () => {
  124. const res = await postL(apis.ISLAND_SIGN_IN);
  125. return res;
  126. };
  127. // 获取积分记录
  128. export const getCreditRecord = async (params?: any) => {
  129. const res = await get(apis.CREDIT_RECORD, params);
  130. return res;
  131. };
  132. // 获取积分显示配置
  133. export const creditShow = async () => {
  134. const res = await get(apis.CREDIT_SHOW);
  135. return res;
  136. };
  137. // 获取展示奖励
  138. export const displayRewards = async () => {
  139. const res = await get(apis.DISPLAY_REWARDS);
  140. return res;
  141. };
  142. // 获取活动列表
  143. export const activityTaList = async () => {
  144. const res = await get(apis.ACTIVITY_TA_LIST);
  145. return res;
  146. };
  147. // 获取活动等级
  148. export const activityTaLevel = async (params?: any) => {
  149. const res = await get(apis.ACTIVITY_TA_LEVEL, params);
  150. return res;
  151. };
  152. // 领取每日奖励
  153. export const claimDailyReward = async (params?: any) => {
  154. const res = await postL(apis.CLAIM_DAILY_REWARD, params);
  155. return res;
  156. };
  157. // 获取新用户数量
  158. export const getNewUserNum = async (params?: any) => {
  159. const res = await get(apis.NEW_USER_NUM, params);
  160. return res;
  161. };
  162. export default {
  163. login,
  164. getUserInfo,
  165. updateUserInfo,
  166. updateAvatar,
  167. updateNickname,
  168. realNameAuth,
  169. sendVerifyCode,
  170. getParamConfig,
  171. getWalletAmount,
  172. getWalletInfo,
  173. logoff,
  174. getHide,
  175. signIn,
  176. islandSignIn,
  177. getCreditRecord,
  178. creditShow,
  179. displayRewards,
  180. activityTaList,
  181. activityTaLevel,
  182. claimDailyReward,
  183. getNewUserNum,
  184. };