participate.go 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. package service
  2. import (
  3. MC "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/encrypt"
  5. "fmt"
  6. "jyBXCore/rpc/model/es"
  7. "jyBXCore/rpc/model/mysql"
  8. "jyBXCore/rpc/type/bxcore"
  9. "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. if in.PositionType > 0 {
  94. // p408 增加
  95. go mysql.NewParStage(in.EntId, in.ProjectIds, "参标").UpdateStage()
  96. }
  97. case "out": //终止参标
  98. if in.BidIds == "" && in.ProjectIds == "" {
  99. return fmt.Errorf("缺少参数")
  100. }
  101. if err := GetProjectInfoByES(in); err != nil {
  102. return err
  103. }
  104. if err := mysql.CancelParticipateInfo(in, entRoleId); err != nil {
  105. return err
  106. }
  107. if in.PositionType > 0 {
  108. // p408 增加
  109. go mysql.NewParStage(in.EntId, in.ProjectIds, "终止参标").UpdateStage()
  110. }
  111. case "transfer":
  112. //PC端 多个项目-》一个人
  113. //移动端 一个项目-》多个人
  114. if in.ProjectIds == "" {
  115. return fmt.Errorf("项目信息有误")
  116. }
  117. //个人版
  118. if in.PositionType == 0 {
  119. return fmt.Errorf("当前企业身份有误")
  120. }
  121. //非管理员
  122. if entRoleId == 0 { //1:企业管理员;2:部门管理员
  123. return fmt.Errorf("当前企业身份无权限")
  124. }
  125. //判断划转人
  126. if in.ToEntUserId == "" {
  127. return fmt.Errorf("划转对象不能为空")
  128. }
  129. //是否保留原跟踪人?
  130. isAllow := mysql.IsALLow(in.EntId)
  131. if (in.IsRetain || len(strings.Split(in.ToEntUserId, ",")) > 1) && !isAllow {
  132. //不允许多人参标,但是前端参数又是保留原参标人 互相矛盾
  133. return fmt.Errorf("当前项目只允许一人参标")
  134. }
  135. //in.ProjectIds //项目id
  136. projectIds := strings.Split(in.ProjectIds, ",")
  137. projectNum := 0
  138. for _, v := range projectIds {
  139. projectId := encrypt.DecodeArticleId2ByCheck(v)[0]
  140. if projectId == "" {
  141. continue
  142. }
  143. if err := mysql.TransferParticipateInfo(projectId, in); err != nil {
  144. log.Println(fmt.Sprintf("是否允许多人参标:%v, 项目id:%s,企业id:%d,划转对象entuserid:%s,划转异常:", isAllow, projectId, in.EntId, in.ToEntUserId))
  145. continue
  146. }
  147. projectNum += 1
  148. }
  149. if projectNum == 0 { //!= len(projectIds)
  150. return fmt.Errorf("划转失败")
  151. }
  152. }
  153. return nil
  154. }
  155. // 参标设置更新及设置内容
  156. func GetParticipateSetInfo(in *bxcore.ParticipateSetUpInfoReq) (*bxcore.ParticipateSetUpInfoRes, error) {
  157. defer MC.Catch()
  158. res := &bxcore.ParticipateSetUpInfoRes{Data: &bxcore.ParticipateSetUpInfo{
  159. IsAllow: 0,
  160. BidType: nil,
  161. RemindRule: nil,
  162. }}
  163. b, entRoleId := util.IsAllowedParticipate(in.AppId, in.MgoUserId, in.NewUserId, in.AccountId, in.EntAccountId, in.EntId, in.EntUserId, in.PositionId, in.PositionType)
  164. if !b {
  165. res.ErrMsg = "没有权限"
  166. res.Data = nil
  167. res.ErrCode = 0
  168. } else {
  169. switch in.SetAction {
  170. case "U": //update 更新设置信息
  171. res.Data = nil
  172. if entRoleId == 0 || entRoleId == 2 { //只有企业管理员有权限
  173. res.ErrCode = -1
  174. res.ErrMsg = "当前企业身份无权限"
  175. }
  176. if err := mysql.UpdateParticipateSetInfo(in); err != nil {
  177. res.ErrCode = -1
  178. res.ErrMsg = err.Error()
  179. }
  180. default: //默认查询对应设置信息
  181. //查询对应用户设置信息
  182. //未设置过 返回默认配置
  183. if info, err := mysql.GetParticipateSetInfo(in); err == nil {
  184. info.IsShow = MC.If(entRoleId == 1, entRoleId, int64(-1)).(int64)
  185. res.Data = info
  186. } else {
  187. res.ErrCode = -1
  188. res.ErrMsg = err.Error()
  189. }
  190. }
  191. }
  192. return res, nil
  193. }
  194. // 参标企业人员信息
  195. func GetParticipatePersonInfo(in *bxcore.ParticipatePersonsReq) *bxcore.ParticipatePersonsRes {
  196. var (
  197. participateMap = map[int64]bool{}
  198. )
  199. if in.ProjectId != "" {
  200. in.ProjectId = encrypt.DecodeArticleId2ByCheck(in.ProjectId)[0]
  201. if in.ProjectId != "" {
  202. participateInfos := mysql.ParticipateProjectEnt(in.EntId, strings.Split(in.ProjectId, ","))
  203. if participateInfos != nil && len(*participateInfos) > 0 {
  204. participateInfo := (*participateInfos)[0]
  205. personIds := MC.ObjToString(participateInfo["personIds"])
  206. if personIds != "" {
  207. for _, p := range strings.Split(personIds, ",") {
  208. personId, _ := strconv.ParseInt(p, 10, 64)
  209. participateMap[personId] = true
  210. }
  211. }
  212. }
  213. }
  214. }
  215. //查询企业人员信息
  216. personInfos := mysql.GetPersonInfo(in.EntId, in.EntUserId, participateMap)
  217. return &bxcore.ParticipatePersonsRes{
  218. Data: personInfos,
  219. }
  220. }
  221. // 获取项目信息
  222. func GetProjectInfoByES(in *bxcore.ParticipateActionReq) error {
  223. //参标和终止参标 单个项目;不进行批量操作
  224. in.ProjectIds = MC.If(in.ProjectIds != "", in.ProjectIds, in.BidIds).(string)
  225. var (
  226. tip = "参标"
  227. )
  228. switch in.ActionType {
  229. case "out":
  230. tip = "终止参标"
  231. //case "transfer":
  232. // tip = "划转"
  233. }
  234. in.ProjectIds = strings.Split(in.ProjectIds, ",")[0]
  235. in.ProjectIds = encrypt.DecodeArticleId2ByCheck(in.ProjectIds)[0]
  236. if in.ProjectIds == "" {
  237. return fmt.Errorf("当前招标信息有误")
  238. }
  239. //当前项目是否符合参标条件
  240. //根据项目id查询project
  241. projectInfos := es.GetBidInfoByPId(in.ProjectIds)
  242. if projectInfos == nil || len(*projectInfos) == 0 {
  243. //当前项目是否符合参标条件
  244. //根据招标信息id 查询bidding
  245. projectInfos = es.GetProjectByInfoId(strings.Split(in.ProjectIds, ","))
  246. if projectInfos == nil || len(*projectInfos) == 0 {
  247. return fmt.Errorf(fmt.Sprintf("当前项目信息不满足%s条件", tip))
  248. }
  249. }
  250. if projectInfos != nil && len(*projectInfos) > 0 {
  251. //符合参标项目id
  252. projectInfo := (*projectInfos)[0]
  253. if projectInfo["_id"] != nil && MC.ObjToString(projectInfo["_id"]) != "" {
  254. bidEndTime := MC.Int64All(projectInfo["bidendtime"]) //1292126400:2010.12.12
  255. if bidEndTime > 1292126400 && bidEndTime < time.Now().Unix() { //招标结束时间已到期
  256. return fmt.Errorf("招标时间已结束")
  257. }
  258. //项目信息id
  259. in.ProjectIds = MC.ObjToString(projectInfo["_id"])
  260. } else {
  261. return fmt.Errorf("当前项目信息有误")
  262. }
  263. }
  264. return nil
  265. }