company_contract_permission.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package company_contract_permission
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CompanyContractPermission struct {
  7. Id int `orm:"column(id);pk" description:"客户合同id"`
  8. CompanyId int `description:"客户id"`
  9. CompanyContractId int `description:"合同id"`
  10. ChartPermissionId int `description:"权限id"`
  11. IsUpgrade int `description:"是否升级,1是,0否"`
  12. ExpensiveYx int `description:"权益研选: 0-3w; 1-5w"`
  13. StartDate string `description:"开始日期"`
  14. EndDate string `description:"结束日期"`
  15. CreateTime time.Time `description:"创建时间"`
  16. ModifyTime time.Time `description:"修改时间"`
  17. ContractType string `description:"签约合同时,当前行业类型:枚举值:'行业新签','行业续约'"`
  18. PermissionName string `description:"权限名称"`
  19. Points float64 `description:"研选扣点包点数"`
  20. }
  21. // 获取合同对应的权限列表
  22. func GetCompanyContractPermissionList(condition string, pars []interface{}) (items []*CompanyContractPermission, err error) {
  23. o := orm.NewOrm()
  24. sql := `SELECT * FROM company_contract_permission WHERE 1 = 1 `
  25. if condition != "" {
  26. sql += condition
  27. }
  28. _, err = o.Raw(sql, pars).QueryRows(&items)
  29. return
  30. }
  31. // UpdateCompanyContractPermissionMulti 批量修改
  32. func UpdateCompanyContractPermissionMulti(items []*CompanyContractPermission) (err error) {
  33. o, err := orm.NewOrm().Begin()
  34. if err != nil {
  35. return
  36. }
  37. defer func() {
  38. if err == nil {
  39. o.Commit()
  40. } else {
  41. o.Rollback()
  42. }
  43. }()
  44. //批量修改公司
  45. p, err := o.Raw("UPDATE company_contract_permission SET permission_name = ? ,contract_type = ? WHERE id = ?").Prepare()
  46. if err != nil {
  47. return
  48. }
  49. defer func() {
  50. _ = p.Close() // 别忘记关闭 statement
  51. }()
  52. for _, v := range items {
  53. _, err = p.Exec(v.PermissionName, v.ContractType, v.Id)
  54. if err != nil {
  55. return
  56. }
  57. }
  58. return
  59. }