增加添加活到规则自动添加到身份权限里

This commit is contained in:
2020-08-19 13:46:28 +08:00
parent 488ab4f410
commit 156ad845f8
6 changed files with 84 additions and 9 deletions

View File

@@ -47,7 +47,7 @@ class IndexController extends AdminController
$grid->column('code', '活动编号');
$grid->column('rule.code', '卡券规则');
$grid->column('所属')->display(function () {
return $this->user_id ? $this->user->nickname : '系统';
return $this->user_id ? $this->user->nickname : '系统';
});
$grid->column('类型')->display(function () {
@@ -90,7 +90,8 @@ class IndexController extends AdminController
return User::with('info')->whereHas('identity', function ($q) {
$q->where('identity_id', 1);
})->orderBy('id', 'desc')->get()->pluck('nickname', 'id');
});
})
->help('活动是否专属,不选择为所有渠道都可使用。');
$form->select('activity_rule_id', '所属规则')
->options(function ($option, $info) {
@@ -109,7 +110,10 @@ class IndexController extends AdminController
->required();
$form->switch('status', '状态')->default(1);
$form->switch('need_check', '校验')->default(1);
$form->switch('need_check', '多次校验')
->default(1)
->help('同一订单多次核销时校验订单每满100元可核销一笔。');
$form->saving(function (Form $form) {
$request = request();
if ($request->type == Activity::TYPE_EXTEND && empty($request->days)) {

View File

@@ -73,7 +73,7 @@ class Activity extends Model
{
try {
$code = 'YSD' . date('ymd') . mt_rand(100, 999);
$code = 'YSD' . date('ymd') . mt_rand(100000, 999999);
if ($this->type == SELF::TYPE_EXTEND) {
$start_at = now();

View File

@@ -0,0 +1,69 @@
<?php
namespace App\Observers;
use App\Models\ActivityRule;
use RuLong\Identity\Models\IdentityCode;
class ActivityRuleObserver
{
/**
* Handle the ActivityRule "created" event.
* @param ActivityRule $rule
* @return void
*/
public function created(ActivityRule $rule)
{
$info = IdentityCode::where('code', $rule->code)->exists();
if (!$info) {
IdentityCode::create([
'identity_id' => 1,
'name' => $rule->title,
'code' => $rule->code,
'profit' => 0,
]);
}
}
/**
* Handle the ActivityRule "updated" event.
* @param ActivityRule $rule
* @return void
*/
public function updated(ActivityRule $rule)
{
//
}
/**
* Handle the ActivityRule "deleted" event.
* @param ActivityRule $rule
* @return void
*/
public function deleted(ActivityRule $rule)
{
}
/**
* Handle the ActivityRule "restored" event.
* @param ActivityRule $rule
* @return void
*/
public function restored(ActivityRule $rule)
{
//
}
/**
* Handle the ActivityRule "force deleted" event.
* @param ActivityRule $rule
* @return void
*/
public function forceDeleted(ActivityRule $rule)
{
//
}
}

View File

@@ -2,6 +2,8 @@
namespace App\Providers;
use App\Models\ActivityRule;
use App\Observers\ActivityRuleObserver;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
@@ -9,7 +11,6 @@ class AppServiceProvider extends ServiceProvider
/**
* Register any application services.
*
* @return void
*/
public function register()
@@ -19,11 +20,12 @@ class AppServiceProvider extends ServiceProvider
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
ActivityRule::observe(ActivityRuleObserver::class);
}
}