Forráskód Böngészése

feat(wechatpay): 实现转账单列表与状态刷新功能

- 新增转账单列表接口,支持分页和筛选
- 添加转账单统计信息获取方法
- 实现单个转账单状态刷新接口
- 配置路由支持刷新操作并添加宏页面中间件
- 完善模型搜索器支持状态和单号查询
- 控制器注入依赖并返回标准化响应数据
runphp 4 hónapja
szülő
commit
eb527e9cd3

+ 5 - 2
route/admin.php

@@ -3,6 +3,7 @@ declare(strict_types=1);
 
 use think\facade\Route;
 use SixShop\WechatPay\Controller\TransferBillController;
+use SixShop\System\Middleware\MacroPageMiddleware;
 
 // API路由
 // 路由前缀: /admin/wechatpay
@@ -10,6 +11,8 @@ use SixShop\WechatPay\Controller\TransferBillController;
 // 如果需要登录请添加认证中间件auth
 // ->middleware(['auth'])
 
-Route::resource('transfer_bill', TransferBillController::class)
+Route::resource('transfer_bill', TransferBillController::class, function (){
+    Route::get('refresh', [TransferBillController::class, 'refresh']);
+})
     ->only(['index'])
-    ->middleware(['auth']);
+    ->middleware(['auth', MacroPageMiddleware::class]);

+ 19 - 6
src/Controller/TransferBillController.php

@@ -2,15 +2,28 @@
 declare(strict_types=1);
 namespace SixShop\WechatPay\Controller;
 
+use SixShop\Core\Request;
+use SixShop\WechatPay\Entity\WechatpayTransferBillEntity;
+use SixShop\WechatPay\Enum\TransferBillStatusEnum;
+use function SixShop\Core\page_response;
+
 class TransferBillController
 {
-    public function index()
+    public function index(Request $request, WechatpayTransferBillEntity $transferBillEntity)
     {
-        // todo
-        return json([
-            'code' => 0,
-            'msg' => 'success',
-            'data' => [],
+        $params = $request->get([
+            'state/s' => 'all',
+            'out_bill_no/s' => '',
         ]);
+        $page = $request->pageAndLimit();
+        $stats = $transferBillEntity->getTransferBillStats($params);
+        return page_response(
+            page:$transferBillEntity->getTransferBillList($params, $page)
+        );
+    }
+
+    public function refresh(int $id, WechatpayTransferBillEntity $transferBillEntity)
+    {
+        return success_response($transferBillEntity->refreshTransferBill($id));
     }
 }

+ 21 - 4
src/Entity/WechatpayTransferBillEntity.php

@@ -4,13 +4,30 @@ namespace SixShop\WechatPay\Entity;
 
 
 use SixShop\Core\Entity\BaseEntity;
+use think\Paginator;
 
+/**
+ * @mixin \SixShop\WechatPay\Model\WechatpayTransferBillModel
+ */
 class WechatpayTransferBillEntity extends BaseEntity
 {
-    protected function getOptions(): array
+    public function getTransferBillList(array $params, array $page): Paginator
     {
-        return [
-            'name' => 'wechatpay_transfer_bill',
-        ];
+        $query = $this->withSearch(['state', 'out_bill_no'], $params);
+        return $query->order('id', 'desc')->paginate($page);
+    }
+
+    public function getTransferBillStats(array $params): array
+    {
+        return $this->field('state, count(*) as count, sum(transfer_amount) as amount')
+            ->group('state')
+            ->select()
+            ->toArray();
+    }
+
+    public function refreshTransferBill(int $id): array
+    {
+        // todo: 刷新转账单状态
+        return $this->find($id)->toArray();
     }
 }

+ 16 - 0
src/Model/WechatpayTransferBillModel.php

@@ -2,6 +2,7 @@
 declare(strict_types=1);
 namespace SixShop\WechatPay\Model;
 
+use think\db\Query;
 use think\Model;
 use SixShop\WechatPay\Enum\TransferBillStatusEnum;
 
@@ -16,4 +17,19 @@ class WechatpayTransferBillModel extends Model
             ],
         ];
     }
+
+    public function searchStateAttr(Query $query, $value)
+    {
+        $value = TransferBillStatusEnum::tryFrom($value);
+        if ($value) {
+            $query->where('state', $value);
+        }
+    }
+
+    public function searchOutBillNoAttr(Query $query, $value)
+    {
+        if ($value) {
+            $query->where('out_bill_no', $value);
+        }
+    }
 }