diff --git a/app/Admin/Controllers/DealerOrderController.php b/app/Admin/Controllers/DealerOrderController.php
index 2b52bdcd..429c0666 100644
--- a/app/Admin/Controllers/DealerOrderController.php
+++ b/app/Admin/Controllers/DealerOrderController.php
@@ -11,7 +11,6 @@ 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;
@@ -24,13 +23,6 @@ use Illuminate\Support\Facades\Request;
class DealerOrderController extends AdminController
{
- protected $payWayDots = [
- DealerOrderModel::PAY_WAY_WALLET=>'warning',
- DealerOrderModel::PAY_WAY_OFFLINE=>'danger',
- DealerOrderModel::PAY_WAY_WXPAY=>'success',
- 'none'=>'#b3b9bf',
- ];
-
/**
* Make a grid builder.
*
@@ -57,7 +49,12 @@ class DealerOrderController extends AdminController
$grid->column('total_amount')->prepend('¥');
$statusTexts = DealerOrderStatus::texts();
- $grid->column('pay_way')->using(DealerOrderModel::$payWayText)->label($this->payWayDots);
+ $grid->column('pay_way')->display(function ($v) {
+ if ($v) {
+ return ' '.$v->getDealerOrderText();
+ }
+ return '';
+ });
$grid->column('order_status')->display(function ($v) {
return $this->order_status;
@@ -158,20 +155,34 @@ class DealerOrderController extends AdminController
$show->field('consignor.phone')->as(function ($value) {
return $value ?? '系统';
});
+ $show->html(function () {
+ $content = '';
- $show->field('pay_way', '支付方式')->using(DealerOrderModel::$payWayText)->dot($this->payWayDots);
+ if ($this->pay_way) {
+ $content = ' '.$this->pay_way->getDealerOrderText();
+ }
+
+ return <<
+
+ 支付方式
+
+
+
+
+HTML;
+ });
$show->field('pay_sn', '支付流水号');
$show->field('pay_time', '支付时间');
$show->field('paied_time');
-
- switch ($show->model()->pay_way) {
- case DealerOrderModel::PAY_WAY_OFFLINE:
- $show->field('pay_image')->image();
- break;
-
- case DealerOrderModel::PAY_WAY_WXPAY:
- $show->field('out_trade_no', '外部交易号');
- break;
+ if ($show->model()->isPayWayWxpay()) {
+ $show->field('out_trade_no', '外部交易号');
+ } elseif ($show->model()->isPayWayOffline()) {
+ $show->field('pay_image')->image();
}
$show->field('remark');
$show->divider();
@@ -182,7 +193,7 @@ class DealerOrderController extends AdminController
});
if (
- $show->model()->pay_way === DealerOrderModel::PAY_WAY_OFFLINE &&
+ $show->model()->isPayWayOffline() &&
!in_array($show->model()->order_status, [
DealerOrderStatus::Pending->value, DealerOrderStatus::Cancelled->value,
])
diff --git a/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php b/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php
index 824c0607..82339896 100644
--- a/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php
+++ b/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php
@@ -5,6 +5,7 @@ namespace App\Endpoint\Api\Http\Controllers\Dealer;
use App\Endpoint\Api\Http\Controllers\Controller;
use App\Endpoint\Api\Http\Resources\Dealer\OrderResource;
use App\Endpoint\Api\Http\Resources\Dealer\OrderSimpleResource;
+use App\Enums\PayWay;
use App\Exceptions\BizException;
use App\Exceptions\PayPasswordIncorrectException;
use App\Helpers\Paginator as PaginatorHelper;
@@ -224,17 +225,30 @@ class OrderController extends Controller
'pay_password' => '支付密码',
]);
+ $payWay = PayWay::tryFrom($input['pay_way'] ?? 'offline');
+
+ if (! in_array($payWay, [PayWay::Offline, PayWay::Wallet, PayWay::WxpayH5])) {
+ throw new BizException('支付方式 非法');
+ }
+
$user = $request->user();
$order = $user->dealerOrders()->findOrFail($id);
- $payWay = $input['pay_way'] ?? 'offline';
+ switch ($payWay) {
+ case PayWay::Wallet:
+ if (! $user->wallet?->verifyPassword($input['pay_password'])) {
+ throw new PayPasswordIncorrectException();
+ }
- if (
- $payWay === DealerOrder::PAY_WAY_WALLET &&
- !$user->wallet?->verifyPassword($input['pay_password'])
- ) {
- throw new PayPasswordIncorrectException();
+ break;
+
+ case PayWay::WxpayH5:
+ if ($order->consignor !== null) {
+ throw new BizException('订单不是签约订单');
+ }
+
+ break;
}
try {
diff --git a/app/Enums/PayWay.php b/app/Enums/PayWay.php
new file mode 100644
index 00000000..d0c85a2e
--- /dev/null
+++ b/app/Enums/PayWay.php
@@ -0,0 +1,36 @@
+ '#5b69bc',
+ static::Wallet => '#ff8acc',
+ static::WxpayH5 => '#21b978',
+ default => '#ea5455',
+ };
+ }
+
+ public function getDealerOrderText()
+ {
+ return match ($this) {
+ static::Offline => '线下打款',
+ static::Wallet => '余额支付',
+ static::WxpayH5 => '微信支付',
+ default => 'Unknown',
+ };
+ }
+}
diff --git a/app/Models/DealerOrder.php b/app/Models/DealerOrder.php
index 926583fc..1d8c8243 100644
--- a/app/Models/DealerOrder.php
+++ b/app/Models/DealerOrder.php
@@ -5,6 +5,7 @@ namespace App\Models;
use App\Casts\JsonArray;
use App\Enums\DealerOrderSettleState;
use App\Enums\DealerOrderStatus;
+use App\Enums\PayWay;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use EloquentFilter\Filterable;
use Illuminate\Database\Eloquent\Model;
@@ -14,10 +15,6 @@ class DealerOrder extends Model
use Filterable;
use HasDateTimeFormatter;
- public const PAY_WAY_WALLET = 'wallet'; // 余额
- public const PAY_WAY_OFFLINE = 'offline'; // 线下支付
- public const PAY_WAY_WXPAY = 'wxpay'; // 微信支付
-
protected $attributes = [
'status' => DealerOrderStatus::Pending,
'settle_state' => DealerOrderSettleState::Pending,
@@ -27,6 +24,7 @@ class DealerOrder extends Model
'status' => DealerOrderStatus::class,
'settle_state' => DealerOrderSettleState::class,
'pay_info'=>JsonArray::class,
+ 'pay_way' => PayWay::class,
'pay_time'=> 'datetime',
'paied_time'=>'datetime',
'shipping_time'=>'datetime',
@@ -55,12 +53,6 @@ class DealerOrder extends Model
'out_trade_no',
];
- public static $payWayText = [
- self::PAY_WAY_WALLET => '余额支付',
- self::PAY_WAY_OFFLINE => '线下打款',
- self::PAY_WAY_WXPAY => '微信支付',
- ];
-
/**
* 仅获取待结算的已付款订单
*/
@@ -255,7 +247,29 @@ class DealerOrder extends Model
*/
public function isPayWayOffline(): bool
{
- return $this->pay_way === static::PAY_WAY_OFFLINE;
+ return $this->pay_way === PayWay::Offline;
+ }
+
+ /**
+ * 支付方式是否是余额支付
+ *
+ * @return bool
+ */
+ public function isPayWayWallet(): bool
+ {
+ return $this->pay_way === PayWay::Wallet;
+ }
+
+ /**
+ * 支付方式是否是微信支付
+ *
+ * @return bool
+ */
+ public function isPayWayWxpay(): bool
+ {
+ return in_array($this->pay_way, [
+ PayWay::WxpayH5,
+ ]);
}
/**
diff --git a/app/Services/Dealer/OrderService.php b/app/Services/Dealer/OrderService.php
index 247d44ae..7ee01cca 100644
--- a/app/Services/Dealer/OrderService.php
+++ b/app/Services/Dealer/OrderService.php
@@ -5,6 +5,7 @@ namespace App\Services\Dealer;
use App\Enums\DealerLvl;
use App\Enums\DealerOrderStatus;
use App\Enums\DealerWalletAction;
+use App\Enums\PayWay;
use App\Exceptions\BizException;
use App\Models\DealerOrder;
use App\Models\DealerOrderAllocateLog;
@@ -238,7 +239,7 @@ class OrderService
throw new BizException('无法付款:订单状态异常,请刷新后再试');
}
switch ($payWay) {
- case DealerOrder::PAY_WAY_WALLET:
+ case PayWay::Wallet->value:
/** 付款以及完成确认收款动作 **/
$walletService = new WalletService();
//付款
@@ -246,7 +247,7 @@ class OrderService
$order->update([
'status'=>DealerOrderStatus::Confirming,
'pay_time' => now(),
- 'pay_way' => DealerOrder::PAY_WAY_WALLET,
+ 'pay_way' => PayWay::Wallet,
]);
//收款
if ($order->consignor) {
@@ -254,13 +255,13 @@ class OrderService
}
$this->paidOrder($order);
break;
- case DealerOrder::PAY_WAY_OFFLINE:
+ case PayWay::Offline->value:
$order->update([
'status' => DealerOrderStatus::Confirming,
'pay_image' => $payImage,
'pay_info' => $order->getConsignorPayInfo() ?? null,
'pay_time' => now(),
- 'pay_way' => DealerOrder::PAY_WAY_OFFLINE,
+ 'pay_way' => PayWay::Offline,
]);
break;
}
@@ -271,13 +272,13 @@ class OrderService
* 支付订单
*
* @param DealerOrder $order
- * @param string $payWay
+ * @param \App\Enums\PayWay $payWay
* @param string|null $payImage
* @return array
*
* @throws \App\Exceptions\BizException
*/
- public function pay(DealerOrder $order, string $payWay, ?string $payImage = null): array
+ public function pay(DealerOrder $order, PayWay $payWay, ?string $payImage = null): array
{
if (! $order->isPendinged()) {
throw new BizException('订单状态不是待付款');
@@ -289,7 +290,7 @@ class OrderService
try {
$payLog = $order->payLogs()->create([
'pay_sn' => serial_number(),
- 'pay_way' => $payWay,
+ 'pay_way' => $payWay->value,
]);
} catch (QueryException $e) {
if (strpos($e->getMessage(), 'Duplicate entry') === false) {
diff --git a/app/Services/PayService.php b/app/Services/PayService.php
index 7bb17327..a7e6abc2 100644
--- a/app/Services/PayService.php
+++ b/app/Services/PayService.php
@@ -107,19 +107,13 @@ class PayService
$payable->pay_sn = $payLog->pay_sn;
$payable->pay_time = $payLog->pay_at;
$payable->out_trade_no = $payLog->out_trade_no;
+ $payable->pay_way = $payLog->pay_way;
if ($payLog->isOffline()) {
$payable->pay_image = $params['pay_image'] ?? null;
$payable->pay_info = $params['pay_info'] ?? null;
- $payable->pay_way = DealerOrder::PAY_WAY_OFFLINE;
$payable->status = DealerOrderStatus::Confirming;
} else {
- if ($payLog->isWallet()) {
- $payable->pay_way = DealerOrder::PAY_WAY_WALLET;
- } elseif ($payLog->isWxpay()) {
- $payable->pay_way = DealerOrder::PAY_WAY_WXPAY;
- }
-
$payable->paied_time = $payLog->pay_at;
$payable->status = DealerOrderStatus::Paid;
}