蛋蛋星球 后台端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hdl_withdraw.go 7.5 KiB

2 days ago
2 days ago
2 days ago
2 days ago
2 days ago
2 days ago
2 days ago
2 days ago
2 days ago
2 days ago
2 days ago
2 days ago
2 days ago
2 days ago
2 days ago
2 days ago
2 days ago
2 days ago
2 days ago
2 days ago
2 days ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. package financial_center
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. md "applet/app/md/financial_center"
  6. svc "applet/app/svc/financial_center"
  7. "applet/app/utils"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  9. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  10. md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
  11. "github.com/gin-gonic/gin"
  12. "time"
  13. )
  14. // GetWithdrawSetting
  15. // @Summary 财务中心-提现-基础设置(获取)
  16. // @Tags 提现
  17. // @Description 基础设置(获取)
  18. // @Accept json
  19. // @Produce json
  20. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  21. // @Success 200 {object} md.GetWithdrawSettingResp "具体数据"
  22. // @Failure 400 {object} md.Response "具体错误"
  23. // @Router /api/financialCenter/withdraw/setting [get]
  24. func GetWithdrawSetting(c *gin.Context) {
  25. settingDb := implement.NewFinWithdrawSettingDb(db.Db)
  26. setting, err := settingDb.FinWithdrawSettingGetOne()
  27. if err != nil {
  28. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  29. return
  30. }
  31. // 不存在则初始化
  32. if setting == nil {
  33. now := time.Now()
  34. frequency := md2.WithdrawFrequencySettingStruct{
  35. Duration: 0,
  36. Num: 0,
  37. }
  38. frequencyStr := utils.SerializeStr(frequency)
  39. m := model.FinWithdrawSetting{
  40. FrequencySet: frequencyStr,
  41. WithdrawType: 0,
  42. VipLevelLimit: 0,
  43. IsRealName: 0,
  44. WithdrawNumsLimit: 0,
  45. WithdrawAmountLimit: "",
  46. WithdrawMultipleLimit: "",
  47. IsSupportDecimalPoint: 0,
  48. IsAuto: 0,
  49. WithdrawTimeInterval: "",
  50. WithdrawFeeSet: "",
  51. CreateAt: now.Format("2006-01-02 15:04:05"),
  52. UpdateAt: "",
  53. }
  54. _, err2 := settingDb.FinWithdrawSettingInsert(&m)
  55. if err2 != nil {
  56. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  57. return
  58. }
  59. setting, err = settingDb.FinWithdrawSettingGetOne()
  60. if err != nil {
  61. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  62. return
  63. }
  64. }
  65. var frequency md.WithdrawFrequencySettingStruct
  66. utils.Unserialize([]byte(setting.FrequencySet), &frequency)
  67. resp := md.GetWithdrawSettingResp{
  68. Id: setting.Id,
  69. FrequencySet: frequency,
  70. WithdrawType: setting.WithdrawType,
  71. VipLevelLimit: setting.VipLevelLimit,
  72. IsRealName: setting.IsRealName,
  73. WithdrawNumsLimit: setting.WithdrawNumsLimit,
  74. WithdrawAmountLimit: setting.WithdrawAmountLimit,
  75. WithdrawMultipleLimit: setting.WithdrawMultipleLimit,
  76. IsSupportDecimalPoint: setting.IsSupportDecimalPoint,
  77. IsAuto: setting.IsAuto,
  78. WithdrawTimeInterval: setting.WithdrawTimeInterval,
  79. WithdrawFeeSet: setting.WithdrawFeeSet,
  80. CreateAt: setting.CreateAt,
  81. UpdateAt: setting.UpdateAt,
  82. }
  83. e.OutSuc(c, resp, nil)
  84. }
  85. // UpdateWithdrawSetting
  86. // @Summary 财务中心-提现-基础设置(更新)
  87. // @Tags 提现
  88. // @Description 基础设置(更新)
  89. // @Accept json
  90. // @Produce json
  91. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  92. // @Param req body md.UpdateWithdrawSettingReq true "id 必填"
  93. // @Success 200 {int} "修改数据条数"
  94. // @Failure 400 {object} md.Response "具体错误"
  95. // @Router /api/financialCenter/withdraw/updateWithdrawSetting [POST]
  96. func UpdateWithdrawSetting(c *gin.Context) {
  97. var req *md.UpdateWithdrawSettingReq
  98. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  99. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  100. return
  101. }
  102. frequencyStr := utils.SerializeStr(req.FrequencySet)
  103. m := model.FinWithdrawSetting{
  104. Id: req.Id,
  105. FrequencySet: frequencyStr,
  106. WithdrawType: req.WithdrawType,
  107. VipLevelLimit: req.VipLevelLimit,
  108. IsRealName: req.IsRealName,
  109. WithdrawNumsLimit: req.WithdrawNumsLimit,
  110. WithdrawAmountLimit: req.WithdrawAmountLimit,
  111. WithdrawMultipleLimit: req.WithdrawMultipleLimit,
  112. IsSupportDecimalPoint: req.IsSupportDecimalPoint,
  113. IsAuto: req.IsAuto,
  114. WithdrawTimeInterval: req.WithdrawTimeInterval,
  115. WithdrawFeeSet: req.WithdrawFeeSet,
  116. }
  117. forceColumns := []string{"withdraw_type", "is_real_name", "withdraw_nums_limit", "withdraw_amount_limit", "withdraw_multiple_limit", "is_support_decimal_point", "is_auto"}
  118. settingDb := implement.NewFinWithdrawSettingDb(db.Db)
  119. affected, err := settingDb.FinWithdrawSettingUpdate(req.Id, &m, forceColumns...)
  120. if err != nil {
  121. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  122. return
  123. }
  124. e.OutSuc(c, affected, nil)
  125. }
  126. // GetWithdrawApplyList
  127. // @Summary 财务中心-提现-提现申请列表(获取)
  128. // @Tags 提现
  129. // @Description 提现申请列表(获取)
  130. // @Accept json
  131. // @Produce json
  132. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  133. // @Param req body md.GetWithdrawApplyListReq false "筛选条件"
  134. // @Success 200 {object} md.GetWithdrawApplyListResp "具体数据"
  135. // @Failure 400 {object} md.Response "具体错误"
  136. // @Router /api/financialCenter/withdraw/applyList [POST]
  137. func GetWithdrawApplyList(c *gin.Context) {
  138. var req *md.GetWithdrawApplyListReq
  139. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  140. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  141. return
  142. }
  143. levelDb := implement.NewUserLevelDb(db.Db)
  144. levels, err1 := levelDb.UserLevelAllByAsc()
  145. if err1 != nil {
  146. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  147. return
  148. }
  149. levelsList := make([]map[string]interface{}, 0)
  150. levelsMap := make(map[int]string)
  151. for _, level := range levels {
  152. levelsList = append(levelsList, map[string]interface{}{
  153. "id": level.Id,
  154. "name": level.LevelName,
  155. })
  156. levelsMap[level.Id] = level.LevelName
  157. }
  158. tagDb := implement.NewUserTagDb(db.Db)
  159. tags, err2 := tagDb.UserTagAllByAsc()
  160. if err2 != nil {
  161. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  162. return
  163. }
  164. tagsList := make([]map[string]interface{}, 0)
  165. tagsMap := make(map[int]string)
  166. for _, tag := range tags {
  167. tagsList = append(tagsList, map[string]interface{}{
  168. "id": tag.Id,
  169. "name": tag.TagName,
  170. })
  171. tagsMap[tag.Id] = tag.TagName
  172. }
  173. applies, total, err3 := svc.WithDrawManagementGetApply(db.Db, req)
  174. if err3 != nil {
  175. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  176. return
  177. }
  178. list := make([]md.GetWithdrawApplyListNode, len(*applies))
  179. for i, apply := range *applies {
  180. list[i] = md.GetWithdrawApplyListNode{
  181. UserID: apply.UserID,
  182. Nickname: apply.Nickname,
  183. ParentID: apply.ParentID,
  184. ParentPhone: apply.ParentPhone,
  185. WithdrawType: apply.WithdrawType,
  186. InviteCode: apply.InviteCode,
  187. Amount: apply.Amount,
  188. ActualReceipt: "",
  189. SysFee: apply.SysFee,
  190. State: apply.State,
  191. ApplyAt: apply.ApplyAt,
  192. PayAt: apply.PayAt,
  193. Memo: apply.Memo,
  194. }
  195. if apply.Amount != "" && apply.SysFee != "" {
  196. actualReceipt := utils.StrToFloat64(apply.Amount) - utils.StrToFloat64(apply.SysFee)
  197. list[i].ActualReceipt = utils.Float64ToStr(actualReceipt)
  198. }
  199. switch apply.WithdrawType {
  200. case 1:
  201. list[i].AliPayName = apply.PayName
  202. list[i].AliPayAccount = apply.PayAccount
  203. case 2:
  204. list[i].WechatPayName = apply.PayName
  205. list[i].WechatPayAccount = apply.PayAccount
  206. }
  207. tag, ok := tagsMap[apply.Tag]
  208. if ok {
  209. list[i].Tag = tag
  210. }
  211. }
  212. resp := md.GetWithdrawApplyListResp{
  213. LevelsList: levelsList,
  214. TagsList: tagsList,
  215. List: list,
  216. Paginate: md.Paginate{
  217. Limit: req.Limit,
  218. Page: req.Page,
  219. Total: total,
  220. },
  221. }
  222. e.OutSuc(c, resp, nil)
  223. }