test_service d3170b4d1c 1
2023-12-01 15:43:29 +08:00

1 line
1.0 KiB
PHP

<?php
namespace app\api\controller\food\market;
use app\api\controller\food\Controller;
use app\api\model\food\CouponOffline as CouponOfflineModel;
/**
* 优惠券管理
*/
class Coupon extends Controller
{
private $user;
/**
* 构造方法
*/
public function initialize()
{
parent::initialize();
$this->user = $this->getUserDetail(); // 用户信息
}
/**
* 线下领取优惠券核销
*/
public function offline($id)
{
//提前3分钟删除即将到期未领取优惠券
(new CouponOfflineModel)->where('status',10)->where('expire_time','<',time()-180)->delete();
if($model = CouponOfflineModel::get($id,['coupon'])){
if($model->writeOff($this->user_id)){
return $this->renderMsg('优惠券领取成功');
}
$error = $model->getError() ?: '优惠券领取失败';
return $this->renderError($error);
}
return $this->renderError('优惠券不存或已过期');
}
}