|
@@ -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();
|
|
|
+ }
|
|
|
+
|
|
|
}
|