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