Ticketcode.php 1.3 KB
<?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');
    }
}