From 3bf648bbe46b99794a26b75f2f0b45d8a1f50e15 Mon Sep 17 00:00:00 2001
From: vine_liutk <961510893@qq.com>
Date: Thu, 10 Feb 2022 13:26:08 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=B9=E9=9B=B6=E8=AE=A2?=
=?UTF-8?q?=E5=8D=95=E5=90=8E=E5=8F=B0=E5=8F=96=E6=B6=88=E5=BE=85=E7=A1=AE?=
=?UTF-8?q?=E8=AE=A4=E8=AE=A2=E5=8D=95=E6=93=8D=E4=BD=9C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Admin/Actions/Grid/DealerOrderCancel.php | 62 +++++++++++++++++++
.../Controllers/DealerOrderController.php | 34 +++++-----
2 files changed, 81 insertions(+), 15 deletions(-)
create mode 100644 app/Admin/Actions/Grid/DealerOrderCancel.php
diff --git a/app/Admin/Actions/Grid/DealerOrderCancel.php b/app/Admin/Actions/Grid/DealerOrderCancel.php
new file mode 100644
index 00000000..bd06b1c6
--- /dev/null
+++ b/app/Admin/Actions/Grid/DealerOrderCancel.php
@@ -0,0 +1,62 @@
+title) {
+ return $this->title;
+ }
+ return ' 取消订单 ';
+ }
+
+ /**
+ * @param Model|Authenticatable|HasPermissions|null $user
+ *
+ * @return bool
+ */
+ protected function authorize($user): bool
+ {
+ return $user->can('dcat.admin.dealer_orders.cancel');
+ }
+
+ /**
+ * Handle the action request.
+ *
+ * @param Request $request
+ *
+ * @return Response
+ */
+ public function handle(Request $request)
+ {
+ $order = DealerOrder::findOrFail($this->getKey());
+ try {
+ DB::beginTransaction();
+ (new OrderService())->cancelOrder($order);
+ DB::commit();
+ } catch (Throwable $th) {
+ DB::rollBack();
+ report($th);
+ return $this->response()->error('操作失败,'.$th->getMessage())->refresh();
+ }
+
+ return $this->response()->success('操作成功')->refresh();
+ }
+
+ /**
+ * @return string|array|void
+ */
+ public function confirm()
+ {
+ return ['确认取消当前订单?', '确认后将无法逆操作'];
+ }
+}
diff --git a/app/Admin/Controllers/DealerOrderController.php b/app/Admin/Controllers/DealerOrderController.php
index 1b58c166..c23a503a 100644
--- a/app/Admin/Controllers/DealerOrderController.php
+++ b/app/Admin/Controllers/DealerOrderController.php
@@ -3,6 +3,7 @@
namespace App\Admin\Controllers;
use App\Admin\Actions\Grid\DealerOrderAllocate;
+use App\Admin\Actions\Grid\DealerOrderCancel;
use App\Admin\Actions\Grid\DealerOrderPaid;
use App\Admin\Actions\Grid\DealerOrderShipping;
use App\Admin\Actions\Show\DealerOrderRemark;
@@ -42,7 +43,7 @@ class DealerOrderController extends AdminController
$grid->column('user.phone')->copyable();
$grid->column('userInfo.nickname');
$grid->column('consignor.phone')->display(function ($value) {
- return $value??'系统';
+ return $value ?? '系统';
});
$grid->column('total_amount')->prepend('¥');
$statusTexts = DealerOrderStatus::texts();
@@ -74,18 +75,21 @@ class DealerOrderController extends AdminController
$actions->append(' 显示 ');
// $actions->disableView(false);
}
- if (!(empty($actions->row->consignor) || $actions->row->consignor_id == 1) && $actions->row->status == DealerOrderStatus::Pending && Admin::user()->can('dcat.admin.dealer_orders.allocate')) {
+ if (!(empty($actions->row->consignor) || $actions->row->consignor_id == 1) && $actions->row->isPending() && Admin::user()->can('dcat.admin.dealer_orders.allocate')) {
$actions->append(new DealerOrderAllocate());
}
if ((empty($actions->row->consignor) || $actions->row->consignor_id == 1)) {
- if ($actions->row->status == DealerOrderStatus::Confirming && Admin::user()->can('dcat.admin.dealer_orders.paid')) {
+ if ($actions->row->isPay() && Admin::user()->can('dcat.admin.dealer_orders.paid')) {
$actions->append(new DealerOrderPaid());
}
- if ($actions->row->status == DealerOrderStatus::Paid && Admin::user()->can('dcat.admin.dealer_orders.shipping')) {
+ if ($actions->row->isPaid() && Admin::user()->can('dcat.admin.dealer_orders.shipping')) {
$actions->append(new DealerOrderShipping());
}
}
+ if ($actions->row->isPending() && Admin::user()->can('dcat.admin.dealer_orders.cancel')) {
+ $actions->append(new DealerOrderCancel());
+ }
});
$grid->filter(function (Grid\Filter $filter) {
$filter->panel();
@@ -125,7 +129,7 @@ class DealerOrderController extends AdminController
$show->field('user.phone');
$show->field('user_info.nickname');
$show->field('consignor.phone')->as(function ($value) {
- return $value??'系统';
+ return $value ?? '系统';
});
$show->field('pay_image')->image();
$show->field('remark');
@@ -142,45 +146,45 @@ class DealerOrderController extends AdminController
$show->divider('收款信息-银行');
$show->field('bank_user_name', '银行-收款人')->as(function () {
$payInfo = $this->getConsignorPayInfo();
- return $payInfo['bank']['user_name']??'';
+ return $payInfo['bank']['user_name'] ?? '';
});
$show->field('bank_bank_name', '银行-名称')->as(function () {
$payInfo = $this->getConsignorPayInfo();
- return $payInfo['bank']['bank_name']??'';
+ return $payInfo['bank']['bank_name'] ?? '';
});
$show->field('bank_bank_number', '银行-卡号')->as(function () {
$payInfo = $this->getConsignorPayInfo();
- return $payInfo['bank']['bank_number']??'';
+ return $payInfo['bank']['bank_number'] ?? '';
});
$show->field('bank_bank_description', '银行-开户行')->as(function () {
$payInfo = $this->getConsignorPayInfo();
- return $payInfo['bank']['bank_description']??'';
+ return $payInfo['bank']['bank_description'] ?? '';
});
$show->divider('收款信息-支付宝');
$show->field('alipay_user_name', '支付宝-真实名称')->as(function () {
$payInfo = $this->getConsignorPayInfo();
- return $payInfo['alipay']['user_name']??'';
+ return $payInfo['alipay']['user_name'] ?? '';
});
$show->field('alipay_ali_name', '支付宝-账户')->as(function () {
$payInfo = $this->getConsignorPayInfo();
- return $payInfo['alipay']['ali_name']??'';
+ return $payInfo['alipay']['ali_name'] ?? '';
});
$show->field('alipay_image', '支付宝-收款码')->as(function () {
$payInfo = $this->getConsignorPayInfo();
- return $payInfo['alipay']['image']??'';
+ return $payInfo['alipay']['image'] ?? '';
})->image();
$show->divider('收款信息-微信');
$show->field('wechat_user_name', '微信-真实名称')->as(function () {
$payInfo = $this->getConsignorPayInfo();
- return $payInfo['wechat']['user_name']??'';
+ return $payInfo['wechat']['user_name'] ?? '';
});
$show->field('wechat_wechat_name', '微信-ID')->as(function () {
$payInfo = $this->getConsignorPayInfo();
- return $payInfo['wechat']['wechat_name']??'';
+ return $payInfo['wechat']['wechat_name'] ?? '';
});
$show->field('wechat_image', '微信-收款码')->as(function () {
$payInfo = $this->getConsignorPayInfo();
- return $payInfo['wechat']['image']??'';
+ return $payInfo['wechat']['image'] ?? '';
})->image();
}
$show->panel()