topup.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. package controller
  2. import (
  3. "fmt"
  4. "net/http"
  5. "net/url"
  6. "strconv"
  7. "sync"
  8. "time"
  9. "github.com/QuantumNous/new-api/common"
  10. "github.com/QuantumNous/new-api/logger"
  11. "github.com/QuantumNous/new-api/model"
  12. "github.com/QuantumNous/new-api/service"
  13. "github.com/QuantumNous/new-api/setting"
  14. "github.com/QuantumNous/new-api/setting/operation_setting"
  15. "github.com/QuantumNous/new-api/setting/system_setting"
  16. "github.com/Calcium-Ion/go-epay/epay"
  17. "github.com/gin-gonic/gin"
  18. "github.com/samber/lo"
  19. "github.com/shopspring/decimal"
  20. )
  21. func GetTopUpInfo(c *gin.Context) {
  22. // 获取支付方式
  23. payMethods := operation_setting.PayMethods
  24. // 如果启用了 Stripe 支付,添加到支付方法列表
  25. if isStripeTopUpEnabled() {
  26. // 检查是否已经包含 Stripe
  27. hasStripe := false
  28. for _, method := range payMethods {
  29. if method["type"] == "stripe" {
  30. hasStripe = true
  31. break
  32. }
  33. }
  34. if !hasStripe {
  35. stripeMethod := map[string]string{
  36. "name": "Stripe",
  37. "type": "stripe",
  38. "color": "rgba(var(--semi-purple-5), 1)",
  39. "min_topup": strconv.Itoa(setting.StripeMinTopUp),
  40. }
  41. payMethods = append(payMethods, stripeMethod)
  42. }
  43. }
  44. // 如果启用了 Waffo 支付,添加到支付方法列表
  45. enableWaffo := isWaffoTopUpEnabled()
  46. if enableWaffo {
  47. hasWaffo := false
  48. for _, method := range payMethods {
  49. if method["type"] == model.PaymentMethodWaffo {
  50. hasWaffo = true
  51. break
  52. }
  53. }
  54. if !hasWaffo {
  55. waffoMethod := map[string]string{
  56. "name": "Waffo (Global Payment)",
  57. "type": model.PaymentMethodWaffo,
  58. "color": "rgba(var(--semi-blue-5), 1)",
  59. "min_topup": strconv.Itoa(setting.WaffoMinTopUp),
  60. }
  61. payMethods = append(payMethods, waffoMethod)
  62. }
  63. }
  64. enableWaffoPancake := isWaffoPancakeTopUpEnabled()
  65. if enableWaffoPancake {
  66. hasWaffoPancake := false
  67. for _, method := range payMethods {
  68. if method["type"] == model.PaymentMethodWaffoPancake {
  69. hasWaffoPancake = true
  70. break
  71. }
  72. }
  73. if !hasWaffoPancake {
  74. payMethods = append(payMethods, map[string]string{
  75. "name": "Waffo Pancake",
  76. "type": model.PaymentMethodWaffoPancake,
  77. "color": "rgba(var(--semi-orange-5), 1)",
  78. "min_topup": strconv.Itoa(setting.WaffoPancakeMinTopUp),
  79. })
  80. }
  81. }
  82. data := gin.H{
  83. "enable_online_topup": isEpayTopUpEnabled(),
  84. "enable_stripe_topup": isStripeTopUpEnabled(),
  85. "enable_creem_topup": isCreemTopUpEnabled(),
  86. "enable_waffo_topup": enableWaffo,
  87. "enable_waffo_pancake_topup": enableWaffoPancake,
  88. "waffo_pay_methods": func() interface{} {
  89. if enableWaffo {
  90. return setting.GetWaffoPayMethods()
  91. }
  92. return nil
  93. }(),
  94. "creem_products": setting.CreemProducts,
  95. "pay_methods": payMethods,
  96. "min_topup": operation_setting.MinTopUp,
  97. "stripe_min_topup": setting.StripeMinTopUp,
  98. "waffo_min_topup": setting.WaffoMinTopUp,
  99. "waffo_pancake_min_topup": setting.WaffoPancakeMinTopUp,
  100. "amount_options": operation_setting.GetPaymentSetting().AmountOptions,
  101. "discount": operation_setting.GetPaymentSetting().AmountDiscount,
  102. "topup_link": common.TopUpLink,
  103. }
  104. common.ApiSuccess(c, data)
  105. }
  106. type EpayRequest struct {
  107. Amount int64 `json:"amount"`
  108. PaymentMethod string `json:"payment_method"`
  109. }
  110. type AmountRequest struct {
  111. Amount int64 `json:"amount"`
  112. }
  113. func GetEpayClient() *epay.Client {
  114. if operation_setting.PayAddress == "" || operation_setting.EpayId == "" || operation_setting.EpayKey == "" {
  115. return nil
  116. }
  117. withUrl, err := epay.NewClient(&epay.Config{
  118. PartnerID: operation_setting.EpayId,
  119. Key: operation_setting.EpayKey,
  120. }, operation_setting.PayAddress)
  121. if err != nil {
  122. return nil
  123. }
  124. return withUrl
  125. }
  126. func getPayMoney(amount int64, group string) float64 {
  127. dAmount := decimal.NewFromInt(amount)
  128. // 充值金额以“展示类型”为准:
  129. // - USD/CNY: 前端传 amount 为金额单位;TOKENS: 前端传 tokens,需要换成 USD 金额
  130. if operation_setting.GetQuotaDisplayType() == operation_setting.QuotaDisplayTypeTokens {
  131. dQuotaPerUnit := decimal.NewFromFloat(common.QuotaPerUnit)
  132. dAmount = dAmount.Div(dQuotaPerUnit)
  133. }
  134. topupGroupRatio := common.GetTopupGroupRatio(group)
  135. if topupGroupRatio == 0 {
  136. topupGroupRatio = 1
  137. }
  138. dTopupGroupRatio := decimal.NewFromFloat(topupGroupRatio)
  139. dPrice := decimal.NewFromFloat(operation_setting.Price)
  140. // apply optional preset discount by the original request amount (if configured), default 1.0
  141. discount := 1.0
  142. if ds, ok := operation_setting.GetPaymentSetting().AmountDiscount[int(amount)]; ok {
  143. if ds > 0 {
  144. discount = ds
  145. }
  146. }
  147. dDiscount := decimal.NewFromFloat(discount)
  148. payMoney := dAmount.Mul(dPrice).Mul(dTopupGroupRatio).Mul(dDiscount)
  149. return payMoney.InexactFloat64()
  150. }
  151. func getMinTopup() int64 {
  152. minTopup := operation_setting.MinTopUp
  153. if operation_setting.GetQuotaDisplayType() == operation_setting.QuotaDisplayTypeTokens {
  154. dMinTopup := decimal.NewFromInt(int64(minTopup))
  155. dQuotaPerUnit := decimal.NewFromFloat(common.QuotaPerUnit)
  156. minTopup = int(dMinTopup.Mul(dQuotaPerUnit).IntPart())
  157. }
  158. return int64(minTopup)
  159. }
  160. func RequestEpay(c *gin.Context) {
  161. var req EpayRequest
  162. err := c.ShouldBindJSON(&req)
  163. if err != nil {
  164. c.JSON(http.StatusOK, gin.H{"message": "error", "data": "参数错误"})
  165. return
  166. }
  167. if req.Amount < getMinTopup() {
  168. c.JSON(http.StatusOK, gin.H{"message": "error", "data": fmt.Sprintf("充值数量不能小于 %d", getMinTopup())})
  169. return
  170. }
  171. id := c.GetInt("id")
  172. group, err := model.GetUserGroup(id, true)
  173. if err != nil {
  174. c.JSON(http.StatusOK, gin.H{"message": "error", "data": "获取用户分组失败"})
  175. return
  176. }
  177. payMoney := getPayMoney(req.Amount, group)
  178. if payMoney < 0.01 {
  179. c.JSON(http.StatusOK, gin.H{"message": "error", "data": "充值金额过低"})
  180. return
  181. }
  182. if !operation_setting.ContainsPayMethod(req.PaymentMethod) {
  183. c.JSON(http.StatusOK, gin.H{"message": "error", "data": "支付方式不存在"})
  184. return
  185. }
  186. callBackAddress := service.GetCallbackAddress()
  187. returnUrl, _ := url.Parse(system_setting.ServerAddress + "/console/log")
  188. notifyUrl, _ := url.Parse(callBackAddress + "/api/user/epay/notify")
  189. tradeNo := fmt.Sprintf("%s%d", common.GetRandomString(6), time.Now().Unix())
  190. tradeNo = fmt.Sprintf("USR%dNO%s", id, tradeNo)
  191. client := GetEpayClient()
  192. if client == nil {
  193. c.JSON(http.StatusOK, gin.H{"message": "error", "data": "当前管理员未配置支付信息"})
  194. return
  195. }
  196. uri, params, err := client.Purchase(&epay.PurchaseArgs{
  197. Type: req.PaymentMethod,
  198. ServiceTradeNo: tradeNo,
  199. Name: fmt.Sprintf("TUC%d", req.Amount),
  200. Money: strconv.FormatFloat(payMoney, 'f', 2, 64),
  201. Device: epay.PC,
  202. NotifyUrl: notifyUrl,
  203. ReturnUrl: returnUrl,
  204. })
  205. if err != nil {
  206. logger.LogError(c.Request.Context(), fmt.Sprintf("易支付 拉起支付失败 user_id=%d trade_no=%s payment_method=%s amount=%d error=%q", id, tradeNo, req.PaymentMethod, req.Amount, err.Error()))
  207. c.JSON(http.StatusOK, gin.H{"message": "error", "data": "拉起支付失败"})
  208. return
  209. }
  210. amount := req.Amount
  211. if operation_setting.GetQuotaDisplayType() == operation_setting.QuotaDisplayTypeTokens {
  212. dAmount := decimal.NewFromInt(int64(amount))
  213. dQuotaPerUnit := decimal.NewFromFloat(common.QuotaPerUnit)
  214. amount = dAmount.Div(dQuotaPerUnit).IntPart()
  215. }
  216. topUp := &model.TopUp{
  217. UserId: id,
  218. Amount: amount,
  219. Money: payMoney,
  220. TradeNo: tradeNo,
  221. PaymentMethod: req.PaymentMethod,
  222. PaymentProvider: model.PaymentProviderEpay,
  223. CreateTime: time.Now().Unix(),
  224. Status: common.TopUpStatusPending,
  225. }
  226. err = topUp.Insert()
  227. if err != nil {
  228. logger.LogError(c.Request.Context(), fmt.Sprintf("易支付 创建充值订单失败 user_id=%d trade_no=%s payment_method=%s amount=%d error=%q", id, tradeNo, req.PaymentMethod, req.Amount, err.Error()))
  229. c.JSON(http.StatusOK, gin.H{"message": "error", "data": "创建订单失败"})
  230. return
  231. }
  232. logger.LogInfo(c.Request.Context(), fmt.Sprintf("易支付 充值订单创建成功 user_id=%d trade_no=%s payment_method=%s amount=%d money=%.2f uri=%q params=%q", id, tradeNo, req.PaymentMethod, req.Amount, payMoney, uri, common.GetJsonString(params)))
  233. c.JSON(http.StatusOK, gin.H{"message": "success", "data": params, "url": uri})
  234. }
  235. // tradeNo lock
  236. var orderLocks sync.Map
  237. var createLock sync.Mutex
  238. // refCountedMutex 带引用计数的互斥锁,确保最后一个使用者才从 map 中删除
  239. type refCountedMutex struct {
  240. mu sync.Mutex
  241. refCount int
  242. }
  243. // LockOrder 尝试对给定订单号加锁
  244. func LockOrder(tradeNo string) {
  245. createLock.Lock()
  246. var rcm *refCountedMutex
  247. if v, ok := orderLocks.Load(tradeNo); ok {
  248. rcm = v.(*refCountedMutex)
  249. } else {
  250. rcm = &refCountedMutex{}
  251. orderLocks.Store(tradeNo, rcm)
  252. }
  253. rcm.refCount++
  254. createLock.Unlock()
  255. rcm.mu.Lock()
  256. }
  257. // UnlockOrder 释放给定订单号的锁
  258. func UnlockOrder(tradeNo string) {
  259. v, ok := orderLocks.Load(tradeNo)
  260. if !ok {
  261. return
  262. }
  263. rcm := v.(*refCountedMutex)
  264. rcm.mu.Unlock()
  265. createLock.Lock()
  266. rcm.refCount--
  267. if rcm.refCount == 0 {
  268. orderLocks.Delete(tradeNo)
  269. }
  270. createLock.Unlock()
  271. }
  272. func EpayNotify(c *gin.Context) {
  273. if !isEpayWebhookEnabled() {
  274. logger.LogWarn(c.Request.Context(), fmt.Sprintf("易支付 webhook 被拒绝 reason=webhook_disabled path=%q client_ip=%s", c.Request.RequestURI, c.ClientIP()))
  275. _, _ = c.Writer.Write([]byte("fail"))
  276. return
  277. }
  278. var params map[string]string
  279. if c.Request.Method == "POST" {
  280. // POST 请求:从 POST body 解析参数
  281. if err := c.Request.ParseForm(); err != nil {
  282. logger.LogError(c.Request.Context(), fmt.Sprintf("易支付 webhook POST 表单解析失败 path=%q client_ip=%s error=%q", c.Request.RequestURI, c.ClientIP(), err.Error()))
  283. _, _ = c.Writer.Write([]byte("fail"))
  284. return
  285. }
  286. params = lo.Reduce(lo.Keys(c.Request.PostForm), func(r map[string]string, t string, i int) map[string]string {
  287. r[t] = c.Request.PostForm.Get(t)
  288. return r
  289. }, map[string]string{})
  290. } else {
  291. // GET 请求:从 URL Query 解析参数
  292. params = lo.Reduce(lo.Keys(c.Request.URL.Query()), func(r map[string]string, t string, i int) map[string]string {
  293. r[t] = c.Request.URL.Query().Get(t)
  294. return r
  295. }, map[string]string{})
  296. }
  297. logger.LogInfo(c.Request.Context(), fmt.Sprintf("易支付 webhook 收到请求 path=%q client_ip=%s method=%s params=%q", c.Request.RequestURI, c.ClientIP(), c.Request.Method, common.GetJsonString(params)))
  298. if len(params) == 0 {
  299. logger.LogWarn(c.Request.Context(), fmt.Sprintf("易支付 webhook 参数为空 path=%q client_ip=%s", c.Request.RequestURI, c.ClientIP()))
  300. _, _ = c.Writer.Write([]byte("fail"))
  301. return
  302. }
  303. client := GetEpayClient()
  304. if client == nil {
  305. logger.LogError(c.Request.Context(), fmt.Sprintf("易支付 client 未初始化 path=%q client_ip=%s", c.Request.RequestURI, c.ClientIP()))
  306. _, err := c.Writer.Write([]byte("fail"))
  307. if err != nil {
  308. logger.LogError(c.Request.Context(), fmt.Sprintf("易支付 webhook 响应写入失败 path=%q client_ip=%s error=%q", c.Request.RequestURI, c.ClientIP(), err.Error()))
  309. }
  310. return
  311. }
  312. verifyInfo, err := client.Verify(params)
  313. if err == nil && verifyInfo.VerifyStatus {
  314. logger.LogInfo(c.Request.Context(), fmt.Sprintf("易支付 webhook 验签成功 trade_no=%s callback_type=%s trade_status=%s client_ip=%s verify_info=%q", verifyInfo.ServiceTradeNo, verifyInfo.Type, verifyInfo.TradeStatus, c.ClientIP(), common.GetJsonString(verifyInfo)))
  315. _, err := c.Writer.Write([]byte("success"))
  316. if err != nil {
  317. logger.LogError(c.Request.Context(), fmt.Sprintf("易支付 webhook 响应写入失败 trade_no=%s client_ip=%s error=%q", verifyInfo.ServiceTradeNo, c.ClientIP(), err.Error()))
  318. }
  319. } else {
  320. _, err := c.Writer.Write([]byte("fail"))
  321. if err != nil {
  322. logger.LogError(c.Request.Context(), fmt.Sprintf("易支付 webhook 响应写入失败 path=%q client_ip=%s error=%q", c.Request.RequestURI, c.ClientIP(), err.Error()))
  323. }
  324. if err != nil {
  325. logger.LogWarn(c.Request.Context(), fmt.Sprintf("易支付 webhook 验签失败 path=%q client_ip=%s verify_error=%q", c.Request.RequestURI, c.ClientIP(), err.Error()))
  326. } else {
  327. logger.LogWarn(c.Request.Context(), fmt.Sprintf("易支付 webhook 验签失败 path=%q client_ip=%s verify_status=false", c.Request.RequestURI, c.ClientIP()))
  328. }
  329. return
  330. }
  331. if verifyInfo.TradeStatus == epay.StatusTradeSuccess {
  332. LockOrder(verifyInfo.ServiceTradeNo)
  333. defer UnlockOrder(verifyInfo.ServiceTradeNo)
  334. topUp := model.GetTopUpByTradeNo(verifyInfo.ServiceTradeNo)
  335. if topUp == nil {
  336. logger.LogWarn(c.Request.Context(), fmt.Sprintf("易支付 回调订单不存在 trade_no=%s callback_type=%s client_ip=%s verify_info=%q", verifyInfo.ServiceTradeNo, verifyInfo.Type, c.ClientIP(), common.GetJsonString(verifyInfo)))
  337. return
  338. }
  339. if topUp.PaymentProvider != model.PaymentProviderEpay {
  340. logger.LogWarn(c.Request.Context(), fmt.Sprintf("易支付 订单支付网关不匹配 trade_no=%s order_provider=%s callback_type=%s client_ip=%s", verifyInfo.ServiceTradeNo, topUp.PaymentProvider, verifyInfo.Type, c.ClientIP()))
  341. return
  342. }
  343. if topUp.Status == common.TopUpStatusPending {
  344. if topUp.PaymentMethod != verifyInfo.Type {
  345. logger.LogInfo(c.Request.Context(), fmt.Sprintf("易支付 实际支付方式与订单不同 trade_no=%s order_payment_method=%s actual_type=%s client_ip=%s", verifyInfo.ServiceTradeNo, topUp.PaymentMethod, verifyInfo.Type, c.ClientIP()))
  346. topUp.PaymentMethod = verifyInfo.Type
  347. }
  348. topUp.Status = common.TopUpStatusSuccess
  349. err := topUp.Update()
  350. if err != nil {
  351. logger.LogError(c.Request.Context(), fmt.Sprintf("易支付 更新充值订单失败 trade_no=%s user_id=%d client_ip=%s error=%q topup=%q", topUp.TradeNo, topUp.UserId, c.ClientIP(), err.Error(), common.GetJsonString(topUp)))
  352. return
  353. }
  354. //user, _ := model.GetUserById(topUp.UserId, false)
  355. //user.Quota += topUp.Amount * 500000
  356. dAmount := decimal.NewFromInt(int64(topUp.Amount))
  357. dQuotaPerUnit := decimal.NewFromFloat(common.QuotaPerUnit)
  358. quotaToAdd := int(dAmount.Mul(dQuotaPerUnit).IntPart())
  359. err = model.IncreaseUserQuota(topUp.UserId, quotaToAdd, true)
  360. if err != nil {
  361. logger.LogError(c.Request.Context(), fmt.Sprintf("易支付 更新用户额度失败 trade_no=%s user_id=%d client_ip=%s quota_to_add=%d error=%q topup=%q", topUp.TradeNo, topUp.UserId, c.ClientIP(), quotaToAdd, err.Error(), common.GetJsonString(topUp)))
  362. return
  363. }
  364. logger.LogInfo(c.Request.Context(), fmt.Sprintf("易支付 充值成功 trade_no=%s user_id=%d client_ip=%s quota_to_add=%d money=%.2f topup=%q", topUp.TradeNo, topUp.UserId, c.ClientIP(), quotaToAdd, topUp.Money, common.GetJsonString(topUp)))
  365. model.RecordTopupLog(topUp.UserId, fmt.Sprintf("使用在线充值成功,充值金额: %v,支付金额:%f", logger.LogQuota(quotaToAdd), topUp.Money), c.ClientIP(), topUp.PaymentMethod, "epay")
  366. }
  367. } else {
  368. logger.LogInfo(c.Request.Context(), fmt.Sprintf("易支付 webhook 忽略事件 trade_no=%s callback_type=%s trade_status=%s client_ip=%s verify_info=%q", verifyInfo.ServiceTradeNo, verifyInfo.Type, verifyInfo.TradeStatus, c.ClientIP(), common.GetJsonString(verifyInfo)))
  369. }
  370. }
  371. func RequestAmount(c *gin.Context) {
  372. var req AmountRequest
  373. err := c.ShouldBindJSON(&req)
  374. if err != nil {
  375. c.JSON(http.StatusOK, gin.H{"message": "error", "data": "参数错误"})
  376. return
  377. }
  378. if req.Amount < getMinTopup() {
  379. c.JSON(http.StatusOK, gin.H{"message": "error", "data": fmt.Sprintf("充值数量不能小于 %d", getMinTopup())})
  380. return
  381. }
  382. id := c.GetInt("id")
  383. group, err := model.GetUserGroup(id, true)
  384. if err != nil {
  385. c.JSON(http.StatusOK, gin.H{"message": "error", "data": "获取用户分组失败"})
  386. return
  387. }
  388. payMoney := getPayMoney(req.Amount, group)
  389. if payMoney <= 0.01 {
  390. c.JSON(http.StatusOK, gin.H{"message": "error", "data": "充值金额过低"})
  391. return
  392. }
  393. c.JSON(http.StatusOK, gin.H{"message": "success", "data": strconv.FormatFloat(payMoney, 'f', 2, 64)})
  394. }
  395. func GetUserTopUps(c *gin.Context) {
  396. userId := c.GetInt("id")
  397. pageInfo := common.GetPageQuery(c)
  398. keyword := c.Query("keyword")
  399. var (
  400. topups []*model.TopUp
  401. total int64
  402. err error
  403. )
  404. if keyword != "" {
  405. topups, total, err = model.SearchUserTopUps(userId, keyword, pageInfo)
  406. } else {
  407. topups, total, err = model.GetUserTopUps(userId, pageInfo)
  408. }
  409. if err != nil {
  410. common.ApiError(c, err)
  411. return
  412. }
  413. pageInfo.SetTotal(int(total))
  414. pageInfo.SetItems(topups)
  415. common.ApiSuccess(c, pageInfo)
  416. }
  417. // GetAllTopUps 管理员获取全平台充值记录
  418. func GetAllTopUps(c *gin.Context) {
  419. pageInfo := common.GetPageQuery(c)
  420. keyword := c.Query("keyword")
  421. var (
  422. topups []*model.TopUp
  423. total int64
  424. err error
  425. )
  426. if keyword != "" {
  427. topups, total, err = model.SearchAllTopUps(keyword, pageInfo)
  428. } else {
  429. topups, total, err = model.GetAllTopUps(pageInfo)
  430. }
  431. if err != nil {
  432. common.ApiError(c, err)
  433. return
  434. }
  435. pageInfo.SetTotal(int(total))
  436. pageInfo.SetItems(topups)
  437. common.ApiSuccess(c, pageInfo)
  438. }
  439. type AdminCompleteTopupRequest struct {
  440. TradeNo string `json:"trade_no"`
  441. }
  442. // AdminCompleteTopUp 管理员补单接口
  443. func AdminCompleteTopUp(c *gin.Context) {
  444. var req AdminCompleteTopupRequest
  445. if err := c.ShouldBindJSON(&req); err != nil || req.TradeNo == "" {
  446. common.ApiErrorMsg(c, "参数错误")
  447. return
  448. }
  449. // 订单级互斥,防止并发补单
  450. LockOrder(req.TradeNo)
  451. defer UnlockOrder(req.TradeNo)
  452. if err := model.ManualCompleteTopUp(req.TradeNo, c.ClientIP()); err != nil {
  453. common.ApiError(c, err)
  454. return
  455. }
  456. common.ApiSuccess(c, nil)
  457. }