AuthService.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package service
  2. import (
  3. "app.yhyue.com/moapp/jybase/date"
  4. "app.yhyue.com/moapp/jybase/go-xweb/log"
  5. "app.yhyue.com/moapp/jybase/mysql"
  6. "bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/entity"
  7. "bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/medical"
  8. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/resource"
  9. "context"
  10. "database/sql"
  11. "fmt"
  12. )
  13. type AuthService struct {
  14. GoodsCode string
  15. GoodsSpecId int64
  16. BasesqlConn *mysql.Mysql
  17. }
  18. //认证信息保存
  19. func (b AuthService) UserAuthInfoSave(in *medical.UserInfo) (bool, string) {
  20. //先判断用户是否存在
  21. user := b.BasesqlConn.FindOne(entity.DOMAIN_CAPITAL_RETENTION, map[string]interface{}{
  22. "user_id": in.UserId, "appid": in.Appid,
  23. }, "id", "")
  24. if user != nil {
  25. if in.OperationType == "add" {
  26. return false, "用户已验证"
  27. }
  28. } else {
  29. if in.OperationType == "update" {
  30. return false, "用户未认证,不可修改"
  31. }
  32. }
  33. if in.OperationType == "update" {
  34. //修改处理
  35. data := map[string]interface{}{
  36. "name": in.Name,
  37. "phone": in.Phone,
  38. "position": in.Position,
  39. "department": in.Department,
  40. "mail": in.Mail,
  41. "ent_name": in.EntName,
  42. "source": entity.MEDICALDOMAIN,
  43. }
  44. ok1 := b.BasesqlConn.Update(entity.DOMAIN_CAPITAL_RETENTION, map[string]interface{}{"user_id": in.UserId, "appid": in.Appid, "source": entity.MEDICALDOMAIN}, data)
  45. if ok1 {
  46. return true, ""
  47. } else {
  48. log.Println(fmt.Sprintf("认证修改失败:入参:%v:%v,", in.UserId, data))
  49. return false, "修改失败"
  50. }
  51. } else {
  52. //新增处理
  53. data := map[string]interface{}{
  54. "name": in.Name,
  55. "phone": in.Phone,
  56. "position": in.Position,
  57. "department": in.Department,
  58. "mail": in.Mail,
  59. "ent_name": in.EntName,
  60. "user_id": in.UserId,
  61. "create_time": date.NowFormat(date.Date_Full_Layout)),
  62. "appid": in.Appid,
  63. "source": entity.MEDICALDOMAIN,
  64. }
  65. msg := ""
  66. ok := b.BasesqlConn.ExecTx("认证信息保存", func(tx *sql.Tx) bool {
  67. ok1 := b.BasesqlConn.InsertByTx(tx, entity.DOMAIN_CAPITAL_RETENTION, data)
  68. if ok1 <= 0 {
  69. log.Println(fmt.Sprintf("认证失败:参数:%v", data))
  70. msg = "认证信息保存失败"
  71. return false
  72. }
  73. //开通权益
  74. req := &resource.PowerReq{
  75. Appid: in.Appid,
  76. GoodsCode: b.GoodsCode,
  77. GoodsSpecId: b.GoodsSpecId,
  78. EntId: 0,
  79. UserId: in.UserId,
  80. BuyNum: 1,
  81. Type: int64(1),
  82. }
  83. resq, err := entity.ResourceLib.PowerHandle(context.Background(), req)
  84. if err != nil || resq.Status != 1 {
  85. log.Println("权益开通调用失败:", req, resq)
  86. msg = "权益开通调用失败"
  87. return false
  88. }
  89. return ok1 > 0
  90. })
  91. return ok, msg
  92. }
  93. }
  94. //认证信息查询
  95. func (b AuthService) UserAuthInfo(in *medical.CommonReq) *map[string]interface{} {
  96. //先判断用户是否存在
  97. user := b.BasesqlConn.FindOne(entity.DOMAIN_CAPITAL_RETENTION, map[string]interface{}{
  98. "user_id": in.UserId, "appid": in.Appid, "source": entity.MEDICALDOMAIN,
  99. }, "*", "")
  100. return user
  101. }