附近小店
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 3.3 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. h5Domain := svc.GetWebSiteDomainInfo(c, "wap")
  41. content := h5Domain + "/#/zy-landing-page/pages/o2o-scan/o2o-scan?qrcode_id=1"
  42. res := map[string]string{
  43. "pay_url": content,
  44. "pay_qrcode": strings.ReplaceAll(qrcode.GetPNGBase64(content), "\u0000", ""),
  45. }
  46. e.OutSuc(c, res, nil)
  47. return
  48. }
  49. func Qrcode(c *gin.Context) {
  50. var arg map[string]string
  51. if err := c.ShouldBindJSON(&arg); err != nil {
  52. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  53. return
  54. }
  55. user := svc.GetUser(c)
  56. arg["uid"] = utils.IntToStr(user.Info.Uid)
  57. arg["store_type"] = "1"
  58. cate, total := db.GetStoreQrcode(svc.MasterDb(c), arg)
  59. list := make([]map[string]string, 0)
  60. if cate != nil {
  61. h5Domain := svc.GetWebSiteDomainInfo(c, "wap")
  62. for _, v := range *cate {
  63. tmp := map[string]string{
  64. "id": utils.IntToStr(v.Id),
  65. "table_num": v.TableNum,
  66. "name": v.Name,
  67. "is_use": utils.IntToStr(v.IsUse),
  68. "qrcode": "",
  69. "url": "",
  70. }
  71. content := h5Domain + "/#/zy-landing-page/pages/o2o-scan/o2o-scan?qrcode_id=" + utils.AnyToString(v.Id)
  72. tmp["qrcode"] = strings.ReplaceAll(qrcode.GetPNGBase64(content), "\u0000", "")
  73. tmp["url"] = content
  74. list = append(list, tmp)
  75. }
  76. }
  77. res := map[string]interface{}{
  78. "list": list, "total": total,
  79. }
  80. e.OutSuc(c, res, nil)
  81. return
  82. }
  83. func QrcodeSave(c *gin.Context) {
  84. var arg map[string]string
  85. if err := c.ShouldBindJSON(&arg); err != nil {
  86. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  87. return
  88. }
  89. user := svc.GetUser(c)
  90. if arg["id"] != "" {
  91. data := db.GetStoreQrcodeById(svc.MasterDb(c), arg["id"])
  92. data.TableNum = arg["table_num"]
  93. data.Name = arg["name"]
  94. data.IsUse = utils.StrToInt(arg["is_use"])
  95. svc.MasterDb(c).Where("id=?", data.Id).Update(data)
  96. } else {
  97. data := &model.CommunityTeamStoreQrcode{
  98. Uid: user.Info.Uid,
  99. TableNum: arg["table_num"],
  100. IsUse: utils.StrToInt(arg["is_use"]),
  101. Name: arg["name"],
  102. }
  103. svc.MasterDb(c).Insert(data)
  104. }
  105. e.OutSuc(c, "success", nil)
  106. return
  107. }
  108. func QrcodeDel(c *gin.Context) {
  109. var arg map[string]string
  110. if err := c.ShouldBindJSON(&arg); err != nil {
  111. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  112. return
  113. }
  114. svc.MasterDb(c).In("id", strings.Split(arg["ids"], ",")).Delete(&model.CommunityTeamStoreQrcode{})
  115. e.OutSuc(c, "success", nil)
  116. return
  117. }