Commit b857f5d7 authored by hujun's avatar hujun

后台商学院接口

parent 7add9f4f
......@@ -66,6 +66,9 @@ class UploadFileService
case 'house_img':
$path .= 'resource/lib/Attachments/images/';
break;
case 'business_school' :
$path .= 'static/business_school/';
break;
default :
$data['code'] = 101;
$data['msg'] = "上传图片类型错误";
......
<?php
/**
* Created by PhpStorm.
* User: fuju
* Date: 2018/6/12
* Time: 17:21
*/
namespace app\index\controller;
use app\api_broker\service\UploadFileService;
use app\index\extend\Basic;
use app\model\SLabel;
use app\model\SNews;
use think\Request;
class News extends Basic
{
protected $m_news;
public function __construct(Request $request = null)
{
parent::__construct($request);
$this->m_news = new SNews();
}
/**
* 商学院列表
*
* @return \think\Response|\think\response\View
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function index()
{
if (!$this->request->isAjax()) {
return view('index');
}
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 10 : $this->params['pageSize'];
if (!empty($this->params['start_time']) && empty($this->params['end_time'])) {
$where['a.create_time'] = [ '> time', $this->params['start_time'] . ' 00:00:00' ];
}
if (!empty($this->params['end_time']) && empty($this->params['start_time'])) {
$where['a.create_time'] = [ '< time', $this->params['end_time'] . ' 23:59:59' ];
}
if (!empty($this->params['end_time']) && !empty($this->params['start_time'])) {
$where['a.create_time'] = [ 'between time', [ $this->params['start_time'] . ' 00:00:00', $this->params['end_time'] . ' 23:59:59' ] ];
}
if (!empty($this->params['title'])) {
$where['a.title'] = [ 'LIKE', '%' . $this->params['title'] . '%' ];
}
if (!empty($this->params['label_id'])) {
$where['a.s_label_id'] = $this->params['label_id'];
}
$field = 'a.id,a.title,a.content,a.create_time,b.name,c.label_name';
$where['a.status'] = 0;
$data['list'] = $this->m_news->getListAgent($pageNo, $pageSize, 'id DESC', $field, $where);
$data['total'] = $this->m_news->getListAgentTotal($where);
return $this->response(200, "", $data);
}
/**
* 新增文章
*
* @return \think\Response
*/
public function addNews()
{
if (empty($this->params['title'])) {
return $this->response(101, '标题为空!');
}
if (empty($this->params['content'])) {
return $this->response(101, '内容为空!');
}
if (empty($_FILES['file_img'])) {
return $this->response(101, '封面图片为空');
}
$upload = new UploadFileService();
$result = $upload->upload($_FILES['file_img'], 'business_school');
$data['title'] = trim($this->params['title']);
$data['content'] = trim($this->params['content']);
$data['publisher_id'] = $this->userId;
$data['cover_plan'] = $result['msg']['img_path'];
$num = $this->m_news->editData($data, $this->params['id']);
if ($num < 1) {
return $this->response(101, '新增失败!');
}
return $this->response(200, '新增成功!');
}
/**
* 商学院资讯详情
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getNewsInfo()
{
if (empty($this->params['id'])) {
return $this->response(101, "Id is null.");
}
$data = $this->m_news->getNewsInfo('id,title,s_label_id,cover_plan,content');
return $this->response(200, "", $data);
}
/**
* 删除状态
*
* @return \think\Response
*/
public function delNews()
{
if (empty($this->params['id'])) {
return $this->response(101, "Id is null.");
}
$num = $this->m_push->editData([ 'status' => 1 ], $this->params['id']);
if ($num > 0) {
return $this->response(200);
} else {
return $this->response(101, "删除失败!");
}
}
/**
* 商学院标签
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getNewsLabel() {
$label = new SLabel();
$data = $label->getList(1, 200, '', 'id,label_name', ['status'=>0]);
return $this->response(200, '', $data);
}
}
\ No newline at end of file
{layout name="global/frame_tpl" /}
商学院
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: fuju
* Date: 2018/7/3
* Time: 14:51
*/
namespace app\model;
class SLabel extends BaseModel
{
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: hu jun
* Date: 2018/7/3
* Time: 14:21
*/
namespace app\model;
class SNews extends BaseModel
{
/**
* 商学院列表
*
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param string $field
* @param string $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getListAgent($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '')
{
return $this->field($field)
->alias('a')
->join('a_agents b', 'a.publisher_id = b.id', 'left')
->join('s_label c', 'a.s_label_id = c.id', 'left')
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
}
/**
* 商学院列表总数
*
* @param $params
* @return int|string
*/
public function getListAgentTotal($params)
{
return $this->alias('a')
->join('a_agents b', 'a.publisher_id = b.id', 'left')
->where($params)
->count();
}
/**
* 商学院资讯详情
*
* @param string $field
* @param string $params
* @param string $order
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getNewsInfo($field = '', $params = '', $order = 'id ASC')
{
return $this->field($field)
->where($params)
->order($order)
->find();
}
}
\ No newline at end of file
......@@ -246,6 +246,10 @@ Route::group('index', [
'evaluationList' => [ 'index/Evaluation/evaluationList', [ 'method' => 'POST|GET' ] ], //评价列表 朱伟 2018-06-13
'marchInList' => [ 'index/MarchIn/marchInList', [ 'method' => 'POST|GET' ] ], //进场记录列表 朱伟 2018-06-13
'superviseList' => [ 'index/Supervise/superviseList', [ 'method' => 'POST|GET' ] ], //监督执行列表 朱伟 2018-06-14
'business_school' => [ 'index/news/index', [ 'method' => 'GET' ] ], //商学院资讯列表
'addNews' => [ 'index/news/addNews', [ 'method' => 'POST' ] ], //新增商学院资讯
'getNewsInfo' => [ 'index/news/getNewsInfo', [ 'method' => 'GET' ] ], //商学院资讯详情
'getNewsLabel' => [ 'index/news/getNewsLabel', [ 'method' => 'GET' ] ], //商学院资标签
]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment