AgentProfileService.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Services\Agent;
  3. use App\Models\Agent\Agent;
  4. /** 登录与个人信息共用的代理概要:类型、平台邀请地址、资金构成、合营方案或入股比例。不含实时保证金。 */
  5. class AgentProfileService
  6. {
  7. public function __construct(private AgentDomainService $domains, private AgentWalletService $wallets)
  8. {
  9. }
  10. public function summary(Agent $agent): array
  11. {
  12. $agent->loadMissing('profitCommissionProfile');
  13. $data = [
  14. 'id' => (int) $agent->id,
  15. 'username' => $agent->username,
  16. 'real_name' => $agent->real_name,
  17. 'language' => $agent->language ?? 'zh',
  18. 'invitation_code' => $agent->invitation_code,
  19. 'type' => (int) $agent->type,
  20. 'type_text' => $agent->type_text,
  21. 'withdraw_fee_rate' => (string) $agent->withdraw_fee_rate,
  22. 'has_withdraw_password' => (string) $agent->withdraw_password !== '',
  23. ] + $this->domains->format($agent) + $this->wallets->funds($agent);
  24. if ($agent->isJoint()) {
  25. $profile = $agent->profitCommissionProfile;
  26. $data['profit_commission_profile_id'] = $agent->profit_commission_profile_id;
  27. $data['profit_commission_profile'] = $profile;
  28. $data['required_margin_amount'] = $profile ? (string) $profile->margin_amount : null;
  29. $data['profit_active'] = (int) $agent->profit_active;
  30. $data['profit_active_text'] = (int) $agent->profit_active ? '分成中' : ($profile ? '保证金不足,暂停分成' : '未开通方案');
  31. }
  32. return $data;
  33. }
  34. }