蛋蛋星球 后台端
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.
 
 
 
 
 

255 lines
8.3 KiB

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