Commit 29ebade8 authored by qinhaitao's avatar qinhaitao

feat: 🎸 任务优化

parent 0e1d8117
...@@ -88,7 +88,7 @@ var Share = /** @class */ (function () { ...@@ -88,7 +88,7 @@ var Share = /** @class */ (function () {
switch (_c.label) { switch (_c.label) {
case 0: case 0:
openId = context.openId; openId = context.openId;
return [4 /*yield*/, taskService.completeTask('invites', inviteUserInfo, activityInfo, { return [4 /*yield*/, taskService.completeTask('invites', activityInfo, inviteUserInfo, {
openId: openId openId: openId
})]; })];
case 1: case 1:
......
{"version":3,"file":"share.controller.js","sourceRoot":"","sources":["../../src/controller/share.controller.ts"],"names":[],"mappings":";AAAA,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEd,+CAAkD;AAClD,+CAAuE;AACvE,8BAAqC;AACrC,sCAAkE;AAClE,0CAAwC;AACxC,6EAA2E;AAC3E,qEAAmE;AACnE,yEAAuE;AACvE,iEAA+D;AAC/D,0CAAyC;AACzC,qDAAmD;AACnD,8DAA4D;AAK5D;IAAA;IA8CA,CAAC;IA7CC;;OAEG;IAGG,4BAAY,GAAlB,UACE,OAAyC,EACzC,EAA8B;YAA5B,QAAQ,cAAA;;;;gBAGO,OAAO,GACpB,QAAQ,oBADY,CACZ;gBAEZ,sBAAO,kBAAY,CAAC,OAAO,CAAC;wBAC1B,OAAO,EAAE,OAAO;qBACjB,CAAC,EAAA;;;KACH;IACD;;OAEG;IAMG,sBAAM,GAAZ,UACE,OAGE,EACF,EAAwD,EACxD,EAAsD;YADpD,QAAQ,cAAA,EAAE,YAAY,kBAAA,EAAE,cAAc,oBAAA;YACvC,WAAW,QAAA,EAAE,WAAW,QAAA;;;;;;wBAEjB,MAAM,GAAK,OAAO,OAAZ,CAAY;wBAEX,qBAAM,WAAW,CAAC,YAAY,CAAC,SAAS,EAAE,cAAc,EAAE,YAAY,EAAE;gCACrF,MAAM,QAAA;6BACP,CAAC,EAAA;;wBAFI,MAAM,GAAG,SAEb;wBAEF,IAAI,CAAC,MAAM;4BAAE,sBAAO,kBAAY,CAAC,KAAK,CAAC,sBAAU,CAAC,YAAY,EAAE,OAAO,CAAC,EAAA;wBAExE,qBAAM,WAAW,CAAC,OAAO,CAAC,qBAAS,CAAC,aAAa,EAAE,QAAQ,CAAC,EAAA;;wBAA5D,SAA4D,CAAA;wBAE5D,sBAAO,kBAAY,CAAC,OAAO,CAAC,IAAI,CAAC,EAAA;;;;KAClC;IAvCD;QAFC,oBAAW,CAAC,CAAC,YAAY,CAAC,CAAC;QAC3B,iBAAQ,CAAC,CAAC,qBAAW,CAAC,CAAC;;;;6CAYvB;IASD;QALC,oBAAW,CAAC,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;QACvC,qBAAY,CAAC,CAAC,SAAS,CAAC,CAAC;QACzB,iBAAQ,CAAC,CAAC,qBAAW,EAAE,qBAAW,CAAC,CAAC;QACpC,iBAAQ,CAAC,CAAC,qCAAiB,EAAE,6BAAa,EAAE,yBAAW,EAAE,iCAAe,CAAC,CAAC;QAC1E,eAAM,CAAC,CAAC,qBAAS,CAAC,CAAC;;;;uCAoBnB;IACH,YAAC;CAAA,AA9CD,IA8CC;kBA9CoB,KAAK"} {"version":3,"file":"share.controller.js","sourceRoot":"","sources":["../../src/controller/share.controller.ts"],"names":[],"mappings":";AAAA,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEd,+CAAkD;AAClD,+CAAuE;AACvE,8BAAqC;AACrC,sCAAkE;AAClE,0CAAwC;AACxC,6EAA2E;AAC3E,qEAAmE;AACnE,yEAAuE;AACvE,iEAA+D;AAC/D,0CAAyC;AACzC,qDAAmD;AACnD,8DAA4D;AAK5D;IAAA;IA8CA,CAAC;IA7CC;;OAEG;IAGG,4BAAY,GAAlB,UACE,OAAyC,EACzC,EAA8B;YAA5B,QAAQ,cAAA;;;;gBAGO,OAAO,GACpB,QAAQ,oBADY,CACZ;gBAEZ,sBAAO,kBAAY,CAAC,OAAO,CAAC;wBAC1B,OAAO,EAAE,OAAO;qBACjB,CAAC,EAAA;;;KACH;IACD;;OAEG;IAMG,sBAAM,GAAZ,UACE,OAGE,EACF,EAAwD,EACxD,EAAsD;YADpD,QAAQ,cAAA,EAAE,YAAY,kBAAA,EAAE,cAAc,oBAAA;YACvC,WAAW,QAAA,EAAE,WAAW,QAAA;;;;;;wBAEjB,MAAM,GAAK,OAAO,OAAZ,CAAY;wBAEX,qBAAM,WAAW,CAAC,YAAY,CAAC,SAAS,EAAE,YAAY,EAAE,cAAc,EAAE;gCACrF,MAAM,QAAA;6BACP,CAAC,EAAA;;wBAFI,MAAM,GAAG,SAEb;wBAEF,IAAI,CAAC,MAAM;4BAAE,sBAAO,kBAAY,CAAC,KAAK,CAAC,sBAAU,CAAC,YAAY,EAAE,OAAO,CAAC,EAAA;wBAExE,qBAAM,WAAW,CAAC,OAAO,CAAC,qBAAS,CAAC,aAAa,EAAE,QAAQ,CAAC,EAAA;;wBAA5D,SAA4D,CAAA;wBAE5D,sBAAO,kBAAY,CAAC,OAAO,CAAC,IAAI,CAAC,EAAA;;;;KAClC;IAvCD;QAFC,oBAAW,CAAC,CAAC,YAAY,CAAC,CAAC;QAC3B,iBAAQ,CAAC,CAAC,qBAAW,CAAC,CAAC;;;;6CAYvB;IASD;QALC,oBAAW,CAAC,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;QACvC,qBAAY,CAAC,CAAC,SAAS,CAAC,CAAC;QACzB,iBAAQ,CAAC,CAAC,qBAAW,EAAE,qBAAW,CAAC,CAAC;QACpC,iBAAQ,CAAC,CAAC,qCAAiB,EAAE,6BAAa,EAAE,yBAAW,EAAE,iCAAe,CAAC,CAAC;QAC1E,eAAM,CAAC,CAAC,qBAAS,CAAC,CAAC;;;;uCAoBnB;IACH,YAAC;CAAA,AA9CD,IA8CC;kBA9CoB,KAAK"}
\ No newline at end of file \ No newline at end of file
...@@ -7,29 +7,19 @@ export default class Task { ...@@ -7,29 +7,19 @@ export default class Task {
*/ */
getTaskList(context: IContext<{ getTaskList(context: IContext<{
activityId: string; activityId: string;
}>, { userInfo, vipInfo, activityInfo }: IControllerInfos, [taskService]: [TaskService]): Promise<IResult<ITaskInfo[]>>; }>, { userInfo, activityInfo }: IControllerInfos, [taskService]: [TaskService]): Promise<IResult<ITaskInfo[]>>;
/**
* 完成关注店铺任务
*/
doFollowTask(context: IContext<{
activityId: string;
}>, { userInfo, activityInfo }: IControllerInfos, [TaskService]: [TaskService]): Promise<IResult<boolean>>;
/** /**
* 积分兑换次数 * 积分兑换次数
*/ */
doExchangeCreditsTask(context: IContext<IParams>, { userInfo, activityInfo, session }: IControllerInfos, [taskService]: [TaskService]): Promise<IResult<boolean>>; doExchangeCreditsTask(context: IContext<IParams>, { userInfo, activityInfo, session }: IControllerInfos, [taskService]: [TaskService]): Promise<IResult<boolean>>;
/** /**
* 浏览商品 * 完成任务
*/
doBrowseGoodsTask(context: IContext<IParams>, { userInfo, activityInfo }: IControllerInfos, [taskService]: [TaskService]): Promise<IResult<boolean>>;
/**
* 收藏商品
*/
doCollectGoodsTask(context: IContext<IParams>, { userInfo, activityInfo }: IControllerInfos, [taskService]: [TaskService]): Promise<IResult<boolean>>;
/**
* 浏览链接
*/ */
doJumpLinkTask(context: IContext<IParams>, { userInfo, activityInfo }: IControllerInfos, [taskService]: [TaskService]): Promise<IResult<boolean>>; doCompleteTask(context: IContext<{
activityId: string;
taskType: ITaskType;
itemId?: string;
}>, { userInfo, activityInfo }: IControllerInfos, [taskService]: [TaskService]): Promise<IResult<boolean>>;
/** /**
* 领取任务奖励 * 领取任务奖励
*/ */
......
This diff is collapsed.
This diff is collapsed.
...@@ -6,7 +6,12 @@ declare const _default: { ...@@ -6,7 +6,12 @@ declare const _default: {
getVipInfo: (context: IContext<import("./controller/user.controller").IVipParams>, { session, activityUserNick }: IControllerInfos) => Promise<IResult<IVipInfo>>; getVipInfo: (context: IContext<import("./controller/user.controller").IVipParams>, { session, activityUserNick }: IControllerInfos) => Promise<IResult<IVipInfo>>;
getTaskList: (context: IContext<{ getTaskList: (context: IContext<{
activityId: string; activityId: string;
}>, { userInfo, vipInfo, activityInfo }: IControllerInfos, [taskService]: [import("./service").TaskService]) => Promise<IResult<import("./service/task.service").ITaskInfo[]>>; }>, { userInfo, activityInfo }: IControllerInfos, [taskService]: [import("./service").TaskService]) => Promise<IResult<import("./service/task.service").ITaskInfo[]>>;
doCompleteTask: (context: IContext<{
activityId: string;
taskType: ITaskType;
itemId?: string;
}>, { userInfo, activityInfo }: IControllerInfos, [taskService]: [import("./service").TaskService]) => Promise<IResult<boolean>>;
receiveTaskRewards: (context: IContext<IParams>, { userInfo }: IControllerInfos, [taskService]: [import("./service").TaskService]) => Promise<IResult<{ receiveTaskRewards: (context: IContext<IParams>, { userInfo }: IControllerInfos, [taskService]: [import("./service").TaskService]) => Promise<IResult<{
rewards: number; rewards: number;
}>>; }>>;
...@@ -17,12 +22,12 @@ declare const _default: { ...@@ -17,12 +22,12 @@ declare const _default: {
list: IAwards[]; list: IAwards[];
}>>; }>>;
receiveObjectPrize: (context: IContext<import("./controller/awards.controller").IReceiveOjectParams>, { activityInfo }: IControllerInfos, [awardSer]: [import("./service").AwardsService]) => Promise<IResult<boolean>>; receiveObjectPrize: (context: IContext<import("./controller/awards.controller").IReceiveOjectParams>, { activityInfo }: IControllerInfos, [awardSer]: [import("./service").AwardsService]) => Promise<IResult<boolean>>;
receiveEnamePrize: (context: IContext<import("./controller/awards.controller").IReceiveEnameParams>, {}: {}, [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<import("taobao-mini-sdk/lib/utils/codetypes").CodeType | IAwards, true>>; receiveEnamePrize: (context: IContext<import("./controller/awards.controller").IReceiveEnameParams>, {}: {}, [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;
......
...@@ -11,8 +11,8 @@ var stat_controller_1 = require("./controller/stat.controller"); ...@@ -11,8 +11,8 @@ var stat_controller_1 = require("./controller/stat.controller");
var login_controller_1 = require("./controller/login.controller"); var login_controller_1 = require("./controller/login.controller");
var _a = new user_controller_1.default(), getVipInfo = _a.getVipInfo, getRankList = _a.getRankList; var _a = new user_controller_1.default(), getVipInfo = _a.getVipInfo, getRankList = _a.getRankList;
var login = new login_controller_1.default().login; var login = new login_controller_1.default().login;
var _b = new task_controller_1.default(), getTaskList = _b.getTaskList, receiveTaskRewards = _b.receiveTaskRewards, getCollectGoodsList = _b.getCollectGoodsList, // 获取收藏商品列表,包含收藏状态 var _b = new task_controller_1.default(), getTaskList = _b.getTaskList, receiveTaskRewards = _b.receiveTaskRewards, doCompleteTask = _b.doCompleteTask, getCollectGoodsList = _b.getCollectGoodsList, // 获取收藏商品列表,包含收藏状态
doFollowTask = _b.doFollowTask, doJumpLinkTask = _b.doJumpLinkTask, doBrowseGoodsTask = _b.doBrowseGoodsTask, doCollectGoodsTask = _b.doCollectGoodsTask, doExchangeCreditsTask = _b.doExchangeCreditsTask; doExchangeCreditsTask = _b.doExchangeCreditsTask;
var _c = new base_controller_1.default(), getActivityBaseInfoById = _c.getActivityBaseInfoById, getItemListByItemIds = _c.getItemListByItemIds; var _c = new base_controller_1.default(), getActivityBaseInfoById = _c.getActivityBaseInfoById, getItemListByItemIds = _c.getItemListByItemIds;
var _d = new awards_controller_1.default(), getMyPrizeList = _d.getMyPrizeList, receiveObjectPrize = _d.receiveObjectPrize, receiveEnamePrize = _d.receiveEnamePrize, drawLotteryPrize = _d.drawLotteryPrize; var _d = new awards_controller_1.default(), getMyPrizeList = _d.getMyPrizeList, receiveObjectPrize = _d.receiveObjectPrize, receiveEnamePrize = _d.receiveEnamePrize, drawLotteryPrize = _d.drawLotteryPrize;
var doHelp = new share_controller_1.default().doHelp; var doHelp = new share_controller_1.default().doHelp;
...@@ -21,6 +21,7 @@ exports.default = { ...@@ -21,6 +21,7 @@ exports.default = {
login: login, login: login,
getVipInfo: getVipInfo, getVipInfo: getVipInfo,
getTaskList: getTaskList, getTaskList: getTaskList,
doCompleteTask: doCompleteTask,
receiveTaskRewards: receiveTaskRewards, receiveTaskRewards: receiveTaskRewards,
getActivityBaseInfoById: getActivityBaseInfoById, getActivityBaseInfoById: getActivityBaseInfoById,
getMyPrizeList: getMyPrizeList, getMyPrizeList: getMyPrizeList,
......
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,cAAc;;AAEd,2CAA2C;AAC3C,gEAAyD;AACzD,gEAAyD;AACzD,gEAAyD;AACzD,oEAA6D;AAC7D,kEAA2D;AAC3D,gEAAyD;AACzD,kEAA2D;AAErD,IAAA,KAA8B,IAAI,yBAAc,EAAE,EAAhD,UAAU,gBAAA,EAAE,WAAW,iBAAyB,CAAA;AAChD,IAAA,KAAK,GAAK,IAAI,0BAAe,EAAE,MAA1B,CAA0B;AAEjC,IAAA,KASF,IAAI,yBAAc,EAAE,EARtB,WAAW,iBAAA,EACX,kBAAkB,wBAAA,EAClB,mBAAmB,yBAAA,EAAE,kBAAkB;AACvC,YAAY,kBAAA,EACZ,cAAc,oBAAA,EACd,iBAAiB,uBAAA,EACjB,kBAAkB,wBAAA,EAClB,qBAAqB,2BACC,CAAA;AAElB,IAAA,KAAoD,IAAI,yBAAc,EAAE,EAAtE,uBAAuB,6BAAA,EAAE,oBAAoB,0BAAyB,CAAA;AAExE,IAAA,KAA8E,IAAI,2BAAgB,EAAE,EAAlG,cAAc,oBAAA,EAAE,kBAAkB,wBAAA,EAAE,iBAAiB,uBAAA,EAAE,gBAAgB,sBAA2B,CAAA;AAElG,IAAA,MAAM,GAAK,IAAI,0BAAe,EAAE,OAA1B,CAA0B;AAElC,IAAA,KAAwB,IAAI,yBAAc,EAAE,EAA1C,QAAQ,cAAA,EAAE,OAAO,aAAyB,CAAA;AAElD,kBAAe;IACb,KAAK,OAAA;IACL,UAAU,YAAA;IACV,WAAW,aAAA;IACX,kBAAkB,oBAAA;IAClB,uBAAuB,yBAAA;IACvB,cAAc,gBAAA;IACd,kBAAkB,oBAAA;IAClB,iBAAiB,mBAAA;IACjB,MAAM,QAAA;IACN,QAAQ,UAAA;IACR,OAAO,SAAA;IACP,WAAW,aAAA;CACZ,CAAA"} {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,cAAc;;AAEd,2CAA2C;AAC3C,gEAAyD;AACzD,gEAAyD;AACzD,gEAAyD;AACzD,oEAA6D;AAC7D,kEAA2D;AAC3D,gEAAyD;AACzD,kEAA2D;AAErD,IAAA,KAA8B,IAAI,yBAAc,EAAE,EAAhD,UAAU,gBAAA,EAAE,WAAW,iBAAyB,CAAA;AAChD,IAAA,KAAK,GAAK,IAAI,0BAAe,EAAE,MAA1B,CAA0B;AAEjC,IAAA,KAMF,IAAI,yBAAc,EAAE,EALtB,WAAW,iBAAA,EACX,kBAAkB,wBAAA,EAClB,cAAc,oBAAA,EACd,mBAAmB,yBAAA,EAAE,kBAAkB;AACvC,qBAAqB,2BACC,CAAA;AAElB,IAAA,KAAoD,IAAI,yBAAc,EAAE,EAAtE,uBAAuB,6BAAA,EAAE,oBAAoB,0BAAyB,CAAA;AAExE,IAAA,KAA8E,IAAI,2BAAgB,EAAE,EAAlG,cAAc,oBAAA,EAAE,kBAAkB,wBAAA,EAAE,iBAAiB,uBAAA,EAAE,gBAAgB,sBAA2B,CAAA;AAElG,IAAA,MAAM,GAAK,IAAI,0BAAe,EAAE,OAA1B,CAA0B;AAElC,IAAA,KAAwB,IAAI,yBAAc,EAAE,EAA1C,QAAQ,cAAA,EAAE,OAAO,aAAyB,CAAA;AAElD,kBAAe;IACb,KAAK,OAAA;IACL,UAAU,YAAA;IACV,WAAW,aAAA;IACX,cAAc,gBAAA;IACd,kBAAkB,oBAAA;IAClB,uBAAuB,yBAAA;IACvB,cAAc,gBAAA;IACd,kBAAkB,oBAAA;IAClB,iBAAiB,mBAAA;IACjB,MAAM,QAAA;IACN,QAAQ,UAAA;IACR,OAAO,SAAA;IACP,WAAW,aAAA;CACZ,CAAA"}
\ No newline at end of file \ No newline at end of file
...@@ -24,18 +24,23 @@ export default class TaskService extends UserService { ...@@ -24,18 +24,23 @@ export default class TaskService extends UserService {
* *
* @param {ITaskType} taskType 任务类型 * @param {ITaskType} taskType 任务类型
* @param {string} title 任务标题 * @param {string} title 任务标题
* @param {ITasks} tasks 任务配置 * @param {IActivityInfo} activityInfo 任务配置
* @param {IUserInfo} userInfo 用户信息 * @param {IUserInfo} userInfo 用户信息
* @return {ITaskInfo} {ITaskInfo} 任务信息 * @return {ITaskInfo} {ITaskInfo} 任务信息
* @memberof TaskService * @memberof TaskService
*/ */
initTask(taskType: ITaskType, title: string, tasks: ITasks, userInfo: IUserInfo): ITaskInfo; initTask(taskType: ITaskType, title: string, activityInfo: IActivityInfo, userInfo: IUserInfo): ITaskInfo;
completeTask(taskType: ITaskType, userInfo: IUserInfo, activityInfo: IActivityInfo, customRecord?: object): Promise<number>; /**
updateVipTask(userInfo: IUserInfo, vipInfo: IVipInfo, tasks: ITasks): { *根据任务类型更新任务待领取次数和任务记录
$set: {}; *
$inc: {}; * @param {string} taskType
$push: {}; * @param {number} activityInfo
}; * @param {IActivityInfo} userInfo
* @param {object} [customRecord]
* @returns {boolean}
* @memberof TaskService
*/
completeTask(taskType: ITaskType, activityInfo: IActivityInfo, userInfo: IUserInfo, customRecord?: object): Promise<number>;
updateOrderGoodsTask(userInfo: IUserInfo, tasks: ITasks, activityStartTime: number, session?: string): Promise<{}>; updateOrderGoodsTask(userInfo: IUserInfo, tasks: ITasks, activityStartTime: number, session?: string): Promise<{}>;
updateSignTask(userInfo: IUserInfo, tasks: ITasks): { updateSignTask(userInfo: IUserInfo, tasks: ITasks): {
$inc: { $inc: {
...@@ -50,38 +55,6 @@ export default class TaskService extends UserService { ...@@ -50,38 +55,6 @@ export default class TaskService extends UserService {
$inc?: undefined; $inc?: undefined;
$push?: undefined; $push?: undefined;
}; };
/**
*更新关注店铺任务状态
*
* @param {IUserInfo} userInfo
* @param {IActivityInfo} activityInfo
* @returns
* @memberof TaskService
*/
updateFollowTask(userInfo: IUserInfo, activityInfo: IActivityInfo): Promise<number>;
/**
*
* 根据用户和任务完成情况,设置任务状态
*
* @param {IUserInfo} useInfo
* @param {string} taskType
* @param {number} taskRateType
* @param {number} [limitTimesEverday] 每天限制次数 任务频率为每天的时候必填
* @return {taskTatus} 1未完成 2 待领取 3 已完成
* @memberof TaskService
*/
setTaskStatus(useInfo: IUserInfo, taskType: string, taskRateType: number, limitTimesEveryday?: number): number;
/**
*根据任务类型更新任务待领取次数和任务记录
*
* @param {string} taskType
* @param {number} rewards
* @param {IUserInfo} userInfo
* @param {object} [customRecord]
* @returns {boolean}
* @memberof TaskService
*/
updateUserTaskRecord(taskType: string, rewards: number, userInfo: IUserInfo, customRecord?: object): Promise<boolean>;
/** /**
* *
* 更新user表中,任务相关字段 * 更新user表中,任务相关字段
......
This diff is collapsed.
This diff is collapsed.
...@@ -213,7 +213,7 @@ var UserService = /** @class */ (function (_super) { ...@@ -213,7 +213,7 @@ var UserService = /** @class */ (function (_super) {
projection.$inc["remainTimes.follow"] = follow.value; projection.$inc["remainTimes.follow"] = follow.value;
} }
newVip = userUpdate_1.isNewVip(userInfo, vipInfo); newVip = userUpdate_1.isNewVip(userInfo, vipInfo);
if (newVip && !userInfo.member.newMember) { if (newVip) {
// @ts-ignore // @ts-ignore
projection.$set.member = this.setNewVipUserData(userInfo.member); projection.$set.member = this.setNewVipUserData(userInfo.member);
projection.$push["taskInfo." + today + ".member"] = { createTime: Date.now() }; projection.$push["taskInfo." + today + ".member"] = { createTime: Date.now() };
......
This diff is collapsed.
...@@ -7,7 +7,6 @@ export * from './common/logger'; ...@@ -7,7 +7,6 @@ export * from './common/logger';
export * from './common/rand'; export * from './common/rand';
export * from './common/getUserOrderlist'; export * from './common/getUserOrderlist';
export * from './common/vip'; export * from './common/vip';
export * from './common/exportHandlers';
export * from './common/helper'; export * from './common/helper';
export * from './common/userUpdate'; export * from './common/userUpdate';
export * from './common/format'; export * from './common/format';
......
...@@ -23,7 +23,6 @@ __exportStar(require("./common/logger"), exports); ...@@ -23,7 +23,6 @@ __exportStar(require("./common/logger"), exports);
__exportStar(require("./common/rand"), exports); __exportStar(require("./common/rand"), exports);
__exportStar(require("./common/getUserOrderlist"), exports); __exportStar(require("./common/getUserOrderlist"), exports);
__exportStar(require("./common/vip"), exports); __exportStar(require("./common/vip"), exports);
__exportStar(require("./common/exportHandlers"), exports);
__exportStar(require("./common/helper"), exports); __exportStar(require("./common/helper"), exports);
__exportStar(require("./common/userUpdate"), exports); __exportStar(require("./common/userUpdate"), exports);
__exportStar(require("./common/format"), exports); __exportStar(require("./common/format"), exports);
......
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";AAAA,cAAc;;;;;;;;;;;;AAEd,cAAc;AACd,sDAAmC;AAEnC,iBAAiB;AACjB,oDAAiC;AAEjC,gBAAgB;AAChB,uDAAoC;AAEpC,SAAS;AACT,sDAAmC;AAEnC,kDAA+B;AAE/B,gDAA6B;AAE7B,4DAAyC;AAEzC,+CAA4B;AAE5B,0DAAuC;AAEvC,kDAA+B;AAE/B,sDAAmC;AAEnC,kDAA+B;AAE/B,qDAAkC"} {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";AAAA,cAAc;;;;;;;;;;;;AAEd,cAAc;AACd,sDAAmC;AAEnC,iBAAiB;AACjB,oDAAiC;AAEjC,gBAAgB;AAChB,uDAAoC;AAEpC,SAAS;AACT,sDAAmC;AAEnC,kDAA+B;AAE/B,gDAA6B;AAE7B,4DAAyC;AAEzC,+CAA4B;AAE5B,kDAA+B;AAE/B,sDAAmC;AAEnC,kDAA+B;AAE/B,qDAAkC"}
\ No newline at end of file \ No newline at end of file
...@@ -52,7 +52,7 @@ export default class Share { ...@@ -52,7 +52,7 @@ export default class Share {
): Promise<IResult<boolean>> { ): Promise<IResult<boolean>> {
const { openId } = context const { openId } = context
const result = await taskService.completeTask('invites', inviteUserInfo, activityInfo, { const result = await taskService.completeTask('invites', activityInfo, inviteUserInfo, {
openId openId
}) })
......
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
import { CODE_TYPES, TASK_RATE_TYPE } from './../constants' import { CODE_TYPES, TASK_RATE_TYPE } from './../constants'
import { checkParams, services, registeInfos, preCheck } from '../decorator/common' import { checkParams, services, registeInfos, preCheck } from '../decorator/common'
import { resultsModel, TBAPIS } from '../sdk' import { resultsModel, TBAPIS } from '../sdk'
import { TaskService, BaseService } from '../service' import { TaskService, BaseService } from '../service'
import { ITaskInfo } from '../service/task.service' import { ITaskInfo } from '../service/task.service'
import { checkActivityTime } from '../utils/common/check/checkActivityTime' import { checkActivityTime } from '../utils/common/check/checkActivityTime'
import { getCompleteTaskByUserTaskInfo, getTodayCompleteTask } from '../utils/common/task' import { getTotalCompleteTask, getTodayCompleteTask } from '../utils/common/task'
import { update } from '../decorator/common/update'
import { updateVip } from '../utils/common/update/updateVip'
import { checkTaskLimit } from '../utils/common/check/checkTaskLimit'
export default class Task { export default class Task {
/** /**
...@@ -17,66 +19,25 @@ export default class Task { ...@@ -17,66 +19,25 @@ export default class Task {
@registeInfos(['vipInfo']) @registeInfos(['vipInfo'])
@services([TaskService]) @services([TaskService])
@preCheck([checkActivityTime]) @preCheck([checkActivityTime])
@update([updateVip])
async getTaskList( async getTaskList(
context: IContext<{ activityId: string }>, context: IContext<{ activityId: string }>,
{ userInfo, vipInfo, activityInfo }: IControllerInfos, { userInfo, activityInfo }: IControllerInfos,
[taskService]: [TaskService] [taskService]: [TaskService]
): Promise<IResult<ITaskInfo[]>> { ): Promise<IResult<ITaskInfo[]>> {
const { tasks, startTime } = activityInfo
// 更新user状态
let updatedUserInfo = await taskService.updateTasks(
userInfo._id,
// 需要查询更新的任务
[
taskService.updateVipTask(userInfo, vipInfo, tasks)
// taskService.updateSignTask(userInfo, tasks),
// await taskService.updateOrderGoodsTask(userInfo, tasks, startTime, session)
],
userInfo
)
if (!updatedUserInfo) return resultsModel.error(CODE_TYPES.SYSTEM_ERROR, '更新任务列表失败')
// 返回对应的任务时, B端b_activity_config tasks 需配置对应的任务
return resultsModel.success([ return resultsModel.success([
taskService.initTask('member', '加入会员', tasks, updatedUserInfo), taskService.initTask('member', '加入会员', activityInfo, userInfo),
taskService.initTask('follow', '关注店铺', tasks, updatedUserInfo) taskService.initTask('follow', '关注店铺', activityInfo, userInfo)
// taskService.initTask('sign', '签到', tasks, updatedUserInfo), // taskService.initTask('sign', '签到', activityInfo, userInfo),
// taskService.initTask('orderGoods', '购买商品', tasks, updatedUserInfo), // taskService.initTask('orderGoods', '购买商品', activityInfo, userInfo),
// taskService.initTask('browseGoods', '浏览商品', tasks, updatedUserInfo), // taskService.initTask('browseGoods', '浏览商品', activityInfo, userInfo),
// taskService.initTask('collectGoods', '收藏商品', tasks, updatedUserInfo), // taskService.initTask('collectGoods', '收藏商品', activityInfo, userInfo),
// taskService.initTask('jumpLink', '浏览页面', tasks, updatedUserInfo), // taskService.initTask('jumpLink', '浏览页面', activityInfo, userInfo),
// taskService.initTask('invites', '邀请好友', tasks, updatedUserInfo), // taskService.initTask('invites', '邀请好友', activityInfo, userInfo)
// taskService.initTask('exchangeCredits', '积分兑换', tasks, updatedUserInfo) // taskService.initTask('exchangeCredits', '积分兑换', activityInfo, updatedUserInfo)
]) ])
} }
/**
* 完成关注店铺任务
*/
@checkParams(['activityId'])
@services([TaskService])
@preCheck([checkActivityTime])
async doFollowTask(
context: IContext<{ activityId: string }>,
{ userInfo, activityInfo }: IControllerInfos,
[TaskService]: [TaskService]
): Promise<IResult<boolean>> {
let { follow } = userInfo
const { flag, newFollow } = follow
// 已经关注过店铺,不可完成
const hasFollowed = flag || newFollow
if (hasFollowed) return resultsModel.error(CODE_TYPES.ERROR_TASK_COMPLETE)
// 更新状态
const result = await TaskService.updateFollowTask(userInfo, activityInfo)
return result ? resultsModel.success(true) : resultsModel.error(CODE_TYPES.SYSTEM_ERROR)
}
/** /**
* 积分兑换次数 * 积分兑换次数
*/ */
...@@ -122,138 +83,32 @@ export default class Task { ...@@ -122,138 +83,32 @@ export default class Task {
if (!result) return resultsModel.error(CODE_TYPES.SYSTEM_ERROR) if (!result) return resultsModel.error(CODE_TYPES.SYSTEM_ERROR)
// 更新user表 // 更新user表
await taskService.updateUserTaskRecord(taskType, value, userInfo) await taskService.completeTask(taskType, activityInfo, userInfo)
return resultsModel.success(true)
}
/**
* 浏览商品
*/
@checkParams(['activityId', 'itemId'])
@services([TaskService])
@preCheck([checkActivityTime])
async doBrowseGoodsTask(
context: IContext<IParams>,
{ userInfo, activityInfo }: IControllerInfos,
[taskService]: [TaskService]
): Promise<IResult<boolean>> {
const taskType = 'browseGoods'
const { itemId } = context.data
const {
tasks: {
browseGoods: { taskRateType, times, itemIds, value }
}
} = activityInfo
const itemIdArray: number[] = Array.isArray(itemIds) ? itemIds : itemIds.split(',').map(v => +v)
// B端配置商品ids不匹配正确
if (!itemIdArray.includes(+itemId)) return resultsModel.error(CODE_TYPES.PARAMS_ERROR, '商品id不匹配')
const { todayTaskInfo, todayCompleteTimes } = getTodayCompleteTask('browseGoods', userInfo)
const hasCompleteToday = todayTaskInfo.some(v => v.itemId === itemId) && taskRateType === TASK_RATE_TYPE.EVERYDAY
// 今日任务已经完成
if (hasCompleteToday) {
return resultsModel.error(CODE_TYPES.PARAMS_ERROR, '今日该浏览商品任务已完成')
}
// 次数超限
if (times && times === todayCompleteTimes && taskRateType === TASK_RATE_TYPE.EVERYDAY) {
return resultsModel.error(CODE_TYPES.ERROR_TASK_LIMIT)
}
// 更新user表
await taskService.updateUserTaskRecord(taskType, value, userInfo, {
itemId
})
return resultsModel.success(true) return resultsModel.success(true)
} }
/** /**
* 收藏商品 * 完成任务
*/ */
@checkParams(['activityId', 'itemId']) @checkParams(['activityId', 'taskType'])
@services([TaskService])
@preCheck([checkActivityTime])
async doCollectGoodsTask(
context: IContext<IParams>,
{ userInfo, activityInfo }: IControllerInfos,
[taskService]: [TaskService]
): Promise<IResult<boolean>> {
const taskType = 'collectGoods'
const { itemId } = context.data
const {
tasks: {
collectGoods: { taskRateType, times, itemIds, value }
}
} = activityInfo
const itemIdArray: number[] = Array.isArray(itemIds) ? itemIds : itemIds.split(',').map(v => +v)
// B端配置商品ids不匹配正确
if (!itemIdArray.includes(+itemId)) return resultsModel.error(CODE_TYPES.PARAMS_ERROR, '商品id不匹配')
const { todayTaskInfo, todayCompleteTimes } = getTodayCompleteTask(taskType, userInfo)
const hasCompleteToday =
todayTaskInfo.filter(v => v.itemId === itemId).length && taskRateType === TASK_RATE_TYPE.EVERYDAY
// 今日任务已经完成
if (hasCompleteToday) {
return resultsModel.error(CODE_TYPES.PARAMS_ERROR, '今日该收藏商品任务已完成')
}
// 次数超限
if (times && times === todayCompleteTimes && taskRateType === TASK_RATE_TYPE.EVERYDAY) {
return resultsModel.error(CODE_TYPES.ERROR_TASK_LIMIT)
}
// 更新user表
await taskService.updateUserTaskRecord(taskType, value, userInfo, {
itemId
})
return resultsModel.success(true)
}
/**
* 浏览链接
*/
@checkParams(['activityId'])
@services([TaskService]) @services([TaskService])
@preCheck([checkActivityTime]) @preCheck([checkActivityTime, checkTaskLimit])
async doJumpLinkTask( async doCompleteTask(
context: IContext<IParams>, context: IContext<{
activityId: string
taskType: ITaskType
itemId?: string // 涉及到商品的任务需传itemId
}>,
{ userInfo, activityInfo }: IControllerInfos, { userInfo, activityInfo }: IControllerInfos,
[taskService]: [TaskService] [taskService]: [TaskService]
): Promise<IResult<boolean>> { ): Promise<IResult<boolean>> {
const taskType = 'jumpLink' const { taskType, itemId } = context.data
const {
tasks: {
jumpLink: { taskRateType, times, value, link }
}
} = activityInfo
const { todayCompleteTimes } = getTodayCompleteTask(taskType, userInfo)
const hasCompleteToday = times && todayCompleteTimes === times && taskRateType === TASK_RATE_TYPE.EVERYDAY
// 今日任务已经完成
if (hasCompleteToday) {
return resultsModel.error(CODE_TYPES.PARAMS_ERROR, '今日跳转链接任务已完成')
}
// 次数超限
if (times && times === todayCompleteTimes && taskRateType === TASK_RATE_TYPE.EVERYDAY) {
return resultsModel.error(CODE_TYPES.ERROR_TASK_LIMIT)
}
// 更新user表 // 更新user表
await taskService.updateUserTaskRecord(taskType, value, userInfo) const result = await taskService.completeTask(taskType, activityInfo, userInfo, { itemId })
return resultsModel.success(true) return result ? resultsModel.success(true) : resultsModel.error(CODE_TYPES.SYSTEM_ERROR, '任务完成失败')
} }
/** /**
...@@ -307,7 +162,7 @@ export default class Task { ...@@ -307,7 +162,7 @@ export default class Task {
const { itemIds } = context.data const { itemIds } = context.data
const list = await baseService.getItemListByIds(itemIds, session) const list = await baseService.getItemListByIds(itemIds, session)
const { taskInfo } = getCompleteTaskByUserTaskInfo('collectGoods', userInfo) const { taskInfo } = getTotalCompleteTask('collectGoods', userInfo)
const listWithCollectStatus = list.map(v => { const listWithCollectStatus = list.map(v => {
return { return {
......
/** @format */ /** @format */
import { merge } from 'lodash'
// 检验参数是否存在 // 检验参数是否存在
export const update = (checks: IFunction[]) => { export const update = (checks: IFunction[]) => {
return function (target: Object, name: string, descriptor: PropertyDescriptor) { return function (target: Object, name: string, descriptor: PropertyDescriptor) {
...@@ -7,17 +9,20 @@ export const update = (checks: IFunction[]) => { ...@@ -7,17 +9,20 @@ export const update = (checks: IFunction[]) => {
descriptor.value = async function (...args: any[]) { descriptor.value = async function (...args: any[]) {
let [context, otherArgs = {}, services = []] = args let [context, otherArgs = {}, services = []] = args
let totalUpdateProjection: IDecoratorUpdateQuery = {}
for (let i = 0; i < checks.length; i++) { for (let i = 0; i < checks.length; i++) {
const checkFn = checks[i] const checkFn = checks[i]
let result = await checkFn.apply(target, [context, { ...otherArgs }, services]) let result: IDecoratorUpdateQuery = await checkFn.apply(target, [context, { ...otherArgs }, services])
result = result || {} result = result || {}
// 校验报错 // 校验报错
if ((result as IErrorResult)?.success === false && (result as IErrorResult)?.code) { if ((result as IErrorResult)?.success === false && (result as IErrorResult)?.code) {
return result return result
} }
otherArgs = { ...otherArgs, ...result } totalUpdateProjection = merge({}, totalUpdateProjection, result)
otherArgs = { ...otherArgs }
} }
return method.apply(target, [context, { ...otherArgs }, services]) return method.apply(target, [context, { ...otherArgs }, services])
} }
......
...@@ -15,11 +15,8 @@ const { login } = new LoginController() ...@@ -15,11 +15,8 @@ const { login } = new LoginController()
const { const {
getTaskList, getTaskList,
receiveTaskRewards, receiveTaskRewards,
doCompleteTask,
getCollectGoodsList, // 获取收藏商品列表,包含收藏状态 getCollectGoodsList, // 获取收藏商品列表,包含收藏状态
doFollowTask,
doJumpLinkTask,
doBrowseGoodsTask,
doCollectGoodsTask,
doExchangeCreditsTask doExchangeCreditsTask
} = new TaskController() } = new TaskController()
...@@ -35,6 +32,7 @@ export default { ...@@ -35,6 +32,7 @@ export default {
login, login,
getVipInfo, getVipInfo,
getTaskList, getTaskList,
doCompleteTask,
receiveTaskRewards, receiveTaskRewards,
getActivityBaseInfoById, getActivityBaseInfoById,
getMyPrizeList, getMyPrizeList,
......
...@@ -18,7 +18,7 @@ import { ...@@ -18,7 +18,7 @@ import {
isNewVip isNewVip
} from '../utils' } from '../utils'
import { TASK_RATE_TYPE, TASK_STATUS } from '../constants' import { TASK_RATE_TYPE, TASK_STATUS } from '../constants'
import { getTodayCompleteTask, getCompleteTaskByUserTaskInfo } from '../utils/common/task' import { getTodayCompleteTask, getTotalCompleteTask, setTaskStatus } from '../utils/common/task'
export interface ITaskInfo { export interface ITaskInfo {
taskType?: string // 任务类型 taskType?: string // 任务类型
...@@ -42,19 +42,16 @@ export default class TaskService extends UserService { ...@@ -42,19 +42,16 @@ export default class TaskService extends UserService {
* *
* @param {ITaskType} taskType 任务类型 * @param {ITaskType} taskType 任务类型
* @param {string} title 任务标题 * @param {string} title 任务标题
* @param {ITasks} tasks 任务配置 * @param {IActivityInfo} activityInfo 任务配置
* @param {IUserInfo} userInfo 用户信息 * @param {IUserInfo} userInfo 用户信息
* @return {ITaskInfo} {ITaskInfo} 任务信息 * @return {ITaskInfo} {ITaskInfo} 任务信息
* @memberof TaskService * @memberof TaskService
*/ */
initTask(taskType: ITaskType, title: string, tasks: ITasks, userInfo: IUserInfo): ITaskInfo { initTask(taskType: ITaskType, title: string, activityInfo: IActivityInfo, userInfo: IUserInfo): ITaskInfo {
const { const { value, itemIds = '', taskRateType, times = 1, link = '' } = activityInfo?.tasks?.[taskType] || {}
[taskType]: { value, itemIds = '', taskRateType, times = 1, link = '' }
} = tasks
const { remainTimes } = userInfo const { remainTimes } = userInfo
const { todayCompleteTimes } = getTodayCompleteTask(taskType, userInfo) const { todayCompleteTimes } = getTodayCompleteTask(taskType, userInfo)
const { completeTimes } = getCompleteTaskByUserTaskInfo(taskType, userInfo) const { completeTimes } = getTotalCompleteTask(taskType, userInfo)
return { return {
taskType, taskType,
...@@ -66,17 +63,32 @@ export default class TaskService extends UserService { ...@@ -66,17 +63,32 @@ export default class TaskService extends UserService {
url: taskType === 'member' ? generateVipUrl(formatVipCbUrl(this.context)) : link, url: taskType === 'member' ? generateVipUrl(formatVipCbUrl(this.context)) : link,
todayCompleteTimes, todayCompleteTimes,
completeTimes, completeTimes,
status: this.setTaskStatus(userInfo, taskType, taskRateType, times), status: setTaskStatus(userInfo, taskType, taskRateType, times),
waitReceive: remainTimes[taskType] waitReceive: remainTimes?.[taskType]
} }
} }
async completeTask(taskType: ITaskType, userInfo: IUserInfo, activityInfo: IActivityInfo, customRecord: object = {}) { /**
*根据任务类型更新任务待领取次数和任务记录
*
* @param {string} taskType
* @param {number} activityInfo
* @param {IActivityInfo} userInfo
* @param {object} [customRecord]
* @returns {boolean}
* @memberof TaskService
*/
async completeTask(
taskType: ITaskType,
activityInfo: IActivityInfo,
userInfo: IUserInfo,
customRecord: object = {}
): Promise<number> {
const today = getToday() const today = getToday()
const rewards = activityInfo?.tasks?.[taskType]?.value || 0 const rewards = activityInfo?.tasks?.[taskType]?.value || 0
return await this.updateUser(userInfo._id, { return await this.updateUser(userInfo._id, {
$inc: { $inc: {
'remainTimes.invites': rewards [`remainTimes.${taskType}`]: rewards
}, },
$push: { $push: {
[`taskInfo.${today}.${taskType}`]: { ...customRecord, createTime: Date.now() } [`taskInfo.${today}.${taskType}`]: { ...customRecord, createTime: Date.now() }
...@@ -84,45 +96,13 @@ export default class TaskService extends UserService { ...@@ -84,45 +96,13 @@ export default class TaskService extends UserService {
}) })
} }
// 根据会员状态更新
updateVipTask(userInfo: IUserInfo, vipInfo: IVipInfo, tasks: ITasks) {
let { member } = userInfo
const { newMember } = member
const today = getToday()
const newVip = isNewVip(userInfo, vipInfo)
const {
member: { value }
} = tasks
let projection = {
$set: {},
$inc: {},
$push: {}
}
if (newVip && !newMember) {
member = setNewVipUserData(member)
// @ts-ignore
projection.$set.member = member
projection.$inc['remainTimes.member'] = +value
projection.$push[`taskInfo.${today}.member`] = {
creatTime: Date.now()
}
}
return projection
}
// 根据下单下单记录,更新状态 // 根据下单下单记录,更新状态
async updateOrderGoodsTask(userInfo: IUserInfo, tasks: ITasks, activityStartTime: number, session?: string) { async updateOrderGoodsTask(userInfo: IUserInfo, tasks: ITasks, activityStartTime: number, session?: string) {
const taskType = 'orderGoods' const taskType = 'orderGoods'
const { const {
[taskType]: { value, itemIds, taskRateType, times } [taskType]: { value, itemIds, taskRateType, times }
} = tasks } = tasks
const { completeTimes, taskInfo } = getCompleteTaskByUserTaskInfo(taskType, userInfo) const { completeTimes, taskInfo } = getTotalCompleteTask(taskType, userInfo)
const { todayCompleteTimes } = getTodayCompleteTask(taskType, userInfo) const { todayCompleteTimes } = getTodayCompleteTask(taskType, userInfo)
// 永久任务且已完成 // 永久任务且已完成
if (taskRateType === TASK_RATE_TYPE.FOREVER && completeTimes) { if (taskRateType === TASK_RATE_TYPE.FOREVER && completeTimes) {
...@@ -199,106 +179,6 @@ export default class TaskService extends UserService { ...@@ -199,106 +179,6 @@ export default class TaskService extends UserService {
: {} : {}
} }
/**
*更新关注店铺任务状态
*
* @param {IUserInfo} userInfo
* @param {IActivityInfo} activityInfo
* @returns
* @memberof TaskService
*/
async updateFollowTask(userInfo: IUserInfo, activityInfo: IActivityInfo) {
const today = getToday()
let { _id, follow } = userInfo
// 获取活动基本信息
const { tasks } = activityInfo
// 获取关注店铺奖励
const {
follow: { value }
} = tasks || {}
// 更新follow信息
const followInfo: IFollowInfo = setNewFollowUserData(follow)
// 增加待领取次数
return await this.updateUser(_id, {
$set: {
follow: followInfo
},
$inc: {
'remainTimes.follow': value
},
$push: {
[`taskInfo.${today}.follow`]: {
creatTime: Date.now()
}
}
})
}
/**
*
* 根据用户和任务完成情况,设置任务状态
*
* @param {IUserInfo} useInfo
* @param {string} taskType
* @param {number} taskRateType
* @param {number} [limitTimesEverday] 每天限制次数 任务频率为每天的时候必填
* @return {taskTatus} 1未完成 2 待领取 3 已完成
* @memberof TaskService
*/
setTaskStatus(useInfo: IUserInfo, taskType: string, taskRateType: number, limitTimesEveryday: number = 1): number {
const waitReceive = useInfo?.remainTimes?.[taskType] || 0
if (waitReceive) return TASK_STATUS.WAIT_RECEIVE
// 当天的完成次数
const { todayCompleteTimes } = getTodayCompleteTask(taskType, useInfo)
// 总共的完成次数
const { completeTimes } = getCompleteTaskByUserTaskInfo(taskType, useInfo)
switch (taskRateType) {
case TASK_RATE_TYPE.FOREVER:
return completeTimes > 0 ? TASK_STATUS.DONE : TASK_STATUS.WAIT_DO
break
case TASK_RATE_TYPE.EVERYDAY:
return todayCompleteTimes >= limitTimesEveryday ? TASK_STATUS.DONE : TASK_STATUS.WAIT_DO
break
case TASK_RATE_TYPE.NOLIMIT:
return TASK_STATUS.WAIT_DO
break
}
}
/**
*根据任务类型更新任务待领取次数和任务记录
*
* @param {string} taskType
* @param {number} rewards
* @param {IUserInfo} userInfo
* @param {object} [customRecord]
* @returns {boolean}
* @memberof TaskService
*/
async updateUserTaskRecord(
taskType: string,
rewards: number,
userInfo: IUserInfo,
customRecord?: object
): Promise<boolean> {
const { _id } = userInfo
const today = getToday()
const result = await this.updateUser(_id, {
$inc: {
[`remainTimes.${taskType}`]: rewards
},
$push: {
[`taskInfo.${today}.${taskType}`]: { createTime: Date.now(), ...customRecord }
}
})
return result === 1
}
/** /**
* *
* 更新user表中,任务相关字段 * 更新user表中,任务相关字段
......
...@@ -127,7 +127,7 @@ class UserService extends BaseService { ...@@ -127,7 +127,7 @@ class UserService extends BaseService {
// 之前进入活动非会员,现在进入会员,则视为新会员用户 // 之前进入活动非会员,现在进入会员,则视为新会员用户
const newVip = isNewVip(userInfo, vipInfo) const newVip = isNewVip(userInfo, vipInfo)
if (newVip && !userInfo.member.newMember) { if (newVip) {
// @ts-ignore // @ts-ignore
projection.$set.member = this.setNewVipUserData(userInfo.member) projection.$set.member = this.setNewVipUserData(userInfo.member)
projection.$push[`taskInfo.${today}.member`] = { createTime: Date.now() } projection.$push[`taskInfo.${today}.member`] = { createTime: Date.now() }
......
...@@ -109,18 +109,21 @@ interface IUpdateQuery { ...@@ -109,18 +109,21 @@ interface IUpdateQuery {
$set?: { [key: string]: any } $set?: { [key: string]: any }
$setOnInsert?: { [key: string]: any } $setOnInsert?: { [key: string]: any }
$unset?: { [key: string]: any } $unset?: { [key: string]: any }
$addToSet?: { [key: string]: any } $addToSet?: { [key: string]: any }
$pop?: { [key: string]: any } $pop?: { [key: string]: any }
$pull?: { [key: string]: any } $pull?: { [key: string]: any }
$push?: { [key: string]: any } $push?: { [key: string]: any }
$pullAll?: { [key: string]: any }
$bit?: { $bit?: {
[key: string]: { [key in 'and' | 'or' | 'xor']?: number } [key: string]: { [key in 'and' | 'or' | 'xor']?: number }
} }
} }
interface IDecoratorUpdateQuery {
$inc?: { [key: string]: number | undefined }
$set?: { [key: string]: any }
$push?: { [key: string]: any }
}
interface IFindProjection { interface IFindProjection {
projection?: { projection?: {
[key: string]: number | boolean | any [key: string]: number | boolean | any
......
/** @format */
import { resultsModel, TBAPIS } from '../../../sdk'
import { CODE_TYPES } from '../../../errorCode'
import { getTodayCompleteTask, getTotalCompleteTask } from '../task'
import { TASK_RATE_TYPE } from '../../../constants'
export const checkExchangeCreditsTask = async (
context: IContext<{ activityId: string; taskType: ITaskType; credits?: number }>,
{ session }: IControllerInfos
) => {
const { taskType, credits } = context.data
// 不是兑换积分类型不校验
if (taskType !== 'exchangeCredits') return
const myCredits = await TBAPIS.queryCredits(context, session)
console.log('myCredits', myCredits)
// 积分不足
if (myCredits < credits) return resultsModel.error(CODE_TYPES.ERROR_NO_CREDITS)
// 扣积分
let result = await TBAPIS.changeCredits(context, session, {
quantity: +credits,
change_type: 2, //变更类型:0交易,1:互动活动,2:权益兑换,3:手工调整
opt_type: 1, // 操作类型,'0':增加,1:扣减
remark: `积分兑换任务减积分`
})
if (!result) return resultsModel.error(CODE_TYPES.SYSTEM_ERROR)
}
...@@ -14,6 +14,7 @@ export const checkInviteId = async (context: IContext<{ activityId: string; invi ...@@ -14,6 +14,7 @@ export const checkInviteId = async (context: IContext<{ activityId: string; invi
// 自己邀请自己 // 自己邀请自己
if (openId === inviteId) return resultsModel.error(CODE_TYPES.ERROR_NO_INVITE_SELF) if (openId === inviteId) return resultsModel.error(CODE_TYPES.ERROR_NO_INVITE_SELF)
// 获取邀请者信息
const inviteUserInfo = await dbFindOne<IUserInfo>(context, USER_DB_NAME, { const inviteUserInfo = await dbFindOne<IUserInfo>(context, USER_DB_NAME, {
activityId, activityId,
openId: inviteId openId: inviteId
......
...@@ -4,11 +4,6 @@ import { resultsModel } from '../../../sdk' ...@@ -4,11 +4,6 @@ import { resultsModel } from '../../../sdk'
import { CODE_TYPES } from '../../../errorCode' import { CODE_TYPES } from '../../../errorCode'
export const checkNewVip = async (context: IContext<IParams>, { vipInfo, userInfo }: IControllerInfos) => { export const checkNewVip = async (context: IContext<IParams>, { vipInfo, userInfo }: IControllerInfos) => {
const {
openId,
data: { activityId, inviteId }
} = context
if (!vipInfo) { if (!vipInfo) {
console.error(`使用checkNewVip registeInfos必须注册vipInfo`) console.error(`使用checkNewVip registeInfos必须注册vipInfo`)
} }
......
/** @format */ /** @format */
export const checkTaskLimit = (taskType: ITaskType) => { import { resultsModel } from '../../../sdk'
return async function (context: IContext<IParams>, { activityInfo, userInfo }: IControllerInfos) { import { CODE_TYPES } from '../../../errorCode'
const { import { getTodayCompleteTask, getTotalCompleteTask } from '../task'
tasks: { import { TASK_RATE_TYPE } from '../../../constants'
[taskType]: { value, taskRateType, times }
export const checkTaskLimit = async (
context: IContext<{ activityId: string; taskType: ITaskType; itemId?: string }>,
{ userInfo, activityInfo }: IControllerInfos
) => {
const { taskType, itemId } = context.data
const { itemIds } = activityInfo?.tasks?.[taskType] || {}
if (!taskType) {
console.error('使用checkTaskLimit, 云函数必须传入taskType参数')
return
}
if (!activityInfo?.tasks?.[taskType]) {
return resultsModel.error(CODE_TYPES.SYSTEM_ERROR, `该活动缺少${taskType}配置项`)
}
if (itemId && !itemIds) {
return resultsModel.error(CODE_TYPES.SYSTEM_ERROR, `该任务缺少商品配置项`)
}
// B端配置商品ids不匹配正确
if (itemId && itemIds) {
const itemIdArray: number[] = Array.isArray(itemIds) ? itemIds : itemIds.split(',').map(v => +v)
if (!itemIdArray.includes(+itemId)) return resultsModel.error(CODE_TYPES.PARAMS_ERROR, '商品id不匹配')
} }
} = activityInfo
const {} = userInfo const { taskRateType, times } = activityInfo?.tasks?.[taskType]
// 永久任务已经完成
const { completeTimes } = getTotalCompleteTask(taskType, userInfo)
const hasComplete = completeTimes && taskRateType === TASK_RATE_TYPE.FOREVER
if (hasComplete) return resultsModel.error(CODE_TYPES.ERROR_TASK_LIMIT, `该任务已完成,去看看其它任务吧~`)
// 每日任务今天已经完成
const { todayCompleteTimes, todayTaskInfo } = getTodayCompleteTask(taskType, userInfo)
const hasCompleteToday = times && todayCompleteTimes === times && taskRateType === TASK_RATE_TYPE.EVERYDAY
if (hasCompleteToday) {
return resultsModel.error(CODE_TYPES.ERROR_TASK_LIMIT, `该任务今天已完成,明天再来吧~`)
}
// 今日任务该商品已经完成
const itemHasCompleteToday =
todayTaskInfo.find(v => v.itemId && v.itemId === itemId) && taskRateType === TASK_RATE_TYPE.EVERYDAY
if (itemHasCompleteToday) {
return resultsModel.error(CODE_TYPES.PARAMS_ERROR, '今日该商品任务已完成')
} }
} }
/** @format */
// 遍历Controller中的方法, 暴露出来
export const exportHandlers = (controllers: any[]) => {
const handlersMapper = controllers
.map(controller => {
const controllerInstance = new controller()
const handlersKeys = Object.getOwnPropertyNames(Object.getPrototypeOf(controllerInstance)).filter(
v => v !== 'constructor'
)
return handlersKeys.reduce((prev, current) => {
return {
...prev,
[current]: controllerInstance[current]
}
}, {})
})
.reduce((prev, current) => {
return {
...current,
...prev
}
}, {})
return handlersMapper
}
/** @format */
import { assign, isEmpty, merge } from 'lodash'
/** /**
* updateUser projection 格式化 * updateUser projection 格式化
* *
...@@ -6,7 +10,6 @@ ...@@ -6,7 +10,6 @@
* @return {*} * @return {*}
* @memberof UserService * @memberof UserService
*/ */
export function formatUpdateUserProjection(projection: IUpdateQuery): IUpdateQuery { export function formatUpdateUserProjection(projection: IUpdateQuery): IUpdateQuery {
projection['$set'] = projection['$set'] || {} projection['$set'] = projection['$set'] || {}
projection['$set'].updateTime = Date.now() projection['$set'].updateTime = Date.now()
...@@ -31,3 +34,25 @@ export function formatUserNick(name: string) { ...@@ -31,3 +34,25 @@ export function formatUserNick(name: string) {
} }
return newStr return newStr
} }
/**
* 不通过数据库select的情况下 获取更新后的数据
*
* @export
* @param {IUserInfo} userInfo
* @param {IDecoratorUpdateQuery} projection
*/
export function formatUpdatedUserInfo(userInfo: IUserInfo, projection: IDecoratorUpdateQuery) {
let updatedUserInfo = assign({}, userInfo)
if (!isEmpty(projection.$set)) {
updatedUserInfo = merge({}, userInfo, projection.$set)
}
if (!isEmpty(projection.$inc)) {
Object.keys(projection.$inc).forEach(key => {
// let splitKey
})
updatedUserInfo = merge({}, userInfo, projection.$set)
}
}
/** @format */ /** @format */
import { getToday } from './getToday' import { getToday } from './getToday'
import { TASK_STATUS, TASK_RATE_TYPE } from '../../constants'
/** /**
* 根据任务类型获取任务完成情况 * 根据任务类型获取任务完成情况
...@@ -10,7 +11,7 @@ import { getToday } from './getToday' ...@@ -10,7 +11,7 @@ import { getToday } from './getToday'
* @returns {array} * @returns {array}
* @memberof TaskService * @memberof TaskService
*/ */
export function getCompleteTaskByUserTaskInfo( export function getTotalCompleteTask(
taskType: string, taskType: string,
userInfo: IUserInfo userInfo: IUserInfo
): { ): {
...@@ -57,3 +58,42 @@ export function getTodayCompleteTask( ...@@ -57,3 +58,42 @@ export function getTodayCompleteTask(
todayTaskInfo: userInfo?.taskInfo?.[today]?.[taskType] || [] todayTaskInfo: userInfo?.taskInfo?.[today]?.[taskType] || []
} }
} }
/**
*
* 根据用户和任务完成情况,设置任务状态
*
* @param {IUserInfo} useInfo
* @param {string} taskType
* @param {number} taskRateType
* @param {number} [limitTimesEverday] 每天限制次数 任务频率为每天的时候必填
* @return {taskTatus} 1未完成 2 待领取 3 已完成
* @memberof TaskService
*/
export function setTaskStatus(
useInfo: IUserInfo,
taskType: string,
taskRateType: number,
limitTimesEveryday: number = 1
): number {
const waitReceive = useInfo?.remainTimes?.[taskType] || 0
if (waitReceive) return TASK_STATUS.WAIT_RECEIVE
// 当天的完成次数
const { todayCompleteTimes } = getTodayCompleteTask(taskType, useInfo)
// 总共的完成次数
const { completeTimes } = getTotalCompleteTask(taskType, useInfo)
switch (taskRateType) {
case TASK_RATE_TYPE.FOREVER:
return completeTimes > 0 ? TASK_STATUS.DONE : TASK_STATUS.WAIT_DO
break
case TASK_RATE_TYPE.EVERYDAY:
return todayCompleteTimes >= limitTimesEveryday ? TASK_STATUS.DONE : TASK_STATUS.WAIT_DO
break
case TASK_RATE_TYPE.NOLIMIT:
return TASK_STATUS.WAIT_DO
break
}
}
...@@ -3,35 +3,30 @@ ...@@ -3,35 +3,30 @@
import { resultsModel } from '../../../sdk' import { resultsModel } from '../../../sdk'
import { CODE_TYPES } from '../../../errorCode' import { CODE_TYPES } from '../../../errorCode'
import { dbCount } from '../../common/db' import { dbCount } from '../../common/db'
import { STAT_DB_NAME } from '../../../db' import { STAT_DB_NAME, USER_DB_NAME } from '../../../db'
import { getToday } from '../getToday' import { getToday } from '../getToday'
import { isNewVip, setNewVipUserData } from '../userUpdate' import { isNewVip, setNewVipUserData } from '../userUpdate'
import { update } from '../../../decorator/common/update'
export function updateVip(context: IContext<IParams>, { vipInfo, userInfo, activityInfo }: IControllerInfos) { export async function updateVip(
context: IContext<IParams>,
{ vipInfo, userInfo, activityInfo }: IControllerInfos
): Promise<IDecoratorUpdateQuery> {
let { member } = userInfo let { member } = userInfo
const { newMember } = member
const today = getToday()
const newVip = isNewVip(userInfo, vipInfo)
const memberReWards = activityInfo?.tasks?.member?.value const memberReWards = activityInfo?.tasks?.member?.value
let projection = { return isNewVip(userInfo, vipInfo)
$set: {}, ? {
$inc: {}, $set: {
$push: {} member: setNewVipUserData(member)
} },
$inc: {
if (newVip && !newMember) { 'remainTimes.member': +memberReWards
member = setNewVipUserData(member) },
$push: {
// @ts-ignore [`taskInfo.${getToday()}.member`]: { creatTime: Date.now() }
projection.$set.member = member
projection.$inc['remainTimes.member'] = +memberReWards
projection.$push[`taskInfo.${today}.member`] = {
creatTime: Date.now()
} }
} }
return projection : {}
} }
...@@ -18,7 +18,7 @@ export function isNewVip(userInfo: IUserInfo, vipInfo: IVipInfo): boolean { ...@@ -18,7 +18,7 @@ export function isNewVip(userInfo: IUserInfo, vipInfo: IVipInfo): boolean {
const { isVip } = vipInfo const { isVip } = vipInfo
return !flag && isVip return !flag && isVip && !userInfo.member.newMember
} }
export function setNewVipUserData(member: IMemberInfo): IMemberInfo { export function setNewVipUserData(member: IMemberInfo): IMemberInfo {
......
...@@ -20,8 +20,6 @@ export * from './common/getUserOrderlist' ...@@ -20,8 +20,6 @@ export * from './common/getUserOrderlist'
export * from './common/vip' export * from './common/vip'
export * from './common/exportHandlers'
export * from './common/helper' export * from './common/helper'
export * from './common/userUpdate' export * from './common/userUpdate'
......
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