PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/web/admin/module/center/all_notice_repay.php

https://gitlab.com/xusasuke6/Slg_php
PHP | 307 lines | 296 code | 10 blank | 1 comment | 20 complexity | 92222539ccc2c8e47b137ea69da94c56 MD5 | raw file
  1. <?php
  2. define('IN_DATANG_SYSTEM', true);
  3. include "../../../config/config.php";
  4. include "../../../admin/class/admin_log_class.php";
  5. include SYSDIR_ADMIN."/include/global.php";
  6. //获取管理员代理权限
  7. $sql_user_agents = "select agent_id from ".T_ADMIN_USER." where uid=".$_SESSION['uid'];
  8. $result = $db->fetchOne($sql_user_agents);
  9. $admin_user_agents = explode(' ', $result['agent_id']);
  10. foreach($admin_user_agents as $v) {
  11. $ADMIN_AGENT_NAME[$v] = $AGENT_NAME[$v];
  12. }
  13. $agent_list = implode(',', $admin_user_agents);
  14. foreach($ALL_SERVER_LIST as $key=>$value) {
  15. if($key == 0) continue;
  16. foreach($value as $k=>$v) {
  17. $serStr = "S".$k;
  18. if($v['stat']==1)
  19. $servers[$key][$k] = $serStr;
  20. }
  21. }
  22. $action_agent = isset($_REQUEST['radio_agent'])?$_REQUEST['radio_agent']:0;
  23. $server_ids = isset($_REQUEST['server_ids'])?$_REQUEST['server_ids']:array(0);
  24. $action = $_REQUEST['action'];
  25. $flag = 0;
  26. foreach($server_ids as $k=>$v) {
  27. if($flag) $server_list .=',';
  28. $server_list .= $k;
  29. $flag = 1;
  30. }
  31. if ( !isset($_REQUEST['dStartDate'])) {
  32. $dStartTime = date("Y-m-d",time()-60*60*24);
  33. }
  34. else {
  35. $dStartTime = trim(SS($_REQUEST['dStartDate']));
  36. }
  37. if ( !isset($_REQUEST['dEndDate'])) {
  38. $dEndTime = strftime ("%Y-%m-%d", time());
  39. }
  40. else {
  41. $dEndTime = trim(SS($_REQUEST['dEndDate']));
  42. }
  43. $start_time = strtotime($dStartTime);
  44. $end_time = strtotime($dEndTime.'23:59:59');
  45. if($_REQUEST['urlflag']) {
  46. $server_list=$_REQUEST['search_servers']?$_REQUEST['search_servers']:0;
  47. $temp = explode(',', $server_list);
  48. $server_ids=array();
  49. foreach ($temp as $v) {
  50. $server_ids[$v] = 1;
  51. }
  52. }
  53. if ( !isset($_REQUEST['start_time'])) {
  54. $reply_start_time = strftime("%Y-%m-%d %H:%M:%S",time());
  55. }
  56. else {
  57. $reply_start_time = trim(SS($_REQUEST['start_time']));
  58. }
  59. if ( !isset($_REQUEST['end_time'])) {
  60. $reply_end_time = strftime ("%Y-%m-%d %H:%M:%S", time()+86400 );
  61. }
  62. else {
  63. $reply_end_time = trim(SS($_REQUEST['end_time']));
  64. }
  65. if ( !isset($_REQUEST['notice_end_time'])) {
  66. $notice_end_time = strftime("%Y-%m-%d %H:%M:%S", time()+7*86400 );
  67. }
  68. else {
  69. $notice_end_time = trim(SS($_REQUEST['notice_end_time']));
  70. }
  71. $keySign = "FTNN4399payKode";
  72. $level_max = 150;
  73. $sign=md5($keySign.$action);
  74. if($action=='bulletin') {
  75. $title = trim($_REQUEST['title']);
  76. if (empty($title)) {
  77. errorExit("公告标题不能为空!");
  78. }
  79. $text = trim($_REQUEST['text']);
  80. $dateEndStamp = intval(strtotime($notice_end_time));
  81. if($dateEndStamp == 0) {
  82. errorExit("请填写公告过期时间!");
  83. }
  84. if (empty($text)) {
  85. errorExit("公告内容不能为空!");
  86. }
  87. $text = str_replace("\\'", "'", $text); // 还原 '
  88. $text = str_replace("\\\"", "\"", $text); // 还原 "
  89. $text = str_replace("\\\\", "\\", $text); // 还原 \
  90. $text = base64_encode(urlencode($text));
  91. $flag_m=0;
  92. if($action_agent==0) {
  93. foreach($ADMIN_AGENT_NAME as $aid=>$value) {
  94. $message .=','. $value;
  95. foreach ($ALL_SERVER_LIST[$aid] as $sid=>$v) {
  96. if($v['stat']!=1) continue;
  97. $url = $v['url'];
  98. $link = $url."web/center/notice_repay.php?action=bulletin&time={$dateEndStamp}&title={$title}&text={$text}&sign={$sign}";
  99. $result = make_request($link,'POST',3);
  100. $data = json_decode($result, true);
  101. if($data!='ok') {
  102. $message .= ' S'.$sid;
  103. $flag_m = 1;
  104. }
  105. }
  106. }
  107. }else {
  108. $message = $ADMIN_AGENT_NAME[$action_agent];
  109. foreach($server_ids as $sid=>$v) {
  110. if($sid==0)continue;
  111. $url = $ALL_SERVER_LIST[$action_agent][$sid]['url'];
  112. $link = $url."web/center/notice_repay.php?action=bulletin&time={$dateEndStamp}&title={$title}&text={$text}&sign={$sign}";
  113. $result = make_request($link,'POST',3);
  114. $data = json_decode($result, true);
  115. if($data!='ok') {
  116. $message .= ' S'.$sid;
  117. $flag_m = 1;
  118. }
  119. }
  120. }
  121. if($flag_m) {
  122. errorExit($message."发布失败!");
  123. }else {
  124. infoExit("公告发布成功");
  125. }
  126. }elseif($action=='compensation_conf') {
  127. $level_max = intval(trim(SS($_REQUEST['level_max'])));
  128. $level_min = intval(trim(SS($_REQUEST['level_min'])));
  129. if ($level_max <=0) {
  130. errorExit("请输入最高等级限制!");
  131. }
  132. if ($level_min <=0) {
  133. errorExit("请输入最低等级限制!");
  134. }
  135. if ($level_min > $level_max) {
  136. errorExit("最近等级大于最高等级!");
  137. }
  138. $goods = intval(SS(trim($_REQUEST['goods'])));
  139. if ($goods <= 0) {
  140. errorExit("请输入补偿的物品ID!");
  141. }
  142. $num = intval(SS(trim($_REQUEST['num'])));
  143. if ($num <= 0) {
  144. errorExit("请输入补偿的数量!");
  145. }
  146. if ($num >5) {
  147. errorExit("补偿的数量不能大于5!");
  148. }
  149. $dateStartStamp = strtotime($reply_start_time);
  150. $dateEndStamp = strtotime($reply_end_time);
  151. if($dateStartStamp == $dateEndStamp) {
  152. errorExit("开始时间和结束时间不能相等!");
  153. }
  154. if($action_agent==0) {
  155. foreach($ADMIN_AGENT_NAME as $aid=>$value) {
  156. $message .=','. $value;
  157. foreach ($ALL_SERVER_LIST[$aid] as $sid=>$v) {
  158. if($v['stat']!=1) continue;
  159. $url = $v['url'];
  160. $link = $url."web/center/notice_repay.php?level_min={$level_min}&level_max={$level_max}"
  161. ."&start_time={$dateStartStamp}&end_time={$dateEndStamp}"
  162. ."&goods={$goods}&num={$num}&admin={$_SESSION['admin_user_name']}&sign={$sign}&action=compensation_conf";
  163. $result = make_request($link,'POST',3);
  164. $data = json_decode($result, true);
  165. if ($data =='ok') {
  166. $insert_sql = "INSERT INTO `all_notice_reply` (`id` ,`start_time` ,`end_time` ,`goods_id` ,`num` ,`level_min` ,`level_max`,`operator`,`agent_id`,`server_id`)VALUES ('','{$dateStartStamp}', '{$dateEndStamp}', '{$goods}', '{$num}', '{$level_min}', '{$level_max}','{$_SESSION['admin_user_name']}',{$aid},{$sid})";
  167. $db->query($insert_sql);
  168. }else {
  169. $message .= ' S'.$sid;
  170. $flag_m = 1;
  171. }
  172. }
  173. }
  174. }else {
  175. $message = $ADMIN_AGENT_NAME[$action_agent];
  176. foreach($server_ids as $sid=>$v){
  177. if($sid==0)continue;
  178. $url = $ALL_SERVER_LIST[$action_agent][$sid]['url'];
  179. $link = $url."web/center/notice_repay.php?level_min={$level_min}&level_max={$level_max}"
  180. ."&start_time={$dateStartStamp}&end_time={$dateEndStamp}"
  181. ."&goods={$goods}&num={$num}&admin={$_SESSION['admin_user_name']}&sign={$sign}&action=compensation_conf";
  182. $result = make_request($link,'POST',3);
  183. $data = json_decode($result, true);
  184. if ($data =='ok') {
  185. $insert_sql = "INSERT INTO `all_notice_reply` (`id` ,`start_time` ,`end_time` ,`goods_id` ,`num` ,`level_min` ,`level_max`,`operator`,`agent_id`,`server_id`)VALUES ('','{$dateStartStamp}', '{$dateEndStamp}', '{$goods}', '{$num}', '{$level_min}', '{$level_max}','{$_SESSION['admin_user_name']}',{$action_agent},{$sid})";
  186. $db->query($insert_sql);
  187. }else {
  188. $message .= ' S'.$sid;
  189. $flag_m = 1;
  190. }
  191. }
  192. }
  193. if($flag_m) {
  194. errorExit($message."发布失败!");
  195. }else {
  196. infoExit("发布成功");
  197. }
  198. }
  199. $pageno = (int)$_REQUEST['page'];
  200. if ($pageno <=0 )
  201. $pageno = 1;
  202. $table = '`all_notice_reply`';
  203. $where = '1 and';
  204. $where .= " ($table.`start_time`<={$end_time} and $table.`end_time`>={$start_time}) ";
  205. $search_agents = $action_agent?$action_agent:$agent_list;
  206. $search_servers = '';
  207. $where .= " and $table.agent_id in ( $search_agents) ";
  208. if($server_list!='0') {
  209. $where .= " and $table.server_id in($server_list) ";
  210. $search_servers = $server_list;
  211. }
  212. $resultCount = getRecordCount("all_notice_reply",$where);
  213. $count_result = $resultCount;
  214. $pagelist = getPages($pageno, $count_result,LIST_PER_PAGE_RECORDS);
  215. $start = ($pageno - 1) * LIST_PER_PAGE_RECORDS;
  216. $count = LIST_PER_PAGE_RECORDS;
  217. $sql = "SELECT all_notice_reply.*,t_PGoods.name FROM all_notice_reply , `t_PGoods` ";
  218. $sql .= ' where '.$where;
  219. $sql .= ' and all_notice_reply.goods_id=`t_PGoods`.id ';
  220. $sql .= " ORDER BY all_notice_reply.id desc" ;
  221. $sql .= " LIMIT {$start},{$count}";
  222. $result = $db->fetchAll($sql);
  223. foreach($result as $key=>$value) {
  224. $result[$key]['agent_name'] = $ADMIN_AGENT_NAME[$value['agent_id']];
  225. }
  226. $smarty->assign(array(
  227. 'page'=>$pageno,
  228. 'data'=>$result,
  229. 'page_list' => $pagelist,
  230. 'page_count'=> ceil($count_result/LIST_PER_PAGE_RECORDS),
  231. ));
  232. $smarty->assign(array(
  233. 'reply_start_time'=>$reply_start_time,
  234. 'reply_end_time'=>$reply_end_time,
  235. 'notice_end_time'=>$notice_end_time,
  236. 'level_max'=>$level_max,
  237. ));
  238. $smarty->assign(array("dStartTime"=>$dStartTime,
  239. "dEndTime"=>$dEndTime,
  240. 'agent_id'=>$action_agent,
  241. 'server_id'=>json_encode($server_ids),
  242. 'servers'=>json_encode($servers),
  243. "allAgentName"=>$ADMIN_AGENT_NAME,
  244. 'keyword'=>$key_word,
  245. 'search_agents'=>$search_agents,
  246. 'search_servers'=>$search_servers
  247. ));
  248. $smarty->display("module/center/all_notice_repay.html");
  249. #-------------------------------------------------------------------------------
  250. function make_request($url, $method = 'GET', $timeout = 5) {
  251. $ch = curl_init();
  252. $header = array(
  253. 'Accept-Language: zh-cn',
  254. 'Connection: Keep-Alive',
  255. 'Cache-Control: no-cache'
  256. );
  257. if ($method == 'GET') {
  258. curl_setopt($ch, CURLOPT_HEADER, 0);
  259. }
  260. else {
  261. $i = strpos($url, '?');
  262. $param_str = substr($url, $i + 1);
  263. $url = substr($url, 0, $i);
  264. curl_setopt($ch, CURLOPT_POST, 1);
  265. curl_setopt($ch, CURLOPT_POSTFIELDS, $param_str);
  266. }
  267. curl_setopt($ch, CURLOPT_URL, $url);
  268. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  269. curl_setopt($ch, CURLOPT_USERAGENT, 'WEB.4399.COM API PHP Servert 0.1 (curl) ' . phpversion());
  270. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  271. if ($timeout > 0) curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  272. $result = curl_exec($ch);
  273. curl_close($ch);
  274. return $result;
  275. }
  276. #-------------------------------------------------------------------------------