package tidb import ( MC "app.yhyue.com/moapp/jybase/common" "app.yhyue.com/moapp/jybase/date" "database/sql" "encoding/json" "fmt" "github.com/zeromicro/go-zero/core/logx" IC "jyBXCore/rpc/init" "jyBXCore/rpc/type/bxcore" "strconv" "strings" "time" ) var ( PartTable = "participate" ) //划转参标信息 func TransferParticipateInfo(in *bxcore.ParticipateActionReq) error { //保存或更新新跟踪人 if !IC.BaseMysql.ExecTx("划转参标信息", func(tx *sql.Tx) bool { var ( b1 = true b2, b3 bool now = time.Now() content = "%s划转给%s" fromUserNames []string ids []int ) //是否保留原参标人 if !in.IsRetain { //不保留 原参标人,获取把原参标人信息 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) if partInfo != nil && len(*partInfo) > 0 { for _, v := range *partInfo { ids = append(ids, MC.IntAll(v["id"])) positionId := MC.Int64All(v["position_id"]) userInfo := IC.Middleground.UserCenter.IdentityByPositionId(positionId) fromUserNames = append(fromUserNames, userInfo.EntUserName) } } 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 } //查询划转人信息 entUserId, _ := strconv.ParseInt(in.ToEntUserId, 10, 64) userInfo := IC.Middleground.UserCenter.IdentityByEntUserId(entUserId) in.PositionId = userInfo.PositionId content = fmt.Sprintf(content, strings.Join(fromUserNames, ","), userInfo.EntUserName) // //保存参标--participate_user b3 = IC.BaseMysql.InsertByTx(tx, "participate_bid_records", map[string]interface{}{ "ent_id": in.EntId, "ent_user_id": in.EntUserId, "position_id": in.PositionId, "project_id": in.BidId, "record_content": content, "create_date": date.FormatDate(&now, date.Date_Full_Layout), }) > 0 return b1 && b2 && b3 }) { logx.Info(in.PositionId, "---终止---", in.BidId) return fmt.Errorf("终止参标更新信息出错") } return nil } //终止参标 func CancelParticipateInfo(in *bxcore.ParticipateActionReq, roleId int64) error { if !IC.BaseMysql.ExecTx("终止参标", func(tx *sql.Tx) bool { var ( b1, b2 bool now = time.Now() tip = "终止参标(被)" ) //管理员终止:当前项目 其他参标人也被终止 query := map[string]interface{}{ "project_id": in.BidId, "ent_id": in.EntId, } //个人终止:仅仅终止本人参标项目 if roleId == 0 { query["position_id"] = in.PositionId tip = "终止参标" } insert := map[string]interface{}{ "state": -1, "update_date": date.FormatDate(&now, date.Date_Full_Layout), } //更新参标participate_user b1 = IC.BaseMysql.UpdateByTx(tx, "participate_user", query, insert) //保存参标记录--participate_bid_records b2 = IC.BaseMysql.InsertByTx(tx, "participate_bid_records", map[string]interface{}{ "ent_id": in.EntId, "ent_user_id": in.EntUserId, "position_id": in.PositionId, "project_id": in.BidId, "record_content": tip, "create_date": date.FormatDate(&now, date.Date_Full_Layout), }) > 0 return b1 && b2 }) { logx.Info(in.PositionId, "---终止---", in.BidId) return fmt.Errorf("终止参标更新信息出错") } return nil } //保存参标信息 func SaveParticipateInfo(in *bxcore.ParticipateActionReq) error { if !IC.BaseMysql.ExecTx("保存|更新参标信息及保存参标记录", func(tx *sql.Tx) bool { var ( b1, b2 bool now = time.Now() ) //保存参标--participate_user //查看是否参标过当前项目 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 { //更新 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 } else { //保存 b1 = IC.BaseMysql.InsertByTx(tx, "participate_user", map[string]interface{}{ "ent_id": in.EntId, "ent_user_id": in.EntUserId, "position_id": in.PositionId, "project_id": in.PositionId, "state": 0, "create_date": date.FormatDate(&now, date.Date_Full_Layout), "update_date": date.FormatDate(&now, date.Date_Full_Layout), }) > 0 } //保存参标记录participate_bid_records b2 = IC.BaseMysql.InsertByTx(tx, "participate_bid_records", map[string]interface{}{ "ent_id": in.EntId, "ent_user_id": in.EntUserId, "position_id": in.PositionId, "project_id": in.BidId, "record_content": "参标", "create_date": date.FormatDate(&now, date.Date_Full_Layout), }) > 0 return b1 && b2 }) { logx.Info(in.PositionId, "---保存---", in.BidId) return fmt.Errorf("保存参标信息出错") } return nil } //查询当前招标信息是否已被参标 func IsParticipatedByBidId(in *bxcore.ParticipateActionReq) bool { //如果不允许多人参标 当前项目是否已经有企业其他人员参标 query := fmt.Sprintf(`SELECT count(id) FROM participate_user WHERE %s AND project_id = %s AND state >-1`, "%s", in.BidId) if in.PositionType > 0 { query = fmt.Sprintf(query, fmt.Sprintf("ent_id = %d", in.EntId)) } else { query = fmt.Sprintf(query, fmt.Sprintf("position_id = %d", in.PositionId)) } return IC.BaseMysql.CountBySql(query) > 0 } //获取参标权限 func GetParticipateIsAllow(query map[string]interface{}) (b bool) { if info, ok := IC.Mgo.FindOne(PartTable, query); ok { if info != nil { if (*info)["i_isallow"] != nil { b = MC.IntAll((*info)["i_isallow"]) > 0 } } } return } //更新设置信息 func UpdateParticipateSetInfo(in *bxcore.ParticipateSetUpInfoReq) error { query := map[string]interface{}{ "i_positionid": in.PositionId, } if in.PositionType > 0 { //企业版 判断是否是管理员 //判断用户身份 userInfo := IC.Middleground.PowerCheckCenter.Check(in.AppId, in.UserId, in.NewUserId, in.AccountId, in.EntId, in.PositionType, in.PositionId) if userInfo.Ent.EntRoleId == 0 { return fmt.Errorf("当前企业身份无权限") } query["i_entid"] = in.EntId } upsert := map[string]interface{}{ "i_entid": in.EntId, "i_entuserid": in.EntUserId, "i_positionid": in.PositionId, "l_createtime": time.Now().Unix(), } if in.IsAllow != "" { isAllow, _ := strconv.Atoi(in.IsAllow) upsert["i_isallow"] = isAllow } if len(in.BidType) > 0 { upsert["o_bidtype"] = in.BidType } if len(in.RemindRule) > 0 { upsert["o_remindrule"] = in.RemindRule } if ok := IC.Mgo.Update(PartTable, query, map[string]interface{}{ "$set": upsert, }, true, false); ok { return nil } return fmt.Errorf("更新失败") } //查询企业|个人参标设置信息 func GetParticipateSetInfo(in *bxcore.ParticipateSetUpInfoReq) (*bxcore.ParticipateSetUpInfo, error) { query := map[string]interface{}{ "i_positionid": in.PositionId, } if in.PositionType > 0 { query["i_entid"] = in.EntId } if setInfo, ok := IC.Mgo.FindOne(PartTable, query); ok { var ( isAllow = "" bidType []*bxcore.BidTypeReq remindRule []*bxcore.RemindRuleReq ) bidType = append(bidType, &bxcore.BidTypeReq{ Name: "直接投标", Content: []string{"未报名", "已报名", "投标决策", "编制投标文件", "递交投标文件", "中标公示", "签合同", "已结束"}, }, &bxcore.BidTypeReq{ Name: "渠道投标", Content: []string{"已报名", "签合同", "已结束"}, }) remindRule = append(remindRule, &bxcore.RemindRuleReq{ BidState: "直接投标", Remainder: 72, Node: "编制投标文件", }) if setInfo != nil { if (*setInfo)["i_isallow"] != nil { isAllow = strconv.Itoa(MC.IntAll((*setInfo)["i_isallow"])) } if (*setInfo)["bidType"] != nil { if sbb, err := json.Marshal((*setInfo)["o_bidtype"]); err == nil { if err := json.Unmarshal(sbb, &bidType); err != nil { logx.Info("bidType json un err:", err.Error()) return nil, err } } else { logx.Info("bidType json err:", err.Error()) return nil, err } } if (*setInfo)["o_remindrule"] != nil { if sbr, err := json.Marshal((*setInfo)["o_remindrule"]); err == nil { if err := json.Unmarshal(sbr, &remindRule); err != nil { logx.Info("remindRule json un err:", err.Error()) return nil, err } } else { logx.Info("remindRule json err:", err.Error()) return nil, err } } } return &bxcore.ParticipateSetUpInfo{ IsAllow: isAllow, BidType: bidType, RemindRule: remindRule, }, nil } return nil, nil }