participate.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. package service
  2. import (
  3. MC "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/encrypt"
  5. "fmt"
  6. "github.com/zeromicro/go-zero/core/logx"
  7. IC "jyBXCore/rpc/init"
  8. "jyBXCore/rpc/model/es"
  9. "jyBXCore/rpc/model/mysql"
  10. "jyBXCore/rpc/type/bxcore"
  11. "jyBXCore/rpc/util"
  12. "strings"
  13. )
  14. //我的参标项目|企业参标项目 列表
  15. func ParticipateList(in *bxcore.ParticipateListReq) (*bxcore.ParticipateListRes, error) {
  16. defer MC.Catch()
  17. res := &bxcore.ParticipateListRes{Data: &bxcore.ParticipateData{}}
  18. if in.PositionType > 0 {
  19. userInfo := IC.Middleground.PowerCheckCenter.Check(in.AppId, in.UserId, in.NewUserId, in.AccountId, in.EntId, in.PositionType, in.PositionId)
  20. if userInfo.Ent.EntRoleId == 0 {
  21. in.EntUserIds = ""
  22. }
  23. }
  24. switch in.Identity {
  25. case "mine": //员工|个人列表
  26. r, e := mysql.SingleParticipateList(in, mysql.ParticipateListSql(in))
  27. if e != nil {
  28. res.ErrCode = -1
  29. res.ErrMsg = e.Error()
  30. return res, nil
  31. }
  32. res.Data = r
  33. case "ent": //企业管理员
  34. r, e := mysql.AdminParticipateList(in, mysql.ParticipateListSql(in))
  35. if e != nil {
  36. res.ErrCode = -1
  37. res.ErrMsg = e.Error()
  38. return res, nil
  39. }
  40. res.Data = r
  41. }
  42. return res, nil
  43. }
  44. /*
  45. 已过投标截止日期项目
  46. (1) 不显示终止投标倒计时
  47. (2) 显示参标人信息
  48. (3) 无终止参标操作入口
  49. (4) 不能划转
  50. (5) 不能参标
  51. */
  52. //参标动作:参标、终止参标、划转:in:参标;out:终止参标;transfer:划转
  53. func ParticipateDo(in *bxcore.ParticipateActionReq) error {
  54. defer MC.Catch()
  55. var (
  56. tip = "参标"
  57. )
  58. switch in.ActionType {
  59. case "out":
  60. tip = "终止参标"
  61. case "transfer":
  62. tip = "划转"
  63. }
  64. //企业版 判断是否是管理员
  65. //判断用户身份
  66. userInfo := IC.Middleground.PowerCheckCenter.Check(in.AppId, in.UserId, in.NewUserId, in.AccountId, in.EntId, in.PositionType, in.PositionId)
  67. switch in.ActionType {
  68. case "in": //参标针对单个招标信息 或者 项目
  69. if in.BidIds == "" && in.ProjectIds == "" {
  70. return fmt.Errorf("缺少参数")
  71. }
  72. if in.ProjectIds != "" {
  73. in.ProjectIds = strings.Split(in.ProjectIds, ",")[0]
  74. in.ProjectIds = encrypt.DecodeArticleId2ByCheck(in.ProjectIds)[0]
  75. if in.ProjectIds == "" {
  76. return fmt.Errorf("当前招标信息有误")
  77. }
  78. //当前项目是否符合参标条件
  79. projectInfos := es.GetBidInfoByPId(in.ProjectIds)
  80. if projectInfos == nil || len(*projectInfos) == 0 {
  81. return fmt.Errorf(fmt.Sprintf("当前项目信息不满足%s条件", tip))
  82. }
  83. //符合参标项目id
  84. projectInfo := (*projectInfos)[0]
  85. if projectInfo["sourceinfoid"] != nil && MC.ObjToString(projectInfo["sourceinfoid"]) != "" {
  86. //招标信息id
  87. in.BidIds = MC.ObjToString(projectInfo["sourceinfoid"])
  88. } else {
  89. return fmt.Errorf("当前项目信息有误")
  90. }
  91. } else {
  92. in.BidIds = strings.Split(in.BidIds, ",")[0]
  93. //招标信息解密
  94. in.BidIds = encrypt.DecodeArticleId2ByCheck(in.BidIds)[0]
  95. if in.BidIds == "" {
  96. return fmt.Errorf("当前招标信息有误")
  97. }
  98. //当前项目是否符合参标条件
  99. projectInfos := es.GetProjectByInfoId(strings.Split(in.BidIds, ","))
  100. if projectInfos == nil || len(*projectInfos) == 0 {
  101. return fmt.Errorf(fmt.Sprintf("当前项目信息不满足%s条件", tip))
  102. }
  103. //符合参标项目id
  104. projectInfo := (*projectInfos)[0]
  105. if projectInfo["_id"] != nil && MC.ObjToString(projectInfo["_id"]) != "" {
  106. //项目信息id
  107. in.ProjectIds = MC.ObjToString(projectInfo["_id"])
  108. } else {
  109. return fmt.Errorf("当前项目信息有误")
  110. }
  111. }
  112. //是否允许多人参标
  113. if isAllow := util.IsALLow(in.EntId); !isAllow {
  114. if ok := mysql.IsParticipatedByBidId(in); ok {
  115. return fmt.Errorf("当前项目不允许多人参标")
  116. }
  117. }
  118. //保存参标信息 更新当前企业参标项目记录
  119. if err := mysql.SaveParticipateInfo(in); err != nil {
  120. return err
  121. }
  122. case "out": //终止参标
  123. if in.ProjectIds == "" {
  124. return fmt.Errorf("项目信息有误")
  125. }
  126. in.ProjectIds = strings.Split(in.ProjectIds, ",")[0]
  127. //招标信息解密
  128. in.ProjectIds = encrypt.DecodeArticleId2ByCheck(in.ProjectIds)[0]
  129. if in.ProjectIds == "" {
  130. return fmt.Errorf("当前项目信息有误")
  131. }
  132. if err := mysql.CancelParticipateInfo(in, userInfo.Ent.EntRoleId); err != nil {
  133. return err
  134. }
  135. case "transfer":
  136. if in.ProjectIds == "" {
  137. return fmt.Errorf("项目信息有误")
  138. }
  139. //个人版
  140. if in.PositionType == 0 {
  141. return fmt.Errorf("当前企业身份有误")
  142. }
  143. //非管理员
  144. if userInfo.Ent.EntRoleId == 0 { //1:企业管理员;2:部门管理员
  145. return fmt.Errorf("当前企业身份无权限")
  146. }
  147. //判断划转人
  148. if in.ToEntUserId == "" {
  149. return fmt.Errorf("划转对象不能为空")
  150. }
  151. //是否保留原跟踪人?
  152. isAllow := util.IsALLow(in.EntId)
  153. if in.IsRetain && !isAllow {
  154. //不允许多人参标,但是前端参数又是保留原参标人 互相矛盾
  155. return fmt.Errorf("当前项目只允许一人参标")
  156. }
  157. //in.ProjectIds //项目id
  158. projectIds := strings.Split(in.ProjectIds, ",")
  159. projectNum := 0
  160. for _, v := range projectIds {
  161. projectId := encrypt.DecodeArticleId2ByCheck(v)[0]
  162. if projectId == "" {
  163. continue
  164. }
  165. if err := mysql.TransferParticipateInfo(projectId, in); err != nil {
  166. logx.Info(fmt.Sprintf("是否允许多人参标:%v, 项目id:%s,企业id:%d,划转对象entuserid:%s,划转异常:", isAllow, projectId, in.EntId, in.ToEntUserId))
  167. continue
  168. }
  169. projectNum += 1
  170. }
  171. if projectNum != len(projectIds) {
  172. return fmt.Errorf("划转失败")
  173. }
  174. }
  175. return nil
  176. }
  177. //参标设置更新及设置内容
  178. func GetParticipateSetInfo(in *bxcore.ParticipateSetUpInfoReq) (*bxcore.ParticipateSetUpInfoRes, error) {
  179. defer MC.Catch()
  180. res := &bxcore.ParticipateSetUpInfoRes{Data: &bxcore.ParticipateSetUpInfo{
  181. IsAllow: "0",
  182. BidType: nil,
  183. RemindRule: nil,
  184. }}
  185. switch in.SetAction {
  186. case "U": //update 更新设置信息
  187. res.Data = nil
  188. if err := mysql.UpdateParticipateSetInfo(in); err != nil {
  189. res.ErrCode = -1
  190. res.ErrMsg = err.Error()
  191. }
  192. default: //默认查询对应设置信息
  193. //查询对应用户设置信息
  194. //未设置过 返回默认配置
  195. if info, err := mysql.GetParticipateSetInfo(in); err == nil {
  196. res.Data = info
  197. } else {
  198. res.ErrCode = -1
  199. res.ErrMsg = err.Error()
  200. }
  201. }
  202. return res, nil
  203. }