AuthService.go 3.0 KB

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