user.ts 5.0 KB

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