123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- <?php
- namespace Home\Controller;
- use Think\Controller;
- include '../Common/function.php';
- class AgwController extends Controller
- {
- public function index()
- {
- header("Access-Control-Allow-Origin:*");
- header("Access-Control-Allow-Methods:GET, POST, OPTIONS, DELETE");
- 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");
- $sql = "select id,title,img_title,synopsis,time from sp_agw_Journalism where type = 2 order by time desc ";
- $res =M()->query($sql);
- // print_r($res);
- $arr=[];
- if (!empty($res)){
- $arr['msg']=true;
- }else{
- $arr['msg']=false;
- }
- $arr['data']=$res;
- // print_r(json_encode($arr));
- echo json_encode($arr);
- }
- //官网新闻显示列表
- public function journalism_display()
- {
- header("Access-Control-Allow-Origin:*");
- header("Access-Control-Allow-Methods:GET, POST, OPTIONS, DELETE");
- 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");
- $Data = I('');
- //
- if (!empty($Data['type'])){
- $type=$Data['type'];
- }else{
- $type=1;
- }
- $sql = "select id,title,img_title,synopsis,time from sp_agw_Journalism where type = ".$type." order by time desc ";
- $res = M()->query($sql);
- $arr=[];
- if (!empty($res)){
- $arr['msg']=true;
- }else{
- $arr['msg']=false;
- }
- $arr['data']=$res;
- echo json_encode($arr);
- }
- //官网新闻显示详情
- public function journalism_details()
- {
- header("Access-Control-Allow-Origin:*");
- header("Access-Control-Allow-Methods:GET, POST, OPTIONS, DELETE");
- 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");
- echo 'cehsi';
- // $Data = I('');
- // $id = $Data['id'];
- //
- //
- // //当前数据
- // $sql = "select id,title,publisher,content,time,type from sp_agw_Journalism where id=" . $id;
- // $res = M()->query($sql);
- // //下一条数据
- // $sql1 = "select id,title from sp_agw_Journalism where id>" . $id . " LIMIT 1";
- // $res1 = M()->query($sql1);
- //
- // //上一条数据
- // $sql2 = "select id,title from sp_agw_Journalism where id<" . $id . " order by id desc LIMIT 1";
- // $res2 = M()->query($sql2);
- //
- // //相关新闻
- // $sql3 = "select id,title from sp_agw_Journalism where id !=".$id." limit 10";
- // $res3 = M()->query($sql3);
- //
- // $arr=[];
- // if (!empty($res)){
- // $arr['msg']=true;
- //
- // }else{
- // $arr['msg']=false;
- // }
- // $arr['id']=$res[0]['id'];
- // $arr['title']=$res[0]['title'];
- // $arr['publisher']=$res[0]['publisher'];
- // $arr['content']=$res[0]['content'];
- // $arr['time']=$res[0]['time'];
- // $arr['type']=$res[0]['type'];
- // if (!empty($res2[0])){
- // $arr['previous']=$res2[0];
- // }else{
- // $arr['previous']=null;
- // }
- //
- // if (!empty($res1)){
- // $arr['next']=$res1[0];
- // }else{
- // $arr['next']=null;
- // }
- // if (!empty($res3)){
- // $arr['related']=$res3;
- // }else{
- // $arr['related']=null;
- // }
- //// print_r($res);
- // echo json_encode($arr);
- }
- //官网新闻发布图片上传
- public function file_upload()
- {
- $Data = I('');
- // print_r($_FILES);
- if ($_FILES) {
- if (!$_FILES['file']['error']) {
- $FileCode = date('YmdHis') . rand(1000, 9999);
- $FileName = $_FILES['file']['name'];
- $FileType = strtolower(substr(strrchr($FileName, '.'), 1));
- $BasefName = $FileCode . '.' . $FileType;
- //图片上传的具体路径就出来了
- $destination = "/var/www/html/jdxf/Maintinfo/image" . DIRECTORY_SEPARATOR . $BasefName; //change this directory
- $newFilePath1 = 'https://qhome.usky.cn/jdxf/Maintinfo/image/' . $BasefName;
- $tmpFilePath = $_FILES['file']['tmp_name'];
- //将图片移动到指定的文件夹****核心代码
- move_uploaded_file($tmpFilePath, $destination);
- echo $newFilePath1;
- } else {
- echo $message = 'Ooops! Your upload triggered the following error: ' . $_FILES['file']['error'];
- }
- }
- }
- //官网新闻发布
- public function journalism_add()
- {
- $Data = I("");
- $title = $Data["title"];
- $content = htmlspecialchars_decode($Data["content"]);
- $time = date("Y-m-d");
- $img_title = $Data["img_title"];
- $publisher = $Data["publisher"];
- $type = $Data["type"];
- $synopsis='测试';
- if (empty($publisher)) {
- $publisher = "永天科技";
- }
- $int_sql = "INSERT INTO sp_agw_Journalism ( title,img_title,synopsis,publisher, content,time,type )
- VALUES
- ( '" . $title . "','" . $img_title . "','".$synopsis."','" . $publisher . "', '" . $content . "','" . $time . "','".$type."' );";
- $res = addInt($int_sql);
- if ($res) {
- echo 1;
- } else {
- echo 0;
- }
- }
- //官网人员招聘显示列表
- public function recruit_display()
- {
- $Data = I("");
- $Data['page'] = 1;
- $start_page = ($Data['page'] - 1) * 10;
- $sql = "select * from sp_agw_recruit order by time desc limit " . $start_page . ",10;";
- $res = M()->query($sql);
- // print_r($res);
- echo json_encode($res);
- }
- //官网人员招聘显示详情
- public function recruit_details()
- {
- $Data = I("");
- $id = $Data['id'];
- $sql = "select * from sp_agw_recruit where id=" . $id;
- $res = M()->query($sql);
- // print_r($res);
- echo json_encode($res);
- }
- //官网人员招聘发布信息
- public function recruit_add()
- {
- $Data = I("");
- $title = $Data["title"];
- $recruit_demand = $Data["recruit_demand"];
- $time = date("Y-m-d H:i:s");
- $int_sql = "INSERT INTO sp_agw_recruit ( title, recruit_demand,time )
- VALUES
- ( '" . $title . "', '" . $recruit_demand . "','" . $time . "' );";
- $res = addInt($int_sql);
- if ($res) {
- echo 1;
- } else {
- echo 0;
- }
- }
- }
|