Files
esun3d/app/code/Esun/Reward/Block/Adminhtml/Customer/Reward.php
T
2026-09-15 10:35:56 +08:00

27 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Esun\Reward\Block\Adminhtml\Customer;
use Esun\Reward\Model\BalanceManager;
use Esun\Reward\Model\TierResolver;
use Magento\Backend\Block\Template;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Esun\Reward\Model\Config;
class Reward extends Template
{
protected $_template = 'Esun_Reward::customer/reward.phtml';
public function __construct(Template\Context $context, private readonly CustomerRepositoryInterface $customers, private readonly BalanceManager $balanceManager, private readonly TierResolver $tierResolver, private readonly Config $config, array $data = []) { parent::__construct($context, $data); }
public function getCustomerId(): int { return (int)$this->getRequest()->getParam('id'); }
public function getRewardData(): array
{
$customerId = $this->getCustomerId(); if ($customerId <= 0) { return []; }
$customer = $this->customers->getById($customerId); $account = $this->balanceManager->getAccount($customerId, (int)$customer->getWebsiteId());
$account['tier'] = $this->tierResolver->resolveEffective((string)$account['tier_code'], (float)$account['lifetime_spend_base']); return $account;
}
public function getTransactions(): array { return $this->getCustomerId() > 0 ? $this->balanceManager->getTransactions($this->getCustomerId(), 20) : []; }
public function getAdjustUrl(): string { return $this->getUrl('esun_reward/customer/adjust'); }
public function getSocialPoints(): int { return $this->config->socialPoints(); }
}