participateBid.go 39 KB

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