Index.class.php 5.0 KB

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