add 公告相关接口
This commit is contained in:
parent
7cc642e2ae
commit
8102bc005e
59
src/admin/controllers/announce.controller.ts
Normal file
59
src/admin/controllers/announce.controller.ts
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import BaseController from '../../common/base.controller'
|
||||||
|
import { permission, router } from '../../decorators/router'
|
||||||
|
import { ZError } from '../../common/ZError'
|
||||||
|
import { ObjectId } from 'bson'
|
||||||
|
import { SysAnnounce } from '../../models/content/SysAnnounce'
|
||||||
|
|
||||||
|
export default class AnnounceController extends BaseController {
|
||||||
|
@permission('shopannounce:read')
|
||||||
|
@router('post /api/announces')
|
||||||
|
async list(req, res) {
|
||||||
|
return SysAnnounce.pageQuery(req.params, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
@permission('shopannounce:read')
|
||||||
|
@router('get /api/announce/:id')
|
||||||
|
async detail(req, res) {
|
||||||
|
let { id } = req.params
|
||||||
|
const record = await SysAnnounce.findById(id)
|
||||||
|
if (!record) {
|
||||||
|
throw new ZError(11, 'record not found')
|
||||||
|
}
|
||||||
|
return record.toJson()
|
||||||
|
}
|
||||||
|
|
||||||
|
@permission('shopannounce:edit')
|
||||||
|
@router('post /api/announce/save')
|
||||||
|
async save(req: any) {
|
||||||
|
const data = req.params
|
||||||
|
if (!data._id) {
|
||||||
|
data.createdBy = req.user.id
|
||||||
|
data._id = new ObjectId()
|
||||||
|
}
|
||||||
|
let record = await SysAnnounce.insertOrUpdate({ _id: data._id }, data)
|
||||||
|
return record.toJson()
|
||||||
|
}
|
||||||
|
|
||||||
|
@permission('shopannounce:delete')
|
||||||
|
@router('post /api/announce/delete')
|
||||||
|
async delete(req: any) {
|
||||||
|
let { ids } = req.params
|
||||||
|
if (!ids) {
|
||||||
|
throw new ZError(11, 'params mismatch')
|
||||||
|
}
|
||||||
|
return SysAnnounce.deleteVirtual(ids)
|
||||||
|
}
|
||||||
|
|
||||||
|
@permission(['shopannounce:publish'])
|
||||||
|
@router('post /api/announce/publish')
|
||||||
|
async publish(req: any) {
|
||||||
|
let { id, active } = req.params
|
||||||
|
let record = await SysAnnounce.findById(id)
|
||||||
|
if (!record) {
|
||||||
|
throw new ZError(11, 'record not found')
|
||||||
|
}
|
||||||
|
record.publish = active
|
||||||
|
await record.save()
|
||||||
|
return record.toJson()
|
||||||
|
}
|
||||||
|
}
|
@ -377,7 +377,7 @@ class PuzzleController extends BaseController {
|
|||||||
if (!history) {
|
if (!history) {
|
||||||
throw new ZError(13, 'not found match info')
|
throw new ZError(13, 'not found match info')
|
||||||
}
|
}
|
||||||
if (!history.hasExpired()) {
|
if (history.hasExpired()) {
|
||||||
throw new ZError(18, 'match has expired')
|
throw new ZError(18, 'match has expired')
|
||||||
}
|
}
|
||||||
if (history.type !== 0) {
|
if (history.type !== 0) {
|
||||||
|
100
src/models/content/SysAnnounce.ts
Normal file
100
src/models/content/SysAnnounce.ts
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
import { dbconn } from '../../decorators/dbconn'
|
||||||
|
import { getModelForClass, modelOptions, prop, ReturnModelType } from '@typegoose/typegoose'
|
||||||
|
import { Severity } from '@typegoose/typegoose/lib/internal/constants'
|
||||||
|
import { BaseModule } from '../Base'
|
||||||
|
import { noJson } from '../../decorators/nojson'
|
||||||
|
import { SysMail } from './SysMail'
|
||||||
|
|
||||||
|
@dbconn()
|
||||||
|
@modelOptions({
|
||||||
|
schemaOptions: { collection: 'sys_announce', timestamps: true },
|
||||||
|
options: { allowMixed: Severity.ALLOW },
|
||||||
|
})
|
||||||
|
export class SysAnnounceClass extends BaseModule {
|
||||||
|
@prop()
|
||||||
|
public shop: string
|
||||||
|
|
||||||
|
@prop()
|
||||||
|
public title: string
|
||||||
|
|
||||||
|
@prop()
|
||||||
|
public content: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型
|
||||||
|
* @type {number} 0: 普通邮件 1: 店铺群发 2: 全体
|
||||||
|
*/
|
||||||
|
@prop()
|
||||||
|
public type: number
|
||||||
|
|
||||||
|
@prop({ default: false })
|
||||||
|
public publish: boolean
|
||||||
|
|
||||||
|
@prop({ type: () => [String] })
|
||||||
|
public accounts: string[]
|
||||||
|
|
||||||
|
@prop({ type: () => [String] })
|
||||||
|
public shops: string[]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否删除
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
@noJson()
|
||||||
|
@prop({ default: false })
|
||||||
|
public deleted: boolean
|
||||||
|
@noJson()
|
||||||
|
@prop()
|
||||||
|
public deleteTime: Date
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建人
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
@prop()
|
||||||
|
public createdBy: string
|
||||||
|
|
||||||
|
@prop()
|
||||||
|
public sendTime: number
|
||||||
|
|
||||||
|
@prop()
|
||||||
|
public endTime: number
|
||||||
|
|
||||||
|
public static async findRecords(
|
||||||
|
this: ReturnModelType<typeof SysAnnounceClass>,
|
||||||
|
accountId: string,
|
||||||
|
shop: string,
|
||||||
|
excludes: string[],
|
||||||
|
) {
|
||||||
|
let now = Date.now()
|
||||||
|
let mails0 = await this.find({
|
||||||
|
accounts: accountId,
|
||||||
|
type: 0,
|
||||||
|
deleted: false,
|
||||||
|
publish: true,
|
||||||
|
sendTime: { $lte: now },
|
||||||
|
endTime: { $gte: now },
|
||||||
|
_id: { $nin: excludes },
|
||||||
|
})
|
||||||
|
let mails1 = await this.find({
|
||||||
|
shops: shop,
|
||||||
|
type: 1,
|
||||||
|
deleted: false,
|
||||||
|
publish: true,
|
||||||
|
sendTime: { $lte: now },
|
||||||
|
endTime: { $gte: now },
|
||||||
|
_id: { $nin: excludes },
|
||||||
|
})
|
||||||
|
let mails2 = await this.find({
|
||||||
|
type: 2,
|
||||||
|
deleted: false,
|
||||||
|
publish: true,
|
||||||
|
sendTime: { $lte: now },
|
||||||
|
endTime: { $gte: now },
|
||||||
|
_id: { $nin: excludes },
|
||||||
|
})
|
||||||
|
return mails0.concat(mails1).concat(mails2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SysAnnounce = getModelForClass(SysAnnounceClass, { existingConnection: SysAnnounceClass.db })
|
Loading…
x
Reference in New Issue
Block a user