Supervise.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class Supervise extends Base
  5. {
  6. public function updates(){
  7. $data = request()->post();
  8. $result = validate('Supervise')->check($data,[],'');
  9. if(true !== $result){
  10. $this->error = validate('Supervise')->getError();
  11. return false;
  12. }
  13. $id = $data['id'];
  14. unset($data['id']);
  15. $content = json_decode($data['content'],true);
  16. if(count($content) < 1){
  17. $this->error ='标准不能为空';
  18. return false;
  19. }
  20. foreach ($content as $k=>$v){
  21. if(!isset($v['title']) && empty($v['title'])){
  22. $this->error ='标准名称不能为空';
  23. return false;
  24. }
  25. if(!isset($v['sub']) || empty($v['sub']) || count($v['sub']) < 1 ){
  26. $this->error ='子标准不能为空';
  27. return false;
  28. }
  29. $score = 0;
  30. $subList = $v['sub'];
  31. foreach($subList as $kk=>$vv){
  32. if(!isset($vv['title']) && empty($vv['title'])){
  33. $this->error ='子标准名称不能为空';
  34. return false;
  35. }
  36. if(!isset($vv['standard']) && empty($vv['standard'])){
  37. $this->error ='子标准评分标准不能为空';
  38. return false;
  39. }
  40. if(!isset($vv['sub']) || empty($vv['sub']) || count($vv['sub']) < 1){
  41. $this->error ='考核标准不能为空';
  42. return false;
  43. }
  44. $subscore = 0;
  45. $subsubList = $vv['sub'];
  46. foreach ($subsubList as $kkk=>$vvv){
  47. if(!isset($vvv['title']) && empty($vvv['title'])){
  48. $this->error ='考核标准内容不能为空';
  49. return false;
  50. }
  51. if($vvv['score'] < 1){
  52. $this->error ='考核标准内容分值不能小于1';
  53. return false;
  54. }
  55. $subscore +=$vvv['score'];
  56. }
  57. $content[$k]['sub'][$kk]['score'] = $subscore;
  58. $score +=$subscore;
  59. }
  60. $content[$k]['score'] = $score;
  61. }
  62. $data['content'] = json_encode($content,JSON_UNESCAPED_UNICODE);
  63. if($id > 0){
  64. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  65. }else{
  66. $data['create_time'] = date('Y-m-d H:i:s');
  67. $ret = $this->allowField(true)->save($data);
  68. }
  69. if(!$ret){
  70. $this->error = '操作失败';
  71. return false;
  72. }
  73. return true;
  74. }
  75. }