Commit ec44152d authored by maggie's avatar maggie

Merge branch 'c_server_ts_perf' of...

Merge branch 'c_server_ts_perf' of http://gitlab2.dui88.com/qinhaitao/taobao-mini-template into c_server_ts_perf
parents 7248fe8e 38358d82
......@@ -29,11 +29,13 @@ export default class BaseController {
context: IContext<IParams>,
{ session }: IControllerInfos,
[baseService]: [BaseService]
): Promise<IResult<ITaoBaoItems[]>> {
): Promise<IResult<{ list: ITaoBaoItems[] }>> {
const { itemIds } = context.data
const list = await baseService.getItemListByIds(itemIds, session)
return resultsModel.success(list)
return resultsModel.success({
...list
})
}
}
/** @format */
import { services, checkParams, preUpdate } from '../decorator/common'
import { services, checkParams } from '../decorator/common'
import { resultsModel } from '../sdk'
import { UserService } from '../service'
......
/** @format */
import { services, checkParams, registeInfos } from '../decorator/common'
import { services, checkParams, registeInfos, preUpdate } from '../decorator/common'
import { resultsModel } from '../sdk'
import { UserService, AccessService } from '../service'
import { noCheckUser } from '../decorator/common'
export default class User {
/**
* 登录接口, 初始化/更新用户信息
*
* updateFirstLoginToday 当天第一次登陆的操作 如增加 3次游戏次数 gameTimes
*
* updateFirstLoginToday({ $inc: { gameTime: 3}})
*/
@checkParams(['activityId', 'userNick', 'avatar', 'isFollow'])
@noCheckUser
......@@ -16,7 +20,7 @@ export default class User {
context: IContext<IParams>,
{ userInfo, activityInfo, vipInfo }: IControllerInfos,
[userService, accessService]: [UserService, AccessService]
): Promise<IResult<{ openId: string }>> {
): Promise<IResult<{ openId: string; firstLoginToday: boolean; newUser: boolean }>> {
const updatedUserInfo = await userService.doLogin(userInfo, vipInfo, activityInfo)
// access表
const openIdResult = await accessService.addAccess(updatedUserInfo, vipInfo)
......
......@@ -23,6 +23,7 @@ export default class UserAccessService {
let { openId, data } = this.context
let { activityId, userNick, avatar, inviteId } = data
const today = getToday()
await this.accessdao.insertOne({
openId,
activityId,
......@@ -37,9 +38,11 @@ export default class UserAccessService {
accessTime: Date.now(),
createTime: Date.now(),
updateTime: Date.now(),
createDay: getToday()
createDay: today
})
return { openId }
const firstLoginToday = userInfo?.login?.[today] === 1
return { openId, firstLoginToday, newUser: userInfo.createDay === today && firstLoginToday }
}
async getAccessCount() {
......
......@@ -33,7 +33,7 @@ export default class BaseService {
* @return {Array}
* @memberof BaseService
*/
async getItemListByIds(itemIds: string, session: string): Promise<Array<ITaoBaoItems>> {
async getItemListByIds(itemIds: string, session: string): Promise<{ list: ITaoBaoItems[] }> {
const GOODSINFO =
'detail_url,approve_status,num_iid,title,nick,type,cid,pic_url,num,props,valid_thru,list_time,desc,price,has_discount,has_invoice,has_warranty,has_showcase,modified,delist_time,postage_id,seller_cids,outer_id,sold_quantity'
const result = await TBAPIS.getItemListByItemIds(this.context, itemIds, { fields: GOODSINFO })
......@@ -50,6 +50,6 @@ export default class BaseService {
}
}
)
return list
return { list }
}
}
......@@ -197,10 +197,10 @@ export default class TaskService extends UserService {
return projection
}
async getItemListWithCollectStatus(list: ITaoBaoItems[], userInfo: IUserInfo) {
async getItemListWithCollectStatus(list: { list: ITaoBaoItems[] }, userInfo: IUserInfo) {
const { taskInfo } = getTotalCompleteTask('collectGoods', userInfo)
return list.map(v => {
return list.list.map(v => {
return {
...v,
// 完成列表是否含有itemId
......
......@@ -2,15 +2,15 @@
import updateVip from './updateVip'
import updateSignTask from './updateSignTask'
import updateOrderGoods from './updateOrderGoods'
import updateFirstLogin from './updateFirstLogin'
import updateFirstLoginToday from './updateFirstLoginToday'
const update = {
updateVip,
updateSignTask,
updateOrderGoods,
updateFirstLogin
updateFirstLoginToday
}
export default update
export { updateVip, updateSignTask, updateOrderGoods, updateFirstLogin }
export { updateVip, updateSignTask, updateOrderGoods, updateFirstLoginToday }
/** @format */
import { getToday } from '../getToday'
import { isNewVip, setNewVipUserData } from '../userUpdate'
export default async function updateFirstLogin(
context: IContext<IParams>,
{ vipInfo, userInfo, activityInfo }: IControllerInfos
): Promise<IPreUpdateQuery> {
let { member } = userInfo
const memberReWards = activityInfo?.tasks?.member?.value
return isNewVip(userInfo, vipInfo)
? {
$set: {
member: setNewVipUserData(member)
},
$inc: {
'remainTimes.member': +memberReWards
},
$push: {
[`taskInfo.${getToday()}.member`]: { creatTime: Date.now() }
}
}
: {}
}
/** @format */
import { getToday } from '../getToday'
// login接口使用 当当天第一次登陆有数据变更的时候使用
export default function updateFirstLoginToday(update?: IPreUpdateQuery) {
return async function (
context: IContext<IParams>,
{ userInfo }: IControllerInfos
): Promise<IPreUpdateQuery | undefined> {
if (!userInfo) return {}
const firstLogin = userInfo?.login?.[`${getToday()}`] === 1
return firstLogin ? update : {}
}
}
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