StoreController.class.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. namespace Admin\Controller;
  3. use Common\Controller\AdminController;
  4. class StoreController extends AdminController {
  5. public function __construct(){
  6. parent::__construct();
  7. }
  8. //题库列表
  9. public function index(){
  10. $condition = array('is_delete'=>1);
  11. //课程类型
  12. $levelRes = M('UserLevel')->where(array('is_delete'=>1))->field('level_id,level_name')->select();
  13. $levelList = array();
  14. foreach ($levelRes as $type){
  15. $levelList[$type['level_id']] = $type['level_name'];
  16. }
  17. $count = M('Store')->where($condition)->count();
  18. //分页
  19. $Page = new \Think\Page($count);
  20. $show = $Page->show();
  21. $storeList = M('Store')->where($condition)->field()->order('store_id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
  22. $this->assign('page',$show);
  23. $this->assign('list',$storeList);
  24. $this->assign('levelList',$levelList);
  25. $this->display();
  26. }
  27. //编辑题库
  28. public function edit(){
  29. $step = I('step','');
  30. $storeId = I('store_id','');
  31. if (empty($step)){
  32. $info = array();
  33. if (!empty($storeId)){
  34. $info = M('Store')->where(array('store_id'=>$storeId))->find();
  35. }
  36. $levelList = M('UserLevel')->where(array('is_delete'=>1))->field('level_id,level_name')->select();
  37. $this->assign('info',$info);
  38. $this->assign('levelList',$levelList);
  39. $this->display();
  40. }else if($step==2){
  41. $levelId = I('level_id','');
  42. /* $storeName = I('store_name','');
  43. if (mb_strlen($storeName,'UTF8')<2 || mb_strlen($storeName,'UTF8')>12){
  44. $this->error('题库名称2到12个汉字');
  45. }
  46. $res = M('Store')->where(array('store_name'=>$storeName,'is_delete'=>1))->field('store_id')->find();
  47. //新增
  48. if (empty($storeId) && $res!=NULL){
  49. $this->error('题库名称已经存在');
  50. }
  51. //更新
  52. if (!empty($storeId) && $storeId!=$res['store_id']){
  53. $this->error('题库名称已经存在');
  54. } */
  55. $res = M('Store')->where(array('level_id'=>$levelId,'is_delete'=>1))->field('store_id')->find();
  56. //新增
  57. if (empty($storeId) && $res!=NULL){
  58. $this->error('题库类型已经存在');
  59. }
  60. //更新
  61. if (!empty($storeId) && $storeId!=$res['store_id']){
  62. $this->error('题库类型已经存在');
  63. }
  64. if (empty($storeId)){
  65. //M('Store')->add(array('level_id'=>$levelId,'store_name'=>$storeName,'operate_dt'=>time()));
  66. M('Store')->add(array('level_id'=>$levelId,'operate_dt'=>time()));
  67. }else{
  68. M('Store')->where(array('store_id'=>$storeId))->save(array('level_id'=>$levelId));
  69. }
  70. $this->success('题库操作成功','/admin/store/index');
  71. }
  72. }
  73. //删除题库
  74. public function del(){
  75. $storeId = I('store_id','');
  76. if (empty($storeId)){
  77. $this->error("题库ID错误",'/admin/store/index');
  78. }
  79. //M('store')->where(array('store_id'=>$storeId))->save(array('is_delete'=>2));
  80. M('store')->where(array('store_id'=>$storeId))->delete();
  81. $this->success('题库删除成功','/admin/store/index');
  82. }
  83. //获取课程的单词列表
  84. public function detail(){
  85. $storeId = I('store_id','');
  86. if (empty($storeId)){
  87. $this->error("题库ID错误",'/admin/store/index');
  88. }
  89. $keyword = I('get.keyword','');
  90. $condition = array('is_delete'=>1,'store_id'=>$storeId);
  91. if (!empty($keyword)){
  92. $condition['words_name'] = array('LIKE','%'.$keyword.'%');
  93. }
  94. $count = M('StoreWords')->where($condition)->count();
  95. //分页
  96. $Page = new \Think\Page($count);
  97. $show = $Page->show();
  98. $wordsRes = M('StoreWords')->where($condition)->field()->order('words_id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
  99. $wordsList = array();
  100. foreach ($wordsRes as $row){
  101. $wordsList[] = array(
  102. 'words_id' => $row['words_id'],
  103. 'store_id' => $row['store_id'],
  104. 'words_name' => $row['words_name'],
  105. 'operate_dt' => $row['operate_dt'],
  106. 'words_text' => $this->getWordsText($row),
  107. );
  108. }
  109. $this->assign('page',$show);
  110. $this->assign('list',$wordsList);
  111. $this->assign('storeId', $storeId);
  112. $this->display();
  113. }
  114. //编辑题库单词
  115. public function words(){
  116. $step = I('step','');
  117. $wordsId = I('words_id','');
  118. $storeId = I('store_id','');
  119. $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',);
  120. if (empty($step)){
  121. $info = array();
  122. if (!empty($storeId)){
  123. $info = M('StoreWords')->where(array('words_id'=>$wordsId))->find();
  124. }
  125. $this->assign('info',$info);
  126. $this->assign('storeId', $storeId);
  127. $this->assign('wordsKeys', $wordsKeys);
  128. $this->display();
  129. }else if($step==2){
  130. $data['store_id'] = $storeId;
  131. $data['words_name'] = I('words_name','');
  132. $wordsVals = array_values($wordsKeys);
  133. $checkWords = true;
  134. foreach ($wordsVals as $keys){
  135. $data[$keys] = I($keys,'');
  136. if (!empty($data[$keys])){
  137. $checkWords = false;
  138. }
  139. }
  140. if (empty($data['words_name'])){
  141. $this->error('单词不能为空');
  142. }
  143. if ($checkWords){
  144. $this->error('中文释义不能为空');
  145. }
  146. $data['operate_dt'] = time();
  147. if ($wordsId){
  148. M('StoreWords')->where(array('words_id'=>$wordsId))->save($data);
  149. }else{
  150. M('StoreWords')->add($data);
  151. M('Store')->where(array('store_id'=>$storeId))->setInc('store_num');
  152. }
  153. //$this->success('单词操作成功','/admin/store/detail?store_id='.$storeId);
  154. $this->success('单词操作成功','/admin/store/words?store_id='.$storeId);
  155. }
  156. }
  157. //删除题库单词
  158. public function delWords(){
  159. $wordsId = I('words_id','');
  160. $storeId = I('store_id','');
  161. //M('StoreWords')->where(array('words_id'=>$wordsId))->save(array('is_delete'=>2));
  162. M('StoreWords')->where(array('words_id'=>$wordsId))->delete();
  163. M('Store')->where(array('store_id'=>$storeId))->setDec('store_num');
  164. $this->success('题库单词删除成功','/admin/store/detail/index?store_id='.$storeId);
  165. }
  166. }