SocietyAction.class.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. class SocietyAction extends CommonAction
  3. {
  4. protected static function str_trim($str)
  5. {
  6. $str = strim($str);
  7. $str = preg_replace("@<script(.*?)</script>@is", "", $str);
  8. $str = preg_replace("@<iframe(.*?)</iframe>@is", "", $str);
  9. $str = preg_replace("@<style(.*?)</style>@is", "", $str);
  10. return preg_replace("@<(.*?)>@is", "", $str);
  11. }
  12. // 公会列表
  13. public function index()
  14. {
  15. $where = 's.user_id = u.id';
  16. if (isset($_REQUEST['name'])) {
  17. $where .= ' and s.name like \'%' . addslashes($_REQUEST['name']) . '%\'';
  18. }
  19. if (isset($_REQUEST['nick_name'])) {
  20. $where .= ' and u.nick_name like \'%' . addslashes($_REQUEST['nick_name']) . '%\'';
  21. }
  22. if ($_REQUEST['begin_time']) {
  23. $where .= ' and s.create_time>=' . strtotime($_REQUEST['begin_time']);
  24. }
  25. if ($_REQUEST['end_time']) {
  26. $where .= ' and s.create_time<=' . strtotime($_REQUEST['end_time']);
  27. }
  28. if (!isset($_REQUEST['status'])) {
  29. $_REQUEST['status'] = -1;
  30. }
  31. if ($_REQUEST['status'] != -1) {
  32. $where .= ' and s.status=' . intval($_REQUEST['status']);
  33. }else{
  34. $where .= ' and s.status!=4 ';
  35. }
  36. $model = M('society');
  37. $table = DB_PREFIX .'society s,'.DB_PREFIX .'user u';
  38. $count = $model->table($table)->where($where)->count();
  39. $p = new Page($count, $listRows = 10);
  40. if ($count) {
  41. $field = 's.*,u.nick_name';
  42. $list = $model->table($table)->where($where)->field($field)->order('s.id')->limit($p->firstRow . ',' . $p->listRows)->select();
  43. foreach ($list as $key => $value) {
  44. $list[$key]['create_time'] = to_date($value['create_time']);
  45. if($list[$key]['logo'] !=''){
  46. $list[$key]['logo'] = get_spec_image($value['logo'],35,35);
  47. }
  48. }
  49. }
  50. $this->assign("page", $p->show());
  51. $this->assign("list", $list);
  52. $this->display();
  53. }
  54. //公会详情
  55. public function edit()
  56. {
  57. $id = intval($_REQUEST['id']);
  58. $model = M('society');
  59. $table = DB_PREFIX .'society s,'.DB_PREFIX .'user u';
  60. $field = 's.*,u.nick_name';
  61. $where = 's.user_id = u.id and s.id=' . $id;
  62. $data = $model->table($table)->where($where)->field($field)->find();
  63. if ($data) {
  64. $data['create_time'] = to_date($data['create_time']);
  65. $data['logo'] = get_spec_image($data['logo']);
  66. }
  67. $this->assign('vo', $data);
  68. $this->display();
  69. }
  70. //更新公会信息
  71. public function update()
  72. {
  73. $id = intval($_REQUEST['id']);
  74. $status = intval($_REQUEST['status']);
  75. $memo = self::str_trim($_REQUEST['memo']);
  76. $manifesto = self::str_trim($_REQUEST['manifesto']);
  77. $name = self::str_trim($_REQUEST['name']);
  78. $refund_rate = $_REQUEST['refund_rate'];
  79. if (floatval($refund_rate) < 0 || floatval($refund_rate) > 1){
  80. $this->error("提现比例范围为0~1");
  81. }elseif (floatval($refund_rate) == 0){
  82. $m_config = load_auto_cache('m_config');
  83. $refund_rate = $m_config['society_public_rate'];
  84. }
  85. $this->assign("jumpUrl", u(MODULE_NAME . "/edit", array("id" => $id)));
  86. if (!$id) {
  87. $this->error("参数错误");
  88. }
  89. $modal = M('society');
  90. $society = $modal->field('name,user_id,status')->where("id=" . $id)->find();
  91. $log_info = $society['name'];
  92. $user_id = $society['user_id'];
  93. $status = $society['status'] == '1' ? 1 : $status;
  94. $res = $modal->save(array('memo' => $memo,'name'=>$name,'manifesto'=>$manifesto,'status' => $status,'refund_rate' => $refund_rate,'id' => $id));
  95. M('user')->save(array('society_id' => $id, 'society_chieftain' => 1, 'id' => $user_id));
  96. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/BaseRedisService.php');
  97. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/UserRedisService.php');
  98. $user_redis = new UserRedisService();
  99. $user_redis->update_db($user_id, array('society_id' => $id, 'family_chieftain' => 1));
  100. if (false === $res) {
  101. //错误提示
  102. save_log($log_info . L("UPDATE_FAILED"), 0);
  103. $this->error(L("UPDATE_FAILED"), 0, $log_info . L("UPDATE_FAILED"));
  104. } else {
  105. //成功提示
  106. clear_auto_cache("banner_list");
  107. load_auto_cache("banner_list");
  108. save_log($log_info . L("UPDATE_SUCCESS"), 1);
  109. $this->success(L("UPDATE_SUCCESS"));
  110. }
  111. }
  112. public function view()
  113. {
  114. $id = intval($_REQUEST['id']);
  115. $model = M('society');
  116. $field = 'name';
  117. $where = 'id=' . $id;
  118. $society = $model->where($where)->field($field)->find();
  119. $table = DB_PREFIX .'society s,'.DB_PREFIX .'user u,'.DB_PREFIX .'society_apply sa';
  120. $where = 'u.id =sa.user_id and s.id ='.$id.' and sa.society_id='.$id ;
  121. if (!isset($_REQUEST['status'])) {
  122. $_REQUEST['status'] = -1;
  123. }
  124. if ($_REQUEST['status'] != -1) {
  125. $where .= ' and sa.status=' . intval($_REQUEST['status']);
  126. } else {
  127. $where .= ' and sa.status<3';
  128. }
  129. $count = $model->table($table)->where($where)->count();
  130. $p = new Page($count, $listRows = 20);
  131. if ($count) {
  132. $field = 's.*,u.nick_name,u.id,u.head_image,sa.society_id,sa.`status`';
  133. $list = $model->table($table)->where($where)->field($field)->order('s.id')->limit($p->firstRow . ',' . $p->listRows)->select();
  134. foreach ($list as $key => $value) {
  135. $list[$key]['create_time'] = to_date($value['create_time']);
  136. $list[$key]['head_image'] = get_spec_image($value['head_image']);
  137. }
  138. }
  139. $this->assign('id', $id);
  140. $this->assign('society', $society);
  141. $this->assign('list', $list);
  142. $this->assign("page", $p->show());
  143. $this->display();
  144. }
  145. //解散公会
  146. public function dissolve(){
  147. $id = intval($_REQUEST['id']);
  148. if (!$id) {
  149. $this->error("参数错误");
  150. }
  151. $model = M('society');
  152. $society_member =$GLOBALS['db']->getOne( "select count(id) from ".DB_PREFIX."society_apply where (status=1 or status=3) and society_id=".$id);
  153. if (intval($society_member) > 1){
  154. $this->error("公会还有其他未退出的成员");
  155. }else{
  156. $data = array();
  157. $data['society_id'] = 0;
  158. $data['society_chieftain'] = 0;
  159. $user_id = $model->where('id='.$id)->getField('user_id');
  160. M('user')->where('id='.$user_id)->save($data);
  161. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/BaseRedisService.php');
  162. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/UserRedisService.php');
  163. $user_redis = new UserRedisService();
  164. $user_redis->update_db($user_id, array('society_id' => 0, 'society_chieftain' => 0));
  165. //将请求加入公会的申请设为拒绝
  166. M('society_apply')->where('society_id='.$id)->setField("status",2);
  167. //status=4 已解散工会
  168. $res = $model->where("id=".$id)->setField("status",4);
  169. $log_info = $id;
  170. if ($res === false) {
  171. //错误提示
  172. save_log($log_info . "公会解散失败", 0);
  173. $this->error(L("公会解散失败"), 0, $log_info . L("公会解散失败"));
  174. } else {
  175. //成功提示
  176. save_log($log_info . L("公会解散成功"), 1);
  177. $this->success(L("公会解散成功"));
  178. }
  179. }
  180. }
  181. }