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/admin/controller/study/ClearanceSubject.php

177 lines
5.2 KiB

<?php
// +----------------------------------------------------------------------
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
// +----------------------------------------------------------------------
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
// +----------------------------------------------------------------------
namespace app\admin\controller\study;
use app\admin\controller\AuthController;
use service\JsonService as Json;
use service\UploadService as Upload;
use think\Request;
use think\Url;
use service\FormBuilder as Form;
use app\wap\model\wap\Clearance as ClearanceModel;
use app\wap\model\wap\ClearanceSubject as ClearanceSubjectModel;
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\Relation;
/**
* 试卷
* Class TestPaper
*/
class ClearanceSubject extends AuthController
{
/**
* 试卷列表
*/
public function index($type = 2)
{
$this->assign([
'type' => $type,
'category' => ClearanceModel::where('type',1)->where('is_del',0)->where('is_show',1)->select(),
]);
return $this->fetch();
}
/**
* 获取试卷列表
*/
public function getTestPaperExercisesList($type = 1)
{
$where = parent::getMore([
['page', 1],
['limit', 20],
['title', ''],
['recite_id', 0]
]);
return Json::successlayui(ClearanceSubjectModel::clearanceSubjectList($where));
}
/**
* 快速编辑
* @param string $field 字段名
* @param int $id 修改的主键
* @param string value 修改后的值
* @return json
*/
public function set_value($field = '', $id = '', $value = '', $test = 0)
{
if (!$field || !$id || $value == '') Json::fail('缺少参数3');
if ($field == 'sort' && bcsub($value, 0, 0) < 0) return Json::fail('排序不能为负数');
$res = ClearanceSubjectModel::where('id', $id)->update([$field => $value]);
if ($res)
return Json::successful('保存成功');
else
return Json::fail('保存失败');
}
/**添加/编辑
* @param int $id
* @return mixed
*/
public function add($id = 0, $type = 2)
{
$test = $id > 0 ? ClearanceSubjectModel::get($id) : [];
// echo "<pre>";
// print_r($test);
// exit();
$this->assign([
'id' => $id,
'type' => $type,
'test' => json_encode($test),
]);
return $this->fetch();
}
/**
* 获取试题分类
*/
public function add_cate_list($type = 1)
{
$category = ClearanceModel::where('type',1)->where('is_del',0)->where('is_show',1)->select();
return Json::successful($category);
}
/**添加/编辑试题
* @param int $id
*/
public function save_add($id = 0, $type = 1)
{
$data = parent::postMore([
['name', ''],
['image', ''],
['recite_id', 0],
['is_show', 1],
['item_number', 0],
['pay_type', 0],
['money', 0],
['member_pay_type', 0],
['member_money', 0],
['sort', 0]
]);
if ($data['recite_id'] <= 0) return Json::fail('请选择试题分类');
if (!$data['name']) return Json::fail('请输入试卷标题');
ClearanceSubjectModel::beginTrans();
if ($id) {
$res = ClearanceSubjectModel::edit($data, $id);
} else {
$data['add_time'] = time();
if (ClearanceSubjectModel::be(['name' => $data['name'], 'is_del' => 0])) {
return Json::fail('标题已存在!');
}
$res = ClearanceSubjectModel::insertGetId($data);
}
if ($res) {
TestPaperModel::commitTrans();
return Json::successful('添加/编辑成功');
} else {
TestPaperModel::rollbackTrans();
return Json::fail('添加/编辑失败');
}
}
/**删除试卷
* @param int $id
*/
public function delete($id = 0)
{
if (!$id) $this->failed('缺少参数');
$download = ClearanceSubjectModel::get($id);
if (!$download) $this->failed('没有查到此资料');
if ($download->is_del) $this->failed('此资料已删除');
$data['is_del'] = 1;
$res = ClearanceSubjectModel::edit($data, $id);
if ($res)
return Json::successful('删除成功');
else
return Json::fail('删除失败');
}
}