package controllers import ( "XT_New/enums" "XT_New/service" "XT_New/utils" "fmt" "github.com/astaxie/beego" "time" ) type NewStockApiController struct { BaseAuthAPIController } func NewStockApiRegistRouters() { beego.Router("/api/drug/stock", &NewStockApiController{}, "Get:GetDrugStock") beego.Router("/api/drug/change", &NewStockApiController{}, "Get:GetDrugChange") //beego.Router("/api/drug/query", &NewStockApiController{}, "Get:GetDrugQuery") } func (c *NewStockApiController) GetDrugStock() { start_time := c.GetString("start_time") end_time := c.GetString("end_time") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") var startTime int64 if len(start_time) > 0 { theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc) if err != nil { fmt.Println(err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } startTime = theTime.Unix() } var endTime int64 if len(end_time) > 0 { theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc) if err != nil { utils.ErrorLog(err.Error()) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } endTime = theTime.Unix() } admin := c.GetAdminUserInfo() is_pc, _ := c.GetInt64("is_pc", 0) is_bg, _ := c.GetInt64("is_bg", 0) //manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId) //dealerList, _ := service.GetAllDealerList(admin.CurrentOrgId) fmt.Println(startTime) fmt.Println(endTime) warehousingInfo, err := service.FindAllDrugWarehousingInfo(admin.CurrentOrgId, is_pc, is_bg, startTime, endTime) //list, _ := service.GetAll/**/StoreHouseListThree(admin.CurrentOrgId) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "info": warehousingInfo, //"manufacturerList": manufacturerList, //"dealerList": dealerList, //"list": list, }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) } } func (c *NewStockApiController) GetDrugChange() { start_time := c.GetString("start_time") end_time := c.GetString("end_time") is_sale, _ := c.GetInt64("is_sale") is_bg, _ := c.GetInt64("is_bg") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") var startTime int64 if len(start_time) > 0 { theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc) if err != nil { fmt.Println(err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } startTime = theTime.Unix() } var endTime int64 if len(end_time) > 0 { theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc) if err != nil { utils.ErrorLog(err.Error()) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } endTime = theTime.Unix() } orgId := c.GetAdminUserInfo().CurrentOrgId page, _ := c.GetInt64("page") limit, _ := c.GetInt64("limit") list, total, _ := service.GetNewDrugFlow(orgId, limit, page, startTime, endTime, is_sale, is_bg) manufacturerList, _ := service.GetAllManufacturerList(orgId) dealerList, _ := service.GetAllDealerList(orgId) houseList, _ := service.GetAllStoreHouseList(orgId) //patientList, _ := service.GetAllPatientListSix(orgId) c.ServeSuccessJSON(map[string]interface{}{ "info": list, "total": total, "manufacturerList": manufacturerList, "dealerList": dealerList, "houseList": houseList, //"patientList": patientList, }) } func (c *NewStockApiController) GetDrugQuery() { id, _ := c.GetInt64("id", 0) if id <= 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } admin := c.GetAdminUserInfo() warehousing, err := service.FindDrugWarehousingById(id, admin.CurrentOrgId) manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId) dealerList, _ := service.GetAllDealerList(admin.CurrentOrgId) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } if warehousing.ID <= 0 { return } warehousingInfo, err := service.FindDrugWarehousingInfoByIdThree(id, admin.CurrentOrgId) list, _ := service.GetAllStoreHouseListThree(admin.CurrentOrgId) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "info": warehousingInfo, "warehousing": warehousing, "manufacturerList": manufacturerList, "dealerList": dealerList, "list": list, }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) } }