GoodController.class.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace Admin\Controller;
  3. use Common\Controller\AdminController;
  4. class GoodController extends AdminController {
  5. public function __construct(){
  6. parent::__construct();
  7. }
  8. public function index(){
  9. $sort = I('sort','1');
  10. $orderList = array(
  11. 1=>array('good_id desc','时间倒序',1),
  12. 2=>array('good_id asc','时间正序',2),
  13. 3=>array('course_join desc','加入量倒序',3),
  14. 4=>array('course_join asc','加入量正序',4),
  15. 5=>array('course_join desc','排序id倒序',5),
  16. 6=>array('course_join asc','排序id正序',6),
  17. );
  18. $orderby = $orderList[$sort][0];
  19. $condition = array('course_flag'=>1);
  20. $count = M('GoodCourse')->count();
  21. //分页
  22. $Page = new \Think\Page($count);
  23. $show = $Page->show();
  24. $field = 'gc.*,c.course_name,c.course_num,c.course_join,u.user_name';
  25. $join = 'gc LEFT JOIN t_course c ON gc.course_id=c.course_id LEFT JOIN t_user u ON c.user_id=u.user_id';
  26. $res = M('GoodCourse')->join($join)->where($condition)->field($field)->order($orderby)->limit($Page->firstRow.','.$Page->listRows)->select();
  27. $resShow = M('GoodCourseShow')->find();
  28. $this->assign('page',$show);
  29. $this->assign('list',$res);
  30. $this->assign('sort',$sort);
  31. $this->assign('orderby',$orderby);
  32. $this->assign('resShow',$resShow);
  33. $this->assign('orderList',$orderList);
  34. $this->display();
  35. }
  36. public function add(){
  37. $step = I('step');
  38. if (empty($step)){
  39. $sort = I('sort','1');
  40. $orderList = array(
  41. 1=>array('good_id desc','时间倒序',1),
  42. 2=>array('good_id asc','时间正序',2),
  43. 3=>array('course_join desc','加入量倒序',3),
  44. 4=>array('course_join asc','加入量正序',4),
  45. 5=>array('course_join desc','排序id倒序',5),
  46. 6=>array('course_join asc','排序id正序',6),
  47. );
  48. $orderby = $orderList[$sort][0];
  49. $condition = array('course_flag'=>1,'course_status'=>3);
  50. $count = M('GoodCourse')->count();
  51. //分页
  52. $Page = new \Think\Page($count);
  53. $show = $Page->show();
  54. $field = 'gc.good_id,c.course_id,c.course_name,c.course_num,c.course_join,u.user_name';
  55. $join = 'c LEFT JOIN t_good_course gc ON gc.course_id=c.course_id LEFT JOIN t_user u ON c.user_id=u.user_id';
  56. $res = M('Course')->join($join)->where($condition)->field($field)->order($orderby)->limit($Page->firstRow.','.$Page->listRows)->select();
  57. //echo D('Course')->getLastSql();exit;
  58. $this->assign('page',$show);
  59. $this->assign('list',$res);
  60. $this->assign('sort',$sort);
  61. $this->assign('orderby',$orderby);
  62. $this->assign('orderList',$orderList);
  63. $this->display();
  64. }else if($step==2){
  65. $courseIdArr = I('course_id');
  66. if (empty($courseIdArr)){
  67. $this->error('请选择需要添加的课程');
  68. }
  69. foreach ($courseIdArr as $courseId){
  70. $dataList[] = array('course_id'=>$courseId,'operate_dt'=>time());
  71. }
  72. M('GoodCourse')->addAll($dataList);
  73. $this->success('添加成功');
  74. }
  75. }
  76. public function del(){
  77. $goodId = I('good_id');
  78. if (empty($goodId)){
  79. $this->error('请选择需要删除的课程');
  80. }
  81. M('GoodCourse')->where(array('good_id'=>$goodId))->delete();
  82. $this->success('删除成功');
  83. }
  84. public function edit(){
  85. $step = I('step');
  86. $goodId = I('good_id');
  87. if (empty($step)){
  88. if (empty($goodId)){
  89. $this->error('请选择需要删除的课程');
  90. }
  91. $info = M('GoodCourse')->where(array('good_id'=>$goodId))->find();
  92. $this->assign('info',$info);
  93. $this->display();
  94. }else if($step==2){
  95. $goodSort = I('good_sort');
  96. $courseInfo = I('course_info');
  97. if ($goodSort<=0){
  98. $this->error('排序id错误');
  99. }
  100. if (!empty($courseInfo)){
  101. if (mb_strlen($courseInfo,'UTF8')<2 || mb_strlen($courseInfo,'UTF8')>140){
  102. $this->error('介绍说明2到140个汉字');
  103. }
  104. }
  105. M('GoodCourse')->where(array('good_id'=>$goodId))->save(array('good_sort'=>$goodSort,'course_info'=>$courseInfo,));
  106. $this->success('编辑成功','/admin/good/index');
  107. }
  108. }
  109. public function status(){
  110. $goodShow = I('good_show');
  111. M('GoodCourseShow')->where(array('show_id'=>1))->save(array('good_show'=>$goodShow));
  112. $this->success('推送设置成功','/admin/good/index');
  113. }
  114. }