bianjunhui 6 dni temu
rodzic
commit
4a991b5bba

+ 188 - 0
packages/Longyi/RewardPoints/EXTENSION_GUIDE.md

@@ -0,0 +1,188 @@
+# 积分类型扩展指南
+
+## 概述
+
+积分系统已重构为配置化设计,新增积分类型只需修改一个文件,无需改动其他代码。
+
+## 核心文件
+
+- **配置文件**: `src/Config/TransactionType.php` - 统一管理所有积分类型
+- **模型类**: `src/Models/RewardActiveRule.php` - 引用配置类的常量
+
+## 新增积分类型步骤
+
+### 1. 在 TransactionType.php 中添加新类型
+
+```php
+class TransactionType
+{
+    // ... 现有类型 ...
+    
+    /**
+     * 新类型:例如“完成任务”
+     */
+    const TASK_COMPLETE = 10;  // 使用下一个可用的ID
+    
+    public static function all(): array
+    {
+        return [
+            // ... 现有类型配置 ...
+            
+            self::TASK_COMPLETE => [
+                'code' => 'task_complete',      // 唯一代码标识
+                'name' => '完成任务',            // 显示名称
+                'description' => '完成指定任务获得积分',  // 描述
+                'icon' => 'icon-task',          // 图标类名
+                'color' => 'cyan',              // 颜色主题
+            ],
+        ];
+    }
+}
+```
+
+**注意**:
+- 类型 ID `10` 已预留给“积分过期”,用于系统自动处理过期积分
+- 类型 ID `11` 已预留给“兑换礼品卡”,用于积分兑换功能
+- 类型 ID `99` 已预留给“管理员操作”,不应在规则中使用
+- 这些特殊类型不会出现在规则配置的下拉选项中
+- 如果需要排除某些类型不出现在规则配置中,可以使用 `getRuleTypes()` 方法
+
+### 2. 在 RewardActiveRule.php 中添加常量引用(保持向后兼容)
+
+```php
+class RewardActiveRule extends Model
+{
+    // ... 现有常量 ...
+    const TYPE_TASK_COMPLETE = TransactionType::TASK_COMPLETE;
+}
+```
+
+### 3. 创建对应的事件监听器(如需要)
+
+```php
+// src/Listeners/TaskEvents.php
+namespace Longyi\RewardPoints\Listeners;
+
+use Longyi\RewardPoints\Repositories\RewardPointRepository;
+use Longyi\RewardPoints\Models\RewardActiveRule;
+
+class TaskEvents
+{
+    protected $rewardPointRepository;
+
+    public function __construct(RewardPointRepository $rewardPointRepository)
+    {
+        $this->rewardPointRepository = $rewardPointRepository;
+    }
+
+    public function handleTaskComplete($event): void
+    {
+        // 获取任务完成规则
+        $rule = RewardActiveRule::active()
+            ->ofType(RewardActiveRule::TYPE_TASK_COMPLETE)
+            ->first();
+        
+        if (!$rule) {
+            return;
+        }
+        
+        // 检查规则是否适用
+        if (!$rule->isApplicableToCustomer($event->customer)) {
+            return;
+        }
+        
+        // 获取积分值
+        $points = $rule->getPointsForCustomer($event->customer);
+        
+        if ($points > 0) {
+            $this->rewardPointRepository->addPoints(
+                $event->customer->id,
+                RewardActiveRule::TYPE_TASK_COMPLETE,
+                $points,
+                null,
+                "完成任务: {$event->task_name}"
+            );
+        }
+    }
+}
+```
+
+### 4. 注册事件监听器
+
+在 `src/Providers/EventServiceProvider.php` 中注册:
+
+```php
+protected $listen = [
+    // ... 其他事件 ...
+    'App\Events\TaskCompleted' => [
+        'Longyi\RewardPoints\Listeners\TaskEvents@handleTaskComplete',
+    ],
+];
+```
+
+### 5. 在后台创建规则
+
+访问后台管理页面,创建新的积分规则:
+- 交易类型选择:"完成任务"
+- 设置积分值、客户群组等参数
+
+## 优势
+
+✅ **单一配置源**: 只需修改 `TransactionType.php`  
+✅ **向后兼容**: 保留原有常量引用方式  
+✅ **易于维护**: 类型信息集中管理  
+✅ **类型安全**: 提供完整的类型检查和验证方法  
+
+## 常用工具方法
+
+```php
+use Longyi\RewardPoints\Config\TransactionType;
+
+// 获取所有类型
+$allTypes = TransactionType::all();
+
+// 获取类型名称
+$name = TransactionType::getName(TransactionType::ORDER);  // "订单"
+
+// 获取类型代码
+$code = TransactionType::getCode(TransactionType::ORDER);  // "order"
+
+// 根据代码获取ID
+$id = TransactionType::getIdByCode('order');  // 3
+
+// 检查类型是否存在
+$exists = TransactionType::exists(3);  // true
+
+// 获取下拉选项
+$options = TransactionType::options();  // [1 => '签到', 2 => '注册', ...]
+```
+
+## 注意事项
+
+1. **ID 唯一性**: 确保新类型的 ID 不与现有类型冲突
+2. **Code 唯一性**: `code` 字段应该是唯一的英文标识符
+3. **数据库迁移**: 如果需要在数据库中存储新类型,确保 `type_of_transaction` 字段能容纳新值
+4. **缓存清理**: 修改后清除应用缓存以确保生效
+
+## 扩展示例:添加"游戏成就"类型
+
+```php
+// 1. 在 TransactionType.php 中添加
+const GAME_ACHIEVEMENT = 10;
+
+// 在 all() 方法中添加配置
+self::GAME_ACHIEVEMENT => [
+    'code' => 'game_achievement',
+    'name' => '游戏成就',
+    'description' => '完成游戏成就获得积分',
+],
+
+// 2. 在 RewardActiveRule.php 中添加
+const TYPE_GAME_ACHIEVEMENT = TransactionType::GAME_ACHIEVEMENT;
+
+// 3. 创建监听器处理游戏成就事件
+// 4. 注册事件
+// 5. 在后台创建规则
+```
+
+完成!无需修改任何其他代码。

+ 269 - 0
packages/Longyi/RewardPoints/src/Config/TransactionType.php

@@ -0,0 +1,269 @@
+<?php
+
+namespace Longyi\RewardPoints\Config;
+
+/**
+ * 积分交易类型配置类
+ * 
+ * 统一管理所有积分交易类型,避免硬编码
+ * 新增类型只需在此类中添加,无需修改其他代码
+ */
+class TransactionType
+{
+    /**
+     * 签到
+     */
+    const SIGN_IN = 1;
+    
+    /**
+     * 注册
+     */
+    const REGISTRATION = 2;
+    
+    /**
+     * 订单
+     */
+    const ORDER = 3;
+    
+    /**
+     * 评价
+     */
+    const REVIEW = 4;
+    
+    /**
+     * 推荐
+     */
+    const REFERRAL = 5;
+    
+    /**
+     * 生日
+     */
+    const BIRTHDAY = 6;
+    
+    /**
+     * 分享
+     */
+    const SHARE = 7;
+    
+    /**
+     * 订阅
+     */
+    const SUBSCRIBE = 8;
+    
+    /**
+     * 登录
+     */
+    const LOGIN = 9;
+    
+    /**
+     * 过期积分
+     */
+    const EXPIRED = 10;
+    
+    /**
+     * 兑换礼品卡
+     */
+    const GIFT_CARD_REDEEM = 11;
+    
+    /**
+     * 后台管理员修改
+     */
+    const ADMIN_ACTION = 99;
+
+    /**
+     * 获取所有类型配置
+     * 
+     * @return array [type_id => ['code' => string, 'name' => string, 'description' => string]]
+     */
+    public static function all(): array
+    {
+        return [
+            self::SIGN_IN => [
+                'code' => 'sign_in',
+                'name' => '签到',
+                'description' => '每日签到获得积分',
+                'icon' => 'icon-calendar',
+                'color' => 'blue',
+            ],
+            self::REGISTRATION => [
+                'code' => 'registration',
+                'name' => '注册',
+                'description' => '新用户注册奖励',
+                'icon' => 'icon-user',
+                'color' => 'green',
+            ],
+            self::ORDER => [
+                'code' => 'order',
+                'name' => '订单',
+                'description' => '下单消费获得积分',
+                'icon' => 'icon-shopping-cart',
+                'color' => 'blue',
+            ],
+            self::REVIEW => [
+                'code' => 'review',
+                'name' => '评价',
+                'description' => '商品评价奖励',
+                'icon' => 'icon-star',
+                'color' => 'yellow',
+            ],
+            self::REFERRAL => [
+                'code' => 'referral',
+                'name' => '推荐',
+                'description' => '推荐新用户奖励',
+                'icon' => 'icon-share',
+                'color' => 'indigo',
+            ],
+            self::BIRTHDAY => [
+                'code' => 'birthday',
+                'name' => '生日',
+                'description' => '生日礼物积分',
+                'icon' => 'icon-gift',
+                'color' => 'pink',
+            ],
+            self::SHARE => [
+                'code' => 'share',
+                'name' => '分享',
+                'description' => '分享商品或活动',
+                'icon' => 'icon-share-alt',
+                'color' => 'orange',
+            ],
+            self::SUBSCRIBE => [
+                'code' => 'subscribe',
+                'name' => '订阅',
+                'description' => '订阅邮件通讯',
+                'icon' => 'icon-envelope',
+                'color' => 'orange',
+            ],
+            self::LOGIN => [
+                'code' => 'login',
+                'name' => '登录',
+                'description' => '每日登录奖励',
+                'icon' => 'icon-login',
+                'color' => 'purple',
+            ],
+            self::EXPIRED => [
+                'code' => 'expired',
+                'name' => '积分过期',
+                'description' => '积分到期自动扣除',
+                'icon' => 'icon-clock',
+                'color' => 'red',
+            ],
+            self::GIFT_CARD_REDEEM => [
+                'code' => 'gift_card_redeem',
+                'name' => '兑换礼品卡',
+                'description' => '使用积分兑换礼品卡',
+                'icon' => 'icon-gift-card',
+                'color' => 'teal',
+            ],
+            self::ADMIN_ACTION => [
+                'code' => 'admin_action',
+                'name' => '管理员操作',
+                'description' => '后台管理员手动调整积分',
+                'icon' => 'icon-setting',
+                'color' => 'gray',
+            ],
+        ];
+    }
+    
+    /**
+     * 获取可用于规则配置的类型(排除管理员操作、过期、兑换等特殊类型)
+     * 
+     * @return array
+     */
+    public static function getRuleTypes(): array
+    {
+        $all = self::all();
+        // 排除特殊类型:管理员操作(99)、过期(10)、兑换礼品卡(11)
+        unset($all[self::ADMIN_ACTION]);
+        unset($all[self::EXPIRED]);
+        unset($all[self::GIFT_CARD_REDEEM]);
+        return $all;
+    }
+
+    /**
+     * 获取单个类型信息
+     * 
+     * @param int $typeId
+     * @return array|null
+     */
+    public static function get(int $typeId): ?array
+    {
+        $all = self::all();
+        return $all[$typeId] ?? null;
+    }
+
+    /**
+     * 根据 code 获取类型 ID
+     * 
+     * @param string $code
+     * @return int|null
+     */
+    public static function getIdByCode(string $code): ?int
+    {
+        foreach (self::all() as $id => $config) {
+            if ($config['code'] === $code) {
+                return $id;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 获取类型名称
+     * 
+     * @param int $typeId
+     * @return string
+     */
+    public static function getName(int $typeId): string
+    {
+        $info = self::get($typeId);
+        return $info['name'] ?? '未知类型';
+    }
+
+    /**
+     * 获取类型代码
+     * 
+     * @param int $typeId
+     * @return string
+     */
+    public static function getCode(int $typeId): string
+    {
+        $info = self::get($typeId);
+        return $info['code'] ?? 'unknown';
+    }
+
+    /**
+     * 检查类型是否存在
+     * 
+     * @param int $typeId
+     * @return bool
+     */
+    public static function exists(int $typeId): bool
+    {
+        return isset(self::all()[$typeId]);
+    }
+
+    /**
+     * 获取所有类型选项(用于下拉选择)
+     * 
+     * @return array [type_id => name]
+     */
+    public static function options(): array
+    {
+        $options = [];
+        foreach (self::all() as $id => $config) {
+            $options[$id] = $config['name'];
+        }
+        return $options;
+    }
+
+    /**
+     * 获取所有类型代码列表
+     * 
+     * @return array
+     */
+    public static function codes(): array
+    {
+        return array_column(self::all(), 'code');
+    }
+}

+ 5 - 3
packages/Longyi/RewardPoints/src/Http/Controllers/Admin/CustomerController.php

@@ -7,6 +7,7 @@ use Webkul\Admin\Http\Controllers\Controller;
 use Longyi\RewardPoints\Repositories\RewardPointRepository;
 use Longyi\RewardPoints\Models\RewardPointCustomer;
 use Longyi\RewardPoints\Models\RewardActiveRule;
+use Longyi\RewardPoints\Config\TransactionType;
 use Webkul\Customer\Models\Customer;
 use Carbon\Carbon;
 
@@ -125,10 +126,10 @@ class CustomerController extends Controller
             if ($action === 'add') {
                 $result = $this->rewardPointRepository->addPoints(
                     $customer->id,
-                    99, // 99 for admin action
+                    TransactionType::ADMIN_ACTION,
                     $points,
-                    null,
-                    "Admin: " . $reason
+                    "Admin: " . $reason,
+                    null
                 );
 
                 if ($result) {
@@ -140,6 +141,7 @@ class CustomerController extends Controller
                 $result = $this->rewardPointRepository->deductPoints(
                     $customer->id,
                     $points,
+                    TransactionType::ADMIN_ACTION,
                     null,
                     "Admin: " . $reason
                 );

+ 6 - 24
packages/Longyi/RewardPoints/src/Http/Controllers/Admin/RuleController.php

@@ -10,31 +10,13 @@ use Illuminate\Validation\Rule;
 use Illuminate\View\View;
 use Longyi\RewardPoints\Models\RewardActiveRule;
 use Longyi\RewardPoints\Repositories\RewardPointRepository;
+use Longyi\RewardPoints\Config\TransactionType;
 use Webkul\Admin\Http\Controllers\Controller;
 use Webkul\Core\Models\Channel;
 use Webkul\Customer\Models\CustomerGroup;
 
 class RuleController extends Controller
 {
-    /**
-     * Transaction type mapping with complete configuration
-     */
-    private const TRANSACTION_TYPES = [
-        3 => ['name' => 'Order', 'icon' => 'icon-shopping-cart', 'color' => 'blue'],
-        2 => ['name' => 'Registration', 'icon' => 'icon-user', 'color' => 'green'],
-        4 => ['name' => 'Product Review', 'icon' => 'icon-star', 'color' => 'yellow'],
-        9 => ['name' => 'Login', 'icon' => 'icon-calendar', 'color' => 'purple'],
-        5 => ['name' => 'Referral', 'icon' => 'icon-share', 'color' => 'indigo'],
-        6 => ['name' => 'Birthday', 'icon' => 'icon-gift', 'color' => 'pink'],
-        7 => ['name' => 'Share', 'icon' => 'icon-share-alt', 'color' => 'orange'],
-        8 => ['name' => 'Subscribe', 'icon' => 'icon-envelope', 'color' => 'orange'],
-    ];
-
-    /**
-     * Valid transaction type IDs
-     */
-    private const VALID_TRANSACTION_TYPES = [1, 2, 3, 4, 5, 6, 7, 8];
-
     /**
      * Color classes mapping for transaction types
      */
@@ -69,7 +51,7 @@ class RuleController extends Controller
             ->paginate(15);
 
         $customerGroupsList = $this->getCustomerGroups();
-        $transactionTypes = self::TRANSACTION_TYPES;
+        $transactionTypes = TransactionType::getRuleTypes();
         $colorClasses = self::COLOR_CLASSES;
 
         $view = $this->_config['view'] ?? 'rewardpoints::admin.rules.index';
@@ -85,7 +67,7 @@ class RuleController extends Controller
         $view = $this->_config['view'] ?? 'rewardpoints::admin.rules.create';
 
         return view($view, [
-            'transactionTypes' => self::TRANSACTION_TYPES,
+            'transactionTypes' => TransactionType::getRuleTypes(),
             'storeViews' => $this->getStoreViews(),
             'customerGroups' => $this->getCustomerGroups(),
             'colorClasses' => self::COLOR_CLASSES,
@@ -121,7 +103,7 @@ class RuleController extends Controller
 
         return view($view, [
             'rule' => $rule,
-            'transactionTypes' => self::TRANSACTION_TYPES,
+            'transactionTypes' => TransactionType::getRuleTypes(),
             'storeViews' => $this->getStoreViews(),
             'customerGroups' => $this->getCustomerGroups(),
             'selectedStoreViewsForSelect' => $selectedStoreViewsForSelect,
@@ -235,7 +217,7 @@ class RuleController extends Controller
     {
         $rules = [
             'rule_name' => 'required|string|max:255',
-            'type_of_transaction' => ['required', 'integer', Rule::in(self::VALID_TRANSACTION_TYPES)],
+            'type_of_transaction' => ['required', 'integer', Rule::in(array_keys(TransactionType::getRuleTypes()))],
             'status' => 'required|boolean',
             'enable_different_points_by_group' => 'nullable|boolean',
             'expired_day' => 'nullable|integer|min:0',
@@ -254,7 +236,7 @@ class RuleController extends Controller
     {
         $rules = [
             'rule_name' => 'required|string|max:255',
-            'type_of_transaction' => ['required', 'integer', Rule::in(self::VALID_TRANSACTION_TYPES)],
+            'type_of_transaction' => ['required', 'integer', Rule::in(array_keys(TransactionType::getRuleTypes()))],
             'status' => 'required|boolean',
             'enable_different_points_by_group' => 'nullable|boolean',
             'default_expired' => 'nullable|boolean',

+ 3 - 15
packages/Longyi/RewardPoints/src/Http/Controllers/Admin/TransactionController.php

@@ -6,6 +6,7 @@ use Illuminate\Http\Request;
 use Webkul\Admin\Http\Controllers\Controller;
 use Longyi\RewardPoints\Models\RewardPointHistory;
 use Longyi\RewardPoints\Models\RewardPointCustomer;
+use Longyi\RewardPoints\Config\TransactionType;
 use Carbon\Carbon;
 use Maatwebsite\Excel\Facades\Excel;
 use Longyi\RewardPoints\Exports\TransactionsExport;
@@ -93,7 +94,7 @@ class TransactionController extends Controller
             'totalEarned',
             'totalRedeemed',
             'totalTransactions'
-        ));
+        ))->with('transactionTypes', TransactionType::all());
     }
 
     /**
@@ -158,19 +159,6 @@ class TransactionController extends Controller
                 'Status'
             ]);
 
-            $typeNames = [
-                3 => 'Order',
-                2 => 'Registration',
-                4 => 'Product Review',
-                1 => 'Daily Sign In',
-                5 => 'Referral',
-                6 => 'Birthday',
-                7 => 'Share',
-                8 => 'Subscribe',
-                9 => 'login',
-                99 => 'Admin Action'
-            ];
-
             $statusNames = [
                 0 => 'Pending',
                 1 => 'Completed',
@@ -184,7 +172,7 @@ class TransactionController extends Controller
                     $transaction->customer_id,
                     $transaction->customer ? $transaction->customer->first_name . ' ' . $transaction->customer->last_name : 'N/A',
                     $transaction->customer ? $transaction->customer->email : 'N/A',
-                    $typeNames[$transaction->type_of_transaction] ?? 'Unknown',
+                    TransactionType::getName($transaction->type_of_transaction),
                     $transaction->amount,
                     $transaction->balance,
                     $transaction->transaction_time,

+ 23 - 23
packages/Longyi/RewardPoints/src/Models/RewardActiveRule.php

@@ -3,20 +3,24 @@
 namespace Longyi\RewardPoints\Models;
 
 use Illuminate\Database\Eloquent\Model;
+use Longyi\RewardPoints\Config\TransactionType;
 use Webkul\Customer\Models\Customer;
 
 class RewardActiveRule extends Model
 {
-    // 定义交易类型常量
-    const TYPE_SIGN_IN = 1;
-    const TYPE_REGISTRATION = 2;
-    const TYPE_ORDER = 3;
-    const TYPE_REVIEW = 4;
-    const TYPE_REFERRAL = 5;
-    const TYPE_BIRTHDAY = 6;
-    const TYPE_SHARE = 7;
-    const TYPE_SUBSCRIBE = 8;
-    const TYPE_LOGIN = 9;
+    // 使用配置类中的常量(保持向后兼容)
+    const TYPE_SIGN_IN = TransactionType::SIGN_IN;
+    const TYPE_REGISTRATION = TransactionType::REGISTRATION;
+    const TYPE_ORDER = TransactionType::ORDER;
+    const TYPE_REVIEW = TransactionType::REVIEW;
+    const TYPE_REFERRAL = TransactionType::REFERRAL;
+    const TYPE_BIRTHDAY = TransactionType::BIRTHDAY;
+    const TYPE_SHARE = TransactionType::SHARE;
+    const TYPE_SUBSCRIBE = TransactionType::SUBSCRIBE;
+    const TYPE_LOGIN = TransactionType::LOGIN;
+    const TYPE_EXPIRED = TransactionType::EXPIRED;
+    const TYPE_GIFT_CARD_REDEEM = TransactionType::GIFT_CARD_REDEEM;
+    const TYPE_ADMIN_ACTION = TransactionType::ADMIN_ACTION;
 
     protected $table = 'mw_reward_active_rules';
     protected $primaryKey = 'rule_id';
@@ -184,19 +188,15 @@ class RewardActiveRule extends Model
      */
     public function getTransactionTypeTextAttribute(): string
     {
-        $types = [
-            self::TYPE_ORDER => 'Order',
-            self::TYPE_REGISTRATION => 'Registration',
-            self::TYPE_REVIEW => 'Product Review',
-            self::TYPE_LOGIN => 'Login',
-            self::TYPE_REFERRAL => 'Referral',
-            self::TYPE_BIRTHDAY => 'Birthday',
-            self::TYPE_SHARE => 'Share',
-            self::TYPE_SUBSCRIBE => 'Subscription',
-            self::TYPE_SIGN_IN => 'Sign In',
-        ];
-
-        return $types[$this->type_of_transaction] ?? 'Unknown';
+        return TransactionType::getName($this->type_of_transaction);
+    }
+    
+    /**
+     * 获取交易类型代码
+     */
+    public function getTransactionTypeCodeAttribute(): string
+    {
+        return TransactionType::getCode($this->type_of_transaction);
     }
 
     /**

+ 24 - 4
packages/Longyi/RewardPoints/src/Repositories/RewardPointRepository.php

@@ -204,7 +204,7 @@ class RewardPointRepository extends Repository
         }
     }
 
-    public function deductPoints($customerId, $amount, $orderId = null, $detail = null)
+    public function deductPoints($customerId, $amount, $type = 0, $detail = null, $orderId = null)
     {
         try {
             return DB::transaction(function () use ($customerId, $amount, $orderId, $detail) {
@@ -237,7 +237,7 @@ class RewardPointRepository extends Repository
                 // 创建历史记录
                 $history = $this->create([
                     'customer_id' => $customerId,
-                    'type_of_transaction' => 0,
+                    'type_of_transaction' => $type,
                     'amount' => -$amount,
                     'balance' => $newBalance,
                     'transaction_detail' => $detail,
@@ -296,17 +296,37 @@ class RewardPointRepository extends Repository
                         ->first();
 
                     if ($customerPoints && $customerPoints->mw_reward_point >= $history->point_remaining) {
-                        $customerPoints->mw_reward_point -= $history->point_remaining;
+                        $expiredAmount = $history->point_remaining;
+                        
+                        // 扣除用户总积分
+                        $customerPoints->mw_reward_point -= $expiredAmount;
                         $customerPoints->save();
 
+                        // 更新原历史记录状态为过期
                         $history->status = RewardPointHistory::STATUS_EXPIRED;
                         $history->point_remaining = 0;
                         $history->save();
 
+                        // 创建一条新的过期扣减记录
+                        $this->create([
+                            'customer_id' => $history->customer_id,
+                            'type_of_transaction' => \Longyi\RewardPoints\Config\TransactionType::EXPIRED,
+                            'amount' => -$expiredAmount,
+                            'balance' => (int) $customerPoints->mw_reward_point,
+                            'transaction_detail' => '积分过期自动扣除',
+                            'transaction_time' => Carbon::now(),
+                            'history_order_id' => 0,
+                            'expired_day' => 0,
+                            'expired_time' => null,
+                            'point_remaining' => 0,
+                            'check_time' => 1,
+                            'status' => RewardPointHistory::STATUS_COMPLETED
+                        ]);
+
                         Log::info('Expired points processed', [
                             'history_id' => $history->history_id,
                             'customer_id' => $history->customer_id,
-                            'points_expired' => $history->getOriginal('point_remaining')
+                            'points_expired' => $expiredAmount
                         ]);
                     }
                 });

+ 4 - 14
packages/Longyi/RewardPoints/src/Resources/views/admin/customers/show.blade.php

@@ -86,22 +86,12 @@
                     <tr class="hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors">
                         <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-300">
                             @php
-                                $typeNames = [
-                                    1 => 'Daily Sign In',
-                                    2 => 'Registration',
-                                    3 => 'Order',
-                                    4 => 'Product Review',
-                                    5 => 'Referral',
-                                    6 => 'Birthday',
-                                    7 => 'Share',
-                                    8 => 'Subscribe',
-                                    9 => 'Login',
-                                    99 => 'Admin Action'
-                                ];
+                                $typeInfo = \Longyi\RewardPoints\Config\TransactionType::get($record->type_of_transaction);
+                                $typeName = $typeInfo['name'] ?? 'Unknown';
                             @endphp
                             <span class="px-2 py-1 inline-flex text-xs leading-5 font-semibold rounded-full bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200">
-                                    {{ $typeNames[$record->type_of_transaction] ?? 'Unknown' }}
-                                </span>
+                                {{ $typeName }}
+                            </span>
                         </td>
                         <td class="px-6 py-4 whitespace-nowrap text-sm">
                                 <span class="font-semibold {{ $record->amount > 0 ? 'text-green-600 dark:text-green-400' : 'text-red-600 dark:text-red-400' }}">

+ 14 - 30
packages/Longyi/RewardPoints/src/Resources/views/admin/transactions/index.blade.php

@@ -103,16 +103,11 @@
                     class="flex w-full min-h-[39px] py-2 px-3 border border-gray-300 dark:border-gray-800 rounded-md text-sm text-gray-600 dark:text-gray-300 transition-all hover:border-gray-400 dark:hover:border-gray-400 focus:border-gray-400 dark:focus:border-gray-400"
                 >
                     <option value="">@lang('All Types')</option>
-                    <option value="3" {{ $transactionType == '3' ? 'selected' : '' }}>@lang('Order')</option>
-                    <option value="2" {{ $transactionType == '2' ? 'selected' : '' }}>@lang('Registration')</option>
-                    <option value="4" {{ $transactionType == '4' ? 'selected' : '' }}>@lang('Product Review')</option>
-                    <option value="1" {{ $transactionType == '1' ? 'selected' : '' }}>@lang('Daily Sign In')</option>
-                    <option value="5" {{ $transactionType == '5' ? 'selected' : '' }}>@lang('Referral')</option>
-                    <option value="6" {{ $transactionType == '6' ? 'selected' : '' }}>@lang('Birthday')</option>
-                    <option value="7" {{ $transactionType == '7' ? 'selected' : '' }}>@lang('Share')</option>
-                    <option value="8" {{ $transactionType == '8' ? 'selected' : '' }}>@lang('Subscribe')</option>
-                    <option value="9" {{ $transactionType == '9' ? 'selected' : '' }}>@lang('Login')</option>
-                    <option value="99" {{ $transactionType == '99' ? 'selected' : '' }}>@lang('Admin Action')</option>
+                    @foreach($transactionTypes as $typeId => $typeInfo)
+                        <option value="{{ $typeId }}" {{ $transactionType == $typeId ? 'selected' : '' }}>
+                            @lang($typeInfo['name'])
+                        </option>
+                    @endforeach
                 </select>
             </div>
 
@@ -259,27 +254,16 @@
                         </td>
                         <td class="px-6 py-4 whitespace-nowrap">
                             @php
-                                $typeNames = [
-                                        3 => 'Order',
-                                        2 => 'Registration',
-                                        4 => 'Product Review',
-                                        1 => 'Daily Sign In',
-                                        5 => 'Referral',
-                                        6 => 'Birthday',
-                                        7 => 'Share',
-                                        8 => 'Subscribe',
-                                        9 => 'login',
-                                        99 => 'Admin Action'
-                                    ];
+                                $typeInfo = \Longyi\RewardPoints\Config\TransactionType::get($transaction->type_of_transaction);
+                                $typeName = $typeInfo['name'] ?? 'Unknown';
+                                $typeColor = match ($transaction->amount > 0) {
+                                    true => 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200',
+                                    false => 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200',
+                                };
                             @endphp
-                            <span class="px-2 py-1 inline-flex text-xs leading-5 font-semibold rounded-full
-            @if($transaction->amount > 0)
-                bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200
-            @else
-                bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200
-            @endif">
-        @lang($typeNames[$transaction->type_of_transaction] ?? 'Unknown')
-    </span>
+                            <span class="px-2 py-1 inline-flex text-xs leading-5 font-semibold rounded-full {{ $typeColor }}">
+                                @lang($typeName)
+                            </span>
                         </td>
                         <td class="px-6 py-4 whitespace-nowrap text-sm">
                                 <span class="font-semibold

+ 3 - 2
packages/Longyi/RewardPoints/src/Services/CartRewardPoints.php

@@ -203,8 +203,9 @@ class CartRewardPoints
         $result = $this->rewardPointRepository->deductPoints(
             $customerId,
             $pointsUsed,
-            $order->id,
-            "Points redeemed for order #{$order->increment_id} (Discount: " . core()->formatPrice($discountAmount) . ")"
+            0,
+            "Points redeemed for order #{$order->increment_id} (Discount: " . core()->formatPrice($discountAmount) . ")",
+            $order->id
         );
         
         // Clear session