增加获取公告列表的接口

This commit is contained in:
zhl 2021-06-10 18:04:05 +08:00
parent 8102bc005e
commit 878d1a3e1c
4 changed files with 64 additions and 4 deletions

View File

@ -764,3 +764,34 @@
```
> 说明, 这里获取的answer是使用 当前比赛session_当前题目的id_答案_jcfw中的sessionid, 计算md5
>
### 22. 公告列表
1. Method: POST
2. <span id="215">URI: /api/:accountId/announces</span>
| 字段 | 说明 |
| -------- | -------------------------------------- |
| accountid | 帐号id |
> POST参数
| 字段 | 说明 |
| -------- | -------------------------------------- |
| sid | 店铺id |
| ids | 已读的公告id数组 |
3. Response: JSON
```js
{
"id": "60c1d800646792f5f3764e93", // 公告id
"content": "22", // 公告内容, 最好用ubb富文本来显示
"endTime": 1623921267010, // 公告过期时间
"sendTime": 1623316467010, // 公告发送时间
"title": "111", // 公告标题
"type": 2 // 公告类型 0: 普通 1: 店铺群发 2: 全体
}
```

View File

@ -47,12 +47,12 @@ export default class AnnounceController extends BaseController {
@permission(['shopannounce:publish'])
@router('post /api/announce/publish')
async publish(req: any) {
let { id, active } = req.params
let { id, publish } = req.params
let record = await SysAnnounce.findById(id)
if (!record) {
throw new ZError(11, 'record not found')
}
record.publish = active
record.publish = publish
await record.save()
return record.toJson()
}

View File

@ -5,6 +5,7 @@ import { SysMail } from '../../models/content/SysMail'
import { ZError } from '../../common/ZError'
import { UserReward } from '../../models/user/UserReward'
import { Shop } from '../../models/shop/Shop'
import { SysAnnounce } from '../../models/content/SysAnnounce'
class MailController extends BaseController {
@role('anon')
@ -89,4 +90,28 @@ class MailController extends BaseController {
}
return results
}
@role('anon')
@router('post /api/:accountId/announces')
async announce_list(req: any) {
const { accountId, sid, ids } = req.params
if (!sid) {
throw new ZError(10, '缺少必要参数: sid')
}
const shop = await Shop.fetchByID(sid)
if (!shop) {
throw new ZError(11, '无法找到对应店铺')
}
let records = await SysAnnounce.findRecords(accountId, shop.id, ids)
return records.map(o => {
return {
id: o._id,
title: o.title,
content: o.content,
type: o.type,
sendTime: o.sendTime,
endTime: o.endTime,
}
})
}
}

View File

@ -22,17 +22,20 @@ export class SysAnnounceClass extends BaseModule {
/**
*
* @type {number} 0: 普通邮件 1: 店铺群发 2: 全体
* @type {number} 0: 普通 1: 店铺群发 2: 全体
*/
@prop()
public type: number
@noJson()
@prop({ default: false })
public publish: boolean
@noJson()
@prop({ type: () => [String] })
public accounts: string[]
@noJson()
@prop({ type: () => [String] })
public shops: string[]
@ -51,6 +54,7 @@ export class SysAnnounceClass extends BaseModule {
*
* @type {string}
*/
@noJson()
@prop()
public createdBy: string