base_ent_wait_empower.go 2.8 KB

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