forked from kuafuRace/phprap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectController.php
More file actions
100 lines (76 loc) · 2.51 KB
/
Copy pathProjectController.php
File metadata and controls
100 lines (76 loc) · 2.51 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
<?php
namespace app\controllers\admin;
use Yii;
use yii\web\Response;
use app\models\Project;
use app\models\project\DeleteProject;
use app\models\project\RecoverProject;
class ProjectController extends PublicController
{
/**
* 搜索项目
* @return string
*/
public function actionIndex()
{
$params = Yii::$app->request->queryParams;
$params['status'] = Project::ACTIVE_STATUS;
$model = Project::findModel()->search($params);
return $this->display('index', ['project' => $model]);
}
/**
* 回收站
* @return string
* @throws \Exception
*/
public function actionRecycle()
{
$params = Yii::$app->request->queryParams;
$params['status'] = Project::DELETED_STATUS;
$params['orderBy'] = 'updated_at desc';
$model = Project::findModel()->search($params);
return $this->display('recycle', ['project' => $model]);
}
/**
* 删除项目
* @param $id
* @return array|string
*/
public function actionDelete($id)
{
$request = Yii::$app->request;
$model = DeleteProject::findModel(['encode_id' => $id]);
if($request->isPost) {
Yii::$app->response->format = Response::FORMAT_JSON;
if(!$model->load($request->post())) {
return ['status' => 'error', 'message' => '数据加载失败'];
}
if($model->delete()) {
return ['status' => 'success', 'message' => '删除成功'];
}
return ['status' => 'error', 'message' => $model->getErrorMessage(), 'label' => $model->getErrorLabel()];
}
return $this->display('delete', ['project' => $model]);
}
/**
* 删除项目
* @param $id
* @return array|string
*/
public function actionRecover($id)
{
$request = Yii::$app->request;
$model = RecoverProject::findModel(['encode_id' => $id]);
if($request->isPost) {
Yii::$app->response->format = Response::FORMAT_JSON;
if(!$model->load($request->post())) {
return ['status' => 'error', 'message' => '数据加载失败'];
}
if($model->delete()) {
return ['status' => 'success', 'message' => '恢复成功'];
}
return ['status' => 'error', 'message' => $model->getErrorMessage(), 'label' => $model->getErrorLabel()];
}
return $this->display('recover', ['project' => $model]);
}
}