添加用户金额筛选
parent
ebdef1f23e
commit
5a741ddebd
|
|
@ -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.= " <span class='label' style='background:#b3b9bf'>冻结</span>";
|
||||
}
|
||||
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.= " <span class='label' style='background:#b3b9bf'>冻结</span>";
|
||||
}
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,204 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Renderable\Grid\Filter;
|
||||
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Grid\Column\Filter;
|
||||
use Dcat\Admin\Grid\Model;
|
||||
|
||||
class PriceBetween extends Filter
|
||||
{
|
||||
protected $dateFormat = null;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $timestamp = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->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(<<<JS
|
||||
$('.{$this->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
|
||||
<span class="dropdown">
|
||||
<form action="{$this->formAction()}" pjax-container style="display: inline-block;">
|
||||
<a href="javascript:void(0);" class="{$active}" data-toggle="dropdown">
|
||||
<i class="feather icon-filter"></i>
|
||||
</a>
|
||||
<ul class="dropdown-menu" role="menu" style="min-width: 180px;padding: 10px;left: -70px;border-radius: 0;font-weight:normal;background:#fff">
|
||||
<li class="dropdown-item">
|
||||
<input type="text"
|
||||
class="form-control input-sm {$this->class['start']}"
|
||||
name="{$this->getQueryName()}[start]"
|
||||
placeholder="{$this->trans('between_start')}"
|
||||
value="{$value['start']}"
|
||||
autocomplete="off" />
|
||||
</li>
|
||||
<li style="margin: 5px;"></li>
|
||||
<li class="dropdown-item">
|
||||
<input type="text"
|
||||
class="form-control input-sm {$this->class['end']}"
|
||||
name="{$this->getQueryName()}[end]"
|
||||
placeholder="{$this->trans('between_end')}"
|
||||
value="{$value['end']}"
|
||||
autocomplete="off"/>
|
||||
</li>
|
||||
{$this->renderFormButtons()}
|
||||
</ul>
|
||||
</form>
|
||||
</span>
|
||||
EOT;
|
||||
}
|
||||
|
||||
protected function requireAssets()
|
||||
{
|
||||
Admin::requireAssets(['moment', 'bootstrap-datetimepicker']);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue