Exams.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  1. <?php
  2. namespace app\admin\controller\teacher;
  3. use PhpOffice\PhpWord\PhpWord;
  4. use app\admin\model\department\Department;
  5. use app\common\controller\Backend;
  6. use think\Db;
  7. use think\exception\PDOException;
  8. use think\exception\ValidateException;
  9. use app\admin\model\teacher\ExamsScore;
  10. use app\admin\model\Fault;
  11. use app\admin\model\Report;
  12. use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
  13. use PhpOffice\PhpSpreadsheet\IOFactory;
  14. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  15. use PhpOffice\PhpSpreadsheet\Reader\Csv;
  16. use PhpOffice\PhpSpreadsheet\Reader\Xls;
  17. use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
  18. /**
  19. * sim-考试表/成绩总分
  20. *
  21. * @icon fa fa-circle-o
  22. */
  23. class Exams extends Backend
  24. {
  25. /**
  26. * Exams模型对象
  27. * @var \app\admin\model\teacher\Exams
  28. */
  29. protected $model = null;
  30. protected $whereExtend = null;
  31. protected $noNeedRight = ['export','examslog','report'];
  32. public function _initialize()
  33. {
  34. parent::_initialize();
  35. $this->model = new \app\admin\model\teacher\Exams;
  36. $this->whereExtend['exam_collection_type'] = 3;
  37. $this->whereExtend['starttime'] = ['>',0];
  38. $this->whereExtend['endtime'] = ['>',0];
  39. $this->relationtTable = 'collection';
  40. }
  41. /**
  42. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  43. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  44. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  45. */
  46. public function index()
  47. {
  48. //查询最后一场考试id
  49. $exam_collection_id = $this->model->where($this->whereExtend)->order('exam_id desc')->value('exam_collection_id');
  50. $collection_name = $this->model->where(['exam_collection_id'=>$exam_collection_id])->value('exam_collection_name');
  51. //设置过滤方法
  52. $this->request->filter(['strip_tags', 'trim']);
  53. if (false === $this->request->isAjax()) {
  54. $this->assignConfig('collection_name', $collection_name);
  55. return $this->view->fetch();
  56. }
  57. //如果发送的来源是 Selectpage,则转发到 Selectpage
  58. if ($this->request->request('keyField')) {
  59. return $this->selectpage();
  60. }
  61. //查询考试
  62. $filter = $this->request->get("filter", '');
  63. $filter = (array)json_decode($filter, true);
  64. $op = $this->request->get("op", '');
  65. $op = (array)json_decode($op, true);
  66. if(isset($filter) &&!empty($filter['exam_collection_name'])){
  67. unset($this->whereExtend['exam_collection_id']);
  68. $this->request->get(['filter'=>json_encode($filter),'op'=>json_encode($op)]);
  69. }else{
  70. $this->whereExtend['exam_collection_id'] = $exam_collection_id;
  71. }
  72. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  73. $list = $this->model
  74. ->where($where)->where($this->whereExtend)
  75. ->order($sort, $order)
  76. ->paginate($limit);
  77. //最高分 最低分 平均分
  78. $select = $this->model->where($where)->where($this->whereExtend)->field('count(*) as count,sum(total_score) as totalscore,min(total_score) as min,max(total_score) as max')->select();
  79. $pingfen = '';
  80. if(!empty($select[0]['totalscore']) && !empty($select[0]['count'])){
  81. $pingfen = bcdiv($select[0]['totalscore'],$select[0]['count']);
  82. }
  83. $defen = ['max'=>$select[0]['max'],'min'=>$select[0]['min'],'pingfen'=>$pingfen];
  84. $one_static = [];
  85. $two_static = [];
  86. $three_static = [];
  87. $where_falut = ['fault_type' => 3,'fault_state'=>0];
  88. $exam_ids = $this->model->where($where)->where($this->whereExtend)->column('exam_id');
  89. foreach ($list as $k => $val){
  90. $one = Fault::where(['sim_type'=>'0001'])->where($where_falut)->field('fault_id,name')->select();
  91. if($val['sim_type']=='0001'){
  92. foreach ($one as $k1 => $val1){
  93. //先查分配次数,在查错误率
  94. $one_total = Db::name('real_exam_fault')->where(['flag'=>1,'exam_id'=>['in',$exam_ids],'fault_id'=>$val1['fault_id']])->count();
  95. $error_total = Db::name('real_exam_fault')->where(['flag'=>1,'exam_id'=>['in',$exam_ids],'fault_id'=>$val1['fault_id'],'answer_right'=>2])->count();
  96. $one[$k1]['epercent'] = '';
  97. if($one_total>0){
  98. $bili = bcmul(bcdiv($error_total,$one_total,2),100);
  99. $one[$k1]['epercent'] = $bili>0 ? $bili.'%' : '';
  100. }
  101. }
  102. $vaccineCount = array_column($one, 'epercent');
  103. array_multisort($vaccineCount,SORT_DESC,$one);
  104. $one_static = $one;
  105. }
  106. $two = Fault::where(['sim_type'=>'0002'])->where($where_falut)->field('fault_id,name')->select();
  107. if($val['sim_type']=='0002'){
  108. foreach ($two as $k2 => $val2){
  109. $two_total = Db::name('real_exam_fault')->where(['flag'=>1,'exam_id'=>['in',$exam_ids],'fault_id'=>$val2['fault_id']])->count();
  110. $error_total = Db::name('real_exam_fault')->where(['flag'=>1,'exam_id'=>['in',$exam_ids],'fault_id'=>$val2['fault_id'],'answer_right'=>2])->count();
  111. $two[$k2]['epercent'] = '';
  112. if($two_total>0){
  113. $bili = bcmul(bcdiv($error_total,$two_total,2),100);
  114. $two[$k2]['epercent'] = $bili>0 ? $bili.'%' : '';
  115. }
  116. }
  117. $vaccineCount1 = array_column($two, 'epercent');
  118. array_multisort($vaccineCount1,SORT_DESC,$two);
  119. }
  120. $two_static = $two;
  121. $three = Fault::where(['sim_type'=>'0003'])->where($where_falut)->field('fault_id,name')->select();
  122. if($val['sim_type']=='0003'){
  123. foreach ($three as $k3 => $val3){
  124. $three_total = Db::name('real_exam_fault')->where(['flag'=>1,'exam_id'=>['in',$exam_ids],'fault_id'=>$val3['fault_id']])->count();
  125. $error_total = Db::name('real_exam_fault')->where(['flag'=>1,'exam_id'=>['in',$exam_ids],'fault_id'=>$val3['fault_id'],'answer_right'=>2])->count();
  126. $three[$k3]['epercent'] = '';
  127. if($three_total>0){
  128. $bili = bcmul(bcdiv($error_total,$three_total,2),100);
  129. $three[$k3]['epercent'] = $bili>0 ? $bili.'%' : '';
  130. }
  131. }
  132. $vaccineCount2 = array_column($three, 'epercent');
  133. array_multisort($vaccineCount2,SORT_DESC,$three);
  134. }
  135. $three_static = $three;
  136. }
  137. //统计错误率
  138. $statistics = [
  139. 'one_static' => $one_static,
  140. 'two_static' => $two_static,
  141. 'three_static' => $three_static,
  142. ];
  143. $result = ['total' => $list->total(), 'rows' => $list->items(),'defen'=>$defen,'tongji'=>$statistics];
  144. return json($result);
  145. }
  146. public function edit($ids = null)
  147. {
  148. $row = Db::name('real_exam_score')->where('exam_id', $ids)->find();
  149. if (!$row) {
  150. $this->error(__('No Results were found'));
  151. }
  152. $rows = $this->model->get($ids);
  153. $row['seat_id'] = $rows->seat_id;
  154. $row['user_nickname'] = $rows->user_nickname;
  155. $row['user_username'] = $rows->user_username;
  156. $row['is_sure'] = $rows->is_sure;
  157. $fault_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  158. $row['fault_name_one'] = Fault::where('fault_id',$fault_list[0]['fault_id'])->value('name');
  159. $row['fault_name_two'] = Fault::where('fault_id',$fault_list[1]['fault_id'])->value('name');
  160. $row['fault_name_three'] = Fault::where('fault_id',$fault_list[2]['fault_id'])->value('name');
  161. $other_jielun = !empty($row['other_jielun']) ? json_decode($row['other_jielun'],true):[];
  162. $diffInSeconds = $rows['endtime'] - $rows['starttime']; // 两个时间戳之间的差异(秒)
  163. $minutes = floor($diffInSeconds / 60); // 计算分钟数
  164. $seconds = $diffInSeconds % 60; // 计算剩余的秒数
  165. $row['shijian'] = $minutes.'分'.$seconds.'秒';
  166. $koufen = 0;
  167. if(!empty($other_jielun)){
  168. foreach ($other_jielun as $key => $value) {
  169. if(!empty($value['cx_score'])){
  170. $koufen = $koufen+abs($value['cx_score']);
  171. }
  172. }
  173. }else{
  174. $koufen = 15;
  175. }
  176. if (false === $this->request->isPost()) {
  177. $this->assignConfig('koufen', $koufen);
  178. $this->view->assign('other_jielun', $other_jielun);
  179. $this->view->assign('row', $row);
  180. return $this->view->fetch();
  181. }
  182. $params = $this->request->post('row/a');
  183. if (empty($params)) {
  184. $this->error(__('Parameter %s can not be empty', ''));
  185. }
  186. $params = $this->preExcludeFields($params);
  187. $result = false;
  188. Db::startTrans();
  189. try {
  190. //是否采用模型验证
  191. $koufen = 0;
  192. if(!empty($other_jielun)){
  193. foreach ($other_jielun as $key => $value) {
  194. if(!empty($value['cx_score'])){
  195. $koufen = $koufen+abs($value['cx_score']);
  196. }
  197. }
  198. }else{
  199. $koufen = 15; //超时未自动交卷的
  200. }
  201. $params['total'] = 100-$params['fault_one_score']-$params['fault_two_score']-$params['fault_three_score']-$params['overtime_score']-$koufen;
  202. $result = Db::name('real_exam_score')->where('id', $row['id'])->update($params);
  203. $rows->total_score = $params['total'];
  204. $rows->is_sure = 1;
  205. $rows->save();
  206. Db::commit();
  207. } catch (ValidateException|PDOException|Exception $e) {
  208. Db::rollback();
  209. $this->error($e->getMessage());
  210. }
  211. if (false === $result) {
  212. $this->error(__('No rows were updated'));
  213. }
  214. $this->success();
  215. }
  216. public function view($type = null,$ids = null)
  217. {
  218. $row = Db::name('real_exam_score')->where('exam_id', $ids)->find();
  219. if (!$row) {
  220. $this->error(__('No Results were found'));
  221. }
  222. $rows = $this->model->get($ids);
  223. $row['fault_total'] = $rows->fault_total;
  224. $row['seat_id'] = $rows->seat_id;
  225. $row['user_nickname'] = $rows->user_nickname;
  226. $row['user_username'] = $rows->user_username;
  227. $row['user_depart_id'] = $rows->user_depart_id;
  228. $row['user_depart_name'] = Department::where('id',$rows->user_depart_id)->value('name');
  229. $row['start_time'] = $rows->start_time;
  230. $row['end_time'] = $rows->end_time;
  231. $row['exam_collection_type'] = $rows->exam_collection_type;
  232. $fault_list = Db::name('real_exam_fault')->where(['exam_id'=>$ids,'flag'=>1])->select();
  233. $row['fault_name_one'] = Fault::where('fault_id',$fault_list[0]['fault_id'])->value('name');
  234. if($rows['fault_total']>0){
  235. if($rows['fault_total']==2){
  236. $row['fault_name_two'] = Fault::where('fault_id',$fault_list[1]['fault_id'])->value('name');
  237. }
  238. if($rows['fault_total']==3){
  239. $row['fault_name_two'] = Fault::where('fault_id',$fault_list[1]['fault_id'])->value('name');
  240. $row['fault_name_three'] = Fault::where('fault_id',$fault_list[2]['fault_id'])->value('name');
  241. }
  242. }else{
  243. $row['fault_name_two'] = Fault::where('fault_id',$fault_list[1]['fault_id'])->value('name');
  244. $row['fault_name_three'] = Fault::where('fault_id',$fault_list[2]['fault_id'])->value('name');
  245. }
  246. $row['fault_score'] = 75-$row['fault_one_score']-$row['fault_two_score']-$row['fault_three_score'];
  247. $row['weixiu_score'] = 10-$row['overtime_score']??0;
  248. $other_jielun = !empty($row['other_jielun']) ? json_decode($row['other_jielun'],true):[];
  249. $koufen = 0;
  250. $dt_count = 0;
  251. if(!empty($other_jielun)){
  252. foreach ($other_jielun as $key => $value) {
  253. if(!empty($value['cx_score'])){
  254. $koufen = $koufen+abs($value['cx_score']);
  255. }
  256. if($value['cx_type']=='未作答'){
  257. $dt_count = $dt_count+1;
  258. }
  259. }
  260. }else{
  261. $koufen = 15;
  262. }
  263. //训练,未作答。展示使用
  264. $is_nowancheng = 0;
  265. if($row['exam_collection_type']== 1 && $row['fault_total'] == $dt_count){
  266. $is_nowancheng = 1;
  267. }
  268. $report_score = 15-$koufen;
  269. $row['report_score'] = $report_score>0?$report_score:0;
  270. $total = $row['fault_score']+$row['report_score']+$row['weixiu_score'];
  271. Db::name('real_exam_score')->where('exam_id', $ids)->update(['total'=>$total]);
  272. Db::name('real_exam')->where('exam_id', $ids)->update(['total_score'=>$total]);
  273. $row['total'] = $total;
  274. $this->view->assign('other_jielun', $other_jielun);
  275. $this->view->assign('dt_count', $dt_count);
  276. $this->view->assign('is_nowancheng', $is_nowancheng);
  277. $diffInSeconds = $rows['endtime'] - $rows['starttime']; // 两个时间戳之间的差异(秒)
  278. $minutes = floor($diffInSeconds / 60); // 计算分钟数
  279. $seconds = $diffInSeconds % 60; // 计算剩余的秒数
  280. $row['shijian'] = $minutes.'分'.$seconds.'秒';
  281. $this->view->assign('row', $row);
  282. if(!empty($type)){
  283. return $this->view->fetch('view1');
  284. }else{
  285. return $this->view->fetch();
  286. }
  287. }
  288. //正在考试
  289. public function persent($ids = null)
  290. {
  291. //设置过滤方法
  292. $this->request->filter(['strip_tags', 'trim']);
  293. if (false === $this->request->isAjax()) {
  294. $this->assignConfig('ids', $ids);
  295. return $this->view->fetch();
  296. }
  297. //如果发送的来源是 Selectpage,则转发到 Selectpage
  298. if ($this->request->request('keyField')) {
  299. return $this->selectpage();
  300. }
  301. $exam_ids = $this->model->where('exam_collection_id',$ids)->column('exam_id');
  302. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  303. $list = Db::name('real_exam_comp_request')
  304. // ->where('exam_collection_type',3)
  305. ->where($where)->where('exam_id','in',$exam_ids)
  306. ->order($sort, $order)
  307. ->paginate($limit);
  308. unset($v);
  309. $result = ['total' => $list->total(), 'rows' => $list->items()];
  310. return json($result);
  311. }
  312. //考试座次历史记录
  313. public function examslog($ids = null)
  314. {
  315. $row = $this->model->get($ids);
  316. if(!$row){
  317. $this->error(__('No Results were found'));
  318. }
  319. $list = $this->model->where(['seat_id'=>$row->seat_id,'exam_collection_id'=>$row->exam_collection_id])->order('starttime asc')->select();
  320. $this->view->assign('list', $list);
  321. return $this->view->fetch();
  322. }
  323. public function examing($ids = null)
  324. {
  325. //设置过滤方法
  326. $this->request->filter(['strip_tags', 'trim']);
  327. if (false === $this->request->isAjax()) {
  328. $this->assignConfig('ids', $ids);
  329. return $this->view->fetch();
  330. }
  331. //如果发送的来源是 Selectpage,则转发到 Selectpage
  332. if ($this->request->request('keyField')) {
  333. return $this->selectpage();
  334. }
  335. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  336. $list = Db::name('seat')->select();
  337. foreach ($list as $key => $value) {
  338. $exam = $this->model->where('exam_collection_id',$ids)->order('starttime desc')->where('seat_id',$value['seat_num'])->find();
  339. $user_username = '';
  340. $user_nickname = '';
  341. $exam_status = '未登录';
  342. $total_score = 0;
  343. $fault_names = '';
  344. $exam_id = 0;
  345. $simtype = '';
  346. $sim_state = '';
  347. if(!empty($exam)){
  348. if(!empty($value['current_sim_id'])){
  349. $sim = Db::name('sim')->where('sim_id',$value['current_sim_id'])->find();
  350. if(!empty($sim['sim_state'])){
  351. switch ($sim['sim_state']) {
  352. case '1':
  353. $sim_state = '在线';
  354. break;
  355. case '2':
  356. $sim_state = '离线';
  357. break;
  358. }
  359. }
  360. $simtype = $sim['sim_type'];
  361. }
  362. $user_username = $exam['user_username']??'';
  363. $user_nickname = $exam['user_nickname']??'';
  364. if($exam['exam_status']==1){
  365. $exam_status= '已登录未开始考试';
  366. }else if($exam['exam_status']==4){
  367. $exam_status= '已开始考试';
  368. }else if($exam['exam_status']==5){
  369. $exam_status= '已交卷';
  370. }
  371. $total_score = $exam['total_score']??'';
  372. $fault_names = $exam['fault_names']??'';
  373. $exam_id = $exam['exam_id']??0;
  374. $simtype = $simtype;
  375. }
  376. $list[$key]['user_username'] = $user_username;
  377. $list[$key]['user_nickname'] = $user_nickname;
  378. $list[$key]['exam_status'] = $exam_status;
  379. $list[$key]['total_score'] = $total_score;
  380. $list[$key]['fault_names'] = $fault_names;
  381. $list[$key]['exam_id'] = $exam_id;
  382. $list[$key]['sim_state'] = $sim_state;
  383. $list[$key]['sim_type'] = $simtype;
  384. }
  385. $result = ['total' => count($list), 'rows' => $list];
  386. return json($result);
  387. }
  388. public function score($ids = null)
  389. {
  390. //设置过滤方法
  391. $this->request->filter(['strip_tags', 'trim']);
  392. if (false === $this->request->isAjax()) {
  393. $this->assignConfig('ids', $ids);
  394. return $this->view->fetch();
  395. }
  396. //如果发送的来源是 Selectpage,则转发到 Selectpage
  397. if ($this->request->request('keyField')) {
  398. return $this->selectpage();
  399. }
  400. $exam_ids = $this->model->where('exam_collection_id',$ids)->column('exam_id');
  401. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  402. $list = ExamsScore::where($where)->alias('s')->join('mx_real_exam e','s.exam_id=e.exam_id')->where('s.exam_id','in',$exam_ids)
  403. ->order($sort, $order)
  404. ->paginate($limit);
  405. foreach ($list as $k => $v){
  406. $exam = $this->model->where(['exam_id'=>$v['exam_id']])->find();
  407. if($exam){
  408. $v->seat_id = $exam['seat_id'];
  409. $v->user_username = $exam['user_username'];
  410. $v->user_nickname = $exam['user_nickname'];
  411. $v->sim_type = $exam['sim_type'];
  412. }
  413. }
  414. unset($v);
  415. $result = ['total' => $list->total(), 'rows' => $list->items()];
  416. return json($result);
  417. }
  418. public function handle($type = null,$ids = null)
  419. {
  420. $row = Db::name('real_exam_comp_request')->where('rel_id',$ids)->find($ids);
  421. if(!$row){
  422. $this->error('未找到记录');
  423. }
  424. if($type ==1){
  425. $request_status = 2;
  426. }
  427. if($type==2)
  428. {
  429. $request_status= 3;
  430. }
  431. Db::name('real_exam_comp_request')->where('rel_id',$ids)->update(['request_status'=>$request_status]);
  432. //同步更新考试表json串
  433. $exam_info = $this->model->get($row['exam_id']);
  434. if(!empty($exam_info)){
  435. $other_replace = json_decode($exam_info['other_replace'],true)??[];
  436. foreach ($other_replace as $k=>$v){
  437. if($v['fault_id'] == $row['fault_id']){
  438. $other_replace[$k]['request_status'] = $request_status;
  439. }
  440. }
  441. $exam_info->other_replace = json_encode($other_replace);
  442. $exam_info->save();
  443. unset($v);
  444. }
  445. $this->success();
  446. }
  447. //啦
  448. public function editscore($ids = "")
  449. {
  450. $row = Db::name('real_exam_score')->where('exam_id', $ids)->find();
  451. if (!$row) {
  452. $this->error(__('No Results were found'));
  453. }
  454. $rows = $this->model->get($ids);
  455. $params = $this->request->post('row/a');
  456. if (empty($params)) {
  457. $this->error(__('Parameter %s can not be empty', ''));
  458. }
  459. $params = $this->preExcludeFields($params);
  460. $result = false;
  461. Db::startTrans();
  462. try {
  463. //是否采用模型验证
  464. $result = Db::name('real_exam_score')->where('id', $row['id'])->update($params);
  465. $info = Db::name('real_exam_score')->where('exam_id', $ids)->find();
  466. $total =100-$info['fault_one_score']-$info['fault_two_score']-$info['fault_three_score']-$info['xianxian_score']-$info['yuanyin_socre']-$info['buwei_score']-$info['fangfa_score']-$info['overtime_score']-$info['jielun_score'];;
  467. $rows->total_score = $total;
  468. $rows->is_sure = 1;
  469. $rows->save();
  470. $result = Db::name('real_exam_score')->where('id', $row['id'])->update(['total'=>$total]);
  471. Db::commit();
  472. } catch (ValidateException|PDOException|Exception $e) {
  473. Db::rollback();
  474. $this->error($e->getMessage());
  475. }
  476. if (false === $result) {
  477. $this->error(__('No rows were updated'));
  478. }
  479. $this->success();
  480. }
  481. public function export()
  482. {
  483. set_time_limit(0);
  484. ini_set('memory_limit', '2560M');
  485. //如果发送的来源是 Selectpage,则转发到 Selectpage
  486. if ($this->request->request('keyField')) {
  487. return $this->selectpage();
  488. }
  489. $exam_collection_id = $this->model->where($this->whereExtend)->order('exam_id desc')->value('exam_collection_id');
  490. $filter = $this->request->get("filter", '');
  491. $filter = (array)json_decode($filter, true);
  492. $op = $this->request->get("op", '');
  493. $op = (array)json_decode($op, true);
  494. if(isset($filter) &&!empty($filter['exam_collection_name'])){
  495. unset($this->whereExtend['exam_collection_id']);
  496. $this->request->get(['filter'=>json_encode($filter),'op'=>json_encode($op)]);
  497. }else{
  498. $this->whereExtend['exam_collection_id'] = $exam_collection_id;
  499. }
  500. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  501. $list = $this->model
  502. ->where($where)->where($this->whereExtend)
  503. // ->order($sort, $order)
  504. ->order('user_username asc')
  505. ->paginate($limit);
  506. $depart_ids = [];
  507. foreach ($list as $k => $v){
  508. if(!in_array($v['user_depart_id'],$depart_ids)){
  509. $depart_ids[] = $v['user_depart_id'];
  510. }
  511. }
  512. $xlsName = '学员成绩信息';
  513. $this->exportExcel($xlsName,'Excel2007', $list,$depart_ids);
  514. }
  515. /**
  516. * 输出到浏览器(需要设置header头)
  517. * @param string $fileName 文件名
  518. * @param string $fileType 文件类型
  519. */
  520. function exportExcel($fileName, $fileType,$data,$depart_ids)
  521. {
  522. //文件名称校验
  523. if (!$fileName) {
  524. trigger_error('文件名不能为空', E_USER_ERROR);
  525. }
  526. //Excel文件类型校验
  527. $type = ['Excel2007', 'Xlsx', 'Excel5', 'xls'];
  528. if (!in_array($fileType, $type)) {
  529. trigger_error('未知文件类型', E_USER_ERROR);
  530. }
  531. $ext = '';
  532. if ($fileType == 'Excel2007' || $fileType == 'Xlsx') {
  533. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  534. header('Content-Disposition: attachment;filename="' . $fileName . '.xlsx"');
  535. header('Cache-Control: max-age=0');
  536. $ext = 'Xlsx';
  537. } else { //Excel5
  538. header('Content-Type: application/vnd.ms-excel');
  539. header('Content-Disposition: attachment;filename="' . $fileName . '.xls"');
  540. header('Cache-Control: max-age=0');
  541. $ext = 'Xls';
  542. }
  543. $spreadsheet = new Spreadsheet();
  544. $worksheet = $spreadsheet->getActiveSheet();
  545. $worksheet->getColumnDimension('A')->setWidth(15);
  546. $worksheet->getColumnDimension('B')->setWidth(20);
  547. $worksheet->getColumnDimension('C')->setWidth(20);
  548. $worksheet->getColumnDimension('D')->setWidth(25);
  549. $worksheet->getColumnDimension('E')->setWidth(30);
  550. $worksheet->getRowDimension('1')->setRowHeight(40);
  551. //设置工作表标题名称
  552. $worksheet->setTitle('学员成绩信息');
  553. //1745459433
  554. $kaoshi = isset($data[0]['endtime']) ? date('Y-m-d',$data[0]['endtime']) : '';
  555. $a = '';
  556. foreach ($depart_ids as $k1=>$v1){
  557. $wu = Db::name('department')->where('id',$v1)->find();
  558. $si = Db::name('department')->where('id',$wu['parent_id'])->find();
  559. $san = Db::name('department')->where('id',$si['parent_id'])->find();
  560. $er = Db::name('department')->where('id',$san['parent_id'])->find();
  561. $yi = Db::name('department')->where('id',$er['parent_id'])->find();
  562. $a = $a.$yi['name']."/".$er['name']."/".$san['name']."/".$si['name']."/".$wu['name']."\n";
  563. }
  564. // $a = "预选军士\n预选军士一区队";
  565. $worksheet->setCellValue('A1',$a);
  566. $worksheet->mergeCells('A1:D1');
  567. $worksheet->setCellValue('E1',"考试日期 ".$kaoshi);
  568. $worksheet->setCellValue('A2',"序号");
  569. $worksheet->setCellValue('B2',"学员账号");
  570. $worksheet->setCellValue('C2',"学员姓名");
  571. $worksheet->setCellValue('D2',"模拟器类型");
  572. $worksheet->setCellValue('E2',"总分");
  573. foreach ($data as $ky => $value)
  574. {
  575. $lie = $ky+3;
  576. $sim_type= '';
  577. if($value['sim_type'] == '0001'){
  578. $sim_type = 'FZD04B型侦毒器';
  579. }else if($value['sim_type'] == '0002'){
  580. $sim_type = 'FZB006型毒剂报警器';
  581. }else if($value['sim_type'] == '0003'){
  582. $sim_type = '防化兵用毒剂报警器';
  583. }
  584. $worksheet->setCellValue('A'.$lie,++$ky);
  585. $worksheet->setCellValue('B'.$lie,$value['user_username']);
  586. $worksheet->setCellValue('C'.$lie,$value['user_nickname']);
  587. $worksheet->setCellValue('D'.$lie,$sim_type);
  588. $worksheet->setCellValue('E'.$lie,$value['total_score']);
  589. }
  590. $titlestyleArray = [
  591. 'font' => [
  592. 'name' => '黑体',
  593. 'size' => 14
  594. ],
  595. ];
  596. $titlestyleArray2 = [
  597. 'font' => [
  598. 'size' => 12
  599. ],
  600. ];
  601. $headerStyleArray = [
  602. 'font' => [
  603. 'name' => '方正小标宋简体',
  604. 'size' => 18
  605. ],
  606. ];
  607. $headStyleArray1 = [
  608. 'alignment' => [
  609. 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
  610. 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
  611. 'wrapText' => true,
  612. ],
  613. ];
  614. $commonStyleArray = [
  615. 'alignment' => [
  616. 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
  617. 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
  618. 'wrapText' => true,
  619. ]
  620. ];
  621. $borderStyleArray = [
  622. 'borders' => [
  623. 'allBorders' => [
  624. // 'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
  625. ],
  626. ],
  627. 'font' => [
  628. 'name' => '黑体',
  629. ],
  630. 'alignment' => [
  631. 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
  632. 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
  633. 'wrapText' => true,
  634. ]
  635. ];
  636. $worksheet->getStyle('A1:E1')->applyFromArray($headStyleArray1);//换行
  637. $worksheet->getStyle('A1:E1')->applyFromArray($titlestyleArray);
  638. $worksheet->getStyle('A2:E2')->applyFromArray($titlestyleArray2);
  639. $worksheet->getStyle('A2:E2')->applyFromArray($commonStyleArray);
  640. // foreach ($data as $k=>$v){
  641. // $kk = $k+3;
  642. // $worksheet->getStyle('A'.$kk.':E'.$kk)->applyFromArray($borderStyleArray);
  643. // }
  644. // $worksheet->getStyle('A3:R3')->applyFromArray($commonStyleArray);
  645. // $worksheet->getStyle('A'.$footer_total.':R'.$footer_total)->applyFromArray($commonStyleArray);
  646. // $worksheet->getStyle('A1:C1')->applyFromArray($borderStyleArray);
  647. // $worksheet->mergeCells('A1:R1');
  648. $writer = IOFactory::createWriter($spreadsheet,$ext);
  649. $writer->save('php://output');
  650. die();
  651. }
  652. /**
  653. *
  654. * @return void
  655. */
  656. public function report()
  657. {
  658. //如果发送的来源是 Selectpage,则转发到 Selectpage
  659. if ($this->request->request('keyField')) {
  660. return $this->selectpage();
  661. }
  662. $exam_collection_id = $this->model->where($this->whereExtend)->order('exam_id desc')->value('exam_collection_id');
  663. $filter = $this->request->get("filter", '');
  664. $filter = (array)json_decode($filter, true);
  665. $op = $this->request->get("op", '');
  666. $op = (array)json_decode($op, true);
  667. $doc_name = '';
  668. if(isset($filter) &&!empty($filter['exam_collection_name'])){
  669. $doc_name = $filter['exam_collection_name'];
  670. unset($this->whereExtend['exam_collection_id']);
  671. $this->request->get(['filter'=>json_encode($filter),'op'=>json_encode($op)]);
  672. }else{
  673. $doc_name = $this->model->where('exam_collection_id',$exam_collection_id)->value('exam_collection_name');
  674. $this->whereExtend['exam_collection_id'] = $exam_collection_id;
  675. }
  676. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  677. $list = $this->model
  678. ->where($where)->where($this->whereExtend)
  679. ->order('user_username asc')
  680. ->paginate($limit);
  681. foreach ($list as $k=>$v){
  682. $fault_list = Db::name('real_exam_fault')->where(['exam_id'=>$v['exam_id'],'flag'=>1])->select();
  683. $list[$k]['fault_name_one'] = Fault::where('fault_id',$fault_list[0]['fault_id'])->value('name');
  684. $list[$k]['fault_name_two'] = Fault::where('fault_id',$fault_list[1]['fault_id'])->value('name');
  685. $list[$k]['fault_name_three'] = Fault::where('fault_id',$fault_list[2]['fault_id'])->value('name');
  686. $score = Db::name('real_exam_score')->where('exam_id', $v['exam_id'])->find();
  687. $list[$k]['fault_score'] = 75-$score['fault_one_score']-$score['fault_two_score']-$score['fault_three_score'];
  688. $list[$k]['fault_one_score'] = $score['fault_one_score'];
  689. $list[$k]['fault_two_score'] = $score['fault_two_score'];
  690. $list[$k]['fault_three_score'] = $score['fault_three_score'];
  691. $list[$k]['weixiu_score'] = 10-$score['overtime_score']??0;
  692. $list[$k]['overtime_score'] = $score['overtime_score']??0;
  693. $list[$k]['other_jielun'] = !empty($score['other_jielun']) ? json_decode($score['other_jielun'],true):[];
  694. $list[$k]['user_depart_name'] = Department::where('id',$v['user_depart_id'])->value('name');
  695. $diffInSeconds = $v['endtime'] - $v['starttime']; // 两个时间戳之间的差异(秒)
  696. $minutes = floor($diffInSeconds / 60); // 计算分钟数
  697. $seconds = $diffInSeconds % 60; // 计算剩余的秒数
  698. $list[$k]['shijian'] = $minutes.'分'.$seconds.'秒';
  699. }
  700. $languageEnGb = new \PhpOffice\PhpWord\Style\Language(\PhpOffice\PhpWord\Style\Language::ZH_CN);
  701. $phpWord = new \PhpOffice\PhpWord\PhpWord();
  702. $phpWord->getSettings()->setThemeFontLang($languageEnGb);
  703. $fancyTableStyleName = 'Fancy Table';
  704. $fancyTableStyle = array('borderSize' => 1, 'borderColor' => '#cad9ea', 'cellMargin' => 0, 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER, 'cellSpacing' => 0);
  705. $fancyTableFirstRowStyle = array('borderBottomSize' => 0, 'borderBottomColor' => '#ffffff', 'bgColor' => '000000');
  706. $fancyTableCellStyle = array('valign' => 'center');
  707. $fancyTableFontStyle = array('bold' => true,'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER);
  708. $fancyTableFontStyle1 = array('bold' => true,'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::START);
  709. $phpWord-> addTableStyle($fancyTableStyleName, $fancyTableStyle, $fancyTableFirstRowStyle);
  710. //中间学员的成绩信息 start
  711. foreach ($list as $k=> $it) {
  712. $section_string = 'section'.$k;
  713. $section_string = $phpWord->addSection([
  714. // 'pageSizeH' => \PhpOffice\PhpWord\Shared\Converter::inchToTwip(12.7),
  715. // 'pageSizeW' => \PhpOffice\PhpWord\Shared\Converter::inchToTwip(8.3)
  716. ]);
  717. $section_string->addTextBreak(1);
  718. $table = $section_string->addTable($fancyTableStyleName);
  719. $section_string -> addText($it['user_nickname'].'考试详细',[
  720. 'size' => 14,
  721. 'name'=>'黑体',
  722. ],['alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER,
  723. 'spaceAfter' => 500, //标题后部预留长度
  724. 'spaceBefore' => 0]);
  725. $TableContentStyle1 = array('size'=>10,'name'=>'宋体','lineHeight' => 2);
  726. $TableContentStyle11 = array('size'=>9,'name'=>'宋体');
  727. $TableContentStyle2 = array('size'=>10,'name'=>'宋体','lineHeight' => 1.5);
  728. $table = $section_string->addTable($fancyTableStyleName);
  729. $table->addRow();
  730. $table->addCell(4000, $fancyTableCellStyle)->addText("学员账号",$TableContentStyle1, $fancyTableFontStyle);
  731. $table->addCell(5000, $fancyTableCellStyle)->addText($it['user_username'],$TableContentStyle1, $fancyTableFontStyle);
  732. $table->addCell(4000, $fancyTableCellStyle)->addText("学员姓名",$TableContentStyle1, $fancyTableFontStyle);
  733. $table->addCell(5000, $fancyTableCellStyle)->addText($it['user_nickname'],$TableContentStyle1, $fancyTableFontStyle);
  734. $table->addCell(2000, $fancyTableCellStyle)->addText("区队",$TableContentStyle1, $fancyTableFontStyle);
  735. $table->addCell(3000, $fancyTableCellStyle)->addText($it['user_depart_name'],$TableContentStyle1, $fancyTableFontStyle);
  736. $table->addRow();
  737. $table->addCell(4000, $fancyTableCellStyle)->addText("考试开始时间",$TableContentStyle1, $fancyTableFontStyle);
  738. $table->addCell(5000, $fancyTableCellStyle)->addText(date('Y/m/d H:i:s',$it['starttime']),$TableContentStyle1, $fancyTableFontStyle);
  739. $table->addCell(4000, $fancyTableCellStyle)->addText("考试结束时间",$TableContentStyle1, $fancyTableFontStyle);
  740. $table->addCell(5000, $fancyTableCellStyle)->addText(date('Y/m/d H:i:s',$it['endtime']),$TableContentStyle1, $fancyTableFontStyle);
  741. $table->addCell(2000, $fancyTableCellStyle)->addText("成绩",$TableContentStyle1, $fancyTableFontStyle);
  742. $table->addCell(3000, $fancyTableCellStyle)->addText($it['total_score'],$TableContentStyle1, $fancyTableFontStyle);
  743. $table2 = $section_string->addTable($fancyTableStyleName);
  744. $table2->addRow();
  745. $table2->addCell(3000, $fancyTableCellStyle)->addText("序号",$TableContentStyle1, $fancyTableFontStyle);
  746. $table2->addCell(7000, $fancyTableCellStyle)->addText("评分标准",$TableContentStyle1, $fancyTableFontStyle);
  747. $table2->addCell(3000, $fancyTableCellStyle)->addText("扣分",$TableContentStyle1, $fancyTableFontStyle);
  748. $table2->addCell(3000, $fancyTableCellStyle)->addText("维修情况",$TableContentStyle1, $fancyTableFontStyle);
  749. $table2->addCell(7000, $fancyTableCellStyle)->addText("题目",$TableContentStyle1, $fancyTableFontStyle);
  750. $table3 = $section_string->addTable($fancyTableStyleName);
  751. $table3->addRow();
  752. $table3->addCell(23000, $fancyTableCellStyle)->addText("一.故障排除(75分)(本题得分:0)",$TableContentStyle1, $fancyTableFontStyle1);
  753. //4
  754. $table4 = $section_string->addTable($fancyTableStyleName);
  755. $table4->addRow();
  756. $table4->addCell(3000, $fancyTableCellStyle)->addText("1",$TableContentStyle1, $fancyTableFontStyle);
  757. $table4->addCell(7000, $fancyTableCellStyle)->addText("故障一未排除扣25分",$TableContentStyle1, $fancyTableFontStyle);
  758. $table4->addCell(3000, $fancyTableCellStyle)->addText($it['fault_one_score'],$TableContentStyle1, $fancyTableFontStyle);
  759. if($it['fault_one_score']==0){
  760. $fault_one_result = '已排除';
  761. }else{
  762. $fault_one_result = '未排除';
  763. }
  764. $table4->addCell(3000, $fancyTableCellStyle)->addText($fault_one_result,$TableContentStyle1, $fancyTableFontStyle);
  765. $table4->addCell(7000, $fancyTableCellStyle)->addText($it['fault_name_one'],$TableContentStyle1, $fancyTableFontStyle);
  766. $table4->addRow();
  767. $table4->addCell(3000, $fancyTableCellStyle)->addText("2",$TableContentStyle1, $fancyTableFontStyle);
  768. $table4->addCell(7000, $fancyTableCellStyle)->addText("故障二未排除扣25分",$TableContentStyle1, $fancyTableFontStyle);
  769. $table4->addCell(3000, $fancyTableCellStyle)->addText($it['fault_two_score'],$TableContentStyle1, $fancyTableFontStyle);
  770. if($it['fault_two_score']==0){
  771. $fault_two_result = '已排除';
  772. }else{
  773. $fault_two_result = '未排除';
  774. }
  775. $table4->addCell(3000, $fancyTableCellStyle)->addText($fault_two_result,$TableContentStyle1, $fancyTableFontStyle);
  776. $table4->addCell(7000, $fancyTableCellStyle)->addText($it['fault_name_two'],$TableContentStyle1, $fancyTableFontStyle);
  777. $table4->addRow();
  778. $table4->addCell(3000, $fancyTableCellStyle)->addText("3",$TableContentStyle1, $fancyTableFontStyle);
  779. $table4->addCell(7000, $fancyTableCellStyle)->addText("故障三未排除扣25分",$TableContentStyle1, $fancyTableFontStyle);
  780. $table4->addCell(3000, $fancyTableCellStyle)->addText($it['fault_three_score'],$TableContentStyle1, $fancyTableFontStyle);
  781. if($it['fault_three_score']==0){
  782. $fault_three_result = '已排除';
  783. }else{
  784. $fault_three_result = '未排除';
  785. }
  786. $table4->addCell(3000, $fancyTableCellStyle)->addText($fault_three_result,$TableContentStyle1, $fancyTableFontStyle);
  787. $table4->addCell(7000, $fancyTableCellStyle)->addText($it['fault_name_three'],$TableContentStyle1, $fancyTableFontStyle);
  788. $table5 = $section_string->addTable($fancyTableStyleName);
  789. $table5->addRow();
  790. $table5->addCell(23000, $fancyTableCellStyle)->addText("二.修理报告表(15分)(本题得分:".$it['fault_score'].")",$TableContentStyle1, $fancyTableFontStyle1);
  791. $table5->addRow();
  792. $table5->addCell(23000, $fancyTableCellStyle)->addText("学员答作答情况",$TableContentStyle1, $fancyTableFontStyle1);
  793. $table6 = $section_string->addTable($fancyTableStyleName);
  794. $table6->addRow();
  795. $table6->addCell(1000, $fancyTableCellStyle)->addText("序号",$TableContentStyle1, $fancyTableFontStyle);
  796. $table6->addCell(3000, $fancyTableCellStyle)->addText("故障现象",$TableContentStyle1, $fancyTableFontStyle);
  797. $table6->addCell(5000, $fancyTableCellStyle)->addText("可能原因",$TableContentStyle1, $fancyTableFontStyle);
  798. $table6->addCell(3000, $fancyTableCellStyle)->addText("故障部位",$TableContentStyle1, $fancyTableFontStyle);
  799. $table6->addCell(3000, $fancyTableCellStyle)->addText("排除方法",$TableContentStyle1, $fancyTableFontStyle);
  800. $table6->addCell(5000, $fancyTableCellStyle)->addText("扣分原因",$TableContentStyle1, $fancyTableFontStyle);
  801. $table6->addCell(3000, $fancyTableCellStyle)->addText("扣分情况",$TableContentStyle1, $fancyTableFontStyle);
  802. //7
  803. $table7 = $section_string->addTable($fancyTableStyleName);
  804. foreach ($it['other_jielun'] as $k1 => $v1) {
  805. $table7->addRow();
  806. $table7->addCell(1000, $fancyTableCellStyle)->addText(++$v1['xh_id'],$TableContentStyle11, $fancyTableFontStyle);
  807. $table7->addCell(3000, $fancyTableCellStyle)->addText($v1['xx_name'],$TableContentStyle11, $fancyTableFontStyle);
  808. $table7->addCell(5000, $fancyTableCellStyle)->addText($v1['yy_name'],$TableContentStyle11, $fancyTableFontStyle);
  809. $table7->addCell(3000, $fancyTableCellStyle)->addText($v1['bw_name'],$TableContentStyle11, $fancyTableFontStyle);
  810. $table7->addCell(3000, $fancyTableCellStyle)->addText($v1['pc_name'],$TableContentStyle11, $fancyTableFontStyle);
  811. $kf_yy = '';
  812. if(!empty($v1['cx_name'])){
  813. foreach ($v1['cx_name'] as $k2 => $v2) {
  814. if($v1['gzxz_id'] == $v2['gzxz_id']){
  815. $kf_yy = $v2['cx_type'].":".$v2['cx_name'];
  816. }
  817. }
  818. }else{
  819. $kf_yy = $v1['cx_type'];
  820. }
  821. $table7->addCell(5000, $fancyTableCellStyle)->addText($kf_yy,$TableContentStyle11, $fancyTableFontStyle);
  822. $table7->addCell(3000, $fancyTableCellStyle)->addText($v1['cx_score']??0,$TableContentStyle11, $fancyTableFontStyle);
  823. }
  824. $table8 = $section_string->addTable($fancyTableStyleName);
  825. $table8->addRow();
  826. $table8->addCell(23000, $fancyTableCellStyle)->addText("故障现象少写或错写1条扣5分;可能原因少写或错写1条扣1分;故障部位少写或错写1条扣1分;排除方法少写或错写1条扣1分。",$TableContentStyle2, $fancyTableFontStyle1);
  827. $table8->addRow();
  828. $table8->addCell(23000, $fancyTableCellStyle)->addText("三.维修时间(10分)(本题得分:".$it['weixiu_score'].")",$TableContentStyle1, $fancyTableFontStyle1);
  829. $table9 = $section_string->addTable($fancyTableStyleName);
  830. $table9->addRow();
  831. $table9->addCell(8500, $fancyTableCellStyle)->addText("按没超过1分钟扣1分的比例扣分",$TableContentStyle1, $fancyTableFontStyle);
  832. $table9->addCell(8500, $fancyTableCellStyle)->addText("考试时长:".$it['shijian'],$TableContentStyle1, $fancyTableFontStyle);
  833. $table9->addCell(6000, $fancyTableCellStyle)->addText("扣分:".$it['overtime_score'],$TableContentStyle1, $fancyTableFontStyle);
  834. $table10 = $section_string->addTable($fancyTableStyleName);
  835. $table10->addRow();
  836. $table10->addCell(11500, $fancyTableCellStyle)->addText("五.成绩",$TableContentStyle1, $fancyTableFontStyle);
  837. $table10->addCell(11500, $fancyTableCellStyle)->addText($it['total_score'],$TableContentStyle1, $fancyTableFontStyle);
  838. }
  839. //中间学员的成绩信息 end
  840. $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
  841. $file_name = 'uploads/'.date('Ymd').'/'.$doc_name.'.docx';
  842. $tmpPath ='uploads/'.date('Ymd').'/';
  843. if(!file_exists($tmpPath)){
  844. mkdir($tmpPath, 0777, true);
  845. }
  846. $objWriter->save($file_name);
  847. //以只读和二进制模式打开文件
  848. $file = fopen ( $file_name, "rb" );
  849. //告诉浏览器这是一个文件流格式的文件
  850. Header ( "Content-type: application/octet-stream" );
  851. //请求范围的度量单位
  852. Header ( "Accept-Ranges: bytes" );
  853. //Content-Length是指定包含于请求或响应中数据的字节长度
  854. Header ( "Accept-Length: " . filesize ( $file_name ) );
  855. //用来告诉浏览器,文件是可以当做附件被下载,下载后的文件名称为$file_name该变量的值。
  856. Header ( "Content-Disposition: attachment; filename=".$doc_name.'.docx' );
  857. //读取文件内容并直接输出到浏览器
  858. echo fread ( $file, filesize ( $file_name ) );
  859. fclose ( $file );
  860. exit ();
  861. }
  862. public function multi($ids = null)
  863. {
  864. if (false === $this->request->isPost()) {
  865. $this->error(__('Invalid parameters'));
  866. }
  867. $ids = $ids ?: $this->request->post('ids');
  868. if (empty($ids)) {
  869. $this->error(__('Parameter %s can not be empty', 'ids'));
  870. }
  871. if (false === $this->request->has('params')) {
  872. $this->error(__('No rows were updated'));
  873. }
  874. parse_str($this->request->post('params'), $values);
  875. // $values = $this->auth->isSuperAdmin() ? $values : array_intersect_key($values, array_flip(is_array($this->multiFields) ? $this->multiFields : explode(',', $this->multiFields)));
  876. // if (empty($values)) {
  877. // $this->error(__('You have no permission'));
  878. // }
  879. $adminIds = $this->getDataLimitAdminIds();
  880. if (is_array($adminIds)) {
  881. $this->model->where($this->dataLimitField, 'in', $adminIds);
  882. }
  883. $count = 0;
  884. Db::startTrans();
  885. try {
  886. $list = $this->model->where($this->model->getPk(), 'in', $ids)->select();
  887. foreach ($list as $item) {
  888. $count += $item->allowField(true)->isUpdate(true)->save($values);
  889. }
  890. Db::commit();
  891. } catch (PDOException|Exception $e) {
  892. Db::rollback();
  893. $this->error($e->getMessage());
  894. }
  895. if ($count) {
  896. $this->success();
  897. }
  898. $this->error(__('No rows were updated'));
  899. }
  900. }