DeductionService.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Modules\InnerApi\Services;
  3. use App\Constants\RedisKeysConstant;
  4. use App\Models\Mysql\AgentModel;
  5. use App\Models\Mysql\ConfigModel;
  6. use App\Models\Mysql\UsersRulesModel;
  7. use Illuminate\Database\Eloquent\Builder;
  8. use Illuminate\Database\Eloquent\Model;
  9. use Illuminate\Support\Facades\Cache;
  10. class DeductionService
  11. {
  12. /**
  13. * 缓存时间
  14. * @var int
  15. */
  16. private $cacheTiem = 300;
  17. /**
  18. * 获取扣量配置
  19. * @param $agentUserId
  20. * @return mixed
  21. * @directions
  22. * 思路:1.如果渠道app是代理开出来的,那么就需要再查推广的规则配置
  23. * 2.如果渠道app是推广开出来的,那就只有一级直接把规则返回
  24. */
  25. public function rulesInfo($agentUserId)
  26. {
  27. $res = Cache::remember(
  28. RedisKeysConstant::CANNEL_USER_RULES.$agentUserId,
  29. $this->cacheTiem,
  30. function () {
  31. $data = ConfigModel::where(['sgroup' => 'sys', 'skey' => 'global_deduction_rules'])->first();
  32. $arrData = !empty($data->svalue) ? json_decode($data->svalue, true) : [];
  33. return ['deductionRule' => $arrData];
  34. }
  35. );
  36. return $res;
  37. }
  38. }