Commit 628ecc22 authored by hujun's avatar hujun

商学院多个附件

parent 4d22cd6a
...@@ -11,6 +11,7 @@ namespace app\index\controller; ...@@ -11,6 +11,7 @@ namespace app\index\controller;
use app\api_broker\service\UploadFileService; use app\api_broker\service\UploadFileService;
use app\index\extend\Basic; use app\index\extend\Basic;
use app\model\SFile;
use app\model\SLabel; use app\model\SLabel;
use app\model\SNews; use app\model\SNews;
use think\Request; use think\Request;
...@@ -100,9 +101,20 @@ class News extends Basic ...@@ -100,9 +101,20 @@ class News extends Basic
$data['annex_file_name'] = $this->params['annex_file_name']; $data['annex_file_name'] = $this->params['annex_file_name'];
try { try {
$this->m_news->editData($data, $this->params['id']); $id = $this->m_news->addData($this->params, $this->userId);
if ($id) {
$m_file = new SFile();
$file_data = [];
foreach ($data['annex_file_name'] as $k=>$v) {
$file_data['file_name'] = $v;
$file_data['new_id'] = $id;
$file_data['type'] = 1;
$file_data['status'] = 0;
$m_file->insertData($file_data);
}
}
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->response(101, '新增或编辑失败!'); return $this->response(101, '新增或编辑失败!'.$e->getMessage());
} }
return $this->response(200, '新增成功!'); return $this->response(200, '新增成功!');
...@@ -161,8 +173,27 @@ class News extends Basic ...@@ -161,8 +173,27 @@ class News extends Basic
$data = $label->getList(1, 200, '', 'id,label_name', ['status'=>0]); $data = $label->getList(1, 200, '', 'id,label_name', ['status'=>0]);
return $this->response(200, '', $data); return $this->response(200, '', $data);
} }
/**
* @return \think\response\View
*/
public function newText() { public function newText() {
return view('new_text'); return view('new_text');
} }
/**
* 删除文件
*
* @return \think\Response
*/
public function delNewsFile() {
if (empty($this->params['file_id'])) {
return $this->response(101, '参数错误');
}
$m_file = new SFile();
$m_file->updateDateById($this->params['file_id'], ['status'=>1]);
return $this->response(200, '删除成功');
}
} }
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: fuju
* Date: 2018/8/23
* Time: 14:58
*/
namespace app\model;
use think\Db;
class SFile extends BaseModel
{
protected $table = 's_file';
private $db_;
public function __construct()
{
$this->db_ = Db::name($this->table);
}
/**
* @param $params
* @return int|string
*/
public function insertData($params)
{
Db::startTrans();
try {
$id = $this->db_->insertGetId($params);
Db::commit();
return $id;
} catch (\Exception $e) {
dump($e->getMessage());die;
Db::rollback();
return 0;
}
}
/**
* 修改信息
*
* @param $id
* @param $params
* @return int
*/
public function updateDateById($id, $params)
{
$params["update_time"] = date("Y-m-d H:i:s", time());
Db::startTrans();
try {
$this->db_->where('id', $id)->update($params);
Db::commit();
return 1;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
}
\ No newline at end of file
...@@ -9,8 +9,18 @@ ...@@ -9,8 +9,18 @@
namespace app\model; namespace app\model;
use think\Db;
class SNews extends BaseModel class SNews extends BaseModel
{ {
protected $table = 's_news';
private $db_;
public function __construct()
{
$this->db_ = Db::name($this->table);
}
/** /**
* 商学院列表 * 商学院列表
* *
...@@ -26,7 +36,7 @@ class SNews extends BaseModel ...@@ -26,7 +36,7 @@ class SNews extends BaseModel
*/ */
public function getListAgent($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '') public function getListAgent($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '')
{ {
$data = $this->field($field) $data = $this->db_->field($field)
->alias('a') ->alias('a')
->join('a_agents b', 'a.publisher_id = b.id', 'left') ->join('a_agents b', 'a.publisher_id = b.id', 'left')
->join('s_label c', 'a.s_label_id = c.id', 'left') ->join('s_label c', 'a.s_label_id = c.id', 'left')
...@@ -52,7 +62,7 @@ class SNews extends BaseModel ...@@ -52,7 +62,7 @@ class SNews extends BaseModel
*/ */
public function getListAgentTotal($params) public function getListAgentTotal($params)
{ {
return $this->alias('a') return $this->db_->alias('a')
->join('a_agents b', 'a.publisher_id = b.id', 'left') ->join('a_agents b', 'a.publisher_id = b.id', 'left')
->where($params) ->where($params)
->count(); ->count();
...@@ -71,13 +81,23 @@ class SNews extends BaseModel ...@@ -71,13 +81,23 @@ class SNews extends BaseModel
*/ */
public function getNewsInfo($field = '', $params = '', $order = 'id ASC') public function getNewsInfo($field = '', $params = '', $order = 'id ASC')
{ {
$data = $this->field($field) $data = $this->db_->field($field)
->where($params) ->where($params)
->order($order) ->order($order)
->find(); ->find();
$file = $this->db_->table('s_file')
->field('id as file_id,file_name')
->where('new_id',$params['id'])
->select();
if (!empty($file[0]['annex_file_name'])) {
$data['annex_file_path'] = CURRENT_URL . 'static/business_school_file/' . $file[0]['annex_file_name'];
}
$data['file'] = $file;
$data['cover_plan'] = CK_IMG_URL . 'images/' . $data['cover_plan']; $data['cover_plan'] = CK_IMG_URL . 'images/' . $data['cover_plan'];
$data['annex_file_path'] = CURRENT_URL . 'static/business_school_file/' . $data['annex_file_name'];
return $data; return $data;
} }
...@@ -90,7 +110,7 @@ class SNews extends BaseModel ...@@ -90,7 +110,7 @@ class SNews extends BaseModel
public function setCommentNumber($id) { public function setCommentNumber($id) {
$comment_number = $this->where('id',$id)->value('comment_number'); $comment_number = $this->where('id',$id)->value('comment_number');
$comment_number += 1; $comment_number += 1;
return $this->where('id', $id)->setField('comment_number', $comment_number); return $this->db_->where('id', $id)->setField('comment_number', $comment_number);
} }
/** /**
...@@ -104,4 +124,42 @@ class SNews extends BaseModel ...@@ -104,4 +124,42 @@ class SNews extends BaseModel
$m_label = new SLabel(); $m_label = new SLabel();
return $m_label->where('id',$id)->value($field); return $m_label->where('id',$id)->value($field);
} }
/**
* 添加商学院文章
*
* @param $data
* @param $publisher_id 发布人
* @return int|string
* @throws \Exception
*/
public function addData($data, $publisher_id) {
$insert = [];
if ($data['title']) {
$insert['title'] = $data['title'];
}
if ($data['content']) {
$insert['content'] = $data['content'];
}
if ($data['cover_plan']) {
$insert['cover_plan'] = $data['cover_plan'];
}
if ($data['s_label_id']) {
$insert['s_label_id'] = $data['s_label_id'];
}
$insert['publisher_id'] = $publisher_id;
if (empty($data['id'])) {
$id = $this->db_->insertGetId($insert);
} else {
$this->db_->where('id',$data['id'])->update($insert);
$id = $data['id'];
}
return $id;
}
} }
\ No newline at end of file
...@@ -268,7 +268,8 @@ Route::group('index', [ ...@@ -268,7 +268,8 @@ Route::group('index', [
'getNewsInfo' => [ 'index/news/getNewsInfo', [ 'method' => 'GET' ] ], //商学院资讯详情 'getNewsInfo' => [ 'index/news/getNewsInfo', [ 'method' => 'GET' ] ], //商学院资讯详情
'getNewsLabel' => [ 'index/news/getNewsLabel', [ 'method' => 'GET' ] ], //商学院资标签 'getNewsLabel' => [ 'index/news/getNewsLabel', [ 'method' => 'GET' ] ], //商学院资标签
'delNews' => [ 'index/news/delNews', [ 'method' => 'POST' ] ], //删除商学院文章 'delNews' => [ 'index/news/delNews', [ 'method' => 'POST' ] ], //删除商学院文章
'new_text' => [ 'index/news/newText', [ 'method' => 'GET' ] ], //删除商学院文章 'new_text' => [ 'index/news/newText', [ 'method' => 'GET' ] ],
'delNewsFile' => [ 'index/news/delNewsFile', [ 'method' => 'POST' ] ], //删除商学院附件
'agentEvaluateNumAndFraction' => [ 'index/agent/agentEvaluateNumAndFraction', [ 'method' => 'POST|GET' ] ],//经纪人列表计算-评价次数和分数 朱伟 2018-07-03 'agentEvaluateNumAndFraction' => [ 'index/agent/agentEvaluateNumAndFraction', [ 'method' => 'POST|GET' ] ],//经纪人列表计算-评价次数和分数 朱伟 2018-07-03
'uploadImg' => [ 'index/UploadImg/uploadImg', [ 'method' => 'POST' ] ],//全局图片上传 'uploadImg' => [ 'index/UploadImg/uploadImg', [ 'method' => 'POST' ] ],//全局图片上传
'followUpList' => [ 'index/HouseFollowUp/followUpList', [ 'method' => 'GET' ] ],//商铺跟进liu 'followUpList' => [ 'index/HouseFollowUp/followUpList', [ 'method' => 'GET' ] ],//商铺跟进liu
......
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