first commit
This commit is contained in:
194
app/Admin/Controllers/Coupon/IndexController.php
Normal file
194
app/Admin/Controllers/Coupon/IndexController.php
Normal file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers\Coupon;
|
||||
|
||||
use App\Admin\Exporters\CouponExport;
|
||||
use App\Models\Coupon;
|
||||
use App\Models\User;
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Grid;
|
||||
|
||||
class IndexController extends AdminController
|
||||
{
|
||||
|
||||
protected $title = '卡券列表';
|
||||
|
||||
/**
|
||||
* Notes:
|
||||
* @Author: <C.Jason>
|
||||
* @Date : 2019/9/18 14:50
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
{
|
||||
$grid = new Grid(new Coupon);
|
||||
$grid->disableCreateButton();
|
||||
$grid->disableBatchActions();
|
||||
$grid->disableActions();
|
||||
|
||||
$grid->model()->whereIn('status', [2, 3])->orderBy('id', 'desc');
|
||||
|
||||
$grid->filter(function ($filter) {
|
||||
$filter->column(1 / 2, function ($filter) {
|
||||
$filter->equal('status', '状态')->select([
|
||||
'2' => '核销成功',
|
||||
'3' => '核销失败',
|
||||
]);
|
||||
$filter->between('created_at', '核销时间')->datetime();
|
||||
$users = User::query()
|
||||
->whereHas('identity', function ($query) {
|
||||
$query->where('identity_id', 1);
|
||||
})
|
||||
->where('type', 'pingan')
|
||||
->get()
|
||||
->pluck('nickname', 'id');
|
||||
$filter->equal('user_id', '渠道')->select($users);
|
||||
$filter->equal('thirdPartyGoodsId', '优惠政策')->select([
|
||||
'YSD-full100-10' => '100减10元',
|
||||
'YSD-full100-25' => '100减25元',
|
||||
'YSD-full100-50' => '100减50元',
|
||||
'YSD-full200-100' => '200减100元',
|
||||
]);
|
||||
});
|
||||
$filter->column(1 / 2, function ($filter) {
|
||||
$filter->like('redemptionCode', '平安券编号');
|
||||
$filter->where(function ($query) {
|
||||
$query->whereHas('outlet', function ($query) {
|
||||
$query->whereHas('info', function ($query) {
|
||||
$query->where('nickname', 'like', "%{$this->input}%");
|
||||
});
|
||||
});
|
||||
}, '网点名称');
|
||||
});
|
||||
});
|
||||
|
||||
$grid->column('id', '#ID#');
|
||||
$grid->column('渠道')->display(function () {
|
||||
return $this->user->nickname;
|
||||
});
|
||||
|
||||
$grid->column('网点名称/编号')->display(function () {
|
||||
return $this->outlet ? $this->outlet->nickname : $this->outletId;
|
||||
});
|
||||
|
||||
$grid->column('redemptionCode', '平安券编号');
|
||||
$grid->column('couponName', '优惠政策');
|
||||
$grid->column('price', '核销金额');
|
||||
$grid->column('资金通道结算')->display(function () {
|
||||
$profit = $this->status == 2 ? $this->profit : '0.00';
|
||||
|
||||
return '<span style="color:red">' . $profit . '</span>';
|
||||
});
|
||||
$grid->column('状态')->display(function () {
|
||||
switch ($this->status) {
|
||||
case 2:
|
||||
return '<span style="color:green">' . $this->status_text . '</span>';
|
||||
break;
|
||||
case 3:
|
||||
return '<span style="color:red">' . $this->status_text . '</span>';
|
||||
break;
|
||||
default:
|
||||
return $this->status_text;
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
$grid->column('remark', '处理结果');
|
||||
$grid->column('startTime', '起始时间');
|
||||
$grid->column('endTime', '到期时间');
|
||||
$grid->column('created_at', '核销时间');
|
||||
$grid->column('省')->display(function () {
|
||||
return ($this->outlet && $this->outlet->province) ? $this->outlet->province->name : '';
|
||||
});
|
||||
|
||||
$grid->column('市')->display(function () {
|
||||
return ($this->outlet && $this->outlet->province) ? $this->outlet->city->name : '';
|
||||
});
|
||||
|
||||
$grid->column('区')->display(function () {
|
||||
return ($this->outlet && $this->outlet->province) ? $this->outlet->district->name : '';
|
||||
});
|
||||
|
||||
$grid->footer(function ($query) {
|
||||
$all = $query->get();
|
||||
$pass = $all->where('status', 2)->all();
|
||||
$pass = collect($pass);
|
||||
|
||||
return '<label class="label label-success">全部:' . $all->count() . '张</label> '
|
||||
. '<label class="label label-success">成功:' . $pass->count() . '张</label> '
|
||||
. '<label class="label label-success">失败:' . $all->where('status', 3)
|
||||
->count() . '张</label> '
|
||||
. '<label class="label label-success">核销金额:' . $pass->sum('price') . '元</label> '
|
||||
. '<label class="label label-success">资金通道结算:' . $pass->sum('profit') . '元</label> '
|
||||
. '<label class="label label-success">打款金额:' . $pass->where('is_profit', 1)
|
||||
->sum('profit') . '元</label> ';
|
||||
});
|
||||
$grid->disableExport(false);
|
||||
|
||||
$grid->export(function ($export) {
|
||||
$export->column('状态', function ($value, $original) {
|
||||
return strip_tags($value);
|
||||
});
|
||||
$export->column('redemptionCode', function ($value, $original) {
|
||||
return $value . "\t";
|
||||
});
|
||||
$export->column('price', function ($value, $original) {
|
||||
return $value . "\t";
|
||||
});
|
||||
$export->column('资金通道结算', function ($value, $original) {
|
||||
return strip_tags($value) . "\t";
|
||||
});
|
||||
$export->filename('卡券列表' . date("YmdHis"));
|
||||
});
|
||||
|
||||
return $grid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
$form = new Form(new Gift);
|
||||
|
||||
$form->text('title', '商品名称')->required();
|
||||
$form->decimal('price', '价格')->required()->default('1');
|
||||
$form->decimal('pv', 'PV')->required()->default(0);
|
||||
$form->decimal('bonus', '主播佣金')->required()->default(0);
|
||||
$form->decimal('recommend', '推荐人佣金')->required()->default(0);
|
||||
$form->number('hots', '热度/亲密度')->required()->default('1');
|
||||
$form->text('times', '显示时间')
|
||||
->default('200')
|
||||
->required()
|
||||
->help('礼物显示时间,毫秒');
|
||||
|
||||
$form->textarea('description', '礼物说明');
|
||||
|
||||
$form->image('cover', '封面')
|
||||
->rules(function ($form) {
|
||||
if ($form->model()->cover != '') {
|
||||
return 'nullable|image';
|
||||
} else {
|
||||
return 'required';
|
||||
}
|
||||
})
|
||||
->move('images/' . date('Y/m/d'))
|
||||
->removable()
|
||||
->uniqueName();
|
||||
|
||||
$form->switch('status', '状态')->default(1);
|
||||
$form->decimal('sort', '排序')->default(0)->help('序号越大越靠前');
|
||||
|
||||
$form->saving(function ($form) {
|
||||
$sum = (int)$form->pv + (int)$form->bonus + (int)$form->recommend;
|
||||
if ((int)$sum > $form->price) {
|
||||
admin_warning('配置错误', 'PV+佣金+推荐人佣金不能超过礼物价值');
|
||||
throw new \Exception('配置错误,PV+佣金+推荐人佣金不能超过礼物价值');
|
||||
}
|
||||
});
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user