Ver código fonte

Fixed 提现修正

程旭源 1 ano atrás
pai
commit
2474d28595

+ 84 - 0
application/admin/controller/greenroom/Withdrawal.php

@@ -2,7 +2,14 @@
 
 namespace app\admin\controller\greenroom;
 
+use app\admin\controller\auth\Admin;
 use app\common\controller\Backend;
+use think\Db;
+use think\Env;
+use think\exception\DbException;
+use think\exception\PDOException;
+use think\exception\ValidateException;
+use Udun\Dispatch\UdunDispatch;
 
 /**
  * 
@@ -18,9 +25,18 @@ class Withdrawal extends Backend
      */
     protected $model = null;
 
+    protected $udunDispatch = null;
+
     public function _initialize()
     {
         parent::_initialize();
+        $this->udunDispatch = new UdunDispatch([
+            'merchant_no' => Env::get("udun.mech_no"), //商户号
+            'api_key' => Env::get("udun.api_key"),//apikey
+            'gateway_address'=>Env::get("udun.host","https://sig10.udun.io"), //节点
+            'callUrl'=>Env::get("udun.callback_url", "https://www.advcover.xyz/admin/index/udun_callback"), //回调地址
+            'debug' => false  //调试模式
+        ]);
         $this->model = new \app\admin\model\greenroom\Withdrawal;
         $this->view->assign("statusList", $this->model->getStatusList());
     }
@@ -68,4 +84,72 @@ class Withdrawal extends Backend
         return $this->view->fetch();
     }
 
+    /**
+     * 编辑
+     *
+     * @param $ids
+     * @return string
+     * @throws DbException
+     * @throws \think\Exception
+     */
+    public function edit($ids = null)
+    {
+        $row = $this->model->get($ids);
+        if (!$row) {
+            $this->error(__('No Results were found'));
+        }
+        $adminIds = $this->getDataLimitAdminIds();
+        if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
+            $this->error(__('You have no permission'));
+        }
+        if (false === $this->request->isPost()) {
+            $this->view->assign('row', $row);
+            return $this->view->fetch();
+        }
+        $params = $this->request->post('row/a');
+        if (empty($params)) {
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        $params = $this->preExcludeFields($params);
+        $result = false;
+        Db::startTrans();
+        try {
+            //是否采用模型验证
+            if ($this->modelValidate) {
+                $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
+                $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
+                $row->validateFailException()->validate($validate);
+            }
+
+            if ($params['status'] == 2) {
+                $accountResult = $this->udunDispatch->checkAddress(195, $row->account);
+                if ($accountResult['code'] != 200) {
+                    // 转账地址不合法
+                    $row->status = 0; // 自动拒绝 转账地址不合法
+                    Admin::where("id", $row->uid)->setInc("money", $row->amount);
+                    Db::commit();
+                    return $this->error('提现地址不正确');
+                }
+
+                $result = $this->udunDispatch->withdraw($row->id, "195", "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",$row->account, bcsub($row->amount, "3", 4),  "提现");
+
+                if ($result['code'] != 200) {
+                    Db::rollback();
+                    return $this->error($result['message']);
+                }
+            }
+
+
+            $result = $row->allowField("status")->save($params);
+            Db::commit();
+        } catch (ValidateException|PDOException|Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        if (false === $result) {
+            $this->error(__('No rows were updated'));
+        }
+        $this->success();
+    }
+
 }

+ 4 - 3
composer.json

@@ -30,13 +30,14 @@
         "ext-curl": "*",
         "ext-pdo": "*",
         "ext-bcmath": "*",
-        "txthinking/mailer": "^2.0"
+        "txthinking/mailer": "^2.0",
+        "uduncloud/udun-wallet-sdk": "^1.0"
     },
     "config": {
         "preferred-install": "dist",
         "allow-plugins": {
-            "easywechat-composer/easywechat-composer": true,
-            "topthink/think-installer": true
+            "topthink/think-installer": true,
+            "easywechat-composer/easywechat-composer": true
         }
     }
 }

+ 1 - 1
public/assets/js/backend/greenroom/withdrawal.js

@@ -30,7 +30,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                         {field: 'addtime', title: __('Addtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                         {field: 'uid', title: __('Uid')},
                         {field: 'account', title: __('Account'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
-                        {field: 'status', title: __('状态'), searchList: {"1":__('申请中'),"2":__('已完成')}, formatter: Table.api.formatter.status},
+                        {field: 'status', title: __('状态'), searchList: {"0":__('已驳回'),"1":__('申请中'),"2":__('审核通过'),"3":__('已完成')}, formatter: Table.api.formatter.status},
                         {field: 'admin.username', title: __('Admin.username'), operate: 'LIKE'},
                         {field: 'admin.nickname', title: __('Admin.nickname'), operate: 'LIKE'},
                         {field: 'admin.appname', title: __('Admin.appname'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},