6
0
Fork 0

添加用户管理操作

release
vine_liutk 2021-12-29 20:06:21 +08:00
parent 8ab8684f9e
commit 22c59d1e4e
9 changed files with 385 additions and 6 deletions

View File

@ -0,0 +1,77 @@
<?php
namespace App\Admin\Actions\Show;
use App\Models\User;
use Dcat\Admin\Show\AbstractTool;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Http\Request;
use Throwable;
class UserDisableBonus extends AbstractTool
{
/**
* @return string
*/
protected $title = '<i class="fa fa-jpy icon-shuffle"></i>&nbsp;关闭奖金分红';
/**
* 按钮样式定义,默认 btn btn-white waves-effect
*
* @var string
*/
protected $style = 'btn btn-sm btn-danger';
/**
* 权限判断,如不需要可以删除此方法
*
* @param Model|Authenticatable|HasPermissions|null $user
*
* @return bool
*/
protected function authorize($user): bool
{
return $user->can('dcat.admin.users.disable_bonus');
}
/**
* 处理请求,如果不需要接口处理,请直接删除这个方法
*
* @param Request $request
*
* @return Response
*/
public function handle(Request $request)
{
// 获取主键
$key = $this->getKey();
$user = User::findOrFail($key);
try {
$user->userInfo->update([
'bonusable'=>0,
]);
} catch (Throwable $th) {
report($th);
return $this->response()->error('操作失败:'.$th->getMessage());
}
return $this->response()
->success(__('admin.update_succeeded'))
->refresh();
}
public function html()
{
return parent::html().'&nbsp;&nbsp;';
}
/**
* 确认弹窗信息,如不需要可以删除此方法
*
* @return string|array|void
*/
public function confirm()
{
return ['是否关闭该用户奖金分红?', '该操作不可逆,确认后该用户将不再享受奖金分红。'];
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Admin\Actions\Show;
use App\Admin\Forms\UserEditBank as UserEditBankForm;
use Dcat\Admin\Show\AbstractTool;
use Dcat\Admin\Widgets\Modal;
class UserEditBank extends AbstractTool
{
/**
* @return string
*/
protected $title = '<i class="feather icon-credit-card"></i>&nbsp;修改银行卡';
/**
* 按钮样式定义,默认 btn btn-white waves-effect
*
* @var string
*/
protected $style = 'btn-warning';
public function render()
{
$form = UserEditBankForm::make()->payload(['id'=>$this->getKey()]);
return Modal::make()
->lg()
->title($this->title)
->body($form)
->button("<a href=\"javascript:void(0)\" class=\"btn btn-sm {$this->style}\">{$this->title}</a>&nbsp;&nbsp;");
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Admin\Actions\Show;
use App\Admin\Forms\UserEditPhone as UserEditPhoneForm;
use Dcat\Admin\Show\AbstractTool;
use Dcat\Admin\Widgets\Modal;
class UserEditPhone extends AbstractTool
{
/**
* @return string
*/
protected $title = '<i class="feather icon-smartphone"></i>&nbsp;修改手机号';
/**
* 按钮样式定义,默认 btn btn-white waves-effect
*
* @var string
*/
protected $style = 'btn-warning';
public function render()
{
$form = UserEditPhoneForm::make()->payload(['id'=>$this->getKey()]);
return Modal::make()
->lg()
->title($this->title)
->body($form)
->button("<a href=\"javascript:void(0)\" class=\"btn btn-sm {$this->style}\">{$this->title}</a>&nbsp;&nbsp;");
}
}

View File

@ -0,0 +1,77 @@
<?php
namespace App\Admin\Actions\Show;
use App\Models\User;
use Dcat\Admin\Show\AbstractTool;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Http\Request;
use Throwable;
class UserEnableBonus extends AbstractTool
{
/**
* @return string
*/
protected $title = '<i class="fa fa-jpy icon-shuffle"></i>&nbsp;开启奖金分红';
/**
* 按钮样式定义,默认 btn btn-white waves-effect
*
* @var string
*/
protected $style = 'btn btn-sm btn-success';
/**
* 权限判断,如不需要可以删除此方法
*
* @param Model|Authenticatable|HasPermissions|null $user
*
* @return bool
*/
protected function authorize($user): bool
{
return $user->can('dcat.admin.users.enable_bonus');
}
/**
* 处理请求,如果不需要接口处理,请直接删除这个方法
*
* @param Request $request
*
* @return Response
*/
public function handle(Request $request)
{
// 获取主键
$key = $this->getKey();
$user = User::findOrFail($key);
try {
$user->userInfo->update([
'bonusable'=>1,
]);
} catch (Throwable $th) {
report($th);
return $this->response()->error('操作失败:'.$th->getMessage());
}
return $this->response()
->success(__('admin.update_succeeded'))
->refresh();
}
public function html()
{
return parent::html().'&nbsp;&nbsp;';
}
/**
* 确认弹窗信息,如不需要可以删除此方法
*
* @return string|array|void
*/
public function confirm()
{
return ['是否开启该用户奖金分红?', '该操作不可逆,确认后该用户将享受奖金分红。'];
}
}

View File

@ -5,6 +5,10 @@ namespace App\Admin\Controllers;
use App\Admin\Actions\Grid\DisableUser;
use App\Admin\Actions\Grid\EnableUser;
use App\Admin\Actions\Grid\Frozen;
use App\Admin\Actions\Show\UserDisableBonus;
use App\Admin\Actions\Show\UserEditBank;
use App\Admin\Actions\Show\UserEditPhone;
use App\Admin\Actions\Show\UserEnableBonus;
use App\Admin\Repositories\User;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
@ -133,13 +137,25 @@ class UserController extends AdminController
$show->field('register_ip');
$show->field('created_at');
$show->panel()
->tools(function ($tools) {
->tools(function ($tools) use ($show) {
$tools->disableEdit();
$tools->disableDelete();
// todo-修改手机号
if (Admin::user()->can('dcat.admin.users.edit_phone')) {
$tools->append(new UserEditPhone());
}
// todo-修改银行卡
if (Admin::user()->can('dcat.admin.users.edit_bank')) {
$tools->append(new UserEditBank());
}
// todo-开启奖金分红
if (!$show->model()->userInfo->bonusable && Admin::user()->can('dcat.admin.users.enable_bonus')) {
$tools->append(new UserEnableBonus());
}
// todo-关闭奖金分红
if ($show->model()->userInfo->bonusable && Admin::user()->can('dcat.admin.users.disable_bonus')) {
$tools->append(new UserDisableBonus());
}
});
}));
});

View File

@ -0,0 +1,80 @@
<?php
namespace App\Admin\Forms;
use App\Models\User;
use App\Models\UserBank;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
use Illuminate\Support\Facades\DB;
use Throwable;
class UserEditBank extends Form implements LazyRenderable
{
use LazyWidget;
/**
* @param Model|Authenticatable|HasPermissions|null $user
*
* @return bool
*/
protected function authorize($user): bool
{
return $user->can('dcat.admin.users.edit_bank');
}
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
$id = $this->payload['id'] ?? 0;
$user = User::findOrFail($id);
try {
DB::beginTransaction();
UserBank::updateOrCreate(['user_id'=>$user->id], $input);
DB::commit();
} catch (Throwable $th) {
DB::rollBack();
report($th);
return $this->response()->error('操作失败:'.$th->getMessage());
}
return $this->response()
->success(__('admin.update_succeeded'))
->refresh();
}
/**
* Build a form here.
*/
public function form()
{
$id = $this->payload['id'] ?? 0;
$user = User::findOrFail($id);
// dd($user->bank);
$this->select('bank_name', '银行')->options([
'中国建设银行'=>'中国建设银行',
'中国农业银行'=>'中国农业银行',
'中国工商银行'=>'中国工商银行',
'中国银行'=>'中国银行',
'交通银行'=>'交通银行',
'招商银行'=>'招商银行',
'民生银行'=>'民生银行',
'兴业银行'=>'兴业银行',
'中信实业银行'=>'中信实业银行',
'上海浦东发展银行'=>'上海浦东发展银行',
'光大银行'=>'光大银行',
'邮政储蓄银行'=>'邮政储蓄银行',
'平安银行'=>'平安银行',
])->required()->value($user->bank?->bank_name);
$this->text('bank_number', '银行卡号')->required()->value($user->bank?->bank_number);
$this->text('bank_description', '开户行')->required()->value($user->bank?->bank_description);
$this->text('real_name', '持卡人')->required()->value($user->bank?->real_name);
}
}

View File

@ -0,0 +1,64 @@
<?php
namespace App\Admin\Forms;
use App\Models\User;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
use Illuminate\Support\Facades\DB;
use Throwable;
class UserEditPhone extends Form implements LazyRenderable
{
use LazyWidget;
/**
* @param Model|Authenticatable|HasPermissions|null $user
*
* @return bool
*/
protected function authorize($user): bool
{
return $user->can('dcat.admin.users.edit_phone');
}
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
$id = $this->payload['id'] ?? 0;
$user = User::findOrFail($id);
try {
DB::beginTransaction();
$user->update($input);
DB::commit();
} catch (Throwable $th) {
DB::rollBack();
report($th);
return $this->response()->error('操作失败:'.$th->getMessage());
}
return $this->response()
->success(__('admin.update_succeeded'))
->refresh();
}
/**
* Build a form here.
*/
public function form()
{
$id = $this->payload['id'] ?? 0;
$user = User::findOrFail($id);
$this->text('old_phone', '旧手机号')->value($user->phone)->disable();
$this->mobile('phone')->rules('unique:users,phone', ['unique'=>'该手机号已存在'])->required();
}
}

View File

@ -339,6 +339,8 @@ class User extends Model implements AuthorizableContract, AuthenticatableContrac
$user->wallet()->create();
//初始化余额
$user->balance()->create();
//初始化绑定的银行卡
$user->bank()->create();
return $user;
}

View File

@ -461,6 +461,10 @@ class AfterSaleService
'shipping_state' => Order::SHIPPING_STATE_PROCESSING,
]);
}
$afterSale->logs()->create([
'name' => '财务审核',
'desc' => $remarks,
]);
$afterSale->update([
'sales_value' => $salesValue,
@ -468,11 +472,6 @@ class AfterSaleService
'remarks' => $remarks,
]);
$afterSale->logs()->create([
'name' => '财务审核',
'desc' => $remarks,
]);
if (! $afterSaleProduct->isGift() && in_array($afterSale->type, [
AfterSale::TYPE_REFUND_AND_RETURN,
AfterSale::TYPE_REFUND,