123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615 |
- 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
- }
|