base_ent_wait_empower.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package entity
  2. import (
  3. "strings"
  4. . "app.yhyue.com/moapp/jybase/common"
  5. . "app.yhyue.com/moapp/jybase/date"
  6. . "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/db"
  7. )
  8. var Base_ent_wait_empower = base_ent_wait_empower{}
  9. //企业授权表
  10. type base_ent_wait_empower struct {
  11. Id int64
  12. Appid string
  13. Goods_spec_power_id int64 //商品规格权益id
  14. Function_code string //功能代码
  15. Ent_id int64 //企业id
  16. Start_time string //开始时间
  17. End_time string //结束时间
  18. Empower_count int64 //授权数量
  19. Limit_strategy string //限制频率;1d:1天 1m:1个月
  20. }
  21. //根据商品规格获取待授权记录
  22. func (b *base_ent_wait_empower) WaitEmpowersBySpecId(appid string, spec_id, ent_id int64) *[]*base_ent_wait_empower {
  23. list := Mysql_BaseService.SelectBySql(`SELECT c.* FROM base_goods_spec a
  24. INNER JOIN base_goods_spec_power b ON (a.id=? AND a.appid=? AND a.id=b.spec_id)
  25. INNER JOIN base_ent_wait_empower c ON (c.ent_id=? AND c.end_time>? AND b.id=c.goods_spec_power_id)`, spec_id, appid, ent_id, NowFormat(Date_Full_Layout))
  26. return JsonUnmarshal(list, &[]*base_ent_wait_empower{}).(*[]*base_ent_wait_empower)
  27. }
  28. //根据功能代码获取待授权记录
  29. func (b *base_ent_wait_empower) WaitEmpowers(appid, function_code string, ent_id int64) *[]*base_ent_wait_empower {
  30. list := Mysql_BaseService.SelectBySql(`select * from base_ent_wait_empower where appid=? and function_code=? and ent_id=? and end_time>?`, appid, function_code, ent_id, NowFormat(Date_Full_Layout))
  31. return JsonUnmarshal(list, &[]*base_ent_wait_empower{}).(*[]*base_ent_wait_empower)
  32. }
  33. //所有待授权记录
  34. func (b *base_ent_wait_empower) AllWaitEmpowers(appid string, ent_id int64) *[]*base_ent_wait_empower {
  35. list := Mysql_BaseService.SelectBySql(`select * from base_ent_wait_empower where appid=? and ent_id=? and end_time>?`, appid, ent_id, NowFormat(Date_Full_Layout))
  36. return JsonUnmarshal(list, &[]*base_ent_wait_empower{}).(*[]*base_ent_wait_empower)
  37. }
  38. //校验功能代码
  39. func (b *base_ent_wait_empower) CheckFunctionCode(appid, function_code string, ent_id int64) bool {
  40. list := b.AllWaitEmpowers(appid, ent_id)
  41. if list == nil {
  42. return false
  43. }
  44. m := map[string]bool{}
  45. for _, v := range *list {
  46. m[v.Function_code] = true
  47. }
  48. for _, v := range strings.Split(function_code, ",") {
  49. if !m[v] {
  50. return false
  51. }
  52. }
  53. return true
  54. }
  55. //是否全部授权
  56. func (b *base_ent_wait_empower) IsAllEmpower(appid, function_code string, ent_id int64) bool {
  57. return Mysql_BaseService.CountBySql(`select count(1) as count from base_ent_wait_empower where appid=? and function_code=? and ent_id=? and end_time>? and empower_count=-1`, appid, function_code, ent_id, NowFormat(Date_Full_Layout)) > 0
  58. }