SnapshotModel.class.php 2.76 KB
<?php
/**
 * 考试-试卷快照表
 * @author: houyingcai
 * @email:  594609175@qq.com
 * @date :  2017-05-19 18:01:50
 */

namespace Common\Model;

class SnapshotModel extends AbstractModel
{

    /**
     * 构造方法
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 获取试题快照列表
     *
     * @author  houyingcai
     * @param array $conds 查询条件参数列表
     * @param array $page_option 分页参数
     * @param array $order_option 排序参数
     * @param string $fields 返回字段
     *
     * @return array|bool
     */
    public function conds_snapshot_list($conds, $page_option = null, $order_option = [], $fields = '*')
    {

        $params = [];
        // 条件
        $wheres = [];
        if (!$this->_parse_where($wheres, $params, $conds)) {
            return false;
        }
        $snapModel = new StatisticsModel();
        $table = $snapModel->get_tname();
        // 企业标记
        $wheres[] = 'a.`domain`=?';
        $params[] = QY_DOMAIN;
        // 状态条件
        $wheres[] = 'a.`status`<?';
        $params[] = $this->get_st_delete();
        // 排序
        $orderby = '';
        if (!$this->_order_by($orderby, $order_option)) {
            return false;
        }
        // 分页参数
        $limit = '';
        if (!$this->_limit($limit, $page_option)) {

            return false;
        }

        $sql = "SELECT  $fields, CASE WHEN b.answer_total>0 THEN b.right_num/b.answer_total ELSE 'false' END as probability,CASE WHEN  a.et_type=" . self::TOPIC_TYPE_VOICE . " or a.et_type=" . self::TOPIC_TYPE_QUESTION . " THEN 1 ELSE 0 END as ea_sort  FROM  __TABLE__ a LEFT JOIN  $table b on a.es_id =b.esr_id and  a.ep_id =b.ep_id  WHERE " . implode(' AND ',
                $wheres) . " {$orderby} {$limit}";
        return $this->_m->fetch_array($sql, $params);
    }

    /**
     * 获取试题快照总数
     *
     * @author  caijainhua
     * @param array $conds 查询条件参数列表
     *
     * @return int
     */
    public function conds_snapshot_count($conds)
    {
        $params = [];
        // 条件
        $wheres = [];
        if (!$this->_parse_where($wheres, $params, $conds)) {
            return false;
        }
        // 企业标记
        $wheres[] = 'a.`domain`=?';
        $params[] = QY_DOMAIN;
        // 状态条件
        $wheres[] = 'a.`status`<?';
        $params[] = $this->get_st_delete();
        $statistics = new StatisticsModel();
        $table = $statistics->get_tname();
        $sql = "SELECT  count(*) as total FROM  __TABLE__ a  LEFT JOIN  $table  b ON a.es_id =b.esr_id and  a.ep_id = b.ep_id   WHERE " . implode(' AND ',
                $wheres);

        $rel = $this->_m->result($sql, $params);
        return $rel;
    }

}