123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- namespace Admin\Controller;
- use Common\Controller\AdminController;
- class StoreController extends AdminController {
- public function __construct(){
- parent::__construct();
- }
- //题库列表
- public function index(){
- $condition = array('is_delete'=>1);
- //课程类型
- $levelRes = M('UserLevel')->where(array('is_delete'=>1))->field('level_id,level_name')->select();
- $levelList = array();
- foreach ($levelRes as $type){
- $levelList[$type['level_id']] = $type['level_name'];
- }
- $count = M('Store')->where($condition)->count();
- //分页
- $Page = new \Think\Page($count);
- $show = $Page->show();
- $storeList = M('Store')->where($condition)->field()->order('store_id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
- $this->assign('page',$show);
- $this->assign('list',$storeList);
- $this->assign('levelList',$levelList);
- $this->display();
- }
- //编辑题库
- public function edit(){
- $step = I('step','');
- $storeId = I('store_id','');
- if (empty($step)){
- $info = array();
- if (!empty($storeId)){
- $info = M('Store')->where(array('store_id'=>$storeId))->find();
- }
- $levelList = M('UserLevel')->where(array('is_delete'=>1))->field('level_id,level_name')->select();
- $this->assign('info',$info);
- $this->assign('levelList',$levelList);
- $this->display();
- }else if($step==2){
- $levelId = I('level_id','');
- /* $storeName = I('store_name','');
- if (mb_strlen($storeName,'UTF8')<2 || mb_strlen($storeName,'UTF8')>12){
- $this->error('题库名称2到12个汉字');
- }
- $res = M('Store')->where(array('store_name'=>$storeName,'is_delete'=>1))->field('store_id')->find();
- //新增
- if (empty($storeId) && $res!=NULL){
- $this->error('题库名称已经存在');
- }
- //更新
- if (!empty($storeId) && $storeId!=$res['store_id']){
- $this->error('题库名称已经存在');
- } */
- $res = M('Store')->where(array('level_id'=>$levelId,'is_delete'=>1))->field('store_id')->find();
- //新增
- if (empty($storeId) && $res!=NULL){
- $this->error('题库类型已经存在');
- }
- //更新
- if (!empty($storeId) && $storeId!=$res['store_id']){
- $this->error('题库类型已经存在');
- }
- if (empty($storeId)){
- //M('Store')->add(array('level_id'=>$levelId,'store_name'=>$storeName,'operate_dt'=>time()));
- M('Store')->add(array('level_id'=>$levelId,'operate_dt'=>time()));
- }else{
- M('Store')->where(array('store_id'=>$storeId))->save(array('level_id'=>$levelId));
- }
- $this->success('题库操作成功','/admin/store/index');
- }
- }
-
- //删除题库
- public function del(){
- $storeId = I('store_id','');
- if (empty($storeId)){
- $this->error("题库ID错误",'/admin/store/index');
- }
- //M('store')->where(array('store_id'=>$storeId))->save(array('is_delete'=>2));
- M('store')->where(array('store_id'=>$storeId))->delete();
- $this->success('题库删除成功','/admin/store/index');
- }
-
- //获取课程的单词列表
- public function detail(){
- $storeId = I('store_id','');
- if (empty($storeId)){
- $this->error("题库ID错误",'/admin/store/index');
- }
- $keyword = I('get.keyword','');
- $condition = array('is_delete'=>1,'store_id'=>$storeId);
- if (!empty($keyword)){
- $condition['words_name'] = array('LIKE','%'.$keyword.'%');
- }
- $count = M('StoreWords')->where($condition)->count();
- //分页
- $Page = new \Think\Page($count);
- $show = $Page->show();
- $wordsRes = M('StoreWords')->where($condition)->field()->order('words_id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
- $wordsList = array();
- foreach ($wordsRes as $row){
- $wordsList[] = array(
- 'words_id' => $row['words_id'],
- 'store_id' => $row['store_id'],
- 'words_name' => $row['words_name'],
- 'operate_dt' => $row['operate_dt'],
- 'words_text' => $this->getWordsText($row),
- );
- }
- $this->assign('page',$show);
- $this->assign('list',$wordsList);
- $this->assign('storeId', $storeId);
- $this->display();
- }
-
- //编辑题库单词
- public function words(){
- $step = I('step','');
- $wordsId = I('words_id','');
- $storeId = I('store_id','');
- $wordsKeys = array('n'=>'words_n','pron'=>'words_pron','adj'=>'words_adj','num'=>'words_num','v'=>'words_v','adv'=>'words_adv','art'=>'words_art','prep'=>'words_prep','conj'=>'words_conj','int'=>'words_int','vt'=>'words_vt','vi'=>'words_vi','other'=>'words_other',);
- if (empty($step)){
- $info = array();
- if (!empty($storeId)){
- $info = M('StoreWords')->where(array('words_id'=>$wordsId))->find();
- }
- $this->assign('info',$info);
- $this->assign('storeId', $storeId);
- $this->assign('wordsKeys', $wordsKeys);
- $this->display();
- }else if($step==2){
- $data['store_id'] = $storeId;
- $data['words_name'] = I('words_name','');
- $wordsVals = array_values($wordsKeys);
- $checkWords = true;
- foreach ($wordsVals as $keys){
- $data[$keys] = I($keys,'');
- if (!empty($data[$keys])){
- $checkWords = false;
- }
- }
- if (empty($data['words_name'])){
- $this->error('单词不能为空');
- }
- if ($checkWords){
- $this->error('中文释义不能为空');
- }
- $data['operate_dt'] = time();
- if ($wordsId){
- M('StoreWords')->where(array('words_id'=>$wordsId))->save($data);
- }else{
- M('StoreWords')->add($data);
- M('Store')->where(array('store_id'=>$storeId))->setInc('store_num');
- }
- //$this->success('单词操作成功','/admin/store/detail?store_id='.$storeId);
- $this->success('单词操作成功','/admin/store/words?store_id='.$storeId);
- }
- }
-
- //删除题库单词
- public function delWords(){
- $wordsId = I('words_id','');
- $storeId = I('store_id','');
- //M('StoreWords')->where(array('words_id'=>$wordsId))->save(array('is_delete'=>2));
- M('StoreWords')->where(array('words_id'=>$wordsId))->delete();
- M('Store')->where(array('store_id'=>$storeId))->setDec('store_num');
- $this->success('题库单词删除成功','/admin/store/detail/index?store_id='.$storeId);
- }
- }
|