| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- package Account
- import (
- "ColdVerify_server/lib"
- "ColdVerify_server/logs"
- "github.com/beego/beego/v2/adapter/orm"
- orm2 "github.com/beego/beego/v2/client/orm"
- _ "github.com/go-sql-driver/mysql"
- "log"
- "time"
- )
- type UserSignature struct {
- Id int `orm:"column(ID);size(11);auto;pk"`
- T_Distributor_id string `orm:"size(256);null"` // 分销商id
- T_uuid string `orm:"size(256);null"` // 公司uuid
- T_name string `orm:"size(256);null"` // 姓名
- T_signature string `orm:"size(256);null"` // 签名
- T_State int `orm:"size(200);default(1)"` // 0删除 1正常
- CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now 每次 model 保存时都会对时间自动更新
- UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"` //auto_now_add 第一次保存时才设置时间
- }
- type UserSignature_R struct {
- Id int
- T_Distributor_id string
- T_Distributor_name string
- T_uuid string
- T_name string
- T_signature string
- }
- func (t *UserSignature) TableName() string {
- return "user_signature" // 数据库名称 // ************** 替换 FormulaList **************
- }
- func init() {
- //注册模型
- orm.RegisterModel(new(UserSignature))
- }
- // -------------------------------------------------------------
- func UserSignatureToUserSignature_R(T UserSignature, distributorMap map[string]string) (T_r UserSignature_R) {
- T_r.Id = T.Id
- T_r.T_uuid = T.T_uuid
- T_r.T_Distributor_id = T.T_Distributor_id
- T_Distributor_name, ok := distributorMap[T.T_Distributor_id]
- if !ok {
- T_Distributor_name = ""
- }
- T_r.T_Distributor_name = T_Distributor_name
- T_r.T_name = T.T_name
- T_r.T_signature = T.T_signature
- return T_r
- }
- // 获取 ById
- func Read_UserSignature_ById(id int) (r UserSignature, is bool) {
- o := orm.NewOrm()
- r = UserSignature{Id: id, T_State: 1}
- err := o.Read(&r, "T_State", "Id") // o.Read(&r,"Tokey") 如果不是 主键 就得指定字段名
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return r, false
- }
- return r, true
- }
- // 获取 By T_name
- func Read_UserSignatureByT_name(T_uuid, T_name string) (r UserSignature, is bool) {
- o := orm.NewOrm()
- qs := o.QueryTable(new(UserSignature))
- err := qs.Filter("T_uuid", T_uuid).Filter("T_name", T_name).Filter("T_State", 1).One(&r)
- if err != nil {
- return r, false
- }
- return r, true
- }
- // 添加
- func Add_UserSignature(r UserSignature) (id int64, is bool) {
- o := orm.NewOrm()
- id, err := o.Insert(&r)
- if err != nil {
- logs.Error(lib.FuncName(), err)
- return 0, false
- }
- return id, true
- }
- // 删除
- func Delete_UserSignature(v UserSignature) bool {
- o := orm.NewOrm()
- v.T_State = 0
- if num, err := o.Update(&v, "T_State"); err == nil {
- log.Println("Number of records updated in database:", num)
- } else {
- return false
- }
- return true
- }
- // 修改
- func Update_UserSignature(m UserSignature, cols ...string) bool {
- o := orm.NewOrm()
- if num, err := o.Update(&m, cols...); err == nil {
- log.Println("Number of records updated in database:", num)
- return true
- }
- return false
- }
- // 获取列表
- func Read_UserSignature_List(T_uuid string, T_name string, page int, page_z int, distributorMap map[string]string) ([]UserSignature_R, int64) {
- o := orm.NewOrm()
- // 也可以直接使用 Model 结构体作为表名
- var r []UserSignature
- qs := o.QueryTable(new(UserSignature))
- var offset int64
- if page <= 1 {
- offset = 0
- } else {
- offset = int64((page - 1) * page_z)
- }
- cond := orm.NewCondition()
- cond1 := cond.And("T_State", 1).And("T_uuid", T_uuid).AndCond(cond.Or("T_name__icontains", T_name))
- qs.Limit(page_z, offset).SetCond((*orm2.Condition)(cond1)).OrderBy("-Id").All(&r)
- cnt, _ := qs.SetCond((*orm2.Condition)(cond1)).Count()
- // 转换
- var UserSignature_r []UserSignature_R
- for _, v := range r {
- UserSignature_r = append(UserSignature_r, UserSignatureToUserSignature_R(v, distributorMap))
- }
- return UserSignature_r, cnt
- }
|