This repository has been archived on 2021-03-23. You can view files and clone it, but cannot push or open issues or pull requests.
Files
pingan_unionpay/app/Admin/Controllers/Activity/RuleController.php

82 lines
2.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Admin\Controllers\Activity;
use App\Models\ActivityRule;
use App\Models\User;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Illuminate\Support\MessageBag;
use RuLong\Identity\Models\Identity;
class RuleController extends AdminController
{
protected $title = '规则管理';
protected function grid()
{
$grid = new Grid(new ActivityRule);
$grid->actions(function ($actions) {
$actions->disableView();
});
$grid->column('id', '#ID#');
$grid->column('title', '规则名称');
$grid->column('code', '规则编号');
$grid->column('full', '满足金额');
$grid->column('take', '扣除金额');
$grid->status('状态')->switch([
'on' => ['value' => 1, 'text' => '正常', 'color' => 'primary'],
'off' => ['value' => 0, 'text' => '关闭', 'color' => 'danger'],
]);
$grid->column('created_at', '创建时间');
return $grid;
}
/**
* Make a form builder.
* @return Form
*/
protected function form()
{
$form = new Form(new ActivityRule);
$form->text('title', '规则名称')->required();
$form->text('code', '规则编号')->required()->help('列YSD-full100-15');
$form->hidden('full', '满足金额')->required()->default(0);
$form->hidden('take', '抵扣金额')->required()->default(0);
$form->switch('status', '状态')->default(1);
$form->saving(function (Form $form) {
$code = $form->code;
$ticket = explode('-', $code);
if (!is_array($ticket) || count($ticket) != 3) {
$error = new MessageBag([
'title' => '错误',
'message' => '规则编号格式错误',
]);
return back()->withInput()->with(compact('error'));
}
$full = $ticket[1]; //full100
$price = $ticket[2];
preg_match('/\d+/', $full, $match);
$form->full = $match[0];
$form->take = $price;
});
return $form;
}
}