participate.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package service
  2. import (
  3. MC "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/encrypt"
  5. "fmt"
  6. IC "jyBXCore/rpc/init"
  7. "jyBXCore/rpc/model/tidb"
  8. "jyBXCore/rpc/type/bxcore"
  9. "jyBXCore/rpc/util"
  10. )
  11. //参标动作:参标、终止参标、划转:in:参标;out:终止参标;transfer:划转
  12. func ParticipateDo(in *bxcore.ParticipateActionReq) (*bxcore.ParticipateActionRes, error) {
  13. //招标信息解密
  14. in.BidId = encrypt.DecodeArticleId2ByCheck(in.BidId)[0]
  15. if in.BidId == "" {
  16. return nil, fmt.Errorf("当前招标信息有误")
  17. }
  18. //当前项目是否符合参标条件
  19. participateBid := NewParticipateBid(in.EntId, in.EntUserId, in.PositionType, in.PositionId)
  20. projectInfos := participateBid.GetProjectByInfoId([]string{in.BidId})
  21. if projectInfos == nil || len(*projectInfos) == 0 {
  22. return nil, fmt.Errorf("当前项目信息不满足参标条件")
  23. }
  24. //符合参标项目id
  25. projectInfo := (*projectInfos)[0]
  26. if projectInfo["_id"] != nil && MC.ObjToString(projectInfo["_id"]) != "" {
  27. in.BidId = MC.ObjToString(projectInfo["_id"])
  28. } else {
  29. return nil, fmt.Errorf("当前项目信息有误")
  30. }
  31. switch in.ActionType {
  32. case "in":
  33. //是否允许多人参标
  34. if isAllow := util.NewPartUserInfo(in.EntId, in.EntUserId, in.PositionId, in.PositionType).IsALLow(); !isAllow {
  35. //如果不允许多人参标 当前项目是否已经有企业其他人员参标
  36. query := fmt.Sprintf(`SELECT count(id) FROM participate_user WHERE %s AND project_id = %s AND state >-1`, "%s", in.BidId)
  37. if in.PositionType > 0 {
  38. query = fmt.Sprintf(query, fmt.Sprintf("ent_id = %d", in.EntId))
  39. } else {
  40. query = fmt.Sprintf(query, fmt.Sprintf("position_id = %d", in.PositionId))
  41. }
  42. if ok := tidb.IsParticipatedByBidId(query); ok {
  43. return nil, fmt.Errorf("当前项目不允许多人参标")
  44. }
  45. }
  46. //保存参标信息 更新当前企业参标项目记录
  47. if err := tidb.SaveParticipateInfo(in); err != nil {
  48. return nil, err
  49. }
  50. case "out": //终止参标
  51. if err := tidb.UpdateParticipateInfo(in); err != nil {
  52. return nil, err
  53. }
  54. case "transfer":
  55. if in.PositionType == 0 {
  56. return nil, fmt.Errorf("当前企业身份有误")
  57. }
  58. //企业版 判断是否是管理员
  59. //判断用户身份
  60. userInfo := IC.Middleground.PowerCheckCenter.Check(in.AppId, in.UserId, in.NewUserId, in.AccountId, in.EntId, in.PositionType, in.PositionId)
  61. if userInfo.Ent.EntRoleId == 0 { //1:企业管理员;2:部门管理员
  62. return nil, fmt.Errorf("当前企业身份无权限")
  63. }
  64. //是否保留原跟踪人?
  65. partUser := util.NewPartUserInfo(in.EntId, in.EntUserId, in.PositionId, in.PositionType)
  66. isAllow := partUser.IsALLow()
  67. if !isAllow && in.IsRetain {
  68. //不允许多人参标,但是前端参数又是保留原参标人 互相矛盾
  69. return nil, fmt.Errorf("当前项目只允许一人参标")
  70. }
  71. if err := tidb.TransferParticipate(in); err != nil {
  72. return nil, err
  73. }
  74. }
  75. return &bxcore.ParticipateActionRes{
  76. Data: true,
  77. }, nil
  78. }
  79. //参标设置更新及设置内容
  80. func GetParticipateSetInfo(in *bxcore.ParticipateSetUpInfoReq) (*bxcore.ParticipateSetUpInfoRes, error) {
  81. res := &bxcore.ParticipateSetUpInfoRes{Data: &bxcore.ParticipateSetUpInfo{
  82. IsAllow: "0",
  83. BidType: nil,
  84. RemindRule: nil,
  85. }}
  86. switch in.SetAction {
  87. case "U": //update 更新设置信息
  88. res.Data = nil
  89. if err := tidb.UpdateParticipateSetInfo(in); err != nil {
  90. res.ErrCode = -1
  91. res.ErrMsg = err.Error()
  92. }
  93. default: //默认查询对应设置信息
  94. //查询对应用户设置信息
  95. //未设置过 返回默认配置
  96. if info, err := tidb.GetParticipateSetInfo(in); err == nil {
  97. res.Data = info
  98. } else {
  99. res.ErrCode = -1
  100. res.ErrMsg = err.Error()
  101. }
  102. }
  103. return res, nil
  104. }