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

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

View File

@@ -73,7 +73,7 @@ class Activity extends Model
{ {
try { try {
$code = 'YSD' . date('ymd') . mt_rand(100, 999); $code = 'YSD' . date('ymd') . mt_rand(100000, 999999);
if ($this->type == SELF::TYPE_EXTEND) { if ($this->type == SELF::TYPE_EXTEND) {
$start_at = now(); $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; namespace App\Providers;
use App\Models\ActivityRule;
use App\Observers\ActivityRuleObserver;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider class AppServiceProvider extends ServiceProvider
@@ -9,7 +11,6 @@ class AppServiceProvider extends ServiceProvider
/** /**
* Register any application services. * Register any application services.
*
* @return void * @return void
*/ */
public function register() public function register()
@@ -19,11 +20,12 @@ class AppServiceProvider extends ServiceProvider
/** /**
* Bootstrap any application services. * Bootstrap any application services.
*
* @return void * @return void
*/ */
public function boot() public function boot()
{ {
ActivityRule::observe(ActivityRuleObserver::class);
} }
} }

View File

@@ -15,13 +15,13 @@ class YsdGrant extends Init
$activity = Activity::where('code', $this->activityId)->first(); $activity = Activity::where('code', $this->activityId)->first();
if (!$activity) { if (!$activity) {
return '没有找到这个活动。'; return '发券失败,没有找到这个活动。';
} }
if ($activity->user) { if ($activity->user) {
$info = User::where('outlet_id', $this->outletId)->first(); $info = User::where('outlet_id', $this->outletId)->first();
if (!$info) { if (!$info) {
return '未查询到此网点信息。'; return '发券失败,未查询到此网点信息。';
} }
if ($info->parent_id != $activity->user_id) { if ($info->parent_id != $activity->user_id) {

View File

@@ -27,7 +27,7 @@ class YsdVerification extends Init
return $res; return $res;
} }
//查询卡券信息 返回model string 说明报错 //查询卡券信息 返回model 返回string 说明报错
$this->query_coupon = (new YsdQuery)->setOutletId($this->outletId) $this->query_coupon = (new YsdQuery)->setOutletId($this->outletId)
->setCode($this->redemptionCode) ->setCode($this->redemptionCode)
->start(); ->start();