Files
Wechat/utils/dashou-profile.js

66 lines
2.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 从服务端刷新打手会员/押金/积分等到 globalData(抢单、考试等页共用)
*/
import request from './request.js';
import { consumeBadgeFields } from './dashou-badges.js';
export async function refreshDashouMembership(app) {
app = app || getApp();
try {
const res = await request({ url: '/yonghu/dashouxinxi', method: 'POST' });
if (res && res.data && res.data.code == 200) {
const data = res.data.data || {};
consumeBadgeFields(data);
if (data.zhanghaostatus !== undefined && Number(data.zhanghaostatus) !== 1) {
try {
const { kickToLoginPage } = require('./fighter-only.js');
kickToLoginPage(
data.fengjin_yuanyin
? `账号状态异常,您的账号已被封禁。原因:${data.fengjin_yuanyin}`
: '账号状态异常,您的账号已被封禁,请联系客服'
);
} catch (e) {}
return app.globalData.clumber || [];
}
const clumber = Array.isArray(data.clumber) ? data.clumber : [];
app.globalData.clumber = clumber;
if (data.yajin !== undefined) app.globalData.yajin = data.yajin;
if (data.jifen !== undefined) app.globalData.jinfen = data.jifen;
if (data.zhanghaostatus !== undefined) app.globalData.zhanghaoStatus = data.zhanghaostatus;
if (data.dashouzhuangtai !== undefined) app.globalData.dashouzhuangtai = data.dashouzhuangtai;
return clumber;
}
} catch (e) {
console.error('refreshDashouMembership failed', e);
}
return app.globalData.clumber || [];
}
/** 会员 ID 等价比较(001 与 1 视为相同,与后端 huiyuan_ids_match 一致) */
export function huiyuanIdMatch(a, b) {
const left = String(a ?? '').trim();
const right = String(b ?? '').trim();
if (!left || !right) return false;
if (left === right) return true;
const leftCore = left.replace(/^0+/, '') || '0';
const rightCore = right.replace(/^0+/, '') || '0';
return leftCore === rightCore;
}
/** 用户是否持有某会员类型(与抢单卡片判断一致;支持总会员 included_huiyuan_ids / from_bundle) */
export function userHasHuiyuan(huiyuanList, huiyuanId) {
if (!huiyuanId && huiyuanId !== 0) return true;
const list = huiyuanList || [];
const req = String(huiyuanId);
return list.some((h) => {
if (huiyuanIdMatch(h.huiyuanid, req) || huiyuanIdMatch(h.huiyuan_id, req)) {
return true;
}
const covers = h.included_huiyuan_ids || h.covers || [];
if (Array.isArray(covers) && covers.some((id) => huiyuanIdMatch(id, req))) {
return true;
}
return false;
});
}