Index.class.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. namespace Cas\Controller\Admin\Category;
  3. use KIF\Core\Request;
  4. use Cas\Controller\Admin\Controller;
  5. use KIF\Page\Page;
  6. use Cas\Dao\Category;
  7. use KIF\Verify;
  8. /**
  9. * "分类相关" - "列表"[分类相关信息]
  10. *
  11. * @author rabin
  12. * 页面: "分类信息"列表 doPageList
  13. * 页面: 查看&修改 "分类信息" doPageShow
  14. * 事件: 创建"分类信息" doReqCreate
  15. * 事件: 修改"分类信息" doReqUp
  16. * 事件: 删除"分类信息" doReqDel  
  17. */
  18. class Index extends Controller {
  19. private $objDCategory;
  20. private $operatorData;
  21. /**
  22. *  初始化
  23. */
  24. public function __construct() {
  25. header ( "Content-Type: text/html; charset=utf-8" );
  26. $this->objDCategory = new Category ();
  27. $this->operatorData = $this->getUser ();
  28. }
  29. /**
  30. * 默认
  31. */
  32. public function doDefault() {
  33. }
  34. /**
  35. * 页面: "分类信息"列表
  36. * 地址:http://cas.lishuy.com/?c=Admin_Category_Index&a=PageList
  37. */
  38. public function doPageList() {
  39. $page = Request::varGetInt ( 'page', 1 );
  40. $size = 10;
  41. $offset = ($page - 1) * $size;
  42. $limit = "{$offset},{$size}";
  43. $condition = array ();
  44. $total_num = $this->objDCategory->totals ( $condition );
  45. $url_tpl = Request::schemeDomain () . "?c=Admin_Category_Index&a=PageList";
  46. $url_tpl .= "&page={page}";
  47. $objPage = new Page ( $total_num, $url_tpl, $page, $size );
  48. $page_html = $objPage->html ();
  49. $order = 'id desc';
  50. $ids = $this->objDCategory->findIdsBy ( $condition, $limit, $order );
  51. $CategoryData = $this->objDCategory->gets ( $ids );
  52. $this->tpl = 'admin/category/list';
  53. $title = '分类列表';
  54. $this->setOutput('title', $title);
  55. $this->setOutput('menu_active', array('name' => 'categorylist', 'item' => 'list')); //激活菜单
  56. $this->addNavMenu('分类设置');
  57. $this->addNavMenu($title);
  58. $this->setOutput('pagePublicData', $this->getPagePublicData()); // 后台管理相关数据
  59. $this->setOutput ( 'page_html', $page_html ); // 分页Html
  60. $this->setOutput ( 'CategoryData', $CategoryData ); // 当前"分类信息"列表数据
  61. }
  62. /**
  63. * 页面: 查看&修改 "分类信息"
  64. * 地址:http://cas.lishuy.com/?c=Admin_Category_Index&a=PageShow&id=nn
  65. * 参数:id "分类信息"id
  66. */
  67. public function doPageShow() {
  68. $id = Request::g ( 'id' );
  69. $CategoryData = $this->objDCategory->get ( $id );
  70. $this->tpl = 'admin/category/edit';
  71. $title = '编辑分类信息';
  72. $this->setOutput('title', $title);
  73. $this->setOutput('menu_active', array('name' => 'categorylist', 'item' => 'list')); //激活菜单
  74. $this->addNavMenu('分类设置');
  75. $this->addNavMenu('分类列表', Request::schemeDomain() . '/?c=Admin_Category_index&a=PageList');
  76. $this->addNavMenu($title);
  77. $this->setOutput('pagePublicData', $this->getPagePublicData()); // 后台管理相关数据
  78. $this->setOutput ( 'CategoryData', $CategoryData ); // 当前"分类信息"内容
  79. }
  80. /**
  81. * 事件:创建"分类信息"
  82. * 地址:http://cas.lishuy.com/index.php?c=Admin_Category_Index&a=ReqCreate
  83. * 参数:见方法内
  84. */
  85. public function doReqCreate() {
  86. $tableInfo = $_POST;
  87. $operator_uid = $this->operatorData ['uid'];
  88. $info = array_merge($tableInfo, array(
  89. 'operator_uid' => $operator_uid
  90. ));
  91. $tmpResult = $this->objDCategory->add ( $info );
  92. if (!$tmpResult) {
  93. $this->ajax_fail_exit('添加新分类失败');
  94. }
  95. $this->ajax_success_exit();
  96. }
  97. /**
  98. * 事件: 修改"分类信息"
  99. * 地址:http://cas.lishuy.com/index.php?c=Admin_Category_Index&a=ReqUp
  100. * 参数:见方法内
  101. */
  102. public function doReqUp() {
  103. $tableInfo = $_POST;
  104. $id = $tableInfo['id'];
  105. unset($tableInfo['id']);
  106. $operator_uid = $this->operatorData ['uid'];
  107. $info = array_merge($tableInfo, array(
  108. 'operator_uid' => $operator_uid
  109. ));
  110. $tmpResult = $this->objDCategory->modify ( $info, array (
  111. 'id' => $id
  112. ) );
  113. if (!$tmpResult->isSuccess()) {
  114. $this->ajax_fail_exit($tmpResult->getData());
  115. }
  116. $this->ajax_success_exit();
  117. }
  118. /**
  119. * 事件: 删除"分类信息"
  120. * 地址:http://cas.lishuy.com/index.php?c=Admin_Category_Index&a=ReqDel
  121. * 参数:见方法内
  122. */
  123. public function doReqDel() {
  124. $id = Request::p ( 'id' );
  125. $this->objDCategory->delete ( array (
  126. 'id' => $id
  127. ) );
  128. // TODO 根据前端自定义返回结果或跳转
  129. header ( "Location: " . Request::schemeDomain () . "/?c=Admin_Category_Index&a=PageList" );
  130. exit ();
  131. }
  132. public function doDelete() {
  133. \KIF\Core\PermissionController::requireCompetence();
  134. $id = Request::p('id');
  135. if (!Verify::unsignedInt($id)) {
  136. $this->ajax_fail_exit('无效id');
  137. }
  138. $this->objDCategory->delete ( array (
  139. 'id' => $id
  140. ) );
  141. $this->ajax_success_exit();
  142. }
  143. public function display() {
  144. return $this->render ();
  145. }
  146. }