participateBid.go 37 KB

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