ActivityController.class.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace Admin\Controller;
  3. use Common\Controller\AdminController;
  4. class ActivityController extends AdminController {
  5. public function __construct(){
  6. parent::__construct();
  7. }
  8. public function index(){
  9. $count = M('Activity')->count();
  10. //分页
  11. $Page = new \Think\Page($count);
  12. $show = $Page->show();
  13. $list = M('Activity')->order('act_id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
  14. $this->assign('page',$show);
  15. $this->assign('list',$list);
  16. $this->display();
  17. }
  18. public function edit(){
  19. $step = I('step','');
  20. $actId = I('act_id','');
  21. if (empty($step)){
  22. $info = array();
  23. if (!empty($actId)){
  24. $info = M('Activity')->where(array('act_id'=>$actId))->find();
  25. }
  26. $this->assign('info',$info);
  27. $this->display();
  28. }else if($step==2){
  29. $saveData =[
  30. 'act_title'=>I('act_title',''),
  31. 'act_sort'=>I('act_sort','0'),
  32. 'act_pic'=>I('act_pic',''),
  33. 'act_name'=>I('act_name',''),
  34. 'act_content'=>I('act_content',''),
  35. ] ;
  36. if (empty($saveData['act_pic'])){
  37. $this->error('图片不能为空');
  38. }
  39. if (empty($saveData['act_title'])){
  40. $this->error('活动名称不能为空');
  41. }
  42. if (empty($saveData['act_name'])){
  43. $this->error('出品方不能为空');
  44. }
  45. if ($actId){
  46. M('Activity')->where(array('act_id'=>$actId))->save($saveData);
  47. }else{
  48. $saveData['operate_dt'] = time();
  49. M('Activity')->add($saveData);
  50. }
  51. $this->success('操作成功','/admin/activity/index');
  52. }
  53. }
  54. public function status(){
  55. $actId = I('act_id','');
  56. $actStatus = I('act_status','');
  57. M('Activity')->where(array('act_id'=>$actId))->save(['act_status'=>$actStatus]);
  58. $this->success('操作成功','/admin/activity/index');
  59. }
  60. //删除
  61. public function del(){
  62. $actId = I('act_id','');
  63. M('Activity')->where(array('act_id'=>$actId))->delete();
  64. $this->success('操作成功','/admin/activity/index');
  65. }
  66. }