package withdrawals import ( "github.com/shopspring/decimal" "path/filepath" "recook/internal/back" "recook/internal/dbc" "recook/internal/domain" "recook/internal/model/user" "recook/internal/static_path" "recook/tools" "time" "github.com/gin-gonic/gin" ) type queryParam struct { UserID uint `json:"userId"` Page uint `json:"page"` MaxMoney float32 `json:"maxMoney"` MinMoney float32 `json:"minMoney"` Name string `json:"name"` ID int `json:"id"` } type downloadIncompleteParam struct { UserID uint `json:"userId"` } /* 打款完成 */ func QueryIncomplete(c *gin.Context) { var p queryParam err := tools.Params(&p, c) if err != nil { back.Fail(c, err.Error()) return } where := "status = 2 " if p.MaxMoney != 0.0 && p.MinMoney != 0.0 { where += " and amount between ? and ?" } else { where += " and amount > ? and amount > ?" } if p.ID != 0 { where += " and id = ?" } else { where += " and id > ?" } var id []uint id = append(id, 0) if p.Name != "" { where += " and user_name =? " } else { where += " and user_name !=? " } var count uint dbc.DB.Table((&user.Withdraw{}).TableName()).Where(where, p.MinMoney, p.MaxMoney, p.ID, p.Name).Count(&count) var array []user.Withdraw dbc.DB.Limit(10).Offset(p.Page*10).Order("created_at desc").Find(&array, where, p.MinMoney, p.MaxMoney, p.ID, p.Name) type moneyType struct { Monet float32 `gorm:"column:all_amount"` ActualAmountCount decimal.Decimal `gorm:"column:actual_amount_count"` } var moneyAll moneyType dbc.DB.Table((&user.Withdraw{}).TableName()).Select("sum(amount) as all_amount, sum(actual_amount) as actual_amount_count").Where(where, p.MinMoney, p.MaxMoney, p.ID, p.Name).Scan(&moneyAll) for key, _info := range array { information := user.Information{} dbc.DB.Table("recook_user_info").First(&information, "id = ?", _info.UserId) array[key].UserTrueName = information.RealName array[key].UserTrueNo = information.IDCard array[key].UserPhone = information.Mobile } back.Suc(c, "", gin.H{ "total": count, "list": array, "money": moneyAll.Monet, "actualAmountCount": moneyAll.ActualAmountCount, }) } func DownloadWaitcomplete(c *gin.Context) { var p downloadIncompleteParam err := tools.Params(&p, c) if err != nil { back.Fail(c, err.Error()) return } var array []user.Withdraw dbc.DB.Find(&array, "status = 1 and wait_status =1 ") if len(array) == 0 { back.Suc(c, "暂无用户提现记录", gin.H{ "path": nil, }) return } var ptrArray [][]interface{} for i := range array { information := user.Information{} dbc.DB.Table("recook_user_info").First(&information, "id = ?", array[i].UserId) array[i].WaitStatus = 1 dbc.DB.Table("recook_user_withdraw").Where("id = ?", array[i].ID).Update(array[i]) one := MapToPtrArray(&array[i], &information) ptrArray = append(ptrArray, one) } f := Create(ptrArray) name := time.Now().Format("20060102-150405") + tools.GenerateGoodsHashSign() + ".xlsx" err = f.SaveAs(filepath.Join(static_path.Dir.Root, static_path.Dir.Temp, name)) if err != nil { back.Err(c, err.Error()) return } back.Suc(c, "", gin.H{ "path": domain.GetName() + filepath.Join(static_path.Dir.Static, static_path.Dir.Temp, name), }) } func DownloadIncomplete(c *gin.Context) { var p downloadIncompleteParam err := tools.Params(&p, c) if err != nil { back.Fail(c, err.Error()) return } var array []user.Withdraw dbc.DB.Find(&array, "status = 1 and wait_status =0 ") if len(array) == 0 { back.Suc(c, "暂无用户提现记录", gin.H{ "path": nil, }) return } var ptrArray [][]interface{} for i := range array { information := user.Information{} dbc.DB.Table("recook_user_info").First(&information, "id = ?", array[i].UserId) array[i].WaitStatus = 1 dbc.DB.Table("recook_user_withdraw").Where("id = ?", array[i].ID).Update(array[i]) one := MapToPtrArray(&array[i], &information) ptrArray = append(ptrArray, one) } f := Create(ptrArray) name := time.Now().Format("20060102-150405") + tools.GenerateGoodsHashSign() + ".xlsx" err = f.SaveAs(filepath.Join(static_path.Dir.Root, static_path.Dir.Temp, name)) if err != nil { back.Err(c, err.Error()) return } back.Suc(c, "", gin.H{ "path": domain.GetName() + filepath.Join(static_path.Dir.Static, static_path.Dir.Temp, name), }) } func QueryWaitcomplete(c *gin.Context) { var p queryParam err := tools.Params(&p, c) if err != nil { back.Fail(c, err.Error()) return } where := "status = 1 and wait_status = 1 " if p.MaxMoney != 0.0 && p.MinMoney != 0.0 { where += " and amount between ? and ?" } else { where += " and amount > ? and amount > ?" } if p.ID != 0 { where += " and id = ?" } else { where += " and id > ?" } var id []uint id = append(id, 0) if p.Name != "" { where += " and user_name =? " } else { where += " and user_name !=? " } var count uint dbc.DB.Table((&user.Withdraw{}).TableName()).Where(where, p.MinMoney, p.MaxMoney, p.ID, p.Name).Count(&count) var array []user.Withdraw dbc.DB.Limit(10).Offset(p.Page*10).Order("created_at desc").Find(&array, where, p.MinMoney, p.MaxMoney, p.ID, p.Name) type moneyType struct { Monet float32 `gorm:"column:all_amount"` ActualAmountCount decimal.Decimal `gorm:"column:actual_amount_count"` } var moneyAll moneyType dbc.DB.Table((&user.Withdraw{}).TableName()).Select("sum(amount) as all_amount, sum(actual_amount) as actual_amount_count").Where(where, p.MinMoney, p.MaxMoney, p.ID, p.Name).Scan(&moneyAll) for key, _info := range array { information := user.Information{} dbc.DB.Table("recook_user_info").First(&information, "id = ?", _info.UserId) array[key].UserTrueName = information.RealName array[key].UserTrueNo = information.IDCard array[key].UserPhone = information.Mobile } back.Suc(c, "", gin.H{ "total": count, "list": array, "money": moneyAll.Monet, "actualAmountCount": moneyAll.ActualAmountCount, }) } //打款失败 func QueryFail(c *gin.Context) { var p queryParam err := tools.Params(&p, c) if err != nil { back.Fail(c, err.Error()) return } where := "status = 3" if p.MaxMoney != 0.0 && p.MinMoney != 0.0 { where += " and amount between ? and ?" } else { where += " and amount > ? and amount > ?" } if p.ID != 0 { where += " and id = ?" } else { where += " and id > ?" } var id []uint id = append(id, 0) if p.Name != "" { where += " and user_name =? " } else { where += " and user_name !=? " } var count uint dbc.DB.Table((&user.Withdraw{}).TableName()).Where(where, p.MinMoney, p.MaxMoney, p.ID, p.Name).Count(&count) var array []user.Withdraw dbc.DB.Limit(10).Offset(p.Page*10).Order("created_at desc").Find(&array, where, p.MinMoney, p.MaxMoney, p.ID, p.Name) type moneyType struct { Monet float32 `gorm:"column:all_amount"` ActualAmountCount decimal.Decimal `gorm:"column:actual_amount_count"` } var moneyAll moneyType dbc.DB.Table((&user.Withdraw{}).TableName()).Select("sum(amount) as all_amount, sum(actual_amount) as actual_amount_count").Where(where, p.MinMoney, p.MaxMoney, p.ID, p.Name).Scan(&moneyAll) for key, _info := range array { information := user.Information{} dbc.DB.Table("recook_user_info").First(&information, "id = ?", _info.UserId) array[key].UserTrueName = information.RealName array[key].UserTrueNo = information.IDCard array[key].UserPhone = information.Mobile } back.Suc(c, "", gin.H{ "total": count, "list": array, "money": moneyAll.Monet, "actualAmountCount": moneyAll.ActualAmountCount, }) } /* 打款未完成 */ func QueryComplete(c *gin.Context) { var p queryParam err := tools.Params(&p, c) if err != nil { back.Fail(c, err.Error()) return } where := "status = 1 and wait_status =0 " if p.MaxMoney != 0.0 && p.MinMoney != 0.0 { where += " and amount between ? and ?" } else { where += " and amount > ? and amount > ?" } if p.ID != 0 { where += " and id = ?" } else { where += " and id > ?" } var id []uint id = append(id, 0) if p.Name != "" { where += " and user_name =? " } else { where += " and user_name !=? " } var count uint dbc.DB.Table((&user.Withdraw{}).TableName()).Where(where, p.MinMoney, p.MaxMoney, p.ID, p.Name).Count(&count) var array []user.Withdraw dbc.DB.Limit(10).Offset(p.Page*10).Order("created_at desc").Find(&array, where, p.MinMoney, p.MaxMoney, p.ID, p.Name) type moneyType struct { Monet float32 `gorm:"column:all_amount"` ActualAmountCount decimal.Decimal `gorm:"column:actual_amount_count"` } var moneyAll moneyType dbc.DB.Table((&user.Withdraw{}).TableName()).Select("sum(amount) as all_amount, sum(actual_amount) as actual_amount_count").Where(where, p.MinMoney, p.MaxMoney, p.ID, p.Name).Scan(&moneyAll) for key, _info := range array { information := user.Information{} dbc.DB.Table("recook_user_info").First(&information, "id = ?", _info.UserId) array[key].UserTrueName = information.RealName array[key].UserTrueNo = information.IDCard array[key].UserPhone = information.Mobile } back.Suc(c, "", gin.H{ "total": count, "list": array, "money": moneyAll.Monet, "actualAmountCount": moneyAll.ActualAmountCount, }) }