participateBid.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  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. "github.com/zeromicro/go-zero/core/logx"
  10. IC "jyBXCore/rpc/init"
  11. "jyBXCore/rpc/model/es"
  12. "jyBXCore/rpc/type/bxcore"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. var (
  18. PartTable = "participate"
  19. ParticipateBidRecordsTable = "participate_bid_records"
  20. ParticipateUserTable = "participate_user" // 参标用户表
  21. )
  22. //划转参标信息
  23. func TransferParticipateInfo(projectId string, in *bxcore.ParticipateActionReq) error {
  24. defer MC.Catch()
  25. //保存或更新新跟踪人
  26. if !IC.BaseMysql.ExecTx("划转参标信息", func(tx *sql.Tx) bool {
  27. var (
  28. b1 = true
  29. b2, b3 bool
  30. now = time.Now()
  31. content = "%s划转给%s%s"
  32. lastNotes = ",保留原参标人"
  33. fromUserNames []string
  34. ids []int
  35. )
  36. partInfo := IC.BaseMysql.SelectBySqlByTx(tx, "SELECT id,position_id FROM `participate_user` WHERE project_id = ? AND ent_id = ? AND state > -1", projectId, in.EntId)
  37. if partInfo == nil || len(*partInfo) == 0 {
  38. logx.Info("当前项目不满足划转条件")
  39. return false
  40. } else {
  41. for _, v := range *partInfo {
  42. ids = append(ids, MC.IntAll(v["id"]))
  43. positionId := MC.Int64All(v["position_id"])
  44. userInfo := IC.Middleground.UserCenter.IdentityByPositionId(positionId)
  45. if userInfo.EntUserName != "" {
  46. fromUserNames = append(fromUserNames, userInfo.EntUserName)
  47. }
  48. }
  49. }
  50. if len(fromUserNames) == 0 {
  51. logx.Info("原参标人信息查询有误")
  52. return false
  53. }
  54. //是否保留原参标人
  55. if !in.IsRetain {
  56. lastNotes = ""
  57. //不保留 原参标人,获取把原参标人信息
  58. //当前项目有参标人 更新参标人状态
  59. b1 = IC.BaseMysql.UpdateByTx(tx, "participate_user", map[string]interface{}{
  60. "ent_id": in.EntId,
  61. "project_id": projectId,
  62. }, map[string]interface{}{
  63. "state": -1,
  64. "mark": -2, //0:参标;1:被划入;-1:终止参标;-2:被划走
  65. "update_date": date.FormatDate(&now, date.Date_Full_Layout),
  66. })
  67. }
  68. //查询划转人信息
  69. entUserId, _ := strconv.ParseInt(in.ToEntUserId, 10, 64)
  70. userInfo := IC.Middleground.UserCenter.IdentityByEntUserId(entUserId)
  71. positionId := userInfo.PositionId
  72. content = fmt.Sprintf(content, strings.Join(fromUserNames, ","), userInfo.EntUserName, lastNotes)
  73. //划转记录
  74. b2 = IC.BaseMysql.InsertByTx(tx, "participate_bid_records", map[string]interface{}{
  75. "ent_id": in.EntId,
  76. "ent_user_id": entUserId,
  77. "position_id": positionId,
  78. "project_id": projectId,
  79. "record_content": content,
  80. "create_date": date.FormatDate(&now, date.Date_Full_Layout),
  81. }) > 0
  82. //保存参标--participate_user
  83. //查看是否参标过当前项目
  84. if c := IC.BaseMysql.CountBySql("SELECT count(id) FROM `participate_user` WHERE position_id = ? AND project_id = ? AND ent_id = ?", positionId, projectId, in.EntId); c > 0 {
  85. //更新
  86. b3 = IC.BaseMysql.UpdateByTx(tx, "participate_user", map[string]interface{}{
  87. "position_id": positionId,
  88. "project_id": projectId,
  89. "ent_id": in.EntId,
  90. }, map[string]interface{}{
  91. "state": 0,
  92. "mark": 1, //0:参标;1:被划入;-1:终止参标;-2:被划走
  93. "update_date": date.FormatDate(&now, date.Date_Full_Layout),
  94. })
  95. } else {
  96. //保存
  97. b3 = IC.BaseMysql.InsertByTx(tx, "participate_user", map[string]interface{}{
  98. "ent_id": in.EntId,
  99. "ent_user_id": entUserId,
  100. "position_id": positionId,
  101. "project_id": projectId,
  102. "state": 0,
  103. "mark": 1, //0:参标;1:被划入;-1:终止参标;-2:被划走
  104. "create_date": date.FormatDate(&now, date.Date_Full_Layout),
  105. "update_date": date.FormatDate(&now, date.Date_Full_Layout),
  106. }) > 0
  107. }
  108. return b1 && b2 && b3
  109. }) {
  110. logx.Info(in.PositionId, "---终止---", projectId)
  111. return fmt.Errorf("终止参标更新信息出错")
  112. }
  113. return nil
  114. }
  115. //终止参标
  116. func CancelParticipateInfo(in *bxcore.ParticipateActionReq, roleId int64) error {
  117. defer MC.Catch()
  118. if !IC.BaseMysql.ExecTx("终止参标", func(tx *sql.Tx) bool {
  119. var (
  120. b1, b2 bool
  121. now = time.Now()
  122. tip = "终止参标(被)"
  123. )
  124. //管理员终止:当前项目 其他参标人也被终止
  125. query := map[string]interface{}{
  126. "project_id": in.ProjectIds,
  127. "ent_id": in.EntId,
  128. }
  129. //个人终止:仅仅终止本人参标项目
  130. if roleId == 0 {
  131. query["position_id"] = in.PositionId
  132. tip = "终止参标"
  133. }
  134. insert := map[string]interface{}{
  135. "state": -1,
  136. "mark": -1, //0:参标;1:被划入;-1:终止参标;-2:被划走
  137. "update_date": date.FormatDate(&now, date.Date_Full_Layout),
  138. }
  139. //更新参标participate_user
  140. b1 = IC.BaseMysql.UpdateByTx(tx, "participate_user", query, insert)
  141. //保存参标记录--participate_bid_records
  142. b2 = IC.BaseMysql.InsertByTx(tx, "participate_bid_records", map[string]interface{}{
  143. "ent_id": in.EntId,
  144. "ent_user_id": in.EntUserId,
  145. "position_id": in.PositionId,
  146. "project_id": in.ProjectIds,
  147. "record_content": tip,
  148. "create_date": date.FormatDate(&now, date.Date_Full_Layout),
  149. }) > 0
  150. return b1 && b2
  151. }) {
  152. logx.Info(in.PositionId, "---终止---", in.ProjectIds)
  153. return fmt.Errorf("终止参标更新信息出错")
  154. }
  155. return nil
  156. }
  157. //保存参标信息
  158. func SaveParticipateInfo(in *bxcore.ParticipateActionReq) error {
  159. defer MC.Catch()
  160. if !IC.BaseMysql.ExecTx("保存|更新参标信息及保存参标记录", func(tx *sql.Tx) bool {
  161. var (
  162. b1, b2, b3 bool
  163. now = time.Now()
  164. )
  165. //保存参标--participate_user
  166. //查看是否参标过当前项目
  167. if c := IC.BaseMysql.CountBySql("SELECT count(id) FROM `participate_user` WHERE position_id = ? AND project_id = ? AND ent_id = ?", in.PositionId, in.ProjectIds, in.EntId); c > 0 {
  168. //更新
  169. b1 = IC.BaseMysql.UpdateByTx(tx, "participate_user", map[string]interface{}{
  170. "state": 0,
  171. "mark": 0,
  172. "update_date": date.FormatDate(&now, date.Date_Full_Layout),
  173. }, map[string]interface{}{
  174. "position_id": in.PositionId,
  175. "ent_id": in.EntId,
  176. "project_id": in.ProjectIds,
  177. })
  178. } else {
  179. //保存
  180. b1 = IC.BaseMysql.InsertByTx(tx, "participate_user", map[string]interface{}{
  181. "ent_id": in.EntId,
  182. "ent_user_id": in.EntUserId,
  183. "position_id": in.PositionId,
  184. "project_id": in.ProjectIds,
  185. "state": 0,
  186. "mark": 0,
  187. "create_date": date.FormatDate(&now, date.Date_Full_Layout),
  188. "update_date": date.FormatDate(&now, date.Date_Full_Layout),
  189. }) > 0
  190. }
  191. if !b1 {
  192. return false
  193. }
  194. //保存参标记录participate_bid_records
  195. b2 = IC.BaseMysql.InsertByTx(tx, "participate_bid_records", map[string]interface{}{
  196. "ent_id": in.EntId,
  197. "ent_user_id": in.EntUserId,
  198. "position_id": in.PositionId,
  199. "project_id": in.ProjectIds,
  200. "record_content": "参标",
  201. "create_date": date.FormatDate(&now, date.Date_Full_Layout),
  202. }) > 0
  203. if !b2 {
  204. return false
  205. }
  206. //保存或更新项目信息
  207. //有问题 其他回滚,项目信息不用回滚
  208. b3 = UpdateProjectInfo(in.ProjectIds, es.GetProjectInfo(in.ProjectIds), es.GetBiddingInfo(in.BidIds)) == nil
  209. return b1 && b2 && b3
  210. }) {
  211. logx.Info(in.PositionId, "---保存---", in.BidIds)
  212. return fmt.Errorf("保存参标信息出错")
  213. }
  214. return nil
  215. }
  216. //查询当前招标信息是否已被参标
  217. func IsParticipatedByBidId(in *bxcore.ParticipateActionReq) bool {
  218. defer MC.Catch()
  219. //如果不允许多人参标 当前项目是否已经有企业其他人员参标
  220. query := fmt.Sprintf(`SELECT count(id) FROM participate_user WHERE %s AND project_id = %s AND state >-1`, "%s", in.BidIds)
  221. if in.PositionType > 0 { //企业版
  222. query = fmt.Sprintf(query, fmt.Sprintf("ent_id = %d", in.EntId))
  223. } else { //个人版
  224. query = fmt.Sprintf(query, fmt.Sprintf("position_id = %d", in.PositionId))
  225. }
  226. return IC.BaseMysql.CountBySql(query) > 0
  227. }
  228. //获取参标权限
  229. func GetParticipateIsAllow(query map[string]interface{}) (b bool) {
  230. defer MC.Catch()
  231. if info, ok := IC.Mgo.FindOne(PartTable, query); ok {
  232. if info != nil {
  233. if (*info)["i_isallow"] != nil {
  234. b = MC.IntAll((*info)["i_isallow"]) > 0
  235. }
  236. }
  237. }
  238. return
  239. }
  240. //更新设置信息
  241. func UpdateParticipateSetInfo(in *bxcore.ParticipateSetUpInfoReq) error {
  242. defer MC.Catch()
  243. query := map[string]interface{}{
  244. "i_positionid": in.PositionId,
  245. }
  246. if in.PositionType > 0 {
  247. //企业版 判断是否是管理员
  248. //判断用户身份
  249. userInfo := IC.Middleground.PowerCheckCenter.Check(in.AppId, in.UserId, in.NewUserId, in.AccountId, in.EntId, in.PositionType, in.PositionId)
  250. if userInfo.Ent.EntRoleId == 0 {
  251. return fmt.Errorf("当前企业身份无权限")
  252. }
  253. query["i_entid"] = in.EntId
  254. }
  255. upsert := map[string]interface{}{
  256. "i_entid": in.EntId,
  257. "i_entuserid": in.EntUserId,
  258. "i_positionid": in.PositionId,
  259. "l_createtime": time.Now().Unix(),
  260. }
  261. if in.IsAllow != "" {
  262. isAllow, _ := strconv.Atoi(in.IsAllow)
  263. upsert["i_isallow"] = isAllow
  264. }
  265. if len(in.BidType) > 0 {
  266. upsert["o_bidtype"] = in.BidType
  267. }
  268. if len(in.RemindRule) > 0 {
  269. upsert["o_remindrule"] = in.RemindRule
  270. }
  271. if ok := IC.Mgo.Update(PartTable, query, map[string]interface{}{
  272. "$set": upsert,
  273. }, true, false); ok {
  274. return nil
  275. }
  276. return fmt.Errorf("更新失败")
  277. }
  278. //查询企业|个人参标设置信息
  279. func GetParticipateSetInfo(in *bxcore.ParticipateSetUpInfoReq) (*bxcore.ParticipateSetUpInfo, error) {
  280. defer MC.Catch()
  281. query := map[string]interface{}{
  282. "i_positionid": in.PositionId,
  283. }
  284. if in.PositionType > 0 {
  285. query["i_entid"] = in.EntId
  286. }
  287. if setInfo, ok := IC.Mgo.FindOne(PartTable, query); ok {
  288. var (
  289. isAllow = ""
  290. bidType []*bxcore.BidTypeReq
  291. remindRule []*bxcore.RemindRuleReq
  292. )
  293. bidType = append(bidType, &bxcore.BidTypeReq{
  294. Name: "直接投标",
  295. Content: []string{"未报名", "已报名", "投标决策", "编制投标文件", "递交投标文件", "中标公示", "签合同", "已结束"},
  296. }, &bxcore.BidTypeReq{
  297. Name: "渠道投标",
  298. Content: []string{"已报名", "签合同", "已结束"},
  299. })
  300. remindRule = append(remindRule, &bxcore.RemindRuleReq{
  301. BidState: "直接投标",
  302. Remainder: 72,
  303. Node: "编制投标文件",
  304. })
  305. if setInfo != nil {
  306. if (*setInfo)["i_isallow"] != nil {
  307. isAllow = strconv.Itoa(MC.IntAll((*setInfo)["i_isallow"]))
  308. }
  309. if (*setInfo)["bidType"] != nil {
  310. if sbb, err := json.Marshal((*setInfo)["o_bidtype"]); err == nil {
  311. if err := json.Unmarshal(sbb, &bidType); err != nil {
  312. logx.Info("bidType json un err:", err.Error())
  313. return nil, err
  314. }
  315. } else {
  316. logx.Info("bidType json err:", err.Error())
  317. return nil, err
  318. }
  319. }
  320. if (*setInfo)["o_remindrule"] != nil {
  321. if sbr, err := json.Marshal((*setInfo)["o_remindrule"]); err == nil {
  322. if err := json.Unmarshal(sbr, &remindRule); err != nil {
  323. logx.Info("remindRule json un err:", err.Error())
  324. return nil, err
  325. }
  326. } else {
  327. logx.Info("remindRule json err:", err.Error())
  328. return nil, err
  329. }
  330. }
  331. }
  332. return &bxcore.ParticipateSetUpInfo{
  333. IsAllow: isAllow,
  334. BidType: bidType,
  335. RemindRule: remindRule,
  336. }, nil
  337. }
  338. return nil, nil
  339. }
  340. //保存或更新tidb 项目信息
  341. func UpdateProjectInfo(id string, pInfo map[string]interface{}, bInfo map[string]interface{}) error {
  342. //id 项目id
  343. //name 项目名称
  344. //area 省份
  345. //city 城市
  346. //buyer 采购单位
  347. //budget 预算
  348. //bid_open_time 开标时间
  349. //bid_time 招标时间 bidding表
  350. //bid_end_time 开标结束时间 bidding表
  351. //pici 批次 轮询更新数据
  352. //
  353. projectInfo := map[string]interface{}{
  354. "id": id,
  355. "name": MC.ObjToString(pInfo["projectname"]),
  356. "area": MC.ObjToString(pInfo["area"]),
  357. "city": MC.ObjToString(pInfo["city"]),
  358. "buyer": MC.ObjToString(pInfo["buyer"]),
  359. "budget": MC.Int64All(pInfo["budget"]),
  360. }
  361. if pInfo["bidopentime"] != nil {
  362. openTime := pInfo["bidopentime"]
  363. projectInfo["bid_open_time"] = date.FormatDateWithObj(&openTime, date.Date_Full_Layout)
  364. }
  365. if pInfo["pici"] != nil {
  366. pici := pInfo["pici"]
  367. projectInfo["pici"] = date.FormatDateWithObj(&pici, date.Date_Full_Layout)
  368. }
  369. // 项目表:zbtime 招标时间是 biding表:publishtime发布时间
  370. if pInfo["zbtime"] != nil {
  371. bidTime := pInfo["zbtime"]
  372. projectInfo["bid_time"] = date.FormatDateWithObj(&bidTime, date.Date_Full_Layout)
  373. }
  374. if bInfo["bidendtime"] != nil {
  375. bidEndTime := bInfo["bidendtime"]
  376. projectInfo["bid_end_time"] = date.FormatDateWithObj(&bidEndTime, date.Date_Full_Layout)
  377. }
  378. if c := IC.BaseMysql.CountBySql(`SELECT COUNT(id) FROM project WHERE id = ?`, id); c > 0 {
  379. if ok := IC.BaseMysql.Update("project", map[string]interface{}{
  380. "id": id,
  381. }, projectInfo); !ok {
  382. return fmt.Errorf("项目信息更新异常", id)
  383. }
  384. } else {
  385. if i := IC.BaseMysql.Insert("project", projectInfo); i < 0 {
  386. return fmt.Errorf("项目信息插入异常", id)
  387. }
  388. }
  389. return nil
  390. }
  391. //参标列表其他条件
  392. func ParticipateListSql(in *bxcore.ParticipateListReq) string {
  393. //b project表
  394. //a participate_user表
  395. now := time.Now()
  396. nowDate := date.FormatDate(&now, date.Date_Full_Layout)
  397. //查询tidb base_service.project
  398. sql := ` `
  399. //地区
  400. if in.Area != "" {
  401. sql += fmt.Sprintf(" AND pt.area IN ('%s') ", strings.ReplaceAll(in.Area, ",", "','"))
  402. }
  403. //城市
  404. if in.City != "" {
  405. sql += fmt.Sprintf(" AND pt.city IN ('%s') ", strings.ReplaceAll(in.City, ",", "','"))
  406. }
  407. //关键词
  408. if in.Keywords != "" {
  409. kSql := ` AND (`
  410. for kk, kv := range strings.Split(in.Keywords, " ") {
  411. if kk > 0 {
  412. kSql += " OR "
  413. }
  414. kSql += " pt.name like '%" + kv + "%'"
  415. }
  416. kSql += `)`
  417. sql += kSql
  418. }
  419. //招标日期
  420. if in.BidTime != "" && strings.Contains(in.BidTime, "-") {
  421. startTime := strings.Split(in.BidTime, "-")[0]
  422. entTime := strings.Split(in.BidTime, "-")[1]
  423. if startTime != "" {
  424. sql += ` AND pt.bid_time > ` + startTime
  425. }
  426. if entTime != "" {
  427. sql += ` AND pt.bid_time < ` + entTime
  428. }
  429. }
  430. //招标截止日期
  431. if in.BidEndTime != "" {
  432. startTime := strings.Split(in.BidEndTime, "-")[0]
  433. entTime := strings.Split(in.BidEndTime, "-")[1]
  434. if startTime != "" {
  435. sql += ` AND pt.bid_end_time > ` + startTime
  436. }
  437. if entTime != "" {
  438. sql += ` AND pt.bid_end_time < ` + entTime
  439. }
  440. }
  441. //开标时间
  442. if in.BidOpenTime != "" {
  443. startTime := strings.Split(in.BidOpenTime, "-")[0]
  444. entTime := strings.Split(in.BidOpenTime, "-")[1]
  445. if startTime != "" {
  446. sql += ` AND pt.bid_open_time > ` + startTime
  447. }
  448. if entTime != "" {
  449. sql += ` AND pt.bid_open_time < ` + entTime
  450. }
  451. }
  452. //投标截止状态1:未截止;2:已截止;3:终止参标
  453. if in.BidEndStatus > 0 {
  454. switch in.BidEndStatus {
  455. case 1:
  456. sql += ` AND pt.bid_end_time > ` + nowDate
  457. case 2:
  458. sql += ` AND pt.bid_end_time < ` + nowDate
  459. case 3:
  460. sql += ` AND pug.state < 0 `
  461. }
  462. }
  463. //开标状态1:未开标;2:已开标
  464. if in.BidOpenStatus > 0 {
  465. switch in.BidOpenStatus {
  466. case 1:
  467. sql += ` AND pt.bid_open_time > ` + nowDate
  468. case 2:
  469. sql += ` AND pt.bid_open_time < ` + nowDate
  470. }
  471. }
  472. //参标人 管理员权限
  473. if in.EntUserIds != "" && in.PositionType > 0 {
  474. sql += ` AND pug.ent_user_id in ('` + strings.ReplaceAll(in.EntUserIds, ",", "','") + `')`
  475. }
  476. //默认按照投标截止日期正序排列、1:开标时间正序、2:更新状态时间倒序
  477. switch in.OrderNum {
  478. case 1:
  479. sql += ` ORDER BY pug.update_date DESC`
  480. case 2:
  481. sql += ` ORDER BY pt.bid_time ASC`
  482. default:
  483. sql += ` ORDER BY pt.bid_end_time ASC`
  484. }
  485. logx.Info(sql)
  486. return sql
  487. }
  488. //个人或员工查询参标列表
  489. func SingleParticipateList(in *bxcore.ParticipateListReq, otherSql string) (data *bxcore.ParticipateData, err error) {
  490. defer MC.Catch()
  491. data = &bxcore.ParticipateData{
  492. Count: 0,
  493. List: []*bxcore.ParticipateList{},
  494. }
  495. //员工|个人列表
  496. singlePersonSql := `SELECT %s FROM participate_user pug LEFT JOIN project pt ON pug.project_id = pt.id WHERE pug.position_id = ? `
  497. singlePersonSql += otherSql
  498. countSql := fmt.Sprintf(singlePersonSql, " COUNT(pt.id) ")
  499. count := IC.BaseMysql.CountBySql(countSql, in.PositionId)
  500. if count > 0 {
  501. data.Count = count
  502. listSql := fmt.Sprintf(singlePersonSql, " pug.update_date,pt.* ")
  503. //分页
  504. listSql += fmt.Sprintf(` LIMIT %d,%d`, in.PageNum, in.PageSize)
  505. list := IC.BaseMysql.SelectBySql(listSql, in.PositionId)
  506. if list != nil && len(*list) > 0 {
  507. for _, v := range *list {
  508. data.List = append(data.List, &bxcore.ParticipateList{
  509. Id: encrypt.EncodeArticleId2ByCheck(MC.ObjToString(v["id"])),
  510. ProjectName: MC.ObjToString(v["name"]),
  511. Buyer: MC.ObjToString(v["buyer"]),
  512. Budget: MC.ObjToString(v["budget"]),
  513. BidTime: MC.ObjToString(v["bid_time"]),
  514. BidEndTime: MC.ObjToString(v["bid_end_time"]),
  515. BidOpenTime: MC.ObjToString(v["bid_open_time"]),
  516. UpdateStatusTime: MC.ObjToString(v["update_date"]),
  517. UpdateStatusCon: GetParticipateContent(in.PositionId, MC.ObjToString(v["id"])), //查询最后一次 投标状态更新,
  518. })
  519. }
  520. return data, nil
  521. }
  522. return nil, fmt.Errorf("数据异常")
  523. }
  524. return data, nil
  525. }
  526. //管理员获取参标列表数据
  527. func AdminParticipateList(in *bxcore.ParticipateListReq, otherSql string) (data *bxcore.ParticipateData, err error) {
  528. defer MC.Catch()
  529. data = &bxcore.ParticipateData{
  530. Count: 0,
  531. List: []*bxcore.ParticipateList{},
  532. }
  533. adminSql := `SELECT %s FROM (SELECT pu.ent_id, pu.project_id, GROUP_CONCAT(pu.ent_user_id SEPARATOR ',') ent_user_id, MAX(pu.update_date) update_date FROM participate_user pu WHERE pu.ent_id = ? AND NOT EXISTS ( SELECT 1 FROM participate_user WHERE project_id = pu.project_id AND state > pu. state ) GROUP BY pu.project_id ) pug LEFT JOIN project pt ON pug.project_id = pt.id`
  534. adminSql += otherSql
  535. adminCountSql := fmt.Sprintf(adminSql, "COUNT(pt.id)")
  536. count := IC.BaseMysql.CountBySql(adminCountSql, in.EntId)
  537. if count > 0 {
  538. data.Count = count
  539. adminListSql := fmt.Sprintf(adminSql, "pt.*, pug.ent_user_id,pug.update_date")
  540. list := IC.BaseMysql.SelectBySql(adminListSql, in.EntId)
  541. if list != nil && len(*list) > 0 {
  542. for _, v := range *list {
  543. data.List = append(data.List, &bxcore.ParticipateList{
  544. Id: encrypt.EncodeArticleId2ByCheck(MC.ObjToString(v["id"])),
  545. ProjectName: MC.ObjToString(v["name"]),
  546. Buyer: MC.ObjToString(v["buyer"]),
  547. Budget: MC.ObjToString(v["budget"]),
  548. BidTime: MC.ObjToString(v["bid_time"]),
  549. BidEndTime: MC.ObjToString(v["bid_end_time"]),
  550. BidOpenTime: MC.ObjToString(v["bid_open_time"]),
  551. UpdateStatusTime: MC.ObjToString(v["update_date"]),
  552. UpdateStatusCon: GetParticipateContent(in.EntId, MC.ObjToString(v["id"])), //查询最后一次 投标状态更新
  553. Participants: GetParticipateUserName(MC.ObjToString(v["ent_user_id"])), //参标人信息
  554. })
  555. }
  556. return data, nil
  557. }
  558. return nil, fmt.Errorf("数据异常")
  559. }
  560. return data, nil
  561. }
  562. //获取最新参标 更新内容
  563. func GetParticipateContent(userId int64, projectId string) string {
  564. recordsSql := `SELECT record_content FROM participate_bid_records WHERE (ent_id = ? OR position_id = ?) AND project_id = ? ORDER BY create_date DESC LIMIT 1;`
  565. records := IC.BaseMysql.SelectBySql(recordsSql, userId, userId, projectId)
  566. if records != nil && len(*records) > 0 {
  567. rec := (*records)[0]
  568. return MC.ObjToString(rec["record_content"])
  569. }
  570. return ""
  571. }
  572. //根据ent_user_id 获取参标人昵称,企业管理员现在都是“我”
  573. func GetParticipateUserName(entUserId string) string {
  574. if entUserId != "" {
  575. var userNames []string
  576. for _, v := range strings.Split(entUserId, ",") {
  577. entUserInfos := IC.MainMysql.SelectBySql(`SELECT * FROM entniche_user WHERE id = ?`, v)
  578. if entUserInfos != nil && len(*entUserInfos) > 0 {
  579. entUserInfo := (*entUserInfos)[0]
  580. if entUserInfo["name"] != nil {
  581. if userName := MC.ObjToString(entUserInfo["name"]); userName != "" {
  582. userNames = append(userNames, userName)
  583. }
  584. }
  585. }
  586. }
  587. return strings.Join(userNames, ",")
  588. }
  589. return ""
  590. }
  591. // GetBidContentEnt 企业版 获取投标状态更新内容
  592. func GetBidContentEnt(projectId string, entId int64) *[]map[string]interface{} {
  593. // record_type '默认0:参标、划转、取消参标;1:投标状态更新存储'
  594. query := "SELECT * FROM " + ParticipateBidRecordsTable + " where project_id=? and ent_id=? and record_type=1 order by create_date desc limit 1; "
  595. return IC.BaseMysql.SelectBySql(query, projectId, entId)
  596. }
  597. // GetBidContentPersonal 个人版 获取投标状态更新内容
  598. func GetBidContentPersonal(projectId string, positionId int64) *[]map[string]interface{} {
  599. query := "SELECT * FROM " + ParticipateBidRecordsTable + " where project_id=? and position_id=? and record_type=1 order by create_date desc limit 1;"
  600. return IC.BaseMysql.SelectBySql(query, projectId, positionId)
  601. }
  602. // UpdateBidContent 更新投标状态信息以及操作记录
  603. func UpdateBidContent(recordData map[string]interface{}) (flag bool) {
  604. r2 := IC.BaseMysql.Insert(ParticipateBidRecordsTable, recordData)
  605. return r2 > 0
  606. }
  607. // InsertBidContent 新增投标状态信息及操作记录
  608. func InsertBidContent(recordData map[string]interface{}) (flag bool) {
  609. r2 := IC.BaseMysql.Insert(ParticipateBidRecordsTable, recordData)
  610. return r2 > 0
  611. }
  612. // GetBidRecordsEnt 获取操作记录列表企业
  613. func GetBidRecordsEnt(projectId string, entId, page, pageSize int64) (rs *[]map[string]interface{}, total int64) {
  614. query := "SELECT * FROM " + ParticipateBidRecordsTable + " where project_id=? and ent_id=? order by create_date desc limit ?,?"
  615. countQuery := "SELECT count(id) FROM " + ParticipateBidRecordsTable + " where project_id=? and ent_id=? ;"
  616. rs = IC.BaseMysql.SelectBySql(query, projectId, entId, (page-1)*pageSize, pageSize)
  617. total = IC.BaseMysql.CountBySql(countQuery, projectId, entId)
  618. return rs, total
  619. }
  620. // GetBidRecordsPersonal 获取操作记录列表个人
  621. func GetBidRecordsPersonal(projectId string, positionId, page, pageSize int64) (rs *[]map[string]interface{}, total int64) {
  622. query := "SELECT * FROM " + ParticipateBidRecordsTable + " where project_id=? and position_id=? order by create_date desc limit ?,?;"
  623. countQuery := "SELECT count(id) FROM " + ParticipateBidRecordsTable + " where project_id=? and position_id=? ;"
  624. rs = IC.BaseMysql.SelectBySql(query, projectId, positionId, (page-1)*pageSize, pageSize)
  625. total = IC.BaseMysql.CountBySql(countQuery, projectId, positionId)
  626. return rs, total
  627. }
  628. // GetUserMap 查询用户id的姓名
  629. func GetUserMap(userIds string) (rs *[]map[string]interface{}) {
  630. query := fmt.Sprintf("select id,name from entniche_user where id in (%s)", userIds)
  631. rs = IC.MainMysql.SelectBySql(query)
  632. return rs
  633. }
  634. // CheckParticipateManager 验证项目id是否是该管理员企业下的参标项目
  635. func CheckParticipateManager(projectId string, entId int64, valid bool) (flag bool) {
  636. stateStr := "" // 是否需要验证是正在参标
  637. if valid {
  638. stateStr = " and state=0"
  639. }
  640. query := "SELECT count(id) FROM " + ParticipateUserTable + " where project_id=? and ent_id=?" + stateStr
  641. return IC.BaseMysql.CountBySql(query, projectId, entId) > 0
  642. }
  643. // CheckParticipateEntUser 验证项目id是否是该企业用户参标的项目
  644. func CheckParticipateEntUser(projectId string, entUserId int64, valid bool) (flag bool) {
  645. stateStr := "" // 是否需要验证是正在参标
  646. if valid {
  647. stateStr = " and state=0"
  648. }
  649. query := "SELECT count(id) FROM " + ParticipateUserTable + " where project_id=? and ent_user_id=?" + stateStr
  650. return IC.BaseMysql.CountBySql(query, projectId, entUserId) > 0
  651. }
  652. // CheckParticipatePersonal 查询项目id是否是该用户参标项目
  653. func CheckParticipatePersonal(projectId string, positionId int64, valid bool) (flag bool) {
  654. stateStr := "" // 是否需要验证是正在参标 终止参标的用户还能查看记录,但是不能更新状态
  655. if valid {
  656. stateStr = " and state=0"
  657. }
  658. query := "SELECT count(id) FROM " + ParticipateUserTable + " where project_id=? and position_id=?" + stateStr
  659. return IC.BaseMysql.CountBySql(query, projectId, positionId) > 0
  660. }