From 7f8c7e6170e2fe29d70493064d82c1846823d1b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B7=B4=E6=8E=8C?= Date: Fri, 28 Dec 2018 15:40:57 +0800 Subject: [PATCH] 0 --- application/rongyu/controller/DwRongyu.php | 84 ++++- application/rongyu/model/DwRongyu.php | 45 +++ application/rongyu/view/dw_rongyu/create.html | 8 +- application/rongyu/view/dw_rongyu/edit.html | 292 +++++++++++------- application/rongyu/view/dw_rongyu/index.html | 20 +- .../migrations/20181218041034_dw_rongyu.php | 4 +- 6 files changed, 314 insertions(+), 139 deletions(-) diff --git a/application/rongyu/controller/DwRongyu.php b/application/rongyu/controller/DwRongyu.php index 654f2cf0..e01923e7 100644 --- a/application/rongyu/controller/DwRongyu.php +++ b/application/rongyu/controller/DwRongyu.php @@ -74,6 +74,8 @@ class DwRongyu extends Base // 获取当前页数据 $data = $data->slice($limit_start,$limit_length); + $data = $data->append(['hjSchool.jiancheng','fzSchool.jiancheng','lxCategory.title','jxCategory.title','jibie']); + // 重组返回内容 $data = [ @@ -119,6 +121,13 @@ class DwRongyu extends Base // 验证表单数据 $result = $validate->check($list); $msg = $validate->getError(); + // 如果验证不通过则停止保存 + if(!$result){ + return json(['msg'=>$msg,'val'=>0]);; + } + + // 保存数据 + $data = dwry::create($list); // 根据更新结果设置返回提示信息 $data ? $data=['msg'=>'添加成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; @@ -162,7 +171,7 @@ class DwRongyu extends Base // 获取表单上传文件 例如上传了001.jpg $file = request()->file('file'); // 移动到框架应用根目录/uploads/ 目录下 - $info = $file->move( '..\public\uploads\student'); + $info = $file->move( '..\public\uploads\danweirongyu'); if($info){ @@ -170,7 +179,7 @@ class DwRongyu extends Base $list['category'] = $info->getExtension(); $list['url'] = $info->getSaveName(); $list['newname'] = $info->getFilename(); - $list['url'] = '..\public\uploads\student\\'.$list['url']; + $list['url'] = '..\public\uploads\danweirongyu\\'.$list['url']; $list['bianjitime'] = filemtime($list['url']); //将文件信息保存 @@ -206,7 +215,15 @@ class DwRongyu extends Base */ public function edit($id) { - // + // 获取学生信息 + $list = dwry::where('id',$id) + ->field('id,title,category,hjschool,fzshijian,fzschool,jiangxiang,url') + ->find(); + + + $this->assign('list',$list); + + return $this->fetch(); } /** @@ -216,9 +233,32 @@ class DwRongyu extends Base * @param int $id * @return \think\Response */ - public function update(Request $request, $id) + public function update($id) { - // + // 获取表单数据 + $list = request()->only(['title','category','hjschool','fzshijian','fzschool','jiangxiang'],'put'); + + // 实例化验证类 + $validate = new \app\rongyu\validate\DwRongyu; + // 验证表单数据 + $result = $validate->check($list); + $msg = $validate->getError(); + + // 如果验证不通过则停止保存 + if(!$result){ + return json(['msg'=>$msg,'val'=>0]);; + } + + + // 更新数据 + $dwry = new dwry(); + $data = $dwry->save($list,['id'=>$id]); + + // 根据更新结果设置返回提示信息 + $data>=0 ? $data=['msg'=>'更新成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); } /** @@ -229,6 +269,38 @@ class DwRongyu extends Base */ public function delete($id) { - // + + if($id == 'm') + { + $id = request()->delete('ids/a');// 获取delete请求方式传送过来的数据并转换成数据 + } + + $data = dwry::destroy($id); + + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'删除成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); + } + + + + // 设置荣誉状态 + public function setStatus() + { + + // 获取id变量 + $id = request()->post('id'); + $value = request()->post('value'); + + // 获取学生信息 + $data = dwry::where('id',$id)->update(['status'=>$value]); + + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'状态设置成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); } } diff --git a/application/rongyu/model/DwRongyu.php b/application/rongyu/model/DwRongyu.php index 6e8028b2..38601626 100644 --- a/application/rongyu/model/DwRongyu.php +++ b/application/rongyu/model/DwRongyu.php @@ -34,6 +34,51 @@ class DwRongyu extends Base }) ->select(); + return $data; } + + + // 获奖单位获取器 + public function hjSchool() + { + return $this->belongsTo('\app\system\model\School','hjschool','id'); + } + + // 颁奖单位获取器 + public function fzSchool() + { + return $this->belongsTo('\app\system\model\School','fzschool','id'); + } + + // 荣誉类型 + public function lxCategory() + { + return $this->belongsTo('\app\system\model\Category','category','id'); + } + + // 奖项 + public function jxCategory() + { + return $this->belongsTo('\app\system\model\Category','category','id'); + } + + // 荣誉级别 + public function getJibieAttr() + { + return $this->fzSchool->jibie; + } + + + // 发证时间修改器 + public function setFzshijianAttr($value) + { + return strtotime($value); + } + + // 发证时间获取器 + public function getFzshijianAttr($value) + { + return date('Y-m-d',$value); + } } diff --git a/application/rongyu/view/dw_rongyu/create.html b/application/rongyu/view/dw_rongyu/create.html index 69ec0d3c..58ba1059 100644 --- a/application/rongyu/view/dw_rongyu/create.html +++ b/application/rongyu/view/dw_rongyu/create.html @@ -32,10 +32,10 @@
- {php}$list = getCategory(112);{/php} + {php}$category = getCategory(112);{/php} @@ -80,10 +80,10 @@
- {php}$list = getCategory(113);{/php} + {php}$jiangxiang = getCategory(113);{/php} diff --git a/application/rongyu/view/dw_rongyu/edit.html b/application/rongyu/view/dw_rongyu/edit.html index 43870ee6..ac152aa2 100644 --- a/application/rongyu/view/dw_rongyu/edit.html +++ b/application/rongyu/view/dw_rongyu/edit.html @@ -1,87 +1,75 @@ {extend name="common@create" /} +{block name="mycss"} +{css href="/static/H-ui.admin_v3.1.3.1/H-ui.admin/lib/webuploader/0.1.5/webuploader.css" /} +{/block} {block name="formaa"} -
+
+ +
+
- +
- +
- -
- -
-
-
- -
-
- - -
-
- - -
-
- - -
-
-
-
- -
- -
-
-
- +
- - {php} - $school = schlist('校级','校级'); - {/php} - + + {volist name="category" id="vo"} + {/volist}
- +
- - {php} - $njlist = nianjiList(); - $banji = new \app\teach\model\Banji; - $bj = $banji::get($list['banji']); - {/php} - + + {volist name="school" id="vo"} + + {/volist}
- {php} - $bjlist = $banji::where('ruxuenian',$bj->ruxuenian)->select(); - $bjlist = $bjlist->append(['title'])->visible(['id','title']); - {/php}
- + +
+ +
+
+
+ +
+ + {php} $school = schlist('区级','其它级');{/php} + + +
+
+
+
- + + {volist name="jiangxiang" id="vo"} + {/volist} @@ -95,8 +83,129 @@ {/block} {block name="yanzheng"} +{js href="/static/H-ui.admin_v3.1.3.1/H-ui.admin/lib/webuploader/0.1.5/webuploader.js"} {/block} \ No newline at end of file diff --git a/application/rongyu/view/dw_rongyu/index.html b/application/rongyu/view/dw_rongyu/index.html index 7a249568..16b6fd10 100644 --- a/application/rongyu/view/dw_rongyu/index.html +++ b/application/rongyu/view/dw_rongyu/index.html @@ -71,16 +71,14 @@
- {php} - $school = schlist('区级','部级'); - {/php} + {php}$category = getCategory(112);{/php}
- {foreach $school as $key=>$vo } + {foreach $category as $key=>$vo } {/foreach}
@@ -156,10 +154,10 @@ var mycolumns = [ { "data": "id" }, { "data": "title" }, - { "data": "hjschool" }, - { "data": "category"}, - { "data": "jiangxiang"}, - { "data": "fzschool" }, + { "data": "hjSchool.jiancheng","name":"hjschool" }, + { "data": "lxCategory.title","name":"category"}, + { "data": "jxCategory.title","name":"jiangxiang"}, + { "data": "fzSchool.jiancheng" ,"name":"fzschool"}, { "data": "jibie","name":"fzschool"}, { "data": "fzshijian" }, { "data": "status" }, @@ -184,8 +182,8 @@ // 启用按钮 startbut = ''; // 编辑按钮 - editbut = ''; - delbut = ''; + editbut = ''; + delbut = ''; if(row.status == '已停用') { buts = startbut + editbut + delbut; diff --git a/database/migrations/20181218041034_dw_rongyu.php b/database/migrations/20181218041034_dw_rongyu.php index 57bba64d..8ff2f3b1 100644 --- a/database/migrations/20181218041034_dw_rongyu.php +++ b/database/migrations/20181218041034_dw_rongyu.php @@ -37,9 +37,9 @@ class DwRongyu extends Migrator ->addColumn('hjschool','integer',['limit'=>11,'null'=>false,'comment'=>'获奖单位']) ->addColumn('fzschool','integer',['limit'=>11,'null'=>false,'comment'=>'发证单位']) ->addColumn('fzshijian','integer',['limit'=>11,'null'=>false,'comment'=>'发证时间']) - ->addColumn('category','string',['limit'=>100,'null'=>false,'comment'=>'荣誉图片']) + ->addColumn('url','string',['limit'=>100,'null'=>false,'comment'=>'荣誉图片']) ->addColumn('jiangxiang','integer',['limit'=>11,'null'=>false,'comment'=>'奖项']) - ->addColumn('pic','integer',['limit'=>15,'null'=>false,'comment'=>'荣誉类型']) + ->addColumn('category','integer',['limit'=>15,'null'=>false,'comment'=>'荣誉类型']) ->addColumn('create_time','integer',['limit'=>11,'null'=>true,'comment'=>'创建时间']) ->addColumn('delete_time','integer',['limit'=>11,'null'=>true,'comment'=>'删除时间']) ->addColumn('update_time','integer',['limit'=>11,'null'=>true,'comment'=>'更新时间'])