<?php /** * AbstractController.class.php * $author$ * @Reader 2017-07-13 10:16:17 zhoutao */ namespace Apicp\Controller\Level; abstract class AbstractController extends \Apicp\Controller\AbstractController { /** * 验证等级数据合法性 * @param $levels */ protected function verificationLevel($levels) { // 重置数组 reset($levels); // 第一级最大积分值不能小于1 if (current($levels)['max'] < 1) { E('_ERR_INTEGRAL_FIRST_LEVELS_MAX'); } // 最后一级最大积分值必须是-1 if (end($levels)['max'] != - 1) { E('_ERR_INTEGRAL_LAST_LEVELS_MAX'); } // 重置数组 reset($levels); // 最后一级的下标 $lastLevelIndex = count($levels) - 1; // 上一级的最大积分值 $previousLevelMax = 0; foreach ($levels as $currentIndex => $level) { // 当前实际等级 $currentRealIndex = $currentIndex + 1; // 无名称 if (empty($level['name'])) { E(L('_ERR_INTEGRAL_LEVELS_NAME_NULL', ['currentLevel' => $currentRealIndex])); } // 无最大值 if (empty($level['max'])) { E(L('_ERR_INTEGRAL_LEVELS_MAX_NULL', ['currentLevel' => $currentRealIndex])); } // 无 icon if (empty($level['icon'])) { E(L('_ERR_INTEGRAL_LEVELS_ICON_NULL', ['currentLevel' => $currentRealIndex])); } // 无 iconType if (empty($level['iconType'])) { E(L('_ERR_INTEGRAL_ICON_TYPE_NULL', ['currentLevel' => $currentRealIndex])); } // 当前为第一级 或者 最后一级时 记录上一级的最大积分值 if ($currentIndex == 0 || $currentIndex == $lastLevelIndex) { $previousLevelMax = $level['max']; continue; } // 当前等级最大积分值必须大于上个等级的最大积分值 if ($previousLevelMax != 0 && $level['max'] <= $previousLevelMax) { E(L('_ERR_INTEGRAL_ADJACENT_LEVELS_MAX', [ 'currentLevel' => $currentRealIndex, 'previousLevel' => $currentIndex ])); } // 记录当前级数最大积分值 $previousLevelMax = $level['max']; } } /** * 更改数组字段名 * @param $arr array 数组数据 * @param $changeFiledName array 要更新的字段名 * '原来的字段名' => '要换成的字段名' */ protected function changeFieldName(&$arr, $changeFiledName) { foreach ($changeFiledName as $originalName => $currentName) { $arr[$currentName] = $arr[$originalName]; unset($arr[$originalName]); } } }