Ticketcode.php
1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace app\api\controller;
use think\Db;
use think\Validate;
use app\common\controller\Api;
/**
* 优惠码接口
*/
class Ticketcode extends Api
{
/**
* @ApiTitle (检查优惠码)
* @ApiSummary (检查优惠码)
* @ApiMethod (POST)
* @ApiRoute (/api/ticketcode/checkTicketCode)
* @ApiHeaders (name=token, type=string, required=false, description="请求的Token")
* @ApiParams (name=ticket_code, type=string, required=false, description="优惠码")
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
"id": "id",// 地区id
"name": "name",// 名称
},
})
*/
public function checkTicketCode()
{
$ticketCodeModel = new \app\api\model\Ticketcode();
//判断优惠码是否可用
$ticketCode = $this->request->param('ticket_code');
if (!$ticketCode) $this->error('缺少参数 ticket_code!');
$ticketCodeInfo = $ticketCodeModel->where('code', $ticketCode)->field('user_id,validtime')->find();
if (!$ticketCodeInfo) $this->error('优惠码不存在!');
if ($ticketCodeInfo['validtime'] < time()) $this->error('优惠码已过期!');
if ($ticketCodeInfo['user_id']) $this->error('优惠码已使用!');
$this->success('SUCCESS');
}
}