From 1fc4748f7e5bbd7d4a0dfb4b71b9f6821902d791 Mon Sep 17 00:00:00 2001
From: yaooo <272523191@qq.com>
Date: Wed, 15 Nov 2023 15:09:54 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8F=90=E9=86=92=E7=AE=A1?=
 =?UTF-8?q?=E7=90=86=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../controller/WithdrawController.php         | 96 +++++++++++++++++++
 1 file changed, 96 insertions(+)
 create mode 100644 app/middleapi/controller/WithdrawController.php

diff --git a/app/middleapi/controller/WithdrawController.php b/app/middleapi/controller/WithdrawController.php
new file mode 100644
index 000000000..f66f7325b
--- /dev/null
+++ b/app/middleapi/controller/WithdrawController.php
@@ -0,0 +1,96 @@
+<?php
+
+namespace app\middleapi\controller;
+
+use app\adminapi\lists\finance\WithdrawLists;
+use app\common\logic\finance\WithdrawLogic;
+use app\common\model\user\Withdraw;
+use think\Exception;
+use app\common\controller\BaseLikeAdminController;
+
+class WithdrawController extends BaseLikeAdminController
+{
+
+    public function index()
+    {
+        if(!$this->request->isPost()){
+            return $this->fail('请求方式错误');
+        }
+        $params = $this->request->post(['page_no','page_size', 'order_sn', 'status']);
+        $where = [];
+        if (!empty($params['order_sn'])) {
+            $where[] = ['order_sn', '=', $params['order_sn']];
+        }
+        if (isset($params['status']) && $params['status'] != '') {
+            $where[] = ['status', '=', $params['status']];
+        }
+        $pageNo = !empty($params['page_no']) ? $params['page_no'] : 1;
+        $pageSize = !empty($params['page_size']) ? $params['page_size'] : 20;
+        $lists = Withdraw::where($where)
+            ->append(['s_date', 'e_date', 'company_name'], true)
+            ->with('user')
+            ->withAttr('company_name', function ($value, $data) {
+                $company = Company::where(['admin_id'=>$data['admin_id']])->find();
+                return $company['company_name']??'';
+            })
+            ->withAttr('s_date', function ($value, $data) {
+                $withdrawedCount = Withdraw::where(['user_id'=>$data['user_id'], 'status'=>3])->count();
+                $company = Company::where(['admin_id'=>$data['admin_id']])->find();
+                if ($withdrawedCount == 0) {
+                    $firstUserLog = UserAccountLog::where(['company_id'=>$company['id'] ?? 0])->order('id', 'asc')->find();
+                    return $firstUserLog['create_time'] ?? '';
+                } else {
+                    $withdrawedCount = Withdraw::where(['user_id'=>$data['user_id'], 'status'=>3])->order('id', 'desc')->find();
+                    return $withdrawedCount['transfer_end_cycel'] ?? '';
+                }
+            })
+            ->withAttr('e_date', function ($value, $data) {
+                return date('Y-m-d H:i:s', $data['transfer_end_cycel']);
+            })
+            ->order('id', 'desc')
+            ->page($pageNo, $pageSize)
+            ->select()
+            ->toArray();
+        $count = Withdraw::where($where)->count();
+        $result = [
+            'lists' => $lists,
+            'count' => $count,
+            'page_no' => $pageNo,
+            'page_size' => $pageSize
+        ];
+        return $this->success('请求成功',$result);
+    }
+
+    public function update($id)
+    {
+        $status = $this->request->param('status');
+        if (!in_array($status, [1, 2, 3])) {
+            return $this->fail('参数错误');
+        }
+        $data = Withdraw::find($id);
+        if (empty($data)) {
+            return $this->fail('数据不存在');
+        }
+        $data->status = $status;
+        $data->udpate_time = time();
+        $data->save();
+        return $this->success('操作成功', [], 1, 1);
+    }
+
+    /**
+     * 提现申请审核
+     */
+    public function audit()
+    {
+        try {
+            $params = $this->request->param();
+            $re = WithdrawLogic::audit($params);
+            if (!$re) {
+                return $this->fail(WithdrawLogic::getError());
+            }
+            return $this->success('操作成功', [], 1, 1);
+        } catch (Exception $exception) {
+            return $this->fail($exception->getMessage());
+        }
+    }
+}
\ No newline at end of file