package controllers import ( "ERP_storage/Nats/NatsServer" "ERP_storage/conf" "ERP_storage/models/Account" "ERP_storage/models/Basic" "ERP_storage/models/Contract" "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" ) type PercentageController struct { beego.Controller User userlibs.User } func (c *PercentageController) Prepare() { c.User = *Account.User_r } // 财务管理列表 func (c *PercentageController) Percentage_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_uuid := c.GetString("T_uuid") T_state, _ := c.GetInt("T_state") userList, _ := NatsServer.Read_User_List_All() Account.Read_User_All_Map(userList) Contract.Read_Contract_All_Map() Contract.Read_VerifyContract_All_Map() PercentageDao := Percentage.NewPercentage(orm.NewOrm()) R_List, R_cnt := PercentageDao.Read_Percentage_List(T_name, T_uuid, T_state, 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 *PercentageController) Percentage_User_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_state, _ := c.GetInt("T_state") userList, _ := NatsServer.Read_User_List_All() Account.Read_User_All_Map(userList) Contract.Read_Contract_All_Map() Contract.Read_VerifyContract_All_Map() PercentageDao := Percentage.NewPercentage(orm.NewOrm()) R_List, R_cnt := PercentageDao.Read_Percentage_User_List(c.User.T_uuid, T_name, T_state, 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 *PercentageController) Percentage_Get() { // 查询 T_id, _ := c.GetInt("T_id") o := orm.NewOrm() PercentageDao := Percentage.NewPercentage(o) ContractDao := Contract.NewContract(o) DeviceDao := Stock.NewDevice(o) contractProductDao := Contract.NewContractProduct(o) percentage, err := PercentageDao.Read_Percentage_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"} c.ServeJSON() return } contract, err := ContractDao.Read_Contract_ByT_number(percentage.T_number) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同不存在!"} c.ServeJSON() return } productList := contractProductDao.Read_ContractProduct_List(contract.T_number) var pList []Contract.ContractProduct_R for _, v := range productList { p := Contract.ContractProductToContractProduct_R(v) p.T_device_list, _ = DeviceDao.Read_DeviceSn_List(contract.T_number, v.T_product_id, "", "") pList = append(pList, p) } userList, _ := NatsServer.Read_User_List_All() Account.Read_User_All_Map(userList) Contract.Read_VerifyContract_All_Map() Basic.Read_VerifyItem_All_Map() c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Percentage.PercentageToPercentage_Detail(percentage, contract, pList)} c.ServeJSON() return } func (c *PercentageController) Percentage_Add() { T_number := c.GetString("T_number") T_uuid := c.GetString("T_uuid") T_money, _ := c.GetFloat("T_money") // 总价 T_type, _ := c.GetInt("T_type") // 类型 T_item := c.GetString("T_item") if len(T_item) == 0 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "提成明细不能为空"} c.ServeJSON() return } var_ := Percentage.Percentage{ T_number: T_number, T_uuid: T_uuid, T_money: float32(T_money), T_type: T_type, //类型 1-验证实施 2-报告编写 T_State: 6, // 6-未提交审核 T_submit: c.User.T_uuid, T_item: T_item, } o := orm.NewOrm() ContractDao := Contract.NewContract(o) _, err := ContractDao.Read_Contract_ByT_number(T_number) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同不存在!"} c.ServeJSON() return } Basic.Read_VerifyItem_All_Map() o.Begin() PercentageDao := Percentage.NewPercentage(o) var T_type_str string if T_type == 1 { T_type_str = "验证实施" } if T_type == 2 { T_type_str = "报告编写" } _, err = PercentageDao.Read_Percentage_ByT_number_T_type(T_number, T_type) if err == nil { o.Rollback() c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("该合同已提交过%s提成申请", T_type_str)} c.ServeJSON() return } var_.T_item_price = Percentage.Generate_VerifyItem_Price(var_.T_item) var_.T_item = "|" + var_.T_item _, err = PercentageDao.Add_Percentage(var_) if err != nil { o.Rollback() c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"} c.ServeJSON() return } o.Commit() NatsServer.AddUserLogs(c.User.T_uuid, "提成", "添加", var_) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number} c.ServeJSON() return } func (c *PercentageController) Percentage_Approval() { T_id, _ := c.GetInt("T_id") T_item := c.GetString("T_item") T_state, _ := c.GetInt("T_state") T_approval_money, _ := c.GetFloat("T_approval_money") T_approval_opinion := c.GetString("T_approval_opinion") o := orm.NewOrm() PercentageDao := Percentage.NewPercentage(o) percentage, err := PercentageDao.Read_Percentage_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"} c.ServeJSON() return } // 未提交审核 不能修改 if percentage.T_State == Percentage.NotSubmit || percentage.T_State == Percentage.AuditPass || percentage.T_State == Percentage.RemitPart || percentage.T_State == Percentage.RemitAll { c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止提交!", Percentage.Read_Audit_Get(percentage.T_State))} c.ServeJSON() return } Basic.Read_VerifyItem_All_Map() if len(T_approval_opinion) > 0 { percentage.T_approval_opinion = T_approval_opinion } if T_approval_money > 0 { percentage.T_approval_money = float32(T_approval_money) } // 2-已通过 3-未通过 if T_state == 2 || T_state == 3 { percentage.T_State = T_state } if len(T_item) > 0 { percentage.T_item = T_item percentage.T_item_price = Percentage.Generate_VerifyItem_Price(percentage.T_item) } err = PercentageDao.Update_Percentage(percentage, "T_State", "T_approval_opinion", "T_approval_money", "T_item", "T_item_price") if err != nil { o.Rollback() c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"} c.ServeJSON() return } if T_state == Percentage.AuditPass { NatsServer.AddNews(percentage.T_uuid, fmt.Sprintf("【提成申请】您提交的提成申请(%s)审核已通过", percentage.T_number), conf.MyPercentageUrl) } if T_state == Percentage.AuditUnPass { NatsServer.AddNews(percentage.T_uuid, fmt.Sprintf("【提成申请】您提交的提成申请(%s)审核未通过", percentage.T_number), conf.MyPercentageUrl) } NatsServer.AddUserLogs(c.User.T_uuid, "提成", "审核", percentage) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id} c.ServeJSON() return } func (c *PercentageController) Percentage_Edit() { T_id, _ := c.GetInt("T_id") T_number := c.GetString("T_number") T_uuid := c.GetString("T_uuid") T_money, _ := c.GetFloat("T_money") // 总价 T_type, _ := c.GetInt("T_type") // 优惠价 T_item := c.GetString("T_item") if len(T_item) == 0 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "提成明细不能为空"} c.ServeJSON() return } var T_type_str string if T_type == 1 { T_type_str = "验证实施" } if T_type == 2 { T_type_str = "报告编写" } o := orm.NewOrm() ContractDao := Contract.NewContract(o) _, err := ContractDao.Read_Contract_ByT_number(T_number) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同不存在!"} c.ServeJSON() return } PercentageDao := Percentage.NewPercentage(o) percentage, err := PercentageDao.Read_Percentage_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"} c.ServeJSON() return } percentage1, err := PercentageDao.Read_Percentage_ByT_number_T_type(T_number, T_type) if err != nil && err.Error() != orm.ErrNoRows.Error() { c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"} c.ServeJSON() return } if percentage1.Id > 0 && percentage1.Id != percentage.Id { c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("该合同已提交过%s提成申请", T_type_str)} c.ServeJSON() return } // 1-待审核 2-审核通过 3-审核不通过 4-部分打款 5-全部打款 6-未提交审核 合同状态为未通过,修改之后将状态更改为待审核 if percentage.T_State == Percentage.AuditPass || percentage.T_State == Percentage.RemitPart || percentage.T_State == Percentage.RemitAll { c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止修改!", Percentage.Read_Audit_Get(percentage.T_State))} c.ServeJSON() return } if len(T_number) > 0 { percentage.T_number = T_number } if len(T_uuid) > 0 { percentage.T_uuid = T_uuid } if T_money > 0 { percentage.T_money = float32(T_money) } if T_type > 0 { percentage.T_type = T_type } if len(T_item) > 0 { percentage.T_item = "|" + T_item percentage.T_item_price = Percentage.Generate_VerifyItem_Price(T_item) } err = PercentageDao.Update_Percentage(percentage, "T_number", "T_uuid", "T_money", "T_type", "T_item", "T_item_price") if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "提成", "修改", percentage) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: percentage.Id} c.ServeJSON() return } func (c *PercentageController) Percentage_Del() { T_id, _ := c.GetInt("T_id") o := orm.NewOrm() PercentageDao := Percentage.NewPercentage(o) percentage, err := PercentageDao.Read_Percentage_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"} c.ServeJSON() return } // 1-待审核 2-审核通过 3-审核不通过 4-部分打款 5-全部打款 合同状态为未通过,修改之后将状态更改为待审核 if percentage.T_State == Percentage.AuditPass || percentage.T_State == Percentage.RemitPart || percentage.T_State == Percentage.RemitAll { c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止删除!", Percentage.Read_Audit_Get(percentage.T_State))} c.ServeJSON() return } err = PercentageDao.Delete_Percentage(percentage) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "提成", "删除", T_id) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id} c.ServeJSON() return } func (c *PercentageController) Percentage_Admin_Del() { T_id, _ := c.GetInt("T_id") o := orm.NewOrm() PercentageDao := Percentage.NewPercentage(o) percentage, err := PercentageDao.Read_Percentage_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"} c.ServeJSON() return } err = PercentageDao.Delete_Percentage(percentage) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "提成", "删除", T_id) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id} c.ServeJSON() return } // 打款 func (c *PercentageController) Percentage_Remit() { T_id, _ := c.GetInt("T_id") T_remit := c.GetString("T_remit") o := orm.NewOrm() PercentageDao := Percentage.NewPercentage(o) percentage, err := PercentageDao.Read_Percentage_ById(T_id) if err != nil { o.Rollback() c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"} c.ServeJSON() return } // 1-待审核 2-审核通过 3-审核不通过 4-部分打款 5-全部打款 合同状态为未通过,修改之后将状态更改为待审核 if percentage.T_State == 1 || percentage.T_State == 3 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "当前状态不可添加打款信息!"} c.ServeJSON() return } if len(T_remit) == 0 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "打款明细不能为空"} c.ServeJSON() return } if len(T_remit) > 0 { percentage.T_remit = T_remit } _, money := Percentage.PercentageToPercentageRemit_R(T_remit) // 部分打款 if percentage.T_approval_money > money && money > 0 { percentage.T_State = 4 } // 全部打款 if percentage.T_approval_money == money && money > 0 { percentage.T_State = 5 } err = PercentageDao.Update_Percentage(percentage, "T_remit", "T_State") if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"} c.ServeJSON() return } if percentage.T_State == 4 { NatsServer.AddNews(percentage.T_uuid, fmt.Sprintf("【提成申请】您提交的提成申请(%s)已部分打款", percentage.T_number), conf.MyPercentageUrl) } if percentage.T_State == 5 { NatsServer.AddNews(percentage.T_uuid, fmt.Sprintf("【提成申请】您提交的提成申请(%s)已全部打款", percentage.T_number), conf.MyPercentageUrl) } NatsServer.AddUserLogs(c.User.T_uuid, "提成", "修改", percentage) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: percentage.Id} c.ServeJSON() return } func (c *PercentageController) User_List() { var r_jsons lib.R_JSONS // 分页参数 初始化 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") ReimburseDao := Percentage.NewPercentage(orm.NewOrm()) uuidList := ReimburseDao.Read_T_uuid_List() if len(uuidList) == 0 { c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } R_List, R_cnt, err := NatsServer.Read_User_List_T_uuid(T_name, uuidList, page, page_z) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败"} c.ServeJSON() return } var U_List []userlibs.User for _, user := range R_List { U_List = append(U_List, user) } r_jsons.Num = R_cnt r_jsons.Data = U_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 *PercentageController) Contract_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") ContractDao := Contract.NewContract(orm.NewOrm()) R_List, R_cnt := ContractDao.Read_Contract_List("", T_name, 0, 0, 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 *PercentageController) Percentage_Submit_Audit() { T_id, _ := c.GetInt("T_id") o := orm.NewOrm() PercentageDao := Percentage.NewPercentage(o) percentage, err := PercentageDao.Read_Percentage_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "提交失败!"} c.ServeJSON() return } if percentage.T_State != 6 && percentage.T_State != 3 { c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止提交!", Percentage.Read_Audit_Get(percentage.T_State))} c.ServeJSON() return } // 1-待审核 2-审核通过 3-审核不通过 4-部分打款 5-全部打款 6-待审核 审核状态 percentage.T_State = 1 err = PercentageDao.Update_Percentage(percentage, "T_State") if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"} c.ServeJSON() return } NatsServer.AddNews(conf.FinanceUuid, fmt.Sprintf("【提成申请】您有一条提成申请(%s)待审核", percentage.T_number), conf.PercentageApprovalUrl) NatsServer.AddUserLogs(c.User.T_uuid, "提成", "审核", percentage) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id} c.ServeJSON() return }