package frontc import ( "wuyebaoxiuapi/models/frontm" "wuyebaoxiuapi/models/backgroundm" "time" ) // 用户维修控制器 type UserRepairController struct { BaseController } // 用户报修数量 func (this *UserRepairController)UserRepairCount() { if this.userInfo.Types != 0 { this.Data["json"] = map[string]interface{}{"code": 0, "message": "登录过期"} this.ServeJSON() } repair := frontm.NewRepair() count := repair.FindRepairUserRepairCount(this.userInfo.Id) result := make(map[string]interface{}) result["count"] = count this.ajaxMsg(MSG_OK,"",result) } // 报修用户报修列表 func (this *UserRepairController)RepairUserRepairs() { userid := this.userInfo.Id page, err := this.GetInt("page") if err != nil { page = 1 } limit, err := this.GetInt("limit") if err != nil { limit = 30 } repair := frontm.NewRepair() repairs,total := repair.FindRepairUserRepairs(userid,page,limit) outReRepairs := make([]*frontm.OutReRepair,0) for _, v := range repairs { outReRepair := new(frontm.OutReRepair) this.fmtOutReRepair(v,outReRepair) outReRepairs = append(outReRepairs,outReRepair) } this.ajaxList(MSG_OK,"",total,outReRepairs) } func (this *UserRepairController)fmtOutReRepair(repair *frontm.Repair,outReRepair *frontm.OutReRepair) { repairUserPicture := frontm.NewRepairUserPicture() outReRepair.Id = repair.Id outReRepair.School = repair.School outReRepair.Position = repair.Position outReRepair.ApplicantName = repair.ApplicantName outReRepair.ApplicantPhone = repair.ApplicantPhone outReRepair.ApplicantUserId = repair.ApplicantUserId outReRepair.CreateTime = repair.CreateTime outReRepair.RepairUserId = repair.RepairUserId outReRepair.Status = repair.Status outReRepair.RepairTime = repair.RepairTime outReRepair.ApplicantContent = repair.ApplicantContent outReRepair.Address = repair.Address // 查找维修图片 images := repairUserPicture.FindPictureByUserIdAndReparId(repair.ApplicantUserId,repair.Id) outReRepair.RepairImages = images // 查找维修图片 outReRepair.ServiceImages = repairUserPicture.FindPictureByUserIdAndReparId(repair.RepairUserId,repair.Id) } // 维修用户维修数量 func (this *UserRepairController)RepairUserRepairCount() { if this.userInfo.Types != 0 { this.Data["json"] = map[string]interface{}{"code": 0, "message": "登录过期"} this.ServeJSON() } repair := frontm.NewRepair() result := make(map[string]interface{}) // 待维修数量 result["WRepairCount"] = repair.FindServiceUserWRepairCount(this.userInfo.Id) // 已维修数量 result["HRepairCount"] = repair.FindServiceUserHRepairCount(this.userInfo.Id) this.ajaxMsg(MSG_OK,"",result) } // 管理员维修数量 func (this *UserRepairController)AdminRepairCount() { repair := frontm.NewRepair() admin := new(backgroundm.Admin) result := make(map[string]interface{}) // 待维修数量 result["WRepairCount"] = repair.FindAdminWRepairCount(0) // 已维修数量 result["HRepairCount"] = repair.FindAdminHRepairCount(0) // 查找维修工人数量 result["RepairWorkerCount"] = admin.FindRepairWorkerCount() this.ajaxMsg(MSG_OK,"",result) } // 维修工人列表 func (this *UserRepairController)RepairWorkers() { repairWorkers,total := this.findRepairWorkers(false) this.ajaxList(MSG_OK,"",total,repairWorkers) } // 维修工人维修列表 func (this *UserRepairController)RepairWorkerRepairs() { id, _ := this.GetInt("id") page, err := this.GetInt("page") if err != nil { page = 1 } limit, err := this.GetInt("limit") if err != nil { limit = 30 } repair := frontm.NewRepair() repairs,total := repair.FindRepairsByUserId(id,page,limit) this.ajaxList(MSG_OK,"",total,repairs) } // 管理员待维修列表 func (this *UserRepairController)AdminWRepairs() { page, err := this.GetInt("page") if err != nil { page = 1 } limit, err := this.GetInt("limit") if err != nil { limit = 30 } repair := frontm.NewRepair() repairs,total :=repair.FindAdminWRepairs(page,limit) outReRepairs := make([]*frontm.OutReRepair,0) for _, v := range repairs { outReRepair := new(frontm.OutReRepair) this.fmtOutReRepair(v,outReRepair) outReRepairs = append(outReRepairs,outReRepair) } this.ajaxList(MSG_OK,"",total,outReRepairs) } // 管理员已维修列表 func (this *UserRepairController)AdminHRepairs() { page, err := this.GetInt("page") if err != nil { page = 1 } limit, err := this.GetInt("limit") if err != nil { limit = 30 } repair := frontm.NewRepair() repairs,total :=repair.FindAdminHRepairs(page,limit) outReRepairs := make([]*frontm.OutReRepair,0) for _, v := range repairs { outReRepair := new(frontm.OutReRepair) this.fmtOutReRepair(v,outReRepair) outReRepairs = append(outReRepairs,outReRepair) } this.ajaxList(MSG_OK,"",total,outReRepairs) } // 指派维修工人列表 func (this *UserRepairController)AssignRepairWorkers() { repairWorkers,total := this.findRepairWorkers(true) this.ajaxList(MSG_OK,"",total,repairWorkers) } // 指派维修任务 func (this *UserRepairController)AssignRepairTask(){ id, _ := this.GetInt("id") repairUserId, _ := this.GetInt("repair_user_id") if id <= 0 { this.ajaxMsg(MSG_ERR,"请选择维修任务",nil) } if repairUserId <= 0 { this.ajaxMsg(MSG_ERR,"请指派维修工人",nil) } repair := frontm.NewRepair() if _,err := repair.AssignRepairTask(id,repairUserId); err != nil { this.ajaxMsg(MSG_ERR,"系统繁忙,请稍后再试",nil) } this.ajaxMsg(MSG_OK,"指派成功",nil) } // 查找维修工人列表 func (this *UserRepairController)findRepairWorkers(isAssign bool)([]*backgroundm.RepairWorker, int64) { page, err := this.GetInt("page") if err != nil { page = 1 } limit, err := this.GetInt("limit") if err != nil { limit = 30 } repairWorkers := make([]*backgroundm.RepairWorker,0) admin := new(backgroundm.Admin) repair := frontm.NewRepair() admins,total := admin.FindRepairWorkers(page,limit) for _, v := range admins { repairWorker := new(backgroundm.RepairWorker) repairWorker.Id = v.Id repairWorker.LoginName = v.LoginName repairWorker.Phone = v.Phone repairWorker.NickName = v.NickName repairWorker.AvatarUrl = v.AvatarUrl // 查找维修用户待维修数量 repairWorker.WRepairCount = repair.FindServiceUserWRepairCount(v.Id) if isAssign == false { // 查找维修用户已维修数量 repairWorker.HRepairCount = repair.FindServiceUserHRepairCount(v.Id) }else{ // 查找维修用户已维修数量 repairWorker.HRepairCount = 0 } repairWorkers = append(repairWorkers, repairWorker) } return repairWorkers,total } // 查找维修用户待维修列表 func (this *UserRepairController)ServiceUserWRepairs()() { page, err := this.GetInt("page") if err != nil { page = 1 } limit, err := this.GetInt("limit") if err != nil { limit = 30 } repair := frontm.NewRepair() repairs,total :=repair.FindServiceUserWRepairs(this.userInfo.Id,page,limit) outReRepairs := make([]*frontm.OutReRepair,0) for _, v := range repairs { outReRepair := new(frontm.OutReRepair) this.fmtOutReRepair(v,outReRepair) outReRepairs = append(outReRepairs,outReRepair) } this.ajaxList(MSG_OK,"",total,outReRepairs) } // 查找维修用户待维修列表 func (this *UserRepairController)ServiceUserHRepairs()() { page, err := this.GetInt("page") if err != nil { page = 1 } limit, err := this.GetInt("limit") if err != nil { limit = 30 } repair := frontm.NewRepair() repairs,total :=repair.FindServiceUserHRepairs(this.userInfo.Id,page,limit) outReRepairs := make([]*frontm.OutReRepair,0) for _, v := range repairs { outReRepair := new(frontm.OutReRepair) this.fmtOutReRepair(v,outReRepair) outReRepairs = append(outReRepairs,outReRepair) } this.ajaxList(MSG_OK,"",total,outReRepairs) } // 确认维修 func (this *UserRepairController)ConfirmRepair()() { repair := frontm.NewRepair() repair.Id, _ = this.GetInt("id") image := this.GetString("image") if repair.Id <= 0 { this.ajaxMsg(MSG_ERR,"请选择要确认维修的任务",nil) } repair.RepairUserId = this.userInfo.Id repair.RepairTime = int(time.Now().Unix()) if _,err := repair.ConfirmRepair(); err != nil { this.ajaxMsg(MSG_ERR,"系统繁忙,请稍后再试",nil) } data := make(map[string]interface{}) data["image"] = image data["repairId"] = repair.Id this.addPicture(data) this.ajaxMsg(MSG_OK,"维修成功",nil) }