participate.go 7.8 KB

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