6
0
Fork 0
jiqu-library-server/app/Admin/Controllers/DealerEarningController.php

273 lines
13 KiB
PHP

<?php
namespace App\Admin\Controllers;
use App\Admin\Actions\Show\DealerEarningPay;
use App\Admin\Repositories\DealerEarning;
use App\Enums\DealerEarningStatus;
use App\Models\DealerChannelSubsidyLog;
use App\Models\DealerEarning as DealerEarningModel;
use App\Models\DealerManagerSalesLog;
use App\Models\DealerManagerSubsidy;
use App\Models\DealerManageSubsidy;
use App\Models\DealerManageSubsidyLog;
use App\Models\DealerPurchaseSubsidy;
use App\Models\DealerPurchaseSubsidyLog;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Layout\Row;
use Dcat\Admin\Show;
use Dcat\Admin\Widgets\Box;
use Dcat\Admin\Widgets\Card;
class DealerEarningController extends AdminController
{
/**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
$earning = DealerEarning::with(['user', 'payer']);
return Grid::make($earning, function (Grid $grid) {
$grid->setResource('dealer-earnings');
$grid->column('id')->sortable();
$grid->column('user.phone');
$grid->column('type_name')->display(function () {
return $this->type_name;
})->label()->filter(Grid\Column\Filter\In::make([
(new DealerManagerSubsidy())->getMorphClass() =>'管理者补贴',
(new DealerManageSubsidy())->getMorphClass() =>'管理补贴',
(new DealerChannelSubsidyLog())->getMorphClass() =>'渠道补贴',
(new DealerPurchaseSubsidy())->getMorphClass() =>'进货补贴',
])->setColumnName('earningable_type'));
$grid->column('remark')->display('详情') // 设置按钮名称
->expand(function () {
// 这里返回 content 字段内容,并用 Card 包裹起来
$card = new Card(null, $this->remark);
return "<div style='padding:10px 10px 0;text-align: center'>$card</div>";
});
// $grid->column('earningable_type');
// $grid->column('earningable_id');
$grid->column('lvl')->display(function () {
return $this->lvl->text();
// return $this->lvl_text;
});
$grid->column('is_manager')->bool();
$grid->column('total_amount')->prepend('¥');
$grid->column('fee_rate')->append('%');
$grid->column('fee')->prepend('¥');
$grid->column('total_earnings')->prepend('¥');
$grid->column('status_format')->display(function ($value) {
return $this->status_format;
})->using([
-1=> '待结算',
0 => '待打款',
1 => '待收款',
2 => '已完成',
])->dot();
$grid->column('settle_at');
$grid->column('payer_id')->display(function () {
return $this->payer_id ? $this->payer?->phone : '公司';
});
// $grid->column('pay_info');
$grid->column('pay_at');
// $grid->column('pay_image');
$grid->column('created_at')->sortable();
$grid->actions(function (Grid\Displayers\Actions $actions) {
//如果不是渠道补贴添加详情显示
// if ($actions->row->earningable_type != (new DealerChannelSubsidyLog())->getMorphClass()) {
$actions->append('<a style="cursor: pointer;" target="_blank" href="'.admin_route('dealer_earnings.show', ['dealer_earning'=>$actions->row]).'"><i class="feather icon-eye"></i> 显示 &nbsp;&nbsp;</a>');
// }
});
$grid->filter(function (Grid\Filter $filter) {
$filter->panel();
$filter->equal('user.phone')->width(3);
});
});
}
/**
* Make a show builder.
*
* @param mixed $id
*
* @return Show
*/
protected function detail($id)
{
return function (Row $row) use ($id) {
$row->column(5, function ($column) use ($id) {
$builder = DealerEarning::with(['user', 'payer']);
$column->row(Show::make($id, $builder, function (Show $show) {
$show->field('id');
$show->field('user.phone');
// $show->field('earningable_type');
// $show->field('earningable_id');
$show->field('lvl')->as(function () {
return $this->lvl->text();
});
$show->field('is_manager')->as(function ($val) {
return $val ? '是' : '否';
});
$show->field('total_amount')->prepend('¥');
$show->field('fee_rate')->append('%');
$show->field('fee')->prepend('¥');
$show->field('total_earnings')->prepend('¥');
$show->field('payer.phone', '打款人')->as(function () {
return $this->payer_id ? $this->payer?->phone : '公司';
});
$show->field('pay_image')->image();
// $show->field('pay_info');
$show->field('pay_at');
$show->field('settle_at');
// $show->field('status');
$show->field('remark');
//非(待结算)显示收款人信息
if ($show->model()->settle_at) {
$show->divider('收款信息-银行');
$show->field('bank_user_name', '银行-收款人')->as(function () {
$payInfo = $this->getPayInfo();
return $payInfo['bank']['user_name']??'';
});
$show->field('bank_bank_name', '银行-名称')->as(function () {
$payInfo = $this->getPayInfo();
return $payInfo['bank']['bank_name']??'';
});
$show->field('bank_bank_number', '银行-卡号')->as(function () {
$payInfo = $this->getPayInfo();
return $payInfo['bank']['bank_number']??'';
});
$show->field('bank_bank_description', '银行-开户行')->as(function () {
$payInfo = $this->getPayInfo();
return $payInfo['bank']['bank_description']??'';
});
$show->divider('收款信息-支付宝');
$show->field('alipay_user_name', '支付宝-真实名称')->as(function () {
$payInfo = $this->getPayInfo();
return $payInfo['alipay']['user_name']??'';
});
$show->field('alipay_ali_name', '支付宝-账户')->as(function () {
$payInfo = $this->getPayInfo();
return $payInfo['alipay']['ali_name']??'';
});
$show->field('alipay_image', '支付宝-收款码')->as(function () {
$payInfo = $this->getPayInfo();
return $payInfo['alipay']['image']??'';
})->image();
$show->divider('收款信息-微信');
$show->field('wechat_user_name', '微信-真实名称')->as(function () {
$payInfo = $this->getPayInfo();
return $payInfo['wechat']['user_name']??'';
});
$show->field('wechat_wechat_name', '微信-ID')->as(function () {
$payInfo = $this->getPayInfo();
return $payInfo['wechat']['wechat_name']??'';
});
$show->field('wechat_image', '微信-收款码')->as(function () {
$payInfo = $this->getPayInfo();
return $payInfo['wechat']['image']??'';
})->image();
}
$show->field('created_at');
// $show->field('updated_at');
$show->panel()
->tools(function (Show\Tools $tools) use ($show) {
$tools->disableEdit();
$tools->disableDelete();
if ($show->model()->status == DealerEarningStatus::Pending && Admin::user()->can('dcat.admin.dealer_earnings.pay')) {
if (!$show->model()->payer_id || $show->model()->payer_id == 1) {
$tools->append(new DealerEarningPay());
}
}
});
}));
});
$row->column(7, function ($column) use ($id) {
$earning = DealerEarningModel::with('earningable')->findOrFail($id);
$grid = '暂无记录';
switch (get_class($earning->earningable)) {
case DealerManagerSubsidy::class://管理者补贴
$builder = DealerManagerSalesLog::with(['order', 'product'])->where('user_id', $earning->earningable->user_id)->whereBetween('order_completed_at', [$earning->earningable->start_at, $earning->earningable->end_at]);
$grid = Grid::make($builder, function (Grid $grid) {
$grid->column('id');
$grid->column('order.sn', '订单编号');
$grid->column('product.name', '商品名称');
$grid->column('sales_volume', '销量');
$grid->column('order_completed_at', '结算时间');
$grid->disableCreateButton();
$grid->disableActions();
$grid->disablePagination();
});
break;
break;
case DealerManageSubsidy::class://管理补贴
$builder = DealerManageSubsidyLog::with(['order', 'product'])->where('user_id', $earning->earningable->user_id)->whereBetween('order_completed_at', [$earning->earningable->start_at, $earning->earningable->end_at]);
$grid = Grid::make($builder, function (Grid $grid) {
$grid->column('id');
$grid->column('order.sn', '订单编号');
$grid->column('product.name', '商品名称');
$grid->column('sales_volume', '销量');
$grid->column('total_amount', '金额');
$grid->column('order_completed_at', '结算时间');
$grid->disableCreateButton();
$grid->disableActions();
// $grid->disablePagination();
});
break;
case DealerPurchaseSubsidy::class://进货补贴
$builder = DealerPurchaseSubsidyLog::where('purchase_subsidy_id', $earning->earningable_id);
$grid = Grid::make($builder, function (Grid $grid) {
$grid->column('id');
$grid->column('change_amount', '变更金额');
$grid->column('remark', '备注');
$grid->column('created_at', '结算时间');
$grid->disableCreateButton();
$grid->disableActions();
$grid->disablePagination();
});
break;
}
$column->row(Box::make('明细记录', $grid));
});
};
}
/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
return Form::make(new DealerEarning(), function (Form $form) {
$form->display('id');
$form->text('user_id');
$form->text('earningable_type');
$form->text('earningable_id');
$form->text('lvl');
$form->text('is_manager');
$form->text('total_amount');
$form->text('total_earnings');
$form->text('fee');
$form->text('fee_rate');
$form->text('payer_id');
$form->text('pay_info');
$form->text('pay_at');
$form->text('settle_at');
$form->text('status');
$form->text('remark');
$form->text('pay_image');
$form->display('created_at');
$form->display('updated_at');
});
}
}