6
0
Fork 0

添加批零订单后台取消待确认订单操作

release
vine_liutk 2022-02-10 13:26:08 +08:00
parent 98d49bfc2b
commit 3bf648bbe4
2 changed files with 81 additions and 15 deletions

View File

@ -0,0 +1,62 @@
<?php
namespace App\Admin\Actions\Grid;
use App\Models\DealerOrder;
use App\Services\Dealer\OrderService;
use Dcat\Admin\Grid\RowAction;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Throwable;
class DealerOrderCancel extends RowAction
{
public function title()
{
if ($this->title) {
return $this->title;
}
return '<i class="feather icon-trash grid-action-icon"></i> 取消订单 &nbsp;&nbsp;';
}
/**
* @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 ['确认取消当前订单?', '确认后将无法逆操作'];
}
}

View File

@ -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('<a style="cursor: pointer;" target="_blank" href="'.admin_route('dealer_orders.show', ['dealer_order'=>$actions->row]).'"><i class="feather icon-eye"></i> 显示 &nbsp;&nbsp;</a>');
// $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()