优化活动列表
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Admin\Controllers\Activity;
|
||||
|
||||
use App\Admin\Renderable\Activity\Grants;
|
||||
use App\Admin\Renderable\Activity\Verifications;
|
||||
use App\Models\Activity;
|
||||
use App\Models\ActivityRule;
|
||||
use App\Models\User;
|
||||
@@ -18,7 +20,7 @@ class IndexController extends AdminController
|
||||
protected function grid(): Grid
|
||||
{
|
||||
$grid = new Grid(new Activity);
|
||||
$grid->model()->withCount('coupons');
|
||||
$grid->model()->with(['rule', 'grants', 'verifications'])->withCount('coupons');
|
||||
|
||||
$grid->actions(function ($actions) {
|
||||
$actions->disableView();
|
||||
@@ -50,30 +52,24 @@ class IndexController extends AdminController
|
||||
});
|
||||
|
||||
$grid->column('channel', '核销途径')
|
||||
->using(Activity::CHANNELS)
|
||||
->label([
|
||||
Activity::CHANNEL_YSD => 'info',
|
||||
Activity::CHANNEL_UNION => 'success',
|
||||
]);
|
||||
->using(Activity::CHANNELS)
|
||||
->label([
|
||||
Activity::CHANNEL_YSD => 'info',
|
||||
Activity::CHANNEL_UNION => 'success',
|
||||
]);
|
||||
|
||||
$grid->column('days', '延期(天)');
|
||||
$grid->column('rule.full', '满足金额');
|
||||
$grid->column('rule.take', '扣除金额');
|
||||
$grid->column('发券渠道')
|
||||
->display(function () {
|
||||
return $this->grants->pluck('user_nickname');
|
||||
})
|
||||
->label()
|
||||
->width(350)
|
||||
->hide();
|
||||
|
||||
$grid->column('核券渠道')
|
||||
->display(function () {
|
||||
return $this->verifications->pluck('user_nickname');
|
||||
})
|
||||
->label()
|
||||
->width(350)
|
||||
->hide();
|
||||
$grid->column('发券渠道')->display(function ($title, $column) {
|
||||
return '查看';
|
||||
})->modal(Grants::class);
|
||||
|
||||
$grid->column('核券渠道')->display(function ($title, $column) {
|
||||
return '查看';
|
||||
})->modal(Verifications::class);
|
||||
|
||||
|
||||
$grid->column('开始时间')->display(function () {
|
||||
return $this->type == Activity::TYPE_SCOPE ? $this->start_at->format('Y-m-d') : '---';
|
||||
@@ -94,6 +90,7 @@ class IndexController extends AdminController
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
protected function form(): Form
|
||||
@@ -104,92 +101,92 @@ class IndexController extends AdminController
|
||||
$form->textarea('description', '活动说明')->required();
|
||||
|
||||
$form->select('activity_rule_id', '所属规则')
|
||||
->options(function ($option, $info) {
|
||||
return ActivityRule::where('status', 1)->pluck('title', 'id');
|
||||
})
|
||||
->required();
|
||||
->options(function ($option, $info) {
|
||||
return ActivityRule::where('status', 1)->pluck('title', 'id');
|
||||
})
|
||||
->required();
|
||||
|
||||
$form->number('total', '总数')
|
||||
->help('可发券总数,0为不限制')
|
||||
->default(10000)
|
||||
->required();
|
||||
->help('可发券总数,0为不限制')
|
||||
->default(10000)
|
||||
->required();
|
||||
|
||||
$form->radio('type', '类型')
|
||||
->options(Activity::TYPES)
|
||||
->when(Activity::TYPE_EXTEND, function (Form $form) {
|
||||
$form->number('days', '延期天数')->default(60)->help('到期日期=发券日期+延期天数');
|
||||
})
|
||||
->when(Activity::TYPE_SCOPE, function (Form $form) {
|
||||
$form->dateRange('start_at', 'end_at', '有效时间');
|
||||
})
|
||||
->required();
|
||||
->options(Activity::TYPES)
|
||||
->when(Activity::TYPE_EXTEND, function (Form $form) {
|
||||
$form->number('days', '延期天数')->default(60)->help('到期日期=发券日期+延期天数');
|
||||
})
|
||||
->when(Activity::TYPE_SCOPE, function (Form $form) {
|
||||
$form->dateRange('start_at', 'end_at', '有效时间');
|
||||
})
|
||||
->required();
|
||||
|
||||
$form->radio('channel', '核销途径')
|
||||
->options(Activity::CHANNELS)
|
||||
->default(Activity::CHANNEL_YSD)
|
||||
->help('券码核销的途径:亿时代是自己核销,银联是银联pos核销')
|
||||
->required();
|
||||
->options(Activity::CHANNELS)
|
||||
->default(Activity::CHANNEL_YSD)
|
||||
->help('券码核销的途径:亿时代是自己核销,银联是银联pos核销')
|
||||
->required();
|
||||
|
||||
$form->switch('status', '状态')->default(1);
|
||||
$form->switch('need_check', '多次校验')
|
||||
->default(1)
|
||||
->help('同一订单,多次核销时校验,订单每满100元可核销一笔。');
|
||||
->default(1)
|
||||
->help('同一订单,多次核销时校验,订单每满100元可核销一笔。');
|
||||
|
||||
$users = User::query()
|
||||
->with('info')
|
||||
->whereHas('identity', function ($q) {
|
||||
$q->where('identity_id', 1);
|
||||
})
|
||||
->orderBy('id', 'desc')
|
||||
->get()
|
||||
->pluck('nickname', 'id');
|
||||
->with('info')
|
||||
->whereHas('identity', function ($q) {
|
||||
$q->where('identity_id', 1);
|
||||
})
|
||||
->orderBy('id', 'desc')
|
||||
->get()
|
||||
->pluck('nickname', 'id');
|
||||
|
||||
$form->listbox('grants.user_id', '可发券渠道')
|
||||
->options($users)
|
||||
->default(function ($form) {
|
||||
if ($form->isEditing()) {
|
||||
return $form->model()->grants()->pluck('user_id')->toArray();
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
})
|
||||
->required();
|
||||
->options($users)
|
||||
->default(function ($form) {
|
||||
if ($form->isEditing()) {
|
||||
return $form->model()->grants()->pluck('user_id')->toArray();
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
})
|
||||
->required();
|
||||
|
||||
$form->listbox('verifications.user_id', '可核券渠道')
|
||||
->options($users)
|
||||
->default(function ($form) {
|
||||
if ($form->isEditing()) {
|
||||
return $form->model()->verifications()->pluck('user_id')->toArray();
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
})
|
||||
->required();
|
||||
->options($users)
|
||||
->default(function ($form) {
|
||||
if ($form->isEditing()) {
|
||||
return $form->model()->verifications()->pluck('user_id')->toArray();
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
})
|
||||
->required();
|
||||
|
||||
$form->radio('verify_shop', '网点校验')
|
||||
->options(Activity::VERIFY_SHOPS)
|
||||
->default(Activity::VERIFY_SHOP_NO)
|
||||
->when(Activity::VERIFY_SHOP_YES, function (Form $form) use ($users) {
|
||||
$form->listbox('shops.user_id', '可核券渠道')
|
||||
->options(function () {
|
||||
return User::query()
|
||||
->with('info')
|
||||
->whereHas('identity', function ($q) {
|
||||
$q->where('identity_id', 2);
|
||||
})
|
||||
->where('status', 1)
|
||||
->orderBy('id', 'desc')
|
||||
->get()
|
||||
->pluck('nickname', 'id');
|
||||
})
|
||||
->default(function ($form) {
|
||||
if ($form->isEditing()) {
|
||||
return $form->model()->shops()->pluck('user_id')->toArray();
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
});
|
||||
->options(Activity::VERIFY_SHOPS)
|
||||
->default(Activity::VERIFY_SHOP_NO)
|
||||
->when(Activity::VERIFY_SHOP_YES, function (Form $form) use ($users) {
|
||||
$form->listbox('shops.user_id', '可核券渠道')
|
||||
->options(function () {
|
||||
return User::query()
|
||||
->with('info')
|
||||
->whereHas('identity', function ($q) {
|
||||
$q->where('identity_id', 2);
|
||||
})
|
||||
->where('status', 1)
|
||||
->orderBy('id', 'desc')
|
||||
->get()
|
||||
->pluck('nickname', 'id');
|
||||
})
|
||||
->default(function ($form) {
|
||||
if ($form->isEditing()) {
|
||||
return $form->model()->shops()->pluck('user_id')->toArray();
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$form->saving(function (Form $form) {
|
||||
$request = request();
|
||||
@@ -222,11 +219,11 @@ class IndexController extends AdminController
|
||||
}
|
||||
|
||||
if (request()->start) {
|
||||
$form->start_at = $form->start_at . ' 00:00:01';
|
||||
$form->start_at = $form->start_at.' 00:00:01';
|
||||
}
|
||||
|
||||
if (request()->end_at) {
|
||||
$form->end_at = $form->end_at . ' 23:59:59';
|
||||
$form->end_at = $form->end_at.' 23:59:59';
|
||||
}
|
||||
|
||||
$shops = isset(request()->shops) ? array_filter(request()->shops['user_id']) : [];
|
||||
@@ -249,10 +246,10 @@ class IndexController extends AdminController
|
||||
foreach ($form->grants['user_id'] as $key => $user_id) {
|
||||
if ($user_id) {
|
||||
$form->model()
|
||||
->grants()
|
||||
->updateOrCreate([
|
||||
'user_id' => $user_id,
|
||||
]);
|
||||
->grants()
|
||||
->updateOrCreate([
|
||||
'user_id' => $user_id,
|
||||
]);
|
||||
$users[] = $user_id;
|
||||
}
|
||||
}
|
||||
@@ -263,10 +260,10 @@ class IndexController extends AdminController
|
||||
foreach ($form->verifications['user_id'] as $key => $user_id) {
|
||||
if ($user_id) {
|
||||
$form->model()
|
||||
->verifications()
|
||||
->updateOrCreate([
|
||||
'user_id' => $user_id,
|
||||
]);
|
||||
->verifications()
|
||||
->updateOrCreate([
|
||||
'user_id' => $user_id,
|
||||
]);
|
||||
$users[] = $user_id;
|
||||
}
|
||||
}
|
||||
@@ -274,16 +271,16 @@ class IndexController extends AdminController
|
||||
|
||||
$shops = isset(request()->shops) ? array_filter(request()->shops['user_id']) : [];
|
||||
|
||||
if (!empty($shops)) {
|
||||
if (! empty($shops)) {
|
||||
//设置核销网点
|
||||
$users = [];
|
||||
foreach ($form->shops['user_id'] as $key => $user_id) {
|
||||
if ($user_id) {
|
||||
$form->model()
|
||||
->shops()
|
||||
->updateOrCreate([
|
||||
'user_id' => $user_id,
|
||||
]);
|
||||
->shops()
|
||||
->updateOrCreate([
|
||||
'user_id' => $user_id,
|
||||
]);
|
||||
$users[] = $user_id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,11 @@ class Grants implements Renderable
|
||||
'nickname' => $info->user_nickname,
|
||||
];
|
||||
});
|
||||
dd($items->toArray());
|
||||
|
||||
return new Table(['Id', '渠道'], $items->toArray());
|
||||
$table = new Table(['Id', '渠道'], $items->toArray());
|
||||
|
||||
return $table->render();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
28
app/Admin/Renderable/Activity/Verifications.php
Normal file
28
app/Admin/Renderable/Activity/Verifications.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Renderable\Activity;
|
||||
|
||||
use App\Models\Activity;
|
||||
use Encore\Admin\Widgets\Table;
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
|
||||
class Verifications implements Renderable
|
||||
{
|
||||
|
||||
public function render($key = null)
|
||||
{
|
||||
$activity = Activity::find($key);
|
||||
$items = $activity->verifications->map(function ($info) {
|
||||
return [
|
||||
'id' => $info->id,
|
||||
'nickname' => $info->user_nickname,
|
||||
];
|
||||
});
|
||||
|
||||
$table = new Table(['Id', '渠道'], $items->toArray());
|
||||
|
||||
return $table->render();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user