-
Notifications
You must be signed in to change notification settings - Fork 3
/
cb.go
111 lines (104 loc) · 3.84 KB
/
cb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2018. box.la authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package controllers
import (
"github.com/gin-gonic/gin"
"database/sql"
log "github.com/alecthomas/log4go"
"github.com/boxproject/appServerGo/models"
"net/http"
"github.com/boxproject/appServerGo/utils"
"strings"
"github.com/satori/go.uuid"
)
// 代理服务器通知临时提现结果
func WithdrawResultOfID(ctx *gin.Context) {
wdhash := ctx.PostForm("wd_hash")
txid := ctx.PostForm("tx_id")
log.Info("代理服务器通知临时提现结果:", gin.H{"wd_hash": wdhash, "tx_id": txid})
if wdhash != "" && txid != "" {
// 获取该笔转账记录详情
txInfo, err := models.GetTransferInfoByWdHash(wdhash)
if err != nil && err != sql.ErrNoRows {
log.Error("代理通知提现结果", err)
utils.RetError(ctx, ERROR_CODE)
return
}
if err != sql.ErrNoRows && txInfo.Arrived != 2 {
// 插入本地数据库 tb_transfer_history,set progress = 1
err = models.AddTempTransferArrivedInfo(wdhash, txid, 1)
if err != nil {
log.Error("代理服务器通知最终提现结果插入记录错误", err)
utils.RetError(ctx, ERROR_CODE)
return
}
}
}
ctx.JSON(http.StatusOK, gin.H{"code": 0, "message": utils.ReadJsonFile(ctx)["NOTICE"]})
}
// 代理服务器通知最终提现信息
func WithdrawResult(ctx *gin.Context) {
wdhash := ctx.PostForm("wd_hash")
txid := ctx.PostForm("tx_id")
if wdhash != "" && txid != "" {
log.Info("代理服务器通知最终提现结果:", gin.H{"wd_hash": wdhash, "tx_id": txid})
// 获取该笔转账记录详情
txInfo, err := models.GetTransferInfoByWdHash(wdhash)
if err != nil && err != sql.ErrNoRows {
log.Error("WithdrawResult")
utils.RetError(ctx, ERROR_CODE)
return
}
if err != sql.ErrNoRows && txInfo.Arrived == 1 {
// 插入本地数据库 tb_transfer_history,set progress = 2
err = models.AddTransferArrivedInfo(txInfo, wdhash, txid, 2)
if err != nil {
log.Error("代理服务器通知最终提现结果插入记录错误", err)
utils.RetError(ctx, ERROR_CODE)
return
}
}
}
ctx.JSON(http.StatusOK, gin.H{"code": 0, "message": utils.ReadJsonFile(ctx)["NOTICE"]})
}
// 代理服务器上报充值记录
func DepositSuccess(ctx *gin.Context) {
fromAddr := ctx.PostForm("from")
toAddr := ctx.PostForm("to")
amount := ctx.PostForm("amount")
txID := ctx.PostForm("tx_id")
currencyID := ctx.PostForm("category")
log.Info("代理服务器通知充值结果", gin.H{"fromAddr": fromAddr, "toAddr": toAddr, "amount": amount, "txID": txID, "currencyID": currencyID})
if fromAddr == "" || toAddr == "" || amount == "" || txID == "" || currencyID == "" {
log.Error("DepositSuccess")
utils.RetError(ctx, ERROR_CODE+1)
return
}
// 获取币种信息
currencyInfo, _ := models.GetCurrencyInfoByID(currencyID)
fromArry := strings.Split(fromAddr, ",")
orderNum := uuid.Must(uuid.NewV4()).String()
// 记录充值记录并更新余额
err := models.DepositHistory(orderNum, toAddr, amount, txID, currencyInfo.CurrencyID, fromArry)
if err != nil {
log.Error("代理服务器上报充值记录落库", err)
utils.RetError(ctx, ERROR_CODE)
return
}
ctx.JSON(http.StatusOK, gin.H{"code": 0, "message": utils.ReadJsonFile(ctx)["NOTICE"]})
}
// 添加代币
func AddCurrency(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{"code": 0, "message": utils.ReadJsonFile(ctx)["NOTICE"]})
}