common.php
6.5 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
/**
* tpshop
* ============================================================================
* 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
* 网站地址: http://www.tp-shop.cn
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
* 不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* Author: 当燃
* Date: 2015-09-09
*/
/**
* 管理员操作记录
* @param $log_url 操作URL
* @param $log_info 记录信息
*/
function adminLog($log_info){
$add['log_time'] = time();
$add['manager_id'] = session('manager_id');
$add['log_info'] = $log_info;
$add['log_ip'] = getIP();
$add['log_url'] = request()->baseUrl() ;
M('manager_log')->add($add);
}
function getAdminInfo($admin_id){
return D('manager_admin')->alias('a')
->join('manager_role b',' a.manager_role_id=b.manager_role_id','left')
->field('a.*,b.manager_role_name')
->where("a.manager_id", $admin_id)->find();
}
function tpversion()
{
//在线升级系统
if(!empty($_SESSION['isset_push']))
return false;
$_SESSION['isset_push'] = 1;
error_reporting(0);//关闭所有错误报告
$app_path = dirname($_SERVER['SCRIPT_FILENAME']).'/';
$version_txt_path = $app_path.'/application/manger/aonf/version.php';
$curent_version = file_get_contents($version_txt_path);
$vaules = array(
'domain'=>$_SERVER['HTTP_HOST'],
'last_domain'=>$_SERVER['HTTP_HOST'],
'key_num'=>$curent_version,
'install_time'=>INSTALL_DATE,
'cpu'=>'0001',
'mac'=>'0002',
'serial_number'=>SERIALNUMBER,
);
$url = "http://service.tp-shop.cn/index.php?m=Home&c=Index&a=user_push&".http_build_query($vaules);
stream_context_set_default(array('http' => array('timeout' => 3)));
file_get_contents($url);
}
/**manager
* 面包屑导航 用于后台管理
* 根据当前的控制器名称 和 action 方法
*/
function navigate_admin()
{
$navigate = include APP_PATH.'manager/conf/navigate.php';
$location = strtolower('manager/'.CONTROLLER_NAME);
$arr = array(
'后台首页'=>'javascript:void();',
$navigate[$location]['name']=>'javascript:void();',
$navigate[$location]['action'][ACTION_NAME]=>'javascript:void();',
);
return $arr;
}
/**
* 导出excel
* @param $strTable 表格内容
* @param $filename 文件名
*/
function downloadExcel($strTable,$filename)
{
header("Content-type: application/vnd.ms-excel");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".$filename."_".date('Y-m-d').".xls");
header('Expires:0');
header('Pragma:public');
echo '<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'.$strTable.'</html>';
}
/**
* 格式化字节大小
* @param number $size 字节数
* @param string $delimiter 数字和单位分隔符
* @return string 格式化后的带单位的大小
*/
function format_bytes($size, $delimiter = '') {
$units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
for ($i = 0; $size >= 1024 && $i < 5; $i++) $size /= 1024;
return round($size, 2) . $delimiter . $units[$i];
}
/**
* 根据id获取地区名字
* @param $regionId id
*/
function getRegionName($regionId){
$data = M('region')->where(array('id'=>$regionId))->field('name')->find();
return $data['name'];
}
function getMenuList($act_list){
//根据角色权限过滤菜单
$menu_list = getAllMenu();
if($act_list != 'all'){
$right = M('manager_menu')->where("id", "in", $act_list)->getField('right',true);
foreach ($right as $val){
$role_right .= $val.',';
}
$role_right = explode(',', $role_right);
foreach($menu_list as $k=>$mrr){
foreach ($mrr['child'] as $j=>$v){
if(!in_array($v['control'].'@'.$v['act'], $role_right)){
unset($menu_list[$k]['child'][$j]);//过滤菜单
}
}
}
}
return $menu_list;
}
function getAllMenu(){
return array(
'system'=>array('name'=>'系统','child'=>array(
array('name' => '基础设置','child' => array(
array('name'=>'系统配置','act'=>'basic','op'=>'system'),
array('name'=>'推送模板','act'=>'wxsendtype','op'=>'Set'),
array('name'=>'地区&配送','act'=>'region','op'=>'Set'),
array('name'=>'广告位置','act'=>'positionList','op'=>'Ad'),
)),
array('name' => '权限','child'=>array(
array('name' => '管理员列表', 'act'=>'index', 'op'=>'Manager'),
array('name' => '角色管理', 'act'=>'role', 'op'=>'Manager'),
array('name'=>'权限资源列表','act'=>'right_list','op'=>'Manager'),
array('name' => '管理员日志', 'act'=>'log', 'op'=>'Manager'),
)),
array('name' => '物流','child'=>array(
array('name' => '物流配置', 'act'=>'index', 'op'=>'Shipping'),
)),
)),
'shop'=>array('name'=>'商家','child'=>array(
array('name' => '商家管理','child' => array(
array('name' => '商家列表', 'act'=>'index', 'op'=>'Admin'),
array('name' => '添加商家', 'act'=>'store_info', 'op'=>'Admin'),
array('name' => '资源权限列表', 'act'=>'right_list', 'op'=>'Admin'),
array('name' => '商家短信', 'act'=>'store_sms', 'op'=>'Admin'),
)),
)),
);
}
function getMenuArr(){
$menuArr = include APP_PATH.'manager/conf/menu.php';
$act_list = session('act_list');
if($act_list != 'all' && !empty($act_list)){
$right = M('manager_menu')->where("id in ($act_list)")->cache(false)->getField('right',true);
foreach ($right as $val){
$role_right .= $val.',';
}
foreach($menuArr as $k=>$val){
foreach ($val['child'] as $j=>$v){
foreach ($v['child'] as $s=>$son){
if(!strpos("0".$role_right,$son['op'].'@'.$son['act'])){
unset($menuArr[$k]['child'][$j]['child'][$s]);//过滤菜单
}
}
}
}
foreach ($menuArr as $mk=>$mr){
foreach ($mr['child'] as $nk=>$nrr){
if(empty($nrr['child'])){
unset($menuArr[$mk]['child'][$nk]);
}
}
}
}
return $menuArr;
}
function respose($res){
exit(json_encode($res));
}