添加订单除发货外操作
parent
f355f9e40b
commit
a317bf06bf
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Show;
|
||||
|
||||
use App\Admin\Forms\OrderConsigneeInfo as OrderConsigneeInfoForm;
|
||||
use Dcat\Admin\Show\AbstractTool;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
|
||||
class OrderConsigneeInfo extends AbstractTool
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected $title = '<i class="feather icon-external-link"></i> 修改订单地址';
|
||||
|
||||
/**
|
||||
* 按钮样式定义,默认 btn btn-white waves-effect
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $style = 'btn-success';
|
||||
|
||||
public function render()
|
||||
{
|
||||
$form = OrderConsigneeInfoForm::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> ");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Show;
|
||||
|
||||
use App\Admin\Forms\OrderPackage;
|
||||
use Dcat\Admin\Show\AbstractTool;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
|
||||
class OrderCreatePackage extends AbstractTool
|
||||
{
|
||||
public function __construct($title = null, $id)
|
||||
{
|
||||
if ($title) {
|
||||
$this->title = $title;
|
||||
}
|
||||
$this->setKey($id);
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected $title = '<i class="feather icon-package"></i> 发货';
|
||||
|
||||
/**
|
||||
* 按钮样式定义,默认 btn btn-white waves-effect
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $style = 'btn-warning';
|
||||
|
||||
public function render()
|
||||
{
|
||||
$form = OrderPackage::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> ");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Show;
|
||||
|
||||
use App\Models\Order;
|
||||
use App\Services\OrderService;
|
||||
use Dcat\Admin\Show\AbstractTool;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class OrderPay extends AbstractTool
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected $title = '<i class="fa fa-jpy icon-shuffle"></i> 支付';
|
||||
|
||||
/**
|
||||
* 按钮样式定义,默认 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.orders.pay');
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理请求,如果不需要接口处理,请直接删除这个方法
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function handle(Request $request)
|
||||
{
|
||||
// 获取主键
|
||||
$key = $this->getKey();
|
||||
|
||||
$orderService = new OrderService();
|
||||
$order = Order::where('status', Order::STATUS_PENDING)->findOrFail($key);
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$orderService->adminPay($order);
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
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 ['是否改变订单支付状态?', '该操作不可逆,确认后将修改为支付状态。'];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Show;
|
||||
|
||||
use App\Admin\Forms\OrderReduce as OrderReduceForm;
|
||||
use Dcat\Admin\Show\AbstractTool;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
|
||||
class OrderReduce extends AbstractTool
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected $title = '<i class="feather icon-shuffle"></i> 改价';
|
||||
|
||||
/**
|
||||
* 按钮样式定义,默认 btn btn-white waves-effect
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $style = 'btn-success';
|
||||
|
||||
public function render()
|
||||
{
|
||||
$form = OrderReduceForm::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> ");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Show;
|
||||
|
||||
use App\Admin\Forms\OrderRemark as OrderRemarkForm;
|
||||
use Dcat\Admin\Show\AbstractTool;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
|
||||
class OrderRemark extends AbstractTool
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected $title = '<i class="feather icon-file-text"></i> 备注';
|
||||
|
||||
/**
|
||||
* 按钮样式定义,默认 btn btn-white waves-effect
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $style = 'btn-success';
|
||||
|
||||
public function render()
|
||||
{
|
||||
$form = OrderRemarkForm::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> ");
|
||||
}
|
||||
}
|
||||
|
|
@ -3,11 +3,18 @@
|
|||
namespace App\Admin\Controllers;
|
||||
|
||||
use App\Admin\Actions\Grid\CreateOrderPackage;
|
||||
use App\Admin\Actions\Show\OrderConsigneeInfo;
|
||||
use App\Admin\Actions\Show\OrderCreatePackage;
|
||||
use App\Admin\Actions\Show\OrderPay;
|
||||
use App\Admin\Actions\Show\OrderReduce;
|
||||
use App\Admin\Actions\Show\OrderRemark;
|
||||
use App\Admin\Repositories\Order;
|
||||
use App\Constants\OrderStatus;
|
||||
use App\Models\Order as OrderModel;
|
||||
use App\Models\OrderLog;
|
||||
use App\Models\OrderPackage;
|
||||
use App\Models\OrderProduct;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Form;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
|
|
@ -30,62 +37,59 @@ class OrderController extends AdminController
|
|||
$grid->column('id')->sortable();
|
||||
$grid->column('sn');
|
||||
$grid->column('user.phone');
|
||||
// $grid->column('user_coupon_id');
|
||||
// $grid->column('coupon_discount_amount');
|
||||
// $grid->column('products_total_amount')->display(function ($value) {
|
||||
// return bcdiv($value, 100, 2);
|
||||
// })->prepend('¥');
|
||||
// $grid->column('vip_discount_amount')->display(function ($value) {
|
||||
// return bcdiv($value, 100, 2);
|
||||
// })->prepend('¥');
|
||||
// $grid->column('coupon_discount_amount')->display(function ($value) {
|
||||
// return bcdiv($value, 100, 2);
|
||||
// })->prepend('¥');
|
||||
// $grid->column('reduced_amount')->display(function ($value) {
|
||||
// return bcdiv($value, 100, 2);
|
||||
// })->prepend('¥');
|
||||
// $grid->column('weight');
|
||||
// $grid->column('shipping_fee')->display(function ($value) {
|
||||
// return bcdiv($value, 100, 2);
|
||||
// })->prepend('¥');
|
||||
$grid->column('total_amount')->display(function ($value) {
|
||||
return bcdiv($value, 100, 2);
|
||||
})->prepend('¥');
|
||||
// $grid->column('note');
|
||||
// $grid->column('remark');
|
||||
// $grid->column('pay_sn');
|
||||
$grid->column('order_status')->display(function ($value) {
|
||||
return $this->order_status;
|
||||
})->using([
|
||||
0=>'待付款',
|
||||
1=>'待发货',
|
||||
2=>'发货中',
|
||||
3=>'已发货',
|
||||
9=>'已完成',
|
||||
10=>'已取消',
|
||||
])->dot([
|
||||
0=>'primary',
|
||||
1=>'warning',
|
||||
2=>'danger',
|
||||
3=>'success',
|
||||
9=>'success',
|
||||
10=>'#b3b9bf',
|
||||
]);
|
||||
$grid->column('pay_way');
|
||||
$grid->column('pay_at');
|
||||
// $grid->column('consignee_name');
|
||||
// $grid->column('consignee_telephone');
|
||||
// $grid->column('consignee_zone');
|
||||
// $grid->column('consignee_address');
|
||||
$grid->column('status')->using([
|
||||
0=>'待支付',
|
||||
1=>'待收货',
|
||||
9=>'已完成',
|
||||
10=>'已取消',
|
||||
])->dot([
|
||||
0=>'primary',
|
||||
1=>'danger',
|
||||
9=>'success',
|
||||
10=>'#b3b9bf',
|
||||
]);
|
||||
$grid->column('shipping_state')->display(function ($v) {
|
||||
if ($this->status <1) {
|
||||
return -1;
|
||||
}
|
||||
return $v;
|
||||
})->using([
|
||||
-1=> '-',
|
||||
0 => '待发货',
|
||||
1 => '发货中',
|
||||
2 => '已完成',
|
||||
])->dot([
|
||||
0 => 'primary',
|
||||
1 => 'danger',
|
||||
2 => 'success',
|
||||
]);
|
||||
|
||||
// $grid->column('status')->using([
|
||||
// 0=>'待支付',
|
||||
// 1=>'待收货',
|
||||
// 9=>'已完成',
|
||||
// 10=>'已取消',
|
||||
// ])->dot([
|
||||
// 0=>'primary',
|
||||
// 1=>'danger',
|
||||
// 9=>'success',
|
||||
// 10=>'#b3b9bf',
|
||||
// ]);
|
||||
// $grid->column('shipping_state')->display(function ($v) {
|
||||
// if ($this->status <1) {
|
||||
// return -1;
|
||||
// }
|
||||
// return $v;
|
||||
// })->using([
|
||||
// -1=> '-',
|
||||
// 0 => '待发货',
|
||||
// 1 => '发货中',
|
||||
// 2 => '已完成',
|
||||
// ])->dot([
|
||||
// 0 => 'primary',
|
||||
// 1 => 'danger',
|
||||
// 2 => 'success',
|
||||
// ]);
|
||||
// $grid->column('completed_at');
|
||||
$grid->column('created_at')->sortable();
|
||||
|
||||
|
|
@ -115,8 +119,25 @@ class OrderController extends AdminController
|
|||
$row->column(5, function ($column) use ($id) {
|
||||
$builder = Order::with(['user', 'userCoupon']);
|
||||
$column->row(Show::make($id, $builder, function (Show $show) {
|
||||
$show->field('id');
|
||||
// $show->field('id');
|
||||
$show->field('sn');
|
||||
$show->field('order_status')->as(function ($v) {
|
||||
return $this->order_status;
|
||||
})->using([
|
||||
0=>'待付款',
|
||||
1=>'待发货',
|
||||
2=>'发货中',
|
||||
3=>'已发货',
|
||||
9=>'已完成',
|
||||
10=>'已取消',
|
||||
])->dot([
|
||||
0=>'primary',
|
||||
1=>'warning',
|
||||
2=>'danger',
|
||||
3=>'success',
|
||||
9=>'success',
|
||||
10=>'#b3b9bf',
|
||||
]);
|
||||
$show->field('total_amount')->as(function ($v) {
|
||||
return bcdiv($v, 100, 2);
|
||||
})->prepend('¥');
|
||||
|
|
@ -124,7 +145,14 @@ class OrderController extends AdminController
|
|||
$show->field('pay_way');
|
||||
$show->field('pay_at');
|
||||
|
||||
$show->field('user.phone');
|
||||
$show->divider();
|
||||
$show->field('consignee_name');
|
||||
$show->field('consignee_telephone');
|
||||
$show->field('consignee')->as(function () {
|
||||
return $this->consignee_zone . ' '. $this->consignee_address;
|
||||
});
|
||||
// $show->field('user.phone');
|
||||
$show->divider();
|
||||
$show->field('products_total_amount')->as(function ($v) {
|
||||
return bcdiv($v, 100, 2);
|
||||
})->prepend('¥');
|
||||
|
|
@ -141,12 +169,25 @@ class OrderController extends AdminController
|
|||
$show->field('shipping_fee')->as(function ($v) {
|
||||
return bcdiv($v, 100, 2);
|
||||
})->prepend('¥');
|
||||
|
||||
$show->divider();
|
||||
$show->field('note');
|
||||
$show->field('remark');
|
||||
|
||||
$show->panel()
|
||||
->tools(function (Show\Tools $tools) use ($show) {
|
||||
$tools->disableEdit();
|
||||
$tools->disableDelete();
|
||||
|
||||
if ($show->model()->status == OrderModel::STATUS_PENDING) {
|
||||
if (Admin::user()->can('dcat.admin.orders.reduce')) {
|
||||
$tools->append(new OrderReduce());
|
||||
}
|
||||
if (Admin::user()->can('dcat.admin.orders.pay')) {
|
||||
$tools->append(new OrderPay());
|
||||
}
|
||||
}
|
||||
$tools->append(new OrderRemark());
|
||||
$tools->append(new OrderConsigneeInfo());
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
|
@ -181,6 +222,8 @@ class OrderController extends AdminController
|
|||
$grid->column('shipping_number', '物流单号');
|
||||
$grid->column('packageProducts', '包裹商品')->setHeaderAttributes(['style' => 'color:#5b69bc']);
|
||||
$grid->column('created_at', '发货时间');
|
||||
$grid->column('status', '包裹状态');
|
||||
$grid->model()->orderBy('created_at', 'desc');
|
||||
|
||||
$grid->disableActions();
|
||||
$grid->disablePagination();
|
||||
|
|
@ -188,9 +231,12 @@ class OrderController extends AdminController
|
|||
});
|
||||
$logBuilder = OrderLog::with('administrator')->where('order_id', $id);
|
||||
$orderLogoGrid = Grid::make($logBuilder, function (Grid $grid) {
|
||||
$grid->column('administrator', '操作人');
|
||||
$grid->column('content', '操作明细');
|
||||
$grid->column('craeted_at', '操作时间');
|
||||
$grid->column('administrator.name', '操作人');
|
||||
$grid->column('content', '操作明细')->display(function ($content) {
|
||||
return $content;
|
||||
});
|
||||
$grid->column('created_at', '操作时间');
|
||||
$grid->model()->orderBy('created_at', 'desc');
|
||||
|
||||
$grid->disableActions();
|
||||
$grid->disablePagination();
|
||||
|
|
@ -199,12 +245,13 @@ class OrderController extends AdminController
|
|||
|
||||
$column->row(Box::make('订单商品', $productGrid));
|
||||
$packagesBox = Box::make('发货包裹', $packageGrid);
|
||||
$packagesBox->tool('<button class="btn btn-sm btn-light shadow-none">发货</button>');
|
||||
//显示发货动作
|
||||
if (in_array(OrderModel::findOrFail($id)->orderStatus, [OrderStatus::PAID, OrderStatus::SHIPPING])) {
|
||||
$packagesBox->tool(new OrderCreatePackage(null, $id));
|
||||
}
|
||||
|
||||
$column->row($packagesBox->collapsable());
|
||||
$logsBox = Box::make('操作记录', $orderLogoGrid);
|
||||
$logsBox->tool('<button class="btn btn-sm btn-light shadow-none">改价</button>');
|
||||
$logsBox->tool('<button class="btn btn-sm btn-light shadow-none">支付</button>');
|
||||
$logsBox->tool('<button class="btn btn-sm btn-light shadow-none">修改收货地址</button>');
|
||||
$column->row($logsBox->collapsable());
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Forms;
|
||||
|
||||
use App\Exceptions\BizException;
|
||||
use App\Models\Order;
|
||||
use App\Services\OrderService;
|
||||
use Dcat\Admin\Contracts\LazyRenderable;
|
||||
use Dcat\Admin\Traits\LazyWidget;
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class OrderConsigneeInfo extends Form implements LazyRenderable
|
||||
{
|
||||
use LazyWidget;
|
||||
|
||||
/**
|
||||
* 权限判断,如不需要可以删除此方法
|
||||
*
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.orders.consignee');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the form request.
|
||||
*
|
||||
* @param array $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(array $input)
|
||||
{
|
||||
$orderId = $this->payload['id'] ?? 0;
|
||||
$order = Order::findOrFail($orderId);
|
||||
$orderService = new OrderService();
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$orderService->adminEditConsignee($order, $input);
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
throw new BizException('操作失败:'.$th->getMessage());
|
||||
}
|
||||
return $this->response()
|
||||
->success(__('admin.update_succeeded'))
|
||||
->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a form here.
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
$orderId = $this->payload['id'] ?? 0;
|
||||
$order = Order::findOrFail($orderId);
|
||||
|
||||
$this->text('consignee_name')->required()->value($order->consignee_name);
|
||||
$this->text('consignee_telephone')->required()->value($order->consignee_telephone);
|
||||
$this->text('consignee_zone')->required()->value($order->consignee_zone);
|
||||
$this->text('consignee_address')->required()->value($order->consignee_address);
|
||||
|
||||
$this->disableResetButton();
|
||||
}
|
||||
}
|
||||
|
|
@ -43,7 +43,7 @@ class OrderPackage extends Form implements LazyRenderable
|
|||
*/
|
||||
public function form()
|
||||
{
|
||||
$orderId = $this->payload['order_id'] ?? 0;
|
||||
$orderId = $this->payload['id'] ?? 0;
|
||||
|
||||
$order = Order::findOrFail($orderId);
|
||||
$this->hidden('order_id');
|
||||
|
|
@ -51,7 +51,7 @@ class OrderPackage extends Form implements LazyRenderable
|
|||
$this->text('shipping_company');
|
||||
$this->text('shipping_number');
|
||||
$this->hasMany('packages', function (Form $form) use ($order) {
|
||||
$form->select('order_product_id')->options($order->products->pluck('name', 'id'));
|
||||
$form->select('order_product_id')->options($order->products()->where('after_sale_state', '<>', 1)->pluck('name', 'id'));
|
||||
$form->number('quantity')->min(0);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Forms;
|
||||
|
||||
use App\Exceptions\BizException;
|
||||
use App\Models\Order;
|
||||
use App\Services\OrderService;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Contracts\LazyRenderable;
|
||||
use Dcat\Admin\Traits\LazyWidget;
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class OrderReduce extends Form implements LazyRenderable
|
||||
{
|
||||
use LazyWidget;
|
||||
|
||||
/**
|
||||
* 权限判断,如不需要可以删除此方法
|
||||
*
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.orders.reduce');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the form request.
|
||||
*
|
||||
* @param array $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(array $input)
|
||||
{
|
||||
$orderId = $this->payload['id'] ?? 0;
|
||||
$order = Order::findOrFail($orderId);
|
||||
$reduceAmount = $input['reduce_amount']??0;
|
||||
//获取调整价格;
|
||||
if ($reduceAmount > $order->total_amount) {
|
||||
throw new BizException('订单价格无法上浮');
|
||||
}
|
||||
if ($reduceAmount == $order->total_amount) {
|
||||
throw new BizException('调整价格和订单原价格一致,无需调整');
|
||||
}
|
||||
$orderService = new OrderService();
|
||||
|
||||
$reduced = $order->total_amount-$reduceAmount;
|
||||
//判断是否在当前操作人调价权限范围内
|
||||
if (!Admin::user()->inReduceRange($reduced)) {
|
||||
throw new BizException('当前调整价格超出权限范围,请重新确认价格。');
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$orderService->adminReduceOrder($order, $reduceAmount);
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
throw new BizException('操作失败:'.$th->getMessage());
|
||||
}
|
||||
return $this->response()
|
||||
->success(__('admin.update_succeeded'))
|
||||
->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a form here.
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
$orderId = $this->payload['id'] ?? 0;
|
||||
$order = Order::findOrFail($orderId);
|
||||
|
||||
$this->currency('reduce_amount', '调整价格')->symbol('¥')->default(0)->customFormat(function ($V) use ($order) {
|
||||
return bcdiv($order->total_amount, 100, 2);
|
||||
})->saving(function ($reduceAmount) {
|
||||
return bcmul($reduceAmount, 100);
|
||||
});
|
||||
|
||||
$this->confirm('是否确认调价?', '该操作不可逆,确认后将更改订单支付价格。');
|
||||
|
||||
$this->disableResetButton();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Forms;
|
||||
|
||||
use App\Exceptions\BizException;
|
||||
use App\Models\Order;
|
||||
use App\Services\OrderService;
|
||||
use Dcat\Admin\Contracts\LazyRenderable;
|
||||
use Dcat\Admin\Traits\LazyWidget;
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class OrderRemark extends Form implements LazyRenderable
|
||||
{
|
||||
use LazyWidget;
|
||||
|
||||
/**
|
||||
* 权限判断,如不需要可以删除此方法
|
||||
*
|
||||
* @param Model|Authenticatable|HasPermissions|null $user
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize($user): bool
|
||||
{
|
||||
return $user->can('dcat.admin.orders.remark');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the form request.
|
||||
*
|
||||
* @param array $input
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(array $input)
|
||||
{
|
||||
$orderId = $this->payload['id'] ?? 0;
|
||||
$order = Order::findOrFail($orderId);
|
||||
|
||||
$remark = $input['remark']??'';
|
||||
$orderService = new OrderService();
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$orderService->adminRemark($order, $remark);
|
||||
DB::commit();
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
throw new BizException('操作失败:'.$th->getMessage());
|
||||
}
|
||||
return $this->response()
|
||||
->success(__('admin.update_succeeded'))
|
||||
->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a form here.
|
||||
*/
|
||||
public function form()
|
||||
{
|
||||
$orderId = $this->payload['id'] ?? 0;
|
||||
$order = Order::findOrFail($orderId);
|
||||
|
||||
$this->text('remark')->required()->value($order->remark);
|
||||
|
||||
$this->disableResetButton();
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Models\Admin;
|
||||
|
||||
use App\Models\OrderReduceRange;
|
||||
use Dcat\Admin\Models\Administrator as DcatAdministrator;
|
||||
|
||||
class Administrator extends DcatAdministrator
|
||||
|
|
@ -49,4 +50,28 @@ class Administrator extends DcatAdministrator
|
|||
{
|
||||
session()->forget(self::SESSION_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员订单调价范围
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function orderReduceRange()
|
||||
{
|
||||
return $this->hasOne(OrderReduceRange::class, 'administrator_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 在调价权限范围内
|
||||
*
|
||||
* @param integer $reduced
|
||||
* @return void
|
||||
*/
|
||||
public function inReduceRange(int $reduced)
|
||||
{
|
||||
if (is_null($this->orderReduceRange)) {
|
||||
return false;
|
||||
}
|
||||
return $reduced <= $this->orderReduceRange->max;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,6 +114,16 @@ class Order extends Model
|
|||
return $this->hasMany(OrderProduct::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 此订单是否待付款
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isPending(): bool
|
||||
{
|
||||
return $this->status === static::STATUS_PENDING;
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认此订单是否可以被确认
|
||||
*
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Models;
|
||||
|
||||
use App\Models\Admin\Administrator;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
|
@ -12,6 +13,10 @@ class OrderLog extends Model
|
|||
use HasFactory;
|
||||
use HasDateTimeFormatter;
|
||||
|
||||
protected $fillable = [
|
||||
'order_id', 'content',
|
||||
];
|
||||
|
||||
public function administrator()
|
||||
{
|
||||
return $this->belongsTo(Administrator::class, 'administrator_id');
|
||||
|
|
@ -21,4 +26,15 @@ class OrderLog extends Model
|
|||
{
|
||||
return $this->belongsTo(Order::class, 'order_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static function booted()
|
||||
{
|
||||
parent::saving(function ($log) {
|
||||
// 如果自动创建sn
|
||||
$log->administrator_id = Admin::user()->id;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class OrderReduceRange extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasDateTimeFormatter;
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ use App\Exceptions\ShippingNotSupportedException;
|
|||
use App\Helpers\Numeric;
|
||||
use App\Helpers\Order as OrderHelper;
|
||||
use App\Models\Order;
|
||||
use App\Models\OrderLog;
|
||||
use App\Models\OrderProduct;
|
||||
use App\Models\ProductSku;
|
||||
use App\Models\ShippingAddress;
|
||||
|
|
@ -568,4 +569,84 @@ class OrderService
|
|||
|
||||
return $user->shippingAddresses()->where('is_default', true)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单调整价格
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function adminReduceOrder(Order $order, int $reduceAmount)
|
||||
{
|
||||
if ($order->isPending()) {
|
||||
$res = $order->where('updated_at', $order->updated_at)->update([
|
||||
'reduced_amount' => $order->total_amount - $reduceAmount + $order->reduced_amount,
|
||||
'total_amount' => $reduceAmount,
|
||||
]);
|
||||
if ($res === 0) {
|
||||
throw new BizException('订单已发生改变');
|
||||
}
|
||||
OrderLog::create([
|
||||
'order_id'=>$order->id,
|
||||
'content'=> '调整订单支付价格为:¥'.bcdiv($reduceAmount, 100, 2),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台支付订单
|
||||
*
|
||||
* @param Order $order
|
||||
* @return void
|
||||
*/
|
||||
public function adminPay(Order $order)
|
||||
{
|
||||
if ($order->isPending()) {
|
||||
//操作订单状态-需要调整为统一支付方法
|
||||
$order->update([
|
||||
'status' => Order::STATUS_PAID,
|
||||
]);
|
||||
|
||||
OrderLog::create([
|
||||
'order_id'=>$order->id,
|
||||
'content'=> '改变订单状态为【已支付】',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加后台备注
|
||||
*
|
||||
* @param Order $order
|
||||
* @param string $remark
|
||||
* @return void
|
||||
*/
|
||||
public function adminRemark(Order $order, string $remark)
|
||||
{
|
||||
//操作订单状态-需要调整为统一支付方法
|
||||
$order->update([
|
||||
'remark' => $remark,
|
||||
]);
|
||||
|
||||
OrderLog::create([
|
||||
'order_id'=>$order->id,
|
||||
'content'=> '修改订单备注:'.$remark,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改订单收货信息
|
||||
*
|
||||
* @param Order $order
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function adminEditConsignee(Order $order, array $params)
|
||||
{
|
||||
$oldOrderConsignee = $order->consignee_name.','.$order->consignee_telephone.','.$order->consignee_zone.$order->consignee_address;
|
||||
$order->update($params);
|
||||
OrderLog::create([
|
||||
'order_id'=>$order->id,
|
||||
'content'=> '修改订单收货信息<br\>原收货信息:'.$oldOrderConsignee,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateOrderReduceRangesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('order_reduce_ranges', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('administrator_id')->comment('操作人ID');
|
||||
$table->unsignedInteger('max')->default(0)->comment('最大额度');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('order_reduce_ranges');
|
||||
}
|
||||
}
|
||||
|
|
@ -31,7 +31,9 @@ return [
|
|||
'consignee_telephone' => '联系方式',
|
||||
'consignee_zone' => '收货地区',
|
||||
'consignee_address' => '收货地址',
|
||||
'consignee'=>'收货地址',
|
||||
'status' => '订单状态',
|
||||
'order_status'=>'订单状态',
|
||||
'shipping_state'=>'物流状态',
|
||||
'completed_at' => '完成时间',
|
||||
'created_at' => '下单时间',
|
||||
|
|
@ -41,6 +43,11 @@ return [
|
|||
'quantity' => '数量',
|
||||
'after_sale_state'=>'售后状态',
|
||||
'product_total_amount'=>'总价',
|
||||
'shipping_company' => '快递公司',
|
||||
'shipping_number' => '快递单号',
|
||||
'packages'=>'包裹内容',
|
||||
'order_product_id' =>'商品',
|
||||
'quantity'=>'数量',
|
||||
],
|
||||
'options' => [
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in New Issue