From 22c59d1e4ebcd4045607c29a4adba88959f5dce1 Mon Sep 17 00:00:00 2001
From: vine_liutk <961510893@qq.com>
Date: Wed, 29 Dec 2021 20:06:21 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E7=AE=A1?=
=?UTF-8?q?=E7=90=86=E6=93=8D=E4=BD=9C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Admin/Actions/Show/UserDisableBonus.php | 77 ++++++++++++++++++++
app/Admin/Actions/Show/UserEditBank.php | 32 +++++++++
app/Admin/Actions/Show/UserEditPhone.php | 32 +++++++++
app/Admin/Actions/Show/UserEnableBonus.php | 77 ++++++++++++++++++++
app/Admin/Controllers/UserController.php | 18 ++++-
app/Admin/Forms/UserEditBank.php | 80 +++++++++++++++++++++
app/Admin/Forms/UserEditPhone.php | 64 +++++++++++++++++
app/Models/User.php | 2 +
app/Services/AfterSaleService.php | 9 ++-
9 files changed, 385 insertions(+), 6 deletions(-)
create mode 100644 app/Admin/Actions/Show/UserDisableBonus.php
create mode 100644 app/Admin/Actions/Show/UserEditBank.php
create mode 100644 app/Admin/Actions/Show/UserEditPhone.php
create mode 100644 app/Admin/Actions/Show/UserEnableBonus.php
create mode 100644 app/Admin/Forms/UserEditBank.php
create mode 100644 app/Admin/Forms/UserEditPhone.php
diff --git a/app/Admin/Actions/Show/UserDisableBonus.php b/app/Admin/Actions/Show/UserDisableBonus.php
new file mode 100644
index 00000000..b790b981
--- /dev/null
+++ b/app/Admin/Actions/Show/UserDisableBonus.php
@@ -0,0 +1,77 @@
+ 关闭奖金分红';
+
+ /**
+ * 按钮样式定义,默认 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().' ';
+ }
+
+ /**
+ * 确认弹窗信息,如不需要可以删除此方法
+ *
+ * @return string|array|void
+ */
+ public function confirm()
+ {
+ return ['是否关闭该用户奖金分红?', '该操作不可逆,确认后该用户将不再享受奖金分红。'];
+ }
+}
diff --git a/app/Admin/Actions/Show/UserEditBank.php b/app/Admin/Actions/Show/UserEditBank.php
new file mode 100644
index 00000000..2e16a851
--- /dev/null
+++ b/app/Admin/Actions/Show/UserEditBank.php
@@ -0,0 +1,32 @@
+ 修改银行卡';
+
+ /**
+ * 按钮样式定义,默认 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("style}\">{$this->title} ");
+ }
+}
diff --git a/app/Admin/Actions/Show/UserEditPhone.php b/app/Admin/Actions/Show/UserEditPhone.php
new file mode 100644
index 00000000..7d80e84e
--- /dev/null
+++ b/app/Admin/Actions/Show/UserEditPhone.php
@@ -0,0 +1,32 @@
+ 修改手机号';
+
+ /**
+ * 按钮样式定义,默认 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("style}\">{$this->title} ");
+ }
+}
diff --git a/app/Admin/Actions/Show/UserEnableBonus.php b/app/Admin/Actions/Show/UserEnableBonus.php
new file mode 100644
index 00000000..fc3cd8fc
--- /dev/null
+++ b/app/Admin/Actions/Show/UserEnableBonus.php
@@ -0,0 +1,77 @@
+ 开启奖金分红';
+
+ /**
+ * 按钮样式定义,默认 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().' ';
+ }
+
+ /**
+ * 确认弹窗信息,如不需要可以删除此方法
+ *
+ * @return string|array|void
+ */
+ public function confirm()
+ {
+ return ['是否开启该用户奖金分红?', '该操作不可逆,确认后该用户将享受奖金分红。'];
+ }
+}
diff --git a/app/Admin/Controllers/UserController.php b/app/Admin/Controllers/UserController.php
index 6d34963d..74b3ab2d 100644
--- a/app/Admin/Controllers/UserController.php
+++ b/app/Admin/Controllers/UserController.php
@@ -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());
+ }
});
}));
});
diff --git a/app/Admin/Forms/UserEditBank.php b/app/Admin/Forms/UserEditBank.php
new file mode 100644
index 00000000..67b4ba65
--- /dev/null
+++ b/app/Admin/Forms/UserEditBank.php
@@ -0,0 +1,80 @@
+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);
+ }
+}
diff --git a/app/Admin/Forms/UserEditPhone.php b/app/Admin/Forms/UserEditPhone.php
new file mode 100644
index 00000000..2d1c0550
--- /dev/null
+++ b/app/Admin/Forms/UserEditPhone.php
@@ -0,0 +1,64 @@
+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();
+ }
+}
diff --git a/app/Models/User.php b/app/Models/User.php
index 4be0ba33..d87b48fa 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -339,6 +339,8 @@ class User extends Model implements AuthorizableContract, AuthenticatableContrac
$user->wallet()->create();
//初始化余额
$user->balance()->create();
+ //初始化绑定的银行卡
+ $user->bank()->create();
return $user;
}
diff --git a/app/Services/AfterSaleService.php b/app/Services/AfterSaleService.php
index af3c2319..7e3b5c09 100644
--- a/app/Services/AfterSaleService.php
+++ b/app/Services/AfterSaleService.php
@@ -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,