调整售后漏发补货流程
parent
0890778f61
commit
85a056bff0
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Actions\Grid;
|
||||||
|
|
||||||
|
use App\Admin\Forms\OrderPackageEdit as OrderPackageEditForm;
|
||||||
|
use Dcat\Admin\Grid\RowAction;
|
||||||
|
use Dcat\Admin\Widgets\Modal;
|
||||||
|
|
||||||
|
class OrderPackageEdit extends RowAction
|
||||||
|
{
|
||||||
|
public function title()
|
||||||
|
{
|
||||||
|
if ($this->title) {
|
||||||
|
return $this->title;
|
||||||
|
}
|
||||||
|
return '<i class="feather grid-action-icon icon-shuffle"></i> 修改数量 ';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Model|Authenticatable|HasPermissions|null $user
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function authorize($user): bool
|
||||||
|
{
|
||||||
|
return $user->can('dcat.admin.order_packages.edit_custom');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
|
$form = OrderPackageEditForm::make()->payload(['id'=>$this->getKey()]);
|
||||||
|
return Modal::make()
|
||||||
|
->lg()
|
||||||
|
->title($this->title())
|
||||||
|
->body($form)
|
||||||
|
->button($this->title());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Admin\Controllers;
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
use App\Admin\Actions\Grid\KuaidiInfo;
|
use App\Admin\Actions\Grid\KuaidiInfo;
|
||||||
|
use App\Admin\Actions\Grid\OrderPackageEdit;
|
||||||
use App\Admin\Actions\Grid\OrderPackageFailed;
|
use App\Admin\Actions\Grid\OrderPackageFailed;
|
||||||
use App\Admin\Actions\Grid\OrderPackageSetTag;
|
use App\Admin\Actions\Grid\OrderPackageSetTag;
|
||||||
use App\Admin\Renderable\PackageProductSimpleTable;
|
use App\Admin\Renderable\PackageProductSimpleTable;
|
||||||
|
|
@ -113,6 +114,11 @@ class OrderPackageController extends AdminController
|
||||||
if (Admin::user()->can('dcat.admin.order_packages.tags')) {
|
if (Admin::user()->can('dcat.admin.order_packages.tags')) {
|
||||||
$actions->append(new OrderPackageSetTag());
|
$actions->append(new OrderPackageSetTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//修改发货单商品数量
|
||||||
|
if (!$actions->row->is_settle && Admin::user()->can('dcat.admin.order_packages.edit')) {
|
||||||
|
$actions->append(new OrderPackageEdit());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 查询 **/
|
/** 查询 **/
|
||||||
|
|
@ -161,7 +167,7 @@ class OrderPackageController extends AdminController
|
||||||
*/
|
*/
|
||||||
protected function form()
|
protected function form()
|
||||||
{
|
{
|
||||||
$builder = OrderPackage::with('order');
|
$builder = OrderPackage::with(['order']);
|
||||||
return Form::make($builder, function (Form $form) {
|
return Form::make($builder, function (Form $form) {
|
||||||
$form->display('id');
|
$form->display('id');
|
||||||
$form->text('order.sn')->disable();
|
$form->text('order.sn')->disable();
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,11 @@
|
||||||
|
|
||||||
namespace App\Admin\Forms;
|
namespace App\Admin\Forms;
|
||||||
|
|
||||||
|
use App\Admin\Services\OrderPackageService;
|
||||||
|
use App\Exceptions\BizException;
|
||||||
use App\Models\AfterSale;
|
use App\Models\AfterSale;
|
||||||
|
use App\Models\Order;
|
||||||
|
use App\Models\OrderPackageProduct;
|
||||||
use App\Services\AfterSaleService;
|
use App\Services\AfterSaleService;
|
||||||
use Dcat\Admin\Contracts\LazyRenderable;
|
use Dcat\Admin\Contracts\LazyRenderable;
|
||||||
use Dcat\Admin\Traits\LazyWidget;
|
use Dcat\Admin\Traits\LazyWidget;
|
||||||
|
|
@ -39,8 +43,43 @@ class AfterSaleShippingFill extends Form implements LazyRenderable
|
||||||
try {
|
try {
|
||||||
DB::beginTransaction();
|
DB::beginTransaction();
|
||||||
$afterSale = AfterSale::where('state', AfterSale::STATE_SHIPPING)->findOrFail($this->payload['id']);
|
$afterSale = AfterSale::where('state', AfterSale::STATE_SHIPPING)->findOrFail($this->payload['id']);
|
||||||
$afterSaleService->shippingFill($afterSale, $input['remarks']);
|
//处理售后
|
||||||
|
$afterSaleService->shippingFill($afterSale, $input['shipping_number']);
|
||||||
|
/** 处理补发逻辑 **/
|
||||||
|
//获取售后商品数量
|
||||||
|
$fillQuantity = $afterSale->num;
|
||||||
|
$packageProduct = OrderPackageProduct::where('order_product_id', $afterSale->order_product_id)->where('quantity', '>', $fillQuantity)->first();
|
||||||
|
if (!$packageProduct) {
|
||||||
|
throw new BizException('补发包裹未找到或者售后补发数量异常');
|
||||||
|
}
|
||||||
|
//调整已发货包裹商品数量
|
||||||
|
$packageProduct->decrement('quantity', $fillQuantity);
|
||||||
|
//回滚对应订单商品待发货数量;
|
||||||
|
$packageProduct->orderProduct->increment('remain_quantity', $fillQuantity);
|
||||||
|
//回滚订单状态
|
||||||
|
if ($afterSale->order->isCompleted()) {
|
||||||
|
$afterSale->order->update([
|
||||||
|
'status'=>Order::STATUS_PAID,
|
||||||
|
'shipping_state'=>Order::SHIPPING_STATE_PROCESSING,
|
||||||
|
'completed_at'=>null,
|
||||||
|
]);
|
||||||
|
} elseif ($afterSale->order->isShipped()) {
|
||||||
|
$afterSale->order->update([
|
||||||
|
'shipping_state'=>Order::SHIPPING_STATE_PROCESSING,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
//自动帮他生成新的发货单
|
||||||
|
$orderPackageService = new OrderPackageService();
|
||||||
|
$orderPackageService->createPackage($afterSale->order, [
|
||||||
|
'shipping_company'=>$input['shipping_company'],
|
||||||
|
'shipping_number'=>$input['shipping_number'],
|
||||||
|
'packages'=>[
|
||||||
|
[
|
||||||
|
'order_product_id'=>$afterSale->order_product_id,
|
||||||
|
'quantity' =>$fillQuantity,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
DB::commit();
|
DB::commit();
|
||||||
} catch (Throwable $th) {
|
} catch (Throwable $th) {
|
||||||
DB::rollBack();
|
DB::rollBack();
|
||||||
|
|
@ -58,7 +97,18 @@ class AfterSaleShippingFill extends Form implements LazyRenderable
|
||||||
*/
|
*/
|
||||||
public function form()
|
public function form()
|
||||||
{
|
{
|
||||||
$this->text('remarks', '填写补货物流单号')->required();
|
$this->select('shipping_company', '快递公司')->options([
|
||||||
|
'圆通速递'=>'圆通速递',
|
||||||
|
'韵达快递'=>'韵达快递',
|
||||||
|
'中通快递'=>'中通快递',
|
||||||
|
'申通快递'=>'申通快递',
|
||||||
|
'百世快递'=>'百世快递',
|
||||||
|
'EMS'=>'EMS',
|
||||||
|
'顺丰速运'=>'顺丰速运',
|
||||||
|
'德邦快递'=>'德邦快递',
|
||||||
|
])->required();
|
||||||
|
$this->text('shipping_number', '快递单号')->required();
|
||||||
|
// $this->text('remarks', '填写补货物流单号')->required();
|
||||||
$this->confirm('是否确认补货完成', '该操作不可逆,确认后将完成该售后单。');
|
$this->confirm('是否确认补货完成', '该操作不可逆,确认后将完成该售后单。');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,96 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Forms;
|
||||||
|
|
||||||
|
use App\Exceptions\BizException;
|
||||||
|
use App\Models\Order;
|
||||||
|
use App\Models\OrderPackage;
|
||||||
|
use App\Models\OrderPackageProduct;
|
||||||
|
use Dcat\Admin\Contracts\LazyRenderable;
|
||||||
|
use Dcat\Admin\Traits\LazyWidget;
|
||||||
|
use Dcat\Admin\Widgets\Form;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class OrderPackageEdit extends Form implements LazyRenderable
|
||||||
|
{
|
||||||
|
use LazyWidget;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Model|Authenticatable|HasPermissions|null $user
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function authorize($user): bool
|
||||||
|
{
|
||||||
|
return $user->can('dcat.admin.order_packages.edit_custom');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the form request.
|
||||||
|
*
|
||||||
|
* @param array $input
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle(array $input)
|
||||||
|
{
|
||||||
|
$id = $this->payload['id'] ?? 0;
|
||||||
|
$packageProductId = $input['package_product_id'];
|
||||||
|
$quantity = $input['quantity']??0;
|
||||||
|
|
||||||
|
$orderPackage = OrderPackage::with('order')->findOrFail($id);
|
||||||
|
//如果订单已分润则不处理
|
||||||
|
if ($orderPackage->order->is_settle) {
|
||||||
|
throw new BizException('该发货单已无法修改数量');
|
||||||
|
}
|
||||||
|
//修改的数量不能大于当前数量,只能变小
|
||||||
|
$packageProduct = OrderPackageProduct::findOrFail($packageProductId);
|
||||||
|
if ($quantity == 0) {
|
||||||
|
throw new BizException('修改的数量不能为0');
|
||||||
|
}
|
||||||
|
if ($packageProduct->quantity <= $quantity) {
|
||||||
|
throw new BizException('修改的数量不能大于等于当前数量');
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
//更新当前包裹这个商品数量;
|
||||||
|
$packageProduct->update([
|
||||||
|
'quantity'=>$quantity,
|
||||||
|
]);
|
||||||
|
//回滚对应订单商品待发货数量;
|
||||||
|
$packageProduct->orderProduct->increment('remain_quantity', $packageProduct->quantity - $quantity);
|
||||||
|
|
||||||
|
//如果订单是已确认收货状态,则回滚到发货中;
|
||||||
|
if ($orderPackage->order->isCompleted()) {
|
||||||
|
$orderPackage->order()->update([
|
||||||
|
'status'=>Order::STATUS_PAID,
|
||||||
|
'shipping_state'=>Order::SHIPPING_STATE_PROCESSING,
|
||||||
|
'completed_at'=>null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
$this->select('package_product_id', '包裹商品')
|
||||||
|
->options(OrderPackageProduct::with('orderProduct')->where('order_package_id', $id)->get()->pluck('orderProduct.name', 'id'))
|
||||||
|
->required();
|
||||||
|
$this->number('quantity', '发货数量')->default(1)->min(1)->required();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -25,19 +25,6 @@ class AfterSaleService
|
||||||
*/
|
*/
|
||||||
public function create(User $user, OrderProduct $orderProduct, int $type, int $num, array $params): AfterSale
|
public function create(User $user, OrderProduct $orderProduct, int $type, int $num, array $params): AfterSale
|
||||||
{
|
{
|
||||||
// if (is_null($orderProduct->after_expire_at)) {
|
|
||||||
// throw new BizException('该订单商品还未签收无法发起售后');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // 校验这个订单商品是否还能发起售后-待完成
|
|
||||||
// if ($orderProduct->after_expire_at < now()) {
|
|
||||||
// throw new BizException('该订单商品已过售后时间');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //校验该订单商品不能有已完成、处理中的售后记录
|
|
||||||
// if ($orderProduct->after_sale_state > 0) {
|
|
||||||
// throw new BizException('该订单商品已申请售后');
|
|
||||||
// }
|
|
||||||
if (!$orderProduct->can_after_sale) {
|
if (!$orderProduct->can_after_sale) {
|
||||||
throw new BizException('该订单商品无法发起售后');
|
throw new BizException('该订单商品无法发起售后');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,11 @@ class AdAddressSeeder extends Seeder
|
||||||
'dimensions'=> '',
|
'dimensions'=> '',
|
||||||
'is_show' => true,
|
'is_show' => true,
|
||||||
],
|
],
|
||||||
|
'app_start_page_banner'=>[
|
||||||
|
'name' => 'APP启动页广告位',
|
||||||
|
'dimensions'=> '',
|
||||||
|
'is_show' => true,
|
||||||
|
],
|
||||||
] as $key => $values) {
|
] as $key => $values) {
|
||||||
AdAddress::firstOrCreate(['key' => $key], $values);
|
AdAddress::firstOrCreate(['key' => $key], $values);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue