jz_qr_code_logic.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package user
  2. import (
  3. "context"
  4. "fmt"
  5. "git.i2edu.net/i2/go-zero/core/logx"
  6. "git.i2edu.net/i2/i2-bill-api/internal/svc"
  7. "git.i2edu.net/i2/i2-bill-api/internal/types"
  8. )
  9. type JzQrCodeLogic struct {
  10. logx.Logger
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. UserId int64
  14. SessionKey string
  15. }
  16. func NewJzQrCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) JzQrCodeLogic {
  17. return JzQrCodeLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. }
  22. }
  23. // JzQrCode 兼职人员兼职码
  24. func (l *JzQrCodeLogic) JzQrCode() (*types.JzQrcodeResponse, error) {
  25. //uid, err := l.svcCtx.Wechat.GenUserQrId(svc.QrcodeJzPrefix, l.UserId, map[string]interface{}{
  26. // "userId": l.UserId,
  27. // "timestamp": time.Now().Unix(),
  28. // "type": "JzQrCode",
  29. //})
  30. //fmt.Println("--uid=", uid)
  31. // l.svcCtx.Wechat.GetQrParams(qrcodeJzPrefix, uid, map[string]interface{}{})
  32. //if err != nil {
  33. // return nil, err
  34. //}
  35. userId := l.svcCtx.GetUserIdByJwt(l.ctx)
  36. attr, err := l.svcCtx.Wechat.GenQrCode(fmt.Sprintf("%d", userId), l.svcCtx.Config.Weixin.SharePage)
  37. tx := l.svcCtx.DB.NewSession()
  38. _, err = tx.Where("user_id = ?", userId).Update(map[string]interface{}{"qr": attr.Url})
  39. if err != nil {
  40. tx.Rollback()
  41. return &types.JzQrcodeResponse{}, err
  42. }
  43. _, err = tx.Insert(attr)
  44. if err != nil {
  45. tx.Rollback()
  46. return &types.JzQrcodeResponse{}, err
  47. }
  48. return &types.JzQrcodeResponse{
  49. FileId: attr.Url,
  50. }, nil
  51. }