| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- <?php
- namespace App\Module\UrsPromotion\AdminControllers;
- use UCore\DcatAdmin\AdminController;
- use App\Module\UrsPromotion\Models\UrsProfit;
- use App\Module\UrsPromotion\Repositorys\UrsProfitRepository;
- use App\Module\UrsPromotion\AdminControllers\Helper\UrsProfitGridHelper;
- use App\Module\UrsPromotion\AdminControllers\Helper\UrsProfitShowHelper;
- use App\Module\UrsPromotion\AdminControllers\Helper\UrsProfitFormHelper;
- use App\Module\UrsPromotion\AdminControllers\Helper\UrsProfitFilterHelper;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use Dcat\Admin\Form;
- /**
- * URS团队收益记录管理控制器
- *
- * @route /admin/urs-promotion/profits
- */
- class UrsProfitController extends AdminController
- {
- /**
- * 页面标题
- */
- protected $title = 'URS团队收益记录';
- /**
- * 模型类
- */
- protected $model = UrsProfit::class;
- /**
- * 仓库类
- */
- protected $repository = UrsProfitRepository::class;
- /**
- * 列表页面
- */
- protected function grid(): Grid
- {
- return UrsProfitGridHelper::make($this->repository(), function (Grid $grid) {
- $grid->column('id', 'ID')->sortable();
- $grid->column('user_id', '获得收益用户')->sortable();
- $grid->column('promotion_member_id', '产生收益用户')->sortable();
- $grid->column('source_type', '收益来源类型');
- $grid->column('source_id', '收益来源ID');
- $grid->column('profit_type', '收益类型')->using([
- 'promotion_reward' => '推广收益',
- 'planting_reward' => '种植收益',
- ])->label([
- 'promotion_reward' => 'primary',
- 'planting_reward' => 'success',
- ]);
- $grid->column('relation_level', '推荐层级')->using([
- 1 => '直推',
- 2 => '间推',
- 3 => '三推',
- ])->label([
- 1 => 'success',
- 2 => 'info',
- 3 => 'warning',
- ]);
- $grid->column('original_amount', '原始金额')->display(function ($value) {
- return number_format($value, 4);
- });
- $grid->column('profit_amount', '分成金额')->display(function ($value) {
- return number_format($value, 4);
- });
- $grid->column('profit_rate', '分成比例')->display(function ($value) {
- return ($value * 100) . '%';
- });
- $grid->column('talent_level', '达人等级')->using([
- 0 => '非达人',
- 1 => '初级达人',
- 2 => '中级达人',
- 3 => '高级达人',
- 4 => '资深达人',
- 5 => '顶级达人',
- ]);
- $grid->column('status', '状态')->using([
- UrsProfit::STATUS_CANCELLED => '取消',
- UrsProfit::STATUS_NORMAL => '正常',
- ])->label([
- UrsProfit::STATUS_CANCELLED => 'danger',
- UrsProfit::STATUS_NORMAL => 'success',
- ]);
- $grid->column('created_at', '创建时间')->sortable();
- // 禁用创建和编辑(收益记录由系统自动生成)
- $grid->disableCreateButton();
- $grid->actions(function (Grid\Displayers\Actions $actions) {
- $actions->disableEdit();
- $actions->disableDelete();
- });
- // 添加统计信息
- $grid->tools(function (Grid\Tools $tools) {
- $tools->append($this->renderStats());
- });
- $grid->filter(function (Grid\Filter $filter) {
- UrsProfitFilterHelper::make($filter);
- });
- });
- }
- /**
- * 详情页面
- */
- protected function detail($id): Show
- {
- return UrsProfitShowHelper::make($this->repository(), $id, function (Show $show) {
- $show->field('id', 'ID');
- $show->field('user_id', '获得收益用户');
- $show->field('promotion_member_id', '产生收益用户');
- $show->field('source_type', '收益来源类型');
- $show->field('source_id', '收益来源ID');
- $show->field('profit_type', '收益类型')->using([
- 'promotion_reward' => '推广收益',
- 'planting_reward' => '种植收益',
- ]);
- $show->field('relation_level', '推荐层级')->using([
- 1 => '直推',
- 2 => '间推',
- 3 => '三推',
- ]);
- $show->field('original_amount', '原始金额');
- $show->field('profit_amount', '分成金额');
- $show->field('profit_rate', '分成比例')->as(function ($value) {
- return ($value * 100) . '%';
- });
- $show->field('talent_level', '达人等级')->using([
- 0 => '非达人',
- 1 => '初级达人',
- 2 => '中级达人',
- 3 => '高级达人',
- 4 => '资深达人',
- 5 => '顶级达人',
- ]);
- $show->field('status', '状态')->using([
- UrsProfit::STATUS_CANCELLED => '取消',
- UrsProfit::STATUS_NORMAL => '正常',
- ]);
- $show->field('created_at', '创建时间');
- $show->field('updated_at', '更新时间');
- });
- }
- /**
- * 表单页面(禁用)
- */
- protected function form(): Form
- {
- return UrsProfitFormHelper::make($this->repository(), function (Form $form) {
- // 收益记录由系统自动生成,不提供手动创建表单
- $form->display('message', '提示')->default('收益记录由系统自动生成,不支持手动添加或编辑');
- });
- }
- /**
- * 渲染统计信息
- */
- private function renderStats(): string
- {
- $totalCount = UrsProfit::where('status', UrsProfit::STATUS_NORMAL)->count();
- $totalAmount = UrsProfit::where('status', UrsProfit::STATUS_NORMAL)->sum('profit_amount');
-
- $promotionCount = UrsProfit::where('status', UrsProfit::STATUS_NORMAL)
- ->where('profit_type', 'promotion_reward')->count();
- $promotionAmount = UrsProfit::where('status', UrsProfit::STATUS_NORMAL)
- ->where('profit_type', 'promotion_reward')->sum('profit_amount');
-
- $plantingCount = UrsProfit::where('status', UrsProfit::STATUS_NORMAL)
- ->where('profit_type', 'planting_reward')->count();
- $plantingAmount = UrsProfit::where('status', UrsProfit::STATUS_NORMAL)
- ->where('profit_type', 'planting_reward')->sum('profit_amount');
- return '
- <div class="row mb-3">
- <div class="col-md-3">
- <div class="card">
- <div class="card-body text-center">
- <h5 class="card-title">总收益记录</h5>
- <p class="card-text">' . $totalCount . ' 条</p>
- <small class="text-muted">总金额: ' . number_format($totalAmount, 4) . '</small>
- </div>
- </div>
- </div>
- <div class="col-md-3">
- <div class="card">
- <div class="card-body text-center">
- <h5 class="card-title">推广收益</h5>
- <p class="card-text">' . $promotionCount . ' 条</p>
- <small class="text-muted">金额: ' . number_format($promotionAmount, 4) . '</small>
- </div>
- </div>
- </div>
- <div class="col-md-3">
- <div class="card">
- <div class="card-body text-center">
- <h5 class="card-title">种植收益</h5>
- <p class="card-text">' . $plantingCount . ' 条</p>
- <small class="text-muted">金额: ' . number_format($plantingAmount, 4) . '</small>
- </div>
- </div>
- </div>
- </div>';
- }
- }
|