123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- package Reimburse
- import (
- "ERP_salary/logs"
- "ERP_salary/models/Account"
- "fmt"
- "git.baozhida.cn/ERP_libs/lib"
- "github.com/beego/beego/v2/adapter/orm"
- orm2 "github.com/beego/beego/v2/client/orm"
- "strconv"
- "strings"
- "time"
- )
- const (
- Delete int = iota
- WaitSubmit // 待提交审核
- WaitAudit // 待审核
- AuditPass // 审核通过
- AuditUnPass // 审核不通过
- RemitPart // 部分打款
- RemitAll // 全部打款
- )
- var (
- AuditMap = map[int]string{
- WaitSubmit: "待提交审核",
- WaitAudit: "待审核",
- AuditPass: "审核通过",
- AuditUnPass: "审核不通过",
- RemitPart: "部分打款",
- RemitAll: "全部打款",
- }
- )
- func Read_Audit_Get(Id int) string {
- v, ok := AuditMap[Id]
- if ok {
- return v
- } else {
- return "未知状态"
- }
- }
- // 报销
- type Reimburse struct {
- Id int `orm:"column(ID);size(11);auto;pk"`
- T_uid string `orm:"index;size(64);null"` // 用户uuid
- T_date string `orm:"size(64);null"` // 提交日期,2023-08-11
- T_money float32 `orm:"digits(12);decimals(2)"` // 报销总金额
- T_remit float32 `orm:"digits(12);decimals(2)"` // 打款金额
- T_State int `orm:"size(20);default(1)"` // 0 删除 1 未提交审核 2 待审核 3 审核通过 4 审核不通过 5 已部分打款 6 已全部打款
- T_remit_detials string `orm:"size(1024)"` // 打款明细 日期,打款金额|日期,打款金额|
- T_approval_money float32 `orm:"digits(12);decimals(2)"` // 审批金额
- CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
- UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"` //auto_now 每次 model 保存时都会对时间自动更新
- }
- func (t *Reimburse) TableName() string {
- return "reimburse"
- }
- type ReimburseDaoImpl struct {
- orm orm.Ormer
- }
- func NewReimburse(orm orm.Ormer) *ReimburseDaoImpl {
- return &ReimburseDaoImpl{orm: orm}
- }
- func init() {
- //注册模型
- orm.Debug = true
- orm.RegisterModel(new(Reimburse))
- }
- type Reimburse_R struct {
- Id int
- T_uid string // 用户uuid
- T_user_name string // 用户名称
- T_date string // 提交日期,2023-08-11
- T_money float32 // 报销总金额
- T_remit float32 // 打款金额
- T_approval_money float32 // 审批金额
- T_State int // 0 删除 1 未提交审核 2 待审核 3 审核通过 4 审核不通过 5 已部分打款 6 已全部打款
- }
- type RemitDetail_R struct {
- T_time string // 打款时间
- T_money float32 // 打款金额
- }
- type Reimburse_Detail struct {
- Id int
- T_uid string // 用户uuid
- T_user_name string // 用户名称
- T_date string // 提交日期,2023-08-11
- T_money float32 // 报销总金额
- T_remit float32 // 打款金额
- T_State int // 0 删除 1 未提交审核 2 待审核 3 审核通过 4 审核不通过 5 已部分打款 6 已全部打款
- T_approval_money float32 // 审批金额
- T_approval_opinion string // 审批意见
- T_reimburse_details []ReimburseDetails_R // 报销明细
- T_remit_detail []RemitDetail_R // 打款明细
- }
- // ---------------- 特殊方法 -------------------
- func ReimburseToReimburse_R(t Reimburse) (r Reimburse_R) {
- r.Id = t.Id
- r.T_uid = t.T_uid
- r.T_user_name = Account.Read_User_T_name_Get(t.T_uid)
- r.T_date = t.T_date
- r.T_money = t.T_money
- r.T_remit = t.T_remit
- r.T_State = t.T_State
- r.T_approval_money = t.T_approval_money
- return r
- }
- func ReimburseToReimburse_Detail(t Reimburse, T_reimburse_details []ReimburseDetails_R) (r Reimburse_Detail) {
- r.Id = t.Id
- r.T_uid = t.T_uid
- r.T_user_name = Account.Read_User_T_name_Get(t.T_uid)
- r.T_date = t.T_date
- r.T_money = t.T_money
- r.T_remit = t.T_remit
- r.T_State = t.T_State
- r.T_approval_money = t.T_approval_money
- r.T_reimburse_details = T_reimburse_details
- r.T_remit_detail = ReimburseToRemitDetail(t.T_remit_detials)
- return r
- }
- func ReimburseToRemitDetail(T_detail string) (r []RemitDetail_R) {
- if len(T_detail) == 0 {
- return
- }
- detailList := strings.Split(strings.Trim(T_detail, "|"), "|")
- for _, detail := range detailList {
- T_time := strings.Split(detail, ",")[0]
- T_money := lib.StringToFloat64TwoDecimal(strings.Split(detail, ",")[1])
- r = append(r, RemitDetail_R{
- T_time: T_time,
- T_money: float32(T_money),
- })
- }
- return r
- }
- func (dao *ReimburseDaoImpl) Read_Reimburse_ById(id int) (r Reimburse, err error) {
- o := orm.NewOrm()
- r = Reimburse{Id: id}
- err = o.Read(&r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return r, err
- }
- return r, err
- }
- // 添加
- func (dao *ReimburseDaoImpl) Add_Reimburse(m Reimburse) (id int64, err error) {
- o := orm.NewOrm()
- id, err = o.Insert(&m)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- return
- }
- // 修改
- func (dao *ReimburseDaoImpl) Update_Reimburse(m Reimburse, cols ...string) (id int64, err error) {
- o := orm.NewOrm()
- id, err = o.Update(&m, cols...)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- fmt.Println("Number of records updated in database:", id)
- return id, nil
- }
- // 删除
- func (dao *ReimburseDaoImpl) Delete_Reimburse(m Reimburse) (id int64, err error) {
- o := orm.NewOrm()
- m.T_State = Delete
- id, err = o.Update(&m, "T_State")
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- fmt.Println("Number of records updated in database:", id)
- return id, nil
- }
- // 获取列表
- func (dao *ReimburseDaoImpl) Read_Reimburse_List(T_uid string, page, page_z int) (r []Reimburse_R, cnt int64) {
- o := orm.NewOrm()
- // 也可以直接使用 Model 结构体作为表名
- var map_r []Reimburse
- qs := o.QueryTable(new(Reimburse))
- var offset int64
- if page <= 1 {
- offset = 0
- } else {
- offset = int64((page - 1) * page_z)
- }
- cond := orm.NewCondition()
- cond = cond.And("T_State__gt", Delete)
- if len(T_uid) > 0 {
- cond = cond.And("T_uid", T_uid)
- }
- var err error
- _, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&map_r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- cnt, err = qs.SetCond((*orm2.Condition)(cond)).Count()
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- for _, v := range map_r {
- r = append(r, ReimburseToReimburse_R(v))
- }
- return r, cnt
- }
- // 获取列表
- func (dao *ReimburseDaoImpl) Read_Reimburse_Finance_List(T_uuid string, page, page_z int) (r []Reimburse_R, cnt int64) {
- o := orm.NewOrm()
- // 也可以直接使用 Model 结构体作为表名
- var map_r []Reimburse
- qs := o.QueryTable(new(Reimburse))
- var offset int64
- if page <= 1 {
- offset = 0
- } else {
- offset = int64((page - 1) * page_z)
- }
- cond := orm.NewCondition()
- state := []int{WaitAudit, AuditPass, AuditUnPass, RemitPart, RemitAll}
- cond = cond.And("T_uid", T_uuid).And("T_State__in", state)
- var err error
- _, err = qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&map_r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- cnt, err = qs.SetCond((*orm2.Condition)(cond)).Count()
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- for _, v := range map_r {
- r = append(r, ReimburseToReimburse_R(v))
- }
- return r, cnt
- }
- func (dao *ReimburseDaoImpl) Read_T_uuid_List_by_State(state int) (lists []string) {
- o := orm.NewOrm()
- sql := "SELECT DISTINCT t_uid FROM reimburse WHERE t__state =" + strconv.Itoa(state) + " LIMIT 0,1000"
- _, err := o.Raw(sql).QueryRows(&lists)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- return lists
- }
- func (dao *ReimburseDaoImpl) Read_T_uuid_List() (lists []string) {
- o := orm.NewOrm()
- sql := "SELECT DISTINCT t_uid FROM reimburse LIMIT 0,1000"
- _, err := o.Raw(sql).QueryRows(&lists)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- return lists
- }
|