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

svc_store.go 4.9 KiB

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