增加发券规则
This commit is contained in:
@@ -73,6 +73,7 @@ class IndexController extends AdminController
|
||||
protected function grid()
|
||||
{
|
||||
$grid = new Grid(new Activity);
|
||||
$grid->model()->withCount('coupons');
|
||||
|
||||
$grid->actions(function ($actions) {
|
||||
$actions->disableView();
|
||||
@@ -99,6 +100,8 @@ class IndexController extends AdminController
|
||||
$grid->column('id', '#ID#');
|
||||
$grid->column('title', '活动名称');
|
||||
$grid->column('code', '活动编号');
|
||||
$grid->column('total', '可发券总数');
|
||||
$grid->column('coupons_count', '可发券总数');
|
||||
$grid->column('rule.code', '卡券规则');
|
||||
$grid->column('类型')->display(function () {
|
||||
return $this->type_text;
|
||||
@@ -155,6 +158,11 @@ class IndexController extends AdminController
|
||||
})
|
||||
->required();
|
||||
|
||||
$form->number('total', '总数')
|
||||
->help('可发券总数')
|
||||
->default(10000)
|
||||
->required();
|
||||
|
||||
$form->radio('type', '类型')
|
||||
->options(Activity::TYPES)
|
||||
->when(Activity::TYPE_EXTEND, function (Form $form) {
|
||||
@@ -192,6 +200,16 @@ class IndexController extends AdminController
|
||||
|
||||
$form->saving(function (Form $form) {
|
||||
$request = request();
|
||||
|
||||
if ($request->total < 0) {
|
||||
$error = new MessageBag([
|
||||
'title' => '错误',
|
||||
'message' => '可发券总数必须大于0',
|
||||
]);
|
||||
|
||||
return back()->withInput()->with(compact('error'));
|
||||
}
|
||||
|
||||
if ($request->type == Activity::TYPE_EXTEND && empty($request->days)) {
|
||||
$error = new MessageBag([
|
||||
'title' => '错误',
|
||||
@@ -209,6 +227,7 @@ class IndexController extends AdminController
|
||||
|
||||
return back()->withInput()->with(compact('error'));
|
||||
}
|
||||
|
||||
if (request()->start) {
|
||||
$form->start_at = $form->start_at . ' 00:00:01';
|
||||
}
|
||||
@@ -216,6 +235,7 @@ class IndexController extends AdminController
|
||||
if (request()->end_at) {
|
||||
$form->end_at = $form->end_at . ' 23:59:59';
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$form->saved(function (Form $form) {
|
||||
|
||||
@@ -20,83 +20,183 @@ class HomeController extends Controller
|
||||
->title('数据看版1')
|
||||
->row(function (Row $row) {
|
||||
$row->column(2, function (Column $column) {
|
||||
$column->append(new InfoBox('渠道商', 'users', 'yellow', '/admin/users?identity[identity_id]=1', User::whereHas('identity', function ($q) {$q->where('identity_id', 1);})->count()));
|
||||
$column->append(new InfoBox(
|
||||
'渠道商',
|
||||
'users',
|
||||
'yellow',
|
||||
'/admin/users?identity[identity_id]=1',
|
||||
User::whereHas('identity', function ($q) {
|
||||
$q->where('identity_id', 1);
|
||||
})->count()
|
||||
));
|
||||
});
|
||||
|
||||
})
|
||||
->row(function (Row $row) {
|
||||
$row->column(2, function (Column $column) {
|
||||
$column->append(new InfoBox('核销卡券总数', '', 'blue', '/admin/coupons', Coupon::whereIn('status', [2, 3])->count()));
|
||||
});
|
||||
|
||||
$row->column(2, function (Column $column) {
|
||||
$column->append(new InfoBox('核销成功', '', 'blue', '/admin/coupons', Coupon::where('status', 2)->count()));
|
||||
$column->append(new InfoBox(
|
||||
'核销卡券总数',
|
||||
'',
|
||||
'blue',
|
||||
'/admin/coupons',
|
||||
Coupon::whereIn('status', [2, 3])->count()
|
||||
));
|
||||
});
|
||||
$row->column(2, function (Column $column) {
|
||||
$column->append(new InfoBox('核销失败', '', 'black', '/admin/coupons', Coupon::where('status', 3)->count()));
|
||||
$column->append(new InfoBox(
|
||||
'核销成功',
|
||||
'',
|
||||
'blue',
|
||||
'/admin/coupons',
|
||||
Coupon::where('status', 2)->count()
|
||||
));
|
||||
});
|
||||
$row->column(2, function (Column $column) {
|
||||
$column->append(new InfoBox('资金通道结算', '', 'red', '/admin/coupons', Coupon::where('status', 2)->sum('price')));
|
||||
$column->append(new InfoBox(
|
||||
'核销失败',
|
||||
'',
|
||||
'black',
|
||||
'/admin/coupons',
|
||||
Coupon::where('status', 3)->count()
|
||||
));
|
||||
});
|
||||
$row->column(2, function (Column $column) {
|
||||
$column->append(new InfoBox('应打款金额', '', 'green', '/admin/coupons', Coupon::where('status', 2)->sum('profit')));
|
||||
$column->append(new InfoBox(
|
||||
'资金通道结算',
|
||||
'',
|
||||
'red',
|
||||
'/admin/coupons',
|
||||
Coupon::where('status', 2)->sum('price')
|
||||
));
|
||||
});
|
||||
$row->column(2, function (Column $column) {
|
||||
$column->append(new InfoBox('已打款金额', '', 'green', '/admin/coupons', Coupon::where('status', 2)->where('is_profit', 1)->sum('profit')));
|
||||
$column->append(new InfoBox(
|
||||
'应打款金额',
|
||||
'',
|
||||
'green',
|
||||
'/admin/coupons',
|
||||
Coupon::where('status', 2)->sum('profit')
|
||||
));
|
||||
});
|
||||
$row->column(2, function (Column $column) {
|
||||
$column->append(new InfoBox(
|
||||
'已打款金额',
|
||||
'',
|
||||
'green',
|
||||
'/admin/coupons',
|
||||
Coupon::where('status', 2)
|
||||
->where('is_profit', 1)
|
||||
->sum('profit')
|
||||
));
|
||||
});
|
||||
})
|
||||
->row(function (Row $row) {
|
||||
|
||||
$coupons = Coupon::where('status', 2)
|
||||
$lists = [
|
||||
'ysd10' => Coupon::where('status', 2)
|
||||
->whereDate('created_at', now()->format('Y-m-d'))
|
||||
->get();
|
||||
$lists = [
|
||||
'ysd10' => $coupons->where('thirdPartyGoodsId', 'YSD-full100-10')->count(),
|
||||
'ysd25' => $coupons->where('thirdPartyGoodsId', 'YSD-full100-25')->count(),
|
||||
'ysd50' => $coupons->where('thirdPartyGoodsId', 'YSD-full100-50')->count(),
|
||||
'ysd100' => $coupons->where('thirdPartyGoodsId', 'YSD-full200-100')->count(),
|
||||
->where('thirdPartyGoodsId', 'YSD-full100-10')
|
||||
->count(),
|
||||
'ysd25' => Coupon::where('status', 2)
|
||||
->whereDate('created_at', now()->format('Y-m-d'))
|
||||
->where('thirdPartyGoodsId', 'YSD-full100-25')
|
||||
->count(),
|
||||
'ysd50' => Coupon::where('status', 2)
|
||||
->whereDate('created_at', now()->format('Y-m-d'))
|
||||
->where('thirdPartyGoodsId', 'YSD-full100-50')
|
||||
->count(),
|
||||
'ysd100' => Coupon::where('status', 2)
|
||||
->whereDate('created_at', now()->format('Y-m-d'))
|
||||
->where('thirdPartyGoodsId', 'YSD-full200-100')
|
||||
->count(),
|
||||
];
|
||||
|
||||
$row->column(2, function (Column $column) use ($lists) {
|
||||
$column->append(new InfoBox('100元减10元成功今日总数', '', 'blue', '/admin/coupons', $lists['ysd10']));
|
||||
$column->append(new InfoBox(
|
||||
'100元减10元成功今日总数',
|
||||
'',
|
||||
'blue',
|
||||
'/admin/coupons',
|
||||
$lists['ysd10']
|
||||
));
|
||||
});
|
||||
|
||||
$row->column(2, function (Column $column) use ($lists) {
|
||||
$column->append(new InfoBox('100元减25元成功今日总数', '', 'blue', '/admin/coupons', $lists['ysd25']));
|
||||
$column->append(new InfoBox(
|
||||
'100元减25元成功今日总数',
|
||||
'',
|
||||
'blue',
|
||||
'/admin/coupons',
|
||||
$lists['ysd25']
|
||||
));
|
||||
});
|
||||
|
||||
$row->column(2, function (Column $column) use ($lists) {
|
||||
$column->append(new InfoBox('100元减50元成功今日总数', '', 'blue', '/admin/coupons', $lists['ysd50']));
|
||||
$column->append(new InfoBox(
|
||||
'100元减50元成功今日总数',
|
||||
'',
|
||||
'blue',
|
||||
'/admin/coupons',
|
||||
$lists['ysd50']
|
||||
));
|
||||
});
|
||||
|
||||
$row->column(2, function (Column $column) use ($lists) {
|
||||
$column->append(new InfoBox('200元减100元成功今日总数', '', 'blue', '/admin/coupons', $lists['ysd100']));
|
||||
$column->append(new InfoBox(
|
||||
'200元减100元成功今日总数',
|
||||
'',
|
||||
'blue',
|
||||
'/admin/coupons',
|
||||
$lists['ysd100']
|
||||
));
|
||||
});
|
||||
})
|
||||
->row(function (Row $row) {
|
||||
|
||||
$coupons = Coupon::where('status', 2)->get();
|
||||
$lists = [
|
||||
'ysd10' => $coupons->where('thirdPartyGoodsId', 'YSD-full100-10')->count(),
|
||||
'ysd25' => $coupons->where('thirdPartyGoodsId', 'YSD-full100-25')->count(),
|
||||
'ysd50' => $coupons->where('thirdPartyGoodsId', 'YSD-full100-50')->count(),
|
||||
'ysd100' => $coupons->where('thirdPartyGoodsId', 'YSD-full200-100')->count(),
|
||||
'ysd10' => Coupon::where('status', 2)->where('thirdPartyGoodsId', 'YSD-full100-10')->count(),
|
||||
'ysd25' => Coupon::where('status', 2)->where('thirdPartyGoodsId', 'YSD-full100-25')->count(),
|
||||
'ysd50' => Coupon::where('status', 2)->where('thirdPartyGoodsId', 'YSD-full100-50')->count(),
|
||||
'ysd100' => Coupon::where('status', 2)->where('thirdPartyGoodsId', 'YSD-full200-100')->count(),
|
||||
];
|
||||
|
||||
$row->column(2, function (Column $column) use ($lists) {
|
||||
$column->append(new InfoBox('100元减10元成功总数', '', 'blue', '/admin/coupons', $lists['ysd10']));
|
||||
$column->append(new InfoBox(
|
||||
'100元减10元成功总数',
|
||||
'',
|
||||
'blue',
|
||||
'/admin/coupons',
|
||||
$lists['ysd10']
|
||||
));
|
||||
});
|
||||
|
||||
$row->column(2, function (Column $column) use ($lists) {
|
||||
$column->append(new InfoBox('100元减25元成功总数', '', 'blue', '/admin/coupons', $lists['ysd25']));
|
||||
$column->append(new InfoBox(
|
||||
'100元减25元成功总数',
|
||||
'',
|
||||
'blue',
|
||||
'/admin/coupons',
|
||||
$lists['ysd25']
|
||||
));
|
||||
});
|
||||
|
||||
$row->column(2, function (Column $column) use ($lists) {
|
||||
$column->append(new InfoBox('100元减50元成功总数', '', 'blue', '/admin/coupons', $lists['ysd50']));
|
||||
$column->append(new InfoBox(
|
||||
'100元减50元成功总数',
|
||||
'',
|
||||
'blue',
|
||||
'/admin/coupons',
|
||||
$lists['ysd50']
|
||||
));
|
||||
});
|
||||
|
||||
$row->column(2, function (Column $column) use ($lists) {
|
||||
$column->append(new InfoBox('200元减100元成功总数', '', 'blue', '/admin/coupons', $lists['ysd100']));
|
||||
$column->append(new InfoBox(
|
||||
'200元减100元成功总数',
|
||||
'',
|
||||
'blue',
|
||||
'/admin/coupons',
|
||||
$lists['ysd100']
|
||||
));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace XuanChen\Coupon\Action\ysd;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use XuanChen\Coupon\Action\Init;
|
||||
|
||||
class YsdGrant extends Init
|
||||
@@ -13,7 +14,7 @@ class YsdGrant extends Init
|
||||
{
|
||||
try {
|
||||
|
||||
$activity = Activity::where('code', $this->activityId)->first();
|
||||
$activity = Activity::withCount('coupons')->where('code', $this->activityId)->first();
|
||||
if (!$activity) {
|
||||
return '发券失败,没有找到这个活动。';
|
||||
}
|
||||
@@ -22,6 +23,14 @@ class YsdGrant extends Init
|
||||
return '发券失败,活动已经关闭。';
|
||||
}
|
||||
|
||||
if ($activity->type == Activity::TYPE_SCOPE && Carbon::now()->gt($activity->end_at)) {
|
||||
return '发券失败,此活动已经结束。';
|
||||
}
|
||||
|
||||
if ($activity->total > 0 && $activity->coupons_count >= $activity->total) {
|
||||
return '发券失败,已达到可发券总数。';
|
||||
}
|
||||
|
||||
$outlet = User::where('outlet_id', $this->outletId)->first();
|
||||
if (!$outlet) {
|
||||
return '发券失败,未查询到此网点信息。';
|
||||
|
||||
Reference in New Issue
Block a user