添加批零订单余额支付
parent
ba5d4283bb
commit
056e8f0833
|
|
@ -10,6 +10,7 @@ use App\Admin\Actions\Show\DealerOrderRemark;
|
|||
use App\Admin\Repositories\DealerOrder;
|
||||
use App\Enums\DealerOrderStatus;
|
||||
use App\Models\DealerChannelSubsidyLog;
|
||||
use App\Models\DealerOrder as DealerOrderModel;
|
||||
use App\Models\DealerOrderProduct;
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Form;
|
||||
|
|
@ -48,6 +49,12 @@ class DealerOrderController extends AdminController
|
|||
$grid->column('total_amount')->prepend('¥');
|
||||
$statusTexts = DealerOrderStatus::texts();
|
||||
|
||||
$grid->column('pay_way')->using(DealerOrderModel::$payWayText)->label([
|
||||
'wallet'=>'warning',
|
||||
'offline'=>'danger',
|
||||
'none'=>'#b3b9bf',
|
||||
]);
|
||||
|
||||
$grid->column('order_status')->display(function ($v) {
|
||||
return $this->order_status;
|
||||
})->using($statusTexts)->dot([
|
||||
|
|
|
|||
|
|
@ -138,8 +138,21 @@ class OrderController extends Controller
|
|||
|
||||
$input = $request->validate([
|
||||
'pay_image' => ['bail', 'string'],
|
||||
'pay_way' => ['bail', 'string'],
|
||||
]);
|
||||
$orderService->payOrder($order, $input['pay_image'] ?? null);
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$orderService->payOrder($order, $input['pay_way'] ?? 'offline', $input['pay_image'] ?? null);
|
||||
DB::commit();
|
||||
} catch (BizException $th) {
|
||||
DB::rollBack();
|
||||
throw $th;
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
throw new BizException('操作失败,请刷新后再试');
|
||||
}
|
||||
|
||||
return response()->noContent();
|
||||
}
|
||||
|
||||
|
|
@ -166,7 +179,40 @@ class OrderController extends Controller
|
|||
if (strpos($e->getMessage(), 'Numeric value out of range') !== false) {
|
||||
$e = new BizException('当前可发货库存不足');
|
||||
}
|
||||
throw $e;
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
throw new BizException('操作失败,请刷新后再试');
|
||||
}
|
||||
return response()->noContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认发货
|
||||
*
|
||||
* @param [type] $id
|
||||
* @param Request $request
|
||||
* @param OrderService $orderService
|
||||
* @return void
|
||||
*/
|
||||
public function shippingOrder($id, Request $request, OrderService $orderService)
|
||||
{
|
||||
$order = DealerOrder::findOrFail($id);
|
||||
$userId = $request->user()->id;
|
||||
//不是发货人
|
||||
if (!$order->isConsignor($userId)) {
|
||||
throw new BizException('订单未找到');
|
||||
}
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$orderService->shippingOrder($order);//确认发货
|
||||
DB::commit();
|
||||
} catch (QueryException $e) {
|
||||
DB::rollBack();
|
||||
if (strpos($e->getMessage(), 'Numeric value out of range') !== false) {
|
||||
$e = new BizException('当前可发货库存不足');
|
||||
}
|
||||
throw $e;
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
|
|
|
|||
|
|
@ -250,8 +250,10 @@ Route::group([
|
|||
Route::post('orders/{order}/confirm', [Dealer\OrderController::class, 'confirmOrder']);
|
||||
//确认打款
|
||||
Route::post('orders/{order}/pay', [Dealer\OrderController::class, 'payOrder']);
|
||||
//确认收款
|
||||
//确认收款+发货
|
||||
Route::post('orders/{order}/paid', [Dealer\OrderController::class, 'paidOrder']);
|
||||
//确认发货
|
||||
Route::post('orders/{order}/shipping', [Dealer\OrderController::class, 'shippingOrder']);
|
||||
//确认收货
|
||||
Route::post('orders/{order}/shippinged', [Dealer\OrderController::class, 'shippingedOrder']);
|
||||
//取消订单
|
||||
|
|
|
|||
|
|
@ -9,4 +9,6 @@ enum DealerWalletAction: int {
|
|||
case ChannelSubsidyIn = 4;
|
||||
case WithdrawBank = 5;
|
||||
case WithdrawFiled = 6;
|
||||
case OrderPaid = 7;
|
||||
case OrderIncome = 8;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@ class DealerOrder extends Model
|
|||
use Filterable;
|
||||
use HasDateTimeFormatter;
|
||||
|
||||
public const PAY_WAY_WALLET = 'wallet'; // 余额
|
||||
public const PAY_WAY_OFFLINE = 'offline'; // 线下支付
|
||||
|
||||
protected $attributes = [
|
||||
'status' => DealerOrderStatus::Pending,
|
||||
'settle_state' => DealerOrderSettleState::Pending,
|
||||
|
|
@ -40,6 +43,7 @@ class DealerOrder extends Model
|
|||
'consignee_telephone',
|
||||
'consignee_zone',
|
||||
'consignee_address',
|
||||
'pay_way',
|
||||
'pay_time',
|
||||
'paied_time',
|
||||
'shipping_time',
|
||||
|
|
@ -48,6 +52,11 @@ class DealerOrder extends Model
|
|||
'remark',
|
||||
];
|
||||
|
||||
public static $payWayText = [
|
||||
self::PAY_WAY_WALLET => '余额支付',
|
||||
self::PAY_WAY_OFFLINE => '线下打款',
|
||||
];
|
||||
|
||||
/**
|
||||
* 仅获取待结算的已付款订单
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace App\Services\Dealer;
|
|||
|
||||
use App\Enums\DealerLvl;
|
||||
use App\Enums\DealerOrderStatus;
|
||||
use App\Enums\DealerWalletAction;
|
||||
use App\Exceptions\BizException;
|
||||
use App\Models\DealerOrder;
|
||||
use App\Models\DealerOrderAllocateLog;
|
||||
|
|
@ -136,17 +137,41 @@ class OrderService
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function payOrder(DealerOrder $order, ?string $payImage)
|
||||
public function payOrder(DealerOrder $order, string $payWay, ?string $payImage)
|
||||
{
|
||||
if (empty($payWay)) {
|
||||
throw new BizException('请选择付款方式');
|
||||
}
|
||||
if (!$order->isPendinged()) {
|
||||
throw new BizException('订单状态异常,请刷新后再试');
|
||||
}
|
||||
$order->update([
|
||||
'status' => DealerOrderStatus::Confirming,
|
||||
'pay_image' => $payImage,
|
||||
'pay_info' => $order->getConsignorPayInfo() ?? null,
|
||||
'pay_time' => now(),
|
||||
]);
|
||||
switch ($payWay) {
|
||||
case DealerOrder::PAY_WAY_WALLET:
|
||||
/** 付款以及完成确认收款动作 **/
|
||||
$walletService = new WalletService();
|
||||
//付款
|
||||
$walletService->changeBalance($order->user, 0 - $order->total_amount, DealerWalletAction::OrderPaid, '订单:'.$order->sn, $order);
|
||||
$order->update([
|
||||
'status'=>DealerOrderStatus::Confirming,
|
||||
'pay_time' => now(),
|
||||
'pay_way' => DealerOrder::PAY_WAY_WALLET,
|
||||
]);
|
||||
//收款
|
||||
if ($order->consignor) {
|
||||
$walletService->changeBalance($order->consignor, $order->total_amount, DealerWalletAction::OrderIncome, '订单:'.$order->sn, $order);
|
||||
}
|
||||
$this->paidOrder($order);
|
||||
break;
|
||||
case DealerOrder::PAY_WAY_OFFLINE:
|
||||
$order->update([
|
||||
'status' => DealerOrderStatus::Confirming,
|
||||
'pay_image' => $payImage,
|
||||
'pay_info' => $order->getConsignorPayInfo() ?? null,
|
||||
'pay_time' => now(),
|
||||
'pay_way' => DealerOrder::PAY_WAY_OFFLINE,
|
||||
]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddPayWayToDealerOrdersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('dealer_orders', function (Blueprint $table) {
|
||||
//
|
||||
$table->string('pay_way')->nullable()->comment('1线下打款,2余额');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('dealer_orders', function (Blueprint $table) {
|
||||
//
|
||||
$table->dropColumn('pay_way');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -33,6 +33,7 @@ return [
|
|||
'consignee_address' => '收货人详细地址',
|
||||
'pay_info' => '收款信息',
|
||||
'pay_image' => '打款凭证',
|
||||
'pay_way'=>'支付方式',
|
||||
'pay_time' => '支付时间',
|
||||
'paied_time' => '确认收款时间',
|
||||
'shipping_time' => '发货时间',
|
||||
|
|
|
|||
Loading…
Reference in New Issue