AbstractController.class.php
2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?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]);
}
}
}