Skip to content

Commit dfa14e2

Browse files
committed
完成添加Bug
1 parent 3aff186 commit dfa14e2

File tree

7 files changed

+261
-4
lines changed

7 files changed

+261
-4
lines changed

application/index/controller/Bug.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
namespace app\index\controller;
1010

1111
use app\index\service\Bug as BugService;
12+
use app\index\model\ProjectModule as ProjectModuleModel;
13+
use app\index\model\ProjectVersion as ProjectVersionModel;
14+
use app\index\model\ProjectUser as ProjectUserModel;
1215

1316
class Bug extends Auth
1417
{
@@ -20,4 +23,23 @@ public function index()
2023

2124
return view('bug/index');
2225
}
26+
27+
public function add()
28+
{
29+
if($this->request->isGet())
30+
{
31+
$this->assign('module',ProjectModuleModel::all(['project_id'=>$this->request->param('id')]));
32+
$this->assign('version',ProjectVersionModel::all(['project_id'=>$this->request->param('id')]));
33+
34+
$this->assign('project_user',ProjectUserModel::all(['project_id'=>$this->request->param('id')]));
35+
36+
$this->assign('id',$this->request->param('id'));
37+
38+
39+
return view('bug/add');
40+
}else{
41+
42+
return BugService::create($this->request->param('id'),$this->user_id,$this->request->post());
43+
}
44+
}
2345
}

application/index/model/ProjectUser.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111

1212
class ProjectUser extends BaseModel
1313
{
14-
14+
public function user()
15+
{
16+
return $this->hasOne('User','id','user_id');
17+
}
1518
}

application/index/service/Bug.php

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
namespace app\index\service;
1010

1111
use app\index\model\Bug as BugModel;
12+
use app\index\model\BugLog as BugLogModel;
13+
use app\index\validate\Bug as BugValidate;
1214

1315
class Bug
1416
{
1517

16-
public static function getBugWithPriority($user_id,$priority_status,$page)
18+
public static function getBugWithPriority($user_id,$priority_status)
1719
{
1820

1921
}
@@ -56,4 +58,64 @@ public static function getAllProjectBugWithStatus($project_id)
5658
return $data;
5759
}
5860

61+
/**
62+
* 创建Bug
63+
* @param $project_id
64+
* @param $user_id
65+
* @param $data
66+
*
67+
* @return ServiceResult
68+
*/
69+
public static function create($project_id,$user_id,$data)
70+
{
71+
$model = new BugModel();
72+
$model->startTrans();
73+
74+
try{
75+
76+
$validate = new BugValidate();
77+
78+
if(!$validate->scene('add')->check([
79+
'bug_title'=>$data['bug_title'],
80+
'bug_content'=>$data['bug_content'],
81+
]))
82+
{
83+
return ServiceResult::Error($validate->getError());
84+
}
85+
86+
$add = $model->save([
87+
'bug_title'=>$data['bug_title'],
88+
'bug_content'=>$data['bug_content'],
89+
'create_user_id'=>$user_id,
90+
'project_id'=>$project_id,
91+
'current_user_id'=>$data['current_user_id'],
92+
'bug_status'=>$data['bug_status'],
93+
'priority_status'=>$data['priority_status'],
94+
'version_id'=>$data['version_id'],
95+
'module_id'=>$data['module_id'],
96+
]);
97+
98+
99+
100+
$model->commit();
101+
102+
}catch (\Exception $e)
103+
{
104+
$model->rollback();
105+
106+
return ServiceResult::Error($e->getMessage());
107+
}
108+
109+
if($add)
110+
{
111+
112+
return ServiceResult::Success(['id'=>$model->id],'创建成功');
113+
114+
}else{
115+
116+
return ServiceResult::Error($model->getError());
117+
118+
}
119+
}
120+
59121
}

application/index/validate/Bug.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: zhangcheng
5+
* Date: 2017/12/28
6+
* Time: 下午2:24
7+
*/
8+
9+
namespace app\index\validate;
10+
11+
12+
class Bug extends BaseValidate
13+
{
14+
protected $rule = [
15+
'bug_title' => 'require|max:255|min:1',
16+
'bug_content' => 'require',
17+
18+
];
19+
20+
protected $message = [
21+
'bug_title.require'=>'Bug标题不为空',
22+
'bug_title.max' => 'Bug标题不能超过255位',
23+
'bug_title.min' => 'Bug标题不为空',
24+
'bug_content.require'=>'Bug描述不为空',
25+
26+
];
27+
28+
29+
protected $scene = [
30+
'add' => ['bug_title'],
31+
'edit' => ['bug_title'],
32+
];
33+
}

application/index/view/bug/add.html

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
{extend name="extend/main" /}
2+
{block name="content"}
3+
<div class="container-fluid">
4+
<div class="col-md-12">
5+
<div class="card">
6+
<form id="TypeValidation" class="form-horizontal" action="" method="">
7+
<div class="card-header card-header-text" data-background-color="rose">
8+
<h4 class="card-title">{:lang('New Bug')}</h4>
9+
</div>
10+
<div class="card-content">
11+
<div class="row">
12+
<label class="col-sm-2 label-on-left">Bug标题</label>
13+
<div class="col-sm-7">
14+
<div class="form-group label-floating">
15+
<label class="control-label"></label>
16+
<input class="form-control" type="text" name="bug_title" required="true" />
17+
</div>
18+
</div>
19+
20+
</div>
21+
<div class="row">
22+
<label class="col-sm-2 label-on-left">版本</label>
23+
<div class="col-sm-7">
24+
<div class="form-group label-floating col-md-6">
25+
<label class="control-label"></label>
26+
<select class="selectpicker" data-style="btn btn-primary btn-round" data-size="<?php echo count($version);?>" id="version_select" name="version_id">
27+
{volist name="version" id="item"}
28+
<option value="{$item.id}">{$item.version_name}</option>
29+
{/volist}
30+
</select>
31+
</div>
32+
</div>
33+
34+
</div>
35+
<div class="row">
36+
<label class="col-sm-2 label-on-left">模块</label>
37+
<div class="col-sm-7">
38+
<div class="form-group label-floating col-md-6">
39+
<label class="control-label"></label>
40+
<select class="selectpicker" data-style="btn btn-warning btn-round" data-size="<?php echo count($module);?>" id="module_select" name="module_id">
41+
{volist name="module" id="item"}
42+
<option value="{$item.id}">{$item.module_name}</option>
43+
{/volist}
44+
</select>
45+
46+
</div>
47+
</div>
48+
49+
</div>
50+
<div class="row">
51+
<label class="col-sm-2 label-on-left">优先级</label>
52+
<div class="col-sm-7">
53+
<div class="form-group label-floating col-md-6">
54+
<label class="control-label"></label>
55+
<select class="selectpicker" data-style="btn btn-info btn-round" data-size="3" id="level_select" name="priority_status">
56+
<option value="0"></option>
57+
<option value="1"></option>
58+
<option value="2"></option>
59+
</select>
60+
61+
</div>
62+
</div>
63+
64+
</div>
65+
<div class="row">
66+
<label class="col-sm-2 label-on-left">处理人</label>
67+
<div class="col-sm-7">
68+
<div class="form-group label-floating col-md-6">
69+
<label class="control-label"></label>
70+
71+
<select name="current_user_id" class="selectpicker" data-style="btn btn-danger btn-round" data-size="{:count($project_user)}">
72+
73+
{volist name="project_user" id="item"}
74+
<option value="{$item.user_id}">{$item->user->username}</option>
75+
{/volist}
76+
</select>
77+
</div>
78+
</div>
79+
80+
</div>
81+
82+
<div class="row">
83+
<label class="col-sm-2 label-on-left">描述</label>
84+
<div class="col-sm-7">
85+
<div class="form-group label-floating">
86+
<label class="control-label"></label>
87+
<textarea name="bug_content" class="form-control " cols="100" rows="10" id="bug_content"></textarea>
88+
89+
</div>
90+
</div>
91+
92+
</div>
93+
</div>
94+
<div class="card-footer text-center">
95+
<input type="button" class="btn btn-rose btn-fill" value="{:lang('Submit')}" id="add_bug_btn">
96+
</div>
97+
</form>
98+
</div>
99+
</div>
100+
</div>
101+
{/block}
102+
{block name="footer"}
103+
<script>
104+
$(function () {
105+
$('#add_bug_btn').click(function(){
106+
axios.post('/index/bug/add', {
107+
bug_title:$('input[name=bug_title]').val(),
108+
bug_content:$('#bug_content').val(),
109+
id:'{$_GET["id"]}',
110+
current_user_id:$('select[name=current_user_id]').val(),
111+
bug_status:0,
112+
priority_status:$('select[name=priority_status]').val(),
113+
version_id:$('select[name=version_id]').val(),
114+
module_id:$('select[name=module_id]').val()
115+
}).then(function (response) {
116+
swal({
117+
title: "提示!",
118+
text: response.data.message,
119+
timer: 2000,
120+
showConfirmButton: false
121+
}).catch(swal.noop)
122+
123+
if(response.data.status == 1)
124+
{
125+
setTimeout(function(){
126+
location.href = '/project/main?id={$_GET["id"]}';
127+
},2100);
128+
}
129+
})
130+
.catch(function (error) {
131+
console.log(error);
132+
});
133+
});
134+
});
135+
</script>
136+
{/block}

application/index/view/project/main.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
</div>
1111
<div class="card-content">
1212
<h4 class="card-title">项目信息
13-
<button class="pull-right btn btn-round btn-primary">
14-
<i class="material-icons">add</i>提交Bug</button>
13+
<a class="pull-right btn btn-round btn-primary" href="/index/bug/add?id={$_GET['id']}">
14+
<i class="material-icons">add</i>提交Bug</a>
1515
</h4>
1616

1717

application/lang/zh-cn.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@
3636
'AllocateToMyBug'=>'分配给我的Bug',
3737
'Created Bug'=>'我创建的Bug',
3838
'All Bug'=>'所有Bug',
39+
'New Bug'=>'新建Bug',
3940
];

0 commit comments

Comments
 (0)