participateBid.go 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  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) bool {
  263. defer MC.Catch()
  264. //如果不允许多人参标 当前项目是否已经有企业其他人员参标
  265. query := fmt.Sprintf(`SELECT count(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. return IC.BaseMysql.CountBySql(query) > 0
  272. }
  273. // 获取参标权限
  274. func GetParticipateIsAllow(query map[string]interface{}) (b bool) {
  275. defer MC.Catch()
  276. if info, ok := IC.Mgo.FindOne(PartTable, query); ok {
  277. if info != nil {
  278. if (*info)["i_isallow"] != nil {
  279. b = MC.IntAll((*info)["i_isallow"]) > 0
  280. }
  281. }
  282. }
  283. return
  284. }
  285. // 更新设置信息
  286. func UpdateParticipateSetInfo(in *bxcore.ParticipateSetUpInfoReq) error {
  287. defer MC.Catch()
  288. query := map[string]interface{}{
  289. "i_positionid": in.PositionId,
  290. }
  291. if in.PositionType > 0 {
  292. query["i_entid"] = in.EntId
  293. }
  294. upsert := map[string]interface{}{
  295. "i_entid": in.EntId,
  296. "i_entuserid": in.EntUserId,
  297. "i_positionid": in.PositionId,
  298. "l_createtime": time.Now().Unix(),
  299. }
  300. if in.IsAllow != "" {
  301. if in.IsAllow == "0" { //修改为允许单人参标
  302. //判断是否有多人参标的项目
  303. pSql := `SELECT project_id,COUNT(id) AS c FROM ` + ParticipateUserTable + ` WHERE ent_id = ? AND state =0 GROUP BY project_id ORDER BY c DESC;`
  304. data := IC.BaseMysql.SelectBySql(pSql, in.EntId)
  305. if data != nil && len(*data) > 0 {
  306. if max := MC.IntAll((*data)[0]["c"]); max > 1 {
  307. return fmt.Errorf("公司当前有项目多人参标的情况,请先确保项目都是单人参标的前提下再调整配置。\n前往”企业参标项目列表“查看具体情况。")
  308. }
  309. }
  310. }
  311. isAllow, _ := strconv.Atoi(in.IsAllow)
  312. upsert["i_isallow"] = isAllow
  313. }
  314. if len(in.BidType) > 0 {
  315. upsert["o_bidtype"] = in.BidType
  316. }
  317. if len(in.RemindRule) > 0 {
  318. upsert["o_remindrule"] = in.RemindRule
  319. }
  320. if in.NecessaryField != "" {
  321. upsert["s_requiredField"] = in.NecessaryField
  322. }
  323. if ok := IC.Mgo.Update(PartTable, query, map[string]interface{}{
  324. "$set": upsert,
  325. }, true, false); ok {
  326. return nil
  327. }
  328. return fmt.Errorf("更新失败")
  329. }
  330. // 查询企业|个人参标设置信息
  331. func GetParticipateSetInfo(in *bxcore.ParticipateSetUpInfoReq) (*bxcore.ParticipateSetUpInfo, error) {
  332. defer MC.Catch()
  333. query := map[string]interface{}{
  334. "i_positionid": in.PositionId,
  335. }
  336. if in.PositionType > 0 {
  337. query["i_entid"] = in.EntId
  338. }
  339. if setInfo, ok := IC.Mgo.FindOne(PartTable, query); ok {
  340. var (
  341. isAllow, isRequird string
  342. bidType []*bxcore.BidTypeReq
  343. remindRule []*bxcore.RemindRuleReq
  344. )
  345. bidType = append(bidType, &bxcore.BidTypeReq{
  346. Name: "直接投标",
  347. Content: []string{"未报名", "已报名", "投标决策", "编制投标文件", "递交投标文件", "中标公示", "签合同", "已结束"},
  348. }, &bxcore.BidTypeReq{
  349. Name: "渠道投标",
  350. Content: []string{"已报名", "签合同", "已结束"},
  351. })
  352. remindRule = append(remindRule, &bxcore.RemindRuleReq{
  353. BidState: "直接投标",
  354. Remainder: 72,
  355. Node: "编制投标文件",
  356. })
  357. if setInfo != nil {
  358. //必填字段
  359. if (*setInfo)["s_requiredField"] != nil {
  360. isRequird = MC.ObjToString((*setInfo)["s_requiredField"])
  361. } else {
  362. isRequird = "bidType"
  363. }
  364. if (*setInfo)["i_isallow"] != nil {
  365. isAllow = strconv.Itoa(MC.IntAll((*setInfo)["i_isallow"]))
  366. } else {
  367. isAllow = "0"
  368. }
  369. if (*setInfo)["o_bidtype"] != nil {
  370. if sbb, err := json.Marshal((*setInfo)["o_bidtype"]); err == nil {
  371. if err := json.Unmarshal(sbb, &bidType); err != nil {
  372. log.Println("bidType json un err:", err.Error())
  373. return nil, err
  374. }
  375. } else {
  376. log.Println("bidType json err:", err.Error())
  377. return nil, err
  378. }
  379. }
  380. if (*setInfo)["o_remindrule"] != nil {
  381. if sbr, err := json.Marshal((*setInfo)["o_remindrule"]); err == nil {
  382. if err := json.Unmarshal(sbr, &remindRule); err != nil {
  383. log.Println("remindRule json un err:", err.Error())
  384. return nil, err
  385. }
  386. } else {
  387. log.Println("remindRule json err:", err.Error())
  388. return nil, err
  389. }
  390. }
  391. }
  392. return &bxcore.ParticipateSetUpInfo{
  393. NecessaryField: isRequird,
  394. IsAllow: isAllow,
  395. BidType: bidType,
  396. RemindRule: remindRule,
  397. }, nil
  398. }
  399. return nil, nil
  400. }
  401. // 保存或更新tidb 项目信息
  402. func UpdateProjectInfo(id string, pInfo map[string]interface{}) error {
  403. //id 项目id
  404. //name 项目名称
  405. //area 省份
  406. //city 城市
  407. //buyer 采购单位
  408. //budget 预算
  409. //bid_open_time 开标时间
  410. //zbtime 招标时间
  411. //bid_end_time 开标结束时间 bidding表 由 数据组 重新生索引到project表
  412. //pici 批次 轮询更新数据
  413. //
  414. projectInfo := map[string]interface{}{
  415. "id": id,
  416. "name": MC.ObjToString(pInfo["projectname"]),
  417. "area": MC.ObjToString(pInfo["area"]),
  418. "city": MC.ObjToString(pInfo["city"]),
  419. "buyer": MC.ObjToString(pInfo["buyer"]),
  420. "budget": MC.Int64All(pInfo["budget"]),
  421. }
  422. if pInfo["bidopentime"] != nil {
  423. openTime := pInfo["bidopentime"]
  424. projectInfo["bid_open_time"] = date.FormatDateWithObj(&openTime, date.Date_Full_Layout)
  425. }
  426. if pInfo["pici"] != nil {
  427. pici := pInfo["pici"]
  428. projectInfo["pici"] = date.FormatDateWithObj(&pici, date.Date_Full_Layout)
  429. }
  430. // 项目表:zbtime 招标时间是 biding表:publishtime发布时间
  431. if pInfo["zbtime"] != nil {
  432. bidTime := pInfo["zbtime"]
  433. projectInfo["bid_time"] = date.FormatDateWithObj(&bidTime, date.Date_Full_Layout)
  434. }
  435. if pInfo["bidendtime"] != nil {
  436. bidEndTime := pInfo["bidendtime"]
  437. projectInfo["bid_end_time"] = date.FormatDateWithObj(&bidEndTime, date.Date_Full_Layout)
  438. }
  439. if c := IC.BaseMysql.CountBySql(`SELECT COUNT(id) FROM project WHERE id = ?`, id); c > 0 {
  440. if ok := IC.BaseMysql.Update("project", map[string]interface{}{
  441. "id": id,
  442. }, projectInfo); !ok {
  443. return fmt.Errorf("项目信息更新异常", id)
  444. }
  445. } else {
  446. if i := IC.BaseMysql.Insert("project", projectInfo); i < 0 {
  447. return fmt.Errorf("项目信息插入异常", id)
  448. }
  449. }
  450. return nil
  451. }
  452. // 参标列表其他条件
  453. func ParticipateListSql(in *bxcore.ParticipateListReq) string {
  454. //b project表
  455. //a participate_user表
  456. now := time.Now()
  457. nowDate := date.FormatDate(&now, date.Date_Full_Layout)
  458. //查询tidb base_service.project
  459. conditionSql := ` `
  460. //地区
  461. if in.Area != "" {
  462. conditionSql += fmt.Sprintf(" AND pt.area IN ('%s') ", strings.ReplaceAll(in.Area, ",", "','"))
  463. }
  464. //城市
  465. if in.City != "" {
  466. conditionSql += fmt.Sprintf(" AND pt.city IN ('%s') ", strings.ReplaceAll(in.City, ",", "','"))
  467. }
  468. //关键词
  469. if in.Keywords != "" {
  470. kSql := ` AND (`
  471. for kk, kv := range strings.Split(in.Keywords, " ") {
  472. log.Println(kk, "----", kv)
  473. if kk > 0 {
  474. kSql += " OR "
  475. }
  476. kSql += " pt.name like '%" + kv + "%'"
  477. }
  478. kSql += `)`
  479. conditionSql += kSql
  480. }
  481. //招标日期
  482. if in.BidTime != "" && strings.Contains(in.BidTime, "-") {
  483. startTime := strings.Split(in.BidTime, "-")[0]
  484. entTime := strings.Split(in.BidTime, "-")[1]
  485. if startTime != "" {
  486. startTimeInt, _ := strconv.ParseInt(startTime, 10, 64)
  487. conditionSql += ` AND pt.bid_time > '` + date.FormatDateByInt64(&startTimeInt, date.Date_Full_Layout) + `'`
  488. }
  489. if entTime != "" {
  490. entTimeInt, _ := strconv.ParseInt(entTime, 10, 64)
  491. conditionSql += ` AND pt.bid_time < '` + date.FormatDateByInt64(&entTimeInt, date.Date_Full_Layout) + `'`
  492. }
  493. }
  494. //招标截止日期
  495. if in.BidEndTime != "" {
  496. //投标截止日期规则:
  497. //1、开始时间小于当前时间 ,结束时间大于当前时间,投标截止状态按钮未截止和已截止可用;
  498. //2、结束时间小于当前时间|开始时间大于当前时间,投标截止状态按钮未截止和已截止不可用;
  499. //3、需要前端做成连动
  500. startTime := strings.Split(in.BidEndTime, "-")[0]
  501. endTime := strings.Split(in.BidEndTime, "-")[1]
  502. startTimeInt, _ := strconv.ParseInt(startTime, 10, 64)
  503. endTimeInt, _ := strconv.ParseInt(endTime, 10, 64)
  504. if startTimeInt > 0 && endTimeInt > 0 && startTimeInt > endTimeInt {
  505. log.Println(fmt.Sprintf("投标截止日期 %d 开始时间 大于 结束时间%d!!!", startTimeInt, endTimeInt))
  506. } else {
  507. switch in.BidEndStatus {
  508. case 0:
  509. if startTimeInt > 0 {
  510. conditionSql += ` AND pt.bid_end_time > '` + date.FormatDateByInt64(&startTimeInt, date.Date_Full_Layout) + `'`
  511. }
  512. if endTimeInt > 0 {
  513. conditionSql += ` AND pt.bid_end_time < '` + date.FormatDateByInt64(&endTimeInt, date.Date_Full_Layout) + `'`
  514. }
  515. case 1: //投标截止状态:1:未截止;2:已截止;3:终止参标
  516. //未截止:
  517. var (
  518. endBool = true
  519. )
  520. //如果结束时间存在且小于当前时间,投标截止日期 范围都是已截止 不会存在未截止的数据
  521. if endTimeInt > 0 {
  522. conditionSql += ` AND pt.bid_end_time < '` + date.FormatDateByInt64(&endTimeInt, date.Date_Full_Layout) + `'`
  523. endBool = endTimeInt > now.Unix()
  524. }
  525. //开始时间小于 当前时间
  526. if endBool && now.Unix() > startTimeInt {
  527. startTimeInt = now.Unix()
  528. }
  529. //存在开始时间为0的情况
  530. if startTimeInt > 0 {
  531. conditionSql += ` AND pt.bid_end_time > '` + date.FormatDateByInt64(&startTimeInt, date.Date_Full_Layout) + `'`
  532. }
  533. case 2: //投标截止状态:1:未截止;2:已截止;3:终止参标
  534. //如果开始时间存在且大于当前时间,投标截止日期 范围都是未截止 不会存在已截止的数据
  535. var (
  536. startBool = true
  537. )
  538. if startTimeInt > 0 {
  539. conditionSql += ` AND pt.bid_end_time > '` + date.FormatDateByInt64(&startTimeInt, date.Date_Full_Layout) + `'`
  540. startBool = startTimeInt < now.Unix()
  541. }
  542. if startBool && (endTimeInt == 0 || now.Unix() < endTimeInt) {
  543. endTimeInt = now.Unix()
  544. }
  545. //存在结束时间为0的情况
  546. if endTimeInt > 0 {
  547. conditionSql += ` AND pt.bid_end_time < '` + date.FormatDateByInt64(&endTimeInt, date.Date_Full_Layout) + `'`
  548. }
  549. case 3:
  550. conditionSql += ` AND pug.state < 0 `
  551. }
  552. }
  553. } else if in.BidEndStatus > 0 { //投标截止状态1:未截止;2:已截止;3:终止参标
  554. switch in.BidEndStatus {
  555. case 1:
  556. conditionSql += ` AND pt.bid_end_time > '` + nowDate + `'`
  557. case 2:
  558. conditionSql += ` AND pt.bid_end_time < '` + nowDate + `'`
  559. case 3:
  560. conditionSql += ` AND pug.state < 0 `
  561. }
  562. }
  563. //开标时间
  564. if in.BidOpenTime != "" {
  565. startTime := strings.Split(in.BidOpenTime, "-")[0]
  566. entTime := strings.Split(in.BidOpenTime, "-")[1]
  567. if startTime != "" {
  568. startTimeInt, _ := strconv.ParseInt(startTime, 10, 64)
  569. conditionSql += ` AND pt.bid_open_time > '` + date.FormatDateByInt64(&startTimeInt, date.Date_Full_Layout) + `'`
  570. }
  571. if entTime != "" {
  572. entTimeInt, _ := strconv.ParseInt(entTime, 10, 64)
  573. conditionSql += ` AND pt.bid_open_time < '` + date.FormatDateByInt64(&entTimeInt, date.Date_Full_Layout) + `'`
  574. }
  575. }
  576. //开标状态1:未开标;2:已开标
  577. if in.BidOpenStatus > 0 {
  578. switch in.BidOpenStatus {
  579. case 1:
  580. conditionSql += ` AND pt.bid_open_time > '` + nowDate + `'`
  581. case 2:
  582. conditionSql += ` AND pt.bid_open_time < '` + nowDate + `'`
  583. }
  584. }
  585. //参标人 管理员权限
  586. if in.EntUserIds != "" && in.PositionType > 0 {
  587. var entUserIdsSql = ""
  588. for k, v := range strings.Split(in.EntUserIds, ",") {
  589. v = encrypt.SE.Decode4HexByCheck(v)
  590. if v == "" {
  591. continue
  592. }
  593. if k > 0 && entUserIdsSql != "" {
  594. entUserIdsSql += " OR "
  595. }
  596. entUserIdsSql += ` FIND_IN_SET(` + v + ` , pug.ent_user_id) `
  597. }
  598. if entUserIdsSql != "" {
  599. conditionSql += ` AND (` + entUserIdsSql + `)`
  600. }
  601. }
  602. //默认按照投标截止日期正序排列、1:开标时间正序、2:更新状态时间倒序
  603. //投标结束时间和开标时间 很多项目数据没有这两个字段值
  604. switch in.OrderNum {
  605. case 1:
  606. conditionSql += ` ORDER BY pt.bid_open_time ASC,pt.bid_end_time ASC,pbr.create_date DESC`
  607. case 2:
  608. conditionSql += ` ORDER BY pbr.create_date DESC`
  609. default:
  610. conditionSql += ` ORDER BY pt.bid_end_time ASC,pt.bid_open_time ASC,pbr.create_date DESC`
  611. }
  612. log.Println(conditionSql)
  613. return conditionSql
  614. }
  615. // 个人或员工查询参标列表
  616. func SingleParticipateList(in *bxcore.ParticipateListReq, conditionSql string) (data *bxcore.ParticipateData, err error) {
  617. defer MC.Catch()
  618. data = &bxcore.ParticipateData{
  619. NowTime: time.Now().Unix(),
  620. Count: 0,
  621. List: []*bxcore.ParticipateList{},
  622. }
  623. //员工|个人列表
  624. 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 = ? `
  625. //singlePersonSql += conditionSql
  626. countSql := fmt.Sprintf(singlePersonSql, " COUNT(pt.id) ") + conditionSql
  627. count := IC.BaseMysql.CountBySql(countSql, in.PositionId)
  628. log.Println(countSql, "---", count)
  629. if count > 0 {
  630. data.Count = count
  631. listSql := fmt.Sprintf(singlePersonSql, " pt.*,pbr.create_date,pug.state ") + conditionSql
  632. //分页
  633. listSql += fmt.Sprintf(` LIMIT %d,%d`, in.PageNum, in.PageSize)
  634. log.Println("listSql:", listSql)
  635. list := IC.BaseMysql.SelectBySql(listSql, in.PositionId)
  636. if list != nil && len(*list) > 0 {
  637. for _, v := range *list {
  638. bidTimeStr := MC.ObjToString(v["bid_time"])
  639. bidEndTimeStr := MC.ObjToString(v["bid_end_time"])
  640. bidOpenTimeStr := MC.ObjToString(v["bid_open_time"])
  641. updateStatusTimeStr := MC.ObjToString(v["create_date"])
  642. stateInt64 := MC.Int64All(v["state"])
  643. var bidTime, bidEndTime, bidOpenTime, updateStatusTime int64
  644. if bidTimeStr != "" {
  645. bidTime_, _ := time.ParseInLocation(date.Date_Full_Layout, bidTimeStr, time.Local)
  646. bidTime = bidTime_.Unix()
  647. }
  648. if bidEndTimeStr != "" {
  649. bidEndTime_, _ := time.ParseInLocation(date.Date_Full_Layout, bidEndTimeStr, time.Local)
  650. bidEndTime = bidEndTime_.Unix()
  651. }
  652. if bidOpenTimeStr != "" {
  653. bidOpenTime_, _ := time.ParseInLocation(date.Date_Full_Layout, bidOpenTimeStr, time.Local)
  654. bidOpenTime = bidOpenTime_.Unix()
  655. }
  656. if updateStatusTimeStr != "" {
  657. updateStatusTime_, _ := time.ParseInLocation(date.Date_Full_Layout, updateStatusTimeStr, time.Local)
  658. updateStatusTime = updateStatusTime_.Unix()
  659. }
  660. data.List = append(data.List, &bxcore.ParticipateList{
  661. Id: encrypt.EncodeArticleId2ByCheck(MC.ObjToString(v["id"])),
  662. ProjectName: MC.ObjToString(v["name"]),
  663. Buyer: MC.ObjToString(v["buyer"]),
  664. Budget: MC.ObjToString(v["budget"]),
  665. BidTime: bidTime,
  666. BidEndTime: bidEndTime,
  667. BidOpenTime: bidOpenTime,
  668. UpdateStatusTime: updateStatusTime,
  669. State: strconv.FormatInt(stateInt64, 10),
  670. //UpdateStatusCon: GetParticipateContent("s", in.PositionId, MC.ObjToString(v["id"])), //查询最后一次 投标状态更新,
  671. })
  672. }
  673. return data, nil
  674. }
  675. return nil, fmt.Errorf("数据异常")
  676. }
  677. return data, nil
  678. }
  679. // 管理员获取参标列表数据
  680. func AdminParticipateList(in *bxcore.ParticipateListReq, conditionSql string) (data *bxcore.ParticipateData, err error) {
  681. defer MC.Catch()
  682. data = &bxcore.ParticipateData{
  683. IsAllow: IsALLow(in.EntId),
  684. NowTime: time.Now().Unix(),
  685. Count: 0,
  686. List: []*bxcore.ParticipateList{},
  687. }
  688. 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 = ? %s 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 `
  689. //maxStateSql := ``
  690. stateSql := ``
  691. if in.EntUserIds == "" {
  692. //maxStateSql = `,MAX(pu.state) state`
  693. stateSql = `AND NOT EXISTS ( SELECT 1 FROM ` + ParticipateUserTable + ` WHERE project_id = pu.project_id AND state > pu. state )`
  694. }
  695. adminSql = fmt.Sprintf(adminSql, "%s", stateSql)
  696. adminCountSql := fmt.Sprintf(adminSql, "COUNT(pt.id)") + conditionSql
  697. log.Println(adminCountSql)
  698. count := IC.BaseMysql.CountBySql(adminCountSql, in.EntId)
  699. if count > 0 {
  700. data.Count = count
  701. adminListSql := fmt.Sprintf(adminSql, " pt.*, pug.ent_user_id,pbr.create_date,pug.state ") + conditionSql + fmt.Sprintf(" LIMIT %d,%d", in.PageNum, in.PageSize)
  702. list := IC.BaseMysql.SelectBySql(adminListSql, in.EntId)
  703. if list != nil && len(*list) > 0 {
  704. for _, v := range *list {
  705. bidTimeStr := MC.ObjToString(v["bid_time"])
  706. bidEndTimeStr := MC.ObjToString(v["bid_end_time"])
  707. bidOpenTimeStr := MC.ObjToString(v["bid_open_time"])
  708. updateStatusTimeStr := MC.ObjToString(v["create_date"])
  709. stateInt64 := MC.Int64All(v["state"])
  710. var bidTime, bidEndTime, bidOpenTime, updateStatusTime int64
  711. if bidTimeStr != "" {
  712. bidTime_, _ := time.ParseInLocation(date.Date_Full_Layout, bidTimeStr, time.Local)
  713. bidTime = bidTime_.Unix()
  714. }
  715. if bidEndTimeStr != "" {
  716. bidEndTime_, _ := time.ParseInLocation(date.Date_Full_Layout, bidEndTimeStr, time.Local)
  717. bidEndTime = bidEndTime_.Unix()
  718. }
  719. if bidOpenTimeStr != "" {
  720. bidOpenTime_, _ := time.ParseInLocation(date.Date_Full_Layout, bidOpenTimeStr, time.Local)
  721. bidOpenTime = bidOpenTime_.Unix()
  722. }
  723. if updateStatusTimeStr != "" {
  724. updateStatusTime_, _ := time.ParseInLocation(date.Date_Full_Layout, updateStatusTimeStr, time.Local)
  725. updateStatusTime = updateStatusTime_.Unix()
  726. }
  727. data.List = append(data.List, &bxcore.ParticipateList{
  728. Id: encrypt.EncodeArticleId2ByCheck(MC.ObjToString(v["id"])),
  729. ProjectName: MC.ObjToString(v["name"]),
  730. Buyer: MC.ObjToString(v["buyer"]),
  731. Budget: MC.ObjToString(v["budget"]),
  732. BidTime: bidTime,
  733. BidEndTime: bidEndTime,
  734. BidOpenTime: bidOpenTime,
  735. UpdateStatusTime: updateStatusTime,
  736. State: strconv.FormatInt(stateInt64, 10),
  737. //UpdateStatusCon: GetParticipateContent("e", in.EntId, MC.ObjToString(v["id"])), //查询最后一次 投标状态更新
  738. Participants: GetParticipateUserName(MC.ObjToString(v["id"]), MC.ObjToString(v["ent_user_id"]), in.EntUserIds != ""), //参标人信息
  739. })
  740. }
  741. return data, nil
  742. }
  743. return nil, fmt.Errorf("数据异常")
  744. }
  745. return data, nil
  746. }
  747. // 获取最新参标 更新内容
  748. func GetParticipateContent(s string, id int64, projectId string) string {
  749. identitySql := `ent_id = ?`
  750. if s == "s" {
  751. identitySql = `position_id = ?`
  752. }
  753. recordsSql := `SELECT record_content,record_type FROM ` + ParticipateBidRecordsTable + ` WHERE ` + identitySql + ` AND project_id = ? ORDER BY create_date DESC LIMIT 1;`
  754. records := IC.BaseMysql.SelectBySql(recordsSql, id, projectId)
  755. if records != nil && len(*records) > 0 {
  756. rec := (*records)[0]
  757. switch MC.IntAll(rec["record_type"]) {
  758. case 0:
  759. return MC.ObjToString(rec["record_content"])
  760. case 1:
  761. recordContent := *MC.ObjToMap(rec["record_content"])
  762. rb, err := json.Marshal(recordContent)
  763. if err != nil {
  764. log.Println(err.Error())
  765. return ""
  766. }
  767. var rc = RecordsContent{
  768. After: PartStatusContent{},
  769. Before: PartStatusContent{},
  770. }
  771. err1 := json.Unmarshal(rb, &rc)
  772. if err1 == nil {
  773. return rc.Content
  774. }
  775. }
  776. }
  777. return ""
  778. }
  779. // 根据ent_user_id 获取参标人昵称,企业管理员现在都是“我”
  780. func GetParticipateUserName(projectId, entUserIdsFromData string, b bool) string {
  781. if entUserIdsFromData != "" {
  782. var userNames []string
  783. for _, v := range strings.Split(entUserIdsFromData, ",") {
  784. if b {
  785. //已终止参标
  786. if c := IC.BaseMysql.CountBySql(`SELECT count(id) FROM `+ParticipateUserTable+` WHERE project_id = ? AND ent_user_id = ? AND state <0`, projectId, v); c > 0 {
  787. continue
  788. }
  789. }
  790. entUserInfos := IC.MainMysql.SelectBySql(`SELECT * FROM entniche_user WHERE id = ?`, v)
  791. if entUserInfos != nil && len(*entUserInfos) > 0 {
  792. entUserInfo := (*entUserInfos)[0]
  793. if entUserInfo["name"] != nil {
  794. if userName := MC.ObjToString(entUserInfo["name"]); userName != "" {
  795. userNames = append(userNames, userName)
  796. }
  797. }
  798. }
  799. }
  800. return strings.Join(userNames, ",")
  801. }
  802. return ""
  803. }
  804. // GetBidContentEnt 企业版 获取投标状态更新内容
  805. func GetBidContentEnt(projectId string, entId int64) *[]map[string]interface{} {
  806. // record_type '默认0:参标、划转、取消参标;1:投标状态更新存储'
  807. query := "SELECT * FROM " + ParticipateBidRecordsTable + " where project_id=? and ent_id=? and record_type=1 order by create_date desc limit 1; "
  808. return IC.BaseMysql.SelectBySql(query, projectId, entId)
  809. }
  810. // GetBidContentPersonal 个人版 获取投标状态更新内容
  811. func GetBidContentPersonal(projectId string, positionId int64) *[]map[string]interface{} {
  812. query := "SELECT * FROM " + ParticipateBidRecordsTable + " where project_id=? and position_id=? and record_type=1 order by create_date desc limit 1;"
  813. return IC.BaseMysql.SelectBySql(query, projectId, positionId)
  814. }
  815. // UpdateBidContent 更新投标状态信息以及操作记录
  816. func UpdateBidContent(recordData map[string]interface{}) (flag bool) {
  817. r2 := IC.BaseMysql.Insert(ParticipateBidRecordsTable, recordData)
  818. return r2 > 0
  819. }
  820. // InsertBidContent 新增投标状态信息及操作记录
  821. func InsertBidContent(recordData map[string]interface{}) (flag bool) {
  822. r2 := IC.BaseMysql.Insert(ParticipateBidRecordsTable, recordData)
  823. return r2 > 0
  824. }
  825. // GetBidRecordsEnt 获取操作记录列表企业
  826. func GetBidRecordsEnt(projectId string, entId, page, pageSize int64) (rs *[]map[string]interface{}, total int64) {
  827. query := "SELECT * FROM " + ParticipateBidRecordsTable + " where project_id=? and ent_id=? order by create_date desc limit ?,?"
  828. countQuery := "SELECT count(id) FROM " + ParticipateBidRecordsTable + " where project_id=? and ent_id=? ;"
  829. rs = IC.BaseMysql.SelectBySql(query, projectId, entId, (page-1)*pageSize, pageSize)
  830. total = IC.BaseMysql.CountBySql(countQuery, projectId, entId)
  831. return rs, total
  832. }
  833. // GetBidRecordsPersonal 获取操作记录列表个人
  834. func GetBidRecordsPersonal(projectId string, positionId, page, pageSize int64) (rs *[]map[string]interface{}, total int64) {
  835. query := "SELECT * FROM " + ParticipateBidRecordsTable + " where project_id=? and position_id=? order by create_date desc limit ?,?;"
  836. countQuery := "SELECT count(id) FROM " + ParticipateBidRecordsTable + " where project_id=? and position_id=? ;"
  837. rs = IC.BaseMysql.SelectBySql(query, projectId, positionId, (page-1)*pageSize, pageSize)
  838. total = IC.BaseMysql.CountBySql(countQuery, projectId, positionId)
  839. return rs, total
  840. }
  841. // GetUserMap 查询用户id的姓名
  842. func GetUserMap(userIds string) (rs *[]map[string]interface{}) {
  843. query := fmt.Sprintf("select id,name from entniche_user where id in (%s)", userIds)
  844. rs = IC.MainMysql.SelectBySql(query)
  845. return rs
  846. }
  847. // CheckParticipateManager 验证项目id是否是该管理员企业下的参标项目
  848. func CheckParticipateManager(projectId string, entId int64, valid bool) (flag bool) {
  849. stateStr := "" // 是否需要验证是正在参标
  850. if valid {
  851. stateStr = " and state=0"
  852. }
  853. query := "SELECT count(id) FROM " + ParticipateUserTable + " where project_id=? and ent_id=?" + stateStr
  854. return IC.BaseMysql.CountBySql(query, projectId, entId) > 0
  855. }
  856. // CheckParticipateEntUser 验证项目id是否是该企业用户参标的项目
  857. func CheckParticipateEntUser(projectId string, entUserId int64, valid bool) (flag bool) {
  858. stateStr := "" // 是否需要验证是正在参标
  859. if valid {
  860. stateStr = " and state=0"
  861. }
  862. query := "SELECT count(id) FROM " + ParticipateUserTable + " where project_id=? and ent_user_id=?" + stateStr
  863. return IC.BaseMysql.CountBySql(query, projectId, entUserId) > 0
  864. }
  865. // CheckParticipatePersonal 查询项目id是否是该用户参标项目
  866. func CheckParticipatePersonal(projectId string, positionId int64, valid bool) (flag bool) {
  867. stateStr := "" // 是否需要验证是正在参标 终止参标的用户还能查看记录,但是不能更新状态
  868. if valid {
  869. stateStr = " and state=0"
  870. }
  871. query := "SELECT count(id) FROM " + ParticipateUserTable + " where project_id=? and position_id=?" + stateStr
  872. return IC.BaseMysql.CountBySql(query, projectId, positionId) > 0
  873. }
  874. // GetNameByUserIds 获取用户名字符串
  875. //
  876. // 参数:逗号分割的用户id "11,22,333..."
  877. // 返回: "张三,李四,王五..."
  878. func GetNameByUserIds(ids string) *[]map[string]interface{} {
  879. query := "select group_concat(name) as name from " + EntnicheUserTable + " where id in (" + ids + ") "
  880. rs := IC.MainMysql.SelectBySql(query)
  881. return rs
  882. }
  883. // ParticipateProjectPersonal 查询给定项目id中已经参标的项目id
  884. func ParticipateProjectPersonal(positionId int64, projectId []string) *[]map[string]interface{} {
  885. // 1. 查询出已经参标的
  886. var arg []string
  887. var value []interface{}
  888. value = append(value, positionId)
  889. for i := 0; i < len(projectId); i++ {
  890. arg = append(arg, "?")
  891. value = append(value, projectId[i])
  892. }
  893. argStr := strings.Join(arg, ",")
  894. query := "select project_id from " + ParticipateUserTable + " where position_id = ? and project_id in (%s) and state=0"
  895. rs := IC.BaseMysql.SelectBySql(fmt.Sprintf(query, argStr), value...)
  896. return rs
  897. }
  898. // ParticipateProjectEnt 查询给定项目id中已经参标的项目id
  899. func ParticipateProjectEnt(entId int64, projectId []string) *[]map[string]interface{} {
  900. // 1. 查询出已经参标的
  901. var arg []string
  902. var value []interface{}
  903. value = append(value, entId)
  904. for i := 0; i < len(projectId); i++ {
  905. arg = append(arg, "?")
  906. value = append(value, projectId[i])
  907. }
  908. argStr := strings.Join(arg, ",")
  909. 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 "
  910. rs := IC.BaseMysql.SelectBySql(fmt.Sprintf(query, argStr), value...)
  911. return rs
  912. }
  913. // 查询企业人员信息
  914. func GetPersonInfo(entId, entUserId int64, participateMap map[int64]bool) []*bxcore.ParticipatePerson {
  915. 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
  916. INNER JOIN entniche_department_user b on (a.ent_id=? and a.id=b.dept_id)
  917. INNER JOIN entniche_user c on (b.user_id=c.id)
  918. LEFT JOIN entniche_user_role d on (c.id=d.user_id)
  919. LEFT JOIN entniche_role e on (d.role_id=e.id)
  920. order by a.id,convert(c.name using gbk) COLLATE gbk_chinese_ci asc`, entId)
  921. var (
  922. list []*bxcore.ParticipatePerson
  923. prevId int64 = 0
  924. )
  925. for _, v := range *r {
  926. //if entUserId == MC.Int64All(v["user_id"]) {
  927. // continue
  928. //}
  929. id := MC.Int64All(v["id"])
  930. userId := strconv.FormatInt(MC.Int64All(v["user_id"]), 10)
  931. user := &bxcore.ParticipatePerson{
  932. Id: encrypt.SE.Encode2HexByCheck(userId),
  933. Power: MC.Int64All(v["user_power"]),
  934. Name: MC.ObjToString(v["user_name"]),
  935. Phone: MC.ObjToString(v["user_phone"]),
  936. Role: MC.ObjToString(v["role"]),
  937. }
  938. if participateMap != nil {
  939. if participateMap[MC.Int64All(v["user_id"])] {
  940. user.IsPart = 1
  941. }
  942. }
  943. if prevId == id {
  944. users := list[len(list)-1].Users
  945. users = append(users, user)
  946. list[len(list)-1].Users = users
  947. } else {
  948. seId := strconv.FormatInt(id, 10)
  949. list = append(list, &bxcore.ParticipatePerson{
  950. Id: encrypt.SE.Encode2HexByCheck(seId),
  951. Name: MC.ObjToString(v["name"]),
  952. Pid: MC.Int64All(v["pid"]),
  953. Users: []*bxcore.ParticipatePerson{user},
  954. })
  955. }
  956. prevId = id
  957. }
  958. return list
  959. }
  960. // 是否允许多人参标
  961. func IsALLow(entId int64) bool {
  962. return GetParticipateIsAllow(map[string]interface{}{
  963. "i_entid": entId,
  964. })
  965. }