base_goods_function.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package entity
  2. import (
  3. "strings"
  4. . "app.yhyue.com/moapp/jybase/common"
  5. . "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/db"
  6. )
  7. var Base_goods_function = base_goods_function{}
  8. //商品功能表
  9. type base_goods_function struct {
  10. Id int64
  11. Appid string
  12. Goods_code string //商品代码
  13. Function_code string //功能代码
  14. Limit_strategy string //限制频率;1d:1天 1m:1个月
  15. Strategy_count int64 //频率数量
  16. Power_type int64 //权益所属类型;1:个人 2:企业
  17. Use_count int64 //使用数量
  18. Power_count int64 //授权数量;-1:默认对企业下所有人授权 0:不授权
  19. Base_function *base_function
  20. }
  21. //根据商品代码查找商品的功能明细
  22. func (b *base_goods_function) FindByGoodsCode(appid, goods_code string) *[]*base_goods_function {
  23. list := Mysql_BaseService.SelectBySql(`select a.id as a_id,a.appid as a_appid,a.goods_code as a_goods_code,a.function_code as a_function_code,a.limit_strategy as a_limit_strategy,a.strategy_count as a_strategy_count,a.power_type as a_power_type,a.use_count as a_use_count,a.power_count as a_power_count,
  24. b.id as b_id,b.appid as b_appid,b.name as b_name,b.code as b_code,b.status as b_status,b.haspower as b_haspower,b.version as b_version,b.power_rule as b_power_rule,b.power_type as b_power_type
  25. from base_goods_function a inner join base_function b on (a.appid=? and a.goods_code=? and b.appid=? and a.function_code=b.code)`, appid, goods_code, appid)
  26. l := []*base_goods_function{}
  27. if list != nil {
  28. for _, v := range *list {
  29. a, b := map[string]interface{}{}, map[string]interface{}{}
  30. for kk, vv := range v {
  31. if strings.HasPrefix(kk, "a_") {
  32. a[strings.TrimPrefix(kk, "a_")] = vv
  33. } else if strings.HasPrefix(kk, "b_") {
  34. b[strings.TrimPrefix(kk, "b_")] = vv
  35. }
  36. }
  37. aa := JsonUnmarshal(a, &base_goods_function{}).(*base_goods_function)
  38. bb := JsonUnmarshal(b, &base_function{}).(*base_function)
  39. aa.Base_function = bb
  40. l = append(l, aa)
  41. }
  42. }
  43. return &l
  44. }