| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- import Http from "../utils/http";
- import { host, isDebug } from "../utils/constant";
- const userHttp = new Http(host);
- export function fetchProfile() {
- return userHttp.get("/user/me").then((res) => {
- res.balance = (Number(res.balance) / 100).toFixed(2);
- res.discountAmount = (Number(res.discountAmount) / 100).toFixed(2);
- res.refundableAmount = (Number(res.refundableAmount) / 100).toFixed(2);
- // if (isDebug) {
- // res.userRechargeRightsList = [
- // {
- // discount: 90,
- // },
- // ];
- // }
- getApp<any>().globalData.user = res;
- return res;
- });
- }
- /**
- * 查询我的权益和优惠券
- */
- export function fetchRightsAndCoupons() {
- return userHttp.get("/account/listRightsAndCoupons").then((res) => {
- return res;
- });
- }
- export function fetchCollectList() {
- if (getApp<any>().globalData.collectIds) {
- return Promise.resolve(getApp<any>().globalData.collectIds);
- }
- return userHttp
- .get<
- {
- status: number;
- stationId: number;
- }[]
- >("/user/collectList?page=1&page_size=999")
- .then((res) => {
- getApp<any>().globalData.collectIds = res
- ? res
- .filter((item) => Number(item.status) === 1)
- .map((item) => {
- return Number(item.stationId);
- })
- : [];
- return getApp<any>().globalData.collectIds;
- });
- }
- export function addCollectList(sid: number) {
- let ids = getApp<any>().globalData.collectIds
- ? (getApp<any>().globalData.collectIds as number[])
- : [];
- const status = ids.includes(sid) ? 0 : 1;
- return userHttp
- .post("/user/collect", {
- data: {
- stationId: sid,
- status,
- },
- })
- .then(() => {
- if (status === 1) {
- ids.push(sid);
- } else {
- ids = ids.filter((id) => id !== sid);
- }
- getApp<any>().globalData.collectIds = ids;
- return status === 1;
- });
- }
- export function updateProfile(data: any) {
- return userHttp.put("/user", {
- data,
- });
- }
- declare const wx: any;
- export function insertMoney(amount: number) {
- if (isDebug) {
- return Promise.resolve();
- }
- return userHttp
- .post("/payment/wxPay", {
- data: {
- amount: parseInt(`${amount * 100}`),
- openid: getApp<any>().globalData.user.openid,
- },
- })
- .then((res: any) => {
- return new Promise((resolve, reject) => {
- // #ifdef MP-WEIXIN
- wx.requestPayment({
- timeStamp: `${res.timeStamp}`,
- nonceStr: res.nonceStr,
- package: res.packageVal,
- signType: res.signType,
- paySign: res.paySign,
- success(res: any) {
- resolve(res);
- },
- fail: reject,
- });
- // #endif
- // #ifndef MP-WEIXIN
- reject({
- errMsg: "目前仅支持微信支付",
- });
- // #endif
- });
- });
- }
- export function logout() {
- return userHttp.get("/user/logout");
- }
- export function fetchWallet(
- type: number,
- page: number,
- pageSize: number,
- query?: string
- ) {
- return userHttp.get(
- `/account/walletDetail?page=${page}&page_size=${pageSize}&type=${type}${
- query ? "&" + query : ""
- }`
- );
- }
- export function fetchOrder(orderid: string) {
- return userHttp.get(`/charge/orderDetail/${orderid}`);
- }
- export function fetchOrders(page: number, pageSize: number, query?: string) {
- return userHttp.get(
- `/charge/listUserChargeOrders?pageNum=${page}&pageSize=${pageSize}${
- query ? "&" + query : ""
- }`
- );
- }
- export function applyRefund(reason: string) {
- return userHttp.post(`/payment/wxApplyRefund`, {
- data: {
- reason,
- },
- });
- }
- export function listRefund(param: any) {
- return userHttp.post(`/account/listRefund`, {
- data: {
- ...param,
- },
- });
- }
- /**
- * 获取站点可以领取的优惠券
- * @param stationId
- */
- export function listAvailableCoupons(stationId: any) {
- return userHttp.get(`/coupon/listAvailableCoupons?stationId=${stationId}`, {
- });
- }
- /**
- * 领取优惠券
- * @param couponId
- */
- export function collectCoupon (couponId: number) {
- return userHttp.get(`/coupon/collectCoupon?couponId=${couponId}`, {
- });
- }
|