Browse Source

fix:商品

super-yimizi 14 hours ago
parent
commit
98464ca7fe

+ 83 - 7
application/admin/controller/commission/Config.php

@@ -4,6 +4,7 @@ namespace app\admin\controller\commission;
 
 
 use app\common\controller\Backend;
 use app\common\controller\Backend;
 use app\common\Service\ShopConfigService;
 use app\common\Service\ShopConfigService;
+use app\common\Enum\CommissionConfigEnum;
 use think\exception\PDOException;
 use think\exception\PDOException;
 use think\exception\ValidateException;
 use think\exception\ValidateException;
 /**
 /**
@@ -32,7 +33,29 @@ class Config extends Backend
     {
     {
         // 获取分销配置
         // 获取分销配置
         $commissionConfig = ShopConfigService::getConfigs('shop.commission');
         $commissionConfig = ShopConfigService::getConfigs('shop.commission');
-        $this->view->assign('commissionConfig', $commissionConfig ?: []);
+        
+        // 合并默认配置
+        $defaultConfig = CommissionConfigEnum::getDefaultConfig();
+        $commissionConfig = array_merge($defaultConfig, $commissionConfig ?: []);
+        
+        // 传递枚举数据给视图
+        $this->view->assign([
+            'commissionConfig' => $commissionConfig,
+            'levelList' => CommissionConfigEnum::$levelList,
+            'switchList' => CommissionConfigEnum::$switchList,
+            'checkList' => CommissionConfigEnum::$checkList,
+            'allowList' => CommissionConfigEnum::$allowList,
+            'upgradeCheckList' => CommissionConfigEnum::$upgradeCheckList,
+            'needFormList' => CommissionConfigEnum::$needFormList,
+            'showProtocolList' => CommissionConfigEnum::$showProtocolList,
+            'inviteLockList' => CommissionConfigEnum::$inviteLockList,
+            'becomeAgentList' => CommissionConfigEnum::$becomeAgentList,
+            'rewardTypeList' => CommissionConfigEnum::$rewardTypeList,
+            'rewardEventList' => CommissionConfigEnum::$rewardEventList,
+            'refundCommissionRewardList' => CommissionConfigEnum::$refundCommissionRewardList,
+            'refundCommissionOrderList' => CommissionConfigEnum::$refundCommissionOrderList
+        ]);
+        
         return $this->view->fetch();
         return $this->view->fetch();
     }
     }
     
     
@@ -46,7 +69,10 @@ class Config extends Backend
             $params = $this->request->post("row/a", [], 'trim');
             $params = $this->request->post("row/a", [], 'trim');
             
             
             if ($params) {
             if ($params) {
-                // try {
+                try {
+                    // 验证配置参数
+                    $this->validateConfigParams($params);
+                    
                     // 特殊处理某些配置项
                     // 特殊处理某些配置项
                     if (isset($params['become_agent']) && is_array($params['become_agent'])) {
                     if (isset($params['become_agent']) && is_array($params['become_agent'])) {
                         $params['become_agent'] = json_encode($params['become_agent'], JSON_UNESCAPED_UNICODE);
                         $params['become_agent'] = json_encode($params['become_agent'], JSON_UNESCAPED_UNICODE);
@@ -55,15 +81,65 @@ class Config extends Backend
                     // 更新配置
                     // 更新配置
                     ShopConfigService::setConfigs('shop.commission', $params);
                     ShopConfigService::setConfigs('shop.commission', $params);
                     $this->success('配置保存成功');
                     $this->success('配置保存成功');
-                // } catch (ValidateException $e) {
-                //     $this->error($e->getMessage());
-                // } catch (PDOException $e) {
-                //     $this->error($e->getMessage());
-                // } catch (\Exception $e) {
+                } catch (ValidateException $e) {
+                    $this->error($e->getMessage());
+                } catch (PDOException $e) {
+                    $this->error($e->getMessage());
+                } 
+                //catch (\Exception $e) {
                 //     $this->error($e->getMessage());
                 //     $this->error($e->getMessage());
                 // }
                 // }
             }
             }
             $this->error(__('Parameter %s can not be empty', ''));
             $this->error(__('Parameter %s can not be empty', ''));
         }
         }
     }
     }
+    
+    /**
+     * 验证配置参数
+     */
+    private function validateConfigParams($params)
+    {
+        // 验证分销层级
+        if (isset($params['level']) && !CommissionConfigEnum::isValidLevel($params['level'])) {
+            throw new ValidateException('分销层级参数无效');
+        }
+        
+        // 验证开关类型参数
+        $switchFields = ['self_buy', 'agent_check', 'upgrade_jump', 'upgrade_check', 'need_form', 'show_protocol'];
+        foreach ($switchFields as $field) {
+            if (isset($params[$field]) && !CommissionConfigEnum::isValidSwitch($params[$field])) {
+                throw new ValidateException("{$field}参数无效");
+            }
+        }
+        
+        // 验证锁定下级条件
+        if (isset($params['invite_lock']) && !CommissionConfigEnum::isValidInviteLock($params['invite_lock'])) {
+            throw new ValidateException('锁定下级条件参数无效');
+        }
+        
+        // 验证成为分销商条件
+        if (isset($params['become_agent']) && is_array($params['become_agent'])) {
+            if (isset($params['become_agent']['type']) && !CommissionConfigEnum::isValidBecomeAgent($params['become_agent']['type'])) {
+                throw new ValidateException('成为分销商条件参数无效');
+            }
+        }
+        
+        // 验证商品结算方式
+        if (isset($params['reward_type']) && !CommissionConfigEnum::isValidRewardType($params['reward_type'])) {
+            throw new ValidateException('商品结算方式参数无效');
+        }
+        
+        // 验证佣金结算方式
+        if (isset($params['reward_event']) && !CommissionConfigEnum::isValidRewardEvent($params['reward_event'])) {
+            throw new ValidateException('佣金结算方式参数无效');
+        }
+        
+        // 验证退款扣除设置
+        $refundFields = ['refund_commission_reward', 'refund_commission_order'];
+        foreach ($refundFields as $field) {
+            if (isset($params[$field]) && !CommissionConfigEnum::isValidSwitch($params[$field])) {
+                throw new ValidateException("{$field}参数无效");
+            }
+        }
+    }
 }
 }

+ 277 - 32
application/admin/controller/commission/Goods.php

@@ -7,6 +7,8 @@ use app\common\model\commission\CommissionGoods as CommissionGoodsModel;
 use app\common\model\Goods as GoodsModel;
 use app\common\model\Goods as GoodsModel;
 use app\common\model\commission\Level as LevelModel;
 use app\common\model\commission\Level as LevelModel;
 use app\common\Enum\CommissionGoodsEnum;
 use app\common\Enum\CommissionGoodsEnum;
+use app\common\Enum\GoodsEnum;
+use app\common\Service\ShopConfigService;
 use think\Db;
 use think\Db;
 
 
 class Goods extends Backend
 class Goods extends Backend
@@ -15,6 +17,16 @@ class Goods extends Backend
     protected $goodsModel;
     protected $goodsModel;
     
     
     /**
     /**
+     * 无需登录的方法,同时也就无需鉴权了
+     */
+    protected $noNeedLogin = [];
+    
+    /**
+     * 无需鉴权的方法,但需要登录
+     */
+    protected $noNeedRight = ['commission', 'detail'];
+    
+    /**
      * 快速搜索时执行查找的字段
      * 快速搜索时执行查找的字段
      */
      */
     protected $searchFields = 'id,title,subtitle';
     protected $searchFields = 'id,title,subtitle';
@@ -39,6 +51,13 @@ class Goods extends Backend
         $this->assignconfig('commission_goods_settlement_list', CommissionGoodsEnum::$settlementList);
         $this->assignconfig('commission_goods_settlement_list', CommissionGoodsEnum::$settlementList);
         $this->assignconfig('commission_goods_commission_settlement_list', CommissionGoodsEnum::$commissionSettlementList);
         $this->assignconfig('commission_goods_commission_settlement_list', CommissionGoodsEnum::$commissionSettlementList);
         $this->assignconfig('commission_goods_commission_type_list', CommissionGoodsEnum::$commissionTypeList);
         $this->assignconfig('commission_goods_commission_type_list', CommissionGoodsEnum::$commissionTypeList);
+        
+        // 传递商品枚举配置给前端
+        $this->assignconfig('goods_status_map', GoodsEnum::getGoodsStatusMap());
+        $this->assignconfig('goods_spec_type_map', GoodsEnum::getSpecTypeMap());
+        $this->assignconfig('goods_type_map', GoodsEnum::getGoodsTypeMap());
+        $this->assignconfig('goods_delivery_type_map', GoodsEnum::getDeliveryTypeMap());
+        $this->assignconfig('goods_express_type_map', GoodsEnum::getExpressTypeMap());
     }
     }
 
 
     public function index()
     public function index()
@@ -60,7 +79,12 @@ class Goods extends Backend
             ->order($sort, $order)
             ->order($sort, $order)
             ->paginate($limit);
             ->paginate($limit);
         
         
-        $result = ['total' => $list->total(), 'rows' => $list->items()];
+        // 为列表项添加文本表示
+        $items = collection($list->items())->each(function ($goods) {
+            return $this->formatGoodsData($goods);
+        });
+        
+        $result = ['total' => $list->total(), 'rows' => $items];
         return json($result);
         return json($result);
     }
     }
 
 
@@ -74,13 +98,22 @@ class Goods extends Backend
         $goodsList = collection(GoodsModel::with(['commission_goods'])->whereIn('id', $id)->select())->each(function ($goods) {
         $goodsList = collection(GoodsModel::with(['commission_goods'])->whereIn('id', $id)->select())->each(function ($goods) {
             $goods->skus = $goods->skus;
             $goods->skus = $goods->skus;
             $goods->sku_prices = $goods->sku_prices;
             $goods->sku_prices = $goods->sku_prices;
+            
+            // 使用统一的格式化方法
+            return $this->formatGoodsData($goods);
         });
         });
 
 
         // 获取分销配置
         // 获取分销配置
         $config = [
         $config = [
             'participate_list' => CommissionGoodsEnum::$participateList,
             'participate_list' => CommissionGoodsEnum::$participateList,
             'rule_type_list' => CommissionGoodsEnum::$ruleTypeList,
             'rule_type_list' => CommissionGoodsEnum::$ruleTypeList,
-            'level_list' => CommissionGoodsEnum::$levelList
+            'level_list' => CommissionGoodsEnum::$levelList,
+            // 商品枚举配置
+            'goods_status_map' => GoodsEnum::getGoodsStatusMap(),
+            'goods_spec_type_map' => GoodsEnum::getSpecTypeMap(),
+            'goods_type_map' => GoodsEnum::getGoodsTypeMap(),
+            'goods_delivery_type_map' => GoodsEnum::getDeliveryTypeMap(),
+            'goods_express_type_map' => GoodsEnum::getExpressTypeMap()
         ];
         ];
         
         
         $this->success('分销商品详情', null, [
         $this->success('分销商品详情', null, [
@@ -94,7 +127,7 @@ class Goods extends Backend
      *
      *
      * @param  $ids
      * @param  $ids
      */
      */
-    public function edit($ids = null)
+    public function commission($ids = null)
     {
     {
         if (!$this->request->isPost()) {
         if (!$this->request->isPost()) {
             // GET请求,显示设置页面
             // GET请求,显示设置页面
@@ -103,21 +136,85 @@ class Goods extends Backend
                 ->with(['commission_goods'])
                 ->with(['commission_goods'])
                 ->select();
                 ->select();
             
             
-            // 获取分销商等级列表
-            $levelList = LevelModel::where('status', 'normal')
-                ->order('level asc')
+            // 获取分销商等级列表及其佣金规则
+            $levelList = LevelModel::order('level asc')
                 ->select();
                 ->select();
             
             
+            // 获取分销配置(用于显示默认佣金比例)
+            $commissionConfig = ShopConfigService::getConfigs('shop.commission');
+            
+            // 提取默认佣金规则用于前端显示
+            $defaultCommissionRules = [];
+            foreach ($levelList as $level) {
+                if (isset($level->commission_rules) && is_array($level->commission_rules)) {
+                    $defaultCommissionRules[$level->level] = $level->commission_rules;
+                }
+            }
+            
+            // 获取第一个商品的分销数据(如果存在)
+            $commissionData = null;
+            if (isset($goodsList[0]) && $goodsList[0]->commission_goods) {
+                $commissionData = $goodsList[0]->commission_goods->toArray();
+                
+                // 如果是默认规则,从系统配置中读取默认值用于前端显示
+                if ($commissionData['rule_type'] == CommissionGoodsEnum::RULE_TYPE_DEFAULT) {
+                    // 从分销配置中读取默认值
+                    $commissionData['config'] = [
+                        'self_buy' => $commissionConfig['self_buy'] ?? 1,
+                        'level' => $commissionConfig['level'] ?? 3,
+                        'reward_type' => $commissionConfig['reward_type'] ?? 'pay_price',
+                        'reward_event' => $commissionConfig['reward_event'] ?? 'paid'
+                    ];
+                }
+            } else {
+                // 如果没有分销数据,创建默认数据,从系统配置中读取
+                $commissionData = [
+                    'rule_type' => CommissionGoodsEnum::RULE_TYPE_DEFAULT,
+                    'status' => CommissionGoodsEnum::PARTICIPATE_NO,
+                    'order_status' => CommissionGoodsEnum::ORDER_STATUS_YES,
+                    'config' => [
+                        'self_buy' => $commissionConfig['self_buy'] ?? 1,
+                        'level' => $commissionConfig['level'] ?? 3,
+                        'reward_type' => $commissionConfig['reward_type'] ?? 'pay_price',
+                        'reward_event' => $commissionConfig['reward_event'] ?? 'paid'
+                    ]
+                ];
+            }
+            
+            // 传递数据给前端
+            $this->assignconfig('commission_data', $commissionData);
+            $this->assignconfig('commission_config', $commissionConfig);
+            $this->assignconfig('default_commission_rules', $defaultCommissionRules);
+            
             $this->view->assign([
             $this->view->assign([
                 'goods_list' => $goodsList,
                 'goods_list' => $goodsList,
                 'level_list' => $levelList,
                 'level_list' => $levelList,
-                'goods_ids' => $ids
+                'goods_ids' => $ids,
+                'commission_data' => $commissionData, // 传递佣金数据用于数据初始化
+                'commission_config' => $commissionConfig, // 传递分销配置
+                'default_commission_rules' => $defaultCommissionRules, // 传递默认佣金规则
+                // 商品枚举配置
+                'goods_status_map' => GoodsEnum::getGoodsStatusMap(),
+                'goods_spec_type_map' => GoodsEnum::getSpecTypeMap(),
+                'goods_type_map' => GoodsEnum::getGoodsTypeMap(),
+                'goods_delivery_type_map' => GoodsEnum::getDeliveryTypeMap(),
+                'goods_express_type_map' => GoodsEnum::getExpressTypeMap(),
+                // 分销商品枚举配置
+                'commission_participate_list' => CommissionGoodsEnum::$participateList,
+                'commission_order_status_list' => CommissionGoodsEnum::$orderStatusList,
+                'commission_rule_type_list' => CommissionGoodsEnum::$ruleTypeList,
+                'commission_level_list' => CommissionGoodsEnum::$levelList,
+                'commission_self_buy_list' => CommissionGoodsEnum::$selfBuyList,
+                'commission_settlement_list' => CommissionGoodsEnum::$settlementList,
+                'commission_settlement_event_list' => CommissionGoodsEnum::$commissionSettlementList,
+                'commission_type_list' => CommissionGoodsEnum::$commissionTypeList
             ]);
             ]);
             
             
             return $this->view->fetch();
             return $this->view->fetch();
         }
         }
 
 
         // POST请求,保存设置
         // POST请求,保存设置
+        $this->token();
         $params = $this->request->post();
         $params = $this->request->post();
         
         
         // 验证必需参数
         // 验证必需参数
@@ -128,6 +225,7 @@ class Goods extends Backend
         $result = Db::transaction(function () use ($ids, $params) {
         $result = Db::transaction(function () use ($ids, $params) {
             $goodsIds = explode(',', $ids);
             $goodsIds = explode(',', $ids);
             $count = 0;
             $count = 0;
+            $ruleType = intval($params['rule_type'] ?? CommissionGoodsEnum::RULE_TYPE_DEFAULT);
 
 
             foreach ($goodsIds as $goods_id) {
             foreach ($goodsIds as $goods_id) {
                 $goods_id = intval($goods_id);
                 $goods_id = intval($goods_id);
@@ -140,30 +238,78 @@ class Goods extends Backend
                     $commissionGoods->goods_id = $goods_id;
                     $commissionGoods->goods_id = $goods_id;
                 }
                 }
 
 
-                // 保存基本设置
-                $commissionGoods->status = intval($params['status'] ?? CommissionGoodsEnum::PARTICIPATE_NO);
-                $commissionGoods->order_status = intval($params['order_status'] ?? CommissionGoodsEnum::ORDER_STATUS_YES);
-                $commissionGoods->rule_type = intval($params['rule_type'] ?? CommissionGoodsEnum::RULE_TYPE_DEFAULT);
-                $commissionGoods->self_buy = intval($params['self_buy'] ?? CommissionGoodsEnum::SELF_BUY_OFF);
-                $commissionGoods->settlement_type = intval($params['settlement_type'] ?? CommissionGoodsEnum::SETTLEMENT_GOODS_PRICE);
-                $commissionGoods->commission_settlement = intval($params['commission_settlement'] ?? CommissionGoodsEnum::COMMISSION_AFTER_PAY);
+                // 保存规则类型(所有情况都需要)
+                $commissionGoods->rule_type = $ruleType;
                 
                 
-                // 保存扩展配置
-                $config = [];
-                if (!empty($params['config'])) {
-                    $config = is_array($params['config']) ? $params['config'] : json_decode($params['config'], true);
-                }
-                $commissionGoods->config = $config;
-
-                $commissionGoods->save();
-
-                // 如果是独立规则或批量规则,保存佣金规则
-                if (in_array($commissionGoods->rule_type, [CommissionGoodsEnum::RULE_TYPE_CUSTOM, CommissionGoodsEnum::RULE_TYPE_BATCH])) {
-                    if (!empty($params['commission_rules'])) {
-                        $this->saveCommissionRules($goods_id, $params['commission_rules'], $commissionGoods->rule_type);
+                // 根据不同规则类型处理
+                if ($ruleType == CommissionGoodsEnum::RULE_TYPE_DEFAULT) {
+                    // 默认规则:保存"是否参与"和"分销商业绩"设置,但不保存其他自定义配置
+                    $commissionGoods->status = intval($params['status'] ?? CommissionGoodsEnum::PARTICIPATE_NO);
+                    $commissionGoods->order_status = intval($params['order_status'] ?? CommissionGoodsEnum::ORDER_STATUS_YES);
+                    $commissionGoods->config = []; // 不保存其他自定义配置
+                    
+                    // 删除可能存在的自定义佣金规则
+                    Db::name('shop_commission_rules')
+                        ->where('goods_id', $goods_id)
+                        ->delete();
+                        
+                } else if (in_array($ruleType, [CommissionGoodsEnum::RULE_TYPE_CUSTOM, CommissionGoodsEnum::RULE_TYPE_BATCH])) {
+                    // 独立规则或批量规则
+                    $distributionStatus = intval($params['status'] ?? CommissionGoodsEnum::PARTICIPATE_NO);
+                    $commissionGoods->status = $distributionStatus;
+                    
+                    // 只有在分销设置开启时才保存其他配置
+                    if ($distributionStatus == CommissionGoodsEnum::PARTICIPATE_YES) {
+                        // 保存分销商业绩设置
+                        $commissionGoods->order_status = intval($params['order_status'] ?? CommissionGoodsEnum::ORDER_STATUS_YES);
+                        
+                        // 保存扩展配置到JSON字段中
+                        $config = $commissionGoods->config ?? [];
+                        
+                        // 保存自购配置
+                        if (isset($params['self_buy'])) {
+                            $config['self_buy'] = intval($params['self_buy']);
+                        }
+                        
+                        // 保存分销层级
+                        if (isset($params['level'])) {
+                            $config['level'] = intval($params['level']);
+                        }
+                        
+                        // 保存商品结算方式
+                        if (isset($params['reward_type'])) {
+                            $config['reward_type'] = $params['reward_type'];
+                        }
+                        
+                        // 保存佣金结算时机
+                        if (isset($params['reward_event'])) {
+                            $config['reward_event'] = $params['reward_event'];
+                        }
+                        
+                        // 如果有其他自定义配置
+                        if (!empty($params['config']) && is_array($params['config'])) {
+                            $config = array_merge($config, $params['config']);
+                        }
+                        
+                        $commissionGoods->config = $config;
+                        
+                        // 保存佣金规则
+                        if (!empty($params['commission_rules'])) {
+                            $this->saveCommissionRules($goods_id, $params['commission_rules'], $ruleType);
+                        }
+                    } else {
+                        // 分销设置关闭时,清空相关配置但保留rule_type
+                        $commissionGoods->order_status = CommissionGoodsEnum::ORDER_STATUS_YES; // 保持默认值
+                        $commissionGoods->config = []; // 清空配置
+                        
+                        // 删除佣金规则
+                        Db::name('shop_commission_rules')
+                            ->where('goods_id', $goods_id)
+                            ->delete();
                     }
                     }
                 }
                 }
 
 
+                $commissionGoods->save();
                 $count++;
                 $count++;
             }
             }
 
 
@@ -183,7 +329,7 @@ class Goods extends Backend
     private function saveCommissionRules($goodsId, $rulesData, $ruleType)
     private function saveCommissionRules($goodsId, $rulesData, $ruleType)
     {
     {
         // 删除现有规则
         // 删除现有规则
-        Db::name('commission_goods_rules')
+        Db::name('shop_commission_rules')
             ->where('goods_id', $goodsId)
             ->where('goods_id', $goodsId)
             ->delete();
             ->delete();
 
 
@@ -205,20 +351,119 @@ class Goods extends Backend
                     'goods_id' => $goodsId,
                     'goods_id' => $goodsId,
                     'sku_id' => 0, // 批量规则统一为0,独立规则需要具体SKU ID
                     'sku_id' => 0, // 批量规则统一为0,独立规则需要具体SKU ID
                     'agent_level' => intval($agentLevel),
                     'agent_level' => intval($agentLevel),
-                    'commission_level' => intval($commissionLevel),
+                    'level' => intval($commissionLevel), // 新表字段名为level
                     'type' => $rule['type'] ?? 'rate',
                     'type' => $rule['type'] ?? 'rate',
                     'value' => floatval($rule['value']),
                     'value' => floatval($rule['value']),
                     'status' => 1,
                     'status' => 1,
-                    'createtime' => time(),
-                    'updatetime' => time()
+                    'created_at' => date('Y-m-d H:i:s'),
+                    'updated_at' => date('Y-m-d H:i:s')
                 ];
                 ];
             }
             }
         }
         }
 
 
         if (!empty($insertData)) {
         if (!empty($insertData)) {
-            return Db::name('commission_goods_rules')->insertAll($insertData);
+            return Db::name('shop_commission_rules')->insertAll($insertData);
         }
         }
 
 
         return true;
         return true;
     }
     }
+
+    /**
+     * 格式化商品数据,添加文本表示
+     * 
+     * @param object $goods 商品对象
+     * @return object
+     */
+    private function formatGoodsData($goods)
+    {
+        // 添加商品状态和规格类型的文本表示
+        $goods->status_text = GoodsEnum::getGoodsStatusText($goods->status);
+        $goods->spec_type_text = GoodsEnum::getSpecTypeText($goods->spec_type);
+        $goods->goods_type_text = GoodsEnum::getGoodsTypeText($goods->type);
+        $goods->delivery_type_text = GoodsEnum::getDeliveryTypeText($goods->delivery_type ?? '');
+        $goods->express_type_text = GoodsEnum::getExpressTypeText($goods->express_type ?? '');
+        
+        // 如果有分销商品信息,添加分销状态文本
+        if ($goods->commission_goods) {
+            $goods->commission_goods->participate_text = CommissionGoodsEnum::getParticipateText($goods->commission_goods->status);
+            $goods->commission_goods->order_status_text = CommissionGoodsEnum::getOrderStatusText($goods->commission_goods->order_status);
+            $goods->commission_goods->rule_type_text = CommissionGoodsEnum::getRuleTypeText($goods->commission_goods->rule_type);
+            
+            // 从config JSON中获取self_buy配置
+            $config = $goods->commission_goods->config ?? [];
+            $selfBuy = $config['self_buy'] ?? 0;
+            $goods->commission_goods->self_buy = $selfBuy;
+            $goods->commission_goods->self_buy_text = CommissionGoodsEnum::getSelfBuyText($selfBuy);
+            
+            // 添加颜色标识
+            $goods->commission_goods->participate_color = CommissionGoodsEnum::getParticipateColor($goods->commission_goods->status);
+            $goods->commission_goods->order_status_color = CommissionGoodsEnum::getOrderStatusColor($goods->commission_goods->order_status);
+            $goods->commission_goods->self_buy_color = CommissionGoodsEnum::getSelfBuyColor($selfBuy);
+            
+            // 从config中获取其他配置
+            $goods->commission_goods->level = $config['level'] ?? 0;
+            $goods->commission_goods->reward_type = $config['reward_type'] ?? 'pay_price';
+            $goods->commission_goods->reward_event = $config['reward_event'] ?? 'paid';
+        }
+        
+        return $goods;
+    }
+    
+    /**
+     * 获取商品状态筛选选项
+     * 
+     * @return array
+     */
+    public function getStatusFilterOptions()
+    {
+        return [
+            'goods_status' => GoodsEnum::getGoodsStatusMap(),
+            'spec_type' => GoodsEnum::getSpecTypeMap(),
+            'goods_type' => GoodsEnum::getGoodsTypeMap(),
+            'commission_participate' => CommissionGoodsEnum::$participateList,
+            'commission_rule_type' => CommissionGoodsEnum::$ruleTypeList
+        ];
+    }
+    
+    /**
+     * 批量设置商品分销状态
+     * 
+     * @param string $ids 商品ID,多个用逗号分隔
+     * @param int $status 分销状态
+     * @return void
+     */
+    public function batchSetStatus($ids, $status)
+    {
+        if (!$this->request->isPost()) {
+            $this->error('请求方式错误');
+        }
+        
+        $goodsIds = explode(',', $ids);
+        $status = intval($status);
+        
+        if (!CommissionGoodsEnum::isValidParticipate($status)) {
+            $this->error('无效的分销状态');
+        }
+        
+        $count = 0;
+        foreach ($goodsIds as $goodsId) {
+            $goodsId = intval($goodsId);
+            if ($goodsId <= 0) continue;
+            
+            // 查找或创建分销商品记录
+            $commissionGoods = CommissionGoodsModel::where('goods_id', $goodsId)->find();
+            if (!$commissionGoods) {
+                $commissionGoods = new CommissionGoodsModel();
+                $commissionGoods->goods_id = $goodsId;
+                $commissionGoods->order_status = 1; // 默认计入业绩
+                $commissionGoods->rule_type = 0; // 默认使用默认规则
+            }
+            
+            $commissionGoods->status = $status;
+            $commissionGoods->save();
+            $count++;
+        }
+        
+        $this->success("已更新 {$count} 个商品的分销状态");
+    }
 }
 }

+ 39 - 44
application/admin/view/commission/config/index.html

@@ -15,10 +15,9 @@
                         <label class="control-label col-xs-12 col-sm-2">分销层级:</label>
                         <label class="control-label col-xs-12 col-sm-2">分销层级:</label>
                         <div class="col-xs-12 col-sm-8">
                         <div class="col-xs-12 col-sm-8">
                             <div class="radio radio-inline">
                             <div class="radio radio-inline">
-                                <label><input name="row[level]" type="radio" value="0" {if $commissionConfig.level == '0' || !$commissionConfig.level}checked{/if}> 关闭</label>
-                                <label><input name="row[level]" type="radio" value="1" {if $commissionConfig.level == '1'}checked{/if}> 一级</label>
-                                <label><input name="row[level]" type="radio" value="2" {if $commissionConfig.level == '2'}checked{/if}> 二级</label>
-                                <label><input name="row[level]" type="radio" value="3" {if $commissionConfig.level == '3'}checked{/if}> 三级</label>
+                                {foreach $levelList as $value => $label}
+                                <label><input name="row[level]" type="radio" value="{$value}" {if $commissionConfig.level == $value}checked{/if}> {$label}</label>
+                                {/foreach}
                             </div>
                             </div>
                             <span class="help-block">默认佣金比例请到 分销商等级 进行设置</span>
                             <span class="help-block">默认佣金比例请到 分销商等级 进行设置</span>
                         </div>
                         </div>
@@ -28,8 +27,9 @@
                         <label class="control-label col-xs-12 col-sm-2">分销自购:</label>
                         <label class="control-label col-xs-12 col-sm-2">分销自购:</label>
                         <div class="col-xs-12 col-sm-8">
                         <div class="col-xs-12 col-sm-8">
                             <div class="radio radio-inline">
                             <div class="radio radio-inline">
-                                <label><input name="row[self_buy]" type="radio" value="0" {if $commissionConfig.self_buy == '0' || !$commissionConfig.self_buy}checked{/if}> 关闭</label>
-                                <label><input name="row[self_buy]" type="radio" value="1" {if $commissionConfig.self_buy == '1'}checked{/if}> 开启</label>
+                                {foreach $switchList as $value => $label}
+                                <label><input name="row[self_buy]" type="radio" value="{$value}" {if $commissionConfig.self_buy == $value}checked{/if}> {$label}</label>
+                                {/foreach}
                             </div>
                             </div>
                             <span class="help-block">自购优惠开启后,分销商自己购买也,下单可以给自己返佣</span>
                             <span class="help-block">自购优惠开启后,分销商自己购买也,下单可以给自己返佣</span>
                         </div>
                         </div>
@@ -39,9 +39,9 @@
                         <label class="control-label col-xs-12 col-sm-2">锁定下级条件:</label>
                         <label class="control-label col-xs-12 col-sm-2">锁定下级条件:</label>
                         <div class="col-xs-12 col-sm-8">
                         <div class="col-xs-12 col-sm-8">
                             <div class="radio radio-inline">
                             <div class="radio radio-inline">
-                                <label><input name="row[invite_lock]" type="radio" value="share" {if $commissionConfig.invite_lock == 'share' || !$commissionConfig.invite_lock}checked{/if}> 首次通过分享进入</label>
-                                <label><input name="row[invite_lock]" type="radio" value="pay" {if $commissionConfig.invite_lock == 'pay'}checked{/if}> 首次付款</label>
-                                <label><input name="row[invite_lock]" type="radio" value="agent" {if $commissionConfig.invite_lock == 'agent'}checked{/if}> 成为子分销商</label>
+                                {foreach $inviteLockList as $value => $label}
+                                <label><input name="row[invite_lock]" type="radio" value="{$value}" {if $commissionConfig.invite_lock == $value}checked{/if}> {$label}</label>
+                                {/foreach}
                             </div>
                             </div>
                         </div>
                         </div>
                     </div>
                     </div>
@@ -50,8 +50,9 @@
                         <label class="control-label col-xs-12 col-sm-2">分销商审核:</label>
                         <label class="control-label col-xs-12 col-sm-2">分销商审核:</label>
                         <div class="col-xs-12 col-sm-8">
                         <div class="col-xs-12 col-sm-8">
                             <div class="radio radio-inline">
                             <div class="radio radio-inline">
-                                <label><input name="row[agent_check]" type="radio" value="0" {if $commissionConfig.agent_check == '0' || !$commissionConfig.agent_check}checked{/if}> 不需要</label>
-                                <label><input name="row[agent_check]" type="radio" value="1" {if $commissionConfig.agent_check == '1'}checked{/if}> 需要</label>
+                                {foreach $checkList as $value => $label}
+                                <label><input name="row[agent_check]" type="radio" value="{$value}" {if $commissionConfig.agent_check == $value}checked{/if}> {$label}</label>
+                                {/foreach}
                             </div>
                             </div>
                         </div>
                         </div>
                     </div>
                     </div>
@@ -60,8 +61,9 @@
                         <label class="control-label col-xs-12 col-sm-2">越级升级:</label>
                         <label class="control-label col-xs-12 col-sm-2">越级升级:</label>
                         <div class="col-xs-12 col-sm-8">
                         <div class="col-xs-12 col-sm-8">
                             <div class="radio radio-inline">
                             <div class="radio radio-inline">
-                                <label><input name="row[upgrade_jump]" type="radio" value="0" {if $commissionConfig.upgrade_jump == '0'}checked{/if}> 不允许</label>
-                                <label><input name="row[upgrade_jump]" type="radio" value="1" {if $commissionConfig.upgrade_jump == '1' || !isset($commissionConfig.upgrade_jump)}checked{/if}> 允许</label>
+                                {foreach $allowList as $value => $label}
+                                <label><input name="row[upgrade_jump]" type="radio" value="{$value}" {if $commissionConfig.upgrade_jump == $value}checked{/if}> {$label}</label>
+                                {/foreach}
                             </div>
                             </div>
                         </div>
                         </div>
                     </div>
                     </div>
@@ -70,8 +72,9 @@
                         <label class="control-label col-xs-12 col-sm-2">升级审核:</label>
                         <label class="control-label col-xs-12 col-sm-2">升级审核:</label>
                         <div class="col-xs-12 col-sm-8">
                         <div class="col-xs-12 col-sm-8">
                             <div class="radio radio-inline">
                             <div class="radio radio-inline">
-                                <label><input name="row[upgrade_check]" type="radio" value="0" {if $commissionConfig.upgrade_check == '0' || !$commissionConfig.upgrade_check}checked{/if}> 自动升级</label>
-                                <label><input name="row[upgrade_check]" type="radio" value="1" {if $commissionConfig.upgrade_check == '1'}checked{/if}> 审核后升级</label>
+                                {foreach $upgradeCheckList as $value => $label}
+                                <label><input name="row[upgrade_check]" type="radio" value="{$value}" {if $commissionConfig.upgrade_check == $value}checked{/if}> {$label}</label>
+                                {/foreach}
                             </div>
                             </div>
                         </div>
                         </div>
                     </div>
                     </div>
@@ -92,12 +95,9 @@
                                 }
                                 }
                             {/php}
                             {/php}
                             <div class="radio radio-inline">
                             <div class="radio radio-inline">
-                                <label><input name="row[become_agent][type]" class="become-agent-type" type="radio" value="register" {if $become_agent.type == 'register'}checked{/if}> 新会员注册</label>
-                                <label><input name="row[become_agent][type]" class="become-agent-type" type="radio" value="apply" {if $become_agent.type == 'apply' || !$become_agent.type}checked{/if}> 自助申请</label>
-                            </div>
-                            <div class="radio radio-inline">
-                                <label><input name="row[become_agent][type]" class="become-agent-type" type="radio" value="goods" {if $become_agent.type == 'goods'}checked{/if}> 购买任意商品</label>
-                                <label><input name="row[become_agent][type]" class="become-agent-type" type="radio" value="consume" {if $become_agent.type == 'consume'}checked{/if}> 消费累计</label>
+                                {foreach $becomeAgentList as $value => $label}
+                                <label><input name="row[become_agent][type]" class="become-agent-type" type="radio" value="{$value}" {if $become_agent.type == $value}checked{/if}> {$label}</label>
+                                {/foreach}
                             </div>
                             </div>
                             <span class="help-block">会员必须进入分销中心手动完善资料并提交后可成为分销商</span>
                             <span class="help-block">会员必须进入分销中心手动完善资料并提交后可成为分销商</span>
 
 
@@ -111,8 +111,9 @@
                         <label class="control-label col-xs-12 col-sm-2">完善资料:</label>
                         <label class="control-label col-xs-12 col-sm-2">完善资料:</label>
                         <div class="col-xs-12 col-sm-8">
                         <div class="col-xs-12 col-sm-8">
                             <div class="radio radio-inline">
                             <div class="radio radio-inline">
-                                <label><input name="row[need_form]" type="radio" value="0" {if $commissionConfig.need_form == '0' || !isset($commissionConfig.need_form)}checked{/if}> 不需要</label>
-                                <label><input name="row[need_form]" type="radio" value="1" {if $commissionConfig.need_form == '1'}checked{/if}> 需要</label>
+                                {foreach $needFormList as $value => $label}
+                                <label><input name="row[need_form]" type="radio" value="{$value}" {if $commissionConfig.need_form == $value}checked{/if}> {$label}</label>
+                                {/foreach}
                             </div>
                             </div>
                         </div>
                         </div>
                     </div>
                     </div>
@@ -136,8 +137,9 @@
                         <label class="control-label col-xs-12 col-sm-2">申请协议:</label>
                         <label class="control-label col-xs-12 col-sm-2">申请协议:</label>
                         <div class="col-xs-12 col-sm-8">
                         <div class="col-xs-12 col-sm-8">
                             <div class="radio radio-inline">
                             <div class="radio radio-inline">
-                                <label><input name="row[show_protocol]" type="radio" value="0" {if $commissionConfig.show_protocol == '0' || !isset($commissionConfig.show_protocol)}checked{/if}> 不显示</label>
-                                <label><input name="row[show_protocol]" type="radio" value="1" {if $commissionConfig.show_protocol == '1'}checked{/if}> 显示</label>
+                                {foreach $showProtocolList as $value => $label}
+                                <label><input name="row[show_protocol]" type="radio" value="{$value}" {if $commissionConfig.show_protocol == $value}checked{/if}> {$label}</label>
+                                {/foreach}
                             </div>
                             </div>
                         </div>
                         </div>
                     </div>
                     </div>
@@ -205,8 +207,9 @@
                         <label class="control-label col-xs-12 col-sm-2">商品结算方式:</label>
                         <label class="control-label col-xs-12 col-sm-2">商品结算方式:</label>
                         <div class="col-xs-12 col-sm-8">
                         <div class="col-xs-12 col-sm-8">
                             <div class="radio radio-inline">
                             <div class="radio radio-inline">
-                                <label><input name="row[reward_type]" type="radio" value="price" {if $commissionConfig.reward_type == 'price'}checked{/if}> 商品价</label>
-                                <label><input name="row[reward_type]" type="radio" value="pay_price" {if $commissionConfig.reward_type == 'pay_price' || !$commissionConfig.reward_type}checked{/if}> 实际支付价</label>
+                                {foreach $rewardTypeList as $value => $label}
+                                <label><input name="row[reward_type]" type="radio" value="{$value}" {if $commissionConfig.reward_type == $value}checked{/if}> {$label}</label>
+                                {/foreach}
                             </div>
                             </div>
                             <span class="help-block">商品价: 商品实际售价/规格价,实际支付价: 实际支付的费用(不含运费)</span>
                             <span class="help-block">商品价: 商品实际售价/规格价,实际支付价: 实际支付的费用(不含运费)</span>
                         </div>
                         </div>
@@ -216,12 +219,9 @@
                         <label class="control-label col-xs-12 col-sm-2">佣金结算方式:</label>
                         <label class="control-label col-xs-12 col-sm-2">佣金结算方式:</label>
                         <div class="col-xs-12 col-sm-8">
                         <div class="col-xs-12 col-sm-8">
                             <div class="radio radio-inline">
                             <div class="radio radio-inline">
-                                <label><input name="row[reward_event]" type="radio" value="paid" {if $commissionConfig.reward_event == 'paid' || !$commissionConfig.reward_event}checked{/if}> 支付后结算</label>
-                                <label><input name="row[reward_event]" type="radio" value="received" {if $commissionConfig.reward_event == 'received'}checked{/if}> 确认收货结算</label>
-                            </div>
-                            <div class="radio radio-inline">
-                                <label><input name="row[reward_event]" type="radio" value="finished" {if $commissionConfig.reward_event == 'finished'}checked{/if}> 订单完成结算</label>
-                                <label><input name="row[reward_event]" type="radio" value="manual" {if $commissionConfig.reward_event == 'manual'}checked{/if}> 手动打款</label>
+                                {foreach $rewardEventList as $value => $label}
+                                <label><input name="row[reward_event]" type="radio" value="{$value}" {if $commissionConfig.reward_event == $value}checked{/if}> {$label}</label>
+                                {/foreach}
                             </div>
                             </div>
                         </div>
                         </div>
                     </div>
                     </div>
@@ -230,8 +230,9 @@
                         <label class="control-label col-xs-12 col-sm-2">分销佣金:</label>
                         <label class="control-label col-xs-12 col-sm-2">分销佣金:</label>
                         <div class="col-xs-12 col-sm-8">
                         <div class="col-xs-12 col-sm-8">
                             <div class="radio radio-inline">
                             <div class="radio radio-inline">
-                                <label><input name="row[refund_commission_reward]" type="radio" value="0" {if $commissionConfig.refund_commission_reward == '0'}checked{/if}> 退款不扣除</label>
-                                <label><input name="row[refund_commission_reward]" type="radio" value="1" {if $commissionConfig.refund_commission_reward == '1' || !isset($commissionConfig.refund_commission_reward)}checked{/if}> 退款扣除</label>
+                                {foreach $refundCommissionRewardList as $value => $label}
+                                <label><input name="row[refund_commission_reward]" type="radio" value="{$value}" {if $commissionConfig.refund_commission_reward == $value}checked{/if}> {$label}</label>
+                                {/foreach}
                             </div>
                             </div>
                         </div>
                         </div>
                     </div>
                     </div>
@@ -240,8 +241,9 @@
                         <label class="control-label col-xs-12 col-sm-2">分销业绩:</label>
                         <label class="control-label col-xs-12 col-sm-2">分销业绩:</label>
                         <div class="col-xs-12 col-sm-8">
                         <div class="col-xs-12 col-sm-8">
                             <div class="radio radio-inline">
                             <div class="radio radio-inline">
-                                <label><input name="row[refund_commission_order]" type="radio" value="0" {if $commissionConfig.refund_commission_order == '0'}checked{/if}> 退款不扣除</label>
-                                <label><input name="row[refund_commission_order]" type="radio" value="1" {if $commissionConfig.refund_commission_order == '1' || !isset($commissionConfig.refund_commission_order)}checked{/if}> 退款扣除</label>
+                                {foreach $refundCommissionOrderList as $value => $label}
+                                <label><input name="row[refund_commission_order]" type="radio" value="{$value}" {if $commissionConfig.refund_commission_order == $value}checked{/if}> {$label}</label>
+                                {/foreach}
                             </div>
                             </div>
                         </div>
                         </div>
                     </div>
                     </div>
@@ -259,11 +261,4 @@
     </div>
     </div>
 </div>
 </div>
 
 
-<script>
-$(function () {
-    require(['commission/config'], function (Controller) {
-        Controller.index();
-    });
-});
-</script>
 
 

+ 500 - 0
application/admin/view/commission/goods/commission.html

@@ -0,0 +1,500 @@
+<style>
+/* 佣金设置表单样式 */
+.commission-form .radio-inline {
+    margin-right: 20px;
+}
+
+.commission-form .radio-inline label {
+    display: inline-flex;
+    align-items: center;
+    padding: 6px 12px;
+    margin-right: 0;
+    background: #f8f9fa;
+    border: 1px solid #dee2e6;
+    border-radius: 6px;
+    font-weight: normal;
+    cursor: pointer;
+    transition: all 0.2s ease;
+}
+
+.commission-form .radio-inline label:hover {
+    background: #e9ecef;
+    border-color: #adb5bd;
+}
+
+.commission-form .radio-inline input[type="radio"]:checked + label,
+.commission-form .radio-inline input[type="radio"]:checked ~ label {
+    background: linear-gradient(135deg, #18bc9c 0%, #16a085 100%);
+    border-color: #18bc9c;
+    color: white;
+}
+
+.commission-form .radio-inline input[type="radio"] {
+    margin-right: 6px;
+}
+
+.commission-form .help-block {
+    margin-top: 8px;
+    font-size: 12px;
+    color: #6c757d;
+    line-height: 1.4;
+}
+
+.commission-form .help-block i {
+    margin-right: 4px;
+}
+
+.commission-form .form-group {
+    margin-bottom: 20px;
+}
+
+.commission-form .panel-heading {
+    background: linear-gradient(135deg, #18bc9c 0%, #16a085 100%);
+    border: none;
+}
+
+.commission-form .panel-heading .panel-title {
+    color: white;
+    font-weight: 500;
+}
+
+.commission-form .goods-info-container {
+    background: #f8f9fa;
+    border: 1px solid #dee2e6;
+    border-radius: 8px;
+    padding: 16px;
+    margin-bottom: 16px;
+}
+
+.commission-form .goods-image img {
+    border-radius: 8px;
+}
+
+.commission-form .goods-title {
+    font-size: 14px;
+    font-weight: 600;
+    color: #495057;
+    margin-bottom: 8px;
+}
+
+.commission-form .goods-price {
+    color: #e74c3c;
+    font-weight: 600;
+}
+
+#advanced-settings {
+    background: #f8f9fa;
+    border: 1px solid #dee2e6;
+    border-radius: 8px;
+    padding: 20px;
+    margin-top: 20px;
+}
+
+#advanced-settings .form-group:last-child {
+    margin-bottom: 0;
+}
+
+/* 禁用状态样式 */
+#advanced-settings[style*="display: none"] input[type="radio"]:disabled + label,
+input[type="radio"]:disabled + label {
+    opacity: 0.6;
+    cursor: not-allowed;
+    background: #f8f9fa !important;
+    color: #6c757d !important;
+    border-color: #dee2e6 !important;
+}
+
+/* 佣金输入组样式 */
+.commission-input-group {
+    text-align: center;
+    min-height: 34px;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+}
+
+.commission-input-group .input-group {
+    max-width: 200px;
+}
+
+.commission-input-group .commission-type-select {
+    border-left: none;
+    border-radius: 0 4px 4px 0;
+}
+
+.commission-input-group .input-group-addon {
+    background: #e9ecef;
+    border-color: #ced4da;
+    color: #495057;
+    font-weight: 500;
+}
+
+/* 默认规则显示值样式 */
+.default-rule-value {
+    display: inline-block;
+    padding: 8px 16px;
+    background: #f8f9fa;
+    border: 1px solid #dee2e6;
+    border-radius: 4px;
+    color: #6c757d;
+    font-weight: 500;
+    font-size: 14px;
+}
+
+/* 佣金比例表格样式优化 */
+#commission-rules-table {
+    margin-bottom: 15px;
+}
+
+#commission-rules-table th {
+    background: #e9ecef;
+    color: #495057;
+    font-weight: 600;
+    text-align: center;
+    vertical-align: middle;
+}
+
+#commission-rules-table td {
+    vertical-align: middle;
+    text-align: center;
+}
+
+#commission-rules-table tbody tr:first-child td:first-child {
+    font-weight: 600;
+    color: #495057;
+}
+
+/* 表单组动画效果 */
+.commission-form .form-group {
+    transition: all 0.3s ease;
+}
+
+/* 禁用表单元素样式 */
+input:disabled, select:disabled {
+    background-color: #e9ecef !important;
+    opacity: 0.65;
+    cursor: not-allowed;
+}
+
+/* 只读模式样式 */
+.commission-form.readonly-mode input[type="radio"]:disabled + label {
+    background: #f1f3f4 !important;
+    color: #5f6368 !important;
+    border-color: #dadce0 !important;
+    cursor: not-allowed;
+    opacity: 0.8;
+}
+
+/* 确保"是否参与"和"分销商业绩"在默认规则下保持可编辑样式 */
+.commission-form.readonly-mode input[name="status"]:not(:disabled) + label,
+.commission-form.readonly-mode input[name="order_status"]:not(:disabled) + label {
+    background: #f8f9fa !important;
+    color: #495057 !important;
+    border-color: #dee2e6 !important;
+    cursor: pointer !important;
+    opacity: 1 !important;
+}
+
+.commission-form.readonly-mode input[name="status"]:not(:disabled):checked + label,
+.commission-form.readonly-mode input[name="order_status"]:not(:disabled):checked + label {
+    background: linear-gradient(135deg, #18bc9c 0%, #16a085 100%) !important;
+    border-color: #18bc9c !important;
+    color: white !important;
+}
+
+.commission-form.readonly-mode .help-block {
+    color: #5f6368;
+}
+
+/* 默认规则值高亮显示 */
+.commission-form.readonly-mode .default-rule-value {
+    background: linear-gradient(135deg, #18bc9c 0%, #16a085 100%);
+    color: white;
+    border-color: #18bc9c;
+    font-weight: 600;
+}
+
+/* 隐藏状态平滑过渡 */
+[style*="display: none"] {
+    opacity: 0;
+    transform: translateY(-10px);
+}
+</style>
+
+<form id="edit-form" class="form-horizontal commission-form" role="form" data-toggle="validator" method="POST" action="{:url('commission/goods/commission')}?ids={$goods_ids}">
+    {:token()}
+    <div class="panel panel-default panel-intro">
+        <div class="panel-heading">
+            <h3 class="panel-title">
+                <i class="fa fa-list"></i> 商品信息
+            </h3>
+        </div>
+        <div class="panel-body">
+            <!-- 商品信息展示 -->
+            <div class="row">
+                {volist name="goods_list" id="goods"}
+                <div class="col-sm-12 goods-info-container">
+                    <div class="media">
+                        <div class="media-left goods-image">
+                            <img src="{$goods.image}" class="media-object" style="width: 64px; height: 64px; object-fit: cover;">
+                        </div>
+                        <div class="media-body" style="padding-left: 15px;">
+                            <div class="goods-title">
+                                {$goods.title}
+                                {if condition="$goods.spec_type == 1"}
+                                <span class="badge badge-primary" style="font-size: 10px; margin-left: 8px;">多规格</span>
+                                {/if}
+                            </div>
+                            {if condition="$goods.sub_title"}
+                            <p class="text-muted" style="margin-bottom: 6px; font-size: 12px; line-height: 1.3;">{$goods.sub_title}</p>
+                            {/if}
+                            <div style="font-size: 12px; color: #6c757d;">
+                                <span>ID: {$goods.id}</span>
+                                <span style="margin-left: 12px;" class="goods-price">价格: ¥{$goods.price}</span>
+
+                            </div>
+                        </div>
+                    </div>
+                </div>
+                {/volist}
+            </div>
+        </div>
+    </div>
+
+    <div class="panel panel-default panel-intro">
+        <div class="panel-heading">
+            <h3 class="panel-title">
+                <i class="fa fa-cog"></i> 佣金设置
+            </h3>
+        </div>
+        <div class="panel-body">
+            
+            <!-- 基础设置 -->
+            <div class="form-group">
+                <label class="control-label col-xs-12 col-sm-2">是否参与:</label>
+                <div class="col-xs-12 col-sm-8">
+                    {foreach $commission_participate_list as $value => $label}
+                    <div class="radio-inline">
+                        <label>
+                            <input name="status" type="radio" value="{$value}" {if $commission_data.status == $value}checked{/if}> {$label}
+                        </label>
+                    </div>
+                    {/foreach}
+                </div>
+            </div>
+
+            <div class="form-group">
+                <label class="control-label col-xs-12 col-sm-2">分销商业绩:</label>
+                <div class="col-xs-12 col-sm-8">
+                    {foreach $commission_order_status_list as $value => $label}
+                    <div class="radio-inline">
+                        <label>
+                            <input name="order_status" type="radio" value="{$value}" {if $commission_data.order_status == $value}checked{/if}> {$label}
+                        </label>
+                    </div>
+                    {/foreach}
+                    <div class="help-block">
+                        <i class="fa fa-info-circle text-info"></i> 关闭则只分佣,不计入分销订单金额和订单数
+                    </div>
+                </div>
+            </div>
+
+            <div class="form-group">
+                <label class="control-label col-xs-12 col-sm-2">佣金规则:</label>
+                <div class="col-xs-12 col-sm-8">
+                    {foreach $commission_rule_type_list as $value => $label}
+                    <div class="radio-inline">
+                        <label>
+                            <input name="rule_type" type="radio" value="{$value}" {if $commission_data.rule_type == $value}checked{/if}> {$label}
+                        </label>
+                    </div>
+                    {/foreach}
+                </div>
+            </div>
+
+            <div class="form-group">
+                <label class="control-label col-xs-12 col-sm-2">分销层级:</label>
+                <div class="col-xs-12 col-sm-8">
+                    {foreach $commission_level_list as $value => $label}
+                    <div class="radio-inline">
+                        <label>
+                            <input name="level" type="radio" value="{$value}" {if ($commission_data.config.level ?? 3) == $value}checked{/if}> {$label}
+                        </label>
+                    </div>
+                    {/foreach}
+                </div>
+            </div>
+
+            <div class="form-group">
+                <label class="control-label col-xs-12 col-sm-2">分销自购:</label>
+                <div class="col-xs-12 col-sm-8">
+                    {foreach $commission_self_buy_list as $value => $label}
+                    <div class="radio-inline">
+                        <label>
+                            <input name="self_buy" type="radio" value="{$value}" {if ($commission_data.config.self_buy ?? 1) == $value}checked{/if}> {$label}
+                        </label>
+                    </div>
+                    {/foreach}
+                    <div class="help-block">
+                        <i class="fa fa-info-circle text-info"></i> 分销自购开启后,分销商自己购买时,下单可以给自己返佣
+                    </div>
+                </div>
+            </div>
+
+            <div class="form-group">
+                <label class="control-label col-xs-12 col-sm-2">商品结算方式:</label>
+                <div class="col-xs-12 col-sm-8">
+                    <div class="radio-inline">
+                        <label>
+                            <input name="reward_type" type="radio" value="goods_price" {if ($commission_data.config.reward_type ?? 'pay_price') == 'goods_price'}checked{/if}> 商品价
+                        </label>
+                    </div>
+                    <div class="radio-inline">
+                        <label>
+                            <input name="reward_type" type="radio" value="pay_price" {if ($commission_data.config.reward_type ?? 'pay_price') == 'pay_price'}checked{/if}> 实际支付价
+                        </label>
+                    </div>
+                    <div class="help-block">
+                        <i class="fa fa-info-circle text-info"></i> 商品价:商品实际售价/规格价,实际支付价:实际支付的费用(不含运费)
+                    </div>
+                </div>
+            </div>
+
+            <div class="form-group">
+                <label class="control-label col-xs-12 col-sm-2">佣金结算方式:</label>
+                <div class="col-xs-12 col-sm-8">
+                    <div class="radio-inline">
+                        <label>
+                            <input name="reward_event" type="radio" value="paid" {if ($commission_data.config.reward_event ?? 'paid') == 'paid'}checked{/if}> 支付后结算
+                        </label>
+                    </div>
+                    <div class="radio-inline">
+                        <label>
+                            <input name="reward_event" type="radio" value="confirm" {if ($commission_data.config.reward_event ?? 'paid') == 'confirm'}checked{/if}> 确认收货结算
+                        </label>
+                    </div>
+                    <div class="radio-inline">
+                        <label>
+                            <input name="reward_event" type="radio" value="finish" {if ($commission_data.config.reward_event ?? 'paid') == 'finish'}checked{/if}> 订单完成结算
+                        </label>
+                    </div>
+                    <div class="radio-inline">
+                        <label>
+                            <input name="reward_event" type="radio" value="admin" {if ($commission_data.config.reward_event ?? 'paid') == 'admin'}checked{/if}> 手动打款
+                        </label>
+                    </div>
+                </div>
+            </div>
+
+            <!-- 佣金规则设置 -->
+            <div class="form-group">
+                <label class="control-label col-xs-12 col-sm-2">佣金比例设置:</label>
+                <div class="col-xs-12 col-sm-10">
+                    <div class="table-responsive">
+                        <table class="table table-bordered table-hover" id="commission-rules-table">
+                            <thead>
+                                <tr>
+                                    <th width="150">分销等级名称</th>
+                                    <th>一级(自购)佣金比例</th>
+                                    <th>二级佣金比例</th>
+                                    <th>三级佣金比例</th>
+                                </tr>
+                            </thead>
+                            <tbody>
+                                {volist name="level_list" id="level"}
+                                <tr>
+                                    <td><strong>{$level.name}</strong></td>
+                                    <td>
+                                        <div class="commission-input-group">
+                                            <!-- 默认规则显示的固定值 -->
+                                            <span class="default-rule-value" style="display: none;">
+                                                {if isset($default_commission_rules[$level.level]['1'])}
+                                                    {$default_commission_rules[$level.level]['1']['value']|default='1'}{$default_commission_rules[$level.level]['1']['type']|default='rate' == 'rate' ? '%' : '元'}
+                                                {else/}
+                                                    1%
+                                                {/if}
+                                            </span>
+                                            <!-- 自定义规则的输入框 -->
+                                            <div class="custom-rule-input" style="display: none;">
+                                                <div class="input-group">
+                                                    <input type="number" name="commission_rules[{$level.level}][1][value]" class="form-control" step="0.01" min="0" placeholder="1" value="1">
+                                                    <div class="input-group-addon">%</div>
+                                                    <select name="commission_rules[{$level.level}][1][type]" class="form-control commission-type-select" style="width: 80px;">
+                                                        <option value="rate">%</option>
+                                                        <option value="money">元</option>
+                                                    </select>
+                                                </div>
+                                            </div>
+                                        </div>
+                                    </td>
+                                    <td>
+                                        <div class="commission-input-group">
+                                            <!-- 默认规则显示的固定值 -->
+                                            <span class="default-rule-value" style="display: none;">
+                                                {if isset($default_commission_rules[$level.level]['2'])}
+                                                    {$default_commission_rules[$level.level]['2']['value']|default='2'}{$default_commission_rules[$level.level]['2']['type']|default='rate' == 'rate' ? '%' : '元'}
+                                                {else/}
+                                                    2%
+                                                {/if}
+                                            </span>
+                                            <!-- 自定义规则的输入框 -->
+                                            <div class="custom-rule-input" style="display: none;">
+                                                <div class="input-group">
+                                                    <input type="number" name="commission_rules[{$level.level}][2][value]" class="form-control" step="0.01" min="0" placeholder="2" value="2">
+                                                    <div class="input-group-addon">%</div>
+                                                    <select name="commission_rules[{$level.level}][2][type]" class="form-control commission-type-select" style="width: 80px;">
+                                                        <option value="rate">%</option>
+                                                        <option value="money">元</option>
+                                                    </select>
+                                                </div>
+                                            </div>
+                                        </div>
+                                    </td>
+                                    <td>
+                                        <div class="commission-input-group">
+                                            <!-- 默认规则显示的固定值 -->
+                                            <span class="default-rule-value" style="display: none;">
+                                                {if isset($default_commission_rules[$level.level]['3'])}
+                                                    {$default_commission_rules[$level.level]['3']['value']|default='3'}{$default_commission_rules[$level.level]['3']['type']|default='rate' == 'rate' ? '%' : '元'}
+                                                {else/}
+                                                    3%
+                                                {/if}
+                                            </span>
+                                            <!-- 自定义规则的输入框 -->
+                                            <div class="custom-rule-input" style="display: none;">
+                                                <div class="input-group">
+                                                    <input type="number" name="commission_rules[{$level.level}][3][value]" class="form-control" step="0.01" min="0" placeholder="3" value="3">
+                                                    <div class="input-group-addon">%</div>
+                                                    <select name="commission_rules[{$level.level}][3][type]" class="form-control commission-type-select" style="width: 80px;">
+                                                        <option value="rate">%</option>
+                                                        <option value="money">元</option>
+                                                    </select>
+                                                </div>
+                                            </div>
+                                        </div>
+                                    </td>
+                                </tr>
+                                {/volist}
+                            </tbody>
+                        </table>
+                    </div>
+                    <p class="help-block default-rule-help" style="display: none;">
+                        <i class="fa fa-info-circle text-muted"></i> 默认规则使用系统配置的佣金比例,不支持自定义修改
+                    </p>
+                    <p class="help-block custom-rule-help" style="display: none;">
+                        <i class="fa fa-info-circle text-info"></i> 说明:比例佣金按百分比计算,固定佣金按每件商品计算
+                    </p>
+                </div>
+            </div>
+        </div>
+    </div>
+
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-success btn-embossed">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+
+</form>

+ 23 - 19
application/admin/view/commission/goods/edit.html

@@ -114,13 +114,13 @@
                 <label class="control-label col-xs-12 col-sm-2">商品结算方式:</label>
                 <label class="control-label col-xs-12 col-sm-2">商品结算方式:</label>
                 <div class="col-xs-12 col-sm-8">
                 <div class="col-xs-12 col-sm-8">
                     <div class="radio">
                     <div class="radio">
-                        <label for="settlement_goods_price">
-                            <input id="settlement_goods_price" name="settlement_type" type="radio" value="0" checked=""> 商品价
+                        <label for="reward_type_price">
+                            <input id="reward_type_price" name="reward_type" type="radio" value="price"> 商品价
                         </label>
                         </label>
                     </div>
                     </div>
                     <div class="radio">
                     <div class="radio">
-                        <label for="settlement_actual_price">
-                            <input id="settlement_actual_price" name="settlement_type" type="radio" value="1"> 实际支付价
+                        <label for="reward_type_pay_price">
+                            <input id="reward_type_pay_price" name="reward_type" type="radio" value="pay_price" checked=""> 实际支付价
                         </label>
                         </label>
                     </div>
                     </div>
                 </div>
                 </div>
@@ -130,23 +130,23 @@
                 <label class="control-label col-xs-12 col-sm-2">佣金结算方式:</label>
                 <label class="control-label col-xs-12 col-sm-2">佣金结算方式:</label>
                 <div class="col-xs-12 col-sm-8">
                 <div class="col-xs-12 col-sm-8">
                     <div class="radio">
                     <div class="radio">
-                        <label for="commission_after_pay">
-                            <input id="commission_after_pay" name="commission_settlement" type="radio" value="0" checked=""> 支付后结算
+                        <label for="reward_event_paid">
+                            <input id="reward_event_paid" name="reward_event" type="radio" value="paid" checked=""> 支付后结算
                         </label>
                         </label>
                     </div>
                     </div>
                     <div class="radio">
                     <div class="radio">
-                        <label for="commission_after_confirm">
-                            <input id="commission_after_confirm" name="commission_settlement" type="radio" value="1"> 确认收货结算
+                        <label for="reward_event_received">
+                            <input id="reward_event_received" name="reward_event" type="radio" value="received"> 确认收货结算
                         </label>
                         </label>
                     </div>
                     </div>
                     <div class="radio">
                     <div class="radio">
-                        <label for="commission_after_complete">
-                            <input id="commission_after_complete" name="commission_settlement" type="radio" value="2"> 订单完成结算
+                        <label for="reward_event_finished">
+                            <input id="reward_event_finished" name="reward_event" type="radio" value="finished"> 订单完成结算
                         </label>
                         </label>
                     </div>
                     </div>
                     <div class="radio">
                     <div class="radio">
-                        <label for="commission_manual">
-                            <input id="commission_manual" name="commission_settlement" type="radio" value="3"> 手动打款
+                        <label for="reward_event_manual">
+                            <input id="reward_event_manual" name="reward_event" type="radio" value="manual"> 手动打款
                         </label>
                         </label>
                     </div>
                     </div>
                 </div>
                 </div>
@@ -213,7 +213,7 @@
     <div class="form-group layer-footer">
     <div class="form-group layer-footer">
         <label class="control-label col-xs-12 col-sm-2"></label>
         <label class="control-label col-xs-12 col-sm-2"></label>
         <div class="col-xs-12 col-sm-8">
         <div class="col-xs-12 col-sm-8">
-            <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
+            <button type="submit" class="btn btn-success btn-embossed">{:__('OK')}</button>
             <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
             <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
         </div>
         </div>
     </div>
     </div>
@@ -272,14 +272,18 @@ $(document).ready(function() {
         if (commissionData.rule_type !== undefined) {
         if (commissionData.rule_type !== undefined) {
             $('input[name="rule_type"][value="' + commissionData.rule_type + '"]').prop('checked', true).trigger('change');
             $('input[name="rule_type"][value="' + commissionData.rule_type + '"]').prop('checked', true).trigger('change');
         }
         }
-        if (commissionData.self_buy !== undefined) {
-            $('input[name="self_buy"][value="' + commissionData.self_buy + '"]').prop('checked', true);
+        
+        // 从config中获取配置
+        var config = commissionData.config || {};
+        
+        if (config.self_buy !== undefined) {
+            $('input[name="self_buy"][value="' + config.self_buy + '"]').prop('checked', true);
         }
         }
-        if (commissionData.settlement_type !== undefined) {
-            $('input[name="settlement_type"][value="' + commissionData.settlement_type + '"]').prop('checked', true);
+        if (config.reward_type !== undefined) {
+            $('input[name="reward_type"][value="' + config.reward_type + '"]').prop('checked', true);
         }
         }
-        if (commissionData.commission_settlement !== undefined) {
-            $('input[name="commission_settlement"][value="' + commissionData.commission_settlement + '"]').prop('checked', true);
+        if (config.reward_event !== undefined) {
+            $('input[name="reward_event"][value="' + config.reward_event + '"]').prop('checked', true);
         }
         }
     }
     }
     {/if}
     {/if}

+ 1 - 1
application/admin/view/commission/goods/index.html

@@ -10,7 +10,7 @@
                         <a href="javascript:;" class="btn btn-success btn-batch-commission" title="批量设置佣金"><i class="fa fa-cog"></i> 批量设置佣金</a>
                         <a href="javascript:;" class="btn btn-success btn-batch-commission" title="批量设置佣金"><i class="fa fa-cog"></i> 批量设置佣金</a>
                     </div>
                     </div>
                     <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
                     <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
-                           data-operate-edit="{:$auth->check('commission/goods/edit')}"
+                           data-operate-edit="{:$auth->check('commission/goods/commission')}"
                            data-operate-del="{:$auth->check('commission/goods/del')}"
                            data-operate-del="{:$auth->check('commission/goods/del')}"
                            width="100%">
                            width="100%">
                     </table>
                     </table>

+ 290 - 0
application/common/Enum/CommissionConfigEnum.php

@@ -0,0 +1,290 @@
+<?php
+
+namespace app\common\Enum;
+
+/**
+ * 分销配置枚举类
+ */
+class CommissionConfigEnum
+{
+    // ===================== 分销层级 =====================
+    
+    /**
+     * 分销层级
+     */
+    const LEVEL_DISABLE = 0; // 关闭
+    const LEVEL_ONE = 1;     // 一级
+    const LEVEL_TWO = 2;     // 二级
+    const LEVEL_THREE = 3;   // 三级
+    
+    public static $levelList = [
+        self::LEVEL_DISABLE => '关闭',
+        self::LEVEL_ONE => '一级',
+        // self::LEVEL_TWO => '二级',
+        // self::LEVEL_THREE => '三级'
+    ];
+
+    // ===================== 开关状态 =====================
+    
+    /**
+     * 开关状态(分销自购、分销商审核等)
+     */
+    const SWITCH_OFF = 0; // 关闭/不需要
+    const SWITCH_ON = 1;  // 开启/需要
+    
+    public static $switchList = [
+        self::SWITCH_OFF => '关闭',
+        self::SWITCH_ON => '开启'
+    ];
+    
+    public static $checkList = [
+        self::SWITCH_OFF => '不需要',
+        self::SWITCH_ON => '需要'
+    ];
+    
+    public static $allowList = [
+        self::SWITCH_OFF => '不允许',
+        self::SWITCH_ON => '允许'
+    ];
+    
+    public static $upgradeCheckList = [
+        self::SWITCH_OFF => '自动升级',
+        self::SWITCH_ON => '审核后升级'
+    ];
+    
+    public static $needFormList = [
+        self::SWITCH_OFF => '不需要',
+        self::SWITCH_ON => '需要'
+    ];
+    
+    public static $showProtocolList = [
+        self::SWITCH_OFF => '不显示',
+        self::SWITCH_ON => '显示'
+    ];
+
+    // ===================== 锁定下级条件 =====================
+    
+    /**
+     * 锁定下级条件
+     */
+    const LOCK_SHARE = 'share'; // 首次通过分享进入
+    const LOCK_PAY = 'pay';     // 首次付款
+    const LOCK_AGENT = 'agent'; // 成为子分销商
+    
+    public static $inviteLockList = [
+        self::LOCK_SHARE => '首次通过分享进入',
+        // self::LOCK_PAY => '首次付款',
+        // self::LOCK_AGENT => '成为子分销商'
+    ];
+
+    // ===================== 成为分销商条件 =====================
+    
+    /**
+     * 成为分销商条件
+     */
+    const BECOME_REGISTER = 'register'; // 新会员注册
+    const BECOME_APPLY = 'apply';       // 自助申请
+    const BECOME_GOODS = 'goods';       // 购买任意商品
+    const BECOME_CONSUME = 'consume';   // 消费累计
+    
+    public static $becomeAgentList = [
+        // self::BECOME_REGISTER => '新会员注册',
+        self::BECOME_APPLY => '自助申请',
+        // self::BECOME_GOODS => '购买任意商品',
+        // self::BECOME_CONSUME => '消费累计'
+    ];
+
+    // ===================== 商品结算方式 =====================
+    
+    /**
+     * 商品结算方式
+     */
+    const REWARD_TYPE_PRICE = 'price';     // 商品价
+    const REWARD_TYPE_PAY_PRICE = 'pay_price'; // 实际支付价
+    
+    public static $rewardTypeList = [
+        self::REWARD_TYPE_PRICE => '商品价',
+        self::REWARD_TYPE_PAY_PRICE => '实际支付价'
+    ];
+
+    // ===================== 佣金结算方式 =====================
+    
+    /**
+     * 佣金结算方式
+     */
+    const REWARD_EVENT_PAID = 'paid';       // 支付后结算
+    const REWARD_EVENT_RECEIVED = 'received'; // 确认收货结算
+    const REWARD_EVENT_FINISHED = 'finished'; // 订单完成结算
+    const REWARD_EVENT_MANUAL = 'manual';   // 手动打款
+    
+    public static $rewardEventList = [
+        self::REWARD_EVENT_PAID => '支付后结算',
+        self::REWARD_EVENT_RECEIVED => '确认收货结算',
+        self::REWARD_EVENT_FINISHED => '订单完成结算',
+        self::REWARD_EVENT_MANUAL => '手动打款'
+    ];
+
+    // ===================== 扣除设置 =====================
+    
+    /**
+     * 退款扣除设置
+     */
+    const REFUND_NO_DEDUCT = 0; // 退款不扣除
+    const REFUND_DEDUCT = 1;    // 退款扣除
+    
+    public static $refundCommissionRewardList = [
+        self::REFUND_NO_DEDUCT => '退款不扣除',
+        self::REFUND_DEDUCT => '退款扣除'
+    ];
+    
+    public static $refundCommissionOrderList = [
+        self::REFUND_NO_DEDUCT => '退款不扣除',
+        self::REFUND_DEDUCT => '退款扣除'
+    ];
+
+    // ===================== 辅助方法 =====================
+    
+    /**
+     * 获取分销层级文本
+     */
+    public static function getLevelText($value)
+    {
+        return self::$levelList[$value] ?? '关闭';
+    }
+    
+    /**
+     * 获取开关状态文本
+     */
+    public static function getSwitchText($value)
+    {
+        return self::$switchList[$value] ?? '关闭';
+    }
+    
+    /**
+     * 获取审核状态文本
+     */
+    public static function getCheckText($value)
+    {
+        return self::$checkList[$value] ?? '不需要';
+    }
+    
+    /**
+     * 获取锁定条件文本
+     */
+    public static function getInviteLockText($value)
+    {
+        return self::$inviteLockList[$value] ?? '首次通过分享进入';
+    }
+    
+    /**
+     * 获取成为分销商条件文本
+     */
+    public static function getBecomeAgentText($value)
+    {
+        return self::$becomeAgentList[$value] ?? '自助申请';
+    }
+    
+    /**
+     * 获取商品结算方式文本
+     */
+    public static function getRewardTypeText($value)
+    {
+        return self::$rewardTypeList[$value] ?? '实际支付价';
+    }
+    
+    /**
+     * 获取佣金结算方式文本
+     */
+    public static function getRewardEventText($value)
+    {
+        return self::$rewardEventList[$value] ?? '支付后结算';
+    }
+    
+    /**
+     * 获取退款佣金扣除文本
+     */
+    public static function getRefundCommissionRewardText($value)
+    {
+        return self::$refundCommissionRewardList[$value] ?? '退款扣除';
+    }
+    
+    /**
+     * 获取退款业绩扣除文本
+     */
+    public static function getRefundCommissionOrderText($value)
+    {
+        return self::$refundCommissionOrderList[$value] ?? '退款扣除';
+    }
+
+    // ===================== 验证方法 =====================
+    
+    /**
+     * 验证分销层级值
+     */
+    public static function isValidLevel($value)
+    {
+        return array_key_exists($value, self::$levelList);
+    }
+    
+    /**
+     * 验证开关值
+     */
+    public static function isValidSwitch($value)
+    {
+        return in_array($value, [self::SWITCH_OFF, self::SWITCH_ON]);
+    }
+    
+    /**
+     * 验证锁定条件值
+     */
+    public static function isValidInviteLock($value)
+    {
+        return array_key_exists($value, self::$inviteLockList);
+    }
+    
+    /**
+     * 验证成为分销商条件值
+     */
+    public static function isValidBecomeAgent($value)
+    {
+        return array_key_exists($value, self::$becomeAgentList);
+    }
+    
+    /**
+     * 验证商品结算方式值
+     */
+    public static function isValidRewardType($value)
+    {
+        return array_key_exists($value, self::$rewardTypeList);
+    }
+    
+    /**
+     * 验证佣金结算方式值
+     */
+    public static function isValidRewardEvent($value)
+    {
+        return array_key_exists($value, self::$rewardEventList);
+    }
+    
+    /**
+     * 获取所有配置的默认值
+     */
+    public static function getDefaultConfig()
+    {
+        return [
+            'level' => self::LEVEL_DISABLE,
+            'self_buy' => self::SWITCH_OFF,
+            'invite_lock' => self::LOCK_SHARE,
+            'agent_check' => self::SWITCH_OFF,
+            'upgrade_jump' => self::SWITCH_ON,
+            'upgrade_check' => self::SWITCH_OFF,
+            'become_agent' => json_encode(['type' => self::BECOME_APPLY, 'value' => '']),
+            'need_form' => self::SWITCH_OFF,
+            'show_protocol' => self::SWITCH_OFF,
+            'reward_type' => self::REWARD_TYPE_PAY_PRICE,
+            'reward_event' => self::REWARD_EVENT_PAID,
+            'refund_commission_reward' => self::REFUND_DEDUCT,
+            'refund_commission_order' => self::REFUND_DEDUCT,
+        ];
+    }
+}

+ 2 - 2
application/common/Enum/CommissionGoodsEnum.php

@@ -54,8 +54,8 @@ class CommissionGoodsEnum
     
     
     public static $ruleTypeList = [
     public static $ruleTypeList = [
         self::RULE_TYPE_DEFAULT => '默认规则',
         self::RULE_TYPE_DEFAULT => '默认规则',
-        self::RULE_TYPE_CUSTOM => '独立规则', 
-        self::RULE_TYPE_BATCH => '批量规则'
+        // self::RULE_TYPE_CUSTOM => '独立规则', 
+        // self::RULE_TYPE_BATCH => '批量规则'
     ];
     ];
 
 
     // ===================== 分销层级 =====================
     // ===================== 分销层级 =====================

+ 303 - 107
public/assets/js/backend/commission/goods.js

@@ -1,17 +1,142 @@
 define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
 define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
 
 
     var Controller = {
     var Controller = {
+        // 模板对象
+        templates: {
+            // 模板渲染工具方法
+            render: function(template, data) {
+                var result = template;
+                Object.keys(data).forEach(function(key) {
+                    var regex = new RegExp('{{' + key + '}}', 'g');
+                    result = result.replace(regex, data[key] || '');
+                });
+                return result;
+            },
+            
+            // 文本截断工具
+            truncateText: function(text, maxLength) {
+                if (!text || text.length <= maxLength) {
+                    return text;
+                }
+                return text.substring(0, maxLength) + '...';
+            },
+            
+            // 安全转义HTML
+            escapeHtml: function(text) {
+                if (typeof Fast !== 'undefined' && Fast.api && Fast.api.escape) {
+                    return Fast.api.escape(text);
+                }
+                return $('<div>').text(text).html();
+            },
+            
+            // 商品信息模板
+            goodsInfo: function(row) {
+                var template = '<div class="goods-info-container" style="display: flex; align-items: center; padding: 8px 0;">' +
+                    '<!-- 商品图片 -->' +
+                    '<div class="goods-image" style="margin-right: 15px; flex-shrink: 0;">' +
+                        '<img src="{{imageUrl}}" ' +
+                             'style="width: 64px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid #e1e5e9; box-shadow: 0 1px 3px rgba(0,0,0,0.1);" ' +
+                             'onerror="this.src=\'/assets/img/goods-default.png\'" />' +
+                    '</div>' +
+                    
+                    '<!-- 商品信息 -->' +
+                    '<div class="goods-content" style="flex: 1; min-width: 0; line-height: 1.4;">' +
+                        '<!-- 商品标题 -->' +
+                        '<div class="goods-title" style="font-weight: 600; color: #495057; margin-bottom: 6px; font-size: 14px;">' +
+                            '<a href="javascript:;" style="color: #495057; text-decoration: none; word-break: break-all; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;">' +
+                                '{{title}}' +
+                            '</a>' +
+                            '{{specBadge}}' +
+                        '</div>' +
+                        
+                        '<!-- 商品描述 -->' +
+                        '{{subtitle}}' +
+                        
+                        '<!-- 商品元信息 -->' +
+                        '<div class="goods-meta" style="color: #6c757d; font-size: 11px; margin-top: 6px;">' +
+                            '<span class="goods-id">ID: {{id}}</span>' +
+                            '{{typeInfo}}' +
+                        '</div>' +
+                    '</div>' +
+                '</div>';
+                
+                // 数据填充
+                var data = {
+                    imageUrl: row.image || '/assets/img/goods-default.png',
+                    title: Controller.templates.truncateText(Controller.templates.escapeHtml(row.title || '未命名商品'), 50),
+                    id: row.id || '-',
+                    subtitle: row.subtitle ? 
+                        '<div class="goods-subtitle" style="color: #6c757d; font-size: 12px; margin-bottom: 4px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;" title="' + 
+                        Controller.templates.escapeHtml(row.subtitle) + '">' + 
+                        Controller.templates.truncateText(Controller.templates.escapeHtml(row.subtitle), 60) + 
+                        '</div>' : '',
+                    specBadge: (row.spec_type == 1 || (row.spec_type_text && row.spec_type_text === '多规格')) ? 
+                        ' <span class="goods-spec-badge">多规格</span>' : '',
+                    typeInfo: row.status_text ? 
+                        ' | <span class="goods-status">' + Controller.templates.escapeHtml(row.status_text) + '</span>' : ''
+                };
+                
+                return Controller.templates.render(template, data);
+            },
+            
+            // 分销规则状态模板
+            commissionStatus: function(row) {
+                if (!row.commission_goods) {
+                    return '<span class="label label-danger">不参与</span>';
+                }
+                
+                var participateStatus = row.commission_goods.status;
+                if (participateStatus == 0) {
+                    return '<span class="label label-danger">不参与</span>';
+                }
+                
+                var ruleTypeList = Config.commission_goods_rule_type_list || {
+                    '0': '默认规则',
+                    '1': '独立规则', 
+                    '2': '批量规则'
+                };
+                var colorMap = {
+                    '0': 'info',
+                    '1': 'success',
+                    '2': 'warning'
+                };
+                
+                var value = row.commission_goods.rule_type;
+                var text = ruleTypeList[value] || '默认规则';
+                var color = colorMap[value] || 'info';
+                
+                return '<span class="label label-' + color + '">' + text + '</span>';
+            },
+            
+            // 商品状态模板
+            goodsStatus: function(row) {
+                var statusMap = {
+                    '0': {text: '仓库中', color: 'default'},
+                    '1': {text: '上架中', color: 'success'},
+                    '2': {text: '已售罄', color: 'warning'},
+                    '3': {text: '已下架', color: 'danger'}
+                };
+                
+                var status = statusMap[row.status] || {text: '未知', color: 'default'};
+                return '<span class="label label-' + status.color + '">' + status.text + '</span>';
+            }
+        },
+        
         index: function () {
         index: function () {
+            // 添加自定义样式
+            Controller.addCustomStyles();
+            
             // 初始化表格参数
             // 初始化表格参数
             Table.api.init({
             Table.api.init({
                 extend: {
                 extend: {
                     index_url: 'commission/goods/index' + location.search,
                     index_url: 'commission/goods/index' + location.search,
                     add_url: '',
                     add_url: '',
-                    edit_url: 'commission/goods/edit',
-                    del_url: 'commission/goods/del',
-                    multi_url: 'commission/goods/multi',
-                    import_url: 'commission/goods/import',
+                    commission_url: 'commission/goods/commission',
+                    del_url: '',
+                    multi_url: '',
+                    import_url: '',
                     table: 'shop_goods',
                     table: 'shop_goods',
+                    dragsort_url: ''
                 }
                 }
             });
             });
 
 
@@ -26,105 +151,29 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                 sort: 'desc',
                 sort: 'desc',
                 columns: [
                 columns: [
                     [
                     [
-                        {checkbox: true},
                         {field: 'id', title: __('ID'), width: 80},
                         {field: 'id', title: __('ID'), width: 80},
-                        {field: 'title', title: __('商品信息'), operate: 'LIKE', width: 350, formatter: function(value, row, index) {
-                            var html = '<div style="display: flex; align-items: center; padding: 5px 0;">';
-                            
-                            // 商品图片
-                            var imageUrl = row.image || '/assets/img/goods-default.png';
-                            html += '<div style="margin-right: 12px; flex-shrink: 0;">';
-                            html += '<img src="' + imageUrl + '" style="width: 60px; height: 60px; object-fit: cover; border-radius: 4px; border: 1px solid #e9ecef;" />';
-                            html += '</div>';
-                            
-                            // 商品信息
-                            html += '<div style="flex: 1; min-width: 0;">';
-                            
-                            // 商品标题
-                            var goodsTitle = row.title || '-';
-                            html += '<div style="color: #337ab7; font-weight: bold; margin-bottom: 4px; line-height: 1.4;">';
-                            html += '<a href="javascript:;" class="goods-title" style="color: #337ab7; text-decoration: none;">';
-                            html += goodsTitle;
-                            html += '</a></div>';
-                            
-                            // 商品副标题/描述
-                            if (row.subtitle) {
-                                html += '<div style="color: #6c757d; font-size: 12px; margin-bottom: 4px; line-height: 1.2;">' + row.subtitle + '</div>';
-                            }
-                            
-                            // 商品分类或其他信息
-                            html += '<div style="color: #999; font-size: 11px;">';
-                            html += 'ID: ' + row.id;
-                            if (row.category_name) {
-                                html += ' | ' + row.category_name;
-                            }
-                            html += '</div>';
-                            
-                            html += '</div></div>';
-                            return html;
+                        {field: 'title', title: __('商品信息'), operate: 'LIKE', width: 400, formatter: function(value, row, index) {
+                            return Controller.templates.goodsInfo(row);
                         }},
                         }},
                         {field: 'price', title: __('价格'), operate: 'BETWEEN', width: 100},
                         {field: 'price', title: __('价格'), operate: 'BETWEEN', width: 100},
                         {field: 'commission_goods.rule_type', title: __('分销规则'), width: 120, formatter: function(value, row, index) {
                         {field: 'commission_goods.rule_type', title: __('分销规则'), width: 120, formatter: function(value, row, index) {
-                            // 如果没有分销配置,默认为不参与
-                            if (!row.commission_goods) {
-                                return '<span class="label label-danger">不参与</span>';
-                            }
-                            
-                            var participateStatus = row.commission_goods.status;
-                            if (participateStatus == 0) {
-                                return '<span class="label label-danger">不参与</span>';
-                            }
-                            
-                            var ruleTypeList = Config.commission_goods_rule_type_list || {
-                                '0': '默认规则',
-                                '1': '独立规则',
-                                '2': '批量规则'
-                            };
-                            var colorMap = {
-                                '0': 'info',
-                                '1': 'success',
-                                '2': 'warning'
-                            };
-                            var text = ruleTypeList[value] || '默认规则';
-                            var color = colorMap[value] || 'info';
-                            return '<span class="label label-' + color + '">' + text + '</span>';
+                            return Controller.templates.commissionStatus(row);
                         }},
                         }},
                         {field: 'status', title: __('商品状态'), width: 100, formatter: function(value, row, index) {
                         {field: 'status', title: __('商品状态'), width: 100, formatter: function(value, row, index) {
-                            var statusMap = {
-                                'normal': {text: '上架中', color: 'success'},
-                                'hidden': {text: '下架', color: 'danger'},
-                                'pulloff': {text: '下架', color: 'danger'}
-                            };
-                            var status = statusMap[value] || {text: '未知', color: 'default'};
-                            return '<span class="label label-' + status.color + '">' + status.text + '</span>';
+                            return Controller.templates.goodsStatus(row);
                         }},
                         }},
                         {field: 'operate', title: __('操作'), table: table, events: Table.api.events.operate, width: 150,
                         {field: 'operate', title: __('操作'), table: table, events: Table.api.events.operate, width: 150,
                          buttons: [
                          buttons: [
                              {
                              {
-                                 name: 'detail',
-                                 text: __('详情'),
-                                 title: __('商品详情'),
-                                 classname: 'btn btn-xs btn-primary',
-                                 icon: 'fa fa-list',
-                                 click: function (data) {
-                                     Fast.api.open('commission/goods/detail?id=' + data.id, '商品详情', {
-                                         area: ['90%', '90%']
-                                     });
-                                 }
-                             },
-                             {
-                                 name: 'edit',
+                                 name: 'commission',
                                  text: __('设置佣金'),
                                  text: __('设置佣金'),
                                  title: __('设置佣金'),
                                  title: __('设置佣金'),
-                                 classname: 'btn btn-xs btn-success',
-                                 icon: 'fa fa-edit',
-                                 click: function (data) {
-                                     Fast.api.open('commission/goods/edit?ids=' + data.id, '设置佣金', {
-                                         area: ['90%', '90%'],
-                                         callback: function(data) {
-                                             table.bootstrapTable('refresh');
-                                         }
-                                     });
+                                 classname: 'btn btn-xs btn-success btn-dialog',
+                                 icon: 'fa fa-cog',
+                                 url: 'commission/goods/commission',
+                                 callback: function(data) {
+                                     // 弹窗回传回调,刷新表格
+                                     table.bootstrapTable('refresh');
                                  }
                                  }
                              }
                              }
                          ], 
                          ], 
@@ -135,22 +184,72 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
 
 
             // 为表格绑定事件
             // 为表格绑定事件
             Table.api.bindevent(table);
             Table.api.bindevent(table);
+        },
+        
+        // 添加自定义样式
+        addCustomStyles: function() {
+            var styles = `
+                <style>
+                /* 商品信息容器样式优化 */
+                .goods-info-container:hover {
+                    background-color: #f8f9fa;
+                    border-radius: 6px;
+                    transition: background-color 0.2s ease;
+                }
+                
+                .goods-image img {
+                    transition: transform 0.2s ease;
+                }
+                
+                .goods-info-container:hover .goods-image img {
+                    transform: scale(1.05);
+                }
+                
+                .goods-title a:hover {
+                    color: #18bc9c !important;
+                    transition: color 0.2s ease;
+                }
+                
+                /* 多规格标签样式 */
+                .goods-spec-badge {
+                    background: linear-gradient(135deg, #18bc9c, #16a085);
+                    color: white;
+                    font-size: 10px;
+                    padding: 2px 8px;
+                    border-radius: 12px;
+                    margin-left: 8px;
+                    font-weight: 500;
+                    box-shadow: 0 1px 3px rgba(24, 188, 156, 0.3);
+                }
+                
+                /* 表格行间距优化 */
+                #table .bootstrap-table .fixed-table-body .table tbody tr td {
+                    padding: 12px 8px;
+                    vertical-align: middle;
+                    border-bottom: 1px solid #e9ecef;
+                }
+                
+                /* 操作按钮样式 */
+                .btn-commission {
+                    background: linear-gradient(135deg, #18bc9c, #16a085);
+                    border: none;
+                    color: white;
+                    font-weight: 500;
+                    transition: all 0.2s ease;
+                }
+                
+                .btn-commission:hover {
+                    background: linear-gradient(135deg, #1dd1a1, #18bc9c);
+                    transform: translateY(-1px);
+                    box-shadow: 0 2px 8px rgba(24, 188, 156, 0.3);
+                }
+                </style>
+            `;
             
             
-            // 批量设置佣金
-            $(document).on('click', '.btn-batch-commission', function() {
-                var ids = Table.api.selectedids(table);
-                if (ids.length == 0) {
-                    Toastr.error('请先选择要设置的商品');
-                    return false;
-                }
-                
-                Fast.api.open('commission/goods/edit?ids=' + ids.join(','), '批量设置佣金', {
-                    area: ['90%', '90%'],
-                    callback: function(data) {
-                        table.bootstrapTable('refresh');
-                    }
-                });
-            });
+            // 添加样式到页面
+            if (!$('#commission-goods-styles').length) {
+                $('head').append(styles.replace('<style>', '<style id="commission-goods-styles">'));
+            }
         },
         },
         detail: function () {
         detail: function () {
             Controller.api.bindevent();
             Controller.api.bindevent();
@@ -158,9 +257,106 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
         edit: function () {
         edit: function () {
             Controller.api.bindevent();
             Controller.api.bindevent();
         },
         },
+        commission: function () {
+            // 佣金设置页面
+            Controller.api.bindevent();
+            
+            // 佣金规则类型切换
+            $(document).on('change', 'input[name="rule_type"]', function() {
+                var ruleType = $(this).val();
+                Controller.updateFormState(ruleType);
+            });
+            
+            // 更新表单状态的方法
+            Controller.updateFormState = function(ruleType) {
+                if (ruleType == '0') { // 默认规则
+                    // 只禁用高级配置项,保持"是否参与"和"分销商业绩"可编辑
+                    $('input[name="level"], input[name="self_buy"], input[name="reward_type"], input[name="reward_event"]').prop('disabled', true);
+                    // "是否参与"和"分销商业绩"保持可编辑
+                    $('input[name="status"], input[name="order_status"]').prop('disabled', false);
+                    
+                    // 显示默认规则的佣金比例
+                    $('.default-rule-value').show();
+                    $('.custom-rule-input').hide();
+                    $('.default-rule-help').show();
+                    $('.custom-rule-help').hide();
+                    
+                    // 添加部分只读样式
+                    $('.commission-form').addClass('readonly-mode');
+                    
+                } else if (ruleType == '1' || ruleType == '2') { // 独立规则或批量规则
+                    // 启用所有配置项
+                    $('input[name="status"], input[name="order_status"], input[name="level"], input[name="self_buy"], input[name="reward_type"], input[name="reward_event"]').prop('disabled', false);
+                    
+                    // 显示自定义规则的输入框
+                    $('.default-rule-value').hide();
+                    $('.custom-rule-input').show();
+                    $('.default-rule-help').hide();
+                    $('.custom-rule-help').show();
+                    
+                    // 移除只读样式
+                    $('.commission-form').removeClass('readonly-mode');
+                }
+            };
+            
+            // 初始化规则显示状态
+            var checkedRuleType = $('input[name="rule_type"]:checked').val() || '0';
+            Controller.updateFormState(checkedRuleType);
+            
+            // 初始化已有数据
+            if (typeof Config.commission_data !== 'undefined' && Config.commission_data) {
+                var commissionData = Config.commission_data;
+                
+                // 设置规则类型
+                if (commissionData.rule_type !== undefined) {
+                    $('input[name="rule_type"][value="' + commissionData.rule_type + '"]').prop('checked', true);
+                }
+                
+                // 设置基本配置
+                if (commissionData.status !== undefined) {
+                    $('input[name="status"][value="' + commissionData.status + '"]').prop('checked', true);
+                }
+                if (commissionData.order_status !== undefined) {
+                    $('input[name="order_status"][value="' + commissionData.order_status + '"]').prop('checked', true);
+                }
+                
+                // 从config中获取扩展配置
+                var config = commissionData.config || {};
+                if (config.self_buy !== undefined) {
+                    $('input[name="self_buy"][value="' + config.self_buy + '"]').prop('checked', true);
+                }
+                if (config.level !== undefined) {
+                    $('input[name="level"][value="' + config.level + '"]').prop('checked', true);
+                }
+                if (config.reward_type !== undefined) {
+                    $('input[name="reward_type"][value="' + config.reward_type + '"]').prop('checked', true);
+                }
+                if (config.reward_event !== undefined) {
+                    $('input[name="reward_event"][value="' + config.reward_event + '"]').prop('checked', true);
+                }
+                
+                // 最后触发状态更新
+                Controller.updateFormState($('input[name="rule_type"]:checked').val() || '0');
+            } else {
+                // 没有数据时,设置默认值
+                $('input[name="rule_type"][value="0"]').prop('checked', true);
+                $('input[name="status"][value="0"]').prop('checked', true);
+                $('input[name="order_status"][value="1"]').prop('checked', true);
+                $('input[name="level"][value="3"]').prop('checked', true);
+                $('input[name="self_buy"][value="1"]').prop('checked', true);
+                $('input[name="reward_type"][value="pay_price"]').prop('checked', true);
+                $('input[name="reward_event"][value="paid"]').prop('checked', true);
+                
+                // 触发状态更新
+                Controller.updateFormState('0');
+            }
+        },
         api: {
         api: {
             bindevent: function () {
             bindevent: function () {
-                Form.api.bindevent($("form[role=form]"));
+                Form.api.bindevent($("form[role=form]"), function(data, ret) {
+                    // 表单提交成功回调
+                    Fast.api.close(ret);
+                });
                 
                 
                 // 绑定独立设置变化事件
                 // 绑定独立设置变化事件
                 $(document).on('change', 'input[name="row[self_rules]"]', function() {
                 $(document).on('change', 'input[name="row[self_rules]"]', function() {