diff --git a/src/super/dao/agent_invoice_dao.go b/src/super/dao/agent_invoice_dao.go new file mode 100644 index 0000000..3884b10 --- /dev/null +++ b/src/super/dao/agent_invoice_dao.go @@ -0,0 +1,16 @@ +package dao + +import "code.fnuoos.com/zhimeng/model.git/src/super/model" + +type AgentInvoiceDao interface { + GetAgentInvoice(settlementId int) (data *model.AgentInvoice, err error) + FindAgentInvoiceList(uuid, types string, page, limit int) (list []AgentInvoiceGroup, total int64, err error) +} +type AgentInvoiceGroup struct { + model.AgentInvoice `xorm:"extends"` + model.AgentSettlement `xorm:"extends"` +} + +func (AgentInvoiceGroup) TableName() string { + return "agent_invoice" +} diff --git a/src/super/dao/medium_invoice_dao.go b/src/super/dao/medium_invoice_dao.go new file mode 100644 index 0000000..b6dd72a --- /dev/null +++ b/src/super/dao/medium_invoice_dao.go @@ -0,0 +1,17 @@ +package dao + +import "code.fnuoos.com/zhimeng/model.git/src/super/model" + +type MediumInvoiceDao interface { + GetMediumInvoice(settlementId int) (data *model.MediumInvoice, err error) + GetMediumInvoiceById(id int) (data *model.MediumInvoice, err error) + FindMediumInvoiceList(uuid, types, mediumId string, page, limit int) (list []MediumInvoiceGroup, total int64, err error) +} +type MediumInvoiceGroup struct { + model.MediumInvoice `xorm:"extends"` + model.MediumSettlement `xorm:"extends"` +} + +func (MediumInvoiceGroup) TableName() string { + return "medium_invoice" +} diff --git a/src/super/implement/agent_invoice_db.go b/src/super/implement/agent_invoice_db.go new file mode 100644 index 0000000..26dc5b2 --- /dev/null +++ b/src/super/implement/agent_invoice_db.go @@ -0,0 +1,43 @@ +package implement + +import ( + "code.fnuoos.com/zhimeng/model.git/src/super/dao" + "code.fnuoos.com/zhimeng/model.git/src/super/model" + zhios_order_relate_logx "code.fnuoos.com/zhimeng/model.git/utils/logx" + "xorm.io/xorm" +) + +func NewAgentInvoiceDb(engine *xorm.Engine) dao.AgentInvoiceDao { + return &AgentInvoiceDb{Db: engine} +} + +type AgentInvoiceDb struct { + Db *xorm.Engine +} + +func (m AgentInvoiceDb) GetAgentInvoice(settlementId int) (data *model.AgentInvoice, err error) { + data = new(model.AgentInvoice) + has, err := m.Db.Where("settlement_id =?", settlementId).Get(data) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + if has == false { + return nil, nil + } + return data, nil +} +func (m AgentInvoiceDb) FindAgentInvoiceList(uuid, types string, page, limit int) (list []dao.AgentInvoiceGroup, total int64, err error) { + sess := m.Db.OrderBy("agent_invoice.update_at desc,agent_invoice.id desc").Limit(limit, (page-1)*limit) + if uuid != "" { + sess.And("agent_settlement.uuid = ?", uuid) + } + if types != "" { + sess.And("agent_invoice.type = ?", types) + } + sess.Join("LEFT", "agent_settlement", "agent_settlement.id = agent_invoice.settlement_id") + total, err = sess.FindAndCount(&list) + if err != nil { + return nil, 0, err + } + return +} diff --git a/src/super/implement/medium_invoice_db.go b/src/super/implement/medium_invoice_db.go new file mode 100644 index 0000000..2a5e721 --- /dev/null +++ b/src/super/implement/medium_invoice_db.go @@ -0,0 +1,58 @@ +package implement + +import ( + "code.fnuoos.com/zhimeng/model.git/src/super/dao" + "code.fnuoos.com/zhimeng/model.git/src/super/model" + zhios_order_relate_logx "code.fnuoos.com/zhimeng/model.git/utils/logx" + "xorm.io/xorm" +) + +func NewMediumInvoiceDb(engine *xorm.Engine) dao.MediumInvoiceDao { + return &MediumInvoiceDb{Db: engine} +} + +type MediumInvoiceDb struct { + Db *xorm.Engine +} + +func (m MediumInvoiceDb) GetMediumInvoice(settlementId int) (data *model.MediumInvoice, err error) { + data = new(model.MediumInvoice) + has, err := m.Db.Where("settlement_id =?", settlementId).Get(data) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + if has == false { + return nil, nil + } + return data, nil +} + +func (m MediumInvoiceDb) GetMediumInvoiceById(id int) (data *model.MediumInvoice, err error) { + data = new(model.MediumInvoice) + has, err := m.Db.Where("id =?", id).Get(data) + if err != nil { + return nil, zhios_order_relate_logx.Error(err) + } + if has == false { + return nil, nil + } + return data, nil +} +func (m MediumInvoiceDb) FindMediumInvoiceList(uuid, types, mediumId string, page, limit int) (list []dao.MediumInvoiceGroup, total int64, err error) { + sess := m.Db.OrderBy("medium_invoice.update_at desc,medium_invoice.id desc").Limit(limit, (page-1)*limit) + if uuid != "" { + sess.And("medium_settlement.uuid = ?", uuid) + } + if types != "" { + sess.And("medium_invoice.type = ?", types) + } + if mediumId != "" { + sess.And("medium_settlement.medium_id = ?", mediumId) + } + sess.Join("LEFT", "medium_settlement", "medium_settlement.id = medium_invoice.settlement_id") + total, err = sess.FindAndCount(&list) + if err != nil { + return nil, 0, err + } + return +}