作者 何书鹏
1 个管道 的构建 通过 耗费 2 秒

后台管理删除优化

... ... @@ -213,6 +213,50 @@ class Almighty extends Backend
}
/**
* 删除
*/
public function del($ids = "")
{
if ($ids) {
$pk = $this->model->getPk();
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$list = $this->model->where($pk, 'in', $ids)->select();
$count = 0;
Db::startTrans();
try {
foreach ($list as $k => $v) {
// 删除回答
Db::name('mobile_question_answer')->where('question_id',$v['id'])->delete();
// 删除收藏
Db::name('mobile_question_collect')->where('question_id',$v['id'])->delete();
// 删除笔记
Db::name('mobile_question_note')->where('question_id',$v['id'])->delete();
// 删除纠错
Db::name('mobile_question_wrong')->where('question_id',$v['id'])->delete();
$count += $v->delete();
}
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($count) {
$this->success();
} else {
$this->error(__('No rows were deleted'));
}
}
$this->error(__('Parameter %s can not be empty', 'ids'));
}
/**
* 导入
*/
public function import()
... ... @@ -323,6 +367,8 @@ class Almighty extends Backend
}
}
$row['option'] = !empty($option_arr) ? json_encode($option_arr) : '';
// 把答案中的中文逗号和空格都过滤掉
$row['answer'] = str_replace(array(",", " "), array(",", ""), $row['answer']);
$insert[] = $row;
}
... ...
... ... @@ -3,6 +3,7 @@
namespace app\admin\controller\mobile;
use app\common\controller\Backend;
use think\Db;
/**
* 每日一练管理
... ... @@ -73,4 +74,53 @@ class Everyday extends Backend
}
return $this->view->fetch();
}
/**
* 删除
*/
public function del($ids = "")
{
if ($ids) {
$pk = $this->model->getPk();
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$list = $this->model->where($pk, 'in', $ids)->select();
$count = 0;
Db::startTrans();
try {
foreach ($list as $k => $v) {
// 删除题目
$question_list = Db::name('mobile_question')->where('target_id',$v['id'])->where('target_type','4')->field('id')->select();
foreach ($question_list as $val){
// 删除回答
Db::name('mobile_question_answer')->where('question_id',$val['id'])->delete();
// 删除收藏
Db::name('mobile_question_collect')->where('question_id',$val['id'])->delete();
// 删除笔记
Db::name('mobile_question_note')->where('question_id',$val['id'])->delete();
// 删除纠错
Db::name('mobile_question_wrong')->where('question_id',$val['id'])->delete();
Db::name('mobile_question')->where('id',$val['id'])->delete();
}
$count += $v->delete();
}
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($count) {
$this->success();
} else {
$this->error(__('No rows were deleted'));
}
}
$this->error(__('Parameter %s can not be empty', 'ids'));
}
}
... ...
... ... @@ -3,6 +3,7 @@
namespace app\admin\controller\mobile;
use app\common\controller\Backend;
use think\Db;
/**
* 历年真题管理
... ... @@ -73,4 +74,55 @@ class Old extends Backend
}
return $this->view->fetch();
}
/**
* 删除
*/
public function del($ids = "")
{
if ($ids) {
$pk = $this->model->getPk();
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$list = $this->model->where($pk, 'in', $ids)->select();
$count = 0;
Db::startTrans();
try {
foreach ($list as $k => $v) {
// 删除题目
$question_list = Db::name('mobile_question')->where('target_id',$v['id'])->where('target_type','3')->field('id')->select();
foreach ($question_list as $val){
// 删除回答
Db::name('mobile_question_answer')->where('question_id',$val['id'])->delete();
// 删除收藏
Db::name('mobile_question_collect')->where('question_id',$val['id'])->delete();
// 删除笔记
Db::name('mobile_question_note')->where('question_id',$val['id'])->delete();
// 删除纠错
Db::name('mobile_question_wrong')->where('question_id',$val['id'])->delete();
Db::name('mobile_question')->where('id',$val['id'])->delete();
}
// 删除考试结果
Db::name('mobile_old_result')->where('old_id',$v['id'])->delete();
$count += $v->delete();
}
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($count) {
$this->success();
} else {
$this->error(__('No rows were deleted'));
}
}
$this->error(__('Parameter %s can not be empty', 'ids'));
}
}
... ...
... ... @@ -3,6 +3,7 @@
namespace app\admin\controller\mobile;
use app\common\controller\Backend;
use think\Db;
/**
* 模拟试题管理
... ... @@ -73,4 +74,55 @@ class Simulation extends Backend
}
return $this->view->fetch();
}
/**
* 删除
*/
public function del($ids = "")
{
if ($ids) {
$pk = $this->model->getPk();
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$list = $this->model->where($pk, 'in', $ids)->select();
$count = 0;
Db::startTrans();
try {
foreach ($list as $k => $v) {
// 删除题目
$question_list = Db::name('mobile_question')->where('target_id',$v['id'])->where('target_type','2')->field('id')->select();
foreach ($question_list as $val){
// 删除回答
Db::name('mobile_question_answer')->where('question_id',$val['id'])->delete();
// 删除收藏
Db::name('mobile_question_collect')->where('question_id',$val['id'])->delete();
// 删除笔记
Db::name('mobile_question_note')->where('question_id',$val['id'])->delete();
// 删除纠错
Db::name('mobile_question_wrong')->where('question_id',$val['id'])->delete();
Db::name('mobile_question')->where('id',$val['id'])->delete();
}
// 删除考试结果
Db::name('mobile_simulation_result')->where('simulation_id',$v['id'])->delete();
$count += $v->delete();
}
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($count) {
$this->success();
} else {
$this->error(__('No rows were deleted'));
}
}
$this->error(__('Parameter %s can not be empty', 'ids'));
}
}
... ...
... ... @@ -220,6 +220,50 @@ class SimulationQuestion extends Backend
}
/**
* 删除
*/
public function del($ids = "")
{
if ($ids) {
$pk = $this->model->getPk();
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$list = $this->model->where($pk, 'in', $ids)->select();
$count = 0;
Db::startTrans();
try {
foreach ($list as $k => $v) {
// 删除回答
Db::name('mobile_question_answer')->where('question_id',$v['id'])->delete();
// 删除收藏
Db::name('mobile_question_collect')->where('question_id',$v['id'])->delete();
// 删除笔记
Db::name('mobile_question_note')->where('question_id',$v['id'])->delete();
// 删除纠错
Db::name('mobile_question_wrong')->where('question_id',$v['id'])->delete();
$count += $v->delete();
}
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($count) {
$this->success();
} else {
$this->error(__('No rows were deleted'));
}
}
$this->error(__('Parameter %s can not be empty', 'ids'));
}
/**
* 导入
*/
public function import()
... ... @@ -332,6 +376,8 @@ class SimulationQuestion extends Backend
}
}
$row['option'] = !empty($option_arr) ? json_encode($option_arr) : '';
// 把答案中的中文逗号和空格都过滤掉
$row['answer'] = str_replace(array(",", " "), array(",", ""), $row['answer']);
$row['target_id'] = $target_id;
$row['target_type'] = $target_type;
$insert[] = $row;
... ...
... ... @@ -117,6 +117,54 @@ class Course extends Backend
}
}
/**
* 删除
*/
public function del($ids = "")
{
if ($ids) {
$pk = $this->model->getPk();
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$list = $this->model->where($pk, 'in', $ids)->select();
$count = 0;
Db::startTrans();
try {
foreach ($list as $k => $v) {
// 删除评价
Db::name('mobile_course_appraise')->where('course_id',$v['id'])->delete();
// 删除目录
Db::name('mobile_course_catalog')->where('course_id',$v['id'])->delete();
// 删除兑换码
Db::name('mobile_course_code')->where('course_id',$v['id'])->delete();
// 删除收藏
Db::name('mobile_course_collect')->where('course_id',$v['id'])->delete();
// 删除订单
Db::name('mobile_course_order')->where('course_id',$v['id'])->delete();
// 删除规格
Db::name('mobile_course_spec')->where('course_id',$v['id'])->delete();
$count += $v->delete();
}
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($count) {
$this->success();
} else {
$this->error(__('No rows were deleted'));
}
}
$this->error(__('Parameter %s can not be empty', 'ids'));
}
public function selectpage()
{
return parent::selectpage(); // TODO: Change the autogenerated stub
... ...
... ... @@ -3,6 +3,7 @@
namespace app\admin\controller\mobile\secret;
use app\common\controller\Backend;
use think\Db;
/**
* 通关密卷管理
... ... @@ -73,4 +74,57 @@ class Secret extends Backend
}
return $this->view->fetch();
}
/**
* 删除
*/
public function del($ids = "")
{
if ($ids) {
$pk = $this->model->getPk();
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$list = $this->model->where($pk, 'in', $ids)->select();
$count = 0;
Db::startTrans();
try {
foreach ($list as $k => $v) {
// 删除题目
$question_list = Db::name('mobile_question')->where('target_id',$v['id'])->where('target_type','5')->field('id')->select();
foreach ($question_list as $val){
// 删除回答
Db::name('mobile_question_answer')->where('question_id',$val['id'])->delete();
// 删除收藏
Db::name('mobile_question_collect')->where('question_id',$val['id'])->delete();
// 删除笔记
Db::name('mobile_question_note')->where('question_id',$val['id'])->delete();
// 删除纠错
Db::name('mobile_question_wrong')->where('question_id',$val['id'])->delete();
Db::name('mobile_question')->where('id',$val['id'])->delete();
}
// 删除订单
Db::name('mobile_secret_order')->where('secret_id',$v['id'])->delete();
// 删除规格
Db::name('mobile_secret_spec')->where('secret_id',$v['id'])->delete();
$count += $v->delete();
}
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($count) {
$this->success();
} else {
$this->error(__('No rows were deleted'));
}
}
$this->error(__('Parameter %s can not be empty', 'ids'));
}
}
... ...