附近小店
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_withdraw.go 4.5 KiB

2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/model"
  5. "applet/app/e"
  6. "applet/app/lib/mob"
  7. "applet/app/lib/sms"
  8. "applet/app/svc"
  9. "applet/app/utils"
  10. "applet/app/utils/cache"
  11. "fmt"
  12. "github.com/gin-gonic/gin"
  13. "github.com/tidwall/gjson"
  14. "time"
  15. )
  16. func StoreWithdrawFlow(c *gin.Context) {
  17. var req map[string]string
  18. if err := c.ShouldBindJSON(&req); err != nil {
  19. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  20. return
  21. }
  22. user := svc.GetUser(c)
  23. req["store_uid"] = utils.IntToStr(user.Info.Uid)
  24. store := db.GetStoreIdEg(svc.MasterDb(c), utils.IntToStr(user.Info.Uid))
  25. if store != nil {
  26. req["parent_uid"] = utils.IntToStr(store.ParentUid)
  27. req["store_type"] = utils.IntToStr(store.StoreType)
  28. }
  29. withdraw, total := db.GetStoreWithdraw(svc.MasterDb(c), req)
  30. list := make([]map[string]string, 0)
  31. if withdraw != nil {
  32. var stateList = []string{"审核中", "审核通过", "审核通过", "审核拒绝"}
  33. for _, v := range *withdraw {
  34. tmp := map[string]string{
  35. "amount": v.Amount,
  36. "alipay_account": v.WithdrawAccount,
  37. "alipay_name": v.WithdrawName,
  38. "state_str": stateList[v.State],
  39. "state": utils.IntToStr(v.State),
  40. "memo": v.Memo,
  41. "time": v.CreateAt.Format("2006-01-02 15:04:05"),
  42. }
  43. list = append(list, tmp)
  44. }
  45. }
  46. res := map[string]interface{}{
  47. "total": total,
  48. "list": list,
  49. }
  50. e.OutSuc(c, res, nil)
  51. return
  52. }
  53. func StoreWithdrawDoing(c *gin.Context) {
  54. var req map[string]string
  55. if err := c.ShouldBindJSON(&req); err != nil {
  56. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  57. return
  58. }
  59. user := svc.GetUser(c)
  60. if user.Profile.AccAlipay == "" || user.Profile.AccAlipayRealName == "" {
  61. e.OutErr(c, 400, e.NewErr(400, "未绑定支付宝"))
  62. return
  63. }
  64. if utils.StrToFloat64(req["amount"]) <= 0 {
  65. e.OutErr(c, 400, e.NewErr(400, "金额不正确"))
  66. return
  67. }
  68. sess := svc.MasterDb(c).NewSession()
  69. defer sess.Close()
  70. sess.Begin()
  71. oid := utils.StrToInt64(utils.OrderUUID(user.Info.Uid))
  72. store := db.GetStoreId(sess, utils.IntToStr(user.Info.Uid))
  73. if store == nil {
  74. e.OutErr(c, 400, e.NewErr(400, "提现失败"))
  75. return
  76. }
  77. bools := svc.MoneyCheck(c, sess, user.Info.Uid, store.ParentUid, store.StoreType, 1, 2, utils.StrToFloat64(req["amount"]), "提现", oid)
  78. if bools == false {
  79. e.OutErr(c, 400, e.NewErr(400, "提现失败"))
  80. return
  81. }
  82. var flow = &model.CommunityTeamStoreWithdrawApply{
  83. Uid: user.Info.Uid,
  84. ParentUid: store.ParentUid,
  85. StoreType: store.StoreType,
  86. Amount: req["amount"],
  87. Type: 1,
  88. WithdrawAccount: user.Profile.AccAlipay,
  89. WithdrawName: user.Profile.AccAlipayRealName,
  90. CreateAt: time.Now(),
  91. UpdateAt: time.Now(),
  92. Oid: oid,
  93. }
  94. insert, err := sess.Insert(flow)
  95. if insert == 0 || err != nil {
  96. e.OutErr(c, 400, e.NewErr(400, "提现失败"))
  97. return
  98. }
  99. sess.Commit()
  100. e.OutSuc(c, "success", nil)
  101. return
  102. }
  103. func StoreWithdrawBindAlipay(c *gin.Context) {
  104. var req map[string]string
  105. if err := c.ShouldBindJSON(&req); err != nil {
  106. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  107. return
  108. }
  109. if req["alipay_account"] == "" {
  110. e.OutErr(c, 400, e.NewErr(400, "支付宝不能为空"))
  111. return
  112. }
  113. if req["alipay_name"] == "" {
  114. e.OutErr(c, 400, e.NewErr(400, "真实姓名不能为空"))
  115. return
  116. }
  117. mob1, errr := mob.GetMobSDK(c.GetString("mid"))
  118. if errr != nil {
  119. e.OutErr(c, e.ERR_MOB_CONFIG, errr)
  120. return
  121. }
  122. user := svc.GetUser(c)
  123. req["phone"] = user.Info.Phone
  124. if req["zone"] == "" {
  125. req["zone"] = "86"
  126. }
  127. send := map[string]interface{}{
  128. "phone": req["phone"],
  129. "zone": req["zone"],
  130. "code": req["captcha"],
  131. }
  132. var ok bool
  133. var err error
  134. // h5(wap) 登录
  135. smsPlatform := sms.GetSmsPlatform(c)
  136. key := fmt.Sprintf("%s_SMS_FastLogin_%s", db.SysCfgGet(c, "app_name"), req["phone"])
  137. if smsPlatform == "ljioe" {
  138. b, err := cache.GetBytes(key)
  139. if err != nil {
  140. e.OutErr(c, e.ERR_MOB_SMS_NO_EXISTS, err)
  141. return
  142. }
  143. if req["captcha"] != gjson.GetBytes(b, "data.captcha").String() {
  144. e.OutErr(c, e.ERR_MOB_SMS_NO_SAME, err)
  145. return
  146. }
  147. ok = true
  148. } else {
  149. c.Set("not_deduction_doing", "1")
  150. ok, err = mob1.MobSMS(c, send)
  151. if err != nil {
  152. e.OutErr(c, 400, err.Error())
  153. return
  154. }
  155. }
  156. if ok {
  157. user.Profile.AccAlipay = req["alipay_account"]
  158. user.Profile.AccAlipayRealName = req["alipay_name"]
  159. svc.MasterDb(c).Where("uid=?", user.Profile.Uid).Cols("acc_alipay,acc_alipay_real_name").Update(user.Profile)
  160. e.OutSuc(c, "success", nil)
  161. return
  162. }
  163. // 验证码无效或者过期,验证码错误
  164. e.OutErr(c, e.ERR_SMS_AUTH, err)
  165. return
  166. }