participate.go 8.5 KB

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