diff --git a/app/Admin/Controllers/DealerWalletToBankLogController.php b/app/Admin/Controllers/DealerWalletToBankLogController.php
index 60072123..1a145466 100644
--- a/app/Admin/Controllers/DealerWalletToBankLogController.php
+++ b/app/Admin/Controllers/DealerWalletToBankLogController.php
@@ -6,6 +6,7 @@ use App\Admin\Actions\Grid\Exports\DealerWalletWithdraw;
use App\Admin\Actions\Show\DealerWalletPay;
use App\Admin\Actions\Show\DealerWalletRefuse;
use App\Admin\Repositories\DealerWalletToBankLog;
+use App\Enums\DealerWalletToBankLogStatus;
use App\Models\DealerWalletToBankLog as DealerWalletToBankLogModel;
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
use Dcat\Admin\Admin;
@@ -14,6 +15,7 @@ use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Show;
use Illuminate\Http\Request;
+use Illuminate\Support\Arr;
class DealerWalletToBankLogController extends AdminController
{
@@ -35,19 +37,16 @@ class DealerWalletToBankLogController extends AdminController
$grid->column('rate')->append('%');
$grid->column('service_amount')->prepend('¥');
$grid->column('account_amount')->prepend('¥');
- $grid->column('status')->using([
- DealerWalletToBankLogModel::STATUS_PENDING=>'待处理',
- DealerWalletToBankLogModel::STATUS_AGREE=>'同意',
- DealerWalletToBankLogModel::STATUS_REFUSE=>'拒绝',
- ])->dot([
- 0=>'primary',
- 1=>'success',
- 2=>'danger',
- ])->filter(Grid\Column\Filter\In::make([
- DealerWalletToBankLogModel::STATUS_PENDING=>'待处理',
- DealerWalletToBankLogModel::STATUS_AGREE=>'同意',
- DealerWalletToBankLogModel::STATUS_REFUSE=>'拒绝',
- ]));
+ $grid->column('status')->display(function ($v) {
+ $text = $v->text();
+ $background = $v->color();
+
+ return " {$text}";
+ })->filter(Grid\Column\Filter\In::make(Arr::except(DealerWalletToBankLogStatus::texts(), [
+ DealerWalletToBankLogStatus::Failed->value,
+ DealerWalletToBankLogStatus::Passed->value,
+ DealerWalletToBankLogStatus::Paying->value,
+ ])));
$grid->column('remarks');
$grid->column('created_at')->sortable();
// $grid->column('updated_at')
@@ -62,11 +61,6 @@ class DealerWalletToBankLogController extends AdminController
$grid->filter(function (Grid\Filter $filter) {
$filter->panel();
- // $filter->equal('status')->select([
- // DealerWalletToBankLogModel::STATUS_PENDING=>'待处理',
- // DealerWalletToBankLogModel::STATUS_AGREE=>'已同意',
- // DealerWalletToBankLogModel::STATUS_REFUSE=>'已拒绝',
- // ])->width(3);
$filter->equal('user.phone')->width(3);
$filter->between('created_at')->dateTime()->width(7);
});
@@ -90,15 +84,12 @@ class DealerWalletToBankLogController extends AdminController
$show->field('rate')->append('%');
$show->field('service_amount')->prepend('¥');
$show->field('account_amount')->prepend('¥');
- $show->field('status')->using([
- DealerWalletToBankLogModel::STATUS_PENDING=>'待处理',
- DealerWalletToBankLogModel::STATUS_AGREE=>'同意',
- DealerWalletToBankLogModel::STATUS_REFUSE=>'拒绝',
- ])->dot([
- 0=>'primary',
- 1=>'success',
- 2=>'danger',
- ]);
+ $show->field('status')->as(function ($v) {
+ $text = $this->status->text();
+ $background = $this->status->color();
+
+ return " {$text}";
+ });
$show->field('pay_image')->image();
$show->field('remarks');
$show->divider('收款信息-银行');
@@ -214,17 +205,13 @@ class DealerWalletToBankLogController extends AdminController
break;
}
}
- $statusArr = [
- DealerWalletToBankLogModel::STATUS_PENDING=>'待处理',
- DealerWalletToBankLogModel::STATUS_AGREE=>'同意',
- DealerWalletToBankLogModel::STATUS_REFUSE=>'拒绝',
- ];
+
foreach ($query->cursor() as $log) {
$payInfo = $log->getPayInfo();
$writer->addRow(WriterEntityFactory::createRowFromArray([
$log->user->phone,
$log->account_amount,
- $statusArr[$log->status],
+ $log->status->text(),
$payInfo ? $payInfo['bank']['user_name'] : '',
$payInfo ? $payInfo['bank']['bank_name'] : '',
$payInfo ? $payInfo['bank']['bank_number'] : '',
diff --git a/app/Admin/Forms/DealerWalletPay.php b/app/Admin/Forms/DealerWalletPay.php
index 1435d19c..e3f96381 100644
--- a/app/Admin/Forms/DealerWalletPay.php
+++ b/app/Admin/Forms/DealerWalletPay.php
@@ -2,6 +2,7 @@
namespace App\Admin\Forms;
+use App\Enums\DealerWalletToBankLogStatus;
use App\Models\DealerWalletToBankLog;
use Carbon\Carbon;
use Dcat\Admin\Contracts\LazyRenderable;
@@ -40,8 +41,8 @@ class DealerWalletPay extends Form implements LazyRenderable
$log = DealerWalletToBankLog::findOrFail($id);
$log->update([
'pay_info' => $log->getPayInfo(),
- 'pay_image' => $input['pay_image']??null,
- 'status' => DealerWalletToBankLog::STATUS_AGREE,
+ 'pay_image' => $input['pay_image'] ?? null,
+ 'status' => DealerWalletToBankLogStatus::Success,
]);
DB::commit();
} catch (Throwable $th) {
diff --git a/app/Admin/Forms/DealerWalletRefuse.php b/app/Admin/Forms/DealerWalletRefuse.php
index d441b990..973d727b 100644
--- a/app/Admin/Forms/DealerWalletRefuse.php
+++ b/app/Admin/Forms/DealerWalletRefuse.php
@@ -3,6 +3,7 @@
namespace App\Admin\Forms;
use App\Enums\DealerWalletAction;
+use App\Enums\DealerWalletToBankLogStatus;
use App\Models\DealerWalletToBankLog;
use App\Services\Dealer\WalletService;
use Dcat\Admin\Contracts\LazyRenderable;
@@ -40,8 +41,8 @@ class DealerWalletRefuse extends Form implements LazyRenderable
DB::beginTransaction();
$log = DealerWalletToBankLog::findOrFail($id);
$log->update([
- 'remark' => $input['remark']??'',
- 'status' => DealerWalletToBankLog::STATUS_REFUSE,
+ 'remark' => $input['remark'] ?? '',
+ 'status' => DealerWalletToBankLogStatus::Refused,
]);
//打回余额
$walletService = new WalletService();
diff --git a/app/Enums/DealerWalletToBankLogStatus.php b/app/Enums/DealerWalletToBankLogStatus.php
new file mode 100644
index 00000000..ccfc4cb1
--- /dev/null
+++ b/app/Enums/DealerWalletToBankLogStatus.php
@@ -0,0 +1,50 @@
+ '#5b69bc',
+ static::Passed => '#dda451',
+ static::Paying => '#3085d6',
+ static::Success => '#21b978',
+ static::Failed => '#ea5455',
+ static::Refused => '#b3b9bf',
+ };
+ }
+
+ /**
+ * @return string
+ */
+ public function text(): string
+ {
+ return static::texts()[$this->value];
+ }
+
+ /**
+ * @return array
+ */
+ public static function texts(): array
+ {
+ return [
+ static::Pending->value => '待处理',
+ static::Passed->value => '待付款',
+ static::Paying->value => '付款中',
+ static::Success->value => '成功',
+ static::Failed->value => '失败',
+ static::Refused->value => '拒绝',
+ ];
+ }
+}
diff --git a/app/Models/DealerWalletToBankLog.php b/app/Models/DealerWalletToBankLog.php
index e440c421..90d3eed6 100644
--- a/app/Models/DealerWalletToBankLog.php
+++ b/app/Models/DealerWalletToBankLog.php
@@ -2,6 +2,7 @@
namespace App\Models;
+use App\Enums\DealerWalletToBankLogStatus;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@@ -11,9 +12,9 @@ class DealerWalletToBankLog extends Model
use HasFactory;
use HasDateTimeFormatter;
- public const STATUS_PENDING = 0;//'待处理'
- public const STATUS_AGREE = 1;//'已同意'
- public const STATUS_REFUSE = 2;//'已拒绝'
+ protected $casts = [
+ 'status' => DealerWalletToBankLogStatus::class,
+ ];
/**
* @var array
@@ -49,7 +50,7 @@ class DealerWalletToBankLog extends Model
*/
public function isPending()
{
- return $this->status == self::STATUS_PENDING;
+ return $this->status === DealerWalletToBankLogStatus::Pending;
}
/**