123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace Admin\Controller;
- use Common\Controller\AdminController;
- class GoodController extends AdminController {
- public function __construct(){
- parent::__construct();
- }
-
- public function index(){
- $sort = I('sort','1');
- $orderList = array(
- 1=>array('good_id desc','时间倒序',1),
- 2=>array('good_id asc','时间正序',2),
- 3=>array('course_join desc','加入量倒序',3),
- 4=>array('course_join asc','加入量正序',4),
- 5=>array('course_join desc','排序id倒序',5),
- 6=>array('course_join asc','排序id正序',6),
- );
- $orderby = $orderList[$sort][0];
- $condition = array('course_flag'=>1);
- $count = M('GoodCourse')->count();
- //分页
- $Page = new \Think\Page($count);
- $show = $Page->show();
- $field = 'gc.*,c.course_name,c.course_num,c.course_join,u.user_name';
- $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';
- $res = M('GoodCourse')->join($join)->where($condition)->field($field)->order($orderby)->limit($Page->firstRow.','.$Page->listRows)->select();
- $resShow = M('GoodCourseShow')->find();
-
- $this->assign('page',$show);
- $this->assign('list',$res);
- $this->assign('sort',$sort);
- $this->assign('orderby',$orderby);
- $this->assign('resShow',$resShow);
- $this->assign('orderList',$orderList);
- $this->display();
- }
-
- public function add(){
- $step = I('step');
- if (empty($step)){
- $sort = I('sort','1');
- $orderList = array(
- 1=>array('good_id desc','时间倒序',1),
- 2=>array('good_id asc','时间正序',2),
- 3=>array('course_join desc','加入量倒序',3),
- 4=>array('course_join asc','加入量正序',4),
- 5=>array('course_join desc','排序id倒序',5),
- 6=>array('course_join asc','排序id正序',6),
- );
- $orderby = $orderList[$sort][0];
- $condition = array('course_flag'=>1,'course_status'=>3);
- $count = M('GoodCourse')->count();
- //分页
- $Page = new \Think\Page($count);
- $show = $Page->show();
- $field = 'gc.good_id,c.course_id,c.course_name,c.course_num,c.course_join,u.user_name';
- $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';
- $res = M('Course')->join($join)->where($condition)->field($field)->order($orderby)->limit($Page->firstRow.','.$Page->listRows)->select();
-
- //echo D('Course')->getLastSql();exit;
- $this->assign('page',$show);
- $this->assign('list',$res);
- $this->assign('sort',$sort);
- $this->assign('orderby',$orderby);
- $this->assign('orderList',$orderList);
- $this->display();
- }else if($step==2){
- $courseIdArr = I('course_id');
- if (empty($courseIdArr)){
- $this->error('请选择需要添加的课程');
- }
- foreach ($courseIdArr as $courseId){
- $dataList[] = array('course_id'=>$courseId,'operate_dt'=>time());
- }
- M('GoodCourse')->addAll($dataList);
- $this->success('添加成功');
- }
- }
-
- public function del(){
- $goodId = I('good_id');
- if (empty($goodId)){
- $this->error('请选择需要删除的课程');
- }
- M('GoodCourse')->where(array('good_id'=>$goodId))->delete();
- $this->success('删除成功');
- }
-
- public function edit(){
- $step = I('step');
- $goodId = I('good_id');
- if (empty($step)){
- if (empty($goodId)){
- $this->error('请选择需要删除的课程');
- }
- $info = M('GoodCourse')->where(array('good_id'=>$goodId))->find();
- $this->assign('info',$info);
- $this->display();
- }else if($step==2){
- $goodSort = I('good_sort');
- $courseInfo = I('course_info');
- if ($goodSort<=0){
- $this->error('排序id错误');
- }
- if (!empty($courseInfo)){
- if (mb_strlen($courseInfo,'UTF8')<2 || mb_strlen($courseInfo,'UTF8')>140){
- $this->error('介绍说明2到140个汉字');
- }
- }
- M('GoodCourse')->where(array('good_id'=>$goodId))->save(array('good_sort'=>$goodSort,'course_info'=>$courseInfo,));
- $this->success('编辑成功','/admin/good/index');
- }
- }
-
- public function status(){
- $goodShow = I('good_show');
- M('GoodCourseShow')->where(array('show_id'=>1))->save(array('good_show'=>$goodShow));
- $this->success('推送设置成功','/admin/good/index');
- }
- }
|