附近小店
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_qrcode.go 4.0 KiB

1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. "applet/app/utils/qrcode"
  9. "encoding/json"
  10. "fmt"
  11. "github.com/gin-gonic/gin"
  12. "strings"
  13. )
  14. func QrcodePayStyle(c *gin.Context) {
  15. eg := svc.MasterDb(c)
  16. user := svc.GetUser(c)
  17. m, _ := SysModDataBySkipIdentifier(c, "pub.flutter.community_store_qrcode_style")
  18. bytes := utils.MarshalJSONCamelCase2JsonSnakeCase(m.Data)
  19. m.Data = string(bytes)
  20. fmt.Println(m.Data)
  21. store := db.GetStoreIdEg(eg, utils.IntToStr(user.Info.Uid))
  22. if store != nil {
  23. m.Data = strings.ReplaceAll(m.Data, "{店铺名}", store.Name)
  24. m.Data = strings.ReplaceAll(m.Data, "{店铺编号}", utils.IntToStr(store.Uid))
  25. }
  26. var res = make(map[string]interface{})
  27. json.Unmarshal([]byte(m.Data), &res)
  28. e.OutSuc(c, res, nil)
  29. return
  30. }
  31. // 获取mod data by SkipIdentifier
  32. func SysModDataBySkipIdentifier(c *gin.Context, name string) (*model.SysModule, error) {
  33. mod, err := db.SysModFindBySkipIdentifier(c, db.DBs[c.GetString("mid")], name)
  34. if err != nil {
  35. return nil, err
  36. }
  37. return mod, nil
  38. }
  39. func QrcodeBase(c *gin.Context) {
  40. user := svc.GetUser(c)
  41. qrcodeData := db.GetStorePayQrcodeByUid(svc.MasterDb(c), user.Info.Uid)
  42. eg := svc.MasterDb(c)
  43. m, _ := SysModDataBySkipIdentifier(c, "pub.flutter.community_store_qrcode_style")
  44. bytes := utils.MarshalJSONCamelCase2JsonSnakeCase(m.Data)
  45. m.Data = string(bytes)
  46. fmt.Println(m.Data)
  47. store := db.GetStoreIdEg(eg, utils.IntToStr(user.Info.Uid))
  48. if store != nil {
  49. m.Data = strings.ReplaceAll(m.Data, "{店铺名}", store.Name)
  50. m.Data = strings.ReplaceAll(m.Data, "{店铺编号}", utils.IntToStr(store.Uid))
  51. }
  52. css := make(map[string]interface{})
  53. json.Unmarshal([]byte(m.Data), &css)
  54. res := map[string]interface{}{
  55. "pay_url": "",
  56. "pay_qrcode": "",
  57. "css": css,
  58. }
  59. if qrcodeData != nil {
  60. h5Domain := svc.GetWebSiteDomainInfo(c, "wap")
  61. content := h5Domain + "/#/zy-landing-page/pages/o2o-scan/o2o-scan?qrcode_id=" + utils.IntToStr(qrcodeData.Id)
  62. res["pay_url"] = content
  63. res["pay_qrcode"] = strings.ReplaceAll(qrcode.GetPNGBase64(content), "\u0000", "")
  64. }
  65. e.OutSuc(c, res, nil)
  66. return
  67. }
  68. func Qrcode(c *gin.Context) {
  69. var arg map[string]string
  70. if err := c.ShouldBindJSON(&arg); err != nil {
  71. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  72. return
  73. }
  74. user := svc.GetUser(c)
  75. arg["uid"] = utils.IntToStr(user.Info.Uid)
  76. arg["store_type"] = "1"
  77. cate, total := db.GetStoreQrcode(svc.MasterDb(c), arg)
  78. list := make([]map[string]string, 0)
  79. if cate != nil {
  80. h5Domain := svc.GetWebSiteDomainInfo(c, "wap")
  81. for _, v := range *cate {
  82. tmp := map[string]string{
  83. "id": utils.IntToStr(v.Id),
  84. "table_num": v.TableNum,
  85. "name": v.Name,
  86. "is_use": utils.IntToStr(v.IsUse),
  87. "qrcode": "",
  88. "url": "",
  89. }
  90. content := h5Domain + "/#/zy-landing-page/pages/o2o-scan/o2o-scan?qrcode_id=" + utils.AnyToString(v.Id)
  91. tmp["qrcode"] = strings.ReplaceAll(qrcode.GetPNGBase64(content), "\u0000", "")
  92. tmp["url"] = content
  93. list = append(list, tmp)
  94. }
  95. }
  96. res := map[string]interface{}{
  97. "list": list, "total": total,
  98. }
  99. e.OutSuc(c, res, nil)
  100. return
  101. }
  102. func QrcodeSave(c *gin.Context) {
  103. var arg map[string]string
  104. if err := c.ShouldBindJSON(&arg); err != nil {
  105. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  106. return
  107. }
  108. user := svc.GetUser(c)
  109. if arg["id"] != "" {
  110. data := db.GetStoreQrcodeById(svc.MasterDb(c), arg["id"])
  111. data.TableNum = arg["table_num"]
  112. data.Name = arg["name"]
  113. data.IsUse = utils.StrToInt(arg["is_use"])
  114. svc.MasterDb(c).Where("id=?", data.Id).Update(data)
  115. } else {
  116. data := &model.CommunityTeamStoreQrcode{
  117. Uid: user.Info.Uid,
  118. TableNum: arg["table_num"],
  119. IsUse: utils.StrToInt(arg["is_use"]),
  120. Name: arg["name"],
  121. }
  122. svc.MasterDb(c).Insert(data)
  123. }
  124. e.OutSuc(c, "success", nil)
  125. return
  126. }
  127. func QrcodeDel(c *gin.Context) {
  128. var arg map[string]string
  129. if err := c.ShouldBindJSON(&arg); err != nil {
  130. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  131. return
  132. }
  133. svc.MasterDb(c).In("id", strings.Split(arg["ids"], ",")).Delete(&model.CommunityTeamStoreQrcode{})
  134. e.OutSuc(c, "success", nil)
  135. return
  136. }