附近小店
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.
 
 
 

161 lines
4.8 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/model"
  5. "applet/app/e"
  6. "applet/app/svc"
  7. "applet/app/utils"
  8. "github.com/gin-gonic/gin"
  9. "strings"
  10. )
  11. func StoreWithdrawFlow(c *gin.Context) {
  12. var req map[string]string
  13. if err := c.ShouldBindJSON(&req); err != nil {
  14. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  15. return
  16. }
  17. user := svc.GetUser(c)
  18. req["agent_uid"] = utils.IntToStr(user.Info.Uid)
  19. withdraw, total := db.GetStoreWithdraw(svc.MasterDb(c), req)
  20. list := make([]map[string]string, 0)
  21. if withdraw != nil {
  22. var stateList = []string{"审核中", "审核通过", "审核通过", "审核拒绝"}
  23. for _, v := range *withdraw {
  24. name := ""
  25. store := db.GetStoreIdEg(svc.MasterDb(c), utils.IntToStr(v.Uid))
  26. if store != nil {
  27. name = store.Name
  28. }
  29. tmp := map[string]string{
  30. "id": utils.Int64ToStr(v.Id),
  31. "name": name,
  32. "amount": v.Amount,
  33. "alipay_account": v.WithdrawAccount,
  34. "alipay_name": v.WithdrawName,
  35. "state_str": stateList[v.State],
  36. "state": utils.IntToStr(v.State),
  37. "time": v.CreateAt.Format("2006-01-02 15:04:05"),
  38. "end_time": "",
  39. "memo": v.Memo,
  40. }
  41. if v.PaymentDate != "" {
  42. tmp["end_time"] = v.PaymentDate
  43. }
  44. list = append(list, tmp)
  45. }
  46. }
  47. res := map[string]interface{}{
  48. "total": total,
  49. "list": list,
  50. "state": []map[string]string{
  51. {"name": "审核中", "value": "0"},
  52. {"name": "审核通过", "value": "1"},
  53. {"name": "审核拒绝", "value": "3"},
  54. },
  55. }
  56. e.OutSuc(c, res, nil)
  57. return
  58. }
  59. func StoreWithdrawTotal(c *gin.Context) {
  60. var req map[string]string
  61. if err := c.ShouldBindJSON(&req); err != nil {
  62. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  63. return
  64. }
  65. user := svc.GetUser(c)
  66. var allAmount float64 = 0
  67. var waitAmount float64 = 0
  68. var failAmount float64 = 0
  69. allAmount, _ = svc.MasterDb(c).Where("parent_uid=?", user.Info.Uid).And("state=?", 1).Sum(&model.CommunityTeamStoreWithdrawApply{}, "amount")
  70. waitAmount, _ = svc.MasterDb(c).Where("parent_uid=?", user.Info.Uid).And("state=?", 0).Sum(&model.CommunityTeamStoreWithdrawApply{}, "amount")
  71. failAmount, _ = svc.MasterDb(c).Where("parent_uid=?", user.Info.Uid).And("state=?", 3).Sum(&model.CommunityTeamStoreWithdrawApply{}, "amount")
  72. res := []map[string]string{
  73. {"name": "累计提现金额(元):" + utils.Float64ToStr(allAmount), "tip": "统计提现成功的金额"},
  74. {"name": "审核中金额(元):" + utils.Float64ToStr(waitAmount), "tip": "统计正在审核中的金额"},
  75. {"name": "审核拒绝金额(元):" + utils.Float64ToStr(failAmount), "tip": "统计审核拒绝的金额"},
  76. }
  77. e.OutSuc(c, res, nil)
  78. return
  79. }
  80. func StoreWithdrawAudit(c *gin.Context) {
  81. var req map[string]string
  82. if err := c.ShouldBindJSON(&req); err != nil {
  83. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  84. return
  85. }
  86. sess := svc.MasterDb(c).NewSession()
  87. defer sess.Close()
  88. sess.Begin()
  89. data := db.GetStoreWithdrawById(sess, req["id"])
  90. if data == nil {
  91. sess.Rollback()
  92. e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
  93. return
  94. }
  95. if data.State > 0 {
  96. sess.Rollback()
  97. e.OutErr(c, 400, e.NewErr(400, "记录已处理"))
  98. return
  99. }
  100. if req["state"] == "3" {
  101. bools := svc.MoneyCheck(c, sess, data.Uid, 0, 3, utils.StrToFloat64(data.Amount), "提现审核拒绝退回", utils.StrToInt64(utils.OrderUUID(data.Uid)))
  102. if bools == false {
  103. sess.Rollback()
  104. e.OutErr(c, 400, e.NewErr(400, "审核失败"))
  105. return
  106. }
  107. }
  108. data.State = utils.StrToInt(req["state"])
  109. data.Memo = req["memo"]
  110. update, err := sess.Where("id=?", data.Id).Cols("state,memo").Update(data)
  111. if update == 0 || err != nil {
  112. sess.Rollback()
  113. e.OutErr(c, 400, e.NewErr(400, "审核失败"))
  114. return
  115. }
  116. sess.Commit()
  117. e.OutSuc(c, "success", nil)
  118. return
  119. }
  120. func StoreWithdrawAuditAll(c *gin.Context) {
  121. var req map[string]string
  122. if err := c.ShouldBindJSON(&req); err != nil {
  123. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  124. return
  125. }
  126. count, _ := svc.MasterDb(c).In("id", strings.Split(req["ids"], ",")).And("state>0").Count(&model.CommunityTeamStoreWithdrawApply{})
  127. if count > 0 {
  128. e.OutErr(c, 400, e.NewErr(400, "存在已处理的记录"))
  129. return
  130. }
  131. svc.MasterDb(c).In("id", strings.Split(req["ids"], ",")).Cols("state").Update(&model.CommunityTeamStoreWithdrawApply{State: 1})
  132. e.OutSuc(c, "success", nil)
  133. return
  134. }
  135. func StoreWithdrawOutPut(c *gin.Context) {
  136. var args map[string]string
  137. if err := c.ShouldBindJSON(&args); err != nil {
  138. e.OutErr(c, 200, e.ERR_INVALID_ARGS)
  139. return
  140. }
  141. name := "提现记录_" + args["p"]
  142. args["state"] = "0"
  143. args["size"] = "3000"
  144. if args["ids"] != "" {
  145. args["size"] = "0"
  146. }
  147. user := svc.GetUser(c)
  148. args["parent_uid"] = utils.IntToStr(user.Info.Uid)
  149. data, _ := db.GetStoreWithdraw(svc.MasterDb(c), args)
  150. file := utils.OutputSecond(c, name, data)
  151. filename := name + ".xls"
  152. r := map[string]string{
  153. "file": file,
  154. "filename": filename,
  155. }
  156. e.OutSuc(c, r, nil)
  157. return
  158. }