AgwController.class.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. include '../Common/function.php';
  5. class AgwController extends Controller
  6. {
  7. public function index()
  8. {
  9. header("Access-Control-Allow-Origin:*");
  10. header("Access-Control-Allow-Methods:GET, POST, OPTIONS, DELETE");
  11. header("Access-Control-Allow-Headers:DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type, Accept-Language, Origin, Accept-Encoding");
  12. $sql = "select id,title,img_title,synopsis,time from sp_agw_Journalism where type = 2 order by time desc ";
  13. $res =M()->query($sql);
  14. // print_r($res);
  15. $arr=[];
  16. if (!empty($res)){
  17. $arr['msg']=true;
  18. }else{
  19. $arr['msg']=false;
  20. }
  21. $arr['data']=$res;
  22. // print_r(json_encode($arr));
  23. echo json_encode($arr);
  24. }
  25. //官网新闻显示列表
  26. public function journalism_display()
  27. {
  28. header("Access-Control-Allow-Origin:*");
  29. header("Access-Control-Allow-Methods:GET, POST, OPTIONS, DELETE");
  30. header("Access-Control-Allow-Headers:DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type, Accept-Language, Origin, Accept-Encoding");
  31. $Data = I('');
  32. //
  33. if (!empty($Data['type'])){
  34. $type=$Data['type'];
  35. }else{
  36. $type=1;
  37. }
  38. $sql = "select id,title,img_title,synopsis,time from sp_agw_Journalism where type = ".$type." order by time desc ";
  39. $res = M()->query($sql);
  40. $arr=[];
  41. if (!empty($res)){
  42. $arr['msg']=true;
  43. }else{
  44. $arr['msg']=false;
  45. }
  46. $arr['data']=$res;
  47. echo json_encode($arr);
  48. }
  49. //官网新闻显示详情
  50. public function journalism_details()
  51. {
  52. header("Access-Control-Allow-Origin:*");
  53. header("Access-Control-Allow-Methods:GET, POST, OPTIONS, DELETE");
  54. header("Access-Control-Allow-Headers:DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type, Accept-Language, Origin, Accept-Encoding");
  55. echo 'cehsi';
  56. // $Data = I('');
  57. // $id = $Data['id'];
  58. //
  59. //
  60. // //当前数据
  61. // $sql = "select id,title,publisher,content,time,type from sp_agw_Journalism where id=" . $id;
  62. // $res = M()->query($sql);
  63. // //下一条数据
  64. // $sql1 = "select id,title from sp_agw_Journalism where id>" . $id . " LIMIT 1";
  65. // $res1 = M()->query($sql1);
  66. //
  67. // //上一条数据
  68. // $sql2 = "select id,title from sp_agw_Journalism where id<" . $id . " order by id desc LIMIT 1";
  69. // $res2 = M()->query($sql2);
  70. //
  71. // //相关新闻
  72. // $sql3 = "select id,title from sp_agw_Journalism where id !=".$id." limit 10";
  73. // $res3 = M()->query($sql3);
  74. //
  75. // $arr=[];
  76. // if (!empty($res)){
  77. // $arr['msg']=true;
  78. //
  79. // }else{
  80. // $arr['msg']=false;
  81. // }
  82. // $arr['id']=$res[0]['id'];
  83. // $arr['title']=$res[0]['title'];
  84. // $arr['publisher']=$res[0]['publisher'];
  85. // $arr['content']=$res[0]['content'];
  86. // $arr['time']=$res[0]['time'];
  87. // $arr['type']=$res[0]['type'];
  88. // if (!empty($res2[0])){
  89. // $arr['previous']=$res2[0];
  90. // }else{
  91. // $arr['previous']=null;
  92. // }
  93. //
  94. // if (!empty($res1)){
  95. // $arr['next']=$res1[0];
  96. // }else{
  97. // $arr['next']=null;
  98. // }
  99. // if (!empty($res3)){
  100. // $arr['related']=$res3;
  101. // }else{
  102. // $arr['related']=null;
  103. // }
  104. //// print_r($res);
  105. // echo json_encode($arr);
  106. }
  107. //官网新闻发布图片上传
  108. public function file_upload()
  109. {
  110. $Data = I('');
  111. // print_r($_FILES);
  112. if ($_FILES) {
  113. if (!$_FILES['file']['error']) {
  114. $FileCode = date('YmdHis') . rand(1000, 9999);
  115. $FileName = $_FILES['file']['name'];
  116. $FileType = strtolower(substr(strrchr($FileName, '.'), 1));
  117. $BasefName = $FileCode . '.' . $FileType;
  118. //图片上传的具体路径就出来了
  119. $destination = "/var/www/html/jdxf/Maintinfo/image" . DIRECTORY_SEPARATOR . $BasefName; //change this directory
  120. $newFilePath1 = 'https://qhome.usky.cn/jdxf/Maintinfo/image/' . $BasefName;
  121. $tmpFilePath = $_FILES['file']['tmp_name'];
  122. //将图片移动到指定的文件夹****核心代码
  123. move_uploaded_file($tmpFilePath, $destination);
  124. echo $newFilePath1;
  125. } else {
  126. echo $message = 'Ooops! Your upload triggered the following error: ' . $_FILES['file']['error'];
  127. }
  128. }
  129. }
  130. //官网新闻发布
  131. public function journalism_add()
  132. {
  133. $Data = I("");
  134. $title = $Data["title"];
  135. $content = htmlspecialchars_decode($Data["content"]);
  136. $time = date("Y-m-d");
  137. $img_title = $Data["img_title"];
  138. $publisher = $Data["publisher"];
  139. $type = $Data["type"];
  140. $synopsis='测试';
  141. if (empty($publisher)) {
  142. $publisher = "永天科技";
  143. }
  144. $int_sql = "INSERT INTO sp_agw_Journalism ( title,img_title,synopsis,publisher, content,time,type )
  145. VALUES
  146. ( '" . $title . "','" . $img_title . "','".$synopsis."','" . $publisher . "', '" . $content . "','" . $time . "','".$type."' );";
  147. $res = addInt($int_sql);
  148. if ($res) {
  149. echo 1;
  150. } else {
  151. echo 0;
  152. }
  153. }
  154. //官网人员招聘显示列表
  155. public function recruit_display()
  156. {
  157. $Data = I("");
  158. $Data['page'] = 1;
  159. $start_page = ($Data['page'] - 1) * 10;
  160. $sql = "select * from sp_agw_recruit order by time desc limit " . $start_page . ",10;";
  161. $res = M()->query($sql);
  162. // print_r($res);
  163. echo json_encode($res);
  164. }
  165. //官网人员招聘显示详情
  166. public function recruit_details()
  167. {
  168. $Data = I("");
  169. $id = $Data['id'];
  170. $sql = "select * from sp_agw_recruit where id=" . $id;
  171. $res = M()->query($sql);
  172. // print_r($res);
  173. echo json_encode($res);
  174. }
  175. //官网人员招聘发布信息
  176. public function recruit_add()
  177. {
  178. $Data = I("");
  179. $title = $Data["title"];
  180. $recruit_demand = $Data["recruit_demand"];
  181. $time = date("Y-m-d H:i:s");
  182. $int_sql = "INSERT INTO sp_agw_recruit ( title, recruit_demand,time )
  183. VALUES
  184. ( '" . $title . "', '" . $recruit_demand . "','" . $time . "' );";
  185. $res = addInt($int_sql);
  186. if ($res) {
  187. echo 1;
  188. } else {
  189. echo 0;
  190. }
  191. }
  192. }