participate.go 6.8 KB

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