user
parent
77a0d0f501
commit
5582972d5b
|
|
@ -51,7 +51,7 @@ $menus = [
|
|||
| balance | decimal(12, 2) | not null | 0 | 余额 |
|
||||
| invite_code | varchar(191) | not null | - | 邀请码 |
|
||||
| inviter_id | bigint | null | - | 邀请人 |
|
||||
| inviter_path | varchart(191) | null | - | 所有的上级邀请人(-1-2-3-) |
|
||||
| inviter_path | varchart(191) | not null | '-' | 所有的上级邀请人(-1-2-3-) |
|
||||
| created_at | timestamp | null | - | 创建时间 |
|
||||
| updated_at | timestamp | null | - | 更新时间 |
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ return new class extends Migration
|
|||
$table->decimal('balance', 12, 2)->default(0)->comment('余额');
|
||||
$table->string('invite_code')->comment('邀请码');
|
||||
$table->unsignedBigInteger('inviter_id')->nullable()->comment('邀请人');
|
||||
$table->string('inviter_path')->nullable()->comment('所有上级邀请人');
|
||||
$table->string('inviter_path')->default('-')->comment('所有上级邀请人');
|
||||
$table->timestamps();
|
||||
|
||||
$table->comment('用户表');
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ Route::group([
|
|||
'prefix' => config('admin.route.prefix'),
|
||||
'middleware' => config('admin.route.middleware'),
|
||||
], function () {
|
||||
Route::get('api/user', [UserController::class, 'list'])->name('dcat.admin.api.users');
|
||||
Route::get('api/users', [UserController::class, 'list'])->name('dcat.admin.api.users');
|
||||
|
||||
Route::resource('users', UserController::class)->names('dcat.admin.users');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,10 +6,11 @@ use EloquentFilter\ModelFilter;
|
|||
|
||||
class UserFilter extends ModelFilter
|
||||
{
|
||||
public function key($key)
|
||||
public function key($v)
|
||||
{
|
||||
$this->where(function ($q) use ($key) {
|
||||
$q->orWhere('phone', 'like', "%$key%")->orWhere('username', 'like', "%$key%");
|
||||
$this->where(function ($q) use ($v) {
|
||||
$search = '%'.$v.'%';
|
||||
$q->orWhere('phone', 'like', $search)->orWhere('username', 'like', $search)->orWhere('name', 'like', $search);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Peidikeji\User\Http\Admin;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Form;
|
||||
use Dcat\Admin\Grid;
|
||||
|
|
@ -32,11 +33,7 @@ class UserController extends AdminController
|
|||
$query->where(fn($q) => $q->where('phone', 'like', $search)->orWhere('name', 'like', $search));
|
||||
}
|
||||
|
||||
if ($request->filled('none_merchant') || $request->filled('amp;none_merchant')) {
|
||||
$query->whereDoesntHave('merchants');
|
||||
}
|
||||
|
||||
$query->select(['id', 'phone as text']);
|
||||
$query->select(['id', 'phone as text'])->sort();
|
||||
|
||||
if ($request->filled('_paginate')) {
|
||||
$list = $query->paginate();
|
||||
|
|
@ -54,12 +51,13 @@ class UserController extends AdminController
|
|||
$grid->disableRowSelector();
|
||||
|
||||
$grid->column('id');
|
||||
$grid->column('username');
|
||||
$grid->column('name')->display(function () {
|
||||
return ($this->avatar ? '<img src="'.$this->avatar.'" width="60" class="img-thumbnail" />' : '') . $this->name;
|
||||
});
|
||||
$grid->column('phone');
|
||||
$grid->column('balance');
|
||||
$grid->column('inviter.phone');
|
||||
$grid->column('inviter.phone')->link(fn() => admin_url('users', ['id' => $this->inviter_id]));
|
||||
$grid->column('created_at');
|
||||
|
||||
$user = Admin::user();
|
||||
|
|
@ -70,10 +68,22 @@ class UserController extends AdminController
|
|||
|
||||
$grid->filter(function (Filter $filter) {
|
||||
$filter->panel();
|
||||
$filter->where('name', function ($q) {
|
||||
$search = '%'.$this->input.'%';
|
||||
$q->where(fn($q) => $q->where('username', 'like', $search)->orWhere('name', 'like', $search)->orWhere('phone', 'like', $search));
|
||||
}, '搜索')->placeholder('姓名/手机号')->width(3);
|
||||
$filter->where('name', fn($q) => $q->filter(['key' => $this->input]), '关键字')->placeholder('用户名/姓名/手机号')->width(3);
|
||||
$filter->equal('inviter_id')->select()->ajax('api/users?_paginate=1')->model(User::class, 'id', 'phone')->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(3);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -93,8 +103,8 @@ class UserController extends AdminController
|
|||
$form->hidden('invite_code');
|
||||
|
||||
$form->saving(function (Form $form) {
|
||||
$form->inviter_path = $form->inviter_id ? User::where('id', $form->inviter_id)->value('inviter_path') . $form->inviter_id.'-' : null;
|
||||
if (!$form->invite_code) {
|
||||
$form->inviter_path = $form->inviter_id ? User::where('id', $form->inviter_id)->value('inviter_path') . $form->inviter_id.'-' : '-';
|
||||
if ($form->isCreating() && !$form->invite_code) {
|
||||
do {
|
||||
$invite_code = strtoupper(Str::random(6));
|
||||
} while(User::where('invite_code', $invite_code)->exists());
|
||||
|
|
|
|||
|
|
@ -2,19 +2,13 @@
|
|||
|
||||
namespace Peidikeji\User\Models;
|
||||
|
||||
use App\Models\BalanceLog;
|
||||
use App\Models\CashOutLog;
|
||||
use App\Models\UserAddress;
|
||||
use App\Models\UserLike;
|
||||
use EloquentFilter\Filterable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Peidikeji\User\Filters\UserFilter;
|
||||
use Peidikeji\Merchant\Models\Merchant;
|
||||
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
||||
use Dcat\Admin\Traits\ModelTree;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Support\Str;
|
||||
use Peidikeji\Goods\Models\GoodsCart;
|
||||
use Peidikeji\Order\Models\Order;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
|
|
@ -22,9 +16,7 @@ class User extends Authenticatable
|
|||
use HasDateTimeFormatter;
|
||||
use Filterable;
|
||||
|
||||
protected $fillable = ['username', 'password', 'avatar', 'balance', 'profit', 'invite_code', 'inviter_id', 'inviter_path', 'name', 'phone', 'vip_expired_at', 'gender'];
|
||||
|
||||
protected $dates = ['vip_expired_at'];
|
||||
protected $fillable = ['username', 'password', 'avatar', 'balance', 'invite_code', 'inviter_id', 'inviter_path', 'name', 'phone'];
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
|
|
@ -62,31 +54,11 @@ class User extends Authenticatable
|
|||
return $this->hasMany(UserSocialite::class, 'user_id');
|
||||
}
|
||||
|
||||
public function balanceLogs()
|
||||
{
|
||||
return $this->morphMany(BalanceLog::class, 'subject');
|
||||
}
|
||||
|
||||
public function cashOutLogs()
|
||||
{
|
||||
return $this->hasMany(CashOutLog::class, 'user_id');
|
||||
}
|
||||
|
||||
public function merchants()
|
||||
{
|
||||
return $this->hasMany(Merchant::class, 'user_id');
|
||||
}
|
||||
|
||||
public function scopeSort($q)
|
||||
{
|
||||
return $q->latest('id');
|
||||
}
|
||||
|
||||
public function isVip(): bool
|
||||
{
|
||||
return $this->vip_expired_at && $this->vip_expired_at->gt(now()) ? true : false;
|
||||
}
|
||||
|
||||
public function getSubPhone()
|
||||
{
|
||||
// 18223350967 => 0967
|
||||
|
|
@ -98,25 +70,4 @@ class User extends Authenticatable
|
|||
// 18223350967 => 182****0967
|
||||
return $this->phone ? substr_replace($this->phone, '****', 3, 4) : '';
|
||||
}
|
||||
|
||||
public function addresses(){
|
||||
return $this->hasMany(UserAddress::class, 'user_id');
|
||||
}
|
||||
|
||||
// 购物车
|
||||
public function carts()
|
||||
{
|
||||
return $this->hasMany(GoodsCart::class, 'user_id');
|
||||
}
|
||||
|
||||
// 订单
|
||||
public function orders()
|
||||
{
|
||||
return $this->hasMany(Order::class, 'user_id');
|
||||
}
|
||||
|
||||
public function likes()
|
||||
{
|
||||
return $this->hasMany(UserLike::class, 'user_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue