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(); } /** * 编辑配置 */ public function edit($ids = null) { if ($this->request->isPost()) { $this->token(); $params = $this->request->post("row/a", [], 'trim'); if ($params) { try { // 验证配置参数 $this->validateConfigParams($params); // 特殊处理某些配置项 if (isset($params['become_agent']) && is_array($params['become_agent'])) { $params['become_agent'] = json_encode($params['become_agent'], JSON_UNESCAPED_UNICODE); } // 更新配置 ShopConfigService::setConfigs('shop.commission', $params); $this->success('配置保存成功'); } catch (ValidateException $e) { $this->error($e->getMessage()); } catch (PDOException $e) { $this->error($e->getMessage()); } //catch (\Exception $e) { // $this->error($e->getMessage()); // } } $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}参数无效"); } } } }