elec_mysql.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package dao
  2. import (
  3. "context"
  4. "math"
  5. "go-common/app/job/main/ugcpay/model"
  6. xsql "go-common/library/database/sql"
  7. )
  8. const (
  9. _oldElecOrderList = `SELECT id,mid,pay_mid,order_no,elec_num,status,ctime,mtime FROM elec_pay_order WHERE id>? ORDER BY ID ASC LIMIT ?`
  10. _oldElecMessageList = `SELECT id,mid,ref_mid,IFNULL(ref_id,0),message,av_no,date_version,type,state,ctime,mtime FROM elec_message WHERE id>? ORDER BY ID ASC LIMIT ?`
  11. _upsertElecMessage = "INSERT INTO elec_message (id,`ver`,avid,up_mid,pay_mid,message,replied,hidden,ctime,mtime) VALUES (?,?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE `ver`=?,avid=?,up_mid=?,pay_mid=?,message=?,replied=?,hidden=?"
  12. _upsertElecReply = "INSERT INTO elec_reply (id,message_id,reply,hidden,ctime,mtime) VALUES (?,?,?,?,?,?) ON DUPLICATE KEY UPDATE message_id=?,reply=?,hidden=?"
  13. _upsertElecAVRank = "INSERT INTO rank_elec_av (ver,avid,up_mid,pay_mid,pay_amount,hidden) VALUES (?,?,?,?,?,?) ON DUPLICATE KEY UPDATE pay_amount = pay_amount + ?"
  14. _upsertElecUPRank = "INSERT INTO rank_elec_up (ver,up_mid,pay_mid,pay_amount,hidden) VALUES (?,?,?,?,?) ON DUPLICATE KEY UPDATE pay_amount = pay_amount + ?"
  15. _selectOldElecTradeInfo = "SELECT id,order_no,IFNULL(av_no,0) FROM elec_pay_trade_info WHERE order_no=? LIMIT 1"
  16. )
  17. // UpsertElecMessage .
  18. func (d *Dao) UpsertElecMessage(ctx context.Context, data *model.DBElecMessage) (err error) {
  19. _, err = d.dbrank.Exec(ctx, _upsertElecMessage, data.ID, data.Ver, data.AVID, data.UPMID, data.PayMID, data.Message, data.Replied, data.Hidden, data.CTime, data.MTime, data.Ver, data.AVID, data.UPMID, data.PayMID, data.Message, data.Replied, data.Hidden)
  20. return
  21. }
  22. // UpsertElecReply .
  23. func (d *Dao) UpsertElecReply(ctx context.Context, data *model.DBElecReply) (err error) {
  24. _, err = d.dbrank.Exec(ctx, _upsertElecReply, data.ID, data.MSGID, data.Reply, data.Hidden, data.CTime, data.MTime, data.MSGID, data.Reply, data.Hidden)
  25. return
  26. }
  27. // TXUpsertElecAVRank .
  28. func (d *Dao) TXUpsertElecAVRank(ctx context.Context, tx *xsql.Tx, ver int64, avID int64, upMID, payMID int64, deltaPayAmount int64, hidden bool) (err error) {
  29. _, err = tx.Exec(_upsertElecAVRank, ver, avID, upMID, payMID, deltaPayAmount, hidden, deltaPayAmount)
  30. return
  31. }
  32. // TXUpsertElecUPRank .
  33. func (d *Dao) TXUpsertElecUPRank(ctx context.Context, tx *xsql.Tx, ver int64, upMID, payMID int64, deltaPayAmount int64, hidden bool) (err error) {
  34. _, err = tx.Exec(_upsertElecUPRank, ver, upMID, payMID, deltaPayAmount, hidden, deltaPayAmount)
  35. return
  36. }
  37. // RawOldElecTradeInfo .
  38. func (d *Dao) RawOldElecTradeInfo(ctx context.Context, orderID string) (data *model.DBOldElecPayTradeInfo, err error) {
  39. row := d.dbrankold.QueryRow(ctx, _selectOldElecTradeInfo, orderID)
  40. data = &model.DBOldElecPayTradeInfo{}
  41. if err = row.Scan(&data.ID, &data.OrderID, &data.AVID); err != nil {
  42. if err == xsql.ErrNoRows {
  43. err = nil
  44. data = nil
  45. }
  46. return
  47. }
  48. return
  49. }
  50. // OldElecMessageList .
  51. func (d *Dao) OldElecMessageList(ctx context.Context, startID int64, limit int) (maxID int64, list []*model.DBOldElecMessage, err error) {
  52. var (
  53. rows *xsql.Rows
  54. )
  55. if rows, err = d.dbrankold.Query(ctx, _oldElecMessageList, startID, limit); err != nil {
  56. return
  57. }
  58. defer rows.Close()
  59. for rows.Next() {
  60. var (
  61. p = &model.DBOldElecMessage{}
  62. )
  63. if err = rows.Scan(&p.ID, &p.MID, &p.RefMID, &p.RefID, &p.Message, &p.AVID, &p.DateVer, &p.Type, &p.State, &p.CTime, &p.MTime); err != nil {
  64. return
  65. }
  66. if maxID < p.ID {
  67. maxID = p.ID
  68. }
  69. list = append(list, p)
  70. }
  71. if err = rows.Err(); err != nil {
  72. return
  73. }
  74. return
  75. }
  76. // OldElecOrderList .
  77. func (d *Dao) OldElecOrderList(ctx context.Context, startID int64, limit int) (maxID int64, list []*model.DBOldElecPayOrder, err error) {
  78. var (
  79. rows *xsql.Rows
  80. )
  81. if rows, err = d.dbrankold.Query(ctx, _oldElecOrderList, startID, limit); err != nil {
  82. return
  83. }
  84. defer rows.Close()
  85. for rows.Next() {
  86. var (
  87. p = &model.DBOldElecPayOrder{}
  88. )
  89. if err = rows.Scan(&p.ID, &p.UPMID, &p.PayMID, &p.OrderID, &p.ElecNum, &p.Status, &p.CTime, &p.MTime); err != nil {
  90. return
  91. }
  92. if maxID < p.ID {
  93. maxID = p.ID
  94. }
  95. list = append(list, p)
  96. }
  97. if err = rows.Err(); err != nil {
  98. return
  99. }
  100. return
  101. }
  102. const (
  103. _elecAddSetting = `INSERT INTO elec_user_setting (mid,value) VALUES (?,?) ON DUPLICATE KEY UPDATE value=value|?`
  104. _elecDeleteSetting = `INSERT INTO elec_user_setting (mid,value) VALUES (?,?) ON DUPLICATE KEY UPDATE value=value&?`
  105. )
  106. // ElecAddSetting .
  107. func (d *Dao) ElecAddSetting(ctx context.Context, defaultValue int32, mid int64, bitValue int32) (err error) {
  108. defaultValue |= bitValue
  109. _, err = d.dbrank.Exec(ctx, _elecAddSetting, mid, defaultValue, bitValue)
  110. return
  111. }
  112. // ElecDeleteSetting .
  113. func (d *Dao) ElecDeleteSetting(ctx context.Context, defaultValue int32, mid int64, bitValue int32) (err error) {
  114. andValue := math.MaxInt32 ^ bitValue
  115. defaultValue &= andValue
  116. _, err = d.dbrank.Exec(ctx, _elecDeleteSetting, mid, defaultValue, andValue)
  117. return
  118. }