tidb.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. "time"
  13. )
  14. var (
  15. PartTable = "participate"
  16. )
  17. //划转参标信息
  18. func TransferParticipate(in *bxcore.ParticipateActionReq) error {
  19. //保存或更新新跟踪人
  20. if !IC.BaseMysql.ExecTx("划转参标信息", func(tx *sql.Tx) bool {
  21. var (
  22. b = true
  23. b2, b3 bool
  24. now = time.Now()
  25. content = "%s划转给%s"
  26. )
  27. //是否保留原参标人
  28. if !in.IsRetain {
  29. content = fmt.Sprintf(content, "", "%s")
  30. b = 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
  31. //不保留 原参标人,获取把原参标人信息
  32. } else {
  33. entUserId, _ := strconv.ParseInt(in.ToEntUserId, 10, 64)
  34. IC.Middleground.UserCenter.IdentityByEntUserId(entUserId)
  35. }
  36. //查询原跟踪人信息
  37. if entUserInfos := IC.MainMysql.SelectBySql(`SELECT name FROM entniche_user WHERE id = ? LIMIT 1`, in.ToEntUserId); entUserInfos != nil && len(*entUserInfos) > 0 {
  38. entUserInfo := (*entUserInfos)[0]
  39. //用户名称
  40. if name := MC.ObjToString(entUserInfo["name"]); name != "" {
  41. b2 = true
  42. content = fmt.Sprintf(content, name)
  43. }
  44. }
  45. //
  46. //保存参标--participate_user
  47. b3 = IC.BaseMysql.InsertByTx(tx, "participate_bid_records", map[string]interface{}{
  48. "ent_id": in.EntId,
  49. "ent_user_id": in.EntUserId,
  50. "position_id": in.PositionId,
  51. "project_id": in.BidId,
  52. "record_content": content,
  53. "create_date": date.FormatDate(&now, date.Date_Full_Layout),
  54. }) > 0
  55. return b && b2 && b3
  56. }) {
  57. logx.Info(in.PositionId, "---终止---", in.BidId)
  58. return fmt.Errorf("终止参标更新信息出错")
  59. }
  60. return nil
  61. }
  62. //更新参标信息
  63. func UpdateParticipateInfo(in *bxcore.ParticipateActionReq) error {
  64. if !IC.BaseMysql.ExecTx("终止参标", func(tx *sql.Tx) bool {
  65. var (
  66. ppu, pph bool
  67. now = time.Now()
  68. )
  69. //更新参标participate_user
  70. ppu = IC.BaseMysql.UpdateOrDeleteBySqlByTx(tx, fmt.Sprintf(`UPDATE participate_user SET state = -1 ,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
  71. //保存参标记录--participate_bid_records
  72. pph = IC.BaseMysql.InsertByTx(tx, "participate_bid_records", map[string]interface{}{
  73. "ent_id": in.EntId,
  74. "ent_user_id": in.EntUserId,
  75. "position_id": in.PositionId,
  76. "project_id": in.BidId,
  77. "record_content": "终止参标",
  78. "create_date": date.FormatDate(&now, date.Date_Full_Layout),
  79. }) > 0
  80. return ppu && pph
  81. }) {
  82. logx.Info(in.PositionId, "---终止---", in.BidId)
  83. return fmt.Errorf("终止参标更新信息出错")
  84. }
  85. return nil
  86. }
  87. //保存参标信息
  88. func SaveParticipateInfo(in *bxcore.ParticipateActionReq) error {
  89. if !IC.BaseMysql.ExecTx("保存|更新参标信息及保存参标记录", func(tx *sql.Tx) bool {
  90. var (
  91. ppu, pph bool
  92. now = time.Now()
  93. )
  94. //保存参标记录participate_bid_records
  95. 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 {
  96. ppu = 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
  97. }
  98. //保存参标--participate_user
  99. pph = IC.BaseMysql.InsertByTx(tx, "participate_bid_records", map[string]interface{}{
  100. "ent_id": in.EntId,
  101. "ent_user_id": in.EntUserId,
  102. "position_id": in.PositionId,
  103. "project_id": in.BidId,
  104. "record_content": "参标",
  105. "create_date": date.FormatDate(&now, date.Date_Full_Layout),
  106. }) > 0
  107. return ppu && pph
  108. }) {
  109. logx.Info(in.PositionId, "---保存---", in.BidId)
  110. return fmt.Errorf("保存参标信息出错")
  111. }
  112. return nil
  113. }
  114. //查询当前招标信息是否已被参标
  115. func IsParticipatedByBidId(query string) bool {
  116. return IC.BaseMysql.CountBySql(query) > 0
  117. }
  118. //获取参标权限
  119. func GetParticipateIsAllow(query map[string]interface{}) (b bool) {
  120. if info, ok := IC.Mgo.FindOne(PartTable, query); ok {
  121. if info != nil {
  122. if (*info)["i_isallow"] != nil {
  123. b = MC.IntAll((*info)["i_isallow"]) > 0
  124. }
  125. }
  126. }
  127. return
  128. }
  129. //更新设置信息
  130. func UpdateParticipateSetInfo(in *bxcore.ParticipateSetUpInfoReq) error {
  131. query := map[string]interface{}{
  132. "i_positionid": in.PositionId,
  133. }
  134. if in.PositionType > 0 {
  135. //企业版 判断是否是管理员
  136. //判断用户身份
  137. userInfo := IC.Middleground.PowerCheckCenter.Check(in.AppId, in.UserId, in.NewUserId, in.AccountId, in.EntId, in.PositionType, in.PositionId)
  138. if userInfo.Ent.EntRoleId == 0 {
  139. return fmt.Errorf("当前企业身份无权限")
  140. }
  141. query["i_entid"] = in.EntId
  142. }
  143. upsert := map[string]interface{}{
  144. "i_entid": in.EntId,
  145. "i_entuserid": in.EntUserId,
  146. "i_positionid": in.PositionId,
  147. "l_createtime": time.Now().Unix(),
  148. }
  149. if in.IsAllow != "" {
  150. isAllow, _ := strconv.Atoi(in.IsAllow)
  151. upsert["i_isallow"] = isAllow
  152. }
  153. if len(in.BidType) > 0 {
  154. upsert["o_bidtype"] = in.BidType
  155. }
  156. if len(in.RemindRule) > 0 {
  157. upsert["o_remindrule"] = in.RemindRule
  158. }
  159. if ok := IC.Mgo.Update(PartTable, query, map[string]interface{}{
  160. "$set": upsert,
  161. }, true, false); ok {
  162. return nil
  163. }
  164. return fmt.Errorf("更新失败")
  165. }
  166. //查询企业|个人参标设置信息
  167. func GetParticipateSetInfo(in *bxcore.ParticipateSetUpInfoReq) (*bxcore.ParticipateSetUpInfo, error) {
  168. query := map[string]interface{}{
  169. "i_positionid": in.PositionId,
  170. }
  171. if in.PositionType > 0 {
  172. query["i_entid"] = in.EntId
  173. }
  174. if setInfo, ok := IC.Mgo.FindOne(PartTable, query); ok {
  175. var (
  176. isAllow = ""
  177. bidType []*bxcore.BidTypeReq
  178. remindRule []*bxcore.RemindRuleReq
  179. )
  180. bidType = append(bidType, &bxcore.BidTypeReq{
  181. Name: "直接投标",
  182. Content: []string{"未报名", "已报名", "投标决策", "编制投标文件", "递交投标文件", "中标公示", "签合同", "已结束"},
  183. }, &bxcore.BidTypeReq{
  184. Name: "渠道投标",
  185. Content: []string{"已报名", "签合同", "已结束"},
  186. })
  187. remindRule = append(remindRule, &bxcore.RemindRuleReq{
  188. BidState: "直接投标",
  189. Remainder: 72,
  190. Node: "编制投标文件",
  191. })
  192. if setInfo != nil {
  193. if (*setInfo)["i_isallow"] != nil {
  194. isAllow = strconv.Itoa(MC.IntAll((*setInfo)["i_isallow"]))
  195. }
  196. if (*setInfo)["bidType"] != nil {
  197. if sbb, err := json.Marshal((*setInfo)["o_bidtype"]); err == nil {
  198. if err := json.Unmarshal(sbb, &bidType); err != nil {
  199. logx.Info("bidType json un err:", err.Error())
  200. return nil, err
  201. }
  202. } else {
  203. logx.Info("bidType json err:", err.Error())
  204. return nil, err
  205. }
  206. }
  207. if (*setInfo)["o_remindrule"] != nil {
  208. if sbr, err := json.Marshal((*setInfo)["o_remindrule"]); err == nil {
  209. if err := json.Unmarshal(sbr, &remindRule); err != nil {
  210. logx.Info("remindRule json un err:", err.Error())
  211. return nil, err
  212. }
  213. } else {
  214. logx.Info("remindRule json err:", err.Error())
  215. return nil, err
  216. }
  217. }
  218. }
  219. return &bxcore.ParticipateSetUpInfo{
  220. IsAllow: isAllow,
  221. BidType: bidType,
  222. RemindRule: remindRule,
  223. }, nil
  224. }
  225. return nil, nil
  226. }