Commit 137dfd58 authored by qinhaitao's avatar qinhaitao

refactor: 💡 login

parent 51ec8a9c
......@@ -27,12 +27,12 @@ declare const _default: {
list: IAwards[];
}>>;
receiveObjectPrize: (context: IContext<import("./controller/awards.controller").IReceiveOjectParams>, { activityInfo }: import("./controller/awards.controller").IReceivePrizeControllerInfos, [awardSer]: [import("./service").AwardsService]) => Promise<IResult<boolean>>;
receiveEnamePrize: (context: IContext<import("./controller/awards.controller").IReceiveEnameParams>, { awardInfo, session }: import("./controller/awards.controller").IReceivePrizeControllerInfos, [awardSer]: [import("./service").AwardsService]) => Promise<import("taobao-mini-sdk/lib/utils/resultmodel").Result<string | boolean | object | string[] | object[] | number[], false> | import("taobao-mini-sdk/lib/utils/resultmodel").Result<IAwards | import("taobao-mini-sdk/lib/utils/codetypes").CodeType, true>>;
receiveEnamePrize: (context: IContext<import("./controller/awards.controller").IReceiveEnameParams>, { awardInfo, session }: import("./controller/awards.controller").IReceivePrizeControllerInfos, [awardSer]: [import("./service").AwardsService]) => Promise<import("taobao-mini-sdk/lib/utils/resultmodel").Result<string | boolean | object | string[] | number[] | object[], false> | import("taobao-mini-sdk/lib/utils/resultmodel").Result<import("taobao-mini-sdk/lib/utils/codetypes").CodeType | IAwards, true>>;
doHelp: (context: IContext<{
activityId: string;
inviteId: string;
}>, { userInfo, activityInfo, inviteUserInfo }: import("./controller/share.controller").IdoHelpInfos, [taskService, statService]: [import("./service").TaskService, import("./service").StatService]) => Promise<IResult<boolean>>;
getStats: (context: IContext<import("./controller/stat.controller").IGetStatsParams>) => Promise<import("taobao-mini-sdk/lib/utils/resultmodel").Result<string | boolean | object | string[] | object[] | number[], false> | import("taobao-mini-sdk/lib/utils/resultmodel").Result<any, true>>;
getStats: (context: IContext<import("./controller/stat.controller").IGetStatsParams>) => Promise<import("taobao-mini-sdk/lib/utils/resultmodel").Result<string | boolean | object | string[] | number[] | object[], false> | import("taobao-mini-sdk/lib/utils/resultmodel").Result<any, true>>;
addStat: (context: IContext<import("./controller/stat.controller").IAddStatsParams>, { userInfo }: IControllerInfos, [statService]: [import("./service").StatService]) => Promise<import("taobao-mini-sdk/lib/utils/resultmodel").Result<boolean, true>>;
getRankList: (context: IContext<{
activityId: string;
......
......@@ -19,6 +19,7 @@ declare class UserService extends BaseService {
* @returns 若用户不存在,返回null; 用户存在,返回用户信息(object对象)
*/
getUserInfoByOpenId(openId: string): Promise<IUserInfo>;
doLogin(userInfo: IUserInfo, vipInfo: IVipInfo, activityInfo: IActivityInfo): Promise<IUserInfo>;
/**
* 初始化用户数据
*
......
......@@ -120,6 +120,25 @@ var UserService = /** @class */ (function (_super) {
});
});
};
UserService.prototype.doLogin = function (userInfo, vipInfo, activityInfo) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!!userInfo) return [3 /*break*/, 2];
return [4 /*yield*/, this.initUserData(vipInfo, activityInfo)];
case 1:
userInfo = _a.sent();
return [3 /*break*/, 4];
case 2: return [4 /*yield*/, this.updateUserData(vipInfo, userInfo, activityInfo)];
case 3:
userInfo = _a.sent();
_a.label = 4;
case 4: return [2 /*return*/, userInfo];
}
});
});
};
/**
* 初始化用户数据
*
......@@ -130,17 +149,17 @@ var UserService = /** @class */ (function (_super) {
*/
UserService.prototype.initUserData = function (vipInfo, activityInfo) {
return __awaiter(this, void 0, void 0, function () {
var _a, openId, data, activityId, isFollow, avatar, inviteId, userNick, today, tasks, follow, member, user;
var _b, _c;
return __generator(this, function (_d) {
switch (_d.label) {
var _a, openId, data, activityId, isFollow, avatar, inviteId, userNick, today, tasks, _b, follow, _c, member, user;
var _d, _e;
return __generator(this, function (_f) {
switch (_f.label) {
case 0:
_a = this.context, openId = _a.openId, data = _a.data;
activityId = data.activityId, isFollow = data.isFollow, avatar = data.avatar, inviteId = data.inviteId, userNick = data.userNick;
today = utils_1.getToday();
console.log("----------" + today + "----------", today);
tasks = activityInfo.tasks;
follow = tasks.follow, member = tasks.member;
_b = tasks.follow, follow = _b === void 0 ? {} : _b, _c = tasks.member, member = _c === void 0 ? {} : _c;
user = {
activityId: activityId,
avatar: avatar,
......@@ -158,12 +177,12 @@ var UserService = /** @class */ (function (_super) {
follow: {
flag: !!isFollow
},
login: (_b = {},
_b[today] = 1,
_b),
taskInfo: (_c = {},
_c[today] = {},
_c),
login: (_d = {},
_d[today] = 1,
_d),
taskInfo: (_e = {},
_e[today] = {},
_e),
createTime: Date.now(),
createDay: today,
updateTime: Date.now()
......@@ -178,7 +197,7 @@ var UserService = /** @class */ (function (_super) {
}
return [4 /*yield*/, this.userdao.insertOne(user)];
case 1:
_d.sent();
_f.sent();
return [2 /*return*/, user];
}
});
......
This diff is collapsed.
......@@ -28,14 +28,9 @@ export default class User {
): Promise<IResult<{ openId: string }>> {
const { openId } = context
if (!userInfo) {
userInfo = await userService.initUserData(vipInfo, activityInfo)
} else {
userInfo = await userService.updateUserData(vipInfo, userInfo, activityInfo)
}
const updatedUserInfo = await userService.doLogin(userInfo, vipInfo, activityInfo)
// access表
await accessService.addAccess(userInfo)
await accessService.addAccess(updatedUserInfo)
return resultsModel.success({
openId
......
......@@ -11,6 +11,7 @@ import { getToday, formatUpdateUserProjection } from '../utils'
import { isNewVip } from '../utils/common/userUpdate'
import { formatUserNick } from '../utils/common/format'
import { getShopVip, formatVipCbUrl } from '../utils/common/vip'
import { userInfo } from 'os'
class UserService extends BaseService {
userdao: IBaseDao
constructor(context: IContext<IParams>) {
......@@ -40,6 +41,15 @@ class UserService extends BaseService {
return record
}
async doLogin(userInfo: IUserInfo, vipInfo: IVipInfo, activityInfo: IActivityInfo) {
if (!userInfo) {
userInfo = await this.initUserData(vipInfo, activityInfo)
} else {
userInfo = await this.updateUserData(vipInfo, userInfo, activityInfo)
}
return userInfo
}
/**
* 初始化用户数据
*
......@@ -54,7 +64,7 @@ class UserService extends BaseService {
const today = getToday()
console.log(`----------${today}----------`, today)
const { tasks } = activityInfo
const { follow, member } = tasks
const { follow = {} as ITaskConfig, member = {} as ITaskConfig } = tasks
const user: IUserInfo = {
activityId,
avatar,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment