participateBid.go 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042
  1. package mysql
  2. import (
  3. MC "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/date"
  5. "app.yhyue.com/moapp/jybase/encrypt"
  6. "database/sql"
  7. "encoding/json"
  8. "fmt"
  9. IC "jyBXCore/rpc/init"
  10. "jyBXCore/rpc/model/es"
  11. "jyBXCore/rpc/type/bxcore"
  12. "log"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. // 投标状态更新内容
  18. type PartStatusContent struct {
  19. BidStage []string `json:"bidStage"` //投标项目阶段
  20. BidType int64 `json:"bidType"` //投标类型1:直接投标;2:渠道投标
  21. ChannelName string `json:"channelName"` //渠道名称
  22. ChannelPerson string `json:"channelPerson"` //联系人
  23. ChannelPhone string `json:"channelPhone"` //联系电话
  24. IsWin int64 `json:"isWin"` //渠道是否中标
  25. Winner string `json:"winner"` //中标单位
  26. }
  27. // 参标
  28. type RecordsContent struct {
  29. After PartStatusContent `json:"after"` //更新前
  30. Before PartStatusContent `json:"before"` //更新后
  31. ChangeField []string `json:"changeField"` //更新字段
  32. Content string `json:"content"` //更新内容
  33. }
  34. var (
  35. PartTable = "participate"
  36. ParticipateBidRecordsTable = "participate_bid_records"
  37. ParticipateUserTable = "participate_user" // 参标用户表
  38. EntnicheUserTable = "entniche_user" // 企业用户表
  39. )
  40. // 划转参标信息
  41. func TransferParticipateInfo(projectId string, in *bxcore.ParticipateActionReq) error {
  42. defer MC.Catch()
  43. //保存或更新新跟踪人
  44. if !IC.BaseMysql.ExecTx("划转参标信息", func(tx *sql.Tx) bool {
  45. var (
  46. b1 = true
  47. b2, b3 bool
  48. now = time.Now()
  49. content = "从%s名下划转给%s%s"
  50. lastNotes = ",保留原参标人"
  51. fromEntUserNames, toEntUserNames, toEntUserIds []string
  52. ids []int
  53. )
  54. partInfo := IC.BaseMysql.SelectBySqlByTx(tx, "SELECT id,position_id FROM "+ParticipateUserTable+" WHERE project_id = ? AND ent_id = ? AND state > -1", projectId, in.EntId)
  55. if partInfo == nil || len(*partInfo) == 0 {
  56. log.Println("当前项目不满足划转条件")
  57. return false
  58. } else {
  59. for _, v := range *partInfo {
  60. ids = append(ids, MC.IntAll(v["id"]))
  61. positionId := MC.Int64All(v["position_id"])
  62. userInfo := IC.Middleground.UserCenter.IdentityByPositionId(positionId)
  63. if userInfo.EntUserName != "" {
  64. fromEntUserNames = append(fromEntUserNames, userInfo.EntUserName)
  65. }
  66. }
  67. }
  68. if len(fromEntUserNames) == 0 {
  69. log.Println("原参标人信息查询有误")
  70. return false
  71. }
  72. //是否保留原参标人
  73. if !in.IsRetain {
  74. lastNotes = ""
  75. //不保留 原参标人,获取把原参标人信息
  76. //当前项目有参标人 更新参标人状态
  77. b1 = IC.BaseMysql.UpdateByTx(tx, ParticipateUserTable, map[string]interface{}{
  78. "ent_id": in.EntId,
  79. "project_id": projectId,
  80. }, map[string]interface{}{
  81. "state": -1,
  82. "mark": -2, //0:参标;1:被划入;-1:终止参标;-2:被划走
  83. "update_date": date.FormatDate(&now, date.Date_Full_Layout),
  84. })
  85. }
  86. //移动端 划转对象是多选
  87. //划转对象entuserid 解密
  88. for _, toEntUserId := range strings.Split(in.ToEntUserId, ",") {
  89. toEntUserId = encrypt.SE.Decode4HexByCheck(toEntUserId)
  90. if toEntUserId == "" {
  91. log.Println("划转对象不能为空", in.ProjectIds, in.EntId)
  92. continue
  93. }
  94. //查询划转人信息
  95. entUserId, _ := strconv.ParseInt(toEntUserId, 10, 64)
  96. userInfo := IC.Middleground.UserCenter.IdentityByEntUserId(entUserId)
  97. positionId := userInfo.PositionId
  98. //保存参标--participate_user
  99. //查看是否参标过当前项目
  100. if c := IC.BaseMysql.CountBySql("SELECT count(id) FROM "+ParticipateUserTable+" WHERE position_id = ? AND project_id = ? AND ent_id = ?", positionId, projectId, in.EntId); c > 0 {
  101. //更新
  102. b3 = IC.BaseMysql.UpdateByTx(tx, ParticipateUserTable, map[string]interface{}{
  103. "position_id": positionId,
  104. "project_id": projectId,
  105. "ent_id": in.EntId,
  106. }, map[string]interface{}{
  107. "state": 0,
  108. "mark": 1, //0:参标;1:被划入;-1:终止参标;-2:被划走
  109. "update_date": date.FormatDate(&now, date.Date_Full_Layout),
  110. })
  111. } else {
  112. //保存
  113. b3 = IC.BaseMysql.InsertByTx(tx, ParticipateUserTable, map[string]interface{}{
  114. "ent_id": in.EntId,
  115. "ent_user_id": entUserId,
  116. "position_id": positionId,
  117. "project_id": projectId,
  118. "user_id": in.MgoUserId,
  119. "state": 0,
  120. "mark": 1, //0:参标;1:被划入;-1:终止参标;-2:被划走
  121. "create_date": date.FormatDate(&now, date.Date_Full_Layout),
  122. "update_date": date.FormatDate(&now, date.Date_Full_Layout),
  123. }) > 0
  124. }
  125. if b3 {
  126. toEntUserIds = append(toEntUserIds, toEntUserId)
  127. toEntUserNames = append(toEntUserNames, userInfo.EntUserName)
  128. }
  129. }
  130. //保存多个用户时 如果个别用户划转参标项目异常,直接跳过此用户,保存其他用户信息
  131. //防止最后一个用户保存异常
  132. if len(toEntUserIds) > 0 {
  133. b3 = true
  134. }
  135. //移动端单个项目划转给多个用户,划转记录保存一份,当前企业下参过标的或当前正在参标的人都能看到次记录
  136. //企业下 根据企业id 和项目id查询划转记录
  137. //个人版 根据职位id 和项目id查询划转记录
  138. //划转记录
  139. b2 = IC.BaseMysql.InsertByTx(tx, ParticipateBidRecordsTable, map[string]interface{}{
  140. "ent_id": in.EntId,
  141. "ent_user_id": in.EntUserId,
  142. "position_id": in.PositionId,
  143. "project_id": projectId,
  144. "record_type": 0,
  145. "transfer_ent_user_id": strings.Join(toEntUserIds, ","),
  146. "record_content": fmt.Sprintf(content, strings.Join(fromEntUserNames, "、"), strings.Join(toEntUserNames, "、"), lastNotes),
  147. "create_date": date.FormatDate(&now, date.Date_Full_Layout),
  148. }) > 0
  149. log.Println(b1, "--", b2, "--", b3)
  150. return b1 && b2 && b3
  151. }) {
  152. log.Println(in.PositionId, "---终止---", projectId)
  153. return fmt.Errorf("终止参标更新信息出错")
  154. }
  155. return nil
  156. }
  157. // 终止参标
  158. func CancelParticipateInfo(in *bxcore.ParticipateActionReq, roleId int64) error {
  159. defer MC.Catch()
  160. if !IC.BaseMysql.ExecTx("终止参标", func(tx *sql.Tx) bool {
  161. var (
  162. b1, b2 bool
  163. now = time.Now()
  164. tip = "终止参标"
  165. )
  166. //管理员终止:当前项目 其他参标人也被终止
  167. query := map[string]interface{}{
  168. "project_id": in.ProjectIds,
  169. "ent_id": in.EntId,
  170. }
  171. //个人终止:仅仅终止本人参标项目
  172. if roleId == 0 {
  173. query["position_id"] = in.PositionId
  174. tip = "终止参标"
  175. }
  176. insert := map[string]interface{}{
  177. "state": -1,
  178. "mark": -1, //0:参标;1:被划入;-1:终止参标;-2:被划走
  179. "update_date": date.FormatDate(&now, date.Date_Full_Layout),
  180. }
  181. //更新参标participate_user
  182. b1 = IC.BaseMysql.UpdateByTx(tx, ParticipateUserTable, query, insert)
  183. //保存参标记录--participate_bid_records
  184. b2 = IC.BaseMysql.InsertByTx(tx, ParticipateBidRecordsTable, map[string]interface{}{
  185. "ent_id": in.EntId,
  186. "ent_user_id": in.EntUserId,
  187. "position_id": in.PositionId,
  188. "project_id": in.ProjectIds,
  189. "record_type": 0,
  190. "record_content": tip,
  191. "create_date": date.FormatDate(&now, date.Date_Full_Layout),
  192. }) > 0
  193. return b1 && b2
  194. }) {
  195. log.Println(in.PositionId, "---终止---", in.ProjectIds)
  196. return fmt.Errorf("终止参标更新信息出错")
  197. }
  198. return nil
  199. }
  200. // 保存参标信息
  201. func SaveParticipateInfo(in *bxcore.ParticipateActionReq) error {
  202. defer MC.Catch()
  203. if !IC.BaseMysql.ExecTx("保存|更新参标信息及保存参标记录", func(tx *sql.Tx) bool {
  204. var (
  205. b1, b2, b3 bool
  206. now = time.Now()
  207. )
  208. //保存参标--participate_user
  209. //查看是否参标过当前项目
  210. if c := IC.BaseMysql.CountBySql("SELECT count(id) FROM "+ParticipateUserTable+" WHERE position_id = ? AND project_id = ? AND ent_id = ?", in.PositionId, in.ProjectIds, in.EntId); c > 0 {
  211. //更新
  212. b1 = IC.BaseMysql.UpdateByTx(tx, ParticipateUserTable, map[string]interface{}{
  213. "position_id": in.PositionId,
  214. "ent_id": in.EntId,
  215. "project_id": in.ProjectIds,
  216. }, map[string]interface{}{
  217. "state": 0,
  218. "mark": 0,
  219. "update_date": date.FormatDate(&now, date.Date_Full_Layout),
  220. })
  221. } else {
  222. //保存
  223. b1 = IC.BaseMysql.InsertByTx(tx, ParticipateUserTable, map[string]interface{}{
  224. "ent_id": in.EntId,
  225. "ent_user_id": in.EntUserId,
  226. "position_id": in.PositionId,
  227. "project_id": in.ProjectIds,
  228. "user_id": in.MgoUserId,
  229. "state": 0,
  230. "mark": 0,
  231. "create_date": date.FormatDate(&now, date.Date_Full_Layout),
  232. "update_date": date.FormatDate(&now, date.Date_Full_Layout),
  233. }) > 0
  234. }
  235. if !b1 {
  236. return false
  237. }
  238. //保存参标记录participate_bid_records
  239. b2 = IC.BaseMysql.InsertByTx(tx, ParticipateBidRecordsTable, map[string]interface{}{
  240. "ent_id": in.EntId,
  241. "ent_user_id": in.EntUserId,
  242. "position_id": in.PositionId,
  243. "project_id": in.ProjectIds,
  244. "record_type": 0,
  245. "record_content": "参标",
  246. "create_date": date.FormatDate(&now, date.Date_Full_Layout),
  247. }) > 0
  248. if !b2 {
  249. return false
  250. }
  251. //保存或更新项目信息
  252. //有问题 其他回滚,项目信息不用回滚
  253. b3 = UpdateProjectInfo(in.ProjectIds, es.GetProjectInfo(in.ProjectIds)) == nil
  254. return b1 && b2 && b3
  255. }) {
  256. log.Println(in.PositionId, "---保存---", in.ProjectIds)
  257. return fmt.Errorf("保存参标信息出错")
  258. }
  259. return nil
  260. }
  261. // 查询当前招标信息是否已被参标
  262. func IsParticipatedByBidId(in *bxcore.ParticipateActionReq) (entUserName string) {
  263. defer MC.Catch()
  264. //如果不允许多人参标 当前项目是否已经有企业其他人员参标
  265. query := fmt.Sprintf(`SELECT ent_id,ent_user_id FROM `+ParticipateUserTable+` WHERE %s AND project_id = '%s' AND state >-1`, "%s", in.ProjectIds)
  266. if in.PositionType > 0 { //企业版
  267. query = fmt.Sprintf(query, fmt.Sprintf("ent_id = %d", in.EntId))
  268. } else { //个人版
  269. query = fmt.Sprintf(query, fmt.Sprintf("position_id = %d", in.PositionId))
  270. }
  271. data := IC.BaseMysql.SelectBySql(query)
  272. if data != nil && len(*data) > 0 {
  273. partInfo := (*data)[0]
  274. if entUserId := MC.Int64All(partInfo["ent_user_id"]); entUserId > 0 {
  275. userInfo := IC.Middleground.UserCenter.IdentityByEntUserId(entUserId)
  276. entUserName = userInfo.EntUserName
  277. }
  278. }
  279. return
  280. }
  281. // 获取参标权限
  282. func GetParticipateIsAllow(query map[string]interface{}) (b bool) {
  283. defer MC.Catch()
  284. if info, ok := IC.Mgo.FindOne(PartTable, query); ok {
  285. if info != nil {
  286. if (*info)["i_isallow"] != nil {
  287. b = MC.IntAll((*info)["i_isallow"]) > 0
  288. }
  289. }
  290. }
  291. return
  292. }
  293. // 更新设置信息
  294. func UpdateParticipateSetInfo(in *bxcore.ParticipateSetUpInfoReq) error {
  295. defer MC.Catch()
  296. query := map[string]interface{}{
  297. "i_positionid": in.PositionId,
  298. }
  299. if in.PositionType > 0 {
  300. query = map[string]interface{}{
  301. "i_entid": in.EntId,
  302. }
  303. }
  304. upsert := map[string]interface{}{
  305. "i_entid": in.EntId,
  306. "i_entuserid": in.EntUserId,
  307. "i_positionid": in.PositionId,
  308. "l_createtime": time.Now().Unix(),
  309. }
  310. if in.IsAllow != "" {
  311. if in.IsAllow == "0" { //修改为允许单人参标
  312. //判断是否有多人参标的项目
  313. //pSql := `SELECT project_id,COUNT(id) AS c FROM ` + ParticipateUserTable + ` WHERE ent_id = ? AND state =0 GROUP BY project_id ORDER BY c DESC;`
  314. pSql := `SELECT pu.project_id,COUNT(pu.id) AS c,p.bid_end_time,p.bid_open_time FROM ` + ParticipateUserTable + ` pu LEFT JOIN project p ON pu.project_id = p.id WHERE pu.ent_id = ? AND pu.state =0 AND ((p.bid_open_time > ? or p.bid_open_time is null) and (p.bid_end_time IS NULL or p.bid_end_time > ?)) GROUP BY pu.project_id ORDER BY c DESC`
  315. data := IC.BaseMysql.SelectBySql(pSql, in.EntId, time.Now().Format(date.Date_Full_Layout), time.Now().Format(date.Date_Full_Layout))
  316. if data != nil && len(*data) > 0 {
  317. if max := MC.IntAll((*data)[0]["c"]); max > 1 {
  318. return fmt.Errorf("公司当前有项目多人参标的情况,请先确保项目都是单人参标的前提下再调整配置。\n前往”企业参标项目列表“查看具体情况。")
  319. }
  320. }
  321. }
  322. isAllow, _ := strconv.Atoi(in.IsAllow)
  323. upsert["i_isallow"] = isAllow
  324. }
  325. if len(in.BidType) > 0 {
  326. upsert["o_bidtype"] = in.BidType
  327. }
  328. if len(in.RemindRule) > 0 {
  329. upsert["o_remindrule"] = in.RemindRule
  330. }
  331. if in.NecessaryField != "" {
  332. upsert["s_requiredField"] = in.NecessaryField
  333. }
  334. if ok := IC.Mgo.Update(PartTable, query, map[string]interface{}{
  335. "$set": upsert,
  336. }, true, false); ok {
  337. return nil
  338. }
  339. return fmt.Errorf("更新失败")
  340. }
  341. // 查询企业|个人参标设置信息
  342. func GetParticipateSetInfo(in *bxcore.ParticipateSetUpInfoReq) (*bxcore.ParticipateSetUpInfo, error) {
  343. defer MC.Catch()
  344. query := map[string]interface{}{
  345. "i_positionid": in.PositionId,
  346. }
  347. if in.PositionType > 0 {
  348. query = map[string]interface{}{
  349. "i_entid": in.EntId,
  350. }
  351. }
  352. if setInfo, ok := IC.Mgo.FindOne(PartTable, query); ok {
  353. var (
  354. isAllow int64
  355. isRequired string
  356. bidType []*bxcore.BidTypeReq
  357. remindRule []*bxcore.RemindRuleReq
  358. )
  359. bidType = append(bidType, &bxcore.BidTypeReq{
  360. Name: "直接投标",
  361. Content: []string{"未报名", "已报名", "投标决策", "编制投标文件", "递交投标文件", "中标公示", "签合同", "已结束"},
  362. }, &bxcore.BidTypeReq{
  363. Name: "渠道投标",
  364. Content: []string{"已报名", "签合同", "已结束"},
  365. })
  366. remindRule = append(remindRule, &bxcore.RemindRuleReq{
  367. BidState: "直接投标",
  368. Remainder: 72,
  369. Node: "编制投标文件",
  370. })
  371. if setInfo != nil {
  372. //必填字段
  373. if (*setInfo)["s_requiredField"] != nil {
  374. isRequired = MC.ObjToString((*setInfo)["s_requiredField"])
  375. } else {
  376. isRequired = "bidType"
  377. }
  378. isAllow = MC.Int64All((*setInfo)["i_isallow"])
  379. if (*setInfo)["o_bidtype"] != nil {
  380. if sbb, err := json.Marshal((*setInfo)["o_bidtype"]); err == nil {
  381. if err := json.Unmarshal(sbb, &bidType); err != nil {
  382. log.Println("bidType json un err:", err.Error())
  383. return nil, err
  384. }
  385. } else {
  386. log.Println("bidType json err:", err.Error())
  387. return nil, err
  388. }
  389. }
  390. if (*setInfo)["o_remindrule"] != nil {
  391. if sbr, err := json.Marshal((*setInfo)["o_remindrule"]); err == nil {
  392. if err := json.Unmarshal(sbr, &remindRule); err != nil {
  393. log.Println("remindRule json un err:", err.Error())
  394. return nil, err
  395. }
  396. } else {
  397. log.Println("remindRule json err:", err.Error())
  398. return nil, err
  399. }
  400. }
  401. }
  402. return &bxcore.ParticipateSetUpInfo{
  403. NecessaryField: isRequired,
  404. IsAllow: isAllow,
  405. BidType: bidType,
  406. RemindRule: remindRule,
  407. }, nil
  408. }
  409. return nil, nil
  410. }
  411. // 保存或更新tidb 项目信息
  412. func UpdateProjectInfo(id string, pInfo map[string]interface{}) error {
  413. //id 项目id
  414. //name 项目名称
  415. //area 省份
  416. //city 城市
  417. //buyer 采购单位
  418. //budget 预算
  419. //bid_open_time 开标时间
  420. //zbtime 招标时间
  421. //bid_end_time 开标结束时间 bidding表 由 数据组 重新生索引到project表
  422. //pici 批次 轮询更新数据
  423. //
  424. projectInfo := map[string]interface{}{
  425. "id": id,
  426. "name": MC.ObjToString(pInfo["projectname"]),
  427. "area": MC.ObjToString(pInfo["area"]),
  428. "city": MC.ObjToString(pInfo["city"]),
  429. "buyer": MC.ObjToString(pInfo["buyer"]),
  430. "budget": MC.Int64All(pInfo["budget"]),
  431. }
  432. if pInfo["bidopentime"] != nil {
  433. openTime := pInfo["bidopentime"]
  434. projectInfo["bid_open_time"] = date.FormatDateWithObj(&openTime, date.Date_Full_Layout)
  435. }
  436. if pInfo["pici"] != nil {
  437. pici := pInfo["pici"]
  438. projectInfo["pici"] = date.FormatDateWithObj(&pici, date.Date_Full_Layout)
  439. }
  440. // 项目表:zbtime 招标时间是 biding表:publishtime发布时间
  441. if pInfo["zbtime"] != nil {
  442. bidTime := pInfo["zbtime"]
  443. projectInfo["bid_time"] = date.FormatDateWithObj(&bidTime, date.Date_Full_Layout)
  444. }
  445. if pInfo["bidendtime"] != nil {
  446. bidEndTime := pInfo["bidendtime"]
  447. projectInfo["bid_end_time"] = date.FormatDateWithObj(&bidEndTime, date.Date_Full_Layout)
  448. }
  449. if c := IC.BaseMysql.CountBySql(`SELECT COUNT(id) FROM project WHERE id = ?`, id); c > 0 {
  450. if ok := IC.BaseMysql.Update("project", map[string]interface{}{
  451. "id": id,
  452. }, projectInfo); !ok {
  453. return fmt.Errorf("项目信息更新异常", id)
  454. }
  455. } else {
  456. if i := IC.BaseMysql.Insert("project", projectInfo); i < 0 {
  457. return fmt.Errorf("项目信息插入异常", id)
  458. }
  459. }
  460. return nil
  461. }
  462. // 参标列表其他条件
  463. func ParticipateListSql(in *bxcore.ParticipateListReq) string {
  464. //b project表
  465. //a participate_user表
  466. now := time.Now()
  467. nowDate := date.FormatDate(&now, date.Date_Full_Layout)
  468. //查询tidb base_service.project
  469. conditionSql := ` `
  470. //地区
  471. if in.Area != "" {
  472. conditionSql += fmt.Sprintf(" AND pt.area IN ('%s') ", strings.ReplaceAll(in.Area, ",", "','"))
  473. }
  474. //城市
  475. if in.City != "" {
  476. conditionSql += fmt.Sprintf(" AND pt.city IN ('%s') ", strings.ReplaceAll(in.City, ",", "','"))
  477. }
  478. //关键词
  479. if in.Keywords != "" {
  480. kSql := ` AND (`
  481. for kk, kv := range strings.Split(in.Keywords, " ") {
  482. log.Println(kk, "----", kv)
  483. if kk > 0 {
  484. kSql += " OR "
  485. }
  486. kSql += " pt.name like '%" + kv + "%'"
  487. }
  488. kSql += `)`
  489. conditionSql += kSql
  490. }
  491. //招标日期
  492. if in.BidTime != "" && strings.Contains(in.BidTime, "-") {
  493. startTime := strings.Split(in.BidTime, "-")[0]
  494. entTime := strings.Split(in.BidTime, "-")[1]
  495. if startTime != "" {
  496. startTimeInt, _ := strconv.ParseInt(startTime, 10, 64)
  497. conditionSql += ` AND pt.bid_time > '` + date.FormatDateByInt64(&startTimeInt, date.Date_Full_Layout) + `'`
  498. }
  499. if entTime != "" {
  500. entTimeInt, _ := strconv.ParseInt(entTime, 10, 64)
  501. conditionSql += ` AND pt.bid_time < '` + date.FormatDateByInt64(&entTimeInt, date.Date_Full_Layout) + `'`
  502. }
  503. }
  504. //招标截止日期
  505. if in.BidEndTime != "" {
  506. //投标截止日期规则:
  507. //1、开始时间小于当前时间 ,结束时间大于当前时间,投标截止状态按钮未截止和已截止可用;
  508. //2、结束时间小于当前时间|开始时间大于当前时间,投标截止状态按钮未截止和已截止不可用;
  509. //3、需要前端做成连动
  510. startTime := strings.Split(in.BidEndTime, "-")[0]
  511. endTime := strings.Split(in.BidEndTime, "-")[1]
  512. startTimeInt, _ := strconv.ParseInt(startTime, 10, 64)
  513. endTimeInt, _ := strconv.ParseInt(endTime, 10, 64)
  514. bidEndTimeSql := ``
  515. if startTimeInt > 0 && endTimeInt > 0 && startTimeInt > endTimeInt {
  516. log.Println(fmt.Sprintf("投标截止日期 %d 开始时间 大于 结束时间%d!!!", startTimeInt, endTimeInt))
  517. } else {
  518. if startTimeInt > 0 {
  519. bidEndTimeSql += ` AND pt.bid_end_time > '` + date.FormatDateByInt64(&startTimeInt, date.Date_Full_Layout) + `'`
  520. }
  521. if endTimeInt > 0 {
  522. bidEndTimeSql += ` AND pt.bid_end_time < '` + date.FormatDateByInt64(&endTimeInt, date.Date_Full_Layout) + `'`
  523. }
  524. switch in.BidEndStatus {
  525. case 1: //投标截止状态:1:未截止;2:已截止;3:终止参标
  526. bidEndTimeSql = ``
  527. //未截止:
  528. var (
  529. endBool = true
  530. )
  531. //如果结束时间存在且小于当前时间,投标截止日期 范围都是已截止 不会存在未截止的数据
  532. if endTimeInt > 0 {
  533. bidEndTimeSql += ` AND pt.bid_end_time < '` + date.FormatDateByInt64(&endTimeInt, date.Date_Full_Layout) + `'`
  534. endBool = endTimeInt > now.Unix()
  535. }
  536. //开始时间小于 当前时间
  537. if endBool && now.Unix() > startTimeInt {
  538. startTimeInt = now.Unix()
  539. }
  540. //存在开始时间为0的情况
  541. if startTimeInt > 0 {
  542. bidEndTimeSql += ` AND pt.bid_end_time > '` + date.FormatDateByInt64(&startTimeInt, date.Date_Full_Layout) + `'`
  543. }
  544. case 2: //投标截止状态:1:未截止;2:已截止;3:终止参标
  545. //如果开始时间存在且大于当前时间,投标截止日期 范围都是未截止 不会存在已截止的数据
  546. var (
  547. startBool = true
  548. )
  549. bidEndTimeSql = ``
  550. if startTimeInt > 0 {
  551. bidEndTimeSql += ` AND pt.bid_end_time > '` + date.FormatDateByInt64(&startTimeInt, date.Date_Full_Layout) + `'`
  552. startBool = startTimeInt < now.Unix()
  553. }
  554. if startBool && (endTimeInt == 0 || now.Unix() < endTimeInt) {
  555. endTimeInt = now.Unix()
  556. }
  557. //存在结束时间为0的情况
  558. if endTimeInt > 0 {
  559. bidEndTimeSql += ` AND pt.bid_end_time < '` + date.FormatDateByInt64(&endTimeInt, date.Date_Full_Layout) + `'`
  560. }
  561. case 3:
  562. bidEndTimeSql += ` AND pug.state < 0 `
  563. }
  564. }
  565. if bidEndTimeSql != "" {
  566. conditionSql += bidEndTimeSql
  567. }
  568. } else if in.BidEndStatus > 0 { //投标截止状态1:未截止;2:已截止;3:终止参标
  569. switch in.BidEndStatus {
  570. case 1:
  571. conditionSql += ` AND pt.bid_end_time > '` + nowDate + `'`
  572. case 2:
  573. conditionSql += ` AND pt.bid_end_time < '` + nowDate + `'`
  574. case 3:
  575. conditionSql += ` AND pug.state < 0 `
  576. }
  577. }
  578. //开标时间
  579. if in.BidOpenTime != "" {
  580. startTime := strings.Split(in.BidOpenTime, "-")[0]
  581. entTime := strings.Split(in.BidOpenTime, "-")[1]
  582. if startTime != "" {
  583. startTimeInt, _ := strconv.ParseInt(startTime, 10, 64)
  584. conditionSql += ` AND pt.bid_open_time > '` + date.FormatDateByInt64(&startTimeInt, date.Date_Full_Layout) + `'`
  585. }
  586. if entTime != "" {
  587. entTimeInt, _ := strconv.ParseInt(entTime, 10, 64)
  588. conditionSql += ` AND pt.bid_open_time < '` + date.FormatDateByInt64(&entTimeInt, date.Date_Full_Layout) + `'`
  589. }
  590. }
  591. //开标状态1:未开标;2:已开标
  592. if in.BidOpenStatus > 0 {
  593. switch in.BidOpenStatus {
  594. case 1:
  595. conditionSql += ` AND pt.bid_open_time > '` + nowDate + `'`
  596. case 2:
  597. conditionSql += ` AND pt.bid_open_time < '` + nowDate + `'`
  598. }
  599. }
  600. //参标人 管理员权限
  601. if in.EntUserIds != "" && in.PositionType > 0 {
  602. var entUserIdsSql = ""
  603. for k, v := range strings.Split(in.EntUserIds, ",") {
  604. v = encrypt.SE.Decode4HexByCheck(v)
  605. if v == "" {
  606. continue
  607. }
  608. if k > 0 && entUserIdsSql != "" {
  609. entUserIdsSql += " OR "
  610. }
  611. entUserIdsSql += ` FIND_IN_SET(` + v + ` , pug.ent_user_id) `
  612. }
  613. if entUserIdsSql != "" {
  614. conditionSql += ` AND (` + entUserIdsSql + `)`
  615. }
  616. }
  617. //默认按照投标截止日期正序排列、1:开标时间正序、2:更新状态时间倒序
  618. //投标结束时间和开标时间 很多项目数据没有这两个字段值
  619. switch in.OrderNum {
  620. case 1:
  621. conditionSql += ` ORDER BY (pt.bid_open_time IS NULL),pt.bid_open_time ASC,(pt.bid_end_time IS NULL),pt.bid_end_time ASC,pbr.create_date DESC`
  622. case 2:
  623. conditionSql += ` ORDER BY pbr.create_date DESC`
  624. default:
  625. conditionSql += ` ORDER BY (pt.bid_end_time IS NULL),pt.bid_end_time ASC,(pt.bid_open_time IS NULL),pt.bid_open_time ASC,pbr.create_date DESC`
  626. }
  627. log.Println(conditionSql)
  628. return conditionSql
  629. }
  630. // 个人或员工查询参标列表
  631. func SingleParticipateList(in *bxcore.ParticipateListReq, conditionSql string) (data *bxcore.ParticipateData, err error) {
  632. defer MC.Catch()
  633. data = &bxcore.ParticipateData{
  634. NowTime: time.Now().Unix(),
  635. Count: 0,
  636. List: []*bxcore.ParticipateList{},
  637. }
  638. //员工|个人列表
  639. singlePersonSql := `SELECT %s FROM ` + ParticipateUserTable + ` pug LEFT JOIN project pt ON pug.project_id = pt.id LEFT JOIN (SELECT project_id,position_id,MAX(create_date) AS create_date FROM participate_bid_records GROUP BY project_id,position_id) pbr ON pbr.project_id = pug.project_id AND pbr.position_id = pug.position_id WHERE pug.position_id = ? `
  640. //singlePersonSql += conditionSql
  641. countSql := fmt.Sprintf(singlePersonSql, " COUNT(pt.id) ") + conditionSql
  642. count := IC.BaseMysql.CountBySql(countSql, in.PositionId)
  643. log.Println(countSql, "---", count)
  644. if count > 0 {
  645. data.Count = count
  646. listSql := fmt.Sprintf(singlePersonSql, " pt.*,pbr.create_date,pug.state ") + conditionSql
  647. //分页
  648. listSql += fmt.Sprintf(` LIMIT %d,%d`, in.PageNum, in.PageSize)
  649. log.Println("listSql:", listSql)
  650. list := IC.BaseMysql.SelectBySql(listSql, in.PositionId)
  651. if list != nil && len(*list) > 0 {
  652. for _, v := range *list {
  653. bidTimeStr := MC.ObjToString(v["bid_time"])
  654. bidEndTimeStr := MC.ObjToString(v["bid_end_time"])
  655. bidOpenTimeStr := MC.ObjToString(v["bid_open_time"])
  656. updateStatusTimeStr := MC.ObjToString(v["create_date"])
  657. beTransferred := true
  658. //已终止参标
  659. stateInt64 := MC.Int64All(v["state"])
  660. if stateInt64 < 0 {
  661. beTransferred = false
  662. }
  663. var bidTime, bidEndTime, bidOpenTime, updateStatusTime int64
  664. if bidTimeStr != "" {
  665. bidTime_, _ := time.ParseInLocation(date.Date_Full_Layout, bidTimeStr, time.Local)
  666. bidTime = bidTime_.Unix()
  667. }
  668. if bidEndTimeStr != "" {
  669. bidEndTime_, _ := time.ParseInLocation(date.Date_Full_Layout, bidEndTimeStr, time.Local)
  670. bidEndTime = bidEndTime_.Unix()
  671. //招标结束时间小于当前时间
  672. if beTransferred && bidEndTime > 0 && bidEndTime < time.Now().Unix() {
  673. beTransferred = false
  674. }
  675. }
  676. if bidOpenTimeStr != "" {
  677. bidOpenTime_, _ := time.ParseInLocation(date.Date_Full_Layout, bidOpenTimeStr, time.Local)
  678. bidOpenTime = bidOpenTime_.Unix()
  679. //招标开始时间小于当前时间
  680. if beTransferred && bidOpenTime > 0 && bidOpenTime < time.Now().Unix() {
  681. beTransferred = false
  682. }
  683. }
  684. if updateStatusTimeStr != "" {
  685. updateStatusTime_, _ := time.ParseInLocation(date.Date_Full_Layout, updateStatusTimeStr, time.Local)
  686. updateStatusTime = updateStatusTime_.Unix()
  687. }
  688. data.List = append(data.List, &bxcore.ParticipateList{
  689. Id: encrypt.EncodeArticleId2ByCheck(MC.ObjToString(v["id"])),
  690. ProjectName: MC.ObjToString(v["name"]),
  691. Buyer: MC.ObjToString(v["buyer"]),
  692. Budget: MC.ObjToString(v["budget"]),
  693. BidTime: bidTime,
  694. BidEndTime: bidEndTime,
  695. BidOpenTime: bidOpenTime,
  696. UpdateStatusTime: updateStatusTime,
  697. State: stateInt64,
  698. BeTransferred: beTransferred, //是否能划转
  699. //UpdateStatusCon: GetParticipateContent("s", in.PositionId, MC.ObjToString(v["id"])), //查询最后一次 投标状态更新,
  700. })
  701. }
  702. return data, nil
  703. }
  704. return nil, fmt.Errorf("数据异常")
  705. }
  706. return data, nil
  707. }
  708. // 管理员获取参标列表数据
  709. func AdminParticipateList(in *bxcore.ParticipateListReq, conditionSql string) (data *bxcore.ParticipateData, err error) {
  710. defer MC.Catch()
  711. data = &bxcore.ParticipateData{
  712. IsAllow: IsALLow(in.EntId),
  713. NowTime: time.Now().Unix(),
  714. Count: 0,
  715. List: []*bxcore.ParticipateList{},
  716. }
  717. adminSql := `SELECT %s FROM (SELECT pu.ent_id, pu.project_id, GROUP_CONCAT(pu.ent_user_id SEPARATOR ',') ent_user_id,MAX(pu.state) state FROM ` + ParticipateUserTable + ` pu WHERE pu.ent_id = ? AND NOT EXISTS ( SELECT 1 FROM ` + ParticipateUserTable + ` ppu WHERE ppu.project_id = pu.project_id AND ppu.ent_id = pu.ent_id AND ppu.state > pu.state ) GROUP BY pu.project_id ) pug LEFT JOIN project pt ON pug.project_id = pt.id LEFT JOIN (SELECT project_id,ent_id,MAX(create_date) AS create_date FROM participate_bid_records GROUP BY project_id,ent_id) pbr ON pbr.project_id = pug.project_id AND pbr.ent_id = pug.ent_id WHERE 1=1 `
  718. //maxStateSql := ``
  719. //stateSql := ``
  720. //if in.EntUserIds == "" {
  721. // //maxStateSql = `,MAX(pu.state) state`
  722. // stateSql = ``
  723. //}
  724. //adminSql = fmt.Sprintf(adminSql, "%s", stateSql)
  725. adminCountSql := fmt.Sprintf(adminSql, "COUNT(pt.id)") + conditionSql
  726. log.Println(adminCountSql)
  727. count := IC.BaseMysql.CountBySql(adminCountSql, in.EntId)
  728. if count > 0 {
  729. data.Count = count
  730. adminListSql := fmt.Sprintf(adminSql, " pt.*, pug.ent_user_id,pbr.create_date,pug.state ") + conditionSql + fmt.Sprintf(" LIMIT %d,%d", in.PageNum, in.PageSize)
  731. list := IC.BaseMysql.SelectBySql(adminListSql, in.EntId)
  732. if list != nil && len(*list) > 0 {
  733. for _, v := range *list {
  734. bidTimeStr := MC.ObjToString(v["bid_time"])
  735. bidEndTimeStr := MC.ObjToString(v["bid_end_time"])
  736. bidOpenTimeStr := MC.ObjToString(v["bid_open_time"])
  737. updateStatusTimeStr := MC.ObjToString(v["create_date"])
  738. beTransferred := true
  739. //已终止参标
  740. stateInt64 := MC.Int64All(v["state"])
  741. if stateInt64 < 0 {
  742. beTransferred = false
  743. }
  744. var bidTime, bidEndTime, bidOpenTime, updateStatusTime int64
  745. if bidTimeStr != "" {
  746. bidTime_, _ := time.ParseInLocation(date.Date_Full_Layout, bidTimeStr, time.Local)
  747. bidTime = bidTime_.Unix()
  748. }
  749. if bidEndTimeStr != "" {
  750. bidEndTime_, _ := time.ParseInLocation(date.Date_Full_Layout, bidEndTimeStr, time.Local)
  751. bidEndTime = bidEndTime_.Unix()
  752. //招标结束时间小于当前时间
  753. if beTransferred && bidEndTime > 0 && bidEndTime < time.Now().Unix() {
  754. beTransferred = false
  755. }
  756. }
  757. if bidOpenTimeStr != "" {
  758. bidOpenTime_, _ := time.ParseInLocation(date.Date_Full_Layout, bidOpenTimeStr, time.Local)
  759. bidOpenTime = bidOpenTime_.Unix()
  760. //招标开始时间小于当前时间
  761. if beTransferred && bidOpenTime > 0 && bidOpenTime < time.Now().Unix() {
  762. beTransferred = false
  763. }
  764. }
  765. if updateStatusTimeStr != "" {
  766. updateStatusTime_, _ := time.ParseInLocation(date.Date_Full_Layout, updateStatusTimeStr, time.Local)
  767. updateStatusTime = updateStatusTime_.Unix()
  768. }
  769. data.List = append(data.List, &bxcore.ParticipateList{
  770. Id: encrypt.EncodeArticleId2ByCheck(MC.ObjToString(v["id"])),
  771. ProjectName: MC.ObjToString(v["name"]),
  772. Buyer: MC.ObjToString(v["buyer"]),
  773. Budget: MC.ObjToString(v["budget"]),
  774. BidTime: bidTime,
  775. BidEndTime: bidEndTime,
  776. BidOpenTime: bidOpenTime,
  777. UpdateStatusTime: updateStatusTime,
  778. State: stateInt64,
  779. BeTransferred: beTransferred, //是否能划转
  780. //UpdateStatusCon: GetParticipateContent("e", in.EntId, MC.ObjToString(v["id"])), //查询最后一次 投标状态更新
  781. Participants: GetParticipateUserName(MC.ObjToString(v["id"]), MC.ObjToString(v["ent_user_id"]), in.EntUserIds != ""), //参标人信息
  782. })
  783. }
  784. return data, nil
  785. }
  786. return nil, fmt.Errorf("数据异常")
  787. }
  788. return data, nil
  789. }
  790. // 获取最新参标 更新内容
  791. func GetParticipateContent(s string, id int64, projectId string) string {
  792. identitySql := `ent_id = ?`
  793. if s == "s" {
  794. identitySql = `position_id = ?`
  795. }
  796. recordsSql := `SELECT record_content,record_type FROM ` + ParticipateBidRecordsTable + ` WHERE ` + identitySql + ` AND project_id = ? ORDER BY create_date DESC LIMIT 1;`
  797. records := IC.BaseMysql.SelectBySql(recordsSql, id, projectId)
  798. if records != nil && len(*records) > 0 {
  799. rec := (*records)[0]
  800. switch MC.IntAll(rec["record_type"]) {
  801. case 0:
  802. return MC.ObjToString(rec["record_content"])
  803. case 1:
  804. recordContent := *MC.ObjToMap(rec["record_content"])
  805. rb, err := json.Marshal(recordContent)
  806. if err != nil {
  807. log.Println(err.Error())
  808. return ""
  809. }
  810. var rc = RecordsContent{
  811. After: PartStatusContent{},
  812. Before: PartStatusContent{},
  813. }
  814. err1 := json.Unmarshal(rb, &rc)
  815. if err1 == nil {
  816. return rc.Content
  817. }
  818. }
  819. }
  820. return ""
  821. }
  822. // 根据ent_user_id 获取参标人昵称,企业管理员现在都是“我”
  823. func GetParticipateUserName(projectId, entUserIdsFromData string, b bool) string {
  824. if entUserIdsFromData != "" {
  825. var userNames []string
  826. for _, v := range strings.Split(entUserIdsFromData, ",") {
  827. if b {
  828. //已终止参标
  829. if c := IC.BaseMysql.CountBySql(`SELECT count(id) FROM `+ParticipateUserTable+` WHERE project_id = ? AND ent_user_id = ? AND state <0`, projectId, v); c > 0 {
  830. continue
  831. }
  832. }
  833. entUserInfos := IC.MainMysql.SelectBySql(`SELECT * FROM entniche_user WHERE id = ?`, v)
  834. if entUserInfos != nil && len(*entUserInfos) > 0 {
  835. entUserInfo := (*entUserInfos)[0]
  836. if entUserInfo["name"] != nil {
  837. if userName := MC.ObjToString(entUserInfo["name"]); userName != "" {
  838. userNames = append(userNames, userName)
  839. }
  840. }
  841. }
  842. }
  843. return strings.Join(userNames, ",")
  844. }
  845. return ""
  846. }
  847. // GetBidContentEnt 企业版 获取投标状态更新内容
  848. func GetBidContentEnt(projectId string, entId int64) *[]map[string]interface{} {
  849. // record_type '默认0:参标、划转、取消参标;1:投标状态更新存储'
  850. query := "SELECT * FROM " + ParticipateBidRecordsTable + " where project_id=? and ent_id=? and record_type=1 order by create_date desc limit 1; "
  851. return IC.BaseMysql.SelectBySql(query, projectId, entId)
  852. }
  853. // GetBidContentPersonal 个人版 获取投标状态更新内容
  854. func GetBidContentPersonal(projectId string, positionId int64) *[]map[string]interface{} {
  855. query := "SELECT * FROM " + ParticipateBidRecordsTable + " where project_id=? and position_id=? and record_type=1 order by create_date desc limit 1;"
  856. return IC.BaseMysql.SelectBySql(query, projectId, positionId)
  857. }
  858. // UpdateBidContent 更新投标状态信息以及操作记录
  859. func UpdateBidContent(recordData map[string]interface{}) (flag bool) {
  860. r2 := IC.BaseMysql.Insert(ParticipateBidRecordsTable, recordData)
  861. return r2 > 0
  862. }
  863. // InsertBidContent 新增投标状态信息及操作记录
  864. func InsertBidContent(recordData map[string]interface{}) (flag bool) {
  865. r2 := IC.BaseMysql.Insert(ParticipateBidRecordsTable, recordData)
  866. return r2 > 0
  867. }
  868. // GetBidRecordsEnt 获取操作记录列表企业
  869. func GetBidRecordsEnt(projectId string, entId, page, pageSize int64) (rs *[]map[string]interface{}, total int64) {
  870. query := "SELECT * FROM " + ParticipateBidRecordsTable + " where project_id=? and ent_id=? order by create_date desc limit ?,?"
  871. countQuery := "SELECT count(id) FROM " + ParticipateBidRecordsTable + " where project_id=? and ent_id=? ;"
  872. rs = IC.BaseMysql.SelectBySql(query, projectId, entId, (page-1)*pageSize, pageSize)
  873. total = IC.BaseMysql.CountBySql(countQuery, projectId, entId)
  874. return rs, total
  875. }
  876. // GetBidRecordsPersonal 获取操作记录列表个人
  877. func GetBidRecordsPersonal(projectId string, positionId, page, pageSize int64) (rs *[]map[string]interface{}, total int64) {
  878. query := "SELECT * FROM " + ParticipateBidRecordsTable + " where project_id=? and position_id=? order by create_date desc limit ?,?;"
  879. countQuery := "SELECT count(id) FROM " + ParticipateBidRecordsTable + " where project_id=? and position_id=? ;"
  880. rs = IC.BaseMysql.SelectBySql(query, projectId, positionId, (page-1)*pageSize, pageSize)
  881. total = IC.BaseMysql.CountBySql(countQuery, projectId, positionId)
  882. return rs, total
  883. }
  884. // GetUserMap 查询用户id的姓名
  885. func GetUserMap(userIds string) (rs *[]map[string]interface{}) {
  886. query := fmt.Sprintf("select id,name from entniche_user where id in (%s)", userIds)
  887. rs = IC.MainMysql.SelectBySql(query)
  888. return rs
  889. }
  890. // CheckParticipateManager 验证项目id是否是该管理员企业下的参标项目
  891. func CheckParticipateManager(projectId string, entId int64, valid bool) (flag bool) {
  892. stateStr := "" // 是否需要验证是正在参标
  893. if valid {
  894. stateStr = " and state=0"
  895. }
  896. query := "SELECT count(id) FROM " + ParticipateUserTable + " where project_id=? and ent_id=?" + stateStr
  897. return IC.BaseMysql.CountBySql(query, projectId, entId) > 0
  898. }
  899. // CheckParticipateEntUser 验证项目id是否是该企业用户参标的项目
  900. func CheckParticipateEntUser(projectId string, entUserId int64, valid bool) (flag bool) {
  901. stateStr := "" // 是否需要验证是正在参标
  902. if valid {
  903. stateStr = " and state=0"
  904. }
  905. query := "SELECT count(id) FROM " + ParticipateUserTable + " where project_id=? and ent_user_id=?" + stateStr
  906. return IC.BaseMysql.CountBySql(query, projectId, entUserId) > 0
  907. }
  908. // CheckParticipatePersonal 查询项目id是否是该用户参标项目
  909. func CheckParticipatePersonal(projectId string, positionId int64, valid bool) (flag bool) {
  910. stateStr := "" // 是否需要验证是正在参标 终止参标的用户还能查看记录,但是不能更新状态
  911. if valid {
  912. stateStr = " and state=0"
  913. }
  914. query := "SELECT count(id) FROM " + ParticipateUserTable + " where project_id=? and position_id=?" + stateStr
  915. return IC.BaseMysql.CountBySql(query, projectId, positionId) > 0
  916. }
  917. // GetNameByUserIds 获取用户名字符串
  918. //
  919. // 参数:逗号分割的用户id "11,22,333..."
  920. // 返回: "张三,李四,王五..."
  921. func GetNameByUserIds(ids string) *[]map[string]interface{} {
  922. query := "select group_concat(name) as name from " + EntnicheUserTable + " where id in (" + ids + ") "
  923. rs := IC.MainMysql.SelectBySql(query)
  924. return rs
  925. }
  926. // ParticipateProjectPersonal 查询给定项目id中已经参标的项目id
  927. func ParticipateProjectPersonal(positionId int64, projectId []string) *[]map[string]interface{} {
  928. // 1. 查询出已经参标的
  929. var arg []string
  930. var value []interface{}
  931. value = append(value, positionId)
  932. for i := 0; i < len(projectId); i++ {
  933. arg = append(arg, "?")
  934. value = append(value, projectId[i])
  935. }
  936. argStr := strings.Join(arg, ",")
  937. query := "select project_id from " + ParticipateUserTable + " where position_id = ? and project_id in (%s) and state=0"
  938. rs := IC.BaseMysql.SelectBySql(fmt.Sprintf(query, argStr), value...)
  939. return rs
  940. }
  941. // ParticipateProjectEnt 查询给定项目id中已经参标的项目id
  942. func ParticipateProjectEnt(entId int64, projectId []string) *[]map[string]interface{} {
  943. // 1. 查询出已经参标的
  944. var arg []string
  945. var value []interface{}
  946. value = append(value, entId)
  947. for i := 0; i < len(projectId); i++ {
  948. arg = append(arg, "?")
  949. value = append(value, projectId[i])
  950. }
  951. argStr := strings.Join(arg, ",")
  952. query := "select GROUP_CONCAT(ent_user_id) as personIds ,project_id from " + ParticipateUserTable + " where ent_id=? and project_id in (%s) and state=0 group by project_id "
  953. rs := IC.BaseMysql.SelectBySql(fmt.Sprintf(query, argStr), value...)
  954. return rs
  955. }
  956. // 查询企业人员信息
  957. func GetPersonInfo(entId, entUserId int64, participateMap map[int64]bool) []*bxcore.ParticipatePerson {
  958. r := IC.MainMysql.SelectBySql(`SELECT a.id,a.pid,a.name,c.id as user_id,c.name as user_name,c.phone as user_phone,c.power as user_power,e.name as role from entniche_department a
  959. INNER JOIN entniche_department_user b on (a.ent_id=? and a.id=b.dept_id)
  960. INNER JOIN entniche_user c on (b.user_id=c.id)
  961. LEFT JOIN entniche_user_role d on (c.id=d.user_id)
  962. LEFT JOIN entniche_role e on (d.role_id=e.id)
  963. order by a.id,convert(c.name using gbk) COLLATE gbk_chinese_ci asc`, entId)
  964. var (
  965. list []*bxcore.ParticipatePerson
  966. prevId int64 = 0
  967. )
  968. for _, v := range *r {
  969. //if entUserId == MC.Int64All(v["user_id"]) {
  970. // continue
  971. //}
  972. id := MC.Int64All(v["id"])
  973. userId := strconv.FormatInt(MC.Int64All(v["user_id"]), 10)
  974. user := &bxcore.ParticipatePerson{
  975. Id: encrypt.SE.Encode2HexByCheck(userId),
  976. Power: MC.Int64All(v["user_power"]),
  977. Name: MC.ObjToString(v["user_name"]),
  978. Phone: MC.ObjToString(v["user_phone"]),
  979. Role: MC.ObjToString(v["role"]),
  980. }
  981. if participateMap != nil {
  982. if participateMap[MC.Int64All(v["user_id"])] {
  983. user.IsPart = 1
  984. }
  985. }
  986. if prevId == id {
  987. users := list[len(list)-1].Users
  988. users = append(users, user)
  989. list[len(list)-1].Users = users
  990. } else {
  991. seId := strconv.FormatInt(id, 10)
  992. list = append(list, &bxcore.ParticipatePerson{
  993. Id: encrypt.SE.Encode2HexByCheck(seId),
  994. Name: MC.ObjToString(v["name"]),
  995. Pid: MC.Int64All(v["pid"]),
  996. Users: []*bxcore.ParticipatePerson{user},
  997. })
  998. }
  999. prevId = id
  1000. }
  1001. return list
  1002. }
  1003. // 是否允许多人参标
  1004. func IsALLow(entId int64) bool {
  1005. return GetParticipateIsAllow(map[string]interface{}{
  1006. "i_entid": entId,
  1007. })
  1008. }