EduTeacherAction.class.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. class EduTeacherAction extends CommonAction
  3. {
  4. public function index()
  5. {
  6. $map = array('is_effect' => 1);
  7. $title = strim($_REQUEST['title']);
  8. if (!empty($title)) {
  9. $this->assign("title", $title);
  10. unset($_REQUEST['title']);
  11. $users = D('User')->where(array(
  12. 'nick_name' => array(
  13. 'like',
  14. '%' . $title . '%'
  15. )
  16. ))->field('id')->findAll();
  17. $user_ids = array_column($users, 'id');
  18. $where = array(
  19. 'title' => array('like', '%' . $title . '%'),
  20. 'user_id' => array('in', $user_ids),
  21. '_logic' => 'OR',
  22. );
  23. $map['_complex'] = $where;
  24. }
  25. $this->assign("default_map", $map);
  26. parent::index();
  27. }
  28. //设置推荐
  29. public function set_recommend()
  30. {
  31. $id = intval($_REQUEST['id']);
  32. $teacher = M(MODULE_NAME)->where("id=" . $id)->find(); //当前状态
  33. $user = M('User')->where("id=" . $teacher['user_id'])->find(); //当前状态
  34. // 审核未通过
  35. if ($user['is_authentication'] != 2) {
  36. $this->ajaxReturn(0, l("RECOMMEND_FAILED"), 0);
  37. } else {
  38. $n_is_effect = $teacher['is_recommend'] == 0 ? 1 : 0; //需设置的状态
  39. M(MODULE_NAME)->where("id=" . $id)->setField("is_recommend", $n_is_effect);
  40. save_log($user['authentication_name'] . l("SET_RECOMMEND_" . $n_is_effect), 1);
  41. $this->ajaxReturn($n_is_effect, l("RECOMMEND_FAILED"), 1);
  42. }
  43. }
  44. public function set_sort()
  45. {
  46. $id = intval($_REQUEST['id']);
  47. $sort = intval($_REQUEST['sort']);
  48. $category = M(MODULE_NAME)->where("id=" . $id)->find();
  49. if (!check_sort($sort)) {
  50. $this->error(l("SORT_FAILED"), 1);
  51. }
  52. M(MODULE_NAME)->where("id=" . $id)->setField("sort", $sort);
  53. save_log($category['title'] . l("SORT_SUCCESS"), 1);
  54. $this->success(l("SORT_SUCCESS"), 1);
  55. }
  56. public function edit()
  57. {
  58. $id = intval($_REQUEST ['id']);
  59. $condition['id'] = $id;
  60. $vo = M(MODULE_NAME)->where($condition)->find();
  61. $vo['tags'] = empty($vo['tags']) ? array() : explode(',', $vo['tags']);
  62. $tags = M("EduTags")->where('type=0')->findAll();
  63. foreach ($tags as &$tag) {
  64. if (in_array($tag['title'], $vo['tags'])) {
  65. $tag['is_checked'] = true;
  66. }
  67. }
  68. unset($tag);
  69. $this->assign('vo', $vo);
  70. $this->assign("tags", $tags);
  71. $m_config = load_auto_cache("m_config");
  72. $this->assign('secret_id', $m_config['qcloud_secret_id']);
  73. $this->display();
  74. }
  75. public function update()
  76. {
  77. B('FilterString');
  78. $data = M(MODULE_NAME)->create();
  79. //开始验证有效性
  80. $this->assign("jumpUrl", u(MODULE_NAME . "/edit", array("id" => $data['id'])));
  81. if (!check_empty($data['desc_image'])) {
  82. $this->error("请上传宣传图片");
  83. }
  84. $teacher = M(MODULE_NAME)->where("id=" . intval($data['id']))->find();
  85. if (empty($data['tags'])) {
  86. $data['tags'] = array();
  87. }
  88. $data['tags'] = implode(',', array_slice($data['tags'], 0, 3));
  89. $log_info = $teacher['title'];
  90. $list = M(MODULE_NAME)->save($data);
  91. if (false !== $list) {
  92. if (!empty($data['file_id']) && $teacher['file_id'] != $data['file_id']) {
  93. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/common_edu.php');
  94. upload_edu_video($data['file_id'], 'edu_teacher', 'desc_video', $data['id']);
  95. }
  96. //更新众筹直播标签
  97. // if($teacher['tags'] != $data['tags']){
  98. // fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/common_edu.php');
  99. // update_deal_tags($teacher['user_id'],$data['tags']);
  100. // }
  101. //成功提示
  102. save_log($log_info . L("UPDATE_SUCCESS"), 1);
  103. $this->success(L("UPDATE_SUCCESS"));
  104. } else {
  105. //错误提示
  106. save_log($log_info . L("UPDATE_FAILED"), 0);
  107. $this->error(L("UPDATE_FAILED"), 0, $log_info . L("UPDATE_FAILED"));
  108. }
  109. }
  110. }