作者 sgj
1 个管道 的构建 失败 耗费 9 秒

新闻机制

... ... @@ -28,4 +28,14 @@ class ActivityNews extends Model
$list=$this->where($map)->select()->order('weight desc')->toArray();
return $list;
}
public function getInfo($id){
$info=$this::find($id);
$info['create_time']=date('Y-m-d',$info['create_time']);
$info['thumbnail']=cmf_get_image_url($info['thumbnail']);
return $info;
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* auther: sgj
* Date: 2020/9/28
* Time: 14:59
*/
namespace api\common\model;
use think\Model;
class ClassModel extends Model
{
protected $name = 'class';
public function getClassList(){
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* auther: sgj
* Date: 2020/9/28
* Time: 17:13
*/
namespace api\common\model;
use think\Model;
class ClassQuestionModel extends Model
{
protected $name = 'class_question';
/**
* 获取班级问题
* @param $class_id
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getClassQuesion($class_id){
// $info[]='A.可能第';
// $info[]='A.可能第';
// $info[]='A.可能第';
// $info[]='A.可能第';
//dump(json_encode($info,true));
$map['class_id']=$class_id;
$list=$this->where($map)->select();
foreach ($list as $k=>$v) {
$info[$k]['options_array']=json_decode($v['options'],true);
$info[$k]['title']=$v['title'];
$info[$k]['answer']=$v['answer'];
$info[$k]['id']=$v['id'];
}
return $info;
}
}
\ No newline at end of file
... ...
... ... @@ -32,4 +32,6 @@ class NewsTypeMode extends Model
}
\ No newline at end of file
... ...
... ... @@ -9,10 +9,15 @@
namespace api\index\controller;
use api\common\model\ActivityNews;
use api\common\model\ClassModel;
use api\common\model\ClassQuestionModel;
use api\common\model\LevelModel;
use api\common\model\NewsTypeMode;
use api\common\model\TeamModel;
use api\common\model\VolunteerModel;
use cmf\controller\RestBaseController;
use think\console\output\formatter\Style;
/**
* @title 志愿者二开接口
... ... @@ -61,6 +66,247 @@ class SecondController extends RestBaseController
$this->success('',$return);
}
/**
* @title 志愿动态栏目类型
* @description 志愿动态栏目类型
* @author sgj
* @url /index/second/getNewsType
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
*
* @return id:栏目id
* @return name:名称
* @throws
*/
public function getNewsType(){
$newType=new NewsTypeMode();
$list=$newType->getNewsType();
foreach ($list as $k=>$v){
$return[$k]['id']=$v['id'];
$return[$k]['name']=$v['type_name'];
}
$this->success('',$return);
}
/**
* @title 获取志愿动态列表
* @description 获取志愿动态列表
* @author sgj
* @url /index/second/getNewsList
* @method GET
*
* @param name:type_id type:int require:1 other: desc:类型id
* @param name:page type:int require:1 other: desc:页数
*
* @return id:栏目type_id
* @return name:名称
* @return create_time:创建时间
* @return thumbnail:封面图
* @throws
*/
public function getNewsList(){
$type_id=input('type_id',1);
$news=new ActivityNews();
$map['activity_type']=$type_id;
$list=$news
->where($map)
->field('id,activity_name,thumbnail,create_time')
->paginate(10,true);
foreach ($list as $k=>$v) {
$list[$k]['create_time']=date('Y-m-d',$v['create_time']);
$list[$k]['thumbnail']=cmf_get_image_url($v['thumbnail']);
}
$this->success('',$list);
}
/**
* @title 获取志愿动态详情
* @description 获取志愿动态详情
* @author sgj
* @url /index/second/getNewsInfo
* @method GET
*
* @param name:id type:int require:1 other: desc:文章id
*
* @return id:文章id
* @return activity_name:文章名称
* @return abstract:简介
* @return thumbnail:头图
* @return content:内容
* @return create_time:发布时间
* @return author:作者
* @throws
*/
public function getNewsInfo(){
$news_id=input('news_id');
$news= new ActivityNews();
$info=$news->getInfo($news_id);
$this->success('',$info);
}
/**
* @title 在线培训列表
* @description 在线培训列表
* @author sgj
* @url /index/second/tranOnlineList
* @method GET
*
*@header name:XX-Token require:1 default: desc:token
*
*
* @return id:文章id
* @return pic:图片
* @return num:题目数量
* @return author:作者
* @return content:内容
* @return user_status:用户状态0,未完成1,已完成
* @return author:作者
*
* @throws
*/
public function tranOnlineList(){
$userId=$this->getUserId();
$map1['user_id']=$userId;
$pass_array=db('user_pass')->where($map1)->column('class_id');
if (empty($pass_array)){
$pass_array=[];
}
$Class=new ClassModel();
$map['status']=1;
$list=$Class->where($map)->paginate('10');
$data=$list->items();
foreach ($data as $k=>$v) {
if (in_array($v['id'],$pass_array)){
$data[$k]['user_status']=1;
}else{
$data[$k]['user_status']=0;
}
$data[$k]['pic']=cmf_get_image_url($v['pic']);
}
$this->success('',$list);
}
/**
* @title 检查志愿者状态
* @description 检查志愿者状态
* @author sgj
* @url /index/second/checkTranStatus
* @method GET
*
*@header name:XX-Token require:1 default: desc:token
*
* @throws
*/
public function checkTranStatus(){
$userId=$this->getUserId();
if (!$this->isVolunteer($userId)){
$this->error('申请成为志愿者后才能答题');
}else{
$this->success();
}
}
/**
* @title 获取班级详情信息
* @description 获取班级详情信息
* @author sgj
* @url /index/second/getClassInfo
* @method GET
*
*
*@header name:XX-Token require:1 default: desc:token
*
*@param name:id type:int require:1 other: desc:课程id
*
*
* @throws
*/
public function getClassInfo(){
$userId=$this->getUserId();
$id=input('id');
if (!$this->isVolunteer($userId)){
$this->error('申请成为志愿者后才能答题');
}
$Class=new ClassModel();
$map['id']=$id;
$classInfo=$Class->where($map)->find();
$classInfo['pic']=cmf_get_image_url($classInfo['pic']);
$this->success('',$classInfo);
}
/**
* @title 获取班级问题
* @description 获取班级详情信息
* @author sgj
* @url /index/second/getClassQuestion
* @method GET
*
*
*@header name:XX-Token require:1 default: desc:token
*
*@param name:class_id type:int require:1 other: desc:课程id
*
*
* @throws
*/
public function getClassQuestion(){
$class_id=input('class_id');
$ClassQuesion=new ClassQuestionModel();
$question=$ClassQuesion->getClassQuesion($class_id);
$this->success('',$question);
}
/**
* @title 提交答案
* @description 提交答案
* @author sgj
* @url /index/second/commitAnswer
* @method GET
*
*
*@header name:XX-Token require:1 default: desc:token
*
*@param name:class_id type:int require:1 other: desc:课程id
*@param name:answer_info type:int require:1 other: desc:回答详情{"1":"0","2":"1","id"=>'答案索引'}
*
*
* @throws
*/
public function commitAnswer(){
$class_id=input('class_id');
$answer_info=input('answer_info');
$answer_info1= htmlspecialchars_decode($answer_info);
$answer_array=json_decode($answer_info1,true);
$ClassQuesion=new ClassQuestionModel();
$question=$ClassQuesion->getClassQuesion($class_id);
foreach ($question as $k=>$v){
$answer[$v['id']]=$v['answer'];
}
if (!empty($answer_array)){
foreach ($answer_array as $k=>$v){
if ($answer[$k]==$v){
unset($answer[$k]);
}
}
}
if (empty($answer)){
/*添加信息*/
/*添加用户时长*/
/*添加到完成*/
$this->success('回答成功');
}else{
$this->error('问题回答错误');
}
}
}
\ No newline at end of file
... ...
... ... @@ -661,6 +661,10 @@ function cmf_get_asset_url($file, $style = '')
*/
function cmf_get_image_url($file, $style = '')
{
if(empty($file)){
return '';
}
if (strpos($file, "http") === 0) {
return $file;
} else if (strpos($file, "/") === 0) {
... ...
... ... @@ -11,6 +11,7 @@
namespace cmf\controller;
use api\index\model\UserModel;
use api\index\model\VolunteerModel;
use think\exception\HttpResponseException;
use think\exception\ValidateException;
use think\Request;
... ... @@ -307,4 +308,24 @@ class RestBaseController
}
}
/**
* 检查是否为志愿者
* @param $user_id 用户id
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function isVolunteer($user_id){
$Volunteer=new VolunteerModel();
$map['user_id']=$user_id;
$map['status']=2;
$isin=$Volunteer->where($map)->find();
if (empty($isin)){
return false;
}else{
return true;
}
}
}
\ No newline at end of file
... ...