tidb.go 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. package tidb
  2. import (
  3. MC "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/date"
  5. "database/sql"
  6. "encoding/json"
  7. "fmt"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. IC "jyBXCore/rpc/init"
  10. "jyBXCore/rpc/type/bxcore"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. var (
  16. PartTable = "participate"
  17. )
  18. //划转参标信息
  19. func TransferParticipateInfo(in *bxcore.ParticipateActionReq) error {
  20. //保存或更新新跟踪人
  21. if !IC.BaseMysql.ExecTx("划转参标信息", func(tx *sql.Tx) bool {
  22. var (
  23. b1 = true
  24. b2, b3 bool
  25. now = time.Now()
  26. content = "%s划转给%s"
  27. fromUserNames []string
  28. ids []int
  29. )
  30. //是否保留原参标人
  31. if !in.IsRetain {
  32. //不保留 原参标人,获取把原参标人信息
  33. partInfo := IC.BaseMysql.SelectBySqlByTx(tx, "SELECT id,position_id FROM `participate_user` WHERE project_id = ? AND ent_id = ? AND state > -1", in.BidId, in.EntId)
  34. if partInfo != nil && len(*partInfo) > 0 {
  35. for _, v := range *partInfo {
  36. ids = append(ids, MC.IntAll(v["id"]))
  37. positionId := MC.Int64All(v["position_id"])
  38. userInfo := IC.Middleground.UserCenter.IdentityByPositionId(positionId)
  39. fromUserNames = append(fromUserNames, userInfo.EntUserName)
  40. }
  41. }
  42. b1 = IC.BaseMysql.UpdateOrDeleteBySqlByTx(tx, fmt.Sprintf(`UPDATE participate_user SET state = -2 ,update_date = %s WHERE ent_id = ? AND project_id = ?`, date.FormatDate(&now, date.Date_Full_Layout)), in.EntId, in.BidId) > 0
  43. }
  44. //查询划转人信息
  45. entUserId, _ := strconv.ParseInt(in.ToEntUserId, 10, 64)
  46. userInfo := IC.Middleground.UserCenter.IdentityByEntUserId(entUserId)
  47. in.PositionId = userInfo.PositionId
  48. content = fmt.Sprintf(content, strings.Join(fromUserNames, ","), userInfo.EntUserName)
  49. //
  50. //保存参标--participate_user
  51. b3 = IC.BaseMysql.InsertByTx(tx, "participate_bid_records", map[string]interface{}{
  52. "ent_id": in.EntId,
  53. "ent_user_id": in.EntUserId,
  54. "position_id": in.PositionId,
  55. "project_id": in.BidId,
  56. "record_content": content,
  57. "create_date": date.FormatDate(&now, date.Date_Full_Layout),
  58. }) > 0
  59. return b1 && b2 && b3
  60. }) {
  61. logx.Info(in.PositionId, "---终止---", in.BidId)
  62. return fmt.Errorf("终止参标更新信息出错")
  63. }
  64. return nil
  65. }
  66. //终止参标
  67. func CancelParticipateInfo(in *bxcore.ParticipateActionReq, roleId int64) error {
  68. if !IC.BaseMysql.ExecTx("终止参标", func(tx *sql.Tx) bool {
  69. var (
  70. b1, b2 bool
  71. now = time.Now()
  72. tip = "终止参标(被)"
  73. )
  74. //管理员终止:当前项目 其他参标人也被终止
  75. query := map[string]interface{}{
  76. "project_id": in.BidId,
  77. "ent_id": in.EntId,
  78. }
  79. //个人终止:仅仅终止本人参标项目
  80. if roleId == 0 {
  81. query["position_id"] = in.PositionId
  82. tip = "终止参标"
  83. }
  84. insert := map[string]interface{}{
  85. "state": -1,
  86. "update_date": date.FormatDate(&now, date.Date_Full_Layout),
  87. }
  88. //更新参标participate_user
  89. b1 = IC.BaseMysql.UpdateByTx(tx, "participate_user", query, insert)
  90. //保存参标记录--participate_bid_records
  91. b2 = IC.BaseMysql.InsertByTx(tx, "participate_bid_records", map[string]interface{}{
  92. "ent_id": in.EntId,
  93. "ent_user_id": in.EntUserId,
  94. "position_id": in.PositionId,
  95. "project_id": in.BidId,
  96. "record_content": tip,
  97. "create_date": date.FormatDate(&now, date.Date_Full_Layout),
  98. }) > 0
  99. return b1 && b2
  100. }) {
  101. logx.Info(in.PositionId, "---终止---", in.BidId)
  102. return fmt.Errorf("终止参标更新信息出错")
  103. }
  104. return nil
  105. }
  106. //保存参标信息
  107. func SaveParticipateInfo(in *bxcore.ParticipateActionReq) error {
  108. if !IC.BaseMysql.ExecTx("保存|更新参标信息及保存参标记录", func(tx *sql.Tx) bool {
  109. var (
  110. b1, b2 bool
  111. now = time.Now()
  112. )
  113. //保存参标--participate_user
  114. //查看是否参标过当前项目
  115. if c := IC.BaseMysql.CountBySql("SELECT count(id) FROM `participate_user` WHERE position_id = ? AND project_id = ? AND ent_id = ?", in.PositionId, in.BidId, in.EntId); c > 0 {
  116. //更新
  117. b1 = IC.BaseMysql.UpdateOrDeleteBySqlByTx(tx, fmt.Sprintf(`UPDATE participate_user SET state = 0 ,update_date = %s WHERE position_id = ? AND ent_id = ? AND project_id = ?`, date.FormatDate(&now, date.Date_Full_Layout)), in.PositionId, in.EntId, in.BidId) > 0
  118. } else {
  119. //保存
  120. b1 = IC.BaseMysql.InsertByTx(tx, "participate_user", map[string]interface{}{
  121. "ent_id": in.EntId,
  122. "ent_user_id": in.EntUserId,
  123. "position_id": in.PositionId,
  124. "project_id": in.PositionId,
  125. "state": 0,
  126. "create_date": date.FormatDate(&now, date.Date_Full_Layout),
  127. "update_date": date.FormatDate(&now, date.Date_Full_Layout),
  128. }) > 0
  129. }
  130. //保存参标记录participate_bid_records
  131. b2 = IC.BaseMysql.InsertByTx(tx, "participate_bid_records", map[string]interface{}{
  132. "ent_id": in.EntId,
  133. "ent_user_id": in.EntUserId,
  134. "position_id": in.PositionId,
  135. "project_id": in.BidId,
  136. "record_content": "参标",
  137. "create_date": date.FormatDate(&now, date.Date_Full_Layout),
  138. }) > 0
  139. return b1 && b2
  140. }) {
  141. logx.Info(in.PositionId, "---保存---", in.BidId)
  142. return fmt.Errorf("保存参标信息出错")
  143. }
  144. return nil
  145. }
  146. //查询当前招标信息是否已被参标
  147. func IsParticipatedByBidId(in *bxcore.ParticipateActionReq) bool {
  148. //如果不允许多人参标 当前项目是否已经有企业其他人员参标
  149. query := fmt.Sprintf(`SELECT count(id) FROM participate_user WHERE %s AND project_id = %s AND state >-1`, "%s", in.BidId)
  150. if in.PositionType > 0 {
  151. query = fmt.Sprintf(query, fmt.Sprintf("ent_id = %d", in.EntId))
  152. } else {
  153. query = fmt.Sprintf(query, fmt.Sprintf("position_id = %d", in.PositionId))
  154. }
  155. return IC.BaseMysql.CountBySql(query) > 0
  156. }
  157. //获取参标权限
  158. func GetParticipateIsAllow(query map[string]interface{}) (b bool) {
  159. if info, ok := IC.Mgo.FindOne(PartTable, query); ok {
  160. if info != nil {
  161. if (*info)["i_isallow"] != nil {
  162. b = MC.IntAll((*info)["i_isallow"]) > 0
  163. }
  164. }
  165. }
  166. return
  167. }
  168. //更新设置信息
  169. func UpdateParticipateSetInfo(in *bxcore.ParticipateSetUpInfoReq) error {
  170. query := map[string]interface{}{
  171. "i_positionid": in.PositionId,
  172. }
  173. if in.PositionType > 0 {
  174. //企业版 判断是否是管理员
  175. //判断用户身份
  176. userInfo := IC.Middleground.PowerCheckCenter.Check(in.AppId, in.UserId, in.NewUserId, in.AccountId, in.EntId, in.PositionType, in.PositionId)
  177. if userInfo.Ent.EntRoleId == 0 {
  178. return fmt.Errorf("当前企业身份无权限")
  179. }
  180. query["i_entid"] = in.EntId
  181. }
  182. upsert := map[string]interface{}{
  183. "i_entid": in.EntId,
  184. "i_entuserid": in.EntUserId,
  185. "i_positionid": in.PositionId,
  186. "l_createtime": time.Now().Unix(),
  187. }
  188. if in.IsAllow != "" {
  189. isAllow, _ := strconv.Atoi(in.IsAllow)
  190. upsert["i_isallow"] = isAllow
  191. }
  192. if len(in.BidType) > 0 {
  193. upsert["o_bidtype"] = in.BidType
  194. }
  195. if len(in.RemindRule) > 0 {
  196. upsert["o_remindrule"] = in.RemindRule
  197. }
  198. if ok := IC.Mgo.Update(PartTable, query, map[string]interface{}{
  199. "$set": upsert,
  200. }, true, false); ok {
  201. return nil
  202. }
  203. return fmt.Errorf("更新失败")
  204. }
  205. //查询企业|个人参标设置信息
  206. func GetParticipateSetInfo(in *bxcore.ParticipateSetUpInfoReq) (*bxcore.ParticipateSetUpInfo, error) {
  207. query := map[string]interface{}{
  208. "i_positionid": in.PositionId,
  209. }
  210. if in.PositionType > 0 {
  211. query["i_entid"] = in.EntId
  212. }
  213. if setInfo, ok := IC.Mgo.FindOne(PartTable, query); ok {
  214. var (
  215. isAllow = ""
  216. bidType []*bxcore.BidTypeReq
  217. remindRule []*bxcore.RemindRuleReq
  218. )
  219. bidType = append(bidType, &bxcore.BidTypeReq{
  220. Name: "直接投标",
  221. Content: []string{"未报名", "已报名", "投标决策", "编制投标文件", "递交投标文件", "中标公示", "签合同", "已结束"},
  222. }, &bxcore.BidTypeReq{
  223. Name: "渠道投标",
  224. Content: []string{"已报名", "签合同", "已结束"},
  225. })
  226. remindRule = append(remindRule, &bxcore.RemindRuleReq{
  227. BidState: "直接投标",
  228. Remainder: 72,
  229. Node: "编制投标文件",
  230. })
  231. if setInfo != nil {
  232. if (*setInfo)["i_isallow"] != nil {
  233. isAllow = strconv.Itoa(MC.IntAll((*setInfo)["i_isallow"]))
  234. }
  235. if (*setInfo)["bidType"] != nil {
  236. if sbb, err := json.Marshal((*setInfo)["o_bidtype"]); err == nil {
  237. if err := json.Unmarshal(sbb, &bidType); err != nil {
  238. logx.Info("bidType json un err:", err.Error())
  239. return nil, err
  240. }
  241. } else {
  242. logx.Info("bidType json err:", err.Error())
  243. return nil, err
  244. }
  245. }
  246. if (*setInfo)["o_remindrule"] != nil {
  247. if sbr, err := json.Marshal((*setInfo)["o_remindrule"]); err == nil {
  248. if err := json.Unmarshal(sbr, &remindRule); err != nil {
  249. logx.Info("remindRule json un err:", err.Error())
  250. return nil, err
  251. }
  252. } else {
  253. logx.Info("remindRule json err:", err.Error())
  254. return nil, err
  255. }
  256. }
  257. }
  258. return &bxcore.ParticipateSetUpInfo{
  259. IsAllow: isAllow,
  260. BidType: bidType,
  261. RemindRule: remindRule,
  262. }, nil
  263. }
  264. return nil, nil
  265. }