v2board/app/Http/Controllers/Admin/CouponController.php
2019-12-31 18:16:43 +08:00

37 lines
783 B
PHP

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\Admin\CouponSave;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Coupon;
use App\Utils\Helper;
class CouponController extends Controller
{
public function fetch (Request $request) {
return response([
'data' => Coupon::all()
]);
}
public function save (CouponSave $request) {
$params = $request->only([
'name',
'type',
'value',
'expired_at',
'limit_use'
]);
$params['code'] = Helper::guid();
if (!Coupon::create($params)) {
abort(500, '创建失败');
}
return response([
'data' => true
]);
}
}