You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
zhishifufei_php/application/wap/controller/Clearance.php

269 lines
10 KiB

<?php
// +----------------------------------------------------------------------
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
// +----------------------------------------------------------------------
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
// +----------------------------------------------------------------------
namespace app\wap\controller;
use app\wap\model\user\User;
use service\JsonService;
use think\cache\driver\Redis;
use think\Cookie;
use think\exception\HttpException;
use think\response\Json;
use think\Session;
use think\Url;
use think\Db;
use think\Request;
use think\Log;
use app\wap\model\wap\Clearance as ClearanceModel;
use app\wap\model\wap\ClearanceSubject;
use app\wap\model\wap\UserStudy;
use app\wap\model\wap\ClearanceSubjectChapter;
use app\wap\model\wap\UserClearanceDetail;
use app\wap\model\wap\UserClearance;
use app\wap\model\special\SpecialSubject;
use app\wap\model\activity\EventRegistration;
use app\wap\model\special\Special as SpecialModel;
use app\wap\model\topic\TestPaper;
use service\GroupDataService;
use service\ClearanceService;
/**过关
* Class Special
* @package app\wap\controller
*/
class Clearance extends AuthController
{
/**
* 白名单
* */
public static function WhiteList()
{
return [
'grade_index'
];
}
/**
* 学习中心首页
* [grade_index description]
* @param integer $subject_id [description]
* @param string $city [description]
* @return [type] [description]
*/
public function grade_index($subject_id = 0, $city = "")
{
//背诵
$recite = ClearanceModel::where('type',1)->where('status',1)->order('sort DESC,id desc')->select();
//刷题
$brush_questions = ClearanceModel::where('type',2)->where('status',1)->order('sort DESC,id desc')->select();
$activity = EventRegistration::eventRegistrationList(1, 4, $city, $subject_id, 0);
$uid = $this->uid;
$where = [
'grade_id' => 1,
'subject_id' => $subject_id,
'search' => '',
'page' => 1,
'limit' => 4,
'type' => 0,
'special_type' => 3,
'is_member' => 0,
'uid' => $uid,
];
$video = SpecialModel::getSpecialList($where);
$where['special_type'] = 4;
$live = SpecialModel::getSpecialList($where);
$sql = "SELECT rank,days FROM (SELECT @rank:=@rank+1 as rank, user_id, days,cate_id FROM tc_user_clearance, (SELECT @rank:=0) r ORDER BY days DESC ) t WHERE user_id = ".$uid ." and cate_id = ".$subject_id;
$userClearance = Db::query($sql);
$sql = "SELECT rank,recite_num FROM (SELECT @rank:=@rank+1 as rank, user_id, recite_num,cate_id FROM tc_user_clearance, (SELECT @rank:=0) r ORDER BY recite_num DESC ) t WHERE user_id = ".$uid ." and cate_id = ".$subject_id;
$userClearance1 = Db::query($sql);
$sql = "SELECT rank,accuracy FROM (SELECT @rank:=@rank+1 as rank, user_id, accuracy,cate_id FROM tc_user_clearance, (SELECT @rank:=0) r ORDER BY accuracy DESC ) t WHERE user_id = ".$uid ." and cate_id = ".$subject_id;
$userClearance2 = Db::query($sql);
//用户进入学习中心展示哪个科目问题处理
if (!$subject_id) {
$userStudy = UserStudy::where('user_id', $this->uid)->find();
if ($userStudy) {
$subject_id = $userStudy['cate_id'];
} else {
$specialSubject = SpecialSubject::where('is_show', 1)->where('is_del', 0)->find();
$subject_id = $specialSubject['id'];
}
}
$specialSubject = SpecialSubject::where('id', $subject_id)->find();
$test_paper = TestPaper::where('id',$specialSubject['exam_id'])->field('id,title as name')->select();
// var_dump($res);
// var_dump($userClearance);
// exit();
$date = date("Y-m-d");
$recite_num = UserClearanceDetail::where('user_id', $this->uid)->where('type', 1)->group('section_id')->count();
$brush_question_num = UserClearanceDetail::where('user_id', $this->uid)->where('type', 2)->group('item_id')->count();
$total_num = $specialSubject['recite_num'] + $specialSubject['brush_question_num'];
return JsonService::successful('ok', [
'exam' => [
'grade_id' => $specialSubject['grade_id'],
'subject_id' => $subject_id,
'name' => $specialSubject['name'],
'date' => date("Y-m-d", $specialSubject['exam_time'] ?? 0),
'distance_exam_day' => ceil((($specialSubject['exam_time'] ?? 0) - time()) / 86400),
],
'user_study' => [
'days' => $userClearance[0]['days'] ?? 0,
'rank' => $userClearance[0]['rank'] ?? 0,
],
'user_recite' => [
'points' => $userClearance1[0]['recite_num'] ?? 0,
'rank' => $userClearance1[0]['rank'] ?? 0,
],
'user_brush_questions' => [
'accuracy' => ($userClearance2[0]['accuracy'] ?? 0)."%",
'rank' => $userClearance2[0]['rank'] ?? 0,
],
'user_clock_in' => [
'progress' => $total_num ? round(($recite_num + $brush_question_num) / $total_num ) : 0,
'list' => $this->dealClockInRecord("", 1, 2),
],
'exam_list' => $test_paper,
'banner' => GroupDataService::getData('mxtk_banner') ?: [],
'recite' => $recite,
'brush_questions' => $brush_questions,
'video' => $video,
'live' => $live,
'offline_courses' => $activity,
]);
}
/**
* 背诵过关
* [clearanceSubject description]
* @return [type] [description]
*/
public function clearanceSubject($recite_id = 0){
$recite_subject_list = ClearanceSubject::where('status',1)->where('recite_id',$recite_id)->order('sort DESC,id desc')->select();
return JsonService::successful('ok', $recite_subject_list);
}
/**
* 背诵章节
* [clearanceSubjectChapter description]
* @param integer $recite_subject_id [description]
* @return [type] [description]
*/
public function clearanceSubjectChapter($recite_subject_id = 0){
$chapters = ClearanceSubjectChapter::where('status',1)->where('recite_subject_id',$recite_subject_id)->order('sort DESC,id desc')->select();
$chapters = subTree($chapters->toArray());
return JsonService::successful('ok', $chapters);
}
/**
* 背诵接口
* [recite description]
* @param integer $chapter_id [description]
* @param integer $section_id [description]
* @return [type] [description]
*/
public function recite($chapter_id = 0, $section_id = 0){
//var_dump($this->uid);exit();
$info = ClearanceSubjectChapter::where('id', $section_id)->where('pid', $chapter_id)->find();
if (!$info) {
return JsonService::fail('背诵内容不存在');
}
$recite_subject = ClearanceSubject::where('id', $info['recite_subject_id'])->find();
if (!$recite_subject) {
return JsonService::fail('背诵内容不存在');
}
$recite = ClearanceModel::where('id', $recite_subject['recite_id'])->find();
if (!$recite) {
return JsonService::fail('背诵内容不存在');
}
ClearanceService::clockIn($this->uid, $recite['subject_id'], 1, $recite['id'], $recite_subject['id'], $chapter_id, $section_id);
return JsonService::successful('ok');
}
protected function dealClockInRecord($date = "", $page = 1, $limit = 10){
$date = $date ? $date : date("Y-m-d");
$list = UserClearanceDetail::where('user_id', $this->uid)->where('date', $date)->order("id desc")->page($page, $limit)->select();
foreach ($list as &$value) {
if ($value['type'] == 1) {
$chapter = ClearanceSubjectChapter::where('id',$value['chapter_id'])->find();
$section = ClearanceSubjectChapter::where('id',$value['section_id'])->find();
$value['name'] = ($chapter['name'] ?? "")." ".($section['name'] ?? "");
} else {
$test_paper = TestPaper::where('id',$value['item_id'])->field('id,title as name')->find();
$value['name'] = $test_paper['name'] ?? "";
$hour = round($value['use_time'] / 3600);
$result = $value['use_time'] % 3600;
$minute = round($result / 60);
$value['use_time'] = $hour."小时".$minute."";
}
}
return $list;
}
public function getMonthRecord($month){
$start_time = strtotime("{$month}-01"); // 月份的开始时间
$end_time = strtotime("+1 month", $start_time) - 1; // 月份的结束时间
$list = UserClearanceDetail::where('user_id', $this->uid)->where('add_time', ">=", $start_time)->where('add_time', "<=", $end_time)->field('date')->group('date')->select();
return JsonService::successful('ok', $list);
}
/**
* 用户打卡记录
* [clockInRecord description]
* @return [type] [description]
*/
public function clockInRecord($date = "", $page = 1, $limit = 10){
$list = $this->dealClockInRecord($date, $page, $limit);
return JsonService::successful('ok', $list);
}
/**
* 学习项目切换
* [study description]
* @param integer $cate_id [description]
* @return [type] [description]
*/
public function study($subject_id = 0){
$info = UserStudy::where('user_id', $this->uid)->find();
if ($info) {
UserStudy::where('id', $info['id'])->update(['cate_id' => $subject_id, 'update_time' => time()]);
return JsonService::successful('ok');
}
UserStudy::create(['user_id' => $this->uid, 'cate_id' => $subject_id, 'add_time' => time(), 'update_time' => time()]);
return JsonService::successful('ok');
}
}