From 5a741ddebdf7c87c62614061413e3c359aee25ca Mon Sep 17 00:00:00 2001
From: vine_liutk <961510893@qq.com>
Date: Fri, 31 Dec 2021 17:36:58 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E9=87=91?=
=?UTF-8?q?=E9=A2=9D=E7=AD=9B=E9=80=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Admin/Controllers/UserController.php | 23 +-
.../Renderable/Grid/Filter/PriceBetween.php | 204 ++++++++++++++++++
2 files changed, 222 insertions(+), 5 deletions(-)
create mode 100644 app/Admin/Renderable/Grid/Filter/PriceBetween.php
diff --git a/app/Admin/Controllers/UserController.php b/app/Admin/Controllers/UserController.php
index 9e55415f..5dc9c21a 100644
--- a/app/Admin/Controllers/UserController.php
+++ b/app/Admin/Controllers/UserController.php
@@ -10,6 +10,7 @@ use App\Admin\Actions\Show\UserEditBank;
use App\Admin\Actions\Show\UserEditPhone;
use App\Admin\Actions\Show\UserEnableBonus;
use App\Admin\Renderable\DistributionPreIncomeSimpleTable;
+use App\Admin\Renderable\Grid\Filter\PriceBetween;
use App\Admin\Renderable\UserBalanceLogSimpleTable;
use App\Admin\Renderable\UserFansSimpleTable;
use App\Admin\Renderable\UserWalletLogSimpleTable;
@@ -45,23 +46,30 @@ class UserController extends AdminController
})->label();
$grid->column('userInfo.inviterInfo.user.phone')->copyable();
- $grid->column('userInfo.growth_value');
- $grid->column('userInfo.group_sales_value');
-
+ $grid->column('userInfo.growth_value')->filter(
+ Grid\Column\Filter\Between::make()
+ );
+ $grid->column('userInfo.group_sales_value')->filter(
+ Grid\Column\Filter\Between::make()
+ );
$grid->column('wallet.balance')->display(function ($value) {
$value = bcdiv($value, 100, 2);
if ($this->wallet?->is_frozen) {
$value.= " 冻结";
}
return $value;
- })->prepend('¥');
+ })->prepend('¥')->filter(
+ PriceBetween::make()
+ );
$grid->column('balance.balance')->display(function ($value) {
$value = bcdiv($value, 100, 2);
if ($this->balance?->is_frozen) {
$value.= " 冻结";
}
return $value;
- })->prepend('¥');
+ })->prepend('¥')->filter(
+ PriceBetween::make()
+ );
$grid->column('created_at')->sortable();
$grid->column('register_ip');
@@ -105,6 +113,11 @@ class UserController extends AdminController
$filter->like('phone')->width(3);
$filter->equal('userInfo.agent_level')->select(UserInfo::$agentLevelTexts)->width(3);
$filter->between('created_at')->dateTime()->width(7);
+ // $filter->between('userInfo.growth_value')->width(6);
+ // $filter->between('userInfo.group_sales_value')->width(6);
+ // $filter->between('wallet.balance')->width(6);
+ // $filter->between('balance.balance')->width(6);
+
// $filter->equal('id');
});
});
diff --git a/app/Admin/Renderable/Grid/Filter/PriceBetween.php b/app/Admin/Renderable/Grid/Filter/PriceBetween.php
new file mode 100644
index 00000000..fe5d45a0
--- /dev/null
+++ b/app/Admin/Renderable/Grid/Filter/PriceBetween.php
@@ -0,0 +1,204 @@
+class = [
+ 'start' => uniqid('column-filter-start-'),
+ 'end' => uniqid('column-filter-end-'),
+ ];
+ }
+
+ /**
+ * Convert the datetime into unix timestamp.
+ *
+ * @return $this
+ */
+ public function toTimestamp()
+ {
+ $this->timestamp = true;
+
+ return $this;
+ }
+
+ /**
+ * Date filter.
+ *
+ * @return $this
+ */
+ public function date()
+ {
+ return $this->setDateFormat('YYYY-MM-DD');
+ }
+
+ /**
+ * Time filter.
+ *
+ * @return $this
+ */
+ public function time()
+ {
+ return $this->setDateFormat('HH:mm:ss');
+ }
+
+ /**
+ * Datetime filter.
+ *
+ * @return $this
+ */
+ public function datetime()
+ {
+ return $this->setDateFormat('YYYY-MM-DD HH:mm:ss');
+ }
+
+ /**
+ * @param string $format
+ * @return $this
+ */
+ protected function setDateFormat($format)
+ {
+ $this->dateFormat = $format;
+
+ $this->requireAssets();
+
+ return $this;
+ }
+
+ /**
+ * Add a binding to the query.
+ *
+ * @param mixed $value
+ * @param Model $model
+ */
+ public function addBinding($value, Model $model)
+ {
+ $value = array_filter((array) $value);
+
+ if (empty($value)) {
+ return;
+ }
+
+ if ($this->timestamp) {
+ $value = array_map(function ($v) {
+ if ($v) {
+ return strtotime($v);
+ }
+ }, $value);
+ }
+
+ if (! isset($value['start'])) {
+ $this->withQuery($model, 'where', ['<=', $value['end']*100]);
+
+ return;
+ }
+
+ if (! isset($value['end'])) {
+ $this->withQuery($model, 'where', ['>=', $value['start']*100]);
+
+ return;
+ }
+
+ $this->withQuery($model, 'whereBetween', [array_values($value)]);
+ }
+
+ protected function addScript()
+ {
+ if (! $this->dateFormat) {
+ return;
+ }
+
+ $options = [
+ 'locale' => config('app.locale'),
+ 'allowInputToggle' => true,
+ 'format' => $this->dateFormat,
+ ];
+
+ $options = json_encode($options);
+
+ Admin::script(<<class['start']}').datetimepicker($options);
+ $('.{$this->class['end']}').datetimepicker($options);
+JS
+ );
+// $('.{$this->class['start']}').on("dp.change", function (e) {
+// $('.{$this->class['end']}').data("DateTimePicker").minDate(e.date);
+// });
+// $('.{$this->class['end']}').on("dp.change", function (e) {
+// $('.{$this->class['start']}').data("DateTimePicker").maxDate(e.date);
+// });
+ }
+
+ /**
+ * Render this filter.
+ *
+ * @return string
+ */
+ public function render()
+ {
+ if (! $this->shouldDisplay()) {
+ return;
+ }
+
+ $script = <<<'JS'
+$('.dropdown-menu input').on('click', function(e) {
+ e.stopPropagation();
+});
+JS;
+
+ Admin::script($script);
+
+ $this->addScript();
+
+ $value = $this->value(['start' => '', 'end' => '']);
+ $active = empty(array_filter($value)) ? '' : 'active';
+
+ return <<
+
+
+EOT;
+ }
+
+ protected function requireAssets()
+ {
+ Admin::requireAssets(['moment', 'bootstrap-datetimepicker']);
+ }
+}