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

1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
6 days ago
1 week ago
5 days ago
1 week ago
6 days ago
1 week ago
1 week ago
5 days ago
6 days ago
1 week ago
5 days ago
5 days ago
1 week ago
5 days ago
1 week ago
5 days ago
5 days ago
5 days ago
1 week ago
1 week ago
5 days ago
1 week ago
5 days ago
6 days ago
1 week ago
5 days ago
1 week ago
1 week ago
5 days ago
6 days ago
1 week ago
5 days ago
1 week ago
5 days ago
1 week ago
1 week ago
5 days ago
1 week ago
5 days ago
1 week ago
5 days ago
1 week ago
5 days ago
1 week ago
5 days ago
1 week ago
5 days ago
1 week ago
5 days ago
1 week ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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. // 等级列表
  27. levelDb := implement.NewUserLevelDb(db.Db)
  28. levels, err1 := levelDb.UserLevelAllByAsc()
  29. if err1 != nil {
  30. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  31. return
  32. }
  33. levelsList := make([]map[string]interface{}, 0)
  34. levelsMap := make(map[int]string)
  35. for _, level := range levels {
  36. levelsList = append(levelsList, map[string]interface{}{
  37. "id": level.Id,
  38. "name": level.LevelName,
  39. })
  40. levelsMap[level.Id] = level.LevelName
  41. }
  42. settingDb := implement.NewFinWithdrawSettingDb(db.Db)
  43. setting, err := settingDb.FinWithdrawSettingGetOne()
  44. if err != nil {
  45. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  46. return
  47. }
  48. // 不存在则初始化
  49. var emptyNum []string
  50. if setting == nil {
  51. now := time.Now()
  52. frequency := md2.WithdrawFrequencySettingStruct{
  53. Duration: 1,
  54. Num: emptyNum,
  55. }
  56. withdrawFeeSet := md2.WithdrawFeeSetStruct{
  57. Kind: 1,
  58. Value: 0,
  59. }
  60. firstWithdrawSet := md2.FirstWithdrawSet{
  61. IsNeedRealName: 0,
  62. FirstWithdrawAmountLimit: "",
  63. }
  64. frequencyStr := utils.SerializeStr(frequency)
  65. withdrawFeeSetStr := utils.SerializeStr(withdrawFeeSet)
  66. firstWithdrawSetStr := utils.SerializeStr(firstWithdrawSet)
  67. m := model.FinWithdrawSetting{
  68. FrequencySet: frequencyStr,
  69. WithdrawType: 1,
  70. VipLevelLimit: 0,
  71. IsRealName: 0,
  72. WithdrawNumsLimit: 0,
  73. WithdrawAmountLimit: "",
  74. WithdrawMultipleLimit: "",
  75. IsSupportDecimalPoint: 0,
  76. IsAuto: 0,
  77. WithdrawTimeInterval: "00:00-00:00",
  78. WithdrawFeeSet: withdrawFeeSetStr,
  79. PendingOrdersIsCanApply: 0,
  80. ConditionIsOpen: 0,
  81. FirstWithdrawSet: firstWithdrawSetStr,
  82. CreateAt: now.Format("2006-01-02 15:04:05"),
  83. }
  84. _, err2 := settingDb.FinWithdrawSettingInsert(&m)
  85. if err2 != nil {
  86. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  87. return
  88. }
  89. setting, err = settingDb.FinWithdrawSettingGetOne()
  90. if err != nil {
  91. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  92. return
  93. }
  94. }
  95. var frequency md2.WithdrawFrequencySettingStruct
  96. var withdrawFeeSet md2.WithdrawFeeSetStruct
  97. var firstWithdrawSet md2.FirstWithdrawSet
  98. utils.Unserialize([]byte(setting.FrequencySet), &frequency)
  99. utils.Unserialize([]byte(setting.WithdrawFeeSet), &withdrawFeeSet)
  100. utils.Unserialize([]byte(setting.FirstWithdrawSet), &firstWithdrawSet)
  101. withdrawTimeIntervals := strings.Split(setting.WithdrawTimeInterval, "-")
  102. withdrawTimeInterval := md2.WithdrawTimeIntervalStruct{
  103. StartAt: withdrawTimeIntervals[0],
  104. EndAt: withdrawTimeIntervals[1],
  105. }
  106. resp := md.GetWithdrawSettingResp{
  107. Id: setting.Id,
  108. FrequencySet: frequency,
  109. WithdrawType: setting.WithdrawType,
  110. VipLevelLimit: setting.VipLevelLimit,
  111. IsRealName: setting.IsRealName,
  112. WithdrawNumsLimit: setting.WithdrawNumsLimit,
  113. WithdrawAmountLimit: setting.WithdrawAmountLimit,
  114. WithdrawMultipleLimit: setting.WithdrawMultipleLimit,
  115. IsSupportDecimalPoint: setting.IsSupportDecimalPoint,
  116. IsAuto: setting.IsAuto,
  117. IsAutoAmountLimit: setting.IsAutoAmountLimit,
  118. WithdrawTimeInterval: withdrawTimeInterval,
  119. WithdrawFeeSet: withdrawFeeSet,
  120. FirstWithdrawSet: firstWithdrawSet,
  121. PendingOrdersIsCanApply: setting.PendingOrdersIsCanApply,
  122. ConditionIsOpen: setting.ConditionIsOpen,
  123. LevelList: levelsList,
  124. }
  125. e.OutSuc(c, resp, nil)
  126. }
  127. // UpdateWithdrawSetting
  128. // @Summary 财务中心-提现-基础设置(更新)
  129. // @Tags 提现
  130. // @Description 基础设置(更新)
  131. // @Accept json
  132. // @Produce json
  133. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  134. // @Param req body md.UpdateWithdrawSettingReq true "id 必填"
  135. // @Success 200 {int} "修改数据条数"
  136. // @Failure 400 {object} md.Response "具体错误"
  137. // @Router /api/financialCenter/withdraw/updateWithdrawSetting [POST]
  138. func UpdateWithdrawSetting(c *gin.Context) {
  139. var req *md.UpdateWithdrawSettingReq
  140. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  141. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  142. return
  143. }
  144. frequencyStr := utils.SerializeStr(req.FrequencySet)
  145. withdrawFeeSetStr := utils.SerializeStr(req.WithdrawFeeSet)
  146. firstWithdrawSetStr := utils.SerializeStr(req.FirstWithdrawSet)
  147. var withdrawTimeInterval []string
  148. withdrawTimeInterval = append(withdrawTimeInterval, req.WithdrawTimeInterval.StartAt)
  149. withdrawTimeInterval = append(withdrawTimeInterval, req.WithdrawTimeInterval.EndAt)
  150. withdrawTimeIntervalStr := strings.Join(withdrawTimeInterval, "-")
  151. m := model.FinWithdrawSetting{
  152. Id: req.Id,
  153. FrequencySet: frequencyStr,
  154. WithdrawType: req.WithdrawType,
  155. VipLevelLimit: req.VipLevelLimit,
  156. IsRealName: req.IsRealName,
  157. WithdrawNumsLimit: req.WithdrawNumsLimit,
  158. WithdrawAmountLimit: req.WithdrawAmountLimit,
  159. WithdrawMultipleLimit: req.WithdrawMultipleLimit,
  160. IsSupportDecimalPoint: req.IsSupportDecimalPoint,
  161. IsAuto: req.IsAuto,
  162. IsAutoAmountLimit: req.IsAutoAmountLimit,
  163. WithdrawTimeInterval: withdrawTimeIntervalStr,
  164. WithdrawFeeSet: withdrawFeeSetStr,
  165. PendingOrdersIsCanApply: req.PendingOrdersIsCanApply,
  166. ConditionIsOpen: req.ConditionIsOpen,
  167. FirstWithdrawSet: firstWithdrawSetStr,
  168. }
  169. forceColumns := []string{"withdraw_type", "is_real_name", "withdraw_nums_limit",
  170. "withdraw_amount_limit", "withdraw_multiple_limit", "is_support_decimal_point",
  171. "is_auto", "first_withdraw_set", "is_auto_amount_limit", "pending_orders_is_can_apply",
  172. "condition_is_open",
  173. }
  174. settingDb := implement.NewFinWithdrawSettingDb(db.Db)
  175. affected, err := settingDb.FinWithdrawSettingUpdate(req.Id, &m, forceColumns...)
  176. if err != nil {
  177. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  178. return
  179. }
  180. e.OutSuc(c, affected, nil)
  181. }
  182. // GetWithdrawApplyList
  183. // @Summary 财务中心-提现-提现申请列表(获取)
  184. // @Tags 提现
  185. // @Description 提现申请列表(获取)
  186. // @Accept json
  187. // @Produce json
  188. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  189. // @Param req body md.GetWithdrawApplyListReq false "筛选条件"
  190. // @Success 200 {object} md.GetWithdrawApplyListResp "具体数据"
  191. // @Failure 400 {object} md.Response "具体错误"
  192. // @Router /api/financialCenter/withdraw/applyList [POST]
  193. func GetWithdrawApplyList(c *gin.Context) {
  194. var req *md.GetWithdrawApplyListReq
  195. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  196. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  197. return
  198. }
  199. levelDb := implement.NewUserLevelDb(db.Db)
  200. levels, err1 := levelDb.UserLevelAllByAsc()
  201. if err1 != nil {
  202. e.OutErr(c, e.ERR_DB_ORM, err1.Error())
  203. return
  204. }
  205. levelsList := make([]map[string]interface{}, 0)
  206. levelsMap := make(map[int]string)
  207. for _, level := range levels {
  208. levelsList = append(levelsList, map[string]interface{}{
  209. "id": level.Id,
  210. "name": level.LevelName,
  211. })
  212. levelsMap[level.Id] = level.LevelName
  213. }
  214. tagDb := implement.NewUserTagDb(db.Db)
  215. tags, err2 := tagDb.UserTagAllByAsc()
  216. if err2 != nil {
  217. e.OutErr(c, e.ERR_DB_ORM, err2.Error())
  218. return
  219. }
  220. tagsList := make([]map[string]interface{}, 0)
  221. tagsMap := make(map[int]string)
  222. for _, tag := range tags {
  223. tagsList = append(tagsList, map[string]interface{}{
  224. "id": tag.Id,
  225. "name": tag.TagName,
  226. })
  227. tagsMap[tag.Id] = tag.TagName
  228. }
  229. applies, total, err3 := svc.WithDrawManagementGetApply(db.Db, req)
  230. if err3 != nil {
  231. e.OutErr(c, e.ERR_DB_ORM, err3.Error())
  232. return
  233. }
  234. list := make([]md.GetWithdrawApplyListNode, len(*applies))
  235. parentIDs := make([]int64, len(*applies))
  236. UserIDs := make([]int64, len(*applies))
  237. for _, apply := range *applies {
  238. parentIDs = append(parentIDs, apply.ParentID)
  239. UserIDs = append(UserIDs, apply.UserID)
  240. }
  241. // 查询上级
  242. userDb := implement.NewUserDb(db.Db)
  243. parents, err := userDb.UserFindByParams(map[string]interface{}{
  244. "key": "id",
  245. "value": parentIDs,
  246. })
  247. if err != nil {
  248. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  249. return
  250. }
  251. parentsMap := make(map[int64]model.User)
  252. for _, parent := range parents {
  253. parentsMap[parent.Id] = parent
  254. }
  255. // 查询标签
  256. recordsDb := implement.NewUserTagRecordsDb(db.Db)
  257. records, err := recordsDb.UserTagRecordsFindByParams(map[string]interface{}{
  258. "key": "uid",
  259. "value": UserIDs,
  260. })
  261. if err != nil {
  262. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  263. return
  264. }
  265. recordsMap := make(map[int64][]md.TagNode)
  266. for _, record := range *records {
  267. temp := md.TagNode{
  268. TagID: record.TagId,
  269. TagName: "",
  270. }
  271. tagName, ok := tagsMap[record.TagId]
  272. temp.TagName = tagName
  273. v, ok := recordsMap[record.Uid]
  274. if ok {
  275. v = append(v, temp)
  276. } else {
  277. recordsMap[record.Uid] = []md.TagNode{temp}
  278. }
  279. }
  280. for i, apply := range *applies {
  281. list[i] = md.GetWithdrawApplyListNode{
  282. UserID: apply.UserID,
  283. Nickname: apply.Nickname,
  284. ParentID: apply.ParentID,
  285. AliPayName: apply.AliPayName,
  286. WechatPayName: apply.WxPayName,
  287. AliPayAccount: apply.AliPayAccount,
  288. WechatPayAccount: apply.WxPayAccount,
  289. WithdrawType: apply.WithdrawType,
  290. InviteCode: apply.InviteCode,
  291. Amount: apply.Amount,
  292. ActualReceipt: apply.RealAmount,
  293. SysFee: apply.SysFee,
  294. State: apply.State,
  295. ApplyAt: apply.ApplyAt,
  296. PayAt: apply.PayAt,
  297. Memo: apply.Memo,
  298. }
  299. if apply.Amount != "" && apply.SysFee != "" {
  300. actualReceipt := utils.StrToFloat64(apply.Amount) - utils.StrToFloat64(apply.SysFee)
  301. list[i].ActualReceipt = utils.Float64ToStr(actualReceipt)
  302. }
  303. if apply.ParentID != 0 {
  304. v, ok := parentsMap[apply.ParentID]
  305. if ok {
  306. list[i].ParentPhone = v.Phone
  307. }
  308. }
  309. tagList, ok := recordsMap[apply.UserID]
  310. if ok {
  311. list[i].Tag = tagList
  312. }
  313. }
  314. applyDb := implement.NewFinWithdrawApplyDb(db.Db)
  315. underReviewAmount, err := applyDb.FinWithdrawApplyAmountGetByParams(map[string]interface{}{
  316. "key": "state",
  317. "value": 0,
  318. })
  319. if err != nil {
  320. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  321. return
  322. }
  323. pendingAmount, err := applyDb.FinWithdrawApplyAmountGetByParams(map[string]interface{}{
  324. "key": "state",
  325. "value": 4,
  326. })
  327. if err != nil {
  328. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  329. return
  330. }
  331. paySucceedAmount, err := applyDb.FinWithdrawApplyAmountGetByParams(map[string]interface{}{
  332. "key": "state",
  333. "value": 2,
  334. })
  335. if err != nil {
  336. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  337. return
  338. }
  339. payFailedAmount, err := applyDb.FinWithdrawApplyAmountGetByParams(map[string]interface{}{
  340. "key": "state",
  341. "value": 3,
  342. })
  343. if err != nil {
  344. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  345. return
  346. }
  347. resp := md.GetWithdrawApplyListResp{
  348. LevelsList: levelsList,
  349. TagsList: tagsList,
  350. PendingAmount: utils.Float64ToStr(pendingAmount),
  351. PaySucceedAmount: utils.Float64ToStr(paySucceedAmount),
  352. PayFailedAmount: utils.Float64ToStr(payFailedAmount),
  353. UnderReviewAmount: utils.Float64ToStr(underReviewAmount),
  354. List: list,
  355. Paginate: md.Paginate{
  356. Limit: req.Limit,
  357. Page: req.Page,
  358. Total: total,
  359. },
  360. }
  361. e.OutSuc(c, resp, nil)
  362. }