123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- 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"
- "time"
- )
- var (
- PartTable = "participate"
- )
- //划转参标信息
- func TransferParticipate(in *bxcore.ParticipateActionReq) error {
- //保存或更新新跟踪人
- if !IC.BaseMysql.ExecTx("划转参标信息", func(tx *sql.Tx) bool {
- var (
- b = true
- b2, b3 bool
- now = time.Now()
- content = "%s划转给%s"
- )
- //是否保留原参标人
- if !in.IsRetain {
- content = fmt.Sprintf(content, "", "%s")
- 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
- //不保留 原参标人,获取把原参标人信息
- } else {
- entUserId, _ := strconv.ParseInt(in.ToEntUserId, 10, 64)
- IC.Middleground.UserCenter.IdentityByEntUserId(entUserId)
- }
- //查询原跟踪人信息
- if entUserInfos := IC.MainMysql.SelectBySql(`SELECT name FROM entniche_user WHERE id = ? LIMIT 1`, in.ToEntUserId); entUserInfos != nil && len(*entUserInfos) > 0 {
- entUserInfo := (*entUserInfos)[0]
- //用户名称
- if name := MC.ObjToString(entUserInfo["name"]); name != "" {
- b2 = true
- content = fmt.Sprintf(content, name)
- }
- }
- //
- //保存参标--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 b && b2 && b3
- }) {
- logx.Info(in.PositionId, "---终止---", in.BidId)
- return fmt.Errorf("终止参标更新信息出错")
- }
- return nil
- }
- //更新参标信息
- func UpdateParticipateInfo(in *bxcore.ParticipateActionReq) error {
- if !IC.BaseMysql.ExecTx("终止参标", func(tx *sql.Tx) bool {
- var (
- ppu, pph bool
- now = time.Now()
- )
- //更新参标participate_user
- 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
- //保存参标记录--participate_bid_records
- pph = 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 ppu && pph
- }) {
- 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 (
- ppu, pph bool
- now = time.Now()
- )
- //保存参标记录participate_bid_records
- 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 {
- 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
- }
- //保存参标--participate_user
- pph = 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 ppu && pph
- }) {
- logx.Info(in.PositionId, "---保存---", in.BidId)
- return fmt.Errorf("保存参标信息出错")
- }
- return nil
- }
- //查询当前招标信息是否已被参标
- func IsParticipatedByBidId(query string) bool {
- 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
- }
|