participateBid.go 37 KB

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