1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package customer
- import (
- "zhiyuan/pkg/app"
- "zhiyuan/pkg/utils"
- "zhiyuan/services/admin"
- "zhiyuan/services/aftersale"
- "zhiyuan/services/form"
- "zhiyuan/services/structs"
- "zhiyuan/services/user"
- "github.com/gin-gonic/gin"
- )
- func HouseList(c *gin.Context) {
- houseList := make([]*structs.HouseList, 0)
- if _, err := user.GetHouseList(map[string]interface{}{"user_id": c.GetInt("userID"), "deleted_at": 0}, nil, app.Page{}, &houseList); err != nil {
- app.Error(c, err.Error())
- return
- }
- adminIds := make([]int, 0)
- adminMap := make(map[int]string)
- for _, v := range houseList {
- if v.Designer > 0 {
- adminIds = append(adminIds, v.Designer)
- }
- if v.Supervisor > 0 {
- adminIds = append(adminIds, v.Supervisor)
- }
- }
- if len(adminIds) > 0 {
- if adminList, err := admin.GetAdmins(map[string]interface{}{"id in": adminIds}, nil, app.Page{}, nil); err == nil {
- for _, v := range adminList {
- adminMap[v.ID] = v.Username
- }
- }
- }
- typeList := make([]*structs.WarrantyType, 0)
- aftersale.GetTypeList(map[string]interface{}{"pid": 0, "`show`": 1}, nil, app.Page{}, &typeList)
- for _, v := range houseList {
- if v.Designer > 0 {
- v.DesignerName = adminMap[v.Designer]
- }
- if v.Supervisor > 0 {
- v.SupervisorName = adminMap[v.Supervisor]
- }
- warrantyType := make([]*structs.WarrantyType, 0)
- utils.DeepCopy(&warrantyType, &typeList)
- warrantyStart := utils.ToInt64(v.WarrantyStart)
- if warrantyStart > 0 {
- for _, t := range warrantyType {
- user.GetWarrantyPeriod(warrantyStart, t, v)
- }
- v.WarrantyStart = utils.Date(warrantyStart, "YYYY-MM-DD")
- }
- v.WarrantyType = warrantyType
- }
- app.Success(c, houseList)
- }
- func HouseEdit(c *gin.Context) {
- id := utils.StrTo(c.Param("id")).MustInt()
- if id <= 0 {
- app.Error(c, "house id must be a number")
- return
- }
- var form form.HouseAddByCustomer
- if app.Bind(c, &form) != nil {
- return
- }
- form.UserID = c.GetInt("userID")
- if err := user.HouseEditByCustomer(form, id); err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- app.Success(c, nil)
- }
- func HouseAdd(c *gin.Context) {
- var form form.HouseAddByCustomer
- if app.Bind(c, &form) != nil {
- return
- }
- form.UserID = c.GetInt("userID")
- houseID, err := user.HouseAddByCustomer(form)
- if err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- app.Success(c, gin.H{"house_id": houseID})
- }
|