package controllers import ( "XT_New/enums" "XT_New/models" "XT_New/service" "XT_New/utils" "encoding/json" "fmt" "github.com/astaxie/beego" "reflect" "strconv" "strings" "time" ) type SupplyOrderApiController struct { BaseAuthAPIController } func SupplyOrderApiRegistRouters() { beego.Router("/api/supply/getinitorder", &SupplyOrderApiController{}, "get:GetInitOrder") beego.Router("/api/supply/savepurchaseorder", &SupplyOrderApiController{}, "post:SavePurchaseOrder") beego.Router("/api/supply/getallsupply", &SupplyOrderApiController{}, "get:GetAllSupply") beego.Router("/api/supply/getallpurchaseorderlist", &SupplyOrderApiController{}, "get:GetAllPurchaseOrderList") beego.Router("/api/supply/updatepurchaseorder", &SupplyOrderApiController{}, "Post:UpdatePurchaseOrder") } func (this *SupplyOrderApiController) GetInitOrder() { orgId := this.GetAdminUserInfo().CurrentOrgId //获取药品库数据 baseList, _ := service.GetSupplyDrugList(orgId) goodList, _ := service.GetSupplyGoodList(orgId) manufactuerList, _ := service.GetAllManufacturerList(orgId) goodTypeList, _ := service.GetAllGoodType(orgId) supplyList, _ := service.GetSupplierList(orgId) var drugType = "药品类型" drugTypeParent, _ := service.GetDrugDataConfig(0, drugType) drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId) this.ServeSuccessJSON(map[string]interface{}{ "drugList": baseList, "goodList": goodList, "manufactuerList": manufactuerList, "goodTypeList": goodTypeList, "drugTypeList": drugTypeList, "supplyList": supplyList, }) return } func (this *SupplyOrderApiController) SavePurchaseOrder() { supplier_id, _ := this.GetInt64("supplier_name") start_time := this.GetString("start_time") end_time := this.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 { this.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()) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } endTime = theTime.Unix() } rate_of_concession := this.GetString("rate_of_concession") rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64) discount_amount := this.GetString("discount_amount") discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64) fmt.Println("supplier_id23323232323232", supplier_id, startTime, endTime, rate_of_concession, rate_of_concession_float, discount_amount, discount_amount_float) dataBody := make(map[string]interface{}, 0) err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody) if err != nil { utils.ErrorLog(err.Error()) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } //生成订货单 timeStr := time.Now().Format("2006-01-02") timeArr := strings.Split(timeStr, "-") orgId := this.GetAdminUserInfo().CurrentOrgId total, _ := service.FindAllSupplyOrder(orgId) total = total + 1 warehousing_order := "CGDD" + timeArr[0] + timeArr[1] + timeArr[2] + "00" + strconv.FormatInt(total, 10) recordDateStr := time.Now().Format("2006-01-02") recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr) fmt.Scan("parseDateErr", parseDateErr) record_date := recordDate.Unix() info := models.SupplierWarehouseInfo{ Number: warehousing_order, UserOrgId: orgId, Creater: this.GetAdminUserInfo().AdminUser.Id, Ctime: time.Now().Unix(), Mtime: 0, Status: 1, RecordDate: record_date, IsCheck: 2, RateOfConcession: rate_of_concession_float, DiscountAmount: discount_amount_float, DocumentDate: startTime, DeliveryDate: endTime, SupplierId: supplier_id, } err = service.CreateSupplyWarehouse(info) warehouseInfo, _ := service.FindLastSupplyWarehouseInfo(orgId) var warehousingInfo []*models.SupplierWarehousingInfoOrder if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" { thisStockIn, _ := dataBody["stockIn"].([]interface{}) if len(thisStockIn) > 0 { for _, item := range thisStockIn { items := item.(map[string]interface{}) if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" { utils.ErrorLog("id") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } id := int64(items["id"].(float64)) if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" { utils.ErrorLog("supply_count") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } supply_count := int64(items["supply_count"].(float64)) if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" { utils.ErrorLog("supply_license_number") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } supply_license_number := items["supply_license_number"].(string) if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" { utils.ErrorLog("supply_price") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } supply_price := items["supply_price"].(string) supply_price_float, _ := strconv.ParseFloat(supply_price, 64) if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" { utils.ErrorLog("supply_remake") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } supply_remake := items["supply_remake"].(string) if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" { utils.ErrorLog("supply_total_price") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } supply_total_price := items["supply_total_price"].(string) supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64) if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" { utils.ErrorLog("type") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } is_source := int64(items["type"].(float64)) if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" { utils.ErrorLog("supply_type") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } supply_type := items["supply_type"].(string) if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" { utils.ErrorLog("supply_specification_name") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } supply_specification_name := items["supply_specification_name"].(string) if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" { utils.ErrorLog("supply_total") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } supply_total := items["supply_total"].(string) if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" { utils.ErrorLog("supply_manufacturer") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } supply_manufacturer := items["supply_manufacturer"].(string) if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" { utils.ErrorLog("name") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } name := items["name"].(string) order := models.SupplierWarehousingInfoOrder{ OrderNumber: warehousing_order, IsSource: is_source, Count: supply_count, Price: supply_price_float, Amount: supply_total_price_float, Remark: supply_remake, UserOrgId: orgId, Ctime: time.Now().Unix(), Status: 1, Mtime: 0, WarehousingId: warehouseInfo.ID, ProjectId: id, SupplyLicenseNumber: supply_license_number, SupplyType: supply_type, SupplySpecificationName: supply_specification_name, SupplyTotal: supply_total, SupplyManufacturer: supply_manufacturer, Name: name, } warehousingInfo = append(warehousingInfo, &order) } } } for _, item := range warehousingInfo { err = service.CreateSupplyWarehousingOrder(item) } //查询 orderInfo, err := service.GetSupplyWarehousingOrderInfo(warehouseInfo.ID) if err == nil { this.ServeSuccessJSON(map[string]interface{}{ "order": warehousingInfo, "warehouseInfo": warehouseInfo, "orderInfo": orderInfo, }) } else { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) } } func (this *SupplyOrderApiController) GetAllSupply() { orgId := this.GetAdminUserInfo().CurrentOrgId appId := this.GetAdminUserInfo().CurrentAppId supplyList, err := service.GetSupplierList(orgId) doctorList, err := service.GetAllDoctor(orgId, appId) if err == nil { this.ServeSuccessJSON(map[string]interface{}{ "supplyList": supplyList, "doctorList": doctorList, }) } else { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) } } func (this *SupplyOrderApiController) GetAllPurchaseOrderList() { check_id, _ := this.GetInt64("check_id") start_time := this.GetString("start_time") end_time := this.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 { this.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()) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } endTime = theTime.Unix() } keyword := this.GetString("keyword") page, _ := this.GetInt64("page") limit, _ := this.GetInt64("limit") orgId := this.GetAdminUserInfo().CurrentOrgId list, total, err := service.GetAllPurchaseOrderList(check_id, startTime, endTime, keyword, page, limit, orgId) if err == nil { this.ServeSuccessJSON(map[string]interface{}{ "list": list, "total": total, }) } else { this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) } } func (this *SupplyOrderApiController) UpdatePurchaseOrder() { supplier_id, _ := this.GetInt64("supplier_name") start_time := this.GetString("start_time") end_time := this.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 { this.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()) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } endTime = theTime.Unix() } rate_of_concession := this.GetString("rate_of_concession") rate_of_concession_float, _ := strconv.ParseFloat(rate_of_concession, 64) discount_amount := this.GetString("discount_amount") discount_amount_float, _ := strconv.ParseFloat(discount_amount, 64) warehousing_id, _ := this.GetInt64("id") number := this.GetString("number") fmt.Println("supplier_id23323232323232", supplier_id, startTime, endTime, rate_of_concession, rate_of_concession_float, discount_amount, discount_amount_float) orgId := this.GetAdminUserInfo().CurrentOrgId info := models.SupplierWarehouseInfo{ RateOfConcession: rate_of_concession_float, DiscountAmount: discount_amount_float, DocumentDate: startTime, DeliveryDate: endTime, SupplierId: supplier_id, Mtime: time.Now().Unix(), } service.ModefySupplyWarehouseInfo(warehousing_id, info) dataBody := make(map[string]interface{}, 0) err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody) if err != nil { utils.ErrorLog(err.Error()) this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } var warehousingInfo []*models.SupplierWarehousingInfoOrder var updateWarehousingInfo []*models.SupplierWarehousingInfoOrder if dataBody["stockIn"] != nil && reflect.TypeOf(dataBody["stockIn"]).String() == "[]interface {}" { thisStockIn, _ := dataBody["stockIn"].([]interface{}) if len(thisStockIn) > 0 { for _, item := range thisStockIn { items := item.(map[string]interface{}) if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" { utils.ErrorLog("id") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } id := int64(items["id"].(float64)) if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" { utils.ErrorLog("project_id") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } project_id := int64(items["project_id"].(float64)) if items["supply_count"] == nil || reflect.TypeOf(items["supply_count"]).String() != "float64" { utils.ErrorLog("supply_count") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } supply_count := int64(items["supply_count"].(float64)) if items["supply_license_number"] == nil || reflect.TypeOf(items["supply_license_number"]).String() != "string" { utils.ErrorLog("supply_license_number") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } supply_license_number := items["supply_license_number"].(string) if items["supply_price"] == nil || reflect.TypeOf(items["supply_price"]).String() != "string" { utils.ErrorLog("supply_price") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } supply_price := items["supply_price"].(string) supply_price_float, _ := strconv.ParseFloat(supply_price, 64) if items["supply_remake"] == nil || reflect.TypeOf(items["supply_remake"]).String() != "string" { utils.ErrorLog("supply_remake") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } supply_remake := items["supply_remake"].(string) if items["supply_total_price"] == nil || reflect.TypeOf(items["supply_total_price"]).String() != "string" { utils.ErrorLog("supply_total_price") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } supply_total_price := items["supply_total_price"].(string) supply_total_price_float, _ := strconv.ParseFloat(supply_total_price, 64) if items["is_source"] == nil || reflect.TypeOf(items["is_source"]).String() != "float64" { utils.ErrorLog("is_source") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } is_source := int64(items["is_source"].(float64)) if items["supply_type"] == nil || reflect.TypeOf(items["supply_type"]).String() != "string" { utils.ErrorLog("supply_type") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } supply_type := items["supply_type"].(string) if items["supply_specification_name"] == nil || reflect.TypeOf(items["supply_specification_name"]).String() != "string" { utils.ErrorLog("supply_specification_name") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } supply_specification_name := items["supply_specification_name"].(string) if items["supply_total"] == nil || reflect.TypeOf(items["supply_total"]).String() != "string" { utils.ErrorLog("supply_total") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } supply_total := items["supply_total"].(string) if items["supply_manufacturer"] == nil || reflect.TypeOf(items["supply_manufacturer"]).String() != "string" { utils.ErrorLog("supply_manufacturer") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } supply_manufacturer := items["supply_manufacturer"].(string) if items["name"] == nil || reflect.TypeOf(items["name"]).String() != "string" { utils.ErrorLog("name") this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } name := items["name"].(string) if id > 0 { order := models.SupplierWarehousingInfoOrder{ ID: id, IsSource: is_source, Count: supply_count, Price: supply_price_float, Amount: supply_total_price_float, Remark: supply_remake, Ctime: time.Now().Unix(), Status: 1, Mtime: 0, ProjectId: project_id, SupplyLicenseNumber: supply_license_number, SupplyType: supply_type, SupplySpecificationName: supply_specification_name, SupplyTotal: supply_total, SupplyManufacturer: supply_manufacturer, Name: name, } updateWarehousingInfo = append(updateWarehousingInfo, &order) } if id == 0 { order := models.SupplierWarehousingInfoOrder{ OrderNumber: number, IsSource: is_source, Count: supply_count, Price: supply_price_float, Amount: supply_total_price_float, Remark: supply_remake, UserOrgId: orgId, Ctime: time.Now().Unix(), Status: 1, Mtime: 0, WarehousingId: warehousing_id, ProjectId: id, SupplyLicenseNumber: supply_license_number, SupplyType: supply_type, SupplySpecificationName: supply_specification_name, SupplyTotal: supply_total, SupplyManufacturer: supply_manufacturer, Name: name, } warehousingInfo = append(warehousingInfo, &order) } } } if len(warehousingInfo) > 0 { for _, item := range warehousingInfo { service.CreateSupplyWarehousingOrder(item) } } if len(updateWarehousingInfo) > 0 { for _, item := range updateWarehousingInfo { service.ModifySupplyWarehouseOrder(item) } } this.ServeSuccessJSON(map[string]interface{}{ "warehousingInfo": warehousingInfo, }) } }