participate.go 8.0 KB

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