123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package Company
- import (
- "Cold_Api/controllers/lib"
- "github.com/beego/beego/v2/adapter/orm"
- orm2 "github.com/beego/beego/v2/client/orm"
- "github.com/beego/beego/v2/core/logs"
- "time"
- )
- type CompanyBill struct {
- Id int `orm:"column(ID);size(11);auto;pk"`
- T_pid int `orm:"index;size(256);"` // Account.Company 绑定公司
- T_type string `orm:"size(256);"` // 扣费/充值
- T_project string `orm:"size(256);"` // 项目
- T_bill string `orm:"type(text);"` // 说明
- T_charging float32 `orm:"digits(12);decimals(2)"` // 金额
- T_balance float32 `orm:"digits(12);decimals(2)"` // 余额(扣费后)
- CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
- }
- func (t *CompanyBill) TableName() string {
- return "company_bill" // 数据库名称 // ************** 替换 DesignDeviceNotice **************
- }
- func init() {
- //注册模型
- orm.RegisterModel(new(CompanyBill))
- }
- func Add_CompanyBill(r CompanyBill) (id int64, err error) {
- o := orm.NewOrm()
- id, err = o.Insert(&r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return
- }
- return
- }
- func Read_CompanyBill_newest(T_pid int) (r CompanyBill, err error) {
- o := orm.NewOrm()
- qs := o.QueryTable(new(CompanyBill))
- cond := orm.NewCondition()
- cond = cond.And("T_pid", T_pid)
- var maps []CompanyBill
- _, err = qs.Limit(1, 0).SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&maps)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return r, err
- }
- if len(maps) == 0 {
- return
- }
- return maps[0], nil
- }
- func Read_CompanyBill_List(T_pid int, T_month string) (r []CompanyBill, err error) {
- o := orm.NewOrm()
- qs := o.QueryTable(new(CompanyBill))
- cond := orm.NewCondition()
- cond = cond.And("T_pid", T_pid).And("CreateTime__startswith", T_month)
- var maps []CompanyBill
- _, err = qs.SetCond((*orm2.Condition)(cond)).OrderBy("-Id").All(&maps)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return r, err
- }
- if len(maps) == 0 {
- return
- }
- return maps, nil
- }
|