common.php
12.6 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<?php
use think\Db;
/**
* 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['admin_id'] = session('admin_id');
$add['log_info'] = $log_info;
$add['log_ip'] = getIP();
$add['log_url'] = request()->baseUrl() ;
$add['store_id']=getAdmStoId();
M('log')->add($add);
}
function getAdminInfo($admin_id){
//return D('admin')->where("admin_id", $admin_id)->find();
return D('admin')
->alias('a')
->join('store b','a.store_id = b.store_id')->where("a.admin_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/admin/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);
}
/**
* 面包屑导航 用于后台管理
* 根据当前的控制器名称 和 action 方法
*/
function navigate_admin()
{
$navigate = include APP_PATH.'admin/conf/navigate.php';
$location = strtolower('Admin/'.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('system_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['sub_menu'] as $j=>$v){
if(!in_array($v['control'].'@'.$v['act'], $role_right)){
unset($menu_list[$k]['sub_menu'][$j]);//过滤菜单
}
}
}
}
return $menu_list;
}
function getAllMenu(){
return array(
'system' => array('name'=>'系统设置','icon'=>'fa-cog','sub_menu'=>array(
array('name'=>'物流配置','act'=>'sindex','op'=>'Plugin'),
array('name'=>'门店分类','act'=>'storages_category_list','op'=>'Pickup'),
array('name'=>'门店管理','act'=>'index','op'=>'Pickup'),
array('name'=>'清除缓存','act'=>'cleanCache','op'=>'System'),
)),
'access' => array('name' => '权限管理', 'icon'=>'fa-gears', 'sub_menu' => array(
array('name' => '管理员列表', 'act'=>'index', 'control'=>'Admin'),
array('name' => '角色管理', 'act'=>'role', 'control'=>'Admin'),
array('name' => '管理员日志', 'act'=>'log', 'control'=>'Admin'),
)),
'member' => array('name'=>'会员管理','icon'=>'fa-user','sub_menu'=>array(
array('name'=>'会员列表','act'=>'index','control'=>'User'),
array('name'=>'会员等级','act'=>'levelList','control'=>'User'),
array('name'=>'充值记录','act'=>'recharge','control'=>'User'),
array('name' => '提现申请', 'act'=>'withdrawals', 'control'=>'User'),
array('name' => '汇款记录', 'act'=>'remittance', 'control'=>'User'),
//array('name'=>'会员整合','act'=>'integrate','control'=>'User'),
)),
'goods' => array('name' => '商品管理', 'icon'=>'fa-book', 'sub_menu' => array(
array('name' => '商品分类', 'act'=>'categoryList', 'op'=>'Goods'),
array('name' => '国家分类', 'act'=>'nationList', 'op'=>'Goods'),
array('name' => '品牌列表', 'act'=>'brandList', 'op'=>'Goods'),
array('name' => '商品管理', 'act'=>'goodsList', 'op'=>'Goods'),
array('name' => '商品分组', 'act'=>'goodsGroup', 'op'=>'Goods'),
)),
'order' => array('name' => '订单管理', 'icon'=>'fa-money', 'sub_menu' => array(
array('name' => '订单列表', 'act'=>'index', 'op'=>'Order'),
array('name' => '发货单', 'act'=>'delivery_list', 'op'=>'Order'),
array('name' => '退货单', 'act'=>'return_list', 'op'=>'Order'),
array('name' => '订单日志','act'=>'order_log','op'=>'Order'),
array('name' => '评论列表', 'act'=>'index', 'op'=>'Comment'),
array('name'=>'提现申请','act'=>'withdrawals','op'=>'User'),
array('name'=>'汇款记录','act'=>'remittance','op'=>'User'),
)),
'promotion' => array('name' => '促销管理', 'icon'=>'fa-bell', 'sub_menu' => array(
array('name' => '秒杀特区', 'act'=>'flash_sale', 'op'=>'Promotion'),
array('name' => '团购管理', 'act'=>'group_buy_list', 'op'=>'Promotion'),
array('name' => '优惠促销', 'act'=>'prom_goods_list', 'op'=>'Promotion'),
array('name' => '订单促销', 'act'=>'prom_order_list', 'op'=>'Promotion'),
array('name' => '优惠券','act'=>'index', 'op'=>'Coupon'),
)),
'Ad' => array('name' => '广告管理', 'icon'=>'fa-flag', 'sub_menu' => array(
array('name'=>'广告列表','act'=>'adList','op'=>'Ad'),
array('name'=>'商城首页','act'=>'shop_index','op'=>'Ad'),
)),
'content' => array('name' => '文章管理', 'icon'=>'fa-comments', 'sub_menu' => array(
array('name' => '文章列表', 'act'=>'articleList', 'op'=>'Article'),
array('name' => '文章分类', 'act'=>'categoryList', 'op'=>'Article'),
)),
'weixin' => array('name' => '微信管理', 'icon'=>'fa-weixin', 'sub_menu' => array(
array('name' => '公众号配置', 'act'=>'wxsq', 'op'=>'Wechat'),
array('name' => '支付配置', 'act'=>'setting', 'op'=>'Wechat'),
array('name' => '微信菜单管理', 'act'=>'menu', 'op'=>'Wechat'),
array('name' => '关注二维码', 'act'=>'bulidewm', 'op'=>'Wechat'),
array('name' => '关键字回复', 'act'=>'keyrepayList', 'op'=>'Wechat'),
array('name' => '推送消息设置', 'act'=>'wxsendlist', 'op'=>'Wechat'),
)),
/**/
'distribut' => array('name' => '分销管理', 'icon'=>'fa-cubes', 'sub_menu' => array(
array('name' => '分销商品列表', 'act'=>'goods_list', 'op'=>'Distribut'),
array('name' => '分销商列表', 'act'=>'distributor_list', 'op'=>'Distribut'),
array('name'=>'分销会员','act'=>'index','op'=>'User'),
array('name' => '分销关系', 'act'=>'tree', 'op'=>'Distribut'),
array('name' => '分销设置', 'act'=>'set', 'op'=>'Distribut'),
array('name' => '分成日志', 'act'=>'rebate_log', 'op'=>'Distribut'),
)),
'count' => array('name' => '统计报表', 'icon'=>'fa-signal', 'sub_menu' => array(
array('name' => '销售统计', 'act'=>'index', 'control'=>'Report'),
array('name' => '销售排行', 'act'=>'saleTop', 'control'=>'Report'),
array('name' => '会员排行', 'act'=>'userTop', 'control'=>'Report'),
array('name' => '销售明细', 'act'=>'saleList', 'control'=>'Report'),
array('name' => '会员统计', 'act'=>'user', 'control'=>'Report'),
array('name' => '财务统计', 'act'=>'finance', 'control'=>'Report'),
)),
'pickup' => array('name' => '自提点管理', 'icon'=>'fa-anchor', 'sub_menu' => array(
array('name' => '自提点列表', 'act'=>'index', 'control'=>'Pickup'),
array('name' => '添加自提点', 'act'=>'add', 'control'=>'Pickup'),
))
);
}
function getMenuArr($stoinfo=null){
if ($stoinfo['isweb_reg'])
{
$menuArr = include APP_PATH.'admin/conf/web_menu.php';
}
else{
$menuArr = include APP_PATH.'admin/conf/menu.php';
}
$act_list = session('act_list');
$role_right="";
if($act_list != 'all' && !empty($act_list)){
$right = M('system_menu')->where("id in ($act_list)")->getField('right',true);
foreach ($right as $val){
$role_right .= $val.',';
}
$role_right=",".$role_right;
foreach($menuArr as $k=>$val){
foreach ($val['child'] as $j=>$v){
foreach ($v['child'] as $s=>$son){
if(!strpos(",".$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));
}
/*--获取退款商品的名称--*/
function getregoodssn($item){
if(empty($item['goods_id'])){
$goodsarr=explode(',',$item['goods_id_list']);
$goods = M('goods')->where("goods_id","in",$goodsarr)->select();
}else{
$goods = M('goods')->where("goods_id", $item['goods_id'])->select();
}
$sn="";
foreach ($goods as $k=>$v){
$sn.=$v['goods_sn'].",";
}
$sn=substr($sn,0,strlen($sn)-1);
return $sn;
}
/*--获取退款商品的编号--*/
function getregoodsname($item){
if(empty($item['goods_id'])){
$goodsarr=explode(',',$item['goods_id_list']);
$goods = M('goods')->where("goods_id","in",$goodsarr)->select();
}else{
$goods = M('goods')->where("goods_id", $item['goods_id'])->select();
}
$name="";
foreach ($goods as $k=>$v){
$name.=$v['goods_name'].",";
}
$name=substr($name,0,strlen($name)-1);
return $name;
}
function getreinfogoodsname($item,$stoid){
if(empty($item['goods_id'])) {
$goodsarr=explode(',',$item['goods_id_list']);
$goods = M('goods')->where("goods_id","in",$goodsarr)->select();
}else{
$goods = M('goods')->where("goods_id", $item['goods_id'])->select();
}
foreach ($goods as $kl=>$vl){
$htm.="<a href ='/index.php/Mobile/Goods/goodsInfo/id/".$vl['goods_id']."/stoid/".$stoid."' target = '_blank' >".$vl[goods_name]."</a> ";
}
return $htm;
}
function html_substr_con($text){
$text=trim($text);
$len=mb_strlen($text,"utf-8");
if($len>30) $text=mb_substr($text,0,20,"utf-8");
return $text;
}
function two_time($time){
$year2 = date("Y",$time); // 时间1的年份
$month2 = date("m",$time); // 时间1的月份
$now=time();
$year1 = date("Y",$now); // 时间2的年份
$month1 = date("m",$now); // 时间2的月份
$need= ($year2 * 12 + $month2) - ($year1 * 12 + $month1)+1;
if($need) return $need;
return 1;
}