recharge.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package service
  2. import (
  3. "errors"
  4. . "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/entity"
  5. )
  6. /*
  7. * 资源充值
  8. * @param appid
  9. * @param function_code 功能代码
  10. * @param account_id 账户id
  11. * @param ent_account_id 企业账户id
  12. * @param entId 企业id
  13. * @param count 充值数量
  14. * @param ids 业务id
  15. * @return 状态 0:失败 1:成功 -1:不在有效期内 -2:数量不足 -3:没有授权 -4:超额
  16. */
  17. func Recharge(appid, function_code string, account_id, ent_account_id int64, count int64, ids []string) (int64, error) {
  18. if appid == "" {
  19. return 0, errors.New("无效的参数appid")
  20. } else if function_code == "" {
  21. return 0, errors.New("无效的参数function_code")
  22. } else if count <= 0 {
  23. return 0, errors.New("无效的参数count")
  24. } else if account_id == 0 && ent_account_id == 0 {
  25. return 0, errors.New("无效的参数account_id、ent_account_id")
  26. }
  27. function := Base_function.FindByCode(appid, function_code)
  28. if function == nil {
  29. return 0, errors.New("功能原始表中没有找到该功能")
  30. }
  31. myPowers := Base_power.FindMyPowersByFc(appid, function_code, account_id, ent_account_id)
  32. if myPowers == nil || len(*myPowers) == 0 {
  33. return -1, errors.New("功能权益表中没有找到权益记录")
  34. }
  35. status := Base_resource_use.Recharge(appid, function_code, (*myPowers)[0].Id, account_id, count, ids)
  36. if status == 1 {
  37. return 1, nil
  38. } else if status == -1 {
  39. return -4, nil
  40. }
  41. return 0, nil
  42. }