order-profit filter
parent
20532caea4
commit
75d4942e9d
|
|
@ -10,6 +10,7 @@ use Dcat\Admin\Http\Controllers\AdminController;
|
||||||
use App\Admin\Extensions\Grid\Tools\ProfitBatchSuccess;
|
use App\Admin\Extensions\Grid\Tools\ProfitBatchSuccess;
|
||||||
use App\Enums\PayWay;
|
use App\Enums\PayWay;
|
||||||
use App\Models\Agent;
|
use App\Models\Agent;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Dcat\Admin\Admin;
|
use Dcat\Admin\Admin;
|
||||||
|
|
||||||
class OrderProfitController extends AdminController
|
class OrderProfitController extends AdminController
|
||||||
|
|
@ -27,7 +28,7 @@ class OrderProfitController extends AdminController
|
||||||
|
|
||||||
$grid->disableViewButton(false);
|
$grid->disableViewButton(false);
|
||||||
|
|
||||||
$grid->column('order.sn');
|
$grid->column('order.sn')->link(fn() => admin_url('orders', ['id' => $this->order_id]));
|
||||||
$grid->column('fromUser.phone');
|
$grid->column('fromUser.phone');
|
||||||
$grid->column('user.phone');
|
$grid->column('user.phone');
|
||||||
$grid->column('role_name');
|
$grid->column('role_name');
|
||||||
|
|
@ -46,6 +47,20 @@ class OrderProfitController extends AdminController
|
||||||
$filter->like('user.phone')->width(3);
|
$filter->like('user.phone')->width(3);
|
||||||
$filter->equal('status')->select(OrderProfit::$statusMap)->width(3);
|
$filter->equal('status')->select(OrderProfit::$statusMap)->width(3);
|
||||||
$filter->where('role_name', fn($q) => $q->role($this->input))->select(Agent::$typeMap)->width(3);
|
$filter->where('role_name', fn($q) => $q->role($this->input))->select(Agent::$typeMap)->width(3);
|
||||||
|
$filter->whereBetween('created_at', function ($q) {
|
||||||
|
$start = data_get($this->input, 'start');
|
||||||
|
$start = $start ? Carbon::createFromFormat('Y-m-d', $start) : null;
|
||||||
|
$end = data_get($this->input, 'end');
|
||||||
|
$end = $end ? Carbon::createFromFormat('Y-m-d', $end) : null;
|
||||||
|
if ($start) {
|
||||||
|
if ($end) {
|
||||||
|
$q->whereBetween('created_at', [$start, $end]);
|
||||||
|
}
|
||||||
|
$q->where('created_at', '>=', $start);
|
||||||
|
} else if ($end) {
|
||||||
|
$q->where('created_at', '<=', $end);
|
||||||
|
}
|
||||||
|
})->date()->width(6);
|
||||||
});
|
});
|
||||||
|
|
||||||
$grid->showRowSelector();
|
$grid->showRowSelector();
|
||||||
|
|
@ -55,6 +70,28 @@ class OrderProfitController extends AdminController
|
||||||
$batch->add(new ProfitBatchSuccess());
|
$batch->add(new ProfitBatchSuccess());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$grid->footer(function ($collection) use ($grid) {
|
||||||
|
$query = OrderProfit::query();
|
||||||
|
$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'] ?? []);
|
||||||
|
});
|
||||||
|
$money = number_format($query->sum('money'), 2);
|
||||||
|
return <<<HTML
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>统计</td>
|
||||||
|
<td>收益金额: $money</td>
|
||||||
|
<tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
HTML;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,13 +53,13 @@ class UserController extends AdminController
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
$grid->column('userInfo.nickname')->display(function () {
|
$grid->column('userInfo.nickname')->display(function () {
|
||||||
$avatar = $this->userInfo->avatar ? '<img src="'.$this->userInfo->avatar.'" width="64" class="img-thumbnail" />' : '';
|
$avatar = $this->userInfo?->avatar ? '<img src="'.$this->userInfo?->avatar.'" width="64" class="img-thumbnail" />' : '';
|
||||||
return $avatar . $this->userInfo->nickname;
|
return $avatar . $this->userInfo?->nickname;
|
||||||
});
|
});
|
||||||
$grid->column('phone')->copyable();
|
$grid->column('phone')->copyable();
|
||||||
$grid->column('userInfo.code')->copyable();
|
$grid->column('userInfo.code')->copyable();
|
||||||
$grid->column('userInfo.inviterInfo.user.phone')->display(function ($v) {
|
$grid->column('userInfo.inviterInfo.user.phone')->display(function ($v) {
|
||||||
return $v ?: $this->userInfo->inviter_id;
|
return $v ?: $this->userInfo?->inviter_id;
|
||||||
})->copyable();
|
})->copyable();
|
||||||
$grid->column('userInfo.growth_value')->filter(
|
$grid->column('userInfo.growth_value')->filter(
|
||||||
Grid\Column\Filter\Between::make()
|
Grid\Column\Filter\Between::make()
|
||||||
|
|
@ -121,6 +121,10 @@ class UserController extends AdminController
|
||||||
$filter->panel();
|
$filter->panel();
|
||||||
$filter->like('phone')->width(3);
|
$filter->like('phone')->width(3);
|
||||||
$filter->like('userInfo.nickname')->width(3);
|
$filter->like('userInfo.nickname')->width(3);
|
||||||
|
$filter->where('inviter_id', function ($q) {
|
||||||
|
$input = $this->input;
|
||||||
|
$q->whereHas('userInfo.inviter', fn($q1) => $q1->where('phone', 'like', '%'.$input.'%'));
|
||||||
|
}, '推荐人')->width(3);
|
||||||
$filter->between('created_at')->dateTime()->width(7);
|
$filter->between('created_at')->dateTime()->width(7);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,11 @@ class UserInfo extends Model
|
||||||
return $this->belongsTo(UserInfo::class, 'inviter_id');
|
return $this->belongsTo(UserInfo::class, 'inviter_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function inviter()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class, 'inviter_id');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取此用户的真实邀请人信息
|
* 获取此用户的真实邀请人信息
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue