179 lines
5.6 KiB
PHP
Executable File
179 lines
5.6 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: lock
|
|
* Date: 2021/8/1
|
|
* Time: 8:30 AM
|
|
*/
|
|
|
|
namespace app\index\controller;
|
|
|
|
|
|
use app\common\classLibrary\ClWechat;
|
|
use think\Request;
|
|
use think\Session;
|
|
|
|
class SysNews extends Common
|
|
{
|
|
/**
|
|
* lists
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|\think\response\View
|
|
*/
|
|
public function lists()
|
|
{
|
|
return view();
|
|
}
|
|
|
|
/**
|
|
* add
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|\think\response\View
|
|
*/
|
|
public function add()
|
|
{
|
|
return view();
|
|
}
|
|
|
|
/**
|
|
* update
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|\think\response\View
|
|
*/
|
|
public function edit()
|
|
{
|
|
$id = Request::instance()->param('id');
|
|
$url = config('api_domain').'/news/get';
|
|
$session = Session::get('admin');
|
|
$params = array();
|
|
$params['token'] = $session['password'];
|
|
$params['id'] = $id;
|
|
$params['debug'] = 1;
|
|
$result = ClWechat::http_post($url,$params);
|
|
$json_arr = json_decode($result,true);
|
|
$this->assign('info',$json_arr['info']);
|
|
return view();
|
|
}
|
|
|
|
/**
|
|
* actionLists
|
|
* @return \think\response\Json
|
|
*/
|
|
public function actionLists()
|
|
{
|
|
$field_arr = array(
|
|
array('field_name' => 'page','rule' => 'require|number'),
|
|
array('field_name' => 'pageSize','rule' => 'require|number')
|
|
);
|
|
$check_arr = $this->checkHave($field_arr);
|
|
if($check_arr[self::$error_code_name] == 0)
|
|
{
|
|
$url = config('api_domain').'/news/lists';
|
|
$session = Session::get('admin');
|
|
$params = array();
|
|
$params['token'] = $session['password'];
|
|
$params['debug'] = 1;
|
|
$params['is_count'] = 1;
|
|
$params['page'] = $check_arr[self::$data_name]['page'];
|
|
$params['pageSize'] = $check_arr[self::$data_name]['pageSize'];
|
|
$result = ClWechat::http_post($url,$params);
|
|
$json_arr = json_decode($result,true);
|
|
$json_arr['code'] = $json_arr['error_code'];
|
|
$json_arr['data'] = $json_arr['lists'];
|
|
self::$result = $json_arr;
|
|
}
|
|
return json(self::$result);
|
|
}
|
|
|
|
/**
|
|
* actionAdd
|
|
* @return \think\response\Json
|
|
*/
|
|
public function actionAdd()
|
|
{
|
|
$field_arr = array(
|
|
array('field_name' => 'title','rule' => ''),
|
|
array('field_name' => 'source','rule' => ''),
|
|
array('field_name' => 'url','rule' => ''),
|
|
array('field_name' => 'content','rule' => ''),
|
|
array('field_name' => 'is_recommend','rule' => ''),
|
|
);
|
|
$check_arr = $this->checkHave($field_arr);
|
|
if($check_arr[self::$error_code_name] == 0)
|
|
{
|
|
$url = config('api_domain').'/news/add';
|
|
$session = Session::get('admin');
|
|
$params = array();
|
|
$params['token'] = $session['password'];
|
|
foreach ($field_arr as $each_v)
|
|
{
|
|
if (array_key_exists($each_v['field_name'],$check_arr[self::$data_name]))
|
|
{
|
|
$params[$each_v['field_name']] = $check_arr[self::$data_name][$each_v['field_name']];
|
|
}
|
|
}
|
|
|
|
$result = ClWechat::http_post($url,$params);
|
|
$json_arr = json_decode($result,true);
|
|
self::$result = $json_arr;
|
|
}
|
|
return json(self::$result);
|
|
}
|
|
|
|
/**
|
|
* actionUpdate
|
|
* @return \think\response\Json
|
|
*/
|
|
public function actionUpdate()
|
|
{
|
|
$field_arr = array(
|
|
array('field_name' => 'id','rule' => 'require|number'),
|
|
array('field_name' => 'title','rule' => ''),
|
|
array('field_name' => 'source','rule' => ''),
|
|
array('field_name' => 'url','rule' => ''),
|
|
array('field_name' => 'content','rule' => ''),
|
|
array('field_name' => 'is_recommend','rule' => ''),
|
|
);
|
|
$check_arr = $this->checkHave($field_arr);
|
|
if($check_arr[self::$error_code_name] == 0)
|
|
{
|
|
$url = config('api_domain').'/news/update';
|
|
$session = Session::get('admin');
|
|
$params = array();
|
|
$params['token'] = $session['password'];
|
|
foreach ($field_arr as $each_v)
|
|
{
|
|
if (array_key_exists($each_v['field_name'],$check_arr[self::$data_name]))
|
|
{
|
|
$params[$each_v['field_name']] = $check_arr[self::$data_name][$each_v['field_name']];
|
|
}
|
|
}
|
|
$result = ClWechat::http_post($url,$params);
|
|
$json_arr = json_decode($result,true);
|
|
self::$result = $json_arr;
|
|
}
|
|
return json(self::$result);
|
|
}
|
|
|
|
/**
|
|
* actionDelete
|
|
* @return \think\response\Json
|
|
*/
|
|
public function actionDelete()
|
|
{
|
|
$field_arr = array(
|
|
array('field_name' => 'id','rule' => 'require|number')
|
|
);
|
|
$check_arr = $this->checkHave($field_arr);
|
|
if($check_arr[self::$error_code_name] == 0)
|
|
{
|
|
$url = config('api_domain').'/news/delete';
|
|
$session = Session::get('admin');
|
|
$params = array();
|
|
$params['token'] = $session['password'];
|
|
$params['id'] = $check_arr[self::$data_name]['id'];
|
|
$params['debug'] = 1;
|
|
$result = ClWechat::http_post($url,$params);
|
|
$json_arr = json_decode($result,true);
|
|
self::$result = $json_arr;
|
|
}
|
|
return json(self::$result);
|
|
}
|
|
} |