north 7 years ago
parent
commit
ca04c395eb

+ 84 - 0
www/protected/controllers/QuestionController.php

@@ -0,0 +1,84 @@
+<?php
+/**
+ * Created by north.Deng's MAC
+ * User: north.Deng
+ * Date: 2018/5/4
+ * Time: 上午10:15
+ * description :
+ */
+
+class QuestionController extends AdminController {
+
+    public function actionIndex()
+    {
+
+        $this->render('index',array(
+
+        ));
+    }
+
+    public function actionList()
+    {
+        $pageParams = CommonFn::getPageParams();
+        $status = intval(Yii::app()->request->getParam('status', 100));
+        $criteria = new EMongoCriteria($pageParams);
+        /*if ($status != 100 ) {
+            $criteria->status('==',$status);
+        }*/
+        $cursor = Question::model()->findAll($criteria);
+        $rows = CommonFn::getRowsFromCursor($cursor);
+        $parsedRows = Question::model()->parse($rows);
+        $total = $cursor->count();
+        echo CommonFn::composeDatagridData($parsedRows, $total);
+    }
+
+    public function actionEdit()
+    {
+        $id = Yii::app()->request->getParam('id','');
+        $title = Yii::app()->request->getParam('title','');
+        $questions = Yii::app()->request->getParam('questions','');
+
+        $question = Question::get(new MongoId($id));
+
+        if (!empty($title)) {
+            $question->title = $title;
+        }
+
+        if (!empty($questions)) {
+            $data = array();
+            foreach ($questions as $key => $value) {
+                if ($key == 4) {
+                    $data['result'] = $value;
+                } else {
+                    $data['question'][] = $value;
+                }
+            }
+            $question->question = $data;
+        }
+
+        $question->save();
+
+        CommonFn::requestAjax(true,'保存成功');exit;
+    }
+    public function actionAdd()
+    {
+        $title = Yii::app()->request->getParam('title','');
+        $questions = Yii::app()->request->getParam('questions','');
+        $data =array();
+        foreach ($questions as $key => $value) {
+            if (empty($value)) {
+                CommonFn::requestAjax(false,'题目不能为空');exit;
+            }
+            if ($key == 4) {
+                $data['result'] = $value;
+            } else {
+                $data['question'][] = $value;
+            }
+        }
+        $question = new Question();
+        $question->title = $title;
+        $question->question = $data;
+        $question->save();
+        CommonFn::requestAjax(true,'保存成功');exit;
+    }
+}

+ 1 - 0
www/protected/modules/j/controllers/JGEmpolyerController.php

@@ -224,6 +224,7 @@ class JgEmpolyerController extends JBaseController
         if ($work_time != '') {
             $criteria->work_time('<=',intval($work_time));
         }
+        $criteria->sort('socre',EMongoCriteria::SORT_DESC);
         $cursor = JGEmploye::model()->findAll($criteria);
         $rows = CommonFn::getRowsFromCursor($cursor);
         $parsedRows = JGEmploye::model()->parse($rows);

+ 52 - 0
www/protected/modules/j/controllers/QuestionController.php

@@ -0,0 +1,52 @@
+<?php
+/**
+ * Created by north.Deng's MAC
+ * User: north.Deng
+ * Date: 2018/5/4
+ * Time: 下午12:34
+ * description :
+ */
+
+class QuestionController extends JBaseController
+{
+    public function actionList()
+    {
+        /* $tmp = Question::get(new MongoId('5aebc756b292c9171883858a'));
+         for ($i=0;$i<20;$i++) {
+             $q = new Question();
+             $q->title = $tmp->title;
+             $q->question = $tmp->question;
+             $q->save();
+         }*/
+        $pageParams = CommonFn::getPageParams();
+        $cursor = Question::model()->findAll();
+        $rows = CommonFn::getRowsFromCursor($cursor);
+        $parsedRows = Question::model()->parse($rows);
+        $total = $cursor->count();
+        if ($total > 10) {
+            $offset = rand(0,$total-10);
+            $limit = 10;
+            $pageParams['offset'] = $offset;
+            $pageParams['limit'] = $limit;
+            $criteria = new EMongoCriteria($pageParams);
+            $cursor = Question::model()->findAll($criteria);
+            $rows = CommonFn::getRowsFromCursor($cursor);
+            $parsedRows = Question::model()->parse($rows);
+            $total = $cursor->count();
+        }
+        echo CommonFn::composeDatagridData($parsedRows, $total);
+    }
+
+    public function actionResult()
+    {
+        $user_id = Yii::app()->request->getParam('id','');
+        $score = Yii::app()->request->getParam('score','');
+        $jgemp = JGEmploye::get(new MongoId($user_id));
+        if (!empty($jgemp)) {
+            $jgemp->score = $score;
+            $jgemp->degree -= 1;
+            $jgemp->save();
+        }
+        CommonFn::requestAjax(true, '答题完毕', array());
+    }
+}

+ 4 - 0
www/protected/modules/j/models/JGEmploye.php

@@ -31,6 +31,8 @@ class JGEmploye extends MongoAr
     public $readme;//自述
     public $store_id;//门店id
     public $desc;//备注
+    public $score = 0;//积分
+    public $degree = 1;//次数
 
     public static $work_type_options = array(
         1 => array('name' => '钟点工'),
@@ -116,6 +118,8 @@ class JGEmploye extends MongoAr
         //$newRow['skill_str'] = self::$skill_options[intval($newRow['skill'])]['name'];
 
         $newRow['star'] = CommonFn::get_val_if_isset($row,'star','');
+        $newRow['degree'] = CommonFn::get_val_if_isset($row,'degree','');
+        $newRow['score'] = CommonFn::get_val_if_isset($row,'score','');
         $newRow['test'] = CommonFn::get_val_if_isset($row,'test','');
         $newRow['test_time'] = CommonFn::get_val_if_isset($row,'test_time','');
         $newRow['cret'] = CommonFn::get_val_if_isset($row,'cret','');

+ 65 - 0
www/protected/modules/j/models/Question.php

@@ -0,0 +1,65 @@
+<?php
+
+/**
+ * Created by north.Deng's MAC
+ * User: north.Deng
+ * Date: 2018/5/4
+ * Time: 上午10:10
+ * description :
+ */
+class Question extends MongoAr
+{
+    public $_id;
+    public $title;//标题
+    public $question = array();
+    public $status = 1;// 0 不使用 1使用
+
+
+
+    public function __construct($scenario='insert'){
+        $this->setMongoDBComponent(Yii::app()->getComponent('mongodb_o2o'));
+        parent::__construct($scenario);
+    }
+
+
+    public static function model($className=__CLASS__)
+    {
+        return parent::model($className);
+    }
+
+    public function getCollectionName()
+    {
+        return 'j_question';
+    }
+
+    public static function get($_id) {
+        if(CommonFn::isMongoId($_id)){
+            $criteria = new EMongoCriteria();
+            $criteria->_id('==', $_id);
+            $model = self::model()->find($criteria);
+            return $model;
+        }else{
+            return false;
+        }
+    }
+
+
+
+
+    public function parseRow($row,$output=array()){
+
+        $newRow = array();
+        $newRow['id'] = (string)$row['_id'];
+        $newRow['title'] = (string)$row['title'];
+        $newRow['question'] = CommonFn::get_val_if_isset($row,'question','');
+
+        if(APPLICATION=='admin'){
+            $newRow['action_user'] = CommonFn::get_val_if_isset($row,'action_user',"");
+            $newRow['action_time'] = CommonFn::get_val_if_isset($row,'action_time',"");
+            $newRow['action_log'] = CommonFn::get_val_if_isset($row,'action_log',"");
+
+        }
+        return $this->output($newRow,$output);
+    }
+
+}

+ 551 - 0
www/protected/views/question/index.php

@@ -0,0 +1,551 @@
+<style>
+    .f_label {width: 90px;}
+    .accordion-body {padding: 0;}
+    #view_select_position {
+        display:inline-block;
+        padding:1px 4px 1px 4px;
+        border:1px solid #999999;
+        text-decoration:none;
+        color:#333333;
+    }
+</style>
+
+<div id="main">
+    <div region="west" border="false" id="west_panel">
+        <table id="dg_content"></table>
+        <div id="tb_content">
+
+
+
+            <div style="margin: 3px 2px;padding:5px;border: 1px solid #95B8E7;">
+                <a href="#" class='easyui-linkbutton' plain="true" iconCls="icon-add" onclick="add_content();return false;">新增题目</a>
+            </div>
+        </div>
+    </div>
+
+    <div id="acc_container" class="accordion" region="center">
+        <div region="center" title="雇员信息" data-options="iconCls:'icon-save',selected:true">
+            <div class="easyui-layout detail_layout">
+                <form id="content_form" method="post">
+                <div data-options="region:'center'" class="detail_center">
+                    <div class="detail_main">
+
+                            <ul>
+                                <li class="f_item">
+                                    <div class="box">
+                                        <div class="f_label">
+                                            <span>ID: </span>
+                                        </div>
+                                        <div class="box_flex f_content">
+                                            <input type="hidden" name="id" id="id" value='' />
+                                            <span id="id_str"></span>
+                                        </div>
+                                    </div>
+                                </li>
+                                <ul>
+                                    <li class="f_item">
+                                        <div class="box">
+                                            <div class="f_label">
+                                                <span>标题: </span>
+                                            </div>
+                                            <div class="box_flex f_content">
+                                                <input id="edit_title" name="title" style="width: 250px;"  />
+                                            </div>
+                                        </div>
+                                    </li>
+                                    <li class="f_item">
+                                        <div class="box">
+                                            <div class="f_label">
+                                                <span>选项A: </span>
+                                            </div>
+                                            <div class="box_flex f_content">
+                                                <input id="edit_questions0" name="questions[0]" style="width: 250px;"  />
+                                            </div>
+                                        </div>
+                                    </li>
+                                    <li class="f_item">
+                                        <div class="box">
+                                            <div class="f_label">
+                                                <span>选项B: </span>
+                                            </div>
+                                            <div class="box_flex f_content">
+                                                <input id="edit_questions1" name="questions[1]" style="width: 250px;"  />
+                                            </div>
+                                        </div>
+                                    </li>
+                                    <li class="f_item">
+                                        <div class="box">
+                                            <div class="f_label">
+                                                <span>选项C: </span>
+                                            </div>
+                                            <div class="box_flex f_content">
+                                                <input id="edit_questions2" name="questions[2]" style="width: 250px;"  />
+                                            </div>
+                                        </div>
+                                    </li>
+                                    <li class="f_item">
+                                        <div class="box">
+                                            <div class="f_label">
+                                                <span>选项D: </span>
+                                            </div>
+                                            <div class="box_flex f_content">
+                                                <input id="edit_questions3" name="questions[3]" style="width: 250px;"  />
+                                            </div>
+                                        </div>
+                                    </li>
+
+                                    <li class="f_item">
+                                        <div class="box">
+                                            <div class="f_label">
+                                                <span>答案: </span>
+                                            </div>
+                                            <div class="box_flex f_content">
+                                                <input id="edit_result" name="questions[4]" style="width: 250px;" data-options="valueField:'id', textField:'text' " />
+                                            </div>
+                                        </div>
+                                    </li>
+
+
+
+                                </ul>
+                            </ul>
+                        </form>
+                    </div>
+                    <div data-options="region:'south'" class="detail_south">
+                        <div class="detail_toolbar">
+                            <a href="#" class="easyui-linkbutton set_button" iconCls="icon-save" onclick="save_content();return false;">保存</a>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+
+
+
+
+</div>
+<div style="display: none;">
+    <div id="add_dialog" style="padding: 15px 0;">
+
+        <form id="add_form" method="post">
+
+            <ul>
+                <li class="f_item">
+                    <div class="box">
+                        <div class="f_label">
+                            <span>标题: </span>
+                        </div>
+                        <div class="box_flex f_content">
+                            <input id="title" name="title" style="width: 250px;"  />
+                        </div>
+                    </div>
+                </li>
+                <li class="f_item">
+                    <div class="box">
+                        <div class="f_label">
+                            <span>选项A: </span>
+                        </div>
+                        <div class="box_flex f_content">
+                            <input id="questions" name="questions[0]" style="width: 250px;"  />
+                        </div>
+                    </div>
+                </li>
+                <li class="f_item">
+                    <div class="box">
+                        <div class="f_label">
+                            <span>选项B: </span>
+                        </div>
+                        <div class="box_flex f_content">
+                            <input id="questions1" name="questions[1]" style="width: 250px;"  />
+                        </div>
+                    </div>
+                </li>
+                <li class="f_item">
+                    <div class="box">
+                        <div class="f_label">
+                            <span>选项C: </span>
+                        </div>
+                        <div class="box_flex f_content">
+                            <input id="questions2" name="questions[2]" style="width: 250px;"  />
+                        </div>
+                    </div>
+                </li>
+                <li class="f_item">
+                    <div class="box">
+                        <div class="f_label">
+                            <span>选项D: </span>
+                        </div>
+                        <div class="box_flex f_content">
+                            <input id="questions3" name="questions[3]" style="width: 250px;"  />
+                        </div>
+                    </div>
+                </li>
+                <li class="f_item">
+                    <div class="box">
+                        <div class="f_label">
+                            <span>答案: </span>
+                        </div>
+                        <div class="box_flex f_content">
+                            <input id="result" name="questions[4]" style="width: 250px;" data-options="valueField:'id', textField:'text' " />
+                        </div>
+                    </div>
+                </li>
+
+
+
+            </ul>
+
+
+        </form>
+    </div>
+
+</div>
+<div style="display:none;">
+    <div id="refund_tip_dialog" style="padding: 30px 0;">
+        <div style="text-align:center;"><span id="refund_tip"></span></div>
+    </div>
+</div>
+<script language="javascript" type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.js"></script>
+<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/js/coolautosuggest/jquery.coolautosuggest.css" />
+<script type="text/javascript">
+  var jq_dg_content = $('#dg_content');
+  var jq_content_form = $('#content_form');
+  var jq_filter_status = $('#filter_status');
+  var jq_setStatus_add = $('#setStatus_add');
+  var module_router = site_root + '/index.php?r=Question';
+  var jq_setStatus = $('#setStatus');
+  var jq_addAuth = $('#addAuth');
+  var jq_editAuth = $('#Editauth');
+  var w_width = $(window).width();
+  var w_height = $(window).height();
+  var jq_ss = $('#ss');
+  var jq_add_dialog = $('#add_dialog');
+  var jq_add_form = $('#add_form');
+
+  var jq_set_precedence = $('#set_precedence');
+  var tmp = 1;
+
+  var jq_acc = $('#acc_container');
+
+
+  $(function(){
+
+
+
+
+
+    $('#pre_production_date').datetimebox({
+      required: false,
+      showSeconds:false,
+      //buttons:buttons_add,
+      // onSelect: function(date){
+      //     var currentDate = new Date();
+      //     $('#order_time_str_add').val(date.getTime()/1000);
+      // }
+    });
+    $('#production_date').datetimebox({
+      required: false,
+      showSeconds:false,
+      //buttons:buttons_add,
+      // onSelect: function(date){
+      //     var currentDate = new Date();
+      //     $('#order_time_str_add').val(date.getTime()/1000);
+      // }
+    });
+
+
+
+
+
+    var buttons = $.extend([], $.fn.datebox.defaults.buttons);
+    buttons[0].text = '确定';
+
+
+    jq_acc.accordion({
+      height: w_height - 18,
+      onSelect: function(title) {
+
+      }
+    });
+
+
+
+
+
+
+
+
+
+    var p_width = parseInt(w_width / 2);
+    if (p_width < 520){
+      p_width = 520;
+    }
+    var d_width = p_width - 10;
+    $('#west_panel').css({width : p_width});
+    $('#main').css({width: w_width - 25, height: w_height - 18}).layout();
+
+    jq_ss.searchbox({
+      width: 130,
+      searcher:function(value){
+        search_content();
+      },
+      prompt: '请输入关键字'
+    });
+
+    jq_add_dialog.dialog({
+      title: '新建题目',
+      width: 500,
+      height: 500,
+      closed: true,
+      modal: true,
+      buttons:[{
+        text: '确认',
+        iconCls: 'icon-ok',
+        handler: function(){
+          // ------ 数据完整性检查 ------
+          var check = checkAddForm();
+          if (!check) {
+            return false;
+          } else {
+            $.messager.progress();
+            jq_add_form.submit();
+          }
+        }
+      },{
+        text: '取消',
+        iconCls: 'icon-cancel',
+        handler: function(){
+          jq_add_dialog.dialog('close');
+        }
+      }],
+      onOpen:function(){
+        jq_add_form.form('clear');
+        jq_add_form.form('load', {});
+        jq_set_precedence.combobox('setValue', 0);
+        $('#result').combobox({
+          editable: false,
+          select: 1,
+          data:
+            [{
+              "id":'A',
+              "text":"A",
+              "selected":true
+            },{
+              "id":'B',
+              "text":"B"
+            },{
+              "id":'C',
+              "text":"C"
+            },{
+              "id":'D',
+              "text":"D"
+            }]
+          ,
+        });
+
+      }
+    });
+    $('#edit_result').combobox({
+      editable: false,
+      select: 1,
+      data:
+        [{
+          "id":'A',
+          "text":"A"
+        },{
+          "id":'B',
+          "text":"B"
+        },{
+          "id":'C',
+          "text":"C"
+        },{
+          "id":'D',
+          "text":"D"
+        }]
+      ,
+    });
+    jq_dg_content.datagrid({
+      url: module_router + '/list',
+      title: '题目列表',
+      width: d_width,
+      height: w_height - 18,
+      fitColumns: true,
+      autoRowHeight: true,
+      striped: true,
+      toolbar: '#tb_content',
+      singleSelect: true,
+      selectOnCheck: false,
+      checkOnSelect: false,
+      rowStyler: function(index,row){
+        if (row.status==1){
+          //return 'color:red;';
+        }else if(row.status==-3){
+          return 'color:green;';
+        }
+      },
+      pagination: true,
+      pageList: [20, 30, 50],
+      pageSize: 20,
+      nowrap: false,
+      idField: 'id',
+      sortName: 'order_time',
+      sortOrder: 'desc',
+      queryParams: get_param_obj(),
+      frozenColumns:[[
+        {field:'ck',checkbox:true}
+      ]],
+      columns:[[
+        {field:'id', title:'id', hidden:true},
+        {field:'title', title:'题目标题', width:160,sortable:false}/*,
+        {
+          field: 'del', title: '删除', width: 40, sortable: false,
+          formatter: function (value, row, index) {
+            console.log(row)
+            return '<a href="#" onclick="del(\''+row.id+'\');return false;" > 删除题目</a>';
+          }
+        }*/
+      ]],
+
+      onSelect: function(index, row){
+       console.log(row)
+        $('#id_str').html(row.id);
+        $('#id').val(row.id);
+        $('#edit_title').val(row.title);
+
+        for (var i in row.question.question) {
+          var id_name = '#edit_questions' + i;
+          console.log(row.question.question[i])
+          $(id_name).val(row.question.question[i]);
+        }
+        $('#edit_result').combobox('select',row.question.result);
+
+      },
+      onLoadSuccess : function () {
+        $('#id').html('');
+        $('#id_str').html('');
+        $('#edit_title').val('');
+        for (var i in [0,1,2,3]) {
+          var id_name = '#edit_questions' + i;
+          $(id_name).val('');
+        }
+        $('#edit_result').combobox('select',' ');
+      }
+
+    });
+
+
+
+
+
+
+    jq_content_form.form({
+      url: module_router + '/edit',
+      onSubmit: function(param){
+        var isValid = $(this).form('validate');
+        if (!isValid){
+          $.messager.progress('close');
+        }
+        return isValid;
+      },
+      success: function(res){
+        $.messager.progress('close');
+        var res = JSON.parse(res);
+
+        if (res.success){
+          jq_dg_content.datagrid('reload');
+        }
+        if(res.success){
+          $.messager.show({
+            title: '提示',
+            msg: '保存成功',
+            timeout: 3500,
+            showType: 'slide'
+          });
+
+          $('#technician_id').val(0);
+        }else{
+          $.messager.show({
+            title: '提示',
+            msg: res.message,
+            timeout: 3500,
+            showType: 'slide'
+          });
+        }
+      }
+    });
+
+    jq_add_form.form({
+      url : module_router + '/add',
+      //url :'index.php?r=moonclub/xOrder/add',
+      onSubmit : function (param) {
+        var isValid = $(this).form('validate');
+        if (!isValid){
+          $.messager.progress('close');
+        }
+        return isValid;
+      },
+      success : function (res) {
+        $.messager.progress('close');
+        var res = JSON.parse(res);
+
+        if (res.success) {
+          $.messager.show({
+            title : '提示',
+            msg : '保存成功',
+            timeout : 3500,
+            showType : 'slide'
+          });
+          jq_add_dialog.dialog('close');
+          jq_dg_content.datagrid('reload');
+        } else {
+          $.messager.show({
+            title : '提示',
+            msg : res.message,
+            timeout : 3500,
+            showType : 'slide'
+          });
+        }
+      }
+    });
+  });
+
+  function search_content(){
+
+    var filter_status = jq_filter_status.combobox('getValue');
+
+    jq_dg_content.datagrid({
+      pageNum: 1,
+      queryParams: {
+        status : filter_status
+      }
+    });
+
+  };
+
+  function checkAddForm () {
+
+    return true;
+  }
+
+  function add_content(){
+    jq_add_dialog.dialog('open');
+  }
+  function   formatDate(now){
+    var   year=now.getFullYear();
+    var   month=now.getMonth()+1;
+    var   date=now.getDate();
+    var  hour = now.getHours();
+    var  minute = now.getMinutes();
+    return   year+"-"+month+"-"+date+" "+hour+":"+minute;
+  }
+  function save_content(){
+    $.messager.progress();
+    jq_content_form.submit();
+  }
+  function del(id) {
+    alert(id);
+  }
+
+
+</script>