1+ <?php
2+
3+ namespace app \admin \controller ;
4+
5+ use gophp \db ;
6+ use gophp \page ;
7+ use gophp \request ;
8+
9+ class project extends auth {
10+
11+ public function index ()
12+ {
13+
14+ $ search = request::get ('search ' , []);
15+
16+ $ db = db::instance ();
17+
18+ $ table_suffix = $ db ->suffix ;
19+ $ table_name = $ table_suffix .'project ' ;
20+
21+ if ($ title = trim ($ search ['project ' ])){
22+
23+ $ where = "title like '% {$ title }%' " ;
24+
25+ }
26+
27+ if ($ user = trim ($ search ['user ' ])){
28+
29+ $ user_sql = 'select id from ' . $ table_suffix . 'user where ' . "(name like '% {$ user }%' or email like '% {$ user }%') " ;
30+
31+ $ user_ids = $ db ->show (false )->query ($ user_sql );
32+
33+ $ user_ids = array_column ($ user_ids , 'id ' );
34+
35+ $ where = $ where ? $ where .= ' and ' : '' ;
36+
37+ if ($ user_ids ){
38+
39+ $ where .= "user_id in ( " . implode (', ' , $ user_ids ) . ') ' ;
40+
41+ }else {
42+
43+ $ where .= 'user_id in (0) ' ;
44+
45+ }
46+
47+ }
48+
49+ $ where = $ where ? ' where ' . $ where : '' ;
50+
51+ $ sql = "select * from $ table_name $ where " ;
52+
53+ $ total = count ($ db ->show (false )->query ($ sql ));
54+
55+ $ pre_rows = 10 ;
56+
57+ $ page = new page ($ total , $ pre_rows );
58+
59+ $ projects = $ db ->show (false )->query ($ sql , $ pre_rows );
60+
61+ $ this ->assign ('search ' , $ search );
62+ $ this ->assign ('page ' , $ page );
63+ $ this ->assign ('projects ' , $ projects );
64+
65+ $ this ->display ('project/index ' );
66+
67+ }
68+
69+ /**
70+ * 删除项目
71+ */
72+ public function delete (){
73+
74+ $ project_id = request::post ('project_id ' , 0 );
75+ $ password = request::post ('password ' , '' );
76+
77+ $ project = \app \project::get_project_info ($ project_id );
78+
79+ if (!$ project ){
80+
81+ response::ajax (['code ' => 301 , 'msg ' => '请选择要删除的项目! ' ]);
82+
83+ }
84+
85+ if (!user::check_password ($ password )){
86+
87+ response::ajax (['code ' => 302 , 'msg ' => '抱歉,密码验证失败! ' ]);
88+
89+ }
90+
91+ if (!user::is_creater ($ project_id ) && !user::is_admin ()){
92+
93+ response::ajax (['code ' => 303 , 'msg ' => '抱歉,您无权删除该项目! ' ]);
94+
95+ }
96+
97+ if (\app \project::delete ($ project_id )){
98+
99+ response::ajax (['code ' => 200 , 'msg ' => '删除成功! ' ]);
100+
101+ }else {
102+
103+ response::ajax (['code ' => 403 , 'msg ' => '删除失败! ' ]);
104+
105+ }
106+
107+ }
108+
109+
110+ }
0 commit comments