增加店铺活动相关接口
This commit is contained in:
parent
639df901da
commit
c32af04b8b
72
src/admin/controllers/shop_active.controller.ts
Normal file
72
src/admin/controllers/shop_active.controller.ts
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import BaseController from '../../common/base.controller'
|
||||||
|
import { permission, router } from '../../decorators/router'
|
||||||
|
import { ShopActivity } from '../../models/shop/ShopActivity'
|
||||||
|
import { Puzzle } from '../../models/content/Puzzle'
|
||||||
|
import { ZError } from '../../common/ZError'
|
||||||
|
|
||||||
|
class ShopActiveController extends BaseController {
|
||||||
|
@permission('active:read')
|
||||||
|
@router('post /actives')
|
||||||
|
async list(req, res) {
|
||||||
|
let { start, limit, page } = req.params
|
||||||
|
limit = +limit || 10
|
||||||
|
start = +start || (+page - 1) * limit|| 0
|
||||||
|
let { opt, sort } = ShopActivity.parseQueryParam(req.params)
|
||||||
|
let records = await ShopActivity.find(opt)
|
||||||
|
.sort(sort)
|
||||||
|
.skip(start)
|
||||||
|
.limit(limit)
|
||||||
|
let count = await ShopActivity.count(opt)
|
||||||
|
|
||||||
|
return {
|
||||||
|
total: count,
|
||||||
|
start,
|
||||||
|
limit,
|
||||||
|
records
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@permission('active:read')
|
||||||
|
@router('get /active/:id')
|
||||||
|
async detail(req, res) {
|
||||||
|
let { id } = req.params
|
||||||
|
const record = await ShopActivity.findById(id)
|
||||||
|
if (!record) {
|
||||||
|
throw new ZError(11, 'record not found')
|
||||||
|
}
|
||||||
|
return record.toJson()
|
||||||
|
}
|
||||||
|
|
||||||
|
@permission('active:read')
|
||||||
|
@router('post /active/save')
|
||||||
|
async save(req: any) {
|
||||||
|
let { _id, withNext } = req.params
|
||||||
|
let user = req.user
|
||||||
|
let record
|
||||||
|
if (!_id) {
|
||||||
|
record = new Puzzle(req.params)
|
||||||
|
record.createdBy = user.id
|
||||||
|
} else {
|
||||||
|
record = await ShopActivity.findById(_id)
|
||||||
|
record.updateFromReq(req.params)
|
||||||
|
}
|
||||||
|
await record.save()
|
||||||
|
return record.toJson()
|
||||||
|
}
|
||||||
|
|
||||||
|
@permission('active:read')
|
||||||
|
@router('post /active/:id/delete')
|
||||||
|
async delete(req: any) {
|
||||||
|
let { id } = req.params
|
||||||
|
if (!id) {
|
||||||
|
throw new ZError(11, 'params mismatch')
|
||||||
|
}
|
||||||
|
await ShopActivity.findByIdAndUpdate(id, {
|
||||||
|
$set: {
|
||||||
|
deleted: true,
|
||||||
|
deleteTime: new Date()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
}
|
@ -12,12 +12,24 @@ import { Severity } from '@typegoose/typegoose/lib/internal/constants'
|
|||||||
@dbconn()
|
@dbconn()
|
||||||
@modelOptions({schemaOptions: {collection: "shop_activity", timestamps: true}, options: {allowMixed: Severity.ALLOW}})
|
@modelOptions({schemaOptions: {collection: "shop_activity", timestamps: true}, options: {allowMixed: Severity.ALLOW}})
|
||||||
class ShopActivityClass extends BaseModule {
|
class ShopActivityClass extends BaseModule {
|
||||||
|
/**
|
||||||
|
* 所属店铺
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
@prop()
|
@prop()
|
||||||
public shop: string
|
public shop: string
|
||||||
|
/**
|
||||||
|
* 活动名
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
@prop()
|
@prop()
|
||||||
public name: string
|
public name: string
|
||||||
|
/**
|
||||||
|
* 简单的说明文字
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
@prop()
|
||||||
|
public desc: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 已选择的题库分类
|
* 已选择的题库分类
|
||||||
@ -25,14 +37,52 @@ class ShopActivityClass extends BaseModule {
|
|||||||
*/
|
*/
|
||||||
@prop()
|
@prop()
|
||||||
public qtypes: string[]
|
public qtypes: string[]
|
||||||
|
/**
|
||||||
|
* 单次活动题目数量
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
@prop()
|
@prop()
|
||||||
public beginTime: number
|
public qcount: number
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重复类型
|
||||||
|
* 0: 不重复
|
||||||
|
* 1: 每日
|
||||||
|
* 2: 每周
|
||||||
|
* 3: 每月
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
@prop()
|
||||||
|
public repeatType: number
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 活动所在日, 只针对每周和每月的type有效
|
||||||
|
* @type {[number]}
|
||||||
|
*/
|
||||||
|
@prop({ type: () => [Number] })
|
||||||
|
public eventDays: number[]
|
||||||
|
/**
|
||||||
|
* 活动正式开始时间, 从0点开始
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
@prop({ type: () => [Number] })
|
||||||
|
public beginTime: number[]
|
||||||
|
/**
|
||||||
|
* 提前多少时间可开始进房间, 单位秒
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
@prop()
|
||||||
|
public prepareTime: number
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
@prop({type: mongoose.Schema.Types.Mixed})
|
@prop({type: mongoose.Schema.Types.Mixed})
|
||||||
public rewardInfo: {};
|
public rewardInfo: {};
|
||||||
|
/**
|
||||||
|
* 是否启用
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
@prop({default: 0})
|
||||||
|
public active: number
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否删除
|
* 是否删除
|
||||||
@ -53,8 +103,8 @@ class ShopActivityClass extends BaseModule {
|
|||||||
public createdBy: string
|
public createdBy: string
|
||||||
|
|
||||||
public static parseQueryParam(params) {
|
public static parseQueryParam(params) {
|
||||||
let {key, timeBegin, timeEnd} = params
|
let {key, timeBegin, timeEnd, active, shop} = params
|
||||||
let opt: any = {deleted: false, show: true}
|
let opt: any = {deleted: false}
|
||||||
if (key) {
|
if (key) {
|
||||||
opt.name = {$regex: key, $options: 'i'}
|
opt.name = {$regex: key, $options: 'i'}
|
||||||
}
|
}
|
||||||
@ -65,10 +115,16 @@ class ShopActivityClass extends BaseModule {
|
|||||||
} else if (!timeBegin && timeEnd) {
|
} else if (!timeBegin && timeEnd) {
|
||||||
opt.createdAt = {$lte: timeEnd};
|
opt.createdAt = {$lte: timeEnd};
|
||||||
}
|
}
|
||||||
|
if (active != undefined) {
|
||||||
|
opt.active = active
|
||||||
|
}
|
||||||
|
if (shop) {
|
||||||
|
opt.shop = shop
|
||||||
|
}
|
||||||
|
|
||||||
let sort = {_id: -1}
|
let sort = {_id: -1}
|
||||||
return { opt, sort }
|
return { opt, sort }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Shop = getModelForClass(ShopActivityClass, { existingConnection: ShopActivityClass.db })
|
export const ShopActivity = getModelForClass(ShopActivityClass, { existingConnection: ShopActivityClass.db })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user