作者 曹东东

查重

@@ -3,7 +3,9 @@ @@ -3,7 +3,9 @@
3 namespace app\school\controller\project_approval; 3 namespace app\school\controller\project_approval;
4 4
5 use app\common\controller\DoubleBase; 5 use app\common\controller\DoubleBase;
  6 +use app\school\model\project_common\ProjectRegister;
6 use think\Db; 7 use think\Db;
  8 +use think\Exception;
7 9
8 class Duplicate extends DoubleBase 10 class Duplicate extends DoubleBase
9 { 11 {
@@ -16,12 +18,163 @@ class Duplicate extends DoubleBase @@ -16,12 +18,163 @@ class Duplicate extends DoubleBase
16 { 18 {
17 parent::_initialize(); 19 parent::_initialize();
18 $this->containerId = $_COOKIE['container_id']; 20 $this->containerId = $_COOKIE['container_id'];
  21 + $this->model = new ProjectRegister();
19 } 22 }
20 23
21 public function index() 24 public function index()
22 { 25 {
  26 + //设置过滤方法
  27 + $this->request->filter(['strip_tags']);
  28 + if ($this->request->isAjax()) {
  29 + list($where, $sort, $order, $offset, $limit) = $this->buildparams();
23 30
  31 + // 默认查询项目容器下未淘汰(|未退回)的项目
  32 + $field = [
  33 + 'a.*',
  34 + 't.name as project_type_name',
  35 + 'u.nickname',
  36 + 'u.student_no',
  37 + 'c.college_name as college_name',
  38 + 'd.specialty_name as major_name',
  39 +// 'SUM(r.result) as sum',
  40 + 'count(member_id) as memberCount'
  41 + ];
  42 + $total = $this->model
  43 + ->field('a.id')
  44 + ->alias('a')
  45 + ->join('user u', 'a.user_id = u.id', 'left')
  46 + ->join('project_type t', 'a.project_type = t.id', 'left')
  47 + ->join('college c', 'u.college = c.id', 'left')
  48 + ->join('specialty d', 'u.specialty = d.id', 'left')
  49 + ->where(['a.container_id' => $this->containerId,'review_stage' => 0])
  50 + ->where('a.repeat_rate','neq',0)
  51 + ->count();
  52 + $list = $this->model
  53 + ->field($field)
  54 + ->alias('a')
  55 + ->join('user u', 'a.user_id = u.id', 'left')
  56 + ->join('project_type t', 'a.project_type = t.id', 'left')
  57 + ->join('college c', 'u.college = c.id', 'left')
  58 + ->join('fa_members m','a.id = m.item_id and member_type = 1 and member_source = 2','left')
  59 + ->join('specialty d', 'u.specialty = d.id', 'left')
  60 + ->where(['a.container_id' => $this->containerId,'review_stage' => 0])
  61 + ->where('a.repeat_rate','neq',0)
  62 + ->group('a.id')
  63 + ->limit($offset, $limit)
  64 + ->select();
  65 + foreach ($list as &$row) {
  66 + $row['project_teachers'] = json_decode($row['project_teachers'], true);
  67 + $row['repeat_rate'] = $row['repeat_rate'].'%';
  68 + if($row['project_status'] != 0) {
  69 + switch ($row['project_status'])
  70 + {
  71 + case 1:
  72 + $row['status'] = '已淘汰';
  73 + break;
  74 + case 2:
  75 + $row['status'] = '已驳回';
  76 + break;
  77 + default:
  78 + $row['status'] = '已延期';
  79 + }
  80 + }else {
  81 + switch ($row['project_approval_status'])
  82 + {
  83 + case 0:
  84 + $row['status'] = '教师未审核';
  85 + break;
  86 + case 1:
  87 + $row['status'] = '学院未审核';
  88 + break;
  89 + case 2:
  90 + $row['status'] = '学校未审核';
  91 + break;
  92 + default:
  93 + $row['status'] = '学校已审核';
  94 + }
  95 + }
  96 +
  97 +
  98 + }
  99 + $result = [
  100 + 'total' => $total,
  101 + 'rows' => $list
  102 + ];
  103 + return $result;
  104 + }
24 return $this->view->fetch(); 105 return $this->view->fetch();
25 } 106 }
26 107
  108 +
  109 + /**
  110 + * 查重审核
  111 + */
  112 + public function editProject()
  113 + {
  114 + if ($this->request->isAjax()) {
  115 + $list = $this->request->param('list');
  116 + $list = json_decode($list, true);
  117 + $user= session("school");
  118 +
  119 + $arr = [];
  120 + foreach ($list as $val) {
  121 + $tmp['id'] = $val['id'];
  122 + $tmp['project_status'] = $val['project_status'];
  123 + $arr[] = $tmp;
  124 + }
  125 + Db::startTrans();
  126 + try {
  127 + //保存审核日志
  128 + $this->register_log($list);
  129 + $this->model->allowField(true)->saveAll($arr);
  130 + Db::commit();
  131 + } catch (Exception $e) {
  132 + Db::rollback();
  133 + $this->error($e->getMessage());
  134 + }
  135 + $this->success();
  136 + }
  137 + }
  138 +
  139 + // 保存审核日志
  140 + private function register_log($list){
  141 + # 获取用户ID
  142 + $admin_id = $this->auth->id;
  143 + #
  144 + if(!empty($list)) {
  145 + $insertData = [];
  146 + foreach ($list as $val) {
  147 + if(isset($val['memo']) && mb_strlen($val['memo'],"UTF-8") > 200) {
  148 + $this->error("审核原因在200字以内");
  149 + }
  150 + $item = ProjectRegister::get($val['id']);
  151 + $data['register_id'] = $item['id'];
  152 + $data['container_id'] = $item['container_id'];
  153 + $data['project_college'] = $item['project_college'];
  154 + $data['project_name'] = $item['project_name'];
  155 + $data['verify_stage'] = $val['verify_stage'];
  156 + $data['memo'] = isset($val['memo']) ? $val['memo'] : '';
  157 + $data['school_id'] = $this->auth->school_id;
  158 + $data['teacher_id'] = $admin_id;
  159 + $data['teacher_name'] = $this->auth->nickname;
  160 + if($item['review_stage'] == 0) {
  161 + switch ($item['project_approval_status'])
  162 + {
  163 + case 1:
  164 + $data['type'] = 'collage';
  165 + break;
  166 + default:
  167 + $data['type'] = 'school';
  168 + }
  169 + }
  170 + $data['operation'] = '驳回';
  171 + $data['created_time'] = date('Y-m-d H:i:s',time());
  172 + $insertData[] = $data;
  173 + }
  174 + if(!empty($insertData)) {
  175 + db('register_log')->insertAll($insertData);
  176 + }
  177 + }
  178 + }
  179 +
27 } 180 }
1 -<h1>查重,待开发...</h1>  
  1 +<div class="panel panel-default panel-intro">
  2 + {:build_heading()}
  3 + <div class="panel-body">
  4 + <div id="myTabContent" class="tab-content">
  5 + <div class="tab-pane fade active in" id="one">
  6 + <div class="widget-body no-padding">
  7 + <div id="toolbar" class="toolbar">
  8 + <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
  9 + <a href="javascript:;" class="btn btn-danger btn-disabled disabled btn-multiBack">批量驳回</a>
  10 + </div>
  11 + <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
  12 + width="100%">
  13 + </table>
  14 + </div>
  15 + </div>
  16 +
  17 + </div>
  18 + </div>
  19 +</div>
  20 +
  21 +<div id="memo" hidden style="text-align: center;padding-top: 10px;">
  22 + <textarea id="mome_text" name="mome_text" placeholder="请输入审核意见...,不超过200字" style="resize:none;" rows="10" cols="100"></textarea>
  23 +</div>
1 define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefined, Backend, Form, Table) { 1 define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefined, Backend, Form, Table) {
2 var Controller = { 2 var Controller = {
3 index: function () { 3 index: function () {
4 - 4 + Table.api.init({
  5 + extend: {
  6 + index_url: 'project_approval/duplicate/index',
  7 + }
  8 + });
  9 + var table = $("#table");
  10 + // 初始化表格
  11 + table.bootstrapTable({
  12 + url: $.fn.bootstrapTable.defaults.extend.index_url,
  13 + pk: 'id',
  14 + // 是否显示快速搜索(搜索框)
  15 + search: false,
  16 + // 是否显示切换视图按钮
  17 + showToggle: false,
  18 + // 是否显示隐藏列按钮
  19 + showColumns: false,
  20 + // 是否显示导出按钮
  21 + showExport: false,
  22 + // 是否开启通用搜索功能(表格右上角的放大镜)
  23 + commonSearch: true,
  24 + columns: [
  25 + [
  26 + {checkbox: true},
  27 + { field: 'id', title: '序号', operate: false },
  28 + // { field: 'id', title: '完整度', operate: false },
  29 + {
  30 + field: 'project_info', title: '项目名称及编号', operate: false, align: 'left', formatter: function (val, row) {
  31 + return row.project_name + '<br/>' + (row.project_no ? row.project_no : '编号:未设置')
  32 + }
  33 + },
  34 + { field: 'memberCount', title: '团队人数', operate: false },
  35 + { field: 'project_type_name', title: '项目分类', operate: false },
  36 + { field: 'college_name', title: '项目所属学院', operate: false },
  37 + {
  38 + field: 'user_info', title: '负责人姓名/学号', align: 'left', operate: false, formatter: function (val, row) {
  39 + return row.nickname + '<br/>' + (row.student_no || '-')
  40 + }
  41 + },
  42 + {
  43 + field: 'user_from', title: '负责人学院/专业', align: 'left', operate: false, formatter: function (val, row) {
  44 + return row.college_name + '<br>' + (row.major_name || '-')
  45 + }
5 }, 46 },
  47 + { field: 'project_teachers', title: '指导教师', formatter: function (val) {
  48 + var teachersName = '';
  49 + for (var p in val) {
  50 + teachersName += (val[p].username + '<br>')
  51 + }
  52 + return teachersName;
  53 + }
  54 + },
  55 + { field: 'status', title: '审核状态', operate: false },
  56 + {
  57 + field: 'repeat_rate', title: '重复率', operate: false, formatter: function (val, row) {
  58 + return "<a style='display: block;background-color:red;color: #ffffff;border-radius: 8%;'>" +row.repeat_rate+"</a>";
  59 + }
  60 + },
  61 + {
  62 + field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
  63 + buttons: [
  64 + {
  65 + name: '_btn1',
  66 + text: '查看项目',
  67 + title: '查看项目',
  68 + classname: 'btn btn-xs btn-info btn-addtabs',
  69 + url: function (val) {
  70 + return '/school/project_common/project_view/index?review_stage=0&ids=' + val.id
  71 + }
  72 + },
  73 + {
  74 + name: '_btn2',
  75 + text: '查看审核信息',
  76 + title: '查看审核信息',
  77 + classname: 'btn btn-xs btn-info btn-addtabs',
  78 + url: function (val) {
  79 + return '/school/project_common/judge/verify_list?review_stage=0&register_id=' + val.id
  80 + }
  81 + }
  82 + ]
  83 + }
  84 + ]
  85 + ]
  86 + });
  87 + // 批量驳回
  88 + $(document).on('click', '.btn-multiBack', function () {
  89 + $("#mome_text").val('');
  90 + layer.open({
  91 + type: 1,
  92 + title:['审核意见', 'background-color:#2C3E50;color:#fff;'],
  93 + skin: 'demo-class', //样式类名
  94 + closeBtn: 0, //不显示关闭按钮
  95 + anim: 2,
  96 + shadeClose: true, //开启遮罩关闭
  97 + area:["70%","70%"],
  98 + content: $("#memo"),
  99 + btn: ['确定驳回', '取消'],
  100 + yes:function(val,row){
  101 + var memo = $("#mome_text").val();
  102 + // var table = $( ('#table' + ($('.nav-tabs .active a').data('limit'))) )
  103 + var ids = Table.api.selectedids(table);
  104 + if ('array' !== typeof ids) {
  105 + ids = (''+ids).split(',');
  106 + }
  107 + if (!ids.length) {
  108 + throw new Error('id不能为空');
  109 + }
  110 + var data = {list:JSON.stringify(ids.map(function (id) {return { id: id, project_status: 2, check_stage: 0, review_stage: 0,memo:memo,verify_stage:0}}))};
  111 + $.ajax({
  112 + url: '/school/project_approval/duplicate/editProject',
  113 + method: 'POST',
  114 + data: data,
  115 + success: function (res) {
  116 + if (1 === res.code) {
  117 + Toastr.success('操作成功')
  118 + layer.close(val);
  119 + table.bootstrapTable("refresh");
  120 + } else {
  121 + Toastr.error(res.msg);
  122 + }
  123 + }
  124 + });
  125 + },
  126 + });
  127 + })
  128 + // 为表格绑定事件
  129 + Table.api.bindevent(table);
  130 + },
  131 +
6 api: { 132 api: {
7 bindevent: function () { 133 bindevent: function () {
8 Form.api.bindevent($("form[role=form]")); 134 Form.api.bindevent($("form[role=form]"));
9 }, 135 },
10 } 136 }
11 } 137 }
12 -  
13 return Controller 138 return Controller
14 }) 139 })