From cfef324f101ae6da7633c662a5a09f8a2523c2df Mon Sep 17 00:00:00 2001
From: vine_liutk <961510893@qq.com>
Date: Wed, 23 Feb 2022 13:41:58 +0800
Subject: [PATCH 1/5] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=90=8E=E5=8F=B0?=
=?UTF-8?q?=E6=8B=92=E7=BB=9D=E6=94=B6=E6=AC=BE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Admin/Forms/DealerOrderRefuse.php | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/app/Admin/Forms/DealerOrderRefuse.php b/app/Admin/Forms/DealerOrderRefuse.php
index c7e0ec34..0525e799 100644
--- a/app/Admin/Forms/DealerOrderRefuse.php
+++ b/app/Admin/Forms/DealerOrderRefuse.php
@@ -40,6 +40,10 @@ class DealerOrderRefuse extends Form
$order->update([
'status' => DealerOrderStatus::Paying,
+ //置空已支付的信息
+ 'pay_way'=> null,
+ 'pay_image'=> null,
+ 'pay_info' => null,
'pay_time' => null,
]);
From 65e34484074876991d8135e3663b44b1375466ca Mon Sep 17 00:00:00 2001
From: vine_liutk <961510893@qq.com>
Date: Wed, 23 Feb 2022 13:43:43 +0800
Subject: [PATCH 2/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8B=92=E7=BB=9D?=
=?UTF-8?q?=E6=94=B6=E6=AC=BE=E7=9A=84=E8=A1=A8=E5=8D=95=E6=8F=90=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Admin/Forms/DealerOrderRefuse.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/Admin/Forms/DealerOrderRefuse.php b/app/Admin/Forms/DealerOrderRefuse.php
index 0525e799..e852922c 100644
--- a/app/Admin/Forms/DealerOrderRefuse.php
+++ b/app/Admin/Forms/DealerOrderRefuse.php
@@ -71,7 +71,7 @@ class DealerOrderRefuse extends Form
*/
public function form()
{
- $this->textarea('reason', '原因')->rules('required|max:255');
+ $this->textarea('reason', '原因')->required()->rules('required|max:255');
}
/**
From 55400515e5fd936ad5f539a265affdc3397e69f1 Mon Sep 17 00:00:00 2001
From: vine_liutk <961510893@qq.com>
Date: Wed, 23 Feb 2022 14:52:27 +0800
Subject: [PATCH 3/5] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E4=BC=98=E5=8C=96?=
=?UTF-8?q?=E8=B0=83=E6=95=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Admin/Controllers/DealerController.php | 3 ++-
app/Admin/Controllers/DealerOrderController.php | 6 +++++-
app/Admin/Metrics/StatisticsTotal.php | 6 ++++++
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/app/Admin/Controllers/DealerController.php b/app/Admin/Controllers/DealerController.php
index 42c0251c..3bc35c43 100644
--- a/app/Admin/Controllers/DealerController.php
+++ b/app/Admin/Controllers/DealerController.php
@@ -88,8 +88,9 @@ class DealerController extends AdminController
$grid->filter(function (Grid\Filter $filter) {
$filter->panel();
$filter->equal('user.phone')->width(3);
- $filter->equal('userInfo.nickname')->width(3);
$filter->equal('userInfo.inviterInfo.user.phone')->width(3);
+ $filter->equal('userInfo.realInviterInfo.user.phone')->width(3);
+ $filter->equal('userInfo.nickname')->width(4);
});
});
}
diff --git a/app/Admin/Controllers/DealerOrderController.php b/app/Admin/Controllers/DealerOrderController.php
index 1181807c..2b52bdcd 100644
--- a/app/Admin/Controllers/DealerOrderController.php
+++ b/app/Admin/Controllers/DealerOrderController.php
@@ -107,7 +107,11 @@ class DealerOrderController extends AdminController
$actions->append(new DealerOrderShipping());
}
}
- if ($actions->row->isPending() && Admin::user()->can('dcat.admin.dealer_orders.cancel')) {
+ if ((
+ $actions->row->isPending() //待确认
+ || $actions->row->isPay() //待付款
+ || $actions->row->isPaid() //待收款
+ ) && Admin::user()->can('dcat.admin.dealer_orders.cancel')) {
$actions->append(new DealerOrderCancel());
}
});
diff --git a/app/Admin/Metrics/StatisticsTotal.php b/app/Admin/Metrics/StatisticsTotal.php
index 16a095a4..22741b72 100644
--- a/app/Admin/Metrics/StatisticsTotal.php
+++ b/app/Admin/Metrics/StatisticsTotal.php
@@ -3,6 +3,7 @@
namespace App\Admin\Metrics;
use App\Models\Balance;
+use App\Models\DealerWallet;
use App\Models\DistributionPreIncome;
use App\Models\UserInfo;
use App\Models\Wallet;
@@ -40,6 +41,7 @@ class StatisticsTotal extends RadialBar
'total_distribution'=> DistributionPreIncome::unsettlement()->sum('total_revenue'),
'total_quota_v2' => UserInfo::sum('quota_v2'),
'total_quota_v1' => UserInfo::sum('quota_v1'),
+ 'total_dealer_wallet' => bcdiv(DealerWallet::sum('balance'), 100, 2),
]);
}
@@ -82,6 +84,10 @@ class StatisticsTotal extends RadialBar
{$content['total_quota_v1']}
老配额
+
+
{$content['total_dealer_wallet']}
+ 批零余额
+
HTML
);
From d0ca429c4c692d5dfa2009173a60578f239e34c1 Mon Sep 17 00:00:00 2001
From: vine_liutk <961510893@qq.com>
Date: Wed, 23 Feb 2022 14:53:17 +0800
Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Admin/Metrics/StatisticsTotal.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/Admin/Metrics/StatisticsTotal.php b/app/Admin/Metrics/StatisticsTotal.php
index 22741b72..ca6649a6 100644
--- a/app/Admin/Metrics/StatisticsTotal.php
+++ b/app/Admin/Metrics/StatisticsTotal.php
@@ -41,7 +41,7 @@ class StatisticsTotal extends RadialBar
'total_distribution'=> DistributionPreIncome::unsettlement()->sum('total_revenue'),
'total_quota_v2' => UserInfo::sum('quota_v2'),
'total_quota_v1' => UserInfo::sum('quota_v1'),
- 'total_dealer_wallet' => bcdiv(DealerWallet::sum('balance'), 100, 2),
+ 'total_dealer_wallet' => bcdiv(DealerWallet::sum('balance'), 1, 2),
]);
}
From a232275dd08adb9767f623ce7efc08654e33267e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?=
Date: Wed, 23 Feb 2022 16:10:46 +0800
Subject: [PATCH 5/5] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=89=B9=E9=9B=B6?=
=?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=94=AF=E4=BB=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Controllers/DealerOrderController.php | 51 +++++++++++--------
.../Controllers/Dealer/OrderController.php | 26 +++++++---
app/Enums/PayWay.php | 36 +++++++++++++
app/Models/DealerOrder.php | 36 +++++++++----
app/Services/Dealer/OrderService.php | 15 +++---
app/Services/PayService.php | 8 +--
6 files changed, 121 insertions(+), 51 deletions(-)
create mode 100644 app/Enums/PayWay.php
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;
}