|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- package svc
-
- import (
- "applet/app/db"
- "applet/app/db/model"
- "applet/app/e"
- "applet/app/svc"
- "applet/app/utils"
- "applet/app/utils/qrcode"
- "encoding/json"
- "fmt"
- "github.com/gin-gonic/gin"
- "strings"
- )
-
- func QrcodePayStyle(c *gin.Context) {
- eg := svc.MasterDb(c)
- user := svc.GetUser(c)
- m, _ := SysModDataBySkipIdentifier(c, "pub.flutter.community_store_qrcode_style")
- bytes := utils.MarshalJSONCamelCase2JsonSnakeCase(m.Data)
- m.Data = string(bytes)
- fmt.Println(m.Data)
- store := db.GetStoreIdEg(eg, utils.IntToStr(user.Info.Uid))
- if store != nil {
- m.Data = strings.ReplaceAll(m.Data, "{店铺名}", store.Name)
- m.Data = strings.ReplaceAll(m.Data, "{店铺编号}", utils.IntToStr(store.Uid))
- }
- var res = make(map[string]interface{})
- json.Unmarshal([]byte(m.Data), &res)
- e.OutSuc(c, res, nil)
- return
- }
-
- // 获取mod data by SkipIdentifier
- func SysModDataBySkipIdentifier(c *gin.Context, name string) (*model.SysModule, error) {
- mod, err := db.SysModFindBySkipIdentifier(c, db.DBs[c.GetString("mid")], name)
- if err != nil {
- return nil, err
- }
- return mod, nil
- }
- func QrcodeBase(c *gin.Context) {
- h5Domain := svc.GetWebSiteDomainInfo(c, "wap")
- content := h5Domain + "/#/zy-landing-page/pages/o2o-scan/o2o-scan?qrcode_id=1"
- res := map[string]string{
- "pay_url": content,
- "pay_qrcode": strings.ReplaceAll(qrcode.GetPNGBase64(content), "\u0000", ""),
- }
- e.OutSuc(c, res, nil)
- return
- }
- func Qrcode(c *gin.Context) {
- var arg map[string]string
- if err := c.ShouldBindJSON(&arg); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- user := svc.GetUser(c)
- arg["uid"] = utils.IntToStr(user.Info.Uid)
- arg["store_type"] = "1"
- cate, total := db.GetStoreQrcode(svc.MasterDb(c), arg)
- list := make([]map[string]string, 0)
- if cate != nil {
- h5Domain := svc.GetWebSiteDomainInfo(c, "wap")
- for _, v := range *cate {
- tmp := map[string]string{
- "id": utils.IntToStr(v.Id),
- "table_num": v.TableNum,
- "name": v.Name,
- "is_use": utils.IntToStr(v.IsUse),
- "qrcode": "",
- "url": "",
- }
- content := h5Domain + "/#/zy-landing-page/pages/o2o-scan/o2o-scan?qrcode_id=" + utils.AnyToString(v.Id)
- tmp["qrcode"] = strings.ReplaceAll(qrcode.GetPNGBase64(content), "\u0000", "")
- tmp["url"] = content
- list = append(list, tmp)
- }
- }
- res := map[string]interface{}{
- "list": list, "total": total,
- }
- e.OutSuc(c, res, nil)
- return
- }
- func QrcodeSave(c *gin.Context) {
- var arg map[string]string
- if err := c.ShouldBindJSON(&arg); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- user := svc.GetUser(c)
- if arg["id"] != "" {
- data := db.GetStoreQrcodeById(svc.MasterDb(c), arg["id"])
- data.TableNum = arg["table_num"]
- data.Name = arg["name"]
- data.IsUse = utils.StrToInt(arg["is_use"])
- svc.MasterDb(c).Where("id=?", data.Id).Update(data)
- } else {
- data := &model.CommunityTeamStoreQrcode{
- Uid: user.Info.Uid,
- TableNum: arg["table_num"],
- IsUse: utils.StrToInt(arg["is_use"]),
- Name: arg["name"],
- }
- svc.MasterDb(c).Insert(data)
- }
- e.OutSuc(c, "success", nil)
- return
- }
- func QrcodeDel(c *gin.Context) {
- var arg map[string]string
- if err := c.ShouldBindJSON(&arg); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- svc.MasterDb(c).In("id", strings.Split(arg["ids"], ",")).Delete(&model.CommunityTeamStoreQrcode{})
- e.OutSuc(c, "success", nil)
- return
- }
|