6
0
Fork 0

切换员工身份

release
panliang 2022-05-07 14:37:34 +08:00
parent 50fb013f22
commit cfcc3b1b3c
8 changed files with 58 additions and 17 deletions

View File

@ -0,0 +1,41 @@
<?php
namespace App\Admin\Actions\Grid;
use App\Models\User;
use Dcat\Admin\Grid\RowAction;
use Illuminate\Http\Request;
class UserCompany extends RowAction
{
public function title()
{
return '<i class="feather icon-users grid-action-icon"></i> 切换员工 &nbsp;&nbsp;';
}
/**
* Handle the action request.
*
* @param Request $request
*
* @return Response
*/
public function handle(Request $request)
{
$user = User::findOrFail($this->getKey());
$user->userInfo->update([
'is_company' => $user->userInfo->is_company ? 0 : 1
]);
return $this->response()->success('操作成功')->refresh();
}
/**
* @return string|array|void
*/
public function confirm()
{
return ['是否确定?'];
}
}

View File

@ -3,7 +3,7 @@
namespace App\Admin\Controllers; namespace App\Admin\Controllers;
use App\Admin\Actions\Grid\DisableUser; use App\Admin\Actions\Grid\DisableUser;
use App\Admin\Actions\Grid\EnableUser; use App\Admin\Actions\Grid\{EnableUser, UserCompany};
use App\Admin\Actions\Grid\Frozen; use App\Admin\Actions\Grid\Frozen;
use App\Admin\Actions\Grid\UserResetAccountPassword; use App\Admin\Actions\Grid\UserResetAccountPassword;
use App\Admin\Actions\Grid\UserResetPassword; use App\Admin\Actions\Grid\UserResetPassword;
@ -80,8 +80,8 @@ class UserController extends AdminController
// PriceBetween::make() // PriceBetween::make()
// ); // );
$grid->column('userInfo.is_company')->bool();
$grid->column('created_at')->sortable(); $grid->column('created_at')->sortable();
$grid->column('register_ip');
$grid->column('status')->using([-1=>'冻结', 1=>'正常', 2=>'禁用']) $grid->column('status')->using([-1=>'冻结', 1=>'正常', 2=>'禁用'])
->dot([ ->dot([
-1 => '#b3b9bf', -1 => '#b3b9bf',
@ -110,21 +110,22 @@ class UserController extends AdminController
$actions->append(new EnableUser()); $actions->append(new EnableUser());
} }
} }
$actions->append(new UserCompany());
// 冻结资产 // 冻结资产
if (Admin::user()->can('dcat.admin.users.frozen')) { // if (Admin::user()->can('dcat.admin.users.frozen')) {
$actions->append(new Frozen()); // $actions->append(new Frozen());
} // }
// 重置用户密码 // 重置用户密码
if (Admin::user()->can('dcat.admin.users.reset_password')) { // if (Admin::user()->can('dcat.admin.users.reset_password')) {
$actions->append(new UserResetPassword()); // $actions->append(new UserResetPassword());
} // }
// 重置用户账户密码 // 重置用户账户密码
if (Admin::user()->can('dcat.admin.users.reset_account_password')) { // if (Admin::user()->can('dcat.admin.users.reset_account_password')) {
$actions->append(new UserResetAccountPassword()); // $actions->append(new UserResetAccountPassword());
} // }
}); });
$grid->filter(function (Grid\Filter $filter) { $grid->filter(function (Grid\Filter $filter) {

View File

@ -26,9 +26,6 @@ class UserController extends Controller
'id' => $user->id, 'id' => $user->id,
'phone' => $user->phone, 'phone' => $user->phone,
'user_info' => UserInfoResource::make($user->userInfo), 'user_info' => UserInfoResource::make($user->userInfo),
'is_vip' => $user->isVip(),
'wallet' => UserWalletResource::make($user->wallet),
'balance' => UserBalanceResource::make($user->balance),
]); ]);
} }

View File

@ -64,7 +64,7 @@ class MiniprogramController extends Controller
DB::commit(); DB::commit();
return response()->json([ return response()->json([
'token' => $token->plainTextToken, 'token' => $token->plainTextToken
]); ]);
} catch (Throwable $e) { } catch (Throwable $e) {
DB::rollBack(); DB::rollBack();

View File

@ -15,6 +15,7 @@ class StoreResource extends JsonResource
public function toArray($request) public function toArray($request)
{ {
return [ return [
'id' => (int) $this->id,
'title' => (string) $this->title, 'title' => (string) $this->title,
'image' => (string) $this->image, 'image' => (string) $this->image,
]; ];

View File

@ -20,8 +20,7 @@ class UserInfoResource extends JsonResource
'gender' => (string) $this->gender, 'gender' => (string) $this->gender,
'birthday' => (string) $this->birthday?->toDateString(), 'birthday' => (string) $this->birthday?->toDateString(),
'code' => (string) $this->code, 'code' => (string) $this->code,
'growth_value' => $this->growth_value, //用户成长值 'is_company' => (boolean) $this->is_company
'points' => (int) $this->points,
]; ];
} }
} }

View File

@ -44,6 +44,7 @@ class UserInfo extends Model
'path', 'path',
'growth_value', 'growth_value',
'real_inviter_id', 'real_inviter_id',
'is_company'
]; ];
/** /**

View File

@ -31,6 +31,7 @@ return [
'phone' =>'推荐人手机', 'phone' =>'推荐人手机',
], ],
], ],
'is_company' => '员工',
], ],
'user_info'=>[ 'user_info'=>[
'avatar' => '头像', 'avatar' => '头像',