118 lines
4.0 KiB
PHP
118 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Actions\ProfitStart;
|
|
use App\Models\Profit;
|
|
use Encore\Admin\Controllers\AdminController;
|
|
use Encore\Admin\Form;
|
|
use Encore\Admin\Grid;
|
|
use Encore\Admin\Widgets\Table;
|
|
use RuLong\Identity\Models\Identity;
|
|
|
|
class ProfitController extends AdminController
|
|
{
|
|
protected $title = '大盘分红管理';
|
|
|
|
protected function grid()
|
|
{
|
|
$grid = new Grid(new Profit);
|
|
$grid->disableFilter();
|
|
$grid->disableExport();
|
|
$grid->disableRowSelector();
|
|
$grid->tools(function ($tools) {
|
|
$tools->batch(function ($batch) {
|
|
$batch->disableDelete();
|
|
});
|
|
});
|
|
|
|
$grid->actions(function ($actions) {
|
|
$actions->disableDelete();
|
|
$actions->disableView();
|
|
if ($this->row->sett === 0) {
|
|
$actions->add(new ProfitStart);
|
|
}
|
|
});
|
|
$grid->fixColumns(0, 0);
|
|
|
|
$grid->model()->orderBy('id', 'asc');
|
|
$grid->column('id', '序号')->sortable();
|
|
$grid->column('分配级别')->display(function () {
|
|
return $this->identity->title ?? '';
|
|
});
|
|
$grid->column('price', '分配额度');
|
|
$grid->column('num', '分配人数');
|
|
$grid->column('single', '单人分红金额');
|
|
$grid->column('realPrice', '实发总金额');
|
|
$grid->column('sett', '是否结算')->using([
|
|
0 => '否',
|
|
1 => '是',
|
|
])->label([
|
|
0 => 'warning',
|
|
1 => 'success',
|
|
]);
|
|
$grid->column('created_at', '添加时间');
|
|
$grid->column('updated_at', '修改时间');
|
|
$grid->column('setted_at', '结算时间');
|
|
$grid->column('分红记录')->display(function () {
|
|
return '点击查看详情';
|
|
})->modal('分红记录', function ($model) {
|
|
$comments = $model->logs->map(function ($comment) {
|
|
return [
|
|
$comment->profit->id,
|
|
$comment->profit->price,
|
|
$comment->user_id,
|
|
$comment->user->username ?? '---',
|
|
$comment->user->info->nickname ?? '---',
|
|
$comment->price,
|
|
$comment->created_at->format('Y-m-d H:i:s'),
|
|
];
|
|
});
|
|
return new Table(['分红ID', '分红总金额', '用户ID', '用户账号', '用户昵称', '分红金额', '产生时间'], $comments->toArray());
|
|
});
|
|
return $grid;
|
|
}
|
|
|
|
protected function form()
|
|
{
|
|
$form = new Form(new Profit);
|
|
$form->display('id', 'ID');
|
|
|
|
$form->tools(function (Form\Tools $tools) {
|
|
$tools->disableDelete();
|
|
$tools->disableView();
|
|
});
|
|
|
|
$identitys = Identity::orderBy('id', 'desc')->pluck('title', 'id')->toArray();
|
|
$form->select('identity_id', '分红身份')->options($identitys)->required();
|
|
$form->currency('price', '分红总额度')->symbol('¥')->rules('required|min:0')->required();
|
|
$states = [
|
|
'on' => ['value' => 1, 'text' => '是', 'color' => 'success'],
|
|
'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
|
|
];
|
|
|
|
$form->switch('sett', '是否立即结算')->states($states)->default('off');
|
|
$form->footer(function ($footer) {
|
|
$footer->disableReset();
|
|
$footer->disableViewCheck();
|
|
$footer->disableCreatingCheck();
|
|
});
|
|
$form->saved(function (Form $form) {
|
|
$log = $form->model();
|
|
if (!empty($log->setted_at) && $log->sett == 0) {
|
|
$log->sett = 1;
|
|
$log->save();
|
|
}
|
|
if ($log->sett == 1 && empty($log->setted_at)) {
|
|
//默认结算,并且结算时间为空,开始结算
|
|
$log->sett = 0;
|
|
$log->save();
|
|
\App\Bonus\ProfitStart::settlement($log);
|
|
}
|
|
|
|
});
|
|
return $form;
|
|
}
|
|
|
|
}
|