participateBid.go 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. package service
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/encrypt"
  5. "fmt"
  6. IC "jyBXCore/rpc/init"
  7. "jyBXCore/rpc/type/bxcore"
  8. "strings"
  9. )
  10. const (
  11. TableEntnicheUser = "entniche_user" // 企业用户表
  12. TableParticipateUser = "participate_user" // 参标用户表
  13. PositionTypeEnt = 1 // 职位类型企业
  14. PositionTypePersonal = 0 // 职位类型个人
  15. ButtonValueParticipate = 0 // 参标按钮 显示值 0-参标
  16. ButtonValueParticipated = 1 // 按钮显示值 列表页面 1-已参标
  17. RoleEntManager = 1 // 企业管理员角色
  18. RoleDepartManager = 2 // 部门管理员角色
  19. BidTypeDirect = 1 // 直接投标
  20. BidTypeChanel = 2 // 渠道投标
  21. )
  22. type ParticipateBid struct {
  23. EntId int64
  24. EntUserId int64
  25. PositionType int64
  26. PositionId int64
  27. EntRoleId int64 // 角色
  28. }
  29. func NewParticipateBid(entId, entUserId, positionType, positionId int64) ParticipateBid {
  30. return ParticipateBid{
  31. EntId: entId,
  32. EntUserId: entUserId,
  33. PositionType: positionType,
  34. PositionId: positionId,
  35. }
  36. }
  37. // PersonalExistProject 个人版要展示的参标按钮 查询出已经参标的项目信息 用于后边格式化数据
  38. func (p *ParticipateBid) PersonalExistProject(projectId []string) map[string]struct{} {
  39. // 1. 查询出已经参标的
  40. var arg []string
  41. var value []interface{}
  42. value = append(value, p.PositionId)
  43. for i := 0; i < len(projectId); i++ {
  44. arg = append(arg, "?")
  45. value = append(value, projectId[i])
  46. }
  47. argStr := strings.Join(arg, ",")
  48. query := "select project_id from " + TableParticipateUser + " where position_id = ? and project_id in (%s) and state>=0"
  49. rs := IC.BaseMysql.SelectBySql(fmt.Sprintf(query, argStr), value...)
  50. existProjectSet := map[string]struct{}{}
  51. if rs != nil && len(*rs) > 0 { // 如果查到了 说明已经参标 这部分应该显示已参标
  52. // 处理成map
  53. for i := 0; i < len(*rs); i++ {
  54. existId := common.ObjToString((*rs)[i]["project_id"])
  55. existProjectSet[existId] = struct{}{}
  56. }
  57. }
  58. return existProjectSet
  59. }
  60. // ListPersonalFormat 列表页个人版 参标按钮 格式化数据
  61. func (p *ParticipateBid) ListPersonalFormat(existProjectSet map[string]struct{}, infoM map[string]string) []*bxcore.ShowInfo {
  62. // 处理成 要返回的返回数据
  63. var formatList []*bxcore.ShowInfo
  64. for k, v := range infoM {
  65. buttonValue := ButtonValueParticipate // 不存在应该显示参标
  66. if _, ok := existProjectSet[v]; ok { // 存在说明应该显示已参标
  67. buttonValue = ButtonValueParticipated
  68. }
  69. formatList = append(formatList, &bxcore.ShowInfo{
  70. Id: encrypt.EncodeArticleId2ByCheck(k),
  71. Value: int64(buttonValue),
  72. })
  73. }
  74. return formatList
  75. }
  76. // EntExistProject 企业版 查出来企业下已经参标的这个项目的以及参标人信息 用于后边格式化数据判断有没有自己
  77. func (p *ParticipateBid) EntExistProject(projectId []string) map[string]string {
  78. var arg []string
  79. var value []interface{}
  80. value = append(value, p.EntId)
  81. for i := 0; i < len(projectId); i++ {
  82. arg = append(arg, "?")
  83. value = append(value, projectId[i])
  84. }
  85. argStr := strings.Join(arg, ",")
  86. query := "select GROUP_CONCAT(ent_user_id) as personIds ,project_id from " + TableParticipateUser + " where ent_id=? and project_id in (%s) and state>=0 group by project_id "
  87. rs := IC.BaseMysql.SelectBySql(fmt.Sprintf(query, argStr), value...)
  88. existProjectMap := map[string]string{}
  89. if rs != nil && len(*rs) > 0 { // 如果查到了 说明这个项目公司里面已经参标 处理一下信息用于后边判断是否是自己参标
  90. // 处理成map
  91. for i := 0; i < len(*rs); i++ {
  92. existId := common.ObjToString((*rs)[i]["project_id"])
  93. personIds := common.ObjToString((*rs)[i]["personIds"])
  94. existProjectMap[existId] = personIds
  95. }
  96. }
  97. return existProjectMap
  98. }
  99. // ListEntFormat 企业版 列表页数据格式化
  100. func (p *ParticipateBid) ListEntFormat(existProjectMap, infoM map[string]string, isAllow bool) []*bxcore.ShowInfo {
  101. // 处理成 要返回的返回数据
  102. var formatList []*bxcore.ShowInfo
  103. for k, v := range infoM {
  104. buttonValue := ButtonValueParticipate // 不存在时-显示参标
  105. if userIds, ok := existProjectMap[v]; ok { // 存在时 说明项目在企业下已经参标 需要进一步判断
  106. // 判断已经存在的参标人中是否包含自己 包含时 显示成已参标
  107. if ContainId(userIds, common.InterfaceToStr(p.EntUserId)) {
  108. buttonValue = ButtonValueParticipated
  109. } else if isAllow { // 不包含自己时需要 进一步判断公司设置是否允许多人参标
  110. // 允许时显示成 参标
  111. buttonValue = ButtonValueParticipate
  112. } else { // 不允许时 跳过该条信息
  113. continue
  114. }
  115. }
  116. formatList = append(formatList, &bxcore.ShowInfo{
  117. Id: encrypt.EncodeArticleId2ByCheck(k),
  118. Value: int64(buttonValue),
  119. })
  120. }
  121. return formatList
  122. }
  123. // DetailEntFormat 企业版 详情页数据格式化 返回数据 参标按钮 终止参标按钮 转给同事按钮 参标人姓名
  124. func (p *ParticipateBid) DetailEntFormat(existProjectMap map[string]string, isValid, isAllow bool) (formatData *bxcore.ParticipateDetailInfo) {
  125. // 处理成 要返回的返回数据
  126. formatData = &bxcore.ParticipateDetailInfo{}
  127. if len(existProjectMap) == 0 && isValid {
  128. // 无参标人 展示参标按钮 其余按钮不显示
  129. formatData.ShowParticipate = true
  130. return
  131. }
  132. persons := ""
  133. for _, v := range existProjectMap { // 这是为了取参标人id信息 列表页是多条数据 详情页这里 map里面只会有一条数据
  134. persons = v
  135. break
  136. }
  137. // 参标人信息 处理成姓名
  138. nameRs := GetNameByUserIds(persons)
  139. if nameRs != nil && len(*nameRs) > 0 {
  140. formatData.UserName = common.ObjToString((*nameRs)[0]["name"])
  141. }
  142. if !isValid {
  143. return
  144. }
  145. // 如果是管理员 显示 终止参标按钮、转给同事按钮
  146. if p.EntRoleId == RoleEntManager || p.EntRoleId == RoleDepartManager {
  147. formatData.ShowStopParticipate = true
  148. formatData.ShowTransfer = true
  149. }
  150. // 如果包含自己 显示终止参标按钮
  151. if ContainId(persons, common.InterfaceToStr(p.EntUserId)) {
  152. formatData.ShowStopParticipate = true
  153. } else if isAllow { // 如果允许多人 显示参标按钮
  154. formatData.ShowParticipate = true
  155. }
  156. return
  157. }
  158. // DetailPersonalFormat 详情页个人版 按钮格式化数据
  159. func (p *ParticipateBid) DetailPersonalFormat(existProjectSet map[string]struct{}, isValid bool) (formatData *bxcore.ParticipateDetailInfo) {
  160. // 处理成 要返回的返回数据
  161. formatData = &bxcore.ParticipateDetailInfo{}
  162. if !isValid {
  163. return
  164. }
  165. // 存在在说明已经参标 显示终止参标
  166. if len(existProjectSet) > 0 {
  167. formatData.ShowStopParticipate = true
  168. } else {
  169. // 不存在则说明 未参标 参标按钮展示
  170. formatData.ShowParticipate = true
  171. }
  172. return
  173. }
  174. // HandlerProjectId 返回信息的映射集合,项目id列表
  175. func HandlerProjectId(projectInfos []map[string]interface{}, infoIds map[string]struct{}) (map[string]string, []string) {
  176. result := map[string]string{}
  177. projectIdList := []string{}
  178. // 记录infoid 和项目id 对应关系 用于最后处理返回的数据
  179. for i := 0; i < len(projectInfos); i++ {
  180. _id := common.ObjToString(projectInfos[i]["_id"])
  181. projectIdList = append(projectIdList, _id)
  182. list, b := projectInfos[i]["list"].([]interface{})
  183. if !b {
  184. continue
  185. }
  186. for j := 0; j < len(list); j++ {
  187. infoidMap := common.ObjToMap(list[j])
  188. if infoidMap == nil {
  189. continue
  190. }
  191. infoid := common.ObjToString((*infoidMap)["infoid"])
  192. if _, ok := infoIds[infoid]; ok && infoid != "" {
  193. result[infoid] = _id
  194. break
  195. }
  196. }
  197. }
  198. return result, projectIdList
  199. }
  200. // DecodeId 解密标讯id 返回一个信息id的列表 和 集合
  201. func DecodeId(ids string) (result []string, resultSet map[string]struct{}) {
  202. idList := strings.Split(ids, ",")
  203. resultSet = map[string]struct{}{}
  204. for i := 0; i < len(idList); i++ {
  205. decodeArray := encrypt.DecodeArticleId2ByCheck(idList[i])
  206. if len(decodeArray) == 1 && decodeArray[0] != "" {
  207. result = append(result, decodeArray[0])
  208. resultSet[decodeArray[0]] = struct{}{}
  209. }
  210. }
  211. return
  212. }
  213. // ContainId 用于判断给定的逗号分割的字符串中是否包含 目标的字符串
  214. func ContainId(ids string, objId string) bool {
  215. list := strings.Split(ids, ",")
  216. for i := 0; i < len(list); i++ {
  217. if list[i] == objId {
  218. return true
  219. }
  220. }
  221. return false
  222. }
  223. // GetNameByUserIds 获取用户名字符串
  224. // 参数:逗号分割的用户id "11,22,333..."
  225. // 返回: "张三,李四,王五..."
  226. func GetNameByUserIds(ids string) *[]map[string]interface{} {
  227. query := "select group_concat(name) as name from " + TableEntnicheUser + " where id in (" + ids + ") "
  228. fmt.Println(query)
  229. rs := IC.MainMysql.SelectBySql(query)
  230. return rs
  231. }
  232. /*
  233. 投标状态更新
  234. 1. 验证参标人
  235. 2. 更新 存操作记录
  236. */
  237. // 更新投标状态
  238. func (p *ParticipateBid) updateBidStatus() {
  239. // 更新
  240. // 存操作记录
  241. }
  242. // 处理操作记录
  243. //var (
  244. // BidTypeKey = map[string]interface{}{
  245. //
  246. // }
  247. // ParticipateBidContentKey = map[string]interface{}{
  248. // "bidType":map[string]interface{}{
  249. // "name":"投标类型",
  250. // "updateAction":"调整",
  251. // "valueType":2,
  252. // "valueMap":map[int]interface{}{
  253. // BidTypeDirect:"直接投标",
  254. // BidTypeChanel:"渠道投标",
  255. // },
  256. // },
  257. // "isWin":map[string]interface{}{
  258. // "name":map[int]string{
  259. // 1:
  260. // },
  261. //
  262. // },
  263. // }
  264. //)