pay.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package db
  2. import (
  3. "runtime/debug"
  4. "bet24.com/database"
  5. "bet24.com/log"
  6. )
  7. // 下单
  8. type (
  9. order_in struct {
  10. UserID int // 用户ID
  11. Price float64 // 价格
  12. ProductID string // 商品ID
  13. PartnerID int // 渠道ID
  14. IpAddress string // IP地址
  15. Name string // 姓名
  16. Tel string // 电话
  17. Email string // 邮箱
  18. Currency string // 币种
  19. Country string // 国家
  20. PayMethod string // 支付方式
  21. TargetOrg string // 目标机构
  22. CardNum string // 银行卡号
  23. PayModel string // 支付模式
  24. }
  25. order_out struct {
  26. OrderID string //订单号
  27. }
  28. order struct {
  29. database.Trans_base
  30. procName string //存储过程
  31. In order_in
  32. Out order_out
  33. }
  34. )
  35. func NewOrder(procName string) *order {
  36. return &order{
  37. procName: procName,
  38. }
  39. }
  40. func (this *order) DoAction(ch chan<- interface{}) {
  41. defer func() {
  42. if err := recover(); err != nil {
  43. log.Release("transaction recover err %v", err)
  44. log.Release("%s", debug.Stack())
  45. }
  46. if ch != nil {
  47. ch <- this
  48. }
  49. }()
  50. statement := database.NewStatement()
  51. statement.SetNeedReturnValue(false)
  52. statement.SetOpenRecordSet(true)
  53. statement.SetProcName(this.procName)
  54. statement.AddParamter("@UserID", database.AdParamInput, database.AdInteger, 4, this.In.UserID)
  55. statement.AddParamter("@Price", database.AdParamInput, database.AdFloat, 20, this.In.Price)
  56. statement.AddParamter("@ProductID", database.AdParamInput, database.AdVarChar, 32, this.In.ProductID)
  57. statement.AddParamter("@PartnerID", database.AdParamInput, database.AdInteger, 4, this.In.PartnerID)
  58. statement.AddParamter("@IPAddress", database.AdParamInput, database.AdVarChar, 16, this.In.IpAddress)
  59. statement.AddParamter("@OrderID", database.AdParamOutput, database.AdVarChar, 32, this.Out.OrderID)
  60. sqlstring := statement.GenSql()
  61. //log.Debug(sqlstring)
  62. retRows := CenterDB.ExecSql(sqlstring)
  63. if len(retRows) <= 0 {
  64. this.State = false
  65. return
  66. }
  67. this.State = true
  68. this.Out.OrderID = retRows[0][0].(string)
  69. }
  70. // 回调
  71. type (
  72. notify_in struct {
  73. OrderID string //订单号
  74. TradeID string //业务流水号
  75. Price float64 //价格
  76. }
  77. notify_out struct {
  78. RetCode int //操作结果
  79. UserID int //用户ID
  80. ProductID string //产品ID
  81. }
  82. notify struct {
  83. database.Trans_base
  84. ProcName string //存储过程
  85. In notify_in
  86. Out notify_out
  87. }
  88. )
  89. func NewNotify(procName string) *notify {
  90. return &notify{
  91. ProcName: procName,
  92. }
  93. }
  94. func (this *notify) DoAction(ch chan<- interface{}) {
  95. defer func() {
  96. if err := recover(); err != nil {
  97. log.Release("transaction recover err %v", err)
  98. log.Release("%s", debug.Stack())
  99. }
  100. if ch != nil {
  101. ch <- this
  102. }
  103. }()
  104. statement := database.NewStatement()
  105. statement.SetNeedReturnValue(false)
  106. statement.SetOpenRecordSet(true)
  107. statement.SetProcName(this.ProcName)
  108. statement.AddParamter("@OrderID", database.AdParamInput, database.AdVarChar, 32, this.In.OrderID)
  109. statement.AddParamter("@TradeID", database.AdParamInput, database.AdVarChar, 64, this.In.TradeID)
  110. statement.AddParamter("@Price", database.AdParamInput, database.AdFloat, 20, this.In.Price)
  111. statement.AddParamter("@RetCode", database.AdParamOutput, database.AdInteger, 4, this.Out.RetCode)
  112. statement.AddParamter("@UserID", database.AdParamOutput, database.AdInteger, 4, this.Out.UserID)
  113. statement.AddParamter("@ProductID", database.AdParamOutput, database.AdVarChar, 32, this.Out.ProductID)
  114. sqlstring := statement.GenSql()
  115. //log.Debug(sqlstring)
  116. retRows := CenterDB.ExecSql(sqlstring)
  117. if len(retRows) <= 0 {
  118. this.State = false
  119. return
  120. }
  121. this.State = true
  122. this.Out.RetCode = int(retRows[0][0].(int64))
  123. this.Out.UserID = int(retRows[0][1].(int64))
  124. this.Out.ProductID = (retRows[0][2].(string))
  125. }