mysql.go 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  1. package dao
  2. import (
  3. "context"
  4. "math"
  5. "time"
  6. "go-common/app/job/main/ugcpay/model"
  7. xsql "go-common/library/database/sql"
  8. )
  9. const (
  10. _asset = `SELECT id,mid,oid,otype,currency,price,state,ctime,mtime FROM asset WHERE oid=? AND otype=? AND currency=? LIMIT 1`
  11. _countPaidOrderUser = "SELECT count(1) FROM order_user WHERE pay_time BETWEEN ? AND ? AND state='paid' LIMIT 1"
  12. _countRefundedOrderUser = "SELECT count(1) FROM order_user WHERE refund_time BETWEEN ? AND ? AND state='st_refunded' LIMIT 1"
  13. _sumPaidOrderUserRealFee = "SELECT IFNULL(sum(real_fee),0) FROM order_user WHERE pay_time BETWEEN ? AND ? AND state='settled' LIMIT 1"
  14. _sumRefundedOrderUserRealFee = "SELECT IFNULL(sum(real_fee),0) FROM order_user WHERE refund_time BETWEEN ? AND ? AND state='ref_finished' LIMIT 1"
  15. _minIDOrderPaid = `SELECT id FROM order_user WHERE pay_time>=? AND state='paid' ORDER BY id ASC LIMIT 1`
  16. _minIDOrderRefunded = `SELECT id FROM order_user WHERE refund_time>=? AND state='st_refunded' ORDER BY id ASC LIMIT 1`
  17. _orderPaidList = `SELECT id,mid,order_id,biz,platform,oid,otype,fee,real_fee,currency,pay_id,pay_reason,pay_time,state,ctime,mtime,refund_time,version FROM order_user WHERE pay_time BETWEEN ? AND ? AND state='paid' AND id>? ORDER BY ID ASC LIMIT ?`
  18. _orderRefundedList = `SELECT id,mid,order_id,biz,platform,oid,otype,fee,real_fee,currency,pay_id,pay_reason,pay_time,state,ctime,mtime,refund_time,version FROM order_user WHERE refund_time BETWEEN ? AND ? AND state='st_refunded' AND id>? ORDER BY ID ASC LIMIT ?`
  19. _updateOrder = `UPDATE order_user SET mid=?,order_id=?,biz=?,platform=?,oid=?,otype=?,fee=?,real_fee=?,currency=?,pay_id=?,pay_reason=?,pay_time=?,state=?,refund_time=?,version=version+1 WHERE id=? AND version=?`
  20. _insertLogOrderUser = "INSERT INTO log_order_user (order_id,from_state,to_state,`desc`) VALUES (?,?,?,?)"
  21. _orderBadDebt = `SELECT id,order_id,type,state,ctime,mtime FROM order_bad_debt WHERE order_id=? ORDER BY id ASC LIMIT 1`
  22. _insertOrderBadDebt = `INSERT INTO order_bad_debt (order_id,type,state) VALUES (?,?,?)`
  23. _updateOrderBadDebt = `UPDATE order_bad_debt SET order_id=?,type=?,state=? WHERE order_id=?`
  24. _countDailyBillByVer = "SELECT count(1) FROM bill_user_daily WHERE ver=? LIMIT 1"
  25. _countDailyBillByMonthVer = "SELECT count(1) FROM bill_user_daily WHERE month_ver=? LIMIT 1"
  26. _sumDailyBill = "SELECT IFNULL(sum(`in`),0),IFNULL(sum(`out`),0) FROM bill_user_daily WHERE ver=? LIMIT 1"
  27. _minIDDailyBillByMonthVer = `SELECT id FROM bill_user_daily WHERE month_ver=? ORDER BY id ASC LIMIT 1`
  28. _dailyBillListByMonthVer = "SELECT id,bill_id,mid,biz,currency,`in`,`out`,ver,month_ver,ctime,mtime,version FROM bill_user_daily WHERE month_ver=? AND id>? ORDER BY ID ASC LIMIT ?"
  29. _minIDDailyBillByVer = `SELECT id FROM bill_user_daily WHERE ver=? ORDER BY id ASC LIMIT 1`
  30. _dailyBillListByVer = "SELECT id,bill_id,mid,biz,currency,`in`,`out`,ver,month_ver,ctime,mtime,version FROM bill_user_daily WHERE ver=? AND id>? ORDER BY ID ASC LIMIT ?"
  31. _dailyBill = "SELECT id,bill_id,mid,biz,currency,`in`,`out`,ver,month_ver,ctime,mtime,version FROM bill_user_daily WHERE mid=? AND biz=? AND currency=? AND ver=? LIMIT 1"
  32. _insertDailyBill = "INSERT INTO bill_user_daily (bill_id,mid,biz,currency,`in`,`out`,ver,month_ver,version) VALUES (?,?,?,?,?,?,?,?,?)"
  33. _updateDailyBill = "UPDATE bill_user_daily SET bill_id=?,mid=?,biz=?,currency=?,`in`=?,`out`=?,ver=?,month_ver=?,version=version+1 WHERE mid=? AND biz=? AND currency=? AND ver=? AND version=?"
  34. _insertDailyBillLog = "INSERT INTO log_bill_user_daily (bill_id,from_in,to_in,from_out,to_out,order_id) VALUES (?,?,?,?,?,?)"
  35. _countMonthlyBillByVer = "SELECT count(1) FROM bill_user_monthly WHERE ver=? LIMIT 1"
  36. _minIDMonthlyBill = `SELECT id FROM bill_user_monthly WHERE ver=? ORDER BY id ASC LIMIT 1`
  37. _monthlyBillList = "SELECT id,bill_id,mid,biz,currency,`in`,`out`,ver,ctime,mtime,version FROM bill_user_monthly WHERE ver=? AND id>? ORDER BY ID ASC LIMIT ?"
  38. _monthlyBill = "SELECT id,bill_id,mid,biz,currency,`in`,`out`,ver,ctime,mtime,version FROM bill_user_monthly WHERE mid=? AND biz=? AND currency=? AND ver=? LIMIT 1"
  39. _insertMonthlyBill = "INSERT INTO bill_user_monthly (bill_id,mid,biz,currency,`in`,`out`,ver,version) VALUES (?,?,?,?,?,?,?,?)"
  40. _updateMonthlyBill = "UPDATE bill_user_monthly SET bill_id=?,mid=?,biz=?,currency=?,`in`=?,`out`=?,ver=?,version=version+1 WHERE mid=? AND biz=? AND currency=? AND ver=? AND version=?"
  41. _insertMonthlyBillLog = "INSERT INTO log_bill_user_monthly (bill_id,from_in,to_in,from_out,to_out,bill_user_daily_id) VALUES (?,?,?,?,?,?)"
  42. _minIDUserAccount = `SELECT id FROM account_user WHERE mtime>=? ORDER BY id ASC LIMIT 1`
  43. _userAccountList = "SELECT id,mid,biz,currency,balance,ver,state,ctime,mtime FROM account_user WHERE mtime BETWEEN ? AND ? AND id>? ORDER BY ID ASC LIMIT ?"
  44. _userAccount = `SELECT id,mid,biz,currency,balance,ver,state,ctime,mtime FROM account_user WHERE mid=? AND biz=? AND currency=? LIMIT 1`
  45. _insertUserAccount = `INSERT INTO account_user (mid,biz,currency,balance,ver,state) VALUES (?,?,?,?,?,?)`
  46. _updateUserAccount = `UPDATE account_user SET mid=?,biz=?,currency=?,balance=?,ver=ver+1,state=? WHERE mid=? AND biz=? AND currency=? AND ver=?`
  47. _insertUserAccountLog = "INSERT INTO log_account_user (account_id,`from`,`to`,ver,state,name) VALUES (?,?,?,?,?,?)"
  48. _bizAccount = `SELECT id,biz,currency,balance,ver,state,ctime,mtime FROM account_biz WHERE biz=? AND currency=? LIMIT 1`
  49. _insertBizAccount = `INSERT INTO account_biz (biz,currency,balance,ver,state) VALUES (?,?,?,?,?)`
  50. _updateBizAccount = `UPDATE account_biz SET biz=?,currency=?,balance=?,ver=ver+1,state=? WHERE biz=? AND currency=? AND ver=?`
  51. _insertBizAccountLog = "INSERT INTO log_account_biz (account_id,`from`,`to`,ver,state,name) VALUES (?,?,?,?,?,?)"
  52. _aggrIncomeUser = "SELECT id,mid,currency,pay_success,pay_error,total_in,total_out,ctime,mtime FROM aggr_income_user WHERE mid=? AND currency=? LIMIT 1"
  53. _insertAggrIncomeUser = "INSERT INTO aggr_income_user (mid,currency,pay_success,pay_error,total_in,total_out) VALUES (?,?,?,?,?,?)"
  54. _updateAggrIncomeUser = "UPDATE aggr_income_user SET mid=?,currency=?,pay_success=?,pay_error=?,total_in=?,total_out=? WHERE mid=? AND currency=?"
  55. _aggrIncomeUserAsset = "SELECT id,mid,currency,ver,oid,otype,pay_success,pay_error,total_in,total_out,ctime,mtime FROM aggr_income_user_asset WHERE mid=? AND currency=? AND ver=? AND oid=? AND otype=? LIMIT 1"
  56. _insertAggrIncomeUserAsset = "INSERT INTO aggr_income_user_asset (mid,currency,`ver`,oid,otype,pay_success,pay_error,total_in,total_out) VALUES (?,?,?,?,?,?,?,?,?)"
  57. _updateAggrIncomeUserAsset = "UPDATE aggr_income_user_asset SET mid=?,currency=?,ver=?,oid=?,otype=?,pay_success=?,pay_error=?,total_in=?,total_out=? WHERE mid=? AND currency=? AND ver=? AND oid=? AND otype=?"
  58. _insertOrderRechargeShell = "INSERT INTO order_recharge_shell (mid,order_id,biz,amount,pay_msg,state,`ver`) VALUES (?,?,?,?,?,?,?)"
  59. _insertOrderRechargeShellLog = "INSERT INTO log_order_recharge_shell (order_id,from_state,to_state,`desc`,bill_user_monthly_id) VALUES (?,?,?,?,?)"
  60. _logTask = "SELECT id,name,expect,success,failure,state,ctime,mtime FROM log_task WHERE name=? LIMIT 1"
  61. _insertLogTask = "INSERT INTO log_task (name,expect,success,failure,state) VALUES (?,?,?,?,?)"
  62. _logTaskSuccessIncr = "UPDATE log_task SET success=success+1 WHERE name=?"
  63. _logTaskFailureIncr = "UPDATE log_task SET failure=failure+1 WHERE name=?"
  64. )
  65. // CountPaidOrderUser .
  66. func (d *Dao) CountPaidOrderUser(ctx context.Context, beginTime, endTime time.Time) (count int64, err error) {
  67. row := d.db.QueryRow(ctx, _countPaidOrderUser, beginTime, endTime)
  68. if err = row.Scan(&count); err != nil {
  69. if err == xsql.ErrNoRows {
  70. err = nil
  71. count = 0
  72. }
  73. return
  74. }
  75. return
  76. }
  77. // CountRefundedOrderUser .
  78. func (d *Dao) CountRefundedOrderUser(ctx context.Context, beginTime, endTime time.Time) (count int64, err error) {
  79. row := d.db.QueryRow(ctx, _countRefundedOrderUser, beginTime, endTime)
  80. if err = row.Scan(&count); err != nil {
  81. if err == xsql.ErrNoRows {
  82. err = nil
  83. count = 0
  84. }
  85. return
  86. }
  87. return
  88. }
  89. // CountDailyBillByVer .
  90. func (d *Dao) CountDailyBillByVer(ctx context.Context, ver int64) (count int64, err error) {
  91. row := d.db.QueryRow(ctx, _countDailyBillByVer, ver)
  92. if err = row.Scan(&count); err != nil {
  93. if err == xsql.ErrNoRows {
  94. err = nil
  95. count = 0
  96. }
  97. return
  98. }
  99. return
  100. }
  101. // CountDailyBillByMonthVer .
  102. func (d *Dao) CountDailyBillByMonthVer(ctx context.Context, monthVer int64) (count int64, err error) {
  103. row := d.db.QueryRow(ctx, _countDailyBillByMonthVer, monthVer)
  104. if err = row.Scan(&count); err != nil {
  105. if err == xsql.ErrNoRows {
  106. err = nil
  107. count = 0
  108. }
  109. return
  110. }
  111. return
  112. }
  113. // CountMonthlyBillByVer .
  114. func (d *Dao) CountMonthlyBillByVer(ctx context.Context, ver int64) (count int64, err error) {
  115. row := d.db.QueryRow(ctx, _countMonthlyBillByVer, ver)
  116. if err = row.Scan(&count); err != nil {
  117. if err == xsql.ErrNoRows {
  118. err = nil
  119. count = 0
  120. }
  121. return
  122. }
  123. return
  124. }
  125. // LogTask .
  126. func (d *Dao) LogTask(ctx context.Context, name string) (data *model.LogTask, err error) {
  127. row := d.db.QueryRow(ctx, _logTask, name)
  128. data = &model.LogTask{}
  129. if err = row.Scan(&data.ID, &data.Name, &data.Expect, &data.Success, &data.Failure, &data.State, &data.CTime, &data.MTime); err != nil {
  130. if err == xsql.ErrNoRows {
  131. err = nil
  132. data = nil
  133. }
  134. return
  135. }
  136. return
  137. }
  138. // InsertLogTask .
  139. func (d *Dao) InsertLogTask(ctx context.Context, data *model.LogTask) (id int64, err error) {
  140. result, err := d.db.Exec(ctx, _insertLogTask, data.Name, data.Expect, data.Success, data.Failure, data.State)
  141. if err != nil {
  142. return
  143. }
  144. id, err = result.LastInsertId()
  145. return
  146. }
  147. // TXIncrLogTaskSuccess .
  148. func (d *Dao) TXIncrLogTaskSuccess(ctx context.Context, tx *xsql.Tx, name string) (rows int64, err error) {
  149. result, err := tx.Exec(_logTaskSuccessIncr, name)
  150. if err != nil {
  151. return
  152. }
  153. rows, err = result.RowsAffected()
  154. return
  155. }
  156. // IncrLogTaskFailure .
  157. func (d *Dao) IncrLogTaskFailure(ctx context.Context, name string) (rows int64, err error) {
  158. result, err := d.db.Exec(ctx, _logTaskFailureIncr, name)
  159. if err != nil {
  160. return
  161. }
  162. rows, err = result.RowsAffected()
  163. return
  164. }
  165. // Asset .
  166. func (d *Dao) Asset(ctx context.Context, oid int64, otype string, currency string) (data *model.Asset, err error) {
  167. row := d.db.QueryRow(ctx, _asset, oid, otype, currency)
  168. data = &model.Asset{}
  169. if err = row.Scan(&data.ID, &data.MID, &data.OID, &data.OType, &data.Currency, &data.Price, &data.State, &data.CTime, &data.MTime); err != nil {
  170. if err == xsql.ErrNoRows {
  171. err = nil
  172. data = nil
  173. }
  174. return
  175. }
  176. return
  177. }
  178. // SumPaidOrderUserRealFee .
  179. func (d *Dao) SumPaidOrderUserRealFee(ctx context.Context, beginTime, endTime time.Time) (sum int64, err error) {
  180. row := d.db.QueryRow(ctx, _sumPaidOrderUserRealFee, beginTime, endTime)
  181. if err = row.Scan(&sum); err != nil {
  182. if err == xsql.ErrNoRows {
  183. err = nil
  184. sum = 0
  185. }
  186. return
  187. }
  188. return
  189. }
  190. // SumRefundedOrderUserRealFee .
  191. func (d *Dao) SumRefundedOrderUserRealFee(ctx context.Context, beginTime, endTime time.Time) (sum int64, err error) {
  192. row := d.db.QueryRow(ctx, _sumRefundedOrderUserRealFee, beginTime, endTime)
  193. if err = row.Scan(&sum); err != nil {
  194. if err == xsql.ErrNoRows {
  195. err = nil
  196. sum = 0
  197. }
  198. return
  199. }
  200. return
  201. }
  202. // SumDailyBill .
  203. func (d *Dao) SumDailyBill(ctx context.Context, ver int64) (sumIn int64, sumOut int64, err error) {
  204. row := d.db.QueryRow(ctx, _sumDailyBill, ver)
  205. if err = row.Scan(&sumIn, &sumOut); err != nil {
  206. if err == xsql.ErrNoRows {
  207. err = nil
  208. sumIn = 0
  209. sumOut = 0
  210. }
  211. return
  212. }
  213. return
  214. }
  215. // MinIDOrderPaid .
  216. func (d *Dao) MinIDOrderPaid(ctx context.Context, beginTime time.Time) (minID int64, err error) {
  217. row := d.db.QueryRow(ctx, _minIDOrderPaid, beginTime)
  218. if err = row.Scan(&minID); err != nil {
  219. if err == xsql.ErrNoRows {
  220. err = nil
  221. minID = math.MaxInt32
  222. }
  223. return
  224. }
  225. minID--
  226. return
  227. }
  228. // OrderPaidList order list
  229. func (d *Dao) OrderPaidList(ctx context.Context, beginTime time.Time, endTime time.Time, fromID int64, limit int) (maxID int64, data []*model.Order, err error) {
  230. rows, err := d.db.Query(ctx, _orderPaidList, beginTime, endTime, fromID, limit)
  231. if err != nil {
  232. return
  233. }
  234. defer rows.Close()
  235. for rows.Next() {
  236. d := &model.Order{}
  237. if err = rows.Scan(&d.ID, &d.MID, &d.OrderID, &d.Biz, &d.Platform, &d.OID, &d.OType, &d.Fee, &d.RealFee, &d.Currency, &d.PayID, &d.PayReason, &d.PayTime, &d.State, &d.CTime, &d.MTime, &d.RefundTime, &d.Version); err != nil {
  238. return
  239. }
  240. if d.ID > maxID {
  241. maxID = d.ID
  242. }
  243. data = append(data, d)
  244. }
  245. err = rows.Err()
  246. return
  247. }
  248. // MinIDOrderRefunded .
  249. func (d *Dao) MinIDOrderRefunded(ctx context.Context, beginTime time.Time) (minID int64, err error) {
  250. row := d.db.QueryRow(ctx, _minIDOrderRefunded, beginTime)
  251. if err = row.Scan(&minID); err != nil {
  252. if err == xsql.ErrNoRows {
  253. err = nil
  254. minID = math.MaxInt32
  255. }
  256. return
  257. }
  258. minID--
  259. return
  260. }
  261. // OrderRefundedList order list
  262. func (d *Dao) OrderRefundedList(ctx context.Context, beginTime time.Time, endTime time.Time, fromID int64, limit int) (maxID int64, data []*model.Order, err error) {
  263. rows, err := d.db.Query(ctx, _orderRefundedList, beginTime, endTime, fromID, limit)
  264. if err != nil {
  265. return
  266. }
  267. defer rows.Close()
  268. for rows.Next() {
  269. d := &model.Order{}
  270. if err = rows.Scan(&d.ID, &d.MID, &d.OrderID, &d.Biz, &d.Platform, &d.OID, &d.OType, &d.Fee, &d.RealFee, &d.Currency, &d.PayID, &d.PayReason, &d.PayTime, &d.State, &d.CTime, &d.MTime, &d.RefundTime, &d.Version); err != nil {
  271. return
  272. }
  273. if d.ID > maxID {
  274. maxID = d.ID
  275. }
  276. data = append(data, d)
  277. }
  278. err = rows.Err()
  279. return
  280. }
  281. // TXUpdateOrder .
  282. func (d *Dao) TXUpdateOrder(ctx context.Context, tx *xsql.Tx, order *model.Order) (rows int64, err error) {
  283. result, err := tx.Exec(_updateOrder, order.MID, order.OrderID, order.Biz, order.Platform, order.OID, order.OType, order.Fee, order.RealFee, order.Currency, order.PayID, order.PayReason, order.PayTime, order.State, order.RefundTime, order.ID, order.Version)
  284. if err != nil {
  285. return
  286. }
  287. rows, err = result.RowsAffected()
  288. return
  289. }
  290. // TXInsertOrderUserLog .
  291. func (d *Dao) TXInsertOrderUserLog(ctx context.Context, tx *xsql.Tx, data *model.LogOrder) (id int64, err error) {
  292. result, err := tx.Exec(_insertLogOrderUser, data.OrderID, data.FromState, data.ToState, data.Desc)
  293. if err != nil {
  294. return
  295. }
  296. if id, err = result.LastInsertId(); err != nil {
  297. return
  298. }
  299. return
  300. }
  301. // MinIDDailyBillByVer .
  302. func (d *Dao) MinIDDailyBillByVer(ctx context.Context, ver int64) (minID int64, err error) {
  303. row := d.db.QueryRow(ctx, _minIDDailyBillByVer, ver)
  304. if err = row.Scan(&minID); err != nil {
  305. if err == xsql.ErrNoRows {
  306. err = nil
  307. minID = math.MaxInt32
  308. }
  309. return
  310. }
  311. minID--
  312. return
  313. }
  314. // DailyBillListByVer bill list
  315. func (d *Dao) DailyBillListByVer(ctx context.Context, ver int64, fromID int64, limit int) (maxID int64, data []*model.DailyBill, err error) {
  316. rows, err := d.db.Query(ctx, _dailyBillListByVer, ver, fromID, limit)
  317. if err != nil {
  318. return
  319. }
  320. defer rows.Close()
  321. for rows.Next() {
  322. d := &model.DailyBill{}
  323. if err = rows.Scan(&d.ID, &d.BillID, &d.MID, &d.Biz, &d.Currency, &d.In, &d.Out, &d.Ver, &d.MonthVer, &d.CTime, &d.MTime, &d.Version); err != nil {
  324. return
  325. }
  326. if d.ID > maxID {
  327. maxID = d.ID
  328. }
  329. data = append(data, d)
  330. }
  331. err = rows.Err()
  332. return
  333. }
  334. // MinIDDailyBillByMonthVer .
  335. func (d *Dao) MinIDDailyBillByMonthVer(ctx context.Context, monthVer int64) (minID int64, err error) {
  336. row := d.db.QueryRow(ctx, _minIDDailyBillByMonthVer, monthVer)
  337. if err = row.Scan(&minID); err != nil {
  338. if err == xsql.ErrNoRows {
  339. err = nil
  340. minID = math.MaxInt32
  341. }
  342. return
  343. }
  344. minID--
  345. return
  346. }
  347. // DailyBillListByMonthVer bill list
  348. func (d *Dao) DailyBillListByMonthVer(ctx context.Context, monthVer int64, fromID int64, limit int) (maxID int64, data []*model.DailyBill, err error) {
  349. rows, err := d.db.Query(ctx, _dailyBillListByMonthVer, monthVer, fromID, limit)
  350. if err != nil {
  351. return
  352. }
  353. defer rows.Close()
  354. for rows.Next() {
  355. d := &model.DailyBill{}
  356. if err = rows.Scan(&d.ID, &d.BillID, &d.MID, &d.Biz, &d.Currency, &d.In, &d.Out, &d.Ver, &d.MonthVer, &d.CTime, &d.MTime, &d.Version); err != nil {
  357. return
  358. }
  359. if d.ID > maxID {
  360. maxID = d.ID
  361. }
  362. data = append(data, d)
  363. }
  364. err = rows.Err()
  365. return
  366. }
  367. // TXInsertLogDailyBill .
  368. func (d *Dao) TXInsertLogDailyBill(ctx context.Context, tx *xsql.Tx, log *model.LogBillDaily) (id int64, err error) {
  369. result, err := tx.Exec(_insertDailyBillLog, log.BillID, log.FromIn, log.ToIn, log.FromOut, log.ToOut, log.OrderID)
  370. if err != nil {
  371. return
  372. }
  373. id, err = result.LastInsertId()
  374. return
  375. }
  376. // TXInsertLogMonthlyBill .
  377. func (d *Dao) TXInsertLogMonthlyBill(ctx context.Context, tx *xsql.Tx, log *model.LogBillMonthly) (id int64, err error) {
  378. result, err := tx.Exec(_insertMonthlyBillLog, log.BillID, log.FromIn, log.ToIn, log.FromOut, log.ToOut, log.BillUserDailyID)
  379. if err != nil {
  380. return
  381. }
  382. id, err = result.LastInsertId()
  383. return
  384. }
  385. // MinIDMonthlyBill .
  386. func (d *Dao) MinIDMonthlyBill(ctx context.Context, ver int64) (minID int64, err error) {
  387. row := d.db.QueryRow(ctx, _minIDMonthlyBill, ver)
  388. if err = row.Scan(&minID); err != nil {
  389. if err == xsql.ErrNoRows {
  390. err = nil
  391. minID = math.MaxInt32
  392. }
  393. return
  394. }
  395. minID--
  396. return
  397. }
  398. // MonthlyBillList bill list
  399. func (d *Dao) MonthlyBillList(ctx context.Context, ver int64, fromID int64, limit int) (maxID int64, data []*model.Bill, err error) {
  400. rows, err := d.db.Query(ctx, _monthlyBillList, ver, fromID, limit)
  401. if err != nil {
  402. return
  403. }
  404. defer rows.Close()
  405. for rows.Next() {
  406. d := &model.Bill{}
  407. if err = rows.Scan(&d.ID, &d.BillID, &d.MID, &d.Biz, &d.Currency, &d.In, &d.Out, &d.Ver, &d.CTime, &d.MTime, &d.Version); err != nil {
  408. return
  409. }
  410. if d.ID > maxID {
  411. maxID = d.ID
  412. }
  413. data = append(data, d)
  414. }
  415. err = rows.Err()
  416. return
  417. }
  418. // DailyBill .
  419. func (d *Dao) DailyBill(ctx context.Context, mid int64, biz string, currency string, ver int64) (data *model.DailyBill, err error) {
  420. row := d.db.QueryRow(ctx, _dailyBill, mid, biz, currency, ver)
  421. data = &model.DailyBill{}
  422. if err = row.Scan(&data.ID, &data.BillID, &data.MID, &data.Biz, &data.Currency, &data.In, &data.Out, &data.Ver, &data.MonthVer, &data.CTime, &data.MTime, &data.Version); err != nil {
  423. if err == xsql.ErrNoRows {
  424. err = nil
  425. data = nil
  426. }
  427. return
  428. }
  429. return
  430. }
  431. // InsertDailyBill .
  432. func (d *Dao) InsertDailyBill(ctx context.Context, bill *model.DailyBill) (id int64, err error) {
  433. result, err := d.db.Exec(ctx, _insertDailyBill, bill.BillID, bill.MID, bill.Biz, bill.Currency, bill.In, bill.Out, bill.Ver, bill.MonthVer, bill.Version)
  434. if err != nil {
  435. return
  436. }
  437. id, err = result.LastInsertId()
  438. return
  439. }
  440. // TXUpdateDailyBill .
  441. func (d *Dao) TXUpdateDailyBill(ctx context.Context, tx *xsql.Tx, bill *model.DailyBill) (rows int64, err error) {
  442. result, err := tx.Exec(_updateDailyBill, bill.BillID, bill.MID, bill.Biz, bill.Currency, bill.In, bill.Out, bill.Ver, bill.MonthVer, bill.MID, bill.Biz, bill.Currency, bill.Ver, bill.Version)
  443. if err != nil {
  444. return
  445. }
  446. rows, err = result.RowsAffected()
  447. return
  448. }
  449. const (
  450. _upsertDeltaDailyBill = "INSERT INTO bill_user_daily (bill_id,mid,biz,currency,`in`,`out`,ver,month_ver) VALUES (?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE `in`=`in`+?,`out`=`out`+?"
  451. _updateDeltaDailyBill = "UPDATE bill_user_daily SET `in`=`in`+?,`out`=`out`+? WHERE mid=? AND biz=? AND currency=? AND ver=?"
  452. )
  453. // TXUpsertDeltaDailyBill .
  454. func (d *Dao) TXUpsertDeltaDailyBill(ctx context.Context, tx *xsql.Tx, bill *model.DailyBill, deltaIn, deltaOut int64) (rows int64, err error) {
  455. result, err := tx.Exec(_upsertDeltaDailyBill, bill.BillID, bill.MID, bill.Biz, bill.Currency, deltaIn, deltaOut, bill.Ver, bill.MonthVer, deltaIn, deltaOut)
  456. if err != nil {
  457. return
  458. }
  459. rows, err = result.RowsAffected()
  460. return
  461. }
  462. // TXUpdateDeltaDailyBill .
  463. func (d *Dao) TXUpdateDeltaDailyBill(ctx context.Context, tx *xsql.Tx, deltaIn, deltaOut int64, mid int64, biz string, currency string, ver int64) (rows int64, err error) {
  464. result, err := tx.Exec(_updateDeltaDailyBill, deltaIn, deltaOut, mid, biz, currency, ver)
  465. if err != nil {
  466. return
  467. }
  468. rows, err = result.RowsAffected()
  469. return
  470. }
  471. // MonthlyBill .
  472. func (d *Dao) MonthlyBill(ctx context.Context, mid int64, biz string, currency string, ver int64) (data *model.Bill, err error) {
  473. row := d.db.QueryRow(ctx, _monthlyBill, mid, biz, currency, ver)
  474. data = &model.Bill{}
  475. if err = row.Scan(&data.ID, &data.BillID, &data.MID, &data.Biz, &data.Currency, &data.In, &data.Out, &data.Ver, &data.CTime, &data.MTime, &data.Version); err != nil {
  476. if err == xsql.ErrNoRows {
  477. err = nil
  478. data = nil
  479. }
  480. return
  481. }
  482. return
  483. }
  484. // InsertMonthlyBill .
  485. func (d *Dao) InsertMonthlyBill(ctx context.Context, bill *model.Bill) (id int64, err error) {
  486. result, err := d.db.Exec(ctx, _insertMonthlyBill, bill.BillID, bill.MID, bill.Biz, bill.Currency, bill.In, bill.Out, bill.Ver, bill.Version)
  487. if err != nil {
  488. return
  489. }
  490. id, err = result.LastInsertId()
  491. return
  492. }
  493. // TXUpdateMonthlyBill .
  494. func (d *Dao) TXUpdateMonthlyBill(ctx context.Context, tx *xsql.Tx, bill *model.Bill) (rows int64, err error) {
  495. result, err := tx.Exec(_updateMonthlyBill, bill.BillID, bill.MID, bill.Biz, bill.Currency, bill.In, bill.Out, bill.Ver, bill.MID, bill.Biz, bill.Currency, bill.Ver, bill.Version)
  496. if err != nil {
  497. return
  498. }
  499. rows, err = result.RowsAffected()
  500. return
  501. }
  502. const (
  503. _upsertDeltaMonthlyBill = "INSERT INTO bill_user_monthly (bill_id,mid,biz,currency,`in`,`out`,ver) VALUES (?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE `in`=`in`+?,`out`=`out`+?"
  504. _updateDeltaMonthlyBill = "UPDATE bill_user_monthly SET `in`=`in`+?,`out`=`out`+? WHERE mid=? AND biz=? AND currency=? AND ver=?"
  505. )
  506. // TXUpsertDeltaMonthlyBill .
  507. func (d *Dao) TXUpsertDeltaMonthlyBill(ctx context.Context, tx *xsql.Tx, bill *model.Bill, deltaIn, deltaOut int64) (rows int64, err error) {
  508. result, err := tx.Exec(_upsertDeltaMonthlyBill, bill.BillID, bill.MID, bill.Biz, bill.Currency, deltaIn, deltaOut, bill.Ver, deltaIn, deltaOut)
  509. if err != nil {
  510. return
  511. }
  512. rows, err = result.RowsAffected()
  513. return
  514. }
  515. // TXUpdateDeltaMonthlyBill .
  516. func (d *Dao) TXUpdateDeltaMonthlyBill(ctx context.Context, tx *xsql.Tx, deltaIn, deltaOut int64, mid int64, biz string, currency string, ver int64) (rows int64, err error) {
  517. result, err := tx.Exec(_updateDeltaMonthlyBill, deltaIn, deltaOut, mid, biz, currency, ver)
  518. if err != nil {
  519. return
  520. }
  521. rows, err = result.RowsAffected()
  522. return
  523. }
  524. // MinIDUserAccount .
  525. func (d *Dao) MinIDUserAccount(ctx context.Context, beginTime time.Time) (minID int64, err error) {
  526. row := d.db.QueryRow(ctx, _minIDUserAccount, beginTime)
  527. if err = row.Scan(&minID); err != nil {
  528. if err == xsql.ErrNoRows {
  529. err = nil
  530. minID = math.MaxInt32
  531. }
  532. return
  533. }
  534. minID--
  535. return
  536. }
  537. // UserAccountList bill list
  538. func (d *Dao) UserAccountList(ctx context.Context, beginTime time.Time, endTime time.Time, fromID int64, limit int) (maxID int64, datas []*model.UserAccount, err error) {
  539. rows, err := d.db.Query(ctx, _userAccountList, beginTime, endTime, fromID, limit)
  540. if err != nil {
  541. return
  542. }
  543. defer rows.Close()
  544. for rows.Next() {
  545. data := &model.UserAccount{}
  546. if err = rows.Scan(&data.ID, &data.MID, &data.Biz, &data.Currency, &data.Balance, &data.Ver, &data.State, &data.CTime, &data.MTime); err != nil {
  547. return
  548. }
  549. if data.ID > maxID {
  550. maxID = data.ID
  551. }
  552. datas = append(datas, data)
  553. }
  554. err = rows.Err()
  555. return
  556. }
  557. // UserAccount .
  558. func (d *Dao) UserAccount(ctx context.Context, mid int64, biz string, currency string) (data *model.UserAccount, err error) {
  559. row := d.db.QueryRow(ctx, _userAccount, mid, biz, currency)
  560. data = &model.UserAccount{}
  561. if err = row.Scan(&data.ID, &data.MID, &data.Biz, &data.Currency, &data.Balance, &data.Ver, &data.State, &data.CTime, &data.MTime); err != nil {
  562. if err == xsql.ErrNoRows {
  563. err = nil
  564. data = nil
  565. }
  566. return
  567. }
  568. return
  569. }
  570. // InsertUserAccount .
  571. func (d *Dao) InsertUserAccount(ctx context.Context, account *model.UserAccount) (id int64, err error) {
  572. result, err := d.db.Exec(ctx, _insertUserAccount, account.MID, account.Biz, account.Currency, account.Balance, account.Ver, account.State)
  573. if err != nil {
  574. return
  575. }
  576. id, err = result.LastInsertId()
  577. return
  578. }
  579. // TXUpdateUserAccount .
  580. func (d *Dao) TXUpdateUserAccount(ctx context.Context, tx *xsql.Tx, account *model.UserAccount) (rows int64, err error) {
  581. result, err := tx.Exec(_updateUserAccount, account.MID, account.Biz, account.Currency, account.Balance, account.State, account.MID, account.Biz, account.Currency, account.Ver)
  582. if err != nil {
  583. return
  584. }
  585. rows, err = result.RowsAffected()
  586. return
  587. }
  588. const (
  589. _upsertDeltaUserAccount = "INSERT INTO account_user (mid,biz,currency,balance,ver,state) VALUES (?,?,?,?,?,?) ON DUPLICATE KEY UPDATE balance=balance+?,ver=ver+1"
  590. _updateDeltaUserAccount = `UPDATE account_user SET balance=balance+?,ver=ver+1 WHERE mid=? AND biz=? AND currency=?`
  591. )
  592. // TXUpsertDeltaUserAccount .
  593. func (d *Dao) TXUpsertDeltaUserAccount(ctx context.Context, tx *xsql.Tx, account *model.UserAccount, deltaBalance int64) (rows int64, err error) {
  594. result, err := tx.Exec(_upsertDeltaUserAccount, account.MID, account.Biz, account.Currency, deltaBalance, account.Ver, account.State, deltaBalance)
  595. if err != nil {
  596. return
  597. }
  598. rows, err = result.RowsAffected()
  599. return
  600. }
  601. // TXUpdateDeltaUserAccount .
  602. func (d *Dao) TXUpdateDeltaUserAccount(ctx context.Context, tx *xsql.Tx, deltaBalance int64, mid int64, biz string, currency string) (rows int64, err error) {
  603. result, err := tx.Exec(_updateDeltaUserAccount, deltaBalance, mid, biz, currency)
  604. if err != nil {
  605. return
  606. }
  607. rows, err = result.RowsAffected()
  608. return
  609. }
  610. // TXInsertUserAccountLog .
  611. func (d *Dao) TXInsertUserAccountLog(ctx context.Context, tx *xsql.Tx, accountLog *model.AccountLog) (err error) {
  612. _, err = tx.Exec(_insertUserAccountLog, accountLog.AccountID, accountLog.From, accountLog.To, accountLog.Ver, accountLog.State, accountLog.Name)
  613. return
  614. }
  615. // BizAccount .
  616. func (d *Dao) BizAccount(ctx context.Context, biz string, currency string) (data *model.BizAccount, err error) {
  617. row := d.db.QueryRow(ctx, _bizAccount, biz, currency)
  618. data = &model.BizAccount{}
  619. if err = row.Scan(&data.ID, &data.Biz, &data.Currency, &data.Balance, &data.Ver, &data.State, &data.CTime, &data.MTime); err != nil {
  620. if err == xsql.ErrNoRows {
  621. err = nil
  622. data = nil
  623. }
  624. return
  625. }
  626. return
  627. }
  628. // InsertBizAccount .
  629. func (d *Dao) InsertBizAccount(ctx context.Context, account *model.BizAccount) (id int64, err error) {
  630. result, err := d.db.Exec(ctx, _insertBizAccount, account.Biz, account.Currency, account.Balance, account.Ver, account.State)
  631. if err != nil {
  632. return
  633. }
  634. id, err = result.LastInsertId()
  635. return
  636. }
  637. // TXUpdateBizAccount .
  638. func (d *Dao) TXUpdateBizAccount(ctx context.Context, tx *xsql.Tx, account *model.BizAccount) (rows int64, err error) {
  639. result, err := tx.Exec(_updateBizAccount, account.Biz, account.Currency, account.Balance, account.State, account.Biz, account.Currency, account.Ver)
  640. if err != nil {
  641. return
  642. }
  643. rows, err = result.RowsAffected()
  644. return
  645. }
  646. const (
  647. _upsertDeltaBizAccount = "INSERT INTO account_biz (biz,currency,balance,ver,state) VALUES (?,?,?,?,?) ON DUPLICATE KEY UPDATE balance=balance+?,ver=ver+1"
  648. _updateDeltaBizAccount = `UPDATE account_biz SET balance=balance+?,ver=ver+1 WHERE biz=? AND currency=?`
  649. )
  650. // TXUpsertDeltaBizAccount .
  651. func (d *Dao) TXUpsertDeltaBizAccount(ctx context.Context, tx *xsql.Tx, account *model.BizAccount, deltaBalance int64) (rows int64, err error) {
  652. result, err := tx.Exec(_upsertDeltaBizAccount, account.Biz, account.Currency, deltaBalance, account.Ver, account.State, deltaBalance)
  653. if err != nil {
  654. return
  655. }
  656. rows, err = result.RowsAffected()
  657. return
  658. }
  659. // TXUpdateDeltaBizAccount .
  660. func (d *Dao) TXUpdateDeltaBizAccount(ctx context.Context, tx *xsql.Tx, deltaBalance int64, biz string, currency string) (rows int64, err error) {
  661. result, err := tx.Exec(_updateDeltaBizAccount, deltaBalance, biz, currency)
  662. if err != nil {
  663. return
  664. }
  665. rows, err = result.RowsAffected()
  666. return
  667. }
  668. // TXInsertBizAccountLog .
  669. func (d *Dao) TXInsertBizAccountLog(ctx context.Context, tx *xsql.Tx, accountLog *model.AccountLog) (err error) {
  670. _, err = tx.Exec(_insertBizAccountLog, accountLog.AccountID, accountLog.From, accountLog.To, accountLog.Ver, accountLog.State, accountLog.Name)
  671. return
  672. }
  673. // AggrIncomeUser .
  674. func (d *Dao) AggrIncomeUser(ctx context.Context, mid int64, currency string) (data *model.AggrIncomeUser, err error) {
  675. row := d.db.QueryRow(ctx, _aggrIncomeUser, mid, currency)
  676. data = &model.AggrIncomeUser{}
  677. if err = row.Scan(&data.ID, &data.MID, &data.Currency, &data.PaySuccess, &data.PayError, &data.TotalIn, &data.TotalOut, &data.CTime, &data.MTime); err != nil {
  678. if err == xsql.ErrNoRows {
  679. err = nil
  680. data = nil
  681. }
  682. return
  683. }
  684. return
  685. }
  686. // InsertAggrIncomeUser .
  687. func (d *Dao) InsertAggrIncomeUser(ctx context.Context, aggr *model.AggrIncomeUser) (id int64, err error) {
  688. result, err := d.db.Exec(ctx, _insertAggrIncomeUser, aggr.MID, aggr.Currency, aggr.PaySuccess, aggr.PayError, aggr.TotalIn, aggr.TotalOut)
  689. if err != nil {
  690. return
  691. }
  692. id, err = result.LastInsertId()
  693. return
  694. }
  695. // TXUpdateAggrIncomeUser .
  696. func (d *Dao) TXUpdateAggrIncomeUser(ctx context.Context, tx *xsql.Tx, aggr *model.AggrIncomeUser) (rows int64, err error) {
  697. result, err := tx.Exec(_updateAggrIncomeUser, aggr.MID, aggr.Currency, aggr.PaySuccess, aggr.PayError, aggr.TotalIn, aggr.TotalOut, aggr.MID, aggr.Currency)
  698. if err != nil {
  699. return
  700. }
  701. rows, err = result.RowsAffected()
  702. return
  703. }
  704. const (
  705. _upsertDeltaAggrIncomeUser = "INSERT INTO aggr_income_user (mid,currency,pay_success,pay_error,total_in,total_out) VALUES (?,?,?,?,?,?) ON DUPLICATE KEY UPDATE pay_success=pay_success+?,pay_error=pay_error+?,total_in=total_in+?,total_out=total_out+?"
  706. _updateDeltaAggrIncomeUser = "UPDATE aggr_income_user SET pay_success=pay_success+?,pay_error=pay_error+?,total_in=total_in+?,total_out=total_out+? WHERE mid=? AND currency=?"
  707. )
  708. // TXUpsertDeltaAggrIncomeUser .
  709. func (d *Dao) TXUpsertDeltaAggrIncomeUser(ctx context.Context, tx *xsql.Tx, aggr *model.AggrIncomeUser, deltaPaySuccess, deltaPayError, deltaTotalIn, deltaTotalOut int64) (rows int64, err error) {
  710. result, err := tx.Exec(_upsertDeltaAggrIncomeUser, aggr.MID, aggr.Currency, deltaPaySuccess, deltaPayError, deltaTotalIn, deltaTotalOut, deltaPaySuccess, deltaPayError, deltaTotalIn, deltaTotalOut)
  711. if err != nil {
  712. return
  713. }
  714. rows, err = result.RowsAffected()
  715. return
  716. }
  717. // TXUpdateDeltaAggrIncomeUser .
  718. func (d *Dao) TXUpdateDeltaAggrIncomeUser(ctx context.Context, tx *xsql.Tx, deltaPaySuccess, deltaPayError, deltaTotalIn, deltaTotalOut int64, mid int64, currency string) (rows int64, err error) {
  719. result, err := tx.Exec(_updateDeltaAggrIncomeUser, deltaPaySuccess, deltaPayError, deltaTotalIn, deltaTotalOut, mid, currency)
  720. if err != nil {
  721. return
  722. }
  723. rows, err = result.RowsAffected()
  724. return
  725. }
  726. // AggrIncomeUserAsset .
  727. func (d *Dao) AggrIncomeUserAsset(ctx context.Context, mid int64, currency string, ver int64, oid int64, otype string) (data *model.AggrIncomeUserAsset, err error) {
  728. row := d.db.QueryRow(ctx, _aggrIncomeUserAsset, mid, currency, ver, oid, otype)
  729. data = &model.AggrIncomeUserAsset{}
  730. if err = row.Scan(&data.ID, &data.MID, &data.Currency, &data.Ver, &data.OID, &data.OType, &data.PaySuccess, &data.PayError, &data.TotalIn, &data.TotalOut, &data.CTime, &data.MTime); err != nil {
  731. if err == xsql.ErrNoRows {
  732. err = nil
  733. data = nil
  734. }
  735. return
  736. }
  737. return
  738. }
  739. // InsertAggrIncomeUserAsset .
  740. func (d *Dao) InsertAggrIncomeUserAsset(ctx context.Context, aggr *model.AggrIncomeUserAsset) (id int64, err error) {
  741. result, err := d.db.Exec(ctx, _insertAggrIncomeUserAsset, aggr.MID, aggr.Currency, aggr.Ver, aggr.OID, aggr.OType, aggr.PaySuccess, aggr.PayError, aggr.TotalIn, aggr.TotalOut)
  742. if err != nil {
  743. return
  744. }
  745. id, err = result.LastInsertId()
  746. return
  747. }
  748. // TXUpdateAggrIncomeUserAsset .
  749. func (d *Dao) TXUpdateAggrIncomeUserAsset(ctx context.Context, tx *xsql.Tx, aggr *model.AggrIncomeUserAsset) (rows int64, err error) {
  750. result, err := tx.Exec(_updateAggrIncomeUserAsset, aggr.MID, aggr.Currency, aggr.Ver, aggr.OID, aggr.OType, aggr.PaySuccess, aggr.PayError, aggr.TotalIn, aggr.TotalOut, aggr.MID, aggr.Currency, aggr.Ver, aggr.OID, aggr.OType)
  751. if err != nil {
  752. return
  753. }
  754. rows, err = result.RowsAffected()
  755. return
  756. }
  757. const (
  758. _upsertDeltaAggrIncomeUserAsset = "INSERT INTO aggr_income_user_asset (mid,currency,`ver`,oid,otype,pay_success,pay_error,total_in,total_out) VALUES (?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE pay_success=pay_success+?,pay_error=pay_error+?,total_in=total_in+?,total_out=total_out+?"
  759. _updateDeltaAggrIncomeUserAsset = "UPDATE aggr_income_user_asset SET pay_success=pay_success+?,pay_error=pay_error+?,total_in=total_in+?,total_out=total_out+? WHERE mid=? AND currency=? AND ver=? AND oid=? AND otype=?"
  760. )
  761. // TXUpsertDeltaAggrIncomeUserAsset .
  762. func (d *Dao) TXUpsertDeltaAggrIncomeUserAsset(ctx context.Context, tx *xsql.Tx, aggr *model.AggrIncomeUserAsset, deltaPaySuccess, deltaPayError, deltaTotalIn, deltaTotalOut int64) (rows int64, err error) {
  763. result, err := tx.Exec(_upsertDeltaAggrIncomeUserAsset, aggr.MID, aggr.Currency, aggr.Ver, aggr.OID, aggr.OType, deltaPaySuccess, deltaPayError, deltaTotalIn, deltaTotalOut, deltaPaySuccess, deltaPayError, deltaTotalIn, deltaTotalOut)
  764. if err != nil {
  765. return
  766. }
  767. rows, err = result.RowsAffected()
  768. return
  769. }
  770. // TXUpdateDeltaAggrIncomeUserAsset .
  771. func (d *Dao) TXUpdateDeltaAggrIncomeUserAsset(ctx context.Context, tx *xsql.Tx, deltaPaySuccess, deltaPayError, deltaTotalIn, deltaTotalOut int64, mid int64, currency string, ver int64, oid int64, otype string) (rows int64, err error) {
  772. result, err := tx.Exec(_updateDeltaAggrIncomeUserAsset, deltaPaySuccess, deltaPayError, deltaTotalIn, deltaTotalOut, mid, currency, ver, oid, otype)
  773. if err != nil {
  774. return
  775. }
  776. rows, err = result.RowsAffected()
  777. return
  778. }
  779. // OrderBadDebt .
  780. func (d *Dao) OrderBadDebt(ctx context.Context, orderID string) (data *model.OrderBadDebt, err error) {
  781. row := d.db.QueryRow(ctx, _orderBadDebt, orderID)
  782. data = &model.OrderBadDebt{}
  783. if err = row.Scan(&data.ID, &data.OrderID, &data.Type, &data.State, &data.CTime, &data.MTime); err != nil {
  784. if err == xsql.ErrNoRows {
  785. err = nil
  786. data = nil
  787. }
  788. return
  789. }
  790. return
  791. }
  792. // InsertOrderBadDebt .
  793. func (d *Dao) InsertOrderBadDebt(ctx context.Context, order *model.OrderBadDebt) (id int64, err error) {
  794. result, err := d.db.Exec(ctx, _insertOrderBadDebt, order.OrderID, order.Type, order.State)
  795. if err != nil {
  796. return
  797. }
  798. id, err = result.LastInsertId()
  799. return
  800. }
  801. // TXUpdateOrderBadDebt .
  802. func (d *Dao) TXUpdateOrderBadDebt(ctx context.Context, tx *xsql.Tx, order *model.OrderBadDebt) (rows int64, err error) {
  803. result, err := tx.Exec(_updateOrderBadDebt, order.OrderID, order.Type, order.State, order.OrderID)
  804. if err != nil {
  805. return
  806. }
  807. rows, err = result.RowsAffected()
  808. return
  809. }
  810. // TXInsertOrderRechargeShell .
  811. func (d *Dao) TXInsertOrderRechargeShell(ctx context.Context, tx *xsql.Tx, order *model.OrderRechargeShell) (id int64, err error) {
  812. result, err := tx.Exec(_insertOrderRechargeShell, order.MID, order.OrderID, order.Biz, order.Amount, order.PayMSG, order.State, order.Ver)
  813. if err != nil {
  814. return
  815. }
  816. id, err = result.LastInsertId()
  817. return
  818. }
  819. // TXInsertOrderRechargeShellLog .
  820. func (d *Dao) TXInsertOrderRechargeShellLog(ctx context.Context, tx *xsql.Tx, order *model.OrderRechargeShellLog) (id int64, err error) {
  821. result, err := tx.Exec(_insertOrderRechargeShellLog, order.OrderID, order.FromState, order.ToState, order.Desc, order.BillUserMonthlyID)
  822. if err != nil {
  823. return
  824. }
  825. id, err = result.LastInsertId()
  826. return
  827. }