user.ts 5.8 KB

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