附近小店
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

169 rader
4.3 KiB

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