| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- package models
- import (
- "errors"
- "fmt"
- "reflect"
- "strings"
- "github.com/beego/beego/v2/client/orm"
- )
- type WalletDetail struct {
- WalletDetailId int `orm:"column(wallet_detail_id);auto" json:"-"`
- UserId string `orm:"column(user_id)" json:"user_id"`
- InviteCode string `orm:"column(invite_code)" json:"invite_code"`
- Addr string `orm:"column(addr)" json:"addr"`
- Email string `orm:"column(email)" json:"email"`
- TransPassword int `orm:"column(trans_password)" json:"trans_password"`
- XaiceStatus int `orm:"column(xaice_status)" json:"xaice_status"`
- XaiceReleaseStatus int `orm:"column(xaice_release_status)" json:"xaice_release_status"`
- UsdBalance string `orm:"column(usd_balance)" json:"usd_balance"`
- AiceBalance string `orm:"column(aice_balance)" json:"aice_balance"`
- AiceBalanceValue string `orm:"column(aice_balance_value)" json:"aice_balance_value"`
- XaiceBalance string `orm:"column(xaice_balance)" json:"xaice_balance"`
- XaiceBalanceValue string `orm:"column(xaice_balance_value)" json:"xaice_balance_value"`
- XaiceReleaseBalance string `orm:"column(xaice_release_balance)" json:"xaice_release_balance"`
- XaiceReleaseBalanceValue string `orm:"column(xaice_release_balance_value)" json:"xaice_release_balance_value"`
- WithdrawLimit string `orm:"column(withdraw_limit)" json:"withdraw_limit"`
- AiceWithdrawLimit string `orm:"column(aice_withdraw_limit)" json:"aice_withdraw_limit"`
- UsdtWithdrawStatus int `orm:"column(usdt_withdraw_status)" json:"usdt_withdraw_status"`
- AiceWithdrawStatus int `orm:"column(aice_withdraw_status)" json:"aice_withdraw_status"`
- BindStatus int `orm:"column(bind_status)" json:"bind_status"`
- UsdtAddress string `orm:"column(usdt_address)" json:"usdt_address"`
- AiceAddress string `orm:"column(aice_address)" json:"aice_address"`
- UdoStatus int `orm:"column(udo_status)" json:"udo_status"`
- UdoAddr string `orm:"column(udo_addr)" json:"udo_addr"`
- UdoBalance string `orm:"column(udo_balance)" json:"udo_balance"`
- UdoPrice string `orm:"column(udo_price)" json:"udo_price"`
- XaicePrice string `orm:"column(xaice_price)" json:"xaice_price"`
- AnygptUserid string `orm:"column(anygpt_userid)" json:"anygpt_userid"`
- ReceiveAddressStatus int `orm:"column(receive_address_status)" json:"receive_address_status"`
- LegacyTokenBalance string `orm:"column(legacy_token_balance)" json:"legacy_token_balance"`
- LegacyCreditBalance string `orm:"column(legacy_credit_balance)" json:"legacy_credit_balance"`
- CoalesceCreditBalance string `orm:"column(coalesce_credit_balance)" json:"coalesce_credit_balance"`
- ExchangeStatus int `orm:"column(exchange_status)" json:"exchange_status"`
- ExchangeFee string `orm:"column(exchange_fee)" json:"exchange_fee"`
- LegacyTokenUsdt string `orm:"column(legacy_token_usdt)" json:"legacy_token_usdt"`
- CoalesceCreditUsdt string `orm:"column(coalesce_credit_usdt)" json:"coalesce_credit_usdt"`
- UsdtWithdrawLimit string `orm:"column(usdt_withdraw_limit)" json:"usdt_withdraw_limit"`
- XaiceUsdtAddress string `orm:"column(xaice_usdt_address)" json:"xaice_usdt_address"`
- XaiceUsdtWithdrawStatus int `orm:"column(xaice_usdt_withdraw_status)" json:"xaice_usdt_withdraw_status"`
- LockAice string `orm:"column(lock_aice)" json:"lock_aice"`
- MusicAmount string `orm:"column(music_amount)" json:"music_amount"`
- ReleaseAice string `orm:"column(release_aice)" json:"release_aice"`
- ReleaseAiceValue string `orm:"column(release_aice_value)" json:"release_aice_value"`
- }
- func (t *WalletDetail) TableName() string {
- return "wallet_detail"
- }
- func init() {
- orm.RegisterModel(new(WalletDetail))
- }
- // AddWalletDetail insert a new WalletDetail into database and returns
- // last inserted Id on success.
- func AddWalletDetail(m *WalletDetail) (id int64, err error) {
- o := orm.NewOrm()
- id, err = o.Insert(m)
- return
- }
- // GetWalletDetailById retrieves WalletDetail by Id. Returns error if
- // Id doesn't exist
- func GetWalletDetailById(id int) (v *WalletDetail, err error) {
- o := orm.NewOrm()
- v = &WalletDetail{WalletDetailId: id}
- if err = o.Read(v); err == nil {
- return v, nil
- }
- return nil, err
- }
- // GetAllWalletDetail retrieves all WalletDetail matches certain condition. Returns empty list if
- // no records exist
- func GetAllWalletDetail(query map[string]string, fields []string, sortby []string, order []string,
- offset int64, limit int64) (ml []interface{}, err error) {
- o := orm.NewOrm()
- qs := o.QueryTable(new(WalletDetail))
- // query k=v
- for k, v := range query {
- // rewrite dot-notation to Object__Attribute
- k = strings.Replace(k, ".", "__", -1)
- if strings.Contains(k, "isnull") {
- qs = qs.Filter(k, (v == "true" || v == "1"))
- } else {
- qs = qs.Filter(k, v)
- }
- }
- // order by:
- var sortFields []string
- if len(sortby) != 0 {
- if len(sortby) == len(order) {
- // 1) for each sort field, there is an associated order
- for i, v := range sortby {
- orderby := ""
- if order[i] == "desc" {
- orderby = "-" + v
- } else if order[i] == "asc" {
- orderby = v
- } else {
- return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
- }
- sortFields = append(sortFields, orderby)
- }
- qs = qs.OrderBy(sortFields...)
- } else if len(sortby) != len(order) && len(order) == 1 {
- // 2) there is exactly one order, all the sorted fields will be sorted by this order
- for _, v := range sortby {
- orderby := ""
- if order[0] == "desc" {
- orderby = "-" + v
- } else if order[0] == "asc" {
- orderby = v
- } else {
- return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
- }
- sortFields = append(sortFields, orderby)
- }
- } else if len(sortby) != len(order) && len(order) != 1 {
- return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
- }
- } else {
- if len(order) != 0 {
- return nil, errors.New("Error: unused 'order' fields")
- }
- }
- var l []WalletDetail
- qs = qs.OrderBy(sortFields...)
- if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
- if len(fields) == 0 {
- for _, v := range l {
- ml = append(ml, v)
- }
- } else {
- // trim unused fields
- for _, v := range l {
- m := make(map[string]interface{})
- val := reflect.ValueOf(v)
- for _, fname := range fields {
- m[fname] = val.FieldByName(fname).Interface()
- }
- ml = append(ml, m)
- }
- }
- return ml, nil
- }
- return nil, err
- }
- // UpdateWalletDetail updates WalletDetail by Id and returns error if
- // the record to be updated doesn't exist
- func UpdateWalletDetailById(m *WalletDetail) (err error) {
- o := orm.NewOrm()
- v := WalletDetail{WalletDetailId: m.WalletDetailId}
- // ascertain id exists in the database
- if err = o.Read(&v); err == nil {
- var num int64
- if num, err = o.Update(m); err == nil {
- fmt.Println("Number of records updated in database:", num)
- }
- }
- return
- }
- // DeleteWalletDetail deletes WalletDetail by Id and returns error if
- // the record to be deleted doesn't exist
- func DeleteWalletDetail(id int) (err error) {
- o := orm.NewOrm()
- v := WalletDetail{WalletDetailId: id}
- // ascertain id exists in the database
- if err = o.Read(&v); err == nil {
- var num int64
- if num, err = o.Delete(&WalletDetail{WalletDetailId: id}); err == nil {
- fmt.Println("Number of records deleted in database:", num)
- }
- }
- return
- }
|