From 7864fc06297bfcd232457e1cda7a46d57594e3b0 Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Fri, 12 Aug 2022 11:35:31 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E5=85=B1=E5=AF=8C=E5=88=B6=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../small_public_platoon_relate_commission.go | 49 ++++++++----------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/rule/small_public_platoon_relate_commission.go b/rule/small_public_platoon_relate_commission.go index 6b4d079..f9337c4 100644 --- a/rule/small_public_platoon_relate_commission.go +++ b/rule/small_public_platoon_relate_commission.go @@ -302,6 +302,24 @@ func smallPublicPlatoon(engine *xorm.Engine, uid, recommendUid int, userPublicPl } + //2、查找对应pid的 user_public_platoon_relation 记录 + var m1 model.UserSmallPublicPlatoonRelation + if has, err := engine.Where("uid=?", fatherUid).Get(&m1); err != nil || has == false { + return userSmallPublicPlatoonRelation, err + } + var fatherUidStr string + if m1.FatherUid == "" { + //TODO::顶级 + fatherUidStr = zhios_order_relate_utils.IntToStr(m1.Id) + } else { + fatherUids := strings.Split(m1.FatherUid, "-") + if len(fatherUids) > userPublicPlatoonSetting.SeveralRows { + fatherUidStr = zhios_order_relate_utils.IntToStr(m1.Id) + "-" + strings.Join(fatherUids[0:userPublicPlatoonSetting.SeveralRows:len(fatherUids)], "-") + } else { + fatherUidStr = zhios_order_relate_utils.IntToStr(m1.Id) + "-" + m1.FatherUid + } + } + if userPublicPlatoonSetting.SettleDay == 0 { userPublicPlatoonSetting.SettleDay = 30 } @@ -309,6 +327,7 @@ func smallPublicPlatoon(engine *xorm.Engine, uid, recommendUid int, userPublicPl // 3、插入 user_public_platoon_relation 记录 now := time.Now() userSmallPublicPlatoonRelation.Uid = uid + userSmallPublicPlatoonRelation.FatherUid = fatherUidStr userSmallPublicPlatoonRelation.FatherUid1 = standardSmallPublicPlatoonRelation.FatherUid1 userSmallPublicPlatoonRelation.FatherUid2 = standardSmallPublicPlatoonRelation.FatherUid2 @@ -355,38 +374,12 @@ func smallPublicPlatoon(engine *xorm.Engine, uid, recommendUid int, userPublicPl userSmallPublicPlatoonRelation.CreateAt = now // userSmallPublicPlatoonRelation.UpdateAt = now userSmallPublicPlatoonRelation.HasSonNum = 0 - insertId, err := db.UserSmallPublicPlatoonRelationInsert(engine, &userSmallPublicPlatoonRelation) + _, err = db.UserSmallPublicPlatoonRelationInsert(engine, &userSmallPublicPlatoonRelation) if err != nil { return model.UserSmallPublicPlatoonRelation{}, err } - // 4、回更 father_uid 字段 - var m1 model.UserSmallPublicPlatoonRelation - if has, err := engine.Where("uid=?", fatherUid).Get(&m1); err != nil || has == false { - return userSmallPublicPlatoonRelation, err - } - var fatherUidStr string - if m1.FatherUid == "" { - //TODO::顶级 - fatherUidStr = zhios_order_relate_utils.IntToStr(insertId) - } else { - fatherUids := strings.Split(m1.FatherUid, "-") - if len(fatherUids) > userPublicPlatoonSetting.SeveralRows { - fatherUidStr = zhios_order_relate_utils.IntToStr(insertId) + "-" + strings.Join(fatherUids[0:userPublicPlatoonSetting.SeveralRows:len(fatherUids)], "-") - } else { - fatherUidStr = zhios_order_relate_utils.IntToStr(insertId) + "-" + m1.FatherUid - } - } - userSmallPublicPlatoonRelation.FatherUid = fatherUidStr - affected, err := db.UserSmallPublicPlatoonRelationUpdate(engine.NewSession(), userSmallPublicPlatoonRelation.Id, &userSmallPublicPlatoonRelation, "father_uid") - if err != nil { - return model.UserSmallPublicPlatoonRelation{}, err - } - if affected == 0 { - return model.UserSmallPublicPlatoonRelation{}, errors.New("更新 user_small_public_platoon_relation 记录失败") - } - - // 5、改变直属父级的 has_son_num 数量 + // 4、改变直属父级的 has_son_num 数量 update, err := engine.Where("uid = ?", fatherUid).SetExpr("has_son_num", "has_son_num + 1").Update(new(model.UserSmallPublicPlatoonRelation)) if err != nil { return userSmallPublicPlatoonRelation, err