Commit 65053abe67d21aa0f813b73820626f8097eeb87d
1 parent
0ec20199
Exists in
master
app-ht(build v0.0.1 build 4)
1.后台项目管理功能实现。
Showing
15 changed files
with
693 additions
and
14 deletions
Show diff stats
app-ht/config/main.php
@@ -46,8 +46,8 @@ $config = [ | @@ -46,8 +46,8 @@ $config = [ | ||
46 | 'my'=>[ | 46 | 'my'=>[ |
47 | 'class' => 'app\ht\modules\my\Module', | 47 | 'class' => 'app\ht\modules\my\Module', |
48 | ], | 48 | ], |
49 | - 'automation' => [ | ||
50 | - 'class' => 'app\ht\modules\automation\Module', | 49 | + 'project' => [ |
50 | + 'class' => 'app\ht\modules\project\Module', | ||
51 | ], | 51 | ], |
52 | 'model' => [ | 52 | 'model' => [ |
53 | 'class' => 'app\ht\modules\model\Module', | 53 | 'class' => 'app\ht\modules\model\Module', |
app-ht/config/params.php
@@ -3,5 +3,5 @@ return [ | @@ -3,5 +3,5 @@ return [ | ||
3 | 'adminEmail' => 'tech@jiwork.com', | 3 | 'adminEmail' => 'tech@jiwork.com', |
4 | 'DINGTALKL_URL' => 'https://tdd.jiwork.com/', //在钉钉端用系统扫码之后跳转到钉钉对应的界面,里面要指定钉钉的网址 | 4 | 'DINGTALKL_URL' => 'https://tdd.jiwork.com/', //在钉钉端用系统扫码之后跳转到钉钉对应的界面,里面要指定钉钉的网址 |
5 | 'BAIDU_MAP_BROWSER_KEY' => 'UzLG5fpQtralY2hXO3wvVFzvlCmw6Rue', | 5 | 'BAIDU_MAP_BROWSER_KEY' => 'UzLG5fpQtralY2hXO3wvVFzvlCmw6Rue', |
6 | - 'VERSION' => 'v0.0.1 build 3', | 6 | + 'VERSION' => 'v0.0.1 build 4', |
7 | ]; | 7 | ]; |
8 | \ No newline at end of file | 8 | \ No newline at end of file |
app-ht/modules/model/controllers/ModelController.php
@@ -53,7 +53,7 @@ class ModelController extends BaseController | @@ -53,7 +53,7 @@ class ModelController extends BaseController | ||
53 | $where[] = ['<=', 'm.created_at', $endTime]; | 53 | $where[] = ['<=', 'm.created_at', $endTime]; |
54 | } | 54 | } |
55 | if ($name) { | 55 | if ($name) { |
56 | - $where[] = ['like', 'p.name', $name]; | 56 | + $where[] = ['like', 'm.name', $name]; |
57 | } | 57 | } |
58 | if ($type == 0) { | 58 | if ($type == 0) { |
59 | $pageList = ModelRepository::getPageList($where); | 59 | $pageList = ModelRepository::getPageList($where); |
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +<?php namespace app\ht\modules\project; | ||
2 | + | ||
3 | +/** | ||
4 | + * @author CM | ||
5 | + */ | ||
6 | +class Module extends \app\ht\modules\BaseModule | ||
7 | +{ | ||
8 | + public function init() | ||
9 | + { | ||
10 | + parent::init(); | ||
11 | + | ||
12 | + $this->params['perm'] = require(__DIR__ . '/config/perm.php'); | ||
13 | + } | ||
14 | +} | ||
0 | \ No newline at end of file | 15 | \ No newline at end of file |
app-ht/modules/project/controllers/ProjectController.php
0 → 100644
@@ -0,0 +1,186 @@ | @@ -0,0 +1,186 @@ | ||
1 | +<?php | ||
2 | + | ||
3 | +namespace app\ht\modules\project\controllers; | ||
4 | + | ||
5 | +use Yii; | ||
6 | +use yii\data\Pagination; | ||
7 | +use domain\project\Project; | ||
8 | +use domain\project\ProjectRepository; | ||
9 | +use app\ht\controllers\BaseController; | ||
10 | + | ||
11 | +/** | ||
12 | + * 项目管理 | ||
13 | + * Class ProjectController | ||
14 | + * @package app\ht\modules\project\controllers | ||
15 | + */ | ||
16 | +class ProjectController extends BaseController | ||
17 | +{ | ||
18 | + /** | ||
19 | + * 项目管理 | ||
20 | + */ | ||
21 | + public function actionIndex() | ||
22 | + { | ||
23 | + $params = $this->dataList(1); | ||
24 | + /** | ||
25 | + * 渲染模板 | ||
26 | + */ | ||
27 | + return $this->render('index', $params); | ||
28 | + } | ||
29 | + | ||
30 | + /** | ||
31 | + * 查询数据列表 | ||
32 | + */ | ||
33 | + protected function dataList($type = '') | ||
34 | + { | ||
35 | + $request = Yii::$app->request; | ||
36 | + $creatTime = $request->get('creatTime'); | ||
37 | + $endTime = $request->get('endTime'); | ||
38 | + $name = $request->get('name'); | ||
39 | + | ||
40 | + $gets = [ | ||
41 | + 'creatTime' => $creatTime, | ||
42 | + 'endTime' => $endTime, | ||
43 | + 'name' => $name, | ||
44 | + ]; | ||
45 | + | ||
46 | + $where = ['and']; | ||
47 | + if ($creatTime) { | ||
48 | + $creatTime = strtotime($creatTime); | ||
49 | + $where[] = ['>=', 'p.created_at', $creatTime]; | ||
50 | + } | ||
51 | + if ($endTime) { | ||
52 | + $endTime = strtotime($endTime) + 86400; | ||
53 | + $where[] = ['<=', 'p.created_at', $endTime]; | ||
54 | + } | ||
55 | + if ($name) { | ||
56 | + $where[] = ['like', 'p.name', $name]; | ||
57 | + } | ||
58 | + if ($type == 0) { | ||
59 | + $pageList = ProjectRepository::getPageList($where); | ||
60 | + $pages = null; | ||
61 | + } else { | ||
62 | + $pageSize = 20; | ||
63 | + $pages = new Pagination(['totalCount' => ProjectRepository::getPageCount($where), 'pageSize' => $pageSize]); | ||
64 | + $pageList = ProjectRepository::getPageList($where, $pages->offset, $pages->limit); | ||
65 | + } | ||
66 | + | ||
67 | + /** | ||
68 | + * 数据整理 | ||
69 | + */ | ||
70 | + return [ | ||
71 | + 'listdata' => $pageList, | ||
72 | + 'pages' => $pages, | ||
73 | + 'gets' => $gets | ||
74 | + ]; | ||
75 | + } | ||
76 | + | ||
77 | + /** | ||
78 | + * 创建项目 | ||
79 | + * @return string | ||
80 | + */ | ||
81 | + public function actionCreate() | ||
82 | + { | ||
83 | + return $this->render('create'); | ||
84 | + } | ||
85 | + | ||
86 | + /** | ||
87 | + * 创建项目 | ||
88 | + * @return string | ||
89 | + */ | ||
90 | + public function actionDoAdd() | ||
91 | + { | ||
92 | + $request = Yii::$app->request; | ||
93 | + $name = $request->post("name"); // 项目 | ||
94 | + if (empty($name)) { | ||
95 | + Yii::$app->session->setFlash('error', '项目不能为空'); | ||
96 | + return $this->render('create'); | ||
97 | + } | ||
98 | + $result = Project::create($request->post()); | ||
99 | + if ($result === -1) { | ||
100 | + Yii::$app->session->setFlash('error', '添加失败, 项目' . $name . '已存在'); | ||
101 | + return $this->render('create'); | ||
102 | + } | ||
103 | + if ($result) { | ||
104 | + Yii::$app->session->setFlash('success', '添加成功'); | ||
105 | + } else { | ||
106 | + Yii::$app->session->setFlash('error', '添加失败'); | ||
107 | + } | ||
108 | + | ||
109 | + return $this->redirect('index'); | ||
110 | + } | ||
111 | + | ||
112 | + /** | ||
113 | + * 编辑项目 | ||
114 | + * @return string | ||
115 | + */ | ||
116 | + public function actionEdit() | ||
117 | + { | ||
118 | + $ProjectId = $this->request->get("mid"); | ||
119 | + $info = ProjectRepository::selectOne($ProjectId, true); | ||
120 | + return $this->render('edit', ["info" => $info]); | ||
121 | + } | ||
122 | + | ||
123 | + /** | ||
124 | + * 编辑项目 | ||
125 | + * @return string | ||
126 | + */ | ||
127 | + public function actionDoEdit() | ||
128 | + { | ||
129 | + $request = Yii::$app->request; | ||
130 | + $name = $request->post("name"); | ||
131 | + $mid = $request->post("mid"); | ||
132 | + if (empty($mid)) { | ||
133 | + Yii::$app->session->setFlash('error', '项目编号不能为空'); | ||
134 | + $params = $this->dataList(1); | ||
135 | + return $this->render('index', $params); | ||
136 | + } | ||
137 | + $Project =ProjectRepository::selectOne($mid,true); | ||
138 | + if (empty($Project)) { | ||
139 | + Yii::$app->session->setFlash('error', '项目记录不存在'); | ||
140 | + $params = $this->dataList(1); | ||
141 | + return $this->render('index', $params); | ||
142 | + } | ||
143 | + if (empty($name)) { | ||
144 | + Yii::$app->session->setFlash('error', '项目不能为空'); | ||
145 | + return $this->render('edit', ["info" => $Project]); | ||
146 | + } | ||
147 | + | ||
148 | + $result = Project::update($mid, $request->post()); | ||
149 | + | ||
150 | + if ($result === -1) { | ||
151 | + Yii::$app->session->setFlash('error', '修改的项目' . $name . '已存在'); | ||
152 | + return $this->render('edit', ["info" => $Project]); | ||
153 | + } | ||
154 | + if ($result) { | ||
155 | + Yii::$app->session->setFlash('success', '编辑成功'); | ||
156 | + } else { | ||
157 | + Yii::$app->session->setFlash('error', '编辑失败'); | ||
158 | + } | ||
159 | + $Project = ProjectRepository::selectOne($mid,true); | ||
160 | + return $this->render('edit', ["info" => $Project]); | ||
161 | + } | ||
162 | + | ||
163 | + /** | ||
164 | + * 删除项目 | ||
165 | + * @return string | ||
166 | + * @throws \Exception | ||
167 | + */ | ||
168 | + public function actionDoDel() | ||
169 | + { | ||
170 | + $request = Yii::$app->request; | ||
171 | + $itemId = $request->post("data_id"); | ||
172 | + $msg = array(); | ||
173 | + | ||
174 | + // 删除对应的项目 | ||
175 | + if (Project::delete($itemId)) { | ||
176 | + $msg['status'] = 1; | ||
177 | + $msg['msg'] = "操作成功"; | ||
178 | + } else { | ||
179 | + $msg['status'] = 0; | ||
180 | + $msg['msg'] = "操作失败"; | ||
181 | + } | ||
182 | + | ||
183 | + return $this->renderJson($msg); | ||
184 | + } | ||
185 | + | ||
186 | +} | ||
0 | \ No newline at end of file | 187 | \ No newline at end of file |
@@ -0,0 +1,60 @@ | @@ -0,0 +1,60 @@ | ||
1 | +<?php | ||
2 | + | ||
3 | +use yii\helpers\Url; | ||
4 | + | ||
5 | +$this->title = '创建项目'; | ||
6 | +$this->params['breadcrumbs'][] = ['label' => '项目管理', 'url' => ['/project/project/index']]; | ||
7 | +$this->params['breadcrumbs'][] = $this->title; | ||
8 | + | ||
9 | +?> | ||
10 | + | ||
11 | +<form action="<?php echo Url::toRoute(['/project/project/do-add']); ?>" name="myFrom" id="myFrom" method="post" enctype="multipart/form-data"> | ||
12 | + <div class="panel panel-default"> | ||
13 | + <div class="panel-body"> | ||
14 | + <div class="form-group col-sm-12" style="text-align: center"> | ||
15 | + <h3>创建项目</h3> | ||
16 | + </div> | ||
17 | + <div class="form-group col-sm-12"> | ||
18 | + <label for="skillName" class="col-sm-4 control-label text-right">项目名称:</label> | ||
19 | + <div class="col-sm-4 text-left"> | ||
20 | + <input type="text" value="" name="name" placeholder="请输入项目名称" style="margin-top: -6px;" class="form-control""> | ||
21 | + </div> | ||
22 | + </div> | ||
23 | + </div> | ||
24 | + | ||
25 | + <div class="panel-footer text-center"> | ||
26 | + <button type="button" class="btn btn-primary ladda-button" data-style="slide-up" id="save">确 定</button> | ||
27 | + <a class="btn btn-default" href="<?=Url::toRoute("/project/project/create")?>">重 置</a> | ||
28 | + </div> | ||
29 | + </div> | ||
30 | + | ||
31 | +</form> | ||
32 | + | ||
33 | +<script> | ||
34 | + // 表单提交验证 | ||
35 | + seajs.use("base/1.0.0/unit/validate/custom-1.0.0",function () { | ||
36 | + var validator = $("#myFrom").validate({ | ||
37 | + //debug:true, | ||
38 | + rules: { | ||
39 | + } | ||
40 | + }); | ||
41 | + }); | ||
42 | + | ||
43 | + $("#save").bind("click", function () { | ||
44 | + var getUrl = '<?=Url::toRoute("/project/project/do-add")?>'; | ||
45 | + $('#myFrom').attr('action', getUrl); | ||
46 | + var a = $("input[name='name']").val(); | ||
47 | + if (a == ""){ | ||
48 | + alert("项目名称不能为空"); | ||
49 | + return false; | ||
50 | + } | ||
51 | + var cb = $("#myFrom").validate().form(); | ||
52 | + if (!cb){ | ||
53 | + return; | ||
54 | + } | ||
55 | + var submit = $('#myFrom').submit(); | ||
56 | + var l = $.ladda(this); | ||
57 | + l.start(); | ||
58 | + return false; | ||
59 | + }); | ||
60 | +</script> | ||
0 | \ No newline at end of file | 61 | \ No newline at end of file |
@@ -0,0 +1,64 @@ | @@ -0,0 +1,64 @@ | ||
1 | +<?php | ||
2 | + | ||
3 | +use yii\helpers\Url; | ||
4 | + | ||
5 | +$this->title = '编辑项目'; | ||
6 | +$this->params['breadcrumbs'][] = ['label' => '项目管理', 'url' => ['/project/project/index']]; | ||
7 | +$this->params['breadcrumbs'][] = $this->title; | ||
8 | + | ||
9 | +?> | ||
10 | + | ||
11 | +<form action="<?php echo Url::toRoute(['/project/project/do-add']); ?>" name="myFrom" id="myFrom" method="post" enctype="multipart/form-data"> | ||
12 | + <div class="panel panel-default"> | ||
13 | + <div class="panel-body"> | ||
14 | + <div style="margin-bottom: 15px;text-align: right;"> | ||
15 | + <a href="<?=Url::toRoute("/project/project/create")?>" class="btn btn-success"> + 创建项目</a> | ||
16 | + </div> | ||
17 | + <div class="form-group col-sm-12" style="text-align: center"> | ||
18 | + <h3>编辑项目</h3> | ||
19 | + </div> | ||
20 | + <div class="form-group col-sm-12"> | ||
21 | + <label for="skillName" class="col-sm-4 control-label text-right">项目名称:</label> | ||
22 | + <div class="col-sm-4 text-left"> | ||
23 | + <input type="text" value="<?= isset($info["name"]) ? $info["name"] : "" ?>" style="margin-top: -6px;" name="name" placeholder="请填写项目名称" class="form-control"> | ||
24 | + </div> | ||
25 | + </div> | ||
26 | + </div> | ||
27 | + | ||
28 | + <div class="panel-footer text-center"> | ||
29 | + <input type="hidden" value="<?= isset($info["id"]) ? $info["id"] : "" ?>" name="mid" class="form-control""> | ||
30 | + <button type="button" class="btn btn-primary ladda-button" data-style="slide-up" id="save">确 定</button> | ||
31 | + <a class="btn btn-default" href="<?=Url::toRoute("/project/project/index")?>">返 回</a> | ||
32 | + </div> | ||
33 | + </div> | ||
34 | + | ||
35 | +</form> | ||
36 | + | ||
37 | +<script> | ||
38 | + // 表单提交验证 | ||
39 | + seajs.use("base/1.0.0/unit/validate/custom-1.0.0",function () { | ||
40 | + var validator = $("#myFrom").validate({ | ||
41 | + //debug:true, | ||
42 | + rules: { | ||
43 | + } | ||
44 | + }); | ||
45 | + }); | ||
46 | + | ||
47 | + $("#save").bind("click", function () { | ||
48 | + var getUrl = '<?=Url::toRoute("/project/project/do-edit")?>'; | ||
49 | + $('#myFrom').attr('action', getUrl); | ||
50 | + var a = $("input[name='name']").val(); | ||
51 | + if (a == ""){ | ||
52 | + alert("项目名称不能为空"); | ||
53 | + return false; | ||
54 | + } | ||
55 | + var cb = $("#myFrom").validate().form(); | ||
56 | + if (!cb){ | ||
57 | + return; | ||
58 | + } | ||
59 | + var submit = $('#myFrom').submit(); | ||
60 | + var l = $.ladda(this); | ||
61 | + l.start(); | ||
62 | + return false; | ||
63 | + }); | ||
64 | +</script> | ||
0 | \ No newline at end of file | 65 | \ No newline at end of file |
@@ -0,0 +1,121 @@ | @@ -0,0 +1,121 @@ | ||
1 | +<?php | ||
2 | +use yii\helpers\Url; | ||
3 | +use app\ht\widgets\LinkPager; | ||
4 | +use common\helpers\ImageManager; | ||
5 | +use domain\shop\ShopItemStatus; | ||
6 | + | ||
7 | +$this->title = '项目管理'; | ||
8 | +$this->params['breadcrumbs'][] = $this->title; | ||
9 | +?> | ||
10 | + | ||
11 | +<div class="panel panel-default"> | ||
12 | + <div class="panel-body"> | ||
13 | + <form action="" method="get" id="search-form" class="filter-form"> | ||
14 | + <table width="100%" class="table"> | ||
15 | + <tbody> | ||
16 | + <tr > | ||
17 | + <td width="10%" class="text-right">项目名称</td> | ||
18 | + <td width="35%" class="text-left"> | ||
19 | + <div class="form-inline"> | ||
20 | + <input type="text" class="form-control" style="width: 150px;" name="name" placeholder="输入项目名称" value="<?php if (!empty($gets['name'])){ echo $gets['name']; } ?>"> | ||
21 | + </div> | ||
22 | + </td> | ||
23 | + <td width="10%" class="text-right">创建时间</td> | ||
24 | + <td width="35%" class="text-left"> | ||
25 | + <div class="form-inline"> | ||
26 | + <input type="date" class="form-control" style="width: 150px;" name="creatTime" placeholder="起" value="<?php if (!empty($gets['creatTime'])){ echo $gets['creatTime']; } ?>"> - | ||
27 | + <input type="date" class="form-control" style="width: 150px;" name="endTime" placeholder="止" value="<?php if (!empty($gets['endTime'])){ echo $gets['endTime']; } ?>"> | ||
28 | + </div> | ||
29 | + </td> | ||
30 | + </tr> | ||
31 | + <tr class="search"> | ||
32 | + <td colspan="4" class="text-center"> | ||
33 | + <button type="submit" class="btn btn-primary btncls" id="search"><i class="glyphicon glyphicon-search"></i> 查 询 </button> | ||
34 | + <a class="btn btn-default btncls" href="<?=Url::toRoute(["/project/project/index"])?>">重 置</a> | ||
35 | + </td> | ||
36 | + </tr> | ||
37 | + </tbody> | ||
38 | + </table> | ||
39 | + </form> | ||
40 | + </div> | ||
41 | +</div> | ||
42 | + | ||
43 | +<div class="panel panel-default"> | ||
44 | + <div class="panel-body"> | ||
45 | + <div style="margin-bottom: 15px;text-align: right;"> | ||
46 | + <a href="<?=Url::toRoute("/project/project/create")?>" class="btn btn-success"> + 创建项目</a> | ||
47 | + </div> | ||
48 | + <table class="table table-striped table-bordered" id="brand-table"> | ||
49 | + <thead> | ||
50 | + <tr> | ||
51 | + <th width="15%">编号</th> | ||
52 | + <th width="25%">项目名称</th> | ||
53 | + <th width="25%">创建时间</th> | ||
54 | + <th width="20%">操作</th> | ||
55 | + </tr> | ||
56 | + </thead> | ||
57 | + | ||
58 | + <tbody> | ||
59 | + <?php if ($listdata) { ?> | ||
60 | + <?php foreach ($listdata as $item) : ?> | ||
61 | + <tr> | ||
62 | + <td style="padding:12px;"><?= (isset($item["project_no"]) ? $item["project_no"] : "") ?></td> | ||
63 | + <td style="padding:12px;"><?= (isset($item["name"]) ? $item["name"] : "") ?> | ||
64 | + <td style="padding:12px;"><?= date("Y-m-d H:i:s", $item['created_at'])?></td> | ||
65 | + <td style="padding:12px;"> | ||
66 | + <button class="btn btn-danger btn-sm btn_del" aid="<?=$item['id'] ?>">删除</button> | | ||
67 | + <a class="btn btn-info btn-sm btn_auth_success" href="<?=Url::toRoute(["/project/project/edit", "mid" => $item['id']])?>" aid="<?=$item['id'] ?>">编辑</a> | ||
68 | + </td> | ||
69 | + </tr> | ||
70 | + <?php endforeach; ?> | ||
71 | + <?php } else { ?> | ||
72 | + <tr> | ||
73 | + <td colspan="8"> | ||
74 | + <center>暂无记录</center> | ||
75 | + </td> | ||
76 | + </tr> | ||
77 | + <?php } ?> | ||
78 | + </tbody> | ||
79 | + </table> | ||
80 | + </div> | ||
81 | + | ||
82 | + <div class="panel-footer"> | ||
83 | + <div class="hqy-panel-pager"> | ||
84 | + <?= LinkPager::widget([ | ||
85 | + 'pagination' => $pages, | ||
86 | + ]); ?> | ||
87 | + <div class="clearfix"></div> | ||
88 | + </div> | ||
89 | + </div> | ||
90 | +</div> | ||
91 | +<script> | ||
92 | + $(document).ready(function () { | ||
93 | + $(".btn_del").bind("click",function () { | ||
94 | + if (confirm("确定要删除该项目吗?")){ | ||
95 | + var data_id = $.trim($(this).attr("aid")); | ||
96 | + if (data_id == null || data_id == ""){ | ||
97 | + alert("丢失参数,暂时无法删除,请刷新后再试"); | ||
98 | + return false; | ||
99 | + } | ||
100 | + var thiz = $(this); | ||
101 | + $.ajax({ | ||
102 | + type: "post", | ||
103 | + url: "do-del", | ||
104 | + dataType:"json", | ||
105 | + data: $.csrf({"data_id":data_id}), | ||
106 | + success:function(msg){ | ||
107 | + alert(msg['msg']); | ||
108 | + if (msg['status'] == 1){ | ||
109 | + thiz.parents("tr").remove(); | ||
110 | + }else{ | ||
111 | + //提示确认失败 | ||
112 | + } | ||
113 | + }, | ||
114 | + error:function(msg){ | ||
115 | + //提示确认失败 | ||
116 | + } | ||
117 | + }); | ||
118 | + } | ||
119 | + }) ; | ||
120 | + }); | ||
121 | +</script> | ||
0 | \ No newline at end of file | 122 | \ No newline at end of file |
app-ht/views/layouts/routes.php
@@ -40,14 +40,14 @@ return [ | @@ -40,14 +40,14 @@ return [ | ||
40 | ] | 40 | ] |
41 | ], | 41 | ], |
42 | [ | 42 | [ |
43 | - 'path' => '/projects', | 43 | + 'path' => '/project', |
44 | 'label' => '项目', | 44 | 'label' => '项目', |
45 | 'routes' => [ | 45 | 'routes' => [ |
46 | [ | 46 | [ |
47 | - 'path' => '/projects', | ||
48 | - 'redirect' => '/projects/projects/index' | 47 | + 'path' => '/project', |
48 | + 'redirect' => '/project/project/index' | ||
49 | ], | 49 | ], |
50 | - ['label' => '项目管理', 'path'=> '/projects/projects/index'], | 50 | + ['label' => '项目管理', 'path'=> '/project/project/index'], |
51 | ] | 51 | ] |
52 | ], | 52 | ], |
53 | [ | 53 | [ |
domain/model/Model.php
domain/model/ModelRepository.php
@@ -21,9 +21,9 @@ class ModelRepository | @@ -21,9 +21,9 @@ class ModelRepository | ||
21 | */ | 21 | */ |
22 | static function getPageList($where, $offset, $limit) | 22 | static function getPageList($where, $offset, $limit) |
23 | { | 23 | { |
24 | - $modelFind = ModelModel::find()->alias("p") | 24 | + $modelFind = ModelModel::find()->alias("m") |
25 | ->select([ | 25 | ->select([ |
26 | - "p.*" | 26 | + "m.*" |
27 | ]); | 27 | ]); |
28 | 28 | ||
29 | if (!empty($where)) { | 29 | if (!empty($where)) { |
@@ -36,7 +36,7 @@ class ModelRepository | @@ -36,7 +36,7 @@ class ModelRepository | ||
36 | $modelFind->limit($limit); | 36 | $modelFind->limit($limit); |
37 | } | 37 | } |
38 | 38 | ||
39 | - $modelFind->orderBy("p.id desc"); | 39 | + $modelFind->orderBy("m.id desc"); |
40 | $modelFind->asArray(); | 40 | $modelFind->asArray(); |
41 | $dataList = $modelFind->all(); | 41 | $dataList = $modelFind->all(); |
42 | 42 | ||
@@ -49,7 +49,7 @@ class ModelRepository | @@ -49,7 +49,7 @@ class ModelRepository | ||
49 | */ | 49 | */ |
50 | static function getPageCount($map = '') | 50 | static function getPageCount($map = '') |
51 | { | 51 | { |
52 | - $modelFind = ModelModel::find()->alias("p"); | 52 | + $modelFind = ModelModel::find()->alias("m"); |
53 | if (!empty($map)) { | 53 | if (!empty($map)) { |
54 | $modelFind->where($map); | 54 | $modelFind->where($map); |
55 | } | 55 | } |
@@ -0,0 +1,99 @@ | @@ -0,0 +1,99 @@ | ||
1 | +<?php | ||
2 | + | ||
3 | +namespace domain\project; | ||
4 | + | ||
5 | +use Yii; | ||
6 | +use domain\project\models\Project as ProjectModel; | ||
7 | +use Exception; | ||
8 | + | ||
9 | +/** | ||
10 | + * 项目 | ||
11 | + * Class Project | ||
12 | + * @package domain\project | ||
13 | + */ | ||
14 | +class Project | ||
15 | +{ | ||
16 | + /** | ||
17 | + * 创建项目 | ||
18 | + * @param $item | ||
19 | + */ | ||
20 | + static function create($item) | ||
21 | + { | ||
22 | + try { | ||
23 | + $findProjectModel = ProjectModel::findOne(['name' => $item["name"]]); | ||
24 | + if (!empty($findProjectModel)) { | ||
25 | + return -1; | ||
26 | + } | ||
27 | + $projectModel = Yii::createObject(ProjectModel::className()); | ||
28 | + $projectModel->project_no = self::getProjectNo(); | ||
29 | + $projectModel->name = $item["name"]; // 项目 | ||
30 | + $saveResult = $projectModel->save(); | ||
31 | + return $saveResult; | ||
32 | + } catch (Exception $e) { | ||
33 | + return false; | ||
34 | + } | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * 更新项目 | ||
39 | + * @param $id | ||
40 | + * @param $item | ||
41 | + * @return null|static | ||
42 | + */ | ||
43 | + static function update($id, $item) | ||
44 | + { | ||
45 | + $projectModel = ProjectModel::findOne($id); | ||
46 | + if (empty($projectModel)) { | ||
47 | + return false; | ||
48 | + } | ||
49 | + if (isset($item['name']) && $projectModel->name != $item['name']) { | ||
50 | + $findProjectModel = ProjectModel::findOne(['name' => $item["name"]]); | ||
51 | + if (!empty($findProjectModel)) { | ||
52 | + return -1; | ||
53 | + } | ||
54 | + } | ||
55 | + if (isset($item['name']) && !empty($item['name'])) { | ||
56 | + $projectModel->name = $item['name']; | ||
57 | + } | ||
58 | + | ||
59 | + $resultSave = $projectModel->save(); | ||
60 | + return $resultSave; | ||
61 | + } | ||
62 | + | ||
63 | + /** | ||
64 | + * 删除项目 | ||
65 | + * @param $id | ||
66 | + * @param $item | ||
67 | + * @return null|static | ||
68 | + */ | ||
69 | + public static function delete($id) | ||
70 | + { | ||
71 | + $projectModel = ProjectModel::findOne($id); | ||
72 | + if (empty($projectModel)) { | ||
73 | + return false; | ||
74 | + } | ||
75 | + | ||
76 | + return ProjectModel::deleteAll(["id" => $id]); | ||
77 | + } | ||
78 | + | ||
79 | + /** | ||
80 | + * 获取十六进制项目编号 | ||
81 | + */ | ||
82 | + private static function getProjectNo() | ||
83 | + { | ||
84 | + $findModel = ProjectModel::find()->orderBy("id desc")->asArray()->one(); | ||
85 | + if (empty($findModel)) { | ||
86 | + return "0001"; | ||
87 | + } | ||
88 | + $dataNo = hexdec($findModel['project_no']) + 1; | ||
89 | + $dataNo = (string) dechex($dataNo); | ||
90 | + if (strlen($dataNo) == 1) { | ||
91 | + $dataNo = "000" . $dataNo; | ||
92 | + } else if (strlen($dataNo) == 2) { | ||
93 | + $dataNo = "00" . $dataNo; | ||
94 | + } else if (strlen($dataNo) == 3) { | ||
95 | + $dataNo = "0" . $dataNo; | ||
96 | + } | ||
97 | + return $dataNo; | ||
98 | + } | ||
99 | +} | ||
0 | \ No newline at end of file | 100 | \ No newline at end of file |
@@ -0,0 +1,85 @@ | @@ -0,0 +1,85 @@ | ||
1 | +<?php | ||
2 | + | ||
3 | +namespace domain\project; | ||
4 | + | ||
5 | +use domain\project\models\Project as ProjectModel; | ||
6 | + | ||
7 | + | ||
8 | +/** | ||
9 | + | ||
10 | + * Class ProjectRepository | ||
11 | + * @package domain\model | ||
12 | + */ | ||
13 | +class ProjectRepository | ||
14 | +{ | ||
15 | + /** | ||
16 | + * 获取分页数据 | ||
17 | + * @param $where | ||
18 | + * @param $offset | ||
19 | + * @param $limit | ||
20 | + * @return array|\yii\db\ActiveRecord[] | ||
21 | + */ | ||
22 | + static function getPageList($where, $offset, $limit) | ||
23 | + { | ||
24 | + $modelFind = ProjectModel::find()->alias("p") | ||
25 | + ->select([ | ||
26 | + "p.*" | ||
27 | + ]); | ||
28 | + | ||
29 | + if (!empty($where)) { | ||
30 | + $modelFind->where($where); | ||
31 | + } | ||
32 | + if ($offset) { | ||
33 | + $modelFind->offset($offset); | ||
34 | + } | ||
35 | + if ($limit) { | ||
36 | + $modelFind->limit($limit); | ||
37 | + } | ||
38 | + | ||
39 | + $modelFind->orderBy("p.id desc"); | ||
40 | + $modelFind->asArray(); | ||
41 | + $dataList = $modelFind->all(); | ||
42 | + | ||
43 | + return $dataList; | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * 列表页面分页器数量 | ||
48 | + * @param string $map | ||
49 | + */ | ||
50 | + static function getPageCount($map = '') | ||
51 | + { | ||
52 | + $modelFind = ProjectModel::find()->alias("p"); | ||
53 | + if (!empty($map)) { | ||
54 | + $modelFind->where($map); | ||
55 | + } | ||
56 | + $pageCount = $modelFind->count(); | ||
57 | + | ||
58 | + return $pageCount; | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * @param $id | ||
63 | + * @param bool|false $asArr | ||
64 | + * @return null|static | ||
65 | + */ | ||
66 | + static function selectOne($id, $asArr = false) | ||
67 | + { | ||
68 | + $model = ProjectModel::findOne($id); | ||
69 | + if ($asArr && $model) { | ||
70 | + $model = $model->toArray(); | ||
71 | + } | ||
72 | + return $model; | ||
73 | + } | ||
74 | + | ||
75 | + /** | ||
76 | + * @param $id | ||
77 | + * @param bool|false $asArr | ||
78 | + * @return null|static | ||
79 | + */ | ||
80 | + static function findOne($condition) | ||
81 | + { | ||
82 | + $model = ProjectModel::findOne($condition); | ||
83 | + return $model; | ||
84 | + } | ||
85 | +} | ||
0 | \ No newline at end of file | 86 | \ No newline at end of file |
@@ -0,0 +1,36 @@ | @@ -0,0 +1,36 @@ | ||
1 | +<?php | ||
2 | + | ||
3 | +namespace domain\project\models; | ||
4 | + | ||
5 | +use yii\db\ActiveRecord; | ||
6 | +use yii\behaviors\TimestampBehavior; | ||
7 | + | ||
8 | +/** | ||
9 | + * 项目 | ||
10 | + * Class Project | ||
11 | + * @package domain\project\models | ||
12 | + */ | ||
13 | +class Project extends ActiveRecord | ||
14 | +{ | ||
15 | + /** | ||
16 | + * @inheritdoc | ||
17 | + */ | ||
18 | + public static function tableName() | ||
19 | + { | ||
20 | + return '{{%project}}'; | ||
21 | + } | ||
22 | + | ||
23 | + /** | ||
24 | + * @return array | ||
25 | + */ | ||
26 | + public function behaviors() | ||
27 | + { | ||
28 | + return [ | ||
29 | + 'time' => [ | ||
30 | + 'class' => TimestampBehavior::className(), | ||
31 | + 'createdAtAttribute' => 'created_at', | ||
32 | + 'updatedAtAttribute' => 'updated_at', | ||
33 | + ] | ||
34 | + ]; | ||
35 | + } | ||
36 | +} | ||
0 | \ No newline at end of file | 37 | \ No newline at end of file |