|
@@ -18,15 +18,22 @@ func ShowPlans(c *gin.Context) {
|
|
|
db.Model(&model.Plan{}).Joins("left join plan_groups on plan.id = plan_id ").
|
|
|
Joins("left join group_users on plan_groups.group_id = group_users.group_id").
|
|
|
Where("user_id = ? and plan.delete <> 1", userId).Distinct().Find(&plans)
|
|
|
-
|
|
|
- response.Success(c, gin.H{"planlists": plans}, "success")
|
|
|
+ planVos := make([]vo.PlanVo, len(plans))
|
|
|
+ for i, v := range plans {
|
|
|
+ planVos[i] = vo.PlanVo{
|
|
|
+ Plan: v,
|
|
|
+ IsJoined: IsJoinedInCurrentPlan(userId, v.Id),
|
|
|
+ }
|
|
|
+ }
|
|
|
+ response.Success(c, gin.H{"planlists": planVos}, "success")
|
|
|
}
|
|
|
|
|
|
func ShowPlan(c *gin.Context) {
|
|
|
- Id := c.Params.ByName("id")
|
|
|
+ planId := c.Params.ByName("planId")
|
|
|
+ userId := c.Params.ByName("userId")
|
|
|
db := common.GetDB()
|
|
|
var plan model.Plan
|
|
|
- if err := db.Model(&model.Plan{}).Where("id = ?", Id).First(&plan).Error; err != nil {
|
|
|
+ if err := db.Model(&model.Plan{}).Where("id = ?", planId).First(&plan).Error; err != nil {
|
|
|
response.Fail(c, nil, "结果不存在")
|
|
|
return
|
|
|
}
|
|
@@ -39,8 +46,15 @@ func ShowPlan(c *gin.Context) {
|
|
|
var user model.User
|
|
|
db.Model(&model.User{}).Where("id = ?", plan.CreatorId).First(&user)
|
|
|
|
|
|
+ planVo := vo.PlanVo{
|
|
|
+ Plan: plan,
|
|
|
+ IsJoined: IsJoinedInCurrentPlan(userId, planId),
|
|
|
+ SendAmount: GetPlanTotalUserAmount(planId),
|
|
|
+ ReceiveAmount: GetPlanTaskAmount(planId),
|
|
|
+ ReportAmount: GetPlanReportAmount(planId),
|
|
|
+ }
|
|
|
response.Success(c, gin.H{
|
|
|
- "plan": plan,
|
|
|
+ "plan": planVo,
|
|
|
"creator": user,
|
|
|
"file": file,
|
|
|
}, "success")
|
|
@@ -189,7 +203,7 @@ func GetPlanAssignedGroups(c *gin.Context) {
|
|
|
|
|
|
func Test(c *gin.Context) {
|
|
|
|
|
|
- response.Success(c, gin.H{"count": IsJoinedInCurrentPlan("TestLaboratory_V1_User_9", "TestLaboratory_V1_Plan_7")}, "success")
|
|
|
+ response.Success(c, gin.H{"count": GetPlanReportAmount("TestLaboratory_V1_Plan_9")}, "success")
|
|
|
}
|
|
|
|
|
|
|
|
@@ -235,5 +249,11 @@ func IsJoinedInCurrentPlan(userId string, planId string) bool {
|
|
|
} else {
|
|
|
return false
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
+func GetPlanReportAmount(planId string) int {
|
|
|
+ var count int64
|
|
|
+ db := common.GetDB()
|
|
|
+ db.Model(&model.Task{}).Where("plan_id = ? and state = 2", planId).Count(&count)
|
|
|
+ return int(count)
|
|
|
}
|