初始化项目:添加后端代码、ThinkPHP框架、前端资源

This commit is contained in:
amb
2026-09-03 12:42:39 +08:00
commit 482bece22e
3726 changed files with 416708 additions and 0 deletions
@@ -0,0 +1,104 @@
<?php
namespace app\admin\model\app\exam;
use think\Model;
class Exercises extends Model
{
// 表名
protected $name = 'app_exam_exercises';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'status_text'
];
public function getStatusList()
{
return ['1' => __('Status 1'), '0' => __('Status 0')];
}
public function getHideList()
{
return ['1' => __('Hide 1'), '0' => __('Hide 0')];
}
public function getSalesTypeList()
{
return ['1' => __('Sales_type 1'), '3' => __('Sales_type 3'), '2' => __('Sales_type 2')];
}
public function getQuestionModeList()
{
return ['sort' => __('Question_mode sort'), 'random' => __('Question_mode random')];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
public function course()
{
return $this->belongsTo('app\admin\model\course\Course', 'bind_course', 'id', [], 'LEFT')->setEagerlyType(0);
}
/**
* 获取绑定的题库分组
* @param $exercisesId
* @return mixed
*/
public function getBindWarehouseGroup($exercisesId){
$data = \app\admin\model\app\exam\ExercisesBindWarehouseGroup::with(['group'])->where([
'exercises_id'=>$exercisesId,
])->order('id','asc')->select();
// 转换为数组处理
$result = collection($data)->toArray();
// 处理未分组的情况(warehouse_group_id = 0 或 group.id 为 null
$allGroupIds = null;
foreach ($result as &$item) {
// 检查 group.id 是否为 null(表示关联的分组不存在)
if (empty($item['group']['id'])) {
// 计算未分组的题目数量(只查询一次)
if ($allGroupIds === null) {
$allGroupIds = \app\admin\model\app\exam\WarehouseGroup::field('id')->column('id');
}
$questionCount = \app\admin\model\app\exam\WarehouseQuestion::where(['group_id' => ['NOT IN', $allGroupIds]])->count();
// 设置未分组信息
$item['group'] = [
'id' => 0,
'name' => '未分组',
'question_count' => $questionCount
];
}
}
return $result;
}
}