增加面向游戏端的优惠券信息接口
This commit is contained in:
parent
ebdfef3b67
commit
c19a3475ad
37
doc/api.md
37
doc/api.md
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
### 20210705
|
### 20210705
|
||||||
|
|
||||||
1. 增加[开始分享优惠券](#223), [领取分享的优惠券](#224) 接口
|
1. 增加[开始分享优惠券](#223), [领取分享的优惠券](#224), [优惠券详情](#225) 接口
|
||||||
2. [用户券列表](#211), [抽奖](#214), [邀请奖励信息](#215), [领取邮件附件](#217)等接口返回的优惠券信息, 增加expire字段
|
2. [用户券列表](#211), [抽奖](#214), [邀请奖励信息](#215), [领取邮件附件](#217)等接口返回的优惠券信息, 增加expire字段
|
||||||
3. [获取店铺信息](#208) 的gamecfg增加返回 default_desc_txt, 用于首页介绍文字
|
3. [获取店铺信息](#208) 的gamecfg增加返回 default_desc_txt, 用于首页介绍文字
|
||||||
|
|
||||||
@ -865,6 +865,7 @@
|
|||||||
| 字段 | 说明 |
|
| 字段 | 说明 |
|
||||||
| -------- | -------------------------------------- |
|
| -------- | -------------------------------------- |
|
||||||
| id | 优惠券的短id |
|
| id | 优惠券的短id |
|
||||||
|
| shop | 优惠券的所属店铺 |
|
||||||
| sender | 分享者的accountId |
|
| sender | 分享者的accountId |
|
||||||
|
|
||||||
3. Response: JSON
|
3. Response: JSON
|
||||||
@ -881,3 +882,37 @@
|
|||||||
expire: 0 // 过期时间, 0表示永不过期
|
expire: 0 // 过期时间, 0表示永不过期
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 25. 优惠券详情
|
||||||
|
|
||||||
|
1. Method: POST
|
||||||
|
2. <span id="225">URI: /api/:accountId/coupon/info</span>
|
||||||
|
|
||||||
|
| 字段 | 说明 |
|
||||||
|
| -------- | -------------------------------------- |
|
||||||
|
| accountid | 优惠券拥有者的帐号id |
|
||||||
|
|
||||||
|
> POST参数
|
||||||
|
|
||||||
|
|
||||||
|
| 字段 | 说明 |
|
||||||
|
| -------- | -------------------------------------- |
|
||||||
|
| id | 优惠券的短id |
|
||||||
|
| shop | 优惠券的所属店铺 |
|
||||||
|
|
||||||
|
3. Response: JSON
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
id: '记录id',
|
||||||
|
shop: '店铺id',
|
||||||
|
shopName: '店铺名',
|
||||||
|
coupon: '券id',
|
||||||
|
couponName: '券名',
|
||||||
|
couponUrl: '券图片url',
|
||||||
|
status: '状态', //0: 未使用 , 1: 已使用 2: 赠送中, 3: 已赠送(已被领取) ,9: 已过期
|
||||||
|
expire: 0, // 过期时间, 0表示永不过期
|
||||||
|
user: '拥有者的昵称',
|
||||||
|
userAvatar: '拥有者的头像'
|
||||||
|
}
|
||||||
|
```
|
@ -5,6 +5,7 @@ import { ZError } from '../../common/ZError'
|
|||||||
import { Shop } from '../../models/shop/Shop'
|
import { Shop } from '../../models/shop/Shop'
|
||||||
import { Coupon } from '../../models/shop/Coupon'
|
import { Coupon } from '../../models/shop/Coupon'
|
||||||
import { getCouponUrl } from '../../services/File'
|
import { getCouponUrl } from '../../services/File'
|
||||||
|
import { GameUser } from 'models/user/GameUser'
|
||||||
|
|
||||||
class CouponController extends BaseController {
|
class CouponController extends BaseController {
|
||||||
/**
|
/**
|
||||||
@ -13,12 +14,17 @@ class CouponController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
@role('anon')
|
@role('anon')
|
||||||
@router('get /pub/coupon/:shop/:id')
|
@router('get /pub/coupon/:shop/:id')
|
||||||
|
@router('post /api/:accountId/coupon/info')
|
||||||
async info(req: any) {
|
async info(req: any) {
|
||||||
const { id, shop } = req.params
|
const { id, shop } = req.params
|
||||||
if (!id || !shop) {
|
if (!id || !shop) {
|
||||||
throw new ZError(10, '缺少必要参数')
|
throw new ZError(10, '缺少必要参数')
|
||||||
}
|
}
|
||||||
const record = await UserCoupon.findOne({ sid: id, shop })
|
const shopData = await Shop.fetchByID(shop)
|
||||||
|
if (!shopData) {
|
||||||
|
throw new ZError(12, '无法找到对应的店铺信息')
|
||||||
|
}
|
||||||
|
const record = await UserCoupon.findOne({ sid: id, shop: shopData.id })
|
||||||
if (!record) {
|
if (!record) {
|
||||||
throw new ZError(11, 'no matched records')
|
throw new ZError(11, 'no matched records')
|
||||||
}
|
}
|
||||||
@ -29,8 +35,8 @@ class CouponController extends BaseController {
|
|||||||
await record.save()
|
await record.save()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const shopData = await Shop.fetchByID(record.shop)
|
|
||||||
const coupon = await Coupon.findById(record.item)
|
const coupon = await Coupon.findById(record.item)
|
||||||
|
const user = await GameUser.getByAccountID(record.accountId)
|
||||||
return {
|
return {
|
||||||
id: record.sid,
|
id: record.sid,
|
||||||
shop: record.shop,
|
shop: record.shop,
|
||||||
@ -40,6 +46,8 @@ class CouponController extends BaseController {
|
|||||||
couponUrl: getCouponUrl(shopData.id, record.item),
|
couponUrl: getCouponUrl(shopData.id, record.item),
|
||||||
status: record.status,
|
status: record.status,
|
||||||
expire: record.expire,
|
expire: record.expire,
|
||||||
|
user: user.nickname,
|
||||||
|
userAvatar: user.avatar,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -93,11 +101,18 @@ class CouponController extends BaseController {
|
|||||||
@role('anon')
|
@role('anon')
|
||||||
@router('post /api/:accountId/coupon/receive_coupon')
|
@router('post /api/:accountId/coupon/receive_coupon')
|
||||||
async receive(req: any) {
|
async receive(req: any) {
|
||||||
const { accountId, id, sender } = req.params
|
const { accountId, id, sender, shop } = req.params
|
||||||
if (!id || !sender) {
|
if (!id || !sender || !shop) {
|
||||||
throw new ZError(10, '缺少必要参数: id')
|
throw new ZError(10, '缺少必要参数: id')
|
||||||
}
|
}
|
||||||
const result = await UserCoupon.updateOne({ sid: id, status: 2, accountId: sender }, { status: 3 })
|
const shopData = await Shop.fetchByID(shop)
|
||||||
|
if (!shopData) {
|
||||||
|
throw new ZError(12, '无法找到对应的店铺信息')
|
||||||
|
}
|
||||||
|
const result = await UserCoupon.updateOne(
|
||||||
|
{ sid: id, status: 2, accountId: sender, shop: shopData.id },
|
||||||
|
{ status: 3 },
|
||||||
|
)
|
||||||
if (result.nModified !== 1) {
|
if (result.nModified !== 1) {
|
||||||
throw new ZError(11, '未找到符合条件的记录, 可能已被别人领走')
|
throw new ZError(11, '未找到符合条件的记录, 可能已被别人领走')
|
||||||
}
|
}
|
||||||
@ -108,15 +123,14 @@ class CouponController extends BaseController {
|
|||||||
recordNew.source = 'receive'
|
recordNew.source = 'receive'
|
||||||
recordNew.activityId = record.id
|
recordNew.activityId = record.id
|
||||||
await recordNew.save()
|
await recordNew.save()
|
||||||
const shop = await Shop.fetchByID(record.shop)
|
|
||||||
const coupon = await Coupon.findById(record.item)
|
const coupon = await Coupon.findById(record.item)
|
||||||
return {
|
return {
|
||||||
id: recordNew.sid,
|
id: recordNew.sid,
|
||||||
shop: recordNew.shop,
|
shop: recordNew.shop,
|
||||||
shopName: shop.showName,
|
shopName: shopData.showName,
|
||||||
coupon: recordNew.item,
|
coupon: recordNew.item,
|
||||||
couponName: coupon.name,
|
couponName: coupon.name,
|
||||||
couponUrl: getCouponUrl(shop.id, recordNew.item),
|
couponUrl: getCouponUrl(shopData.id, recordNew.item),
|
||||||
status: recordNew.status,
|
status: recordNew.status,
|
||||||
expire: recordNew.expire,
|
expire: recordNew.expire,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user