sandm 1 年之前
父節點
當前提交
46f8b16ac5

+ 117 - 26
server/api/modules/v1/controllers/SurveyController.php

@@ -9,6 +9,7 @@ use common\helpers\CodeImgGenerate;
 use common\helpers\Util;
 use common\modules\config\models\Config;
 use common\models\Survey;
+use common\models\SurveyNew;
 use Yii;
 use yii\helpers\ArrayHelper;
 use api\common\behaviors\QueryParamAuth;
@@ -197,43 +198,132 @@ class SurveyController extends Controller {
 		$type = request()->get('type');
         if(empty($type)) $type = 'industry';
         
-		$survey = Survey::find()->where(['type' => $type])->all();
+		$survey = ArrayHelper::toArray(SurveyNew::find()->where(['type' => $type])->all());
 
         $captcha = new CodeImgGenerate(\Yii::$app->controller->id,\Yii::$app->controller);
 
-        $result = $captcha->validate($data['code']);
-        
-         if(!$result){
-             return ['errcode' => CodeEnum::CODE_ERROR, 'errmsg' => '验证码错误'];
-         }
+//        $result = $captcha->validate($data['code']);
+//
+//         if(!$result){
+//             return ['errcode' => CodeEnum::CODE_ERROR, 'errmsg' => '验证码错误'];
+//         }
+
+        //$selects = ArrayHelper::toArray(Config::find()->where(['group' => 'industry','type' => 'select'])->all());
 
 		$list = [];
+
 		foreach ($survey as $key=>$value) {
-		    $filter = json_decode($value['filter'],true);
-			foreach ($filter as $key=>$value1) {
-			    if(!empty($value1)){
-			        $str = join('|',(array)$value1);
-			        if(array_key_exists($key,$data) && !empty($data[$key])){
-                        if(strpos($str,(string)$data[$key]) !== false){
-                            $list[] = [
-                                'id'=>$value['id'],
-                                'title'=>$value['title'],
-                                'content'=>$value['content']
-                            ];
-                            continue;
+            $filter = explode(';',$value['filter']);//先判断第一层and关系
+            $is_match = [];
+            foreach ($filter as $key1 => $value1){
+                if(!empty($value1)){
+
+                    if(array_key_exists($value1,$data) && !empty($data[$value1]) && $data[$value1] != '请选择' && !in_array($value1,['shengte','shenga','quanyi','shengb','rencaileixing','zhuanyelingyunianxian'])){
+                        if(strpos($value['title'],(string)$data[$value1]) === false){//如果用户提交的信息字眼有出现在政策条件内,相当于条件符合
+                            $is_match[$key1] = false;
+                            continue 2;
+                        }else{
+                            $is_match[$key1] = true;
                         }
                     }
-			    }
-			}
+
+                    if(strpos($value1,'-') !== false){//如果有存在或关系
+                        $filter1 = explode('-',$value1);
+                        $i = 0;
+                        foreach ($filter1 as $key2 => $value2){
+                            if(array_key_exists($value2,$data) && !empty($data[$value2]) && $data[$value2] != '请选择'){
+                                if(strpos($value['title'],(string)$data[$value2]) !== false){//如果用户提交的信息字眼有出现在政策条件内,相当于条件符合
+                                    $i++;
+                                }
+                            }
+                        }
+                        if($i == 0){
+                            $is_match[$key1] = false;
+                            continue 2;
+                        }else{
+                            $is_match[$key1] = true;
+                        }
+                    }
+
+
+                    if(strpos($value1,'|') !== false){//如果有存在判断大小
+                        $filter2 = explode('|',$value1);
+                        if(array_key_exists($filter2[0],$data) && !empty($data[$filter2[0]]) && $data[$filter2[0]] != '请选择'){
+                            switch ($filter2[1]){
+                                case '>=':
+                                    if($data[$filter2[0]] >= $filter2[2]){
+                                        $is_match[$key1] = true;
+                                    }else{
+                                        $is_match[$key1] = false;
+                                        continue 2;
+                                    }
+                                    break;
+                                case '=':
+                                    if($data[$filter2[0]] == $filter2[2]){
+                                        $is_match[$key1] = true;
+                                    }else{
+                                        $is_match[$key1] = false;
+                                        continue 2;
+                                    }
+                                    break;
+                            }
+                        }else{
+                            $is_match[$key1] = false;
+                            continue 2;
+                        }
+                    }
+
+                }
+            }
+
+            $match_count = 0;
+            foreach ($is_match as $v){
+                if($v){
+                    $match_count++;
+                }
+            }
+            if($match_count == count($filter)){
+                switch ($value['cengci']){
+                    case '1':
+                        $level = '第一层次';
+                        break;
+                    case '2':
+                        $level = '第二层次';
+                        break;
+                    case '3':
+                        $level = '第三层次';
+                        break;
+                    case '4':
+                        $level = '第四层次';
+                        break;
+                    case '5':
+                        $level = '第五层次';
+                        break;
+                    case '6':
+                        $level = '第六层次';
+                        break;
+                    case '7':
+                        $level = '第七层次';
+                        break;
+                }
+                $list[] = [
+                    'id'=>$value['id'],
+                    'title'=>$value['title'],
+                    'content'=>$value['content'],
+                    'level' => $level
+                ];
+            }
 		}
+
         //去重复
 		$cengci = [];      
-        foreach ($list as $value) {       
-            if(isset($cengci[$value['title']])){
-                unset($value['title']);
+        foreach ($list as $value) {
+
+            if(isset($cengci[$value['level']])){
+                unset($value['level']);
             }else{
-                $cengci[$value['title']] = $value;
-            }  
+                $cengci[$value['level']] = $value;
+            }
         }
         $cengci = array_values($cengci);
 
@@ -243,7 +333,8 @@ class SurveyController extends Controller {
         $query->andWhere(new \yii\db\Expression('FIND_IN_SET("'. Policy::TYPE_SURVEY .'", type)'));
         if(!empty($cengci)){
             foreach ($cengci as $value) {
-		         $query->orWhere(new \yii\db\Expression('FIND_IN_SET("'.$value['title'].'", cengci)'));
+
+		         $query->orWhere(new \yii\db\Expression('FIND_IN_SET("'.$value['level'].'", cengci)'));
     		}
             $list = $query->all();
         }

+ 0 - 11
server/backend/controllers/SurveyNewController.php

@@ -88,11 +88,7 @@ class SurveyNewController extends Controller
                 $typeDesc = '集成电路';
                 break;
         }
-      
-		$configModels = Config::find()->select(['name','value','extra','description','type'])->where(['group' => $type])->all();
 
-        $cengciModels =  Config::find()->select(['name','value','extra','description','type'])->where(['group' => 'policy', 'name' => 'cengci'])->all();
-		
 		if (Yii::$app->request->isPost) {
 			$data = Yii::$app->request->post();
 			
@@ -104,9 +100,6 @@ class SurveyNewController extends Controller
 				$arr[$key] = $value;
 			}
 
-			$data['SurveyNew']['filter'] = json_encode($arr,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
-            $data['SurveyNew']['type'] = $type;
-            
 			$model->load($data);
 			$model->save();
 			return $this->redirect(['index']);
@@ -115,8 +108,6 @@ class SurveyNewController extends Controller
 		return $this->render('create', [
 			'model' => $model,
 			'type'=>$typeDesc,
-			'configModels' => $configModels,
-			'cengciModels' => $cengciModels,
 		]);
 
     }
@@ -161,8 +152,6 @@ class SurveyNewController extends Controller
 				}
 				$arr[$key] = $value;
 			}
-
-			$data['SurveyNew']['filter'] = json_encode($arr,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
           
 			$model->load($data);
 			$model->save();

+ 2 - 35
server/backend/views/survey-new/_form.php

@@ -17,43 +17,10 @@ use yii\widgets\ActiveForm;
         <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
         <?= $form->field($model, 'type',['options'=>['class'=>'hide']])->textInput(['maxlength' => true]) ?>
 
+        <?= $form->field($model, 'filter')->textarea() ?>
+        <?= $form->field($model, 'cengci')->radioList([1 =>'第一层次',2 => '第二层次',3 => '第三层次',4 => '第四层次',5 => '第五层次',6 => '第六层次',7 => '第七层次']) ?>
 
 
-		<?php
-	    //人才层次
-        foreach ($cengciModels as $index => $configModel) {
-
-			$value = explode("\r\n",$configModel['extra']);
-
-			$arr = [];
-			foreach($value as &$val){
-				$val = trim($val);
-				$arr[$val] = $val;
-			}
-
-            echo $form->field($model, 'id')->checkboxList($arr,[
-				'name'=>$configModel['name'],
-				'value'=>$model->filter[$configModel['name']]
-			])->label($configModel['description']);
-        }
-        foreach ($configModels as $index => $configModel) {
-
-			$value = explode("\r\n",$configModel['extra']);
-
-			$arr = [];
-			foreach($value as &$val){
-				$val = trim($val);
-				$arr[$val] = $val;
-			}
-
-            echo $form->field($model, 'id')->checkboxList($arr,[
-				'name'=>$configModel['name'],
-				'value'=>$model->filter[$configModel['name']]
-			])->label($configModel['description']);
-        }
-
-        ?>
-
         <?= $form->field($model, 'content')->widget(\common\widgets\EditorWidget::className(), $model->isNewRecord ? ['type' => request('editor') ?: config('page_editor_type')] : ['isMarkdown' => $model->markdown]) ?>
 
         <div class="form-group form-submit">

+ 1 - 1
server/backend/views/survey-new/index.php

@@ -30,7 +30,7 @@ $this->params['breadcrumbs'][] = $this->title;
 //                },
 //            ],
             'title',
-            'slug',
+            'cengcis',
 
             ['class' => 'common\helpers\DiyActionColumn'],
         ],

+ 1 - 2
server/backend/views/survey-new/update.php

@@ -11,8 +11,7 @@ $this->params['breadcrumbs'][] = 'Update';
 <div class="page-update">
 
     <?= $this->render('_form', [
-        'model' => $model,
-		'configModels' => $configModels,
+        'model' => $model
     ]) ?>
 
 </div>

+ 1 - 0
server/common/models/SurveyNew.php

@@ -35,6 +35,7 @@ class SurveyNew extends \yii\db\ActiveRecord
             [['content', 'title'], 'required'],
             [['content'], 'string'],
 			[['filter'], 'string'],
+            [['cengci'],'string'],
             ['markdown', 'default', 'value' => $this->getIsMarkdown()],
             [['use_layout'], 'in', 'range' => [0, 1]],
             [['title'], 'string', 'max' => 50],

+ 1 - 1
server/web/mobile/index.html

@@ -1,2 +1,2 @@
 <!DOCTYPE html><html lang=zh-CN><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><title>加载中</title><script>var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') || CSS.supports('top: constant(a)'))
-            document.write('<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' + (coverSupport ? ', viewport-fit=cover' : '') + '" />')</script><link rel=stylesheet href=/mobile/static/index.63b34199.css></head><body><noscript><strong>Please enable JavaScript to continue.</strong></noscript><div id=app></div><script src=/mobile/static/js/chunk-vendors.a5b9e456.js></script><script src=/mobile/static/js/index.fe0f60de.js></script></body></html>
+            document.write('<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' + (coverSupport ? ', viewport-fit=cover' : '') + '" />')</script><link rel=stylesheet href=/mobile/static/index.97465e7b.css></head><body><noscript><strong>Please enable JavaScript to continue.</strong></noscript><div id=app></div><script src=/mobile/static/js/chunk-vendors.5bad1cee.js></script><script src=/mobile/static/js/index.cd84de72.js></script></body></html>