EduOrgAction.class.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. class EduOrgAction 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. );
  22. $where['_logic'] = 'or';
  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. $org = M(MODULE_NAME)->where("id=" . $id)->find(); //当前状态
  33. $user = M('User')->where("id=" . $org['user_id'])->find(); //当前状态
  34. if ($user['is_authentication'] != 2) {
  35. $this->ajaxReturn(0, l("RECOMMEND_FAILED"), 0);
  36. } else {
  37. $n_is_effect = $org['is_recommend'] == 0 ? 1 : 0; //需设置的状态
  38. M(MODULE_NAME)->where("id=" . $id)->setField("is_recommend", $n_is_effect);
  39. save_log($org['title'] . l("SET_RECOMMEND_" . $n_is_effect), 1);
  40. $this->ajaxReturn($n_is_effect, l("SET_RECOMMEND_" . $n_is_effect), 1);
  41. }
  42. }
  43. public function set_sort()
  44. {
  45. $id = intval($_REQUEST['id']);
  46. $sort = intval($_REQUEST['sort']);
  47. $category = M(MODULE_NAME)->where("id=" . $id)->find();
  48. if (!check_sort($sort)) {
  49. $this->error(l("SORT_FAILED"), 1);
  50. }
  51. M(MODULE_NAME)->where("id=" . $id)->setField("sort", $sort);
  52. save_log($category['title'] . l("SORT_SUCCESS"), 1);
  53. $this->success(l("SORT_SUCCESS"), 1);
  54. }
  55. public function edit()
  56. {
  57. $id = intval($_REQUEST ['id']);
  58. $condition['id'] = $id;
  59. $vo = M(MODULE_NAME)->where($condition)->find();
  60. $images = json_decode($vo['images'], true);
  61. $members = json_decode($vo['members'], true);
  62. $vo['tags'] = empty($vo['tags']) ? array() : explode(',', $vo['tags']);
  63. $tags = M("EduTags")->where('type=1')->findAll();
  64. foreach ($tags as &$tag) {
  65. if (in_array($tag['title'], $vo['tags'])) {
  66. $tag['is_checked'] = true;
  67. }
  68. }
  69. unset($tag);
  70. $this->assign('vo', $vo);
  71. $this->assign('images', $images);
  72. $this->assign('image_num', count($images));
  73. $this->assign('members', $members);
  74. $this->assign('member_num', count($members));
  75. $this->assign("tags", $tags);
  76. $m_config = load_auto_cache("m_config");
  77. $this->assign('secret_id', $m_config['qcloud_secret_id']);
  78. $this->display();
  79. }
  80. public function update()
  81. {
  82. B('FilterString');
  83. $data = M(MODULE_NAME)->create();
  84. $org = M(MODULE_NAME)->where("id=" . intval($data['id']))->find();
  85. //开始验证有效性
  86. $this->assign("jumpUrl", u(MODULE_NAME . "/edit", array("id" => $data['id'])));
  87. if (!check_empty($data['logo'])) {
  88. $this->error("请上传 Logo 图片");
  89. }
  90. $data['images'] = json_encode(array_values(array_filter($data['images'])));
  91. $data['members'] = json_encode(array_values(array_filter($data['members'], function ($m) {
  92. return !empty($m['name']) && !empty($m['avatar']);
  93. })));
  94. if (empty($data['tags'])) {
  95. $data['tags'] = array();
  96. }
  97. $data['tags'] = implode(',', array_slice($data['tags'], 0, 3));
  98. $log_info = $org['title'];
  99. $list = M(MODULE_NAME)->save($data);
  100. if (false !== $list) {
  101. if (!empty($data['file_id']) && $org['file_id'] != $data['file_id']) {
  102. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/common_edu.php');
  103. upload_edu_video($data['file_id'], 'edu_org', 'desc_video', $data['id']);
  104. }
  105. //更新众筹直播标签
  106. // if($org['tags'] != $data['tags']){
  107. // fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/common_edu.php');
  108. // update_deal_tags($org['user_id'],$data['tags']);
  109. // }
  110. //成功提示
  111. save_log($log_info . L("UPDATE_SUCCESS"), 1);
  112. $this->success(L("UPDATE_SUCCESS"));
  113. } else {
  114. //错误提示
  115. save_log($log_info . L("UPDATE_FAILED"), 0);
  116. $this->error(L("UPDATE_FAILED"), 0, $log_info . L("UPDATE_FAILED"));
  117. }
  118. }
  119. }