|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- 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"
- "strings"
- "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
- }
- // 不存在则初始化
- var emptyNum []string
- if setting == nil {
- now := time.Now()
- frequency := md2.WithdrawFrequencySettingStruct{
- Duration: 0,
- Num: emptyNum,
- }
- withdrawFeeSet := md2.WithdrawFeeSetStruct{
- Kind: 0,
- Value: 0,
- }
- frequencyStr := utils.SerializeStr(frequency)
- withdrawFeeSetStr := utils.SerializeStr(withdrawFeeSet)
- m := model.FinWithdrawSetting{
- FrequencySet: frequencyStr,
- WithdrawType: 0,
- VipLevelLimit: 0,
- IsRealName: 0,
- WithdrawNumsLimit: 0,
- WithdrawAmountLimit: "",
- WithdrawMultipleLimit: "",
- IsSupportDecimalPoint: 0,
- IsAuto: 0,
- WithdrawTimeInterval: "00:00-00:00",
- WithdrawFeeSet: withdrawFeeSetStr,
- 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 md2.WithdrawFrequencySettingStruct
- var withdrawFeeSet md2.WithdrawFeeSetStruct
- utils.Unserialize([]byte(setting.FrequencySet), &frequency)
- utils.Unserialize([]byte(setting.WithdrawFeeSet), &withdrawFeeSet)
- withdrawTimeIntervals := strings.Split(setting.WithdrawTimeInterval, "-")
- withdrawTimeInterval := md2.WithdrawTimeIntervalStruct{
- StartAt: withdrawTimeIntervals[0],
- EndAt: withdrawTimeIntervals[1],
- }
- 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: withdrawTimeInterval,
- WithdrawFeeSet: 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)
- withdrawFeeSetStr := utils.SerializeStr(req.WithdrawFeeSet)
- var withdrawTimeInterval []string
- withdrawTimeInterval = append(withdrawTimeInterval, req.WithdrawTimeInterval.StartAt)
- withdrawTimeInterval = append(withdrawTimeInterval, req.WithdrawTimeInterval.EndAt)
- withdrawTimeIntervalStr := strings.Join(withdrawTimeInterval, "-")
- 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: withdrawTimeIntervalStr,
- WithdrawFeeSet: withdrawFeeSetStr,
- }
-
- 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)
- }
|