MissionAction.class.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维p2p借贷系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. class MissionAction extends CommonAction
  10. {
  11. protected static $title = [
  12. 0 => '在线任务',
  13. 1 => '玩游戏任务',
  14. 2 => '打赏主播任务',
  15. 3 => '分享主播任务',
  16. 4 => '关注主播任务',
  17. ];
  18. public function index()
  19. {
  20. // $this->__set('default_map',[]);
  21. $_REQUEST['_order'] = $_REQUEST['_order'] ? $_REQUEST['_order'] : 'type`,`sort';
  22. $_REQUEST['_sort'] = $_REQUEST['_sort'] ? $_REQUEST['_sort'] : 'desc';
  23. $this->assign("default_map", 'is_effect = 1');
  24. parent::index();
  25. }
  26. public function add()
  27. {
  28. $this->assign("title", self::$title);
  29. $this->assign("new_sort", M(MODULE_NAME)->max("sort") + 1);
  30. $this->display();
  31. }
  32. public function edit()
  33. {
  34. $this->assign("title", self::$title);
  35. $id = intval($_REQUEST['id']);
  36. $condition['id'] = $id;
  37. $vo = M(MODULE_NAME)->where($condition)->find();
  38. $this->assign('vo', $vo);
  39. $this->display();
  40. }
  41. //彻底删除指定记录
  42. public function foreverdelete()
  43. {
  44. //彻底删除指定记录
  45. $ajax = intval($_REQUEST['ajax']);
  46. $id = $_REQUEST['id'];
  47. if (isset($id)) {
  48. $types = [];
  49. $condition = array('id' => array('in', explode(',', $id)));
  50. $rel_data = M(MODULE_NAME)->where($condition)->findAll();
  51. foreach ($rel_data as $data) {
  52. $info[] = $data['name'];
  53. if (!in_array($data['type'], $types)) {
  54. $types[] = $data['type'];
  55. }
  56. }
  57. if ($info) {
  58. $info = implode(",", $info);
  59. }
  60. $list = M(MODULE_NAME)->where($condition)->delete();
  61. if ($list !== false) {
  62. foreach ($types as $type) {
  63. self::orderSort($type);
  64. }
  65. save_log($info . l("FOREVER_DELETE_SUCCESS"), 1);
  66. clear_auto_cache("get_help_cache");
  67. $this->success(l("FOREVER_DELETE_SUCCESS"), $ajax);
  68. } else {
  69. save_log($info . l("FOREVER_DELETE_FAILED"), 0);
  70. $this->error(l("FOREVER_DELETE_FAILED"), $ajax);
  71. }
  72. } else {
  73. $this->error(l("INVALID_OPERATION"), $ajax);
  74. }
  75. }
  76. public function insert()
  77. {
  78. B('FilterString');
  79. $ajax = intval($_REQUEST['ajax']);
  80. $data = M(MODULE_NAME)->create();
  81. //开始验证有效性
  82. $this->assign("jumpUrl", u(MODULE_NAME . "/add"));
  83. if (!check_empty($data['name'])) {
  84. $this->error("请输入名称");
  85. }
  86. // 更新数据
  87. $log_info = $data['name'];
  88. $list = M(MODULE_NAME)->add($data);
  89. if (false !== $list) {
  90. self::orderSort($data['type']);
  91. //成功提示
  92. save_log($log_info . L("INSERT_SUCCESS"), 1);
  93. clear_auto_cache("get_help_cache");
  94. $this->success(L("INSERT_SUCCESS"));
  95. } else {
  96. //错误提示
  97. save_log($log_info . L("INSERT_FAILED"), 0);
  98. $this->error(L("INSERT_FAILED"));
  99. }
  100. }
  101. public function update()
  102. {
  103. B('FilterString');
  104. $data = M(MODULE_NAME)->create();
  105. $data['is_order'] = 0;
  106. $type = M(MODULE_NAME)->where("id=" . intval($data['id']))->getField("type");
  107. $log_info = M(MODULE_NAME)->where("id=" . intval($data['id']))->getField("name");
  108. //开始验证有效性
  109. $this->assign("jumpUrl", u(MODULE_NAME . "/edit", array("id" => $data['id'])));
  110. if (!check_empty($data['name'])) {
  111. $this->error("请输入名称");
  112. }
  113. // 更新数据
  114. $list = M(MODULE_NAME)->save($data);
  115. if (false !== $list) {
  116. self::orderSort($type);
  117. self::orderSort($data['type']);
  118. //成功提示
  119. save_log($log_info . L("UPDATE_SUCCESS"), 1);
  120. clear_auto_cache("get_help_cache");
  121. $users = M("User")->where("authent_list_id = " . intval($data['id']))->findAll();
  122. if (sizeof($users) > 0) {
  123. $user_ids = array_column($users, "id");
  124. $condition['id'] = array('in', $user_ids);
  125. $condition['is_authentication'] = 2;
  126. M("User")->where($condition)->setField("v_icon", get_spec_image($data['icon']));
  127. user_deal_to_reids($user_ids);
  128. }
  129. $this->success(L("UPDATE_SUCCESS"));
  130. } else {
  131. //错误提示
  132. save_log($log_info . L("UPDATE_FAILED"), 0);
  133. $this->error(L("UPDATE_FAILED"), 0, $log_info . L("UPDATE_FAILED"));
  134. }
  135. }
  136. public function set_sort()
  137. {
  138. $id = intval($_REQUEST['id']);
  139. $sort = intval($_REQUEST['sort']);
  140. $log_info = M(MODULE_NAME)->where("id=" . $id)->getField("name");
  141. $type = M(MODULE_NAME)->where("id=" . $id)->getField("type");
  142. if (!check_sort($sort)) {
  143. $this->error(l("SORT_FAILED"), 1);
  144. }
  145. M(MODULE_NAME)->save(["sort" => $sort, 'id' => $id, 'is_sort' => 0]);
  146. self::orderSort($type);
  147. save_log($log_info . l("SORT_SUCCESS"), 1);
  148. clear_auto_cache("get_help_cache");
  149. $this->success(l("SORT_SUCCESS"), 1);
  150. }
  151. public function set_effect()
  152. {
  153. $id = intval($_REQUEST['id']);
  154. $ajax = intval($_REQUEST['ajax']);
  155. $info = M(MODULE_NAME)->where("id=" . $id)->getField("adm_name");
  156. $c_is_effect = M(MODULE_NAME)->where("id=" . $id)->getField("is_effect"); //当前状态
  157. $type = M(MODULE_NAME)->where("id=" . $id)->getField("type"); //当前状态
  158. if (conf("DEFAULT_ADMIN") == $info) {
  159. $this->ajaxReturn($c_is_effect, l("DEFAULT_ADMIN_CANNOT_EFFECT"), 1);
  160. }
  161. $n_is_effect = $c_is_effect == 0 ? 1 : 0; //需设置的状态
  162. M(MODULE_NAME)->save(["is_effect" => $n_is_effect, 'id' => $id]);
  163. self::orderSort($type);
  164. save_log($info . l("SET_EFFECT_" . $n_is_effect), 1);
  165. $this->ajaxReturn($n_is_effect, l("SET_EFFECT_" . $n_is_effect), 1);
  166. }
  167. protected static function orderSort($type = 0)
  168. {
  169. $mod = M(MODULE_NAME);
  170. $list = $mod->where(array('is_effect' => 1, 'type' => $type))->order('sort,is_order')->select();
  171. if ($list) {
  172. $order_list = array();
  173. foreach ($list as $value) {
  174. if ($value['sort'] > 0) {
  175. $order_list[] = $value;
  176. }
  177. }
  178. foreach ($list as $value) {
  179. if ($value['sort'] <= 0) {
  180. $order_list[] = $value;
  181. }
  182. }
  183. foreach ($order_list as $key => $value) {
  184. if (!($key + 1 == $value['sort'] && $value['is_order'])) {
  185. $mod->where(array(
  186. 'id' => $value['id'],
  187. ))->save(array(
  188. 'sort' => $key + 1,
  189. 'is_order' => 1,
  190. ));
  191. }
  192. }
  193. }
  194. }
  195. }