322 lines
15 KiB
PHP
322 lines
15 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Actions\Show\DealerEarningPay;
|
|
use App\Admin\Renderable\Grid\Filter\DealerEarningStatusIn;
|
|
use App\Admin\Repositories\DealerEarning;
|
|
use App\Admin\Widgets\InfoBox;
|
|
use App\Enums\DealerEarningStatus;
|
|
use App\Enums\PayWay;
|
|
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()
|
|
{
|
|
Admin::style(
|
|
<<<CSS
|
|
.card-header {
|
|
margin-top: 1.5rem !important;
|
|
margin-bottom: -1rem !important;
|
|
}
|
|
CSS
|
|
);
|
|
|
|
$earning = DealerEarning::with(['user.userInfo', 'payer']);
|
|
|
|
return Grid::make($earning, function (Grid $grid) {
|
|
$grid->setResource('dealer-earnings');
|
|
$grid->model()->orderBy('id', 'desc'); //默认ID倒叙
|
|
|
|
$grid->column('id')->sortable();
|
|
$grid->column('user.phone');
|
|
$grid->column('user.userInfo.nickname', '昵称');
|
|
$grid->column('lvl')->display(function () {
|
|
return $this->lvl->text();
|
|
});
|
|
$grid->column('earningable_type', '资金类型')->display(function () {
|
|
return $this->earningable_type_text;
|
|
})->label([
|
|
(new DealerManageSubsidy())->getMorphClass() => 'primary',
|
|
(new DealerManagerSubsidy())->getMorphClass() => 'success',
|
|
(new DealerPurchaseSubsidy())->getMorphClass() => 'danger',
|
|
(new DealerChannelSubsidyLog())->getMorphClass() => 'warning',
|
|
])->filter(Grid\Column\Filter\In::make([
|
|
(new DealerManagerSubsidy())->getMorphClass() =>'管理者补贴',
|
|
(new DealerManageSubsidy())->getMorphClass() => '管理补贴',
|
|
(new DealerChannelSubsidyLog())->getMorphClass() => '渠道补贴',
|
|
(new DealerPurchaseSubsidy())->getMorphClass() => '进货补贴',
|
|
]));
|
|
$grid->column('total_amount')->prepend('¥');
|
|
$grid->column('fee_rate')->append('%');
|
|
$grid->column('fee')->prepend('¥');
|
|
$grid->column('total_earnings')->prepend('¥');
|
|
$grid->column('remark')->display('查看') // 设置按钮名称
|
|
->expand(function () {
|
|
$card = new Card(null, nl2br($this->remark));
|
|
|
|
return "<div style='padding:10px 10px 0'>$card</div>";
|
|
});
|
|
$grid->column('status', '状态')->display(function ($v) {
|
|
if (! $this->isSettled()) {
|
|
return "<i class='fa fa-circle' style='font-size: 13px;color: #b9c3cd'></i> 待结算";
|
|
}
|
|
|
|
return "<i class='fa fa-circle' style='font-size: 13px;color: {$v->color()}'></i> {$v->text()}";
|
|
})->filter(DealerEarningStatusIn::make([
|
|
-1 => '待结算',
|
|
0 => '待打款',
|
|
1 => '待收款',
|
|
5 => '已完成',
|
|
]));
|
|
$grid->column('settle_at');
|
|
$grid->column('payer_id')->display(function () {
|
|
return $this->payer_id ? $this->payer?->phone : '公司';
|
|
});
|
|
$grid->column('pay_way', '支付方式')->display(function ($v) {
|
|
return $v?->text();
|
|
})->circleDot(PayWay::colors());
|
|
$grid->column('pay_at');
|
|
$grid->column('created_at')->sortable();
|
|
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
|
$actions->append('<a style="cursor: pointer;" target="_blank" href="'.admin_route('dealer_earnings.show', ['dealer_earning'=>$actions->row]).'"><i class="feather icon-eye"></i> 显示 </a>');
|
|
});
|
|
|
|
$grid->header(function ($collection) use ($grid) {
|
|
return tap(new Row(), function ($row) use ($grid) {
|
|
$query = DealerEarningModel::query();
|
|
|
|
// 拿到表格筛选 where 条件数组进行遍历
|
|
$grid->model()->getQueries()->unique()->each(function ($value) use (&$query) {
|
|
if (in_array($value['method'], ['paginate', 'get', 'orderBy', 'orderByDesc'], true)) {
|
|
return;
|
|
}
|
|
|
|
$query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []);
|
|
});
|
|
|
|
// 查出统计数据
|
|
$totalAmount = (clone $query)->sum('total_amount');
|
|
|
|
$row->column(3, new InfoBox('金额', $totalAmount, 'fa fa-cny'));
|
|
$row->column(3, new InfoBox('手续费', (clone $query)->sum('fee'), 'fa fa-cny'));
|
|
});
|
|
});
|
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->panel();
|
|
$filter->equal('user.phone')->width(3);
|
|
$filter->between('settle_at')->dateTime()->width(6);
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 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.userInfo', 'payer']);
|
|
$column->row(Show::make($id, $builder, function (Show $show) {
|
|
$show->field('id');
|
|
$show->field('user.phone');
|
|
$show->field('user.user_info.nickname', '昵称');
|
|
$show->field('lvl')->as(function () {
|
|
return $this->lvl->text();
|
|
});
|
|
$show->field('earningable_type', '资金类型')->as(function () {
|
|
return $this->earningable_type_text;
|
|
})->label();
|
|
$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_way', '打款方式')->as(function () {
|
|
return $this->pay_way?->text();
|
|
})->circleDot(PayWay::colors());
|
|
$show->field('pay_at', '打款时间')->as(function () {
|
|
return $this->pay_at?->toDateTimeString();
|
|
});
|
|
$show->field('pay_image')->image();
|
|
$show->field('settle_at');
|
|
$show->field('remark')->unescape()->as(function () {
|
|
return nl2br($this->remark);
|
|
});
|
|
$show->field('status', '状态')->unescape()->as(function () {
|
|
if (! $this->isSettled()) {
|
|
return "<i class='fa fa-circle' style='font-size: 13px;color: #b9c3cd'></i> 待结算";
|
|
}
|
|
|
|
return "<i class='fa fa-circle' style='font-size: 13px;color: {$this->status->color()}'></i> {$this->status->text()}";
|
|
});
|
|
$show->field('created_at');
|
|
|
|
// 非(待结算)显示收款人信息
|
|
if ($show->model()->isSettled()) {
|
|
$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->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();
|
|
});
|
|
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');
|
|
});
|
|
}
|
|
}
|