Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录
切换导航
T
taote
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
李达
taote
Commits
963a47b7
提交
963a47b7
authored
3 年前
作者:
duanyinglei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加会员管理模块
上级
cb7672e6
全部展开
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
120 行增加
和
272 行删除
+120
-272
Material.php
application/admin/controller/Material.php
+84
-124
Operators.php
application/admin/controller/Operators.php
+1
-0
User.php
application/admin/controller/user/User.php
+15
-21
edit.html
application/admin/view/user/user/edit.html
+16
-114
user.js
public/assets/js/backend/user/user.js
+4
-13
没有找到文件。
application/admin/controller/Material.php
浏览文件 @
963a47b7
...
...
@@ -2,13 +2,9 @@
namespace
app\admin\controller
;
use
app\admin\library\Auth
;
use
app\common\controller\Backend
;
use
PhpOffice\PhpSpreadsheet\Cell\Coordinate
;
use
PhpOffice\PhpSpreadsheet\Reader\Csv
;
use
PhpOffice\PhpSpreadsheet\Reader\Xls
;
use
PhpOffice\PhpSpreadsheet\Reader\Xlsx
;
use
think\exception\PDOException
;
use
think\Db
;
use
think\Session
;
/**
*
...
...
@@ -31,141 +27,105 @@ class Material extends Backend
}
public
function
import
()
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 排除前台提交过来的字段
* @param $params
* @return array
*/
protected
function
preExcludeFields
(
$params
)
{
$file
=
$this
->
request
->
request
(
'file'
);
if
(
!
$file
)
{
$this
->
error
(
__
(
'Parameter %s can not be empty'
,
'file'
));
}
$filePath
=
ROOT_PATH
.
DS
.
'public'
.
DS
.
$file
;
if
(
!
is_file
(
$filePath
))
{
$this
->
error
(
__
(
'No results were found'
));
}
//实例化reader
$ext
=
pathinfo
(
$filePath
,
PATHINFO_EXTENSION
);
if
(
!
in_array
(
$ext
,
[
'csv'
,
'xls'
,
'xlsx'
]))
{
$this
->
error
(
__
(
'Unknown data format'
));
}
if
(
$ext
===
'csv'
)
{
$file
=
fopen
(
$filePath
,
'r'
);
$filePath
=
tempnam
(
sys_get_temp_dir
(),
'import_csv'
);
$fp
=
fopen
(
$filePath
,
"w"
);
$n
=
0
;
while
(
$line
=
fgets
(
$file
))
{
$line
=
rtrim
(
$line
,
"
\n\r\0
"
);
$encoding
=
mb_detect_encoding
(
$line
,
[
'utf-8'
,
'gbk'
,
'latin1'
,
'big5'
]);
if
(
$encoding
!=
'utf-8'
)
{
$line
=
mb_convert_encoding
(
$line
,
'utf-8'
,
$encoding
);
}
if
(
$n
==
0
||
preg_match
(
'/^".*"$/'
,
$line
))
{
fwrite
(
$fp
,
$line
.
"
\n
"
);
}
else
{
fwrite
(
$fp
,
'"'
.
str_replace
([
'"'
,
','
],
[
'""'
,
'","'
],
$line
)
.
"
\"\n
"
);
if
(
is_array
(
$this
->
excludeFields
))
{
foreach
(
$this
->
excludeFields
as
$field
)
{
if
(
key_exists
(
$field
,
$params
))
{
unset
(
$params
[
$field
]);
}
$n
++
;
}
fclose
(
$file
)
||
fclose
(
$fp
);
$reader
=
new
Csv
();
}
elseif
(
$ext
===
'xls'
)
{
$reader
=
new
Xls
();
}
else
{
$reader
=
new
Xlsx
();
if
(
key_exists
(
$this
->
excludeFields
,
$params
))
{
unset
(
$params
[
$this
->
excludeFields
]);
}
//导入文件首行类型,默认是注释,如果需要使用字段名称请使用name
$importHeadType
=
isset
(
$this
->
importHeadType
)
?
$this
->
importHeadType
:
'comment'
;
$table
=
$this
->
model
->
getQuery
()
->
getTable
();
$database
=
\think\Config
::
get
(
'database.database'
);
$fieldArr
=
[];
$list
=
db
()
->
query
(
"SELECT COLUMN_NAME,COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?"
,
[
$table
,
$database
]);
foreach
(
$list
as
$k
=>
$v
)
{
if
(
$importHeadType
==
'comment'
)
{
$fieldArr
[
$v
[
'COLUMN_COMMENT'
]]
=
$v
[
'COLUMN_NAME'
];
}
else
{
$fieldArr
[
$v
[
'COLUMN_NAME'
]]
=
$v
[
'COLUMN_NAME'
];
}
return
$params
;
}
//加载文件
$insert
=
[];
try
{
if
(
!
$PHPExcel
=
$reader
->
load
(
$filePath
))
{
$this
->
error
(
__
(
'Unknown data format'
));
/**
* 查看
*/
public
function
index
()
{
//设置过滤方法
$this
->
request
->
filter
([
'strip_tags'
,
'trim'
]);
if
(
$this
->
request
->
isAjax
())
{
//如果发送的来源是Selectpage,则转发到Selectpage
if
(
$this
->
request
->
request
(
'keyField'
))
{
return
$this
->
selectpage
();
}
list
(
$where
,
$sort
,
$order
,
$offset
,
$limit
)
=
$this
->
buildparams
();
$admin_id
=
session
::
get
(
"admin"
)[
"id"
]
;
$admin
=
[];
if
(
$admin_id
!=
1
){
$admin
=
[
"admin_id"
=>
$admin_id
];
}
$list
=
$this
->
model
->
where
(
$where
)
->
where
(
$admin
)
->
order
(
$sort
,
$order
)
->
paginate
(
$limit
);
$result
=
array
(
"total"
=>
$list
->
total
(),
"rows"
=>
$list
->
items
());
return
json
(
$result
);
}
return
$this
->
view
->
fetch
();
}
$currentSheet
=
$PHPExcel
->
getSheet
(
0
);
//读取文件中的第一个工作表
$allColumn
=
$currentSheet
->
getHighestDataColumn
();
//取得最大的列号
$allRow
=
$currentSheet
->
getHighestRow
();
//取得一共有多少行
$maxColumnNumber
=
Coordinate
::
columnIndexFromString
(
$allColumn
);
$fields
=
[];
for
(
$currentRow
=
1
;
$currentRow
<=
1
;
$currentRow
++
)
{
for
(
$currentColumn
=
1
;
$currentColumn
<=
$maxColumnNumber
;
$currentColumn
++
)
{
$val
=
$currentSheet
->
getCellByColumnAndRow
(
$currentColumn
,
$currentRow
)
->
getValue
();
$fields
[]
=
$val
;
/**
* 添加
*/
public
function
add
(){
//设置过滤方法
$this
->
request
->
filter
([
'strip_tags'
,
'trim'
]);
if
(
$this
->
request
->
isAjax
())
{
$data
=
$_POST
[
"row"
];
$insert
=
DB
::
name
(
"material"
)
->
insert
(
$data
);
if
(
$insert
>
0
)
{
$this
->
success
();
}
else
{
$this
->
error
(
"添加失败"
);
}
}
return
$this
->
view
->
fetch
();
for
(
$currentRow
=
2
;
$currentRow
<=
$allRow
;
$currentRow
++
)
{
$values
=
[];
for
(
$currentColumn
=
1
;
$currentColumn
<=
$maxColumnNumber
;
$currentColumn
++
)
{
$val
=
$currentSheet
->
getCellByColumnAndRow
(
$currentColumn
,
$currentRow
)
->
getValue
();
$values
[]
=
is_null
(
$val
)
?
''
:
$val
;
}
$row
=
[];
$temp
=
array_combine
(
$fields
,
$values
);
foreach
(
$temp
as
$k
=>
$v
)
{
if
(
isset
(
$fieldArr
[
$k
])
&&
$k
!==
''
)
{
$row
[
$fieldArr
[
$k
]]
=
$v
;
}
}
if
(
$row
)
{
$insert
[]
=
$row
;
}
}
}
catch
(
Exception
$exception
)
{
$this
->
error
(
$exception
->
getMessage
());
}
if
(
!
$insert
)
{
$this
->
error
(
__
(
'No rows were updated'
));
}
try
{
//是否包含admin_id字段
$has_admin_id
=
false
;
foreach
(
$fieldArr
as
$name
=>
$key
)
{
if
(
$key
==
'admin_id'
)
{
$has_admin_id
=
true
;
break
;
}
}
if
(
$has_admin_id
)
{
$auth
=
Auth
::
instance
();
foreach
(
$insert
as
&
$val
)
{
if
(
!
isset
(
$val
[
'admin_id'
])
||
empty
(
$val
[
'admin_id'
]))
{
$val
[
'admin_id'
]
=
$auth
->
isLogin
()
?
$auth
->
id
:
0
;
}
}
/**
* 删除
*/
public
function
del
(
$ids
=
""
){
if
(
!
$this
->
request
->
isPost
())
{
$this
->
error
(
__
(
"Invalid parameters"
));
}
$this
->
model
->
saveAll
(
$insert
);
}
catch
(
PDOException
$exception
)
{
$msg
=
$exception
->
getMessage
();
if
(
preg_match
(
"/.+Integrity constraint violation: 1062 Duplicate entry '(.+)' for key '(.+)'/is"
,
$msg
,
$matches
))
{
$msg
=
"导入失败,包含【
{
$matches
[
1
]
}
】的记录已存在"
;
};
$this
->
error
(
$msg
);
}
catch
(
Exception
$e
)
{
$this
->
error
(
$e
->
getMessage
());
$ids
=
$ids
?
$ids
:
$this
->
request
->
post
(
"ids"
);
if
(
$ids
)
{
$adminIds
=
$this
->
getDataLimitAdminIds
();
if
(
is_array
(
$adminIds
))
{
$this
->
model
->
where
(
$this
->
dataLimitField
,
'in'
,
$adminIds
);
}
$operators
=
$this
->
model
->
where
([
"id"
=>
$ids
])
->
delete
();
if
(
$operators
){
$this
->
success
();
}
else
{
$this
->
error
(
"删除失败"
);
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
// public function
}
$this
->
error
(
__
(
'Parameter %s can not be empty'
,
'ids'
));
}
}
This diff is collapsed.
Click to expand it.
application/admin/controller/Operators.php
浏览文件 @
963a47b7
...
...
@@ -148,6 +148,7 @@ class Operators extends Backend
Db
::
commit
();
$this
->
success
();
}
else
{
Db
::
rollback
();
$this
->
error
(
"删除失败"
);
}
...
...
This diff is collapsed.
Click to expand it.
application/admin/controller/user/User.php
浏览文件 @
963a47b7
...
...
@@ -4,6 +4,8 @@ namespace app\admin\controller\user;
use
app\common\controller\Backend
;
use
app\common\library\Auth
;
use
think\Session
;
use
think\Db
;
/**
* 会员管理
...
...
@@ -39,12 +41,21 @@ class User extends Backend
if
(
$this
->
request
->
request
(
'keyField'
))
{
return
$this
->
selectpage
();
}
$id
=
Session
::
get
(
"admin"
)[
"id"
];
$id_where
=
[];
if
(
$id
!=
1
){
$id_group
=
DB
::
name
(
"operators"
)
->
where
([
"admin_id"
=>
$id
])
->
column
(
"id"
);
$id_where
=
[
"user.operators_id"
=>
[
"in"
,
$id_group
]];
}
list
(
$where
,
$sort
,
$order
,
$offset
,
$limit
)
=
$this
->
buildparams
();
$list
=
$this
->
model
->
with
(
'group'
)
->
field
(
"fa_user.*,o.name as o_name"
)
->
join
(
"operators o"
,
"o.id = fa_user.operators_id"
)
->
where
(
$where
)
->
where
(
$id_where
)
->
order
(
$sort
,
$order
)
->
paginate
(
$limit
);
foreach
(
$list
as
$k
=>
$v
)
{
$v
->
avatar
=
$v
->
avatar
?
cdnurl
(
$v
->
avatar
,
true
)
:
letter_avatar
(
$v
->
nickname
);
$v
->
hidden
([
'password'
,
'salt'
]);
...
...
@@ -75,31 +86,14 @@ class User extends Backend
if
(
$this
->
request
->
isPost
())
{
$this
->
token
();
}
$row
=
$this
->
model
->
get
(
$ids
);
$row
=
$this
->
model
->
field
(
"fa_user.*,o.name as o_name"
)
->
join
(
"operators o"
,
"fa_user.operators_id = o.id"
)
->
where
(
"fa_user.id"
,
$ids
)
->
find
(
);
$this
->
modelValidate
=
true
;
if
(
!
$row
)
{
$this
->
error
(
__
(
'No Results were found'
));
}
$this
->
view
->
assign
(
'groupList'
,
build_select
(
'row[group_id]'
,
\app\admin\model\UserGroup
::
column
(
'id,name'
),
$row
[
'group_id'
],
[
'class'
=>
'form-control selectpicker'
])
);
return
parent
::
edit
(
$ids
);
$this
->
view
->
assign
(
"row"
,
$row
);
return
$this
->
view
->
fetch
(
);
}
/**
* 删除
*/
public
function
del
(
$ids
=
""
)
{
if
(
!
$this
->
request
->
isPost
())
{
$this
->
error
(
__
(
"Invalid parameters"
));
}
$ids
=
$ids
?
$ids
:
$this
->
request
->
post
(
"ids"
);
$row
=
$this
->
model
->
get
(
$ids
);
$this
->
modelValidate
=
true
;
if
(
!
$row
)
{
$this
->
error
(
__
(
'No Results were found'
));
}
Auth
::
instance
()
->
delete
(
$row
[
'id'
]);
$this
->
success
();
}
}
This diff is collapsed.
Click to expand it.
application/admin/view/user/user/edit.html
浏览文件 @
963a47b7
差异被折叠。
点击展开。
public/assets/js/backend/user/user.js
浏览文件 @
963a47b7
...
...
@@ -26,21 +26,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{
checkbox
:
true
},
{
field
:
'id'
,
title
:
__
(
'Id'
),
sortable
:
true
},
{
field
:
'group.name'
,
title
:
__
(
'Group'
)},
{
field
:
'username'
,
title
:
__
(
'Username'
),
operate
:
'LIKE'
},
{
field
:
'nickname'
,
title
:
__
(
'Nickname'
),
operate
:
'LIKE'
},
{
field
:
'email'
,
title
:
__
(
'Email'
),
operate
:
'LIKE'
},
{
field
:
'mobile'
,
title
:
__
(
'Mobile'
),
operate
:
'LIKE'
},
{
field
:
'avatar'
,
title
:
__
(
'Avatar'
),
events
:
Table
.
api
.
events
.
image
,
formatter
:
Table
.
api
.
formatter
.
image
,
operate
:
false
},
{
field
:
'level'
,
title
:
__
(
'Level'
),
operate
:
'BETWEEN'
,
sortable
:
true
},
{
field
:
'gender'
,
title
:
__
(
'Gender'
),
visible
:
false
,
searchList
:
{
1
:
__
(
'Male'
),
0
:
__
(
'Female'
)}},
{
field
:
'score'
,
title
:
__
(
'Score'
),
operate
:
'BETWEEN'
,
sortable
:
true
},
{
field
:
'successions'
,
title
:
__
(
'Successions'
),
visible
:
false
,
operate
:
'BETWEEN'
,
sortable
:
true
},
{
field
:
'maxsuccessions'
,
title
:
__
(
'Maxsuccessions'
),
visible
:
false
,
operate
:
'BETWEEN'
,
sortable
:
true
},
{
field
:
'nickname'
,
title
:
__
(
'Nickname'
),
operate
:
'LIKE'
},
{
field
:
'operators_id'
,
title
:
"运营商ID"
,
operate
:
'LIKE'
},
{
field
:
'popularize_id'
,
title
:
"推广页ID"
,
operate
:
'LIKE'
},
{
field
:
'o_name'
,
title
:
"运营商"
,
operate
:
'LIKE'
},
{
field
:
'logintime'
,
title
:
__
(
'Logintime'
),
formatter
:
Table
.
api
.
formatter
.
datetime
,
operate
:
'RANGE'
,
addclass
:
'datetimerange'
,
sortable
:
true
},
{
field
:
'loginip'
,
title
:
__
(
'Loginip'
),
formatter
:
Table
.
api
.
formatter
.
search
},
{
field
:
'jointime'
,
title
:
__
(
'Jointime'
),
formatter
:
Table
.
api
.
formatter
.
datetime
,
operate
:
'RANGE'
,
addclass
:
'datetimerange'
,
sortable
:
true
},
{
field
:
'joinip'
,
title
:
__
(
'Joinip'
),
formatter
:
Table
.
api
.
formatter
.
search
},
{
field
:
'status'
,
title
:
__
(
'Status'
),
formatter
:
Table
.
api
.
formatter
.
status
,
searchList
:
{
normal
:
__
(
'Normal'
),
hidden
:
__
(
'Hidden'
)}},
{
field
:
'operate'
,
title
:
__
(
'Operate'
),
table
:
table
,
events
:
Table
.
api
.
events
.
operate
,
formatter
:
Table
.
api
.
formatter
.
operate
}
]
]
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论