Commit 137dfd58 authored by qinhaitao's avatar qinhaitao

refactor: 💡 login

parent 51ec8a9c
...@@ -27,12 +27,12 @@ declare const _default: { ...@@ -27,12 +27,12 @@ declare const _default: {
list: IAwards[]; list: IAwards[];
}>>; }>>;
receiveObjectPrize: (context: IContext<import("./controller/awards.controller").IReceiveOjectParams>, { activityInfo }: import("./controller/awards.controller").IReceivePrizeControllerInfos, [awardSer]: [import("./service").AwardsService]) => Promise<IResult<boolean>>; 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<{ doHelp: (context: IContext<{
activityId: string; activityId: string;
inviteId: string; inviteId: string;
}>, { userInfo, activityInfo, inviteUserInfo }: import("./controller/share.controller").IdoHelpInfos, [taskService, statService]: [import("./service").TaskService, import("./service").StatService]) => Promise<IResult<boolean>>; }>, { 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>>; 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<{ getRankList: (context: IContext<{
activityId: string; activityId: string;
......
...@@ -19,6 +19,7 @@ declare class UserService extends BaseService { ...@@ -19,6 +19,7 @@ declare class UserService extends BaseService {
* @returns 若用户不存在,返回null; 用户存在,返回用户信息(object对象) * @returns 若用户不存在,返回null; 用户存在,返回用户信息(object对象)
*/ */
getUserInfoByOpenId(openId: string): Promise<IUserInfo>; getUserInfoByOpenId(openId: string): Promise<IUserInfo>;
doLogin(userInfo: IUserInfo, vipInfo: IVipInfo, activityInfo: IActivityInfo): Promise<IUserInfo>;
/** /**
* 初始化用户数据 * 初始化用户数据
* *
......
...@@ -120,6 +120,25 @@ var UserService = /** @class */ (function (_super) { ...@@ -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) { ...@@ -130,17 +149,17 @@ var UserService = /** @class */ (function (_super) {
*/ */
UserService.prototype.initUserData = function (vipInfo, activityInfo) { UserService.prototype.initUserData = function (vipInfo, activityInfo) {
return __awaiter(this, void 0, void 0, function () { return __awaiter(this, void 0, void 0, function () {
var _a, openId, data, activityId, isFollow, avatar, inviteId, userNick, today, tasks, follow, member, user; var _a, openId, data, activityId, isFollow, avatar, inviteId, userNick, today, tasks, _b, follow, _c, member, user;
var _b, _c; var _d, _e;
return __generator(this, function (_d) { return __generator(this, function (_f) {
switch (_d.label) { switch (_f.label) {
case 0: case 0:
_a = this.context, openId = _a.openId, data = _a.data; _a = this.context, openId = _a.openId, data = _a.data;
activityId = data.activityId, isFollow = data.isFollow, avatar = data.avatar, inviteId = data.inviteId, userNick = data.userNick; activityId = data.activityId, isFollow = data.isFollow, avatar = data.avatar, inviteId = data.inviteId, userNick = data.userNick;
today = utils_1.getToday(); today = utils_1.getToday();
console.log("----------" + today + "----------", today); console.log("----------" + today + "----------", today);
tasks = activityInfo.tasks; 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 = { user = {
activityId: activityId, activityId: activityId,
avatar: avatar, avatar: avatar,
...@@ -158,12 +177,12 @@ var UserService = /** @class */ (function (_super) { ...@@ -158,12 +177,12 @@ var UserService = /** @class */ (function (_super) {
follow: { follow: {
flag: !!isFollow flag: !!isFollow
}, },
login: (_b = {}, login: (_d = {},
_b[today] = 1, _d[today] = 1,
_b), _d),
taskInfo: (_c = {}, taskInfo: (_e = {},
_c[today] = {}, _e[today] = {},
_c), _e),
createTime: Date.now(), createTime: Date.now(),
createDay: today, createDay: today,
updateTime: Date.now() updateTime: Date.now()
...@@ -178,7 +197,7 @@ var UserService = /** @class */ (function (_super) { ...@@ -178,7 +197,7 @@ var UserService = /** @class */ (function (_super) {
} }
return [4 /*yield*/, this.userdao.insertOne(user)]; return [4 /*yield*/, this.userdao.insertOne(user)];
case 1: case 1:
_d.sent(); _f.sent();
return [2 /*return*/, user]; return [2 /*return*/, user];
} }
}); });
......
This diff is collapsed.
...@@ -28,14 +28,9 @@ export default class User { ...@@ -28,14 +28,9 @@ export default class User {
): Promise<IResult<{ openId: string }>> { ): Promise<IResult<{ openId: string }>> {
const { openId } = context const { openId } = context
if (!userInfo) { const updatedUserInfo = await userService.doLogin(userInfo, vipInfo, activityInfo)
userInfo = await userService.initUserData(vipInfo, activityInfo)
} else {
userInfo = await userService.updateUserData(vipInfo, userInfo, activityInfo)
}
// access表 // access表
await accessService.addAccess(userInfo) await accessService.addAccess(updatedUserInfo)
return resultsModel.success({ return resultsModel.success({
openId openId
......
...@@ -11,6 +11,7 @@ import { getToday, formatUpdateUserProjection } from '../utils' ...@@ -11,6 +11,7 @@ import { getToday, formatUpdateUserProjection } from '../utils'
import { isNewVip } from '../utils/common/userUpdate' import { isNewVip } from '../utils/common/userUpdate'
import { formatUserNick } from '../utils/common/format' import { formatUserNick } from '../utils/common/format'
import { getShopVip, formatVipCbUrl } from '../utils/common/vip' import { getShopVip, formatVipCbUrl } from '../utils/common/vip'
import { userInfo } from 'os'
class UserService extends BaseService { class UserService extends BaseService {
userdao: IBaseDao userdao: IBaseDao
constructor(context: IContext<IParams>) { constructor(context: IContext<IParams>) {
...@@ -40,6 +41,15 @@ class UserService extends BaseService { ...@@ -40,6 +41,15 @@ class UserService extends BaseService {
return record 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 { ...@@ -54,7 +64,7 @@ class UserService extends BaseService {
const today = getToday() const today = getToday()
console.log(`----------${today}----------`, today) console.log(`----------${today}----------`, today)
const { tasks } = activityInfo const { tasks } = activityInfo
const { follow, member } = tasks const { follow = {} as ITaskConfig, member = {} as ITaskConfig } = tasks
const user: IUserInfo = { const user: IUserInfo = {
activityId, activityId,
avatar, 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