EduClassOfflineAction.class.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. class EduClassOfflineAction extends CommonAction
  3. {
  4. public function index()
  5. {
  6. $user_id = intval($_REQUEST['user_id']);
  7. if ($user_id > 0) {
  8. $this->assign("user_id", $user_id);
  9. }
  10. $map = array('is_delete' => 0);
  11. $title = strim($_REQUEST['title']);
  12. if (!empty($title)) {
  13. $map['title'] = array('like', '%' . $title . '%');
  14. }
  15. $this->assign("default_map", $map);
  16. parent::index();
  17. }
  18. public function add()
  19. {
  20. $user_id = intval($_REQUEST['user_id']);
  21. $org = M('EduOrg')->where(array('user_id' => $user_id))->find();
  22. if (empty($org)) {
  23. throw new Exception;
  24. }
  25. if (empty($org['logo']) || empty($org['description']) || empty($org['members'])) {
  26. $this->assign("jumpUrl", u("EduOrg/edit", array('id' => $org['id'])));
  27. $this->error("请完善机构信息");
  28. }
  29. $this->assign('user_id', $user_id);
  30. $this->display();
  31. }
  32. public function edit()
  33. {
  34. $id = intval($_REQUEST ['id']);
  35. $condition['id'] = $id;
  36. $vo = M(MODULE_NAME)->where($condition)->find();
  37. $this->assign('vo', $vo);
  38. $this->display();
  39. }
  40. public function insert()
  41. {
  42. B('FilterString');
  43. $data = M(MODULE_NAME)->create();
  44. //开始验证有效性
  45. $this->assign("jumpUrl", u(MODULE_NAME . "/add", array('user_id' => $data['user_id'])));
  46. if (!check_empty($data['title'])) {
  47. $this->error("请输入课程标题");
  48. }
  49. if (!check_empty($data['image'])) {
  50. $this->error("请上传图片");
  51. }
  52. $org_id = M('EduOrg')->where(array('user_id' => $data['user_id']))->getField('id');
  53. if (!$org_id) {
  54. $this->error("操作不正确");
  55. }
  56. if ($data['price'] <= 0) {
  57. $this->error("请输入价格");
  58. }
  59. if ($data['class_num'] < 1) {
  60. $this->error("请输入课时数量");
  61. }
  62. // 更新数据
  63. $log_info = $data['title'];
  64. $list = M(MODULE_NAME)->add($data);
  65. if (false !== $list) {
  66. //成功提示
  67. save_log($log_info . L("INSERT_SUCCESS"), 1);
  68. $this->success(L("INSERT_SUCCESS"));
  69. } else {
  70. //错误提示
  71. save_log($log_info . L("INSERT_FAILED"), 0);
  72. $this->error(L("INSERT_FAILED"));
  73. }
  74. }
  75. public function update()
  76. {
  77. B('FilterString');
  78. $data = M(MODULE_NAME)->create();
  79. $log_info = M(MODULE_NAME)->where("id=" . intval($data['id']))->getField("title");
  80. //开始验证有效性
  81. $this->assign("jumpUrl", u(MODULE_NAME . "/edit", array("id" => $data['id'])));
  82. if (!check_empty($data['title'])) {
  83. $this->error("请输入课程标题");
  84. }
  85. if ($data['price'] <= 0) {
  86. $this->error("请输入价格");
  87. }
  88. if ($data['class_num'] < 1) {
  89. $this->error("请输入课时数量");
  90. }
  91. $list = M(MODULE_NAME)->save($data);
  92. if (false !== $list) {
  93. //成功提示
  94. save_log($log_info . L("UPDATE_SUCCESS"), 1);
  95. $this->success(L("UPDATE_SUCCESS"));
  96. } else {
  97. //错误提示
  98. save_log($log_info . L("UPDATE_FAILED"), 0);
  99. $this->error(L("UPDATE_FAILED"), 0, $log_info . L("UPDATE_FAILED"));
  100. }
  101. }
  102. public function delete()
  103. {
  104. //删除指定记录
  105. $ajax = intval($_REQUEST['ajax']);
  106. $id = $_REQUEST ['id'];
  107. if (isset ($id)) {
  108. $info = M(MODULE_NAME)->where(array('id' => $id))->getField('title');
  109. $list = M(MODULE_NAME)->save(array('id' => $id, 'is_delete' => 1));
  110. if ($list !== false) {
  111. save_log($info . l("DELETE_SUCCESS"), 1);
  112. $this->success(l("DELETE_SUCCESS"), $ajax);
  113. } else {
  114. save_log($info . l("DELETE_FAILED"), 0);
  115. $this->error(l("DELETE_FAILED"), $ajax);
  116. }
  117. } else {
  118. $this->error(l("INVALID_OPERATION"), $ajax);
  119. }
  120. }
  121. }