From 2ff139ca1e790b426e52ab6703473a861326d2af Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Thu, 27 Jan 2022 14:08:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=8E=E5=8F=B0=E8=A1=A5?= =?UTF-8?q?=E8=B4=B4=E7=8A=B6=E6=80=81=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/DealerEarningController.php | 10 ++- .../Grid/Filter/DealerEarningStatusIn.php | 78 +++++++++++++++++++ 2 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 app/Admin/Renderable/Grid/Filter/DealerEarningStatusIn.php diff --git a/app/Admin/Controllers/DealerEarningController.php b/app/Admin/Controllers/DealerEarningController.php index 4a18c275..1e8a7b60 100644 --- a/app/Admin/Controllers/DealerEarningController.php +++ b/app/Admin/Controllers/DealerEarningController.php @@ -3,6 +3,7 @@ namespace App\Admin\Controllers; use App\Admin\Actions\Show\DealerEarningPay; +use App\Admin\Renderable\Grid\Filter\DealerEarningStatusIn; use App\Admin\Repositories\DealerEarning; use App\Enums\DealerEarningStatus; use App\Models\DealerChannelSubsidyLog; @@ -68,8 +69,13 @@ class DealerEarningController extends AdminController -1=> '待结算', 0 => '待打款', 1 => '待收款', - 2 => '已完成', - ])->dot(); + 5 => '已完成', + ])->dot()->filter(DealerEarningStatusIn::make([ + -1=> '待结算', + 0 => '待打款', + 1 => '待收款', + 5 => '已完成', + ])); $grid->column('settle_at'); $grid->column('payer_id')->display(function () { return $this->payer_id ? $this->payer?->phone : '公司'; diff --git a/app/Admin/Renderable/Grid/Filter/DealerEarningStatusIn.php b/app/Admin/Renderable/Grid/Filter/DealerEarningStatusIn.php new file mode 100644 index 00000000..e007fe78 --- /dev/null +++ b/app/Admin/Renderable/Grid/Filter/DealerEarningStatusIn.php @@ -0,0 +1,78 @@ +options = $options; + + $this->class = [ + 'all' => uniqid('column-filter-all-'), + 'item' => uniqid('column-filter-item-'), + ]; + } + + /** + * Add a binding to the query. + * + * @param array $value + * @param Model $model + */ + public function addBinding($value, Model $model) + { + if (empty($value)) { + return; + } + $all = [-1, 0, 1, 5]; + + if (array_diff($all, $value)) {//无差别则直接跳过 + //判断查询的状态有哪些; + $model->where(function ($query) use ($value) { + foreach ($value as $status) { + switch ($status) { + case -1: + $query->orWhereNull('settle_at'); + break; + case 0: + $query->orWhere('status', 0); + break; + case 1: + $query->orWhere('status', 1); + break; + case 5: + $query->orWhere('status', 5); + break; + } + } + }); + } + } + + /** + * Render this filter. + * + * @return string + */ + public function render() + { + return $this->renderCheckbox(); + } +}