123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2021/11/23 0023
- * Time: 15:20
- */
- class SGeneralProductSetting extends MyActiveRecord
- {
- public static function model($className = __CLASS__)
- {
- return parent::model($className);
- }
- public function tableName()
- {
- return 'general_product_setting';
- }
- /**
- * 产品列表
- * @param array $condition
- * @param array $orderBy
- * @param int $pageSize
- * @return array
- * @throws CDbException
- * @throws CException
- */
- public function getList($condition = array(), $orderBy = array("p.create_time desc"), $pageSize = 10)
- {
- $condition = $this->condition($condition);
- $orderBy = $this->orderBy($orderBy);
- $con = $this->getDbConnection();
- $handle = $con->createCommand("
- select p.gp_id,p.name,p.reset_times,g.gp_group_id,g.setting,g.status,g.repair_info,c.grade,c.class_id,c.class_name,p.learn_tube_reset_count,p.learn_tube_reset_time,p.create_time from general_product p join general_product_setting g on g.gp_group_id=p.gp_group_id join class c on p.class_id= c.class_id
- {$condition}
- group by p.gp_id
- {$orderBy}
- ")->query();
- $rs = $this->paging($this->getDbConnection(), $handle, $pageSize);
- if ($rs['rs']) {
- foreach ($rs['rs'] as $k => $v) {
- $setting = json_decode($v['setting'],true);
- $rs['rs'][$k]['totalCount'] = 0;
- $rs['rs'][$k]['pdfCount'] = 0;
- $rs['rs'][$k]['isDown'] = 0;
- $rs['rs'][$k]['downTime'] = '';
- $rs['rs'][$k]['createType'] = isset($setting['create_type'])?$setting['create_type']:0;
- $gp_id = $v['gp_id'];
- $sql = "select COUNT(distinct s.student_id) AS totalCount,SUM(CASE WHEN s.is_create_pdf = 1 THEN 1 ELSE 0 END) AS pdfCount from general_product_student s inner join student_info i on s.student_id=i.student_id where s.gp_id = '{$gp_id}'";
- $countArr = $con->createCommand($sql)->queryRow();
- if ($countArr) {
- $rs['rs'][$k]['totalCount'] = isset($countArr['totalCount']) ? $countArr['totalCount'] : 0;
- $rs['rs'][$k]['pdfCount'] = isset($countArr['pdfCount']) ? $countArr['pdfCount'] : 0;
- }
- $sql = "select download_time from general_product_student where gp_id = '{$gp_id}' and is_download = 1 order by download_time desc limit 1";
- $isDownArr = $con->createCommand($sql)->queryRow();
- if ($isDownArr) {
- $rs['rs'][$k]['isDown'] = 1;
- $rs['rs'][$k]['downTime'] = isset($isDownArr['download_time']) ? date("Y-m-d H:i", $isDownArr['download_time']) : '';
- }
- }
- }
- return $rs;
- }
- public function paging($conn, $handle, $pageSize){
- $pager = new CPagination($handle->rowCount, $pageSize);
- $handle = $conn->createCommand($handle->queryString." limit :offset, :limit");
- $handle->bindValue(":offset", $pager->currentPage * $pager->pageSize);
- $handle->bindValue(":limit", $pager->pageSize);
- $rs = $handle->queryAll();
- return array("rs" => $rs, "pager" => $pager);
- }
- public function condition($condition = array()){
- return $condition ? " where ".implode(" and ", $condition) : "";
- }
- public function orderBy($orderBy = array()){
- return $orderBy ? " order by ".implode(",", $orderBy) : "";
- }
- /**
- * 专题超出次数的班级
- * @param $gpId
- * @param $productType
- * @param $classIds
- * @return array
- * @throws CDbException
- * @throws CException
- */
- public function classHistory($gpId, $productType,$classIds){
- $list = array();
- $rs = $this->getDbConnection()->createCommand("select g.setting,c.class_id,c.class_name from general_product p join general_product_setting g
- on g.gp_group_id=p.gp_group_id join class c on p.class_id= c.class_id where g.product_type={$productType} and p.class_id in ($classIds)")->queryAll();
- if($rs){
- foreach ($rs as $item){
- $setting = json_decode($item['setting'],true);
- $specialId = isset($setting['pc_ids'][0]['pc_id']) ? $setting['pc_ids'][0]['pc_id'] : 0;
- if($specialId && $gpId==$specialId){
- $list[$item['class_id']]['class_name'] = $item['class_name'];
- if(isset($list[$item['class_id']]['special_count'])){
- $list[$item['class_id']]['special_count']++;
- }else{
- $list[$item['class_id']]['special_count'] = 1;
- }
- }
- }
- }
- $limitClass = array();
- if($list){
- foreach ($list as $key=>$item){
- if($item['special_count']>=3){
- array_push($limitClass,$item['class_name']);
- }
- }
- }
- return $limitClass;
- }
- //校本纠错本班级列表
- public function getCorrectClassList($gpGroupId){
- $conn = $this->getDbConnection();
- $sql="select gp_id,gp.class_id,c.class_name,gp.name,create_time,c.grade from general_product gp left join class c on c.class_id=gp.class_id where gp_group_id='{$gpGroupId}'";
- $result=$conn->createCommand($sql)->queryAll();
- return $result;
- }
- //纠错本学生
- public function getCorrectStudent($gpId){
- $conn = $this->getDbConnection();
- $sql="select gp_id,student_id,is_create_pdf,download_time,is_download from general_product_student where gp_id='{$gpId}'";
- $result=$conn->createCommand($sql)->queryAll();
- return $result;
- }
- //读取纠错本配置信息
- public function getGeneralSetting($gpGroupId){
- $conn = $this->getDbConnection();
- $sql="select setting from general_product_setting where gp_group_id='{$gpGroupId}'";
- $result=$conn->createCommand($sql)->queryRow();
- if($result){
- return $result['setting'];
- }else{
- return null;
- }
- }
- }
|