package financial_center import ( "applet/app/db" "applet/app/e" md "applet/app/md/financial_center" svc "applet/app/svc/financial_center" "applet/app/utils" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" "github.com/gin-gonic/gin" "time" ) // GetWithdrawSetting // @Summary 财务中心-提现-基础设置(获取) // @Tags 提现 // @Description 基础设置(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Success 200 {object} md.GetWithdrawSettingResp "具体数据" // @Failure 400 {object} md.Response "具体错误" // @Router /api/financialCenter/withdraw/setting [get] func GetWithdrawSetting(c *gin.Context) { settingDb := implement.NewFinWithdrawSettingDb(db.Db) setting, err := settingDb.FinWithdrawSettingGetOne() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } // 不存在则初始化 if setting == nil { now := time.Now() frequency := md2.WithdrawFrequencySettingStruct{ Duration: 0, Num: 0, } frequencyStr := utils.SerializeStr(frequency) m := model.FinWithdrawSetting{ FrequencySet: frequencyStr, WithdrawType: 0, VipLevelLimit: 0, IsRealName: 0, WithdrawNumsLimit: 0, WithdrawAmountLimit: "", WithdrawMultipleLimit: "", IsSupportDecimalPoint: 0, IsAuto: 0, WithdrawTimeInterval: "", WithdrawFeeSet: "", CreateAt: now.Format("2006-01-02 15:04:05"), UpdateAt: "", } _, err2 := settingDb.FinWithdrawSettingInsert(&m) if err2 != nil { e.OutErr(c, e.ERR_DB_ORM, err2.Error()) return } setting, err = settingDb.FinWithdrawSettingGetOne() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } } var frequency md.WithdrawFrequencySettingStruct utils.Unserialize([]byte(setting.FrequencySet), &frequency) resp := md.GetWithdrawSettingResp{ Id: setting.Id, FrequencySet: frequency, WithdrawType: setting.WithdrawType, VipLevelLimit: setting.VipLevelLimit, IsRealName: setting.IsRealName, WithdrawNumsLimit: setting.WithdrawNumsLimit, WithdrawAmountLimit: setting.WithdrawAmountLimit, WithdrawMultipleLimit: setting.WithdrawMultipleLimit, IsSupportDecimalPoint: setting.IsSupportDecimalPoint, IsAuto: setting.IsAuto, WithdrawTimeInterval: setting.WithdrawTimeInterval, WithdrawFeeSet: setting.WithdrawFeeSet, CreateAt: setting.CreateAt, UpdateAt: setting.UpdateAt, } e.OutSuc(c, resp, nil) } // UpdateWithdrawSetting // @Summary 财务中心-提现-基础设置(更新) // @Tags 提现 // @Description 基础设置(更新) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Param req body md.UpdateWithdrawSettingReq true "id 必填" // @Success 200 {int} "修改数据条数" // @Failure 400 {object} md.Response "具体错误" // @Router /api/financialCenter/withdraw/updateWithdrawSetting [POST] func UpdateWithdrawSetting(c *gin.Context) { var req *md.UpdateWithdrawSettingReq if err1 := c.ShouldBindJSON(&req); err1 != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error()) return } frequencyStr := utils.SerializeStr(req.FrequencySet) m := model.FinWithdrawSetting{ Id: req.Id, FrequencySet: frequencyStr, WithdrawType: req.WithdrawType, VipLevelLimit: req.VipLevelLimit, IsRealName: req.IsRealName, WithdrawNumsLimit: req.WithdrawNumsLimit, WithdrawAmountLimit: req.WithdrawAmountLimit, WithdrawMultipleLimit: req.WithdrawMultipleLimit, IsSupportDecimalPoint: req.IsSupportDecimalPoint, IsAuto: req.IsAuto, WithdrawTimeInterval: req.WithdrawTimeInterval, WithdrawFeeSet: req.WithdrawFeeSet, } forceColumns := []string{"withdraw_type", "is_real_name", "withdraw_nums_limit", "withdraw_amount_limit", "withdraw_multiple_limit", "is_support_decimal_point", "is_auto"} settingDb := implement.NewFinWithdrawSettingDb(db.Db) affected, err := settingDb.FinWithdrawSettingUpdate(req.Id, &m, forceColumns...) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } e.OutSuc(c, affected, nil) } // GetWithdrawApplyList // @Summary 财务中心-提现-提现申请列表(获取) // @Tags 提现 // @Description 提现申请列表(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Param req body md.GetWithdrawApplyListReq false "筛选条件" // @Success 200 {object} md.GetWithdrawApplyListResp "具体数据" // @Failure 400 {object} md.Response "具体错误" // @Router /api/financialCenter/withdraw/applyList [POST] func GetWithdrawApplyList(c *gin.Context) { var req *md.GetWithdrawApplyListReq if err1 := c.ShouldBindJSON(&req); err1 != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error()) return } levelDb := implement.NewUserLevelDb(db.Db) levels, err1 := levelDb.UserLevelAllByAsc() if err1 != nil { e.OutErr(c, e.ERR_DB_ORM, err1.Error()) return } levelsList := make([]map[string]interface{}, 0) levelsMap := make(map[int]string) for _, level := range levels { levelsList = append(levelsList, map[string]interface{}{ "id": level.Id, "name": level.LevelName, }) levelsMap[level.Id] = level.LevelName } tagDb := implement.NewUserTagDb(db.Db) tags, err2 := tagDb.UserTagAllByAsc() if err2 != nil { e.OutErr(c, e.ERR_DB_ORM, err2.Error()) return } tagsList := make([]map[string]interface{}, 0) tagsMap := make(map[int]string) for _, tag := range tags { tagsList = append(tagsList, map[string]interface{}{ "id": tag.Id, "name": tag.TagName, }) tagsMap[tag.Id] = tag.TagName } applies, total, err3 := svc.WithDrawManagementGetApply(db.Db, req) if err3 != nil { e.OutErr(c, e.ERR_DB_ORM, err3.Error()) return } list := make([]md.GetWithdrawApplyListNode, len(*applies)) for i, apply := range *applies { list[i] = md.GetWithdrawApplyListNode{ UserID: apply.UserID, Nickname: apply.Nickname, ParentID: apply.ParentID, ParentPhone: apply.ParentPhone, WithdrawType: apply.WithdrawType, InviteCode: apply.InviteCode, Amount: apply.Amount, ActualReceipt: "", SysFee: apply.SysFee, State: apply.State, ApplyAt: apply.ApplyAt, PayAt: apply.PayAt, Memo: apply.Memo, } if apply.Amount != "" && apply.SysFee != "" { actualReceipt := utils.StrToFloat64(apply.Amount) - utils.StrToFloat64(apply.SysFee) list[i].ActualReceipt = utils.Float64ToStr(actualReceipt) } switch apply.WithdrawType { case 1: list[i].AliPayName = apply.PayName list[i].AliPayAccount = apply.PayAccount case 2: list[i].WechatPayName = apply.PayName list[i].WechatPayAccount = apply.PayAccount } tag, ok := tagsMap[apply.Tag] if ok { list[i].Tag = tag } } resp := md.GetWithdrawApplyListResp{ LevelsList: levelsList, TagsList: tagsList, List: list, Paginate: md.Paginate{ Limit: req.Limit, Page: req.Page, Total: total, }, } e.OutSuc(c, resp, nil) }