| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace Longyi\RewardPoints\Console\Commands;
- use Illuminate\Console\Command;
- use Longyi\RewardPoints\Repositories\RewardPointRepository;
- use Longyi\RewardPoints\Models\RewardActiveRule;
- use Webkul\Customer\Models\Customer;
- class TestRegistrationPoints extends Command
- {
- protected $signature = 'reward-points:test-registration {email?}';
- protected $description = 'Test registration points for a customer';
- protected $rewardPointRepository;
- public function __construct(RewardPointRepository $rewardPointRepository)
- {
- parent::__construct();
- $this->rewardPointRepository = $rewardPointRepository;
- }
- public function handle()
- {
- $email = $this->argument('email');
- if (!$email) {
- // 获取最后一个注册的客户
- $customer = Customer::orderBy('id', 'desc')->first();
- } else {
- $customer = Customer::where('email', $email)->first();
- }
- if (!$customer) {
- $this->error('Customer not found!');
- return 1;
- }
- $this->info("Testing registration points for customer: {$customer->name} ({$customer->email})");
- $this->info("Customer ID: {$customer->id}");
- // 检查是否有注册规则
- $registrationRule = RewardActiveRule::where('type_of_transaction', RewardActiveRule::TYPE_REGISTRATION)
- ->where('status', 1)
- ->first();
- if ($registrationRule) {
- $this->info("Found registration rule:");
- $this->table(
- ['ID', 'Name', 'Points', 'Status'],
- [[
- $registrationRule->id,
- $registrationRule->name,
- $registrationRule->reward_point,
- $registrationRule->status ? 'Active' : 'Inactive'
- ]]
- );
- } else {
- $this->warn("No active registration rule found. Using config value.");
- $pointsFromConfig = config('rewardpoints.registration.points_per_registration', 100);
- $this->info("Points from config: {$pointsFromConfig}");
- }
- // 手动触发注册积分
- $this->info("\nManually adding registration points...");
- try {
- $event = new \stdClass();
- $event->id = $customer->id;
- $listener = new \Longyi\RewardPoints\Listeners\CustomerEvents($this->rewardPointRepository);
- $listener->handleCustomerRegistration($customer);
- $this->info("✓ Points added successfully!");
- // 显示当前积分
- $currentPoints = $this->rewardPointRepository->getCustomerPoints($customer->id);
- $this->info("Current points balance: {$currentPoints}");
- } catch (\Exception $e) {
- $this->error("Error: " . $e->getMessage());
- $this->error($e->getTraceAsString());
- return 1;
- }
- return 0;
- }
- }
|