You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.0 KiB
34 lines
1.0 KiB
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\CouponTemplate;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CouponTemplateController extends Controller
|
|
{
|
|
/**
|
|
* 显示可用的优惠券模板
|
|
*
|
|
* @return \Illuminate\View\View 返回包含优惠券模板的视图
|
|
*/
|
|
public function index()
|
|
{
|
|
// 获取今天的日期,格式为 YYYY-MM-DD
|
|
$today = Carbon::today()->toDateString();
|
|
|
|
// 查询未过期的优惠券模板,并标记用户已领取的优惠券
|
|
$templates = CouponTemplate::query()
|
|
->withCount(['coupons' => function ($query) {
|
|
// 统计当前用户已领取的优惠券数量
|
|
$query->where('user_id', auth()->id());
|
|
}])
|
|
->where('end_date', '>=', $today) // 只选择未过期的优惠券模板
|
|
->get(); // 执行查询并获取结果
|
|
|
|
// 返回包含优惠券模板的视图
|
|
return view('coupons.templates', compact('templates'));
|
|
}
|
|
}
|