package hdl import ( "applet/app/admin/enum" "applet/app/admin/lib/validate" "applet/app/admin/md" "applet/app/db" "applet/app/db/model" "applet/app/e" "applet/app/utils" "github.com/gin-gonic/gin" "time" ) func CompanyList(c *gin.Context) { companyDb := db.CompanyDb{} companyDb.Set() companies, err := companyDb.FindCompany(0, 0) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } e.OutSuc(c, map[string]interface{}{ "list": companies, "state": []map[string]interface{}{ { "name": "正常", "value": enum.CompanyStateForNormal, }, { "name": "冻结", "value": enum.CompanyStateForFreeze, }, }, }, nil) return } func CompanyAdd(c *gin.Context) { var req md.CompanyAddReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } companyDb := db.CompanyDb{} companyDb.Set() now := time.Now() company := model.Company{ Name: req.Name, State: enum.CompanyStateForNormal, Memo: req.Memo, LeadName: req.LeadName, LeadPhone: req.LeadPhone, CreateAt: now.Format("2006-01-02 15:04:05"), UpdateAt: now.Format("2006-01-02 15:04:05"), } _, err = companyDb.CompanyInsert(&company) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } e.OutSuc(c, "success", nil) return } func CompanyUpdate(c *gin.Context) { var req md.CompanyUpdateReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } companyDb := db.CompanyDb{} companyDb.Set() company, err := companyDb.GetCompany(req.Id) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if company == nil { e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") return } now := time.Now() company.Name = req.Name company.LeadName = req.LeadName company.LeadPhone = req.LeadPhone if req.State != 0 { company.State = req.State } company.UpdateAt = now.Format("2006-01-02 15:04:05") _, err = companyDb.CompanyUpdate(company, "name", "memo", "state", "lead_name", "lead_phone", "update_at") if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } e.OutSuc(c, "success", nil) return } func CompanyDelete(c *gin.Context) { id := c.Param("id") companyDb := db.CompanyDb{} companyDb.Set() company, err := companyDb.GetCompany(utils.StrToInt(id)) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if company == nil { e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") return } _, err = companyDb.CompanyDelete(id) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } e.OutSuc(c, "success", nil) return }