db_pre = Yii::$app->db->tablePrefix; $this->model_id = $model_id; $this->fields = json_decode(Yii::$app->cache->get(CacheId::modelFieldCacheId($model_id)),true); $this->model = json_decode(Yii::$app->cache->get(CacheId::modelFieldCacheId($model_id)),true); $this->site_config = json_decode(Yii::$app->cache->get(CacheId::siteConfigCacheId()),true); } function get($data,$is_import = 0) { $identityInfo = Yii::$app->controller->getIdentityInfo(); if(!defined('IN_ADMIN')) $group_id = $identityInfo['group_id'];//获取用户组 else $role_id = $identityInfo['role_id']; $this->data = $data = trim_script($data); $info = array(); foreach($data as $field=>$value) { if(!isset($this->fields[$field]) || check_in($role_id, $this->fields[$field]['unset_role_ids']) || check_in($group_id, $this->fields[$field]['unset_group_ids'])) continue; $name = $this->fields[$field]['name']; $min_length = $this->fields[$field]['min_length']; $max_length = $this->fields[$field]['max_length']; $pattern = $this->fields[$field]['pattern']; $error_tips = $this->fields[$field]['error_tips']; if(empty($error_tips)) $error_tips = $name.'不符合条件'; $length = empty($value) ? 0 : (is_string($value) ? strlen($value) : count($value)); if($min_length && $length < $min_length) { if($is_import) { return false; } else { Yii::$app->controller->showMessage(array('class'=>'info', 'message'=>$name.' 不能少于 '.$min_length.'个字符')); } } if($max_length && $length > $max_length) { if($is_import) { $value = str_cut($value,0,$max_length,''); } else { Yii::$app->controller->showMessage(array('class'=>'info', 'message'=>$name.' 不能多于 '.$max_length.'个字符')); } } elseif($max_length) { $value = str_cut($value,0,$max_length,''); } if($pattern && $length && !preg_match($pattern, $value) && !$is_import) Yii::$app->controller->showMessage(array('class'=>'info', 'message'=>$error_tips)); $this->table_name = $this->fields[$field]['is_system'] ? $this->db_pre.$this->model['table_name'] : $this->db_pre.$this->model['table_name'].'_data'; if($this->fields[$field]['is_unique']) { //这里要补充判断唯一方法 $exists = (new \yii\db\Query()) ->from($this->table_name) ->where([$field => $value]) ->count(); if($exists)Yii::$app->controller->showMessage(array('class'=>'info', 'message'=>$name.' 不能重复')); } $func = $this->fields[$field]['form_type']; if(method_exists($this, $func)) $value = $this->$func($field, $value); if($this->fields[$field]['is_system']) { $info['system'][$field] = $value; } else { $info['model'][$field] = $value; } //颜色选择为隐藏域 在这里进行取值 $info['system']['style'] = $_POST['style_color'] ? strip_tags($_POST['style_color']) : ''; if($_POST['style_font_weight']) $info['system']['style'] = $info['system']['style'].';'.strip_tags($_POST['style_font_weight']); } return $info; } }?>