package controllers import ( "ERP_storage/Nats/NatsServer" "ERP_storage/conf" "ERP_storage/models/Account" "ERP_storage/models/Basic" "ERP_storage/models/Percentage" "ERP_storage/models/Stock" "fmt" userlibs "git.baozhida.cn/ERP_libs/User" "git.baozhida.cn/ERP_libs/lib" "github.com/beego/beego/v2/adapter/orm" beego "github.com/beego/beego/v2/server/web" "math" "strconv" ) type BasicController struct { beego.Controller User userlibs.User } func (c *BasicController) Prepare() { c.User = *Account.User_r } func (c *BasicController) Depot_List() { // 分页参数 初始化 page, _ := c.GetInt("page") if page < 1 { page = 1 } page_z, _ := c.GetInt("page_z") if page_z < 1 { page_z = conf.Page_size } // 查询 T_name := c.GetString("T_name") R_List, R_cnt := Basic.Read_Depot_List(T_name, page, page_z) var r_jsons lib.R_JSONS r_jsons.Num = R_cnt r_jsons.Data = R_List r_jsons.Page = page r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z))) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } func (c *BasicController) Depot_Add() { T_name := c.GetString("T_name") var_ := Basic.Depot{ T_name: T_name, T_State: 1, } Id, err := Basic.Add_Depot(var_) if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "仓库", "添加", var_) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id} c.ServeJSON() return } func (c *BasicController) Depot_Edit() { T_id, _ := c.GetInt("T_id") T_name := c.GetString("T_name") Depot_r, err := Basic.Read_Depot_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"} c.ServeJSON() return } if len(T_name) > 0 { Depot_r.T_name = T_name } if err = Basic.Update_Depot(Depot_r, "T_name"); err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "仓库", "修改", Depot_r) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } func (c *BasicController) Depot_Del() { T_id, _ := c.GetInt("T_id") Depot_r, err := Basic.Read_Depot_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"} c.ServeJSON() return } StockDao := Stock.NewStock(orm.NewOrm()) count := StockDao.Read_Stock_Count_ByT_depot_id(Depot_r.Id) if count > 0 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "该仓库库存不为空,禁止删除!"} c.ServeJSON() return } if err = Basic.Delete_Depot(Depot_r); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "仓库", "删除", strconv.Itoa(T_id)) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 产品型号 func (c *BasicController) ProductModel_List() { // 查询 T_name := c.GetString("T_name") c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Basic.Read_ProductModel_List(T_name)} c.ServeJSON() return } func (c *BasicController) ProductName_List() { // 查询 T_name := c.GetString("T_name") T_class, _ := c.GetInt("T_class") c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Basic.Read_ProductName_List(T_name, T_class)} c.ServeJSON() return } // 产品规格 func (c *BasicController) ProductSpec_List() { // 查询 T_name := c.GetString("T_name") c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Basic.Read_ProductSpec_List(T_name)} c.ServeJSON() return } func (c *BasicController) ProductClass_List() { // 分页参数 初始化 page, _ := c.GetInt("page") if page < 1 { page = 1 } page_z, _ := c.GetInt("page_z") if page_z < 1 { page_z = conf.Page_size } // 查询 T_name := c.GetString("T_name") R_List, R_cnt := Basic.Read_ProductClass_List(T_name, page, page_z) var r_jsons lib.R_JSONS r_jsons.Num = R_cnt r_jsons.Data = R_List r_jsons.Page = page r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z))) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } func (c *BasicController) ProductClass_Add() { T_name := c.GetString("T_name") var_ := Basic.ProductClass{ T_name: T_name, T_State: 1, } Id, err := Basic.Add_ProductClass(var_) if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "仓库", "添加", var_) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id} c.ServeJSON() return } func (c *BasicController) ProductClass_Edit() { T_id, _ := c.GetInt("T_id") T_name := c.GetString("T_name") ProductClass_r, err := Basic.Read_ProductClass_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"} c.ServeJSON() return } if len(T_name) > 0 { ProductClass_r.T_name = T_name } if err = Basic.Update_ProductClass(ProductClass_r, "T_name"); err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "仓库", "修改", ProductClass_r) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } func (c *BasicController) ProductClass_Del() { T_id, _ := c.GetInt("T_id") ProductClass_r, err := Basic.Read_ProductClass_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"} c.ServeJSON() return } if err = Basic.Delete_ProductClass(ProductClass_r); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "仓库", "删除", strconv.Itoa(T_id)) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } func (c *BasicController) Product_List() { // 分页参数 初始化 page, _ := c.GetInt("page") if page < 1 { page = 1 } page_z, _ := c.GetInt("page_z") if page_z < 1 { page_z = conf.Page_size } // 查询 T_name := c.GetString("T_name") T_model := c.GetString("T_model") T_class, _ := c.GetInt("T_class") T_VerifyContract, _ := c.GetInt("T_VerifyContract") R_List, R_cnt := Basic.Read_Product_List(T_name, T_model, T_class, T_VerifyContract, page, page_z) var r_jsons lib.R_JSONS r_jsons.Num = R_cnt r_jsons.Data = R_List r_jsons.Page = page r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z))) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } func (c *BasicController) Product_Add() { T_name := c.GetString("T_name") T_class, _ := c.GetInt("T_class") T_model := c.GetString("T_model") T_spec := c.GetString("T_spec") T_relation_sn, _ := c.GetInt("T_relation_sn") T_price, _ := c.GetFloat("T_price") T_img := c.GetString("T_img") T_remark := c.GetString("T_remark") if len(T_name) == 0 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "产品名称不能为空!"} c.ServeJSON() return } product, err := Basic.Read_Product_ByT_name(T_name, T_model, T_spec) if err != nil && err.Error() != orm.ErrNoRows.Error() { c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"} c.ServeJSON() return } if product.Id > 0 { c.Data["json"] = lib.JSONS{Code: 203, Msg: "该产品已存在"} c.ServeJSON() return } var_ := Basic.Product{ T_name: T_name, T_class: T_class, T_model: T_model, T_spec: T_spec, T_price: float32(T_price), T_relation_sn: T_relation_sn, T_img: T_img, T_remark: T_remark, T_State: 1, } Id, err := Basic.Add_Product(var_) if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "产品", "添加", var_) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id} c.ServeJSON() return } func (c *BasicController) Product_Edit() { T_id, _ := c.GetInt("T_id") T_name := c.GetString("T_name") T_class, _ := c.GetInt("T_class") T_model := c.GetString("T_model") T_spec := c.GetString("T_spec") T_price, _ := c.GetFloat("T_price") T_relation_sn, _ := c.GetInt("T_relation_sn") T_img := c.GetString("T_img") T_remark := c.GetString("T_remark") Product_r, err := Basic.Read_Product_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"} c.ServeJSON() return } if len(T_name) > 0 { Product_r.T_name = T_name } if T_class > 0 { Product_r.T_class = T_class } if len(T_model) > 0 { Product_r.T_model = T_model } if len(T_spec) > 0 { Product_r.T_spec = T_spec } if T_relation_sn > 0 { Product_r.T_relation_sn = T_relation_sn } if len(T_img) > 0 { Product_r.T_img = T_img } if len(T_remark) > 0 { Product_r.T_remark = T_remark } if T_price > 0 { Product_r.T_price = float32(T_price) } if err = Basic.Update_Product(Product_r, "T_name", "T_class", "T_model", "T_spec", "T_price", "T_relation_sn", "T_img", "T_remark"); err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"} c.ServeJSON() return } // 修改库存关联的产品信息 StockDao := Stock.NewStock(orm.NewOrm()) list, err := StockDao.Read_Stock_List_ByT_product_id(T_id) for _, v := range list { v.T_product_class = Product_r.T_class v.T_product_name = Product_r.T_name v.T_product_model = Product_r.T_model StockDao.Update_Stock(v, "T_product_class", "T_product_name", "T_product_model") } // 修改月度统计信息 // 修改库存关联的产品信息 StockMonthDao := Stock.NewStockMonth(orm.NewOrm()) stockMonthList, err := StockMonthDao.Read_StockMonth_ByT_product_id(T_id) for _, v := range stockMonthList { v.T_product_class = Product_r.T_class StockMonthDao.Update_StockMonth(v, "T_product_class") } NatsServer.AddUserLogs(c.User.T_uuid, "产品", "修改", Product_r) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } func (c *BasicController) Product_Del() { T_id, _ := c.GetInt("T_id") Product_r, err := Basic.Read_Product_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"} c.ServeJSON() return } if err = Basic.Delete_Product(Product_r); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "产品", "删除", strconv.Itoa(T_id)) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id} c.ServeJSON() return } // 修改产品排序 func (c *BasicController) Product_Edit_Sort() { T_id, _ := c.GetInt("T_id") T_sort, _ := c.GetInt("T_sort") Product_r, err := Basic.Read_Product_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"} c.ServeJSON() return } Product_r.T_sort = T_sort if err = Basic.Update_Product(Product_r, "T_sort"); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "产品", "修改排序", Product_r) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 验证项目 func (c *BasicController) VerifyItem_List() { // 分页参数 初始化 page, _ := c.GetInt("page") if page < 1 { page = 1 } page_z, _ := c.GetInt("page_z") if page_z < 1 { page_z = conf.Page_size } // 查询 T_type, _ := c.GetInt("T_type") T_name := c.GetString("T_name") R_List, R_cnt := Basic.Read_VerifyItem_List(T_type, T_name, page, page_z) var r_jsons lib.R_JSONS r_jsons.Num = R_cnt r_jsons.Data = R_List r_jsons.Page = page r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z))) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } func (c *BasicController) VerifyItem_Add() { T_name := c.GetString("T_name") T_type, _ := c.GetInt("T_type") T_price, _ := c.GetFloat("T_price") var_ := Basic.VerifyItem{ T_name: T_name, T_type: T_type, T_price: float32(T_price), T_State: 1, } VerifyItem_r, err := Basic.Read_VerifyItem_ByT_nameT_type(T_name, T_type) if err != nil && err.Error() != orm.ErrNoRows.Error() { c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"} c.ServeJSON() return } if VerifyItem_r.Id > 0 { c.Data["json"] = lib.JSONS{Code: 203, Msg: fmt.Sprintf("【%s】项目已存在", T_name)} c.ServeJSON() return } Id, err := Basic.Add_VerifyItem(var_) if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "提成验证项目", "添加", var_) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id} c.ServeJSON() return } func (c *BasicController) VerifyItem_Edit() { T_id, _ := c.GetInt("T_id") T_name := c.GetString("T_name") T_type, _ := c.GetInt("T_type") T_price, _ := c.GetFloat("T_price") VerifyItem_r, err := Basic.Read_VerifyItem_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"} c.ServeJSON() return } VerifyItem_r2, err := Basic.Read_VerifyItem_ByT_nameT_type(T_name, T_type) if err != nil && err.Error() != orm.ErrNoRows.Error() { c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"} c.ServeJSON() return } if VerifyItem_r2.Id != VerifyItem_r.Id && VerifyItem_r2.Id > 0 { c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("【%s】项目已存在", T_name)} c.ServeJSON() return } cnt, err := Percentage.Get_Percentage_Count_ByVerifyItemId(VerifyItem_r.Id) if VerifyItem_r2.Id != VerifyItem_r.Id && VerifyItem_r2.Id > 0 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询提成项目统计失败"} c.ServeJSON() return } if VerifyItem_r.T_price != float32(T_price) && cnt > 0 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "有未处理的提成项目,无法修改"} c.ServeJSON() return } if len(T_name) > 0 { VerifyItem_r.T_name = T_name } if T_type > 0 { VerifyItem_r.T_type = T_type } if T_price > 0 { VerifyItem_r.T_price = float32(T_price) } if err = Basic.Update_VerifyItem(VerifyItem_r, "T_name", "T_type", "T_price"); err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "提成验证项目", "修改", VerifyItem_r) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } func (c *BasicController) VerifyItem_Del() { T_id, _ := c.GetInt("T_id") VerifyItem_r, err := Basic.Read_VerifyItem_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"} c.ServeJSON() return } if err = Basic.Delete_VerifyItem(VerifyItem_r); err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "提成验证项目", "删除", strconv.Itoa(T_id)) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return }