1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace app\common\model;
- use think\Db;
- class Supervise extends Base
- {
- public function updates(){
- $data = request()->post();
- $result = validate('Supervise')->check($data,[],'');
- if(true !== $result){
- $this->error = validate('Supervise')->getError();
- return false;
- }
- $id = $data['id'];
- unset($data['id']);
- $content = json_decode($data['content'],true);
- if(count($content) < 1){
- $this->error ='标准不能为空';
- return false;
- }
- foreach ($content as $k=>$v){
- if(!isset($v['title']) && empty($v['title'])){
- $this->error ='标准名称不能为空';
- return false;
- }
- if(!isset($v['sub']) || empty($v['sub']) || count($v['sub']) < 1 ){
- $this->error ='子标准不能为空';
- return false;
- }
- $score = 0;
- $subList = $v['sub'];
- foreach($subList as $kk=>$vv){
- if(!isset($vv['title']) && empty($vv['title'])){
- $this->error ='子标准名称不能为空';
- return false;
- }
- if(!isset($vv['standard']) && empty($vv['standard'])){
- $this->error ='子标准评分标准不能为空';
- return false;
- }
- if(!isset($vv['sub']) || empty($vv['sub']) || count($vv['sub']) < 1){
- $this->error ='考核标准不能为空';
- return false;
- }
- $subscore = 0;
- $subsubList = $vv['sub'];
- foreach ($subsubList as $kkk=>$vvv){
- if(!isset($vvv['title']) && empty($vvv['title'])){
- $this->error ='考核标准内容不能为空';
- return false;
- }
- if($vvv['score'] < 1){
- $this->error ='考核标准内容分值不能小于1';
- return false;
- }
- $subscore +=$vvv['score'];
- }
- $content[$k]['sub'][$kk]['score'] = $subscore;
- $score +=$subscore;
- }
- $content[$k]['score'] = $score;
- }
- $data['content'] = json_encode($content,JSON_UNESCAPED_UNICODE);
- if($id > 0){
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $data['create_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- $this->error = '操作失败';
- return false;
- }
- return true;
- }
- }
|