AdAction.class.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. class AdAction extends CommonAction
  3. {
  4. public function index()
  5. {
  6. if(trim($_REQUEST['ad_info'])!='')
  7. {
  8. $map['title'] = array('like','%'.trim($_REQUEST['ad_info']).'%');
  9. }
  10. if (method_exists ( $this, '_filter' )) {
  11. $this->_filter ( $map );
  12. }
  13. $name=$this->getActionName();
  14. $model = D ($name);
  15. if (! empty ( $model )) {
  16. $this->_list ( $model, $map );
  17. }
  18. // $map = array();
  19. // $this->assign("default_map", $map);
  20. // parent::index();
  21. $this->display ();
  22. }
  23. public function add()
  24. {
  25. $this->assign("place_list", M("AdPlace")->findAll());
  26. $this->assign("new_sort", 10);
  27. rm_auto_cache("ad_list");
  28. $this->display();
  29. }
  30. public function delete(){
  31. //删除指定记录
  32. $ajax = intval($_REQUEST['ajax']);
  33. $id = $_REQUEST ['id'];
  34. if (isset ( $id )) {
  35. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  36. $rel_data = M(MODULE_NAME)->where($condition)->findAll();
  37. foreach($rel_data as $data)
  38. {
  39. $info[] = $data['title'];
  40. }
  41. if($info) $info = implode(",",$info);
  42. $list = M(MODULE_NAME)->where ( $condition )->delete();
  43. if ($list!==false) {
  44. rm_auto_cache("ad_list");
  45. save_log($info.l("DELETE_SUCCESS"),1);
  46. clear_auto_cache("get_help_cache");
  47. clear_auto_cache("article_notice");
  48. $this->success (l("DELETE_SUCCESS"),$ajax);
  49. } else {
  50. save_log($info.l("DELETE_FAILED"),0);
  51. $this->error (l("DELETE_FAILED"),$ajax);
  52. }
  53. } else {
  54. $this->error (l("INVALID_OPERATION"),$ajax);
  55. }
  56. }
  57. public function edit()
  58. {
  59. $id = intval($_REQUEST ['id']);
  60. $condition['id'] = $id;
  61. $vo = M(MODULE_NAME)->where($condition)->find();
  62. $this->assign('vo', $vo);
  63. $this->assign("place_list", M("AdPlace")->findAll());
  64. $this->display();
  65. }
  66. public function insert()
  67. {
  68. B('FilterString');
  69. $data = M(MODULE_NAME)->create();
  70. //开始验证有效性
  71. $this->assign("jumpUrl", u(MODULE_NAME . "/add"));
  72. if (!check_empty($data['title'])) {
  73. $this->error("请输入标题");
  74. }
  75. if (!check_empty($data['url'])) {
  76. $this->error("请输入跳转地址");
  77. }
  78. if (!check_empty($data['image'])) {
  79. $this->error("请上传广告图");
  80. }
  81. if (!check_empty($data['place_id'])) {
  82. $this->error("请选择区域");
  83. }
  84. // 更新数据
  85. $log_info = $data['title'];
  86. $list = M(MODULE_NAME)->add($data);
  87. if (false !== $list) {
  88. rm_auto_cache("ad_list");
  89. clear_auto_cache("ad_list", $data['place_id']);
  90. load_auto_cache("ad_list", $data['place_id']);
  91. //成功提示
  92. save_log($log_info . L("INSERT_SUCCESS"), 1);
  93. $this->success(L("INSERT_SUCCESS"));
  94. } else {
  95. //错误提示
  96. save_log($log_info . L("INSERT_FAILED"), 0);
  97. $this->error(L("INSERT_FAILED"));
  98. }
  99. }
  100. public function update()
  101. {
  102. B('FilterString');
  103. $data = M(MODULE_NAME)->create();
  104. $log_info = M(MODULE_NAME)->where("id=" . intval($data['id']))->getField("title");
  105. //开始验证有效性
  106. $this->assign("jumpUrl", u(MODULE_NAME . "/edit", array("id" => $data['id'])));
  107. if (!check_empty($data['title'])) {
  108. $this->error("请输入标题");
  109. }
  110. if (!check_empty($data['image'])) {
  111. $this->error("请上传广告图");
  112. }
  113. if (!check_empty($data['title'])) {
  114. $this->error("请输入标题");
  115. }
  116. if (!check_empty($data['place_id'])) {
  117. $this->error("请选择区域");
  118. }
  119. $list = M(MODULE_NAME)->save($data);
  120. if (false !== $list) {
  121. rm_auto_cache("ad_list");
  122. clear_auto_cache("ad_list", $data['place_id']);
  123. load_auto_cache("ad_list", $data['place_id']);
  124. //成功提示
  125. save_log($log_info . L("UPDATE_SUCCESS"), 1);
  126. $this->success(L("UPDATE_SUCCESS"));
  127. } else {
  128. //错误提示
  129. save_log($log_info . L("UPDATE_FAILED"), 0);
  130. $this->error(L("UPDATE_FAILED"), 0, $log_info . L("UPDATE_FAILED"));
  131. }
  132. }
  133. }