|
@@ -4,7 +4,6 @@ namespace app\admin\controller\article;
|
|
|
|
|
|
|
|
use app\admin\controller\AuthController;
|
|
use app\admin\controller\AuthController;
|
|
|
use crmeb\services\UtilService as Util;
|
|
use crmeb\services\UtilService as Util;
|
|
|
-use crmeb\services\PHPTreeService as Phptree;
|
|
|
|
|
use crmeb\services\JsonService as Json;
|
|
use crmeb\services\JsonService as Json;
|
|
|
use crmeb\services\UploadService as Upload;
|
|
use crmeb\services\UploadService as Upload;
|
|
|
use app\admin\model\article\ArticleCategory as ArticleCategoryModel;
|
|
use app\admin\model\article\ArticleCategory as ArticleCategoryModel;
|
|
@@ -28,22 +27,12 @@ class Article extends AuthController
|
|
|
public function index()
|
|
public function index()
|
|
|
{
|
|
{
|
|
|
$where = Util::getMore([
|
|
$where = Util::getMore([
|
|
|
- ['title',''],
|
|
|
|
|
- ['cid','']
|
|
|
|
|
- ],$this->request);
|
|
|
|
|
- $pid = $this->request->param('pid');
|
|
|
|
|
- $this->assign('where',$where);
|
|
|
|
|
|
|
+ ['title', ''],
|
|
|
|
|
+ ['cid', $this->request->param('pid', '')]
|
|
|
|
|
+ ], $this->request);
|
|
|
|
|
+ $this->assign('where', $where);
|
|
|
$where['merchant'] = 0;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
|
|
$where['merchant'] = 0;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
|
|
|
- $cateList = ArticleCategoryModel::getArticleCategoryList();
|
|
|
|
|
- $tree = [];
|
|
|
|
|
- //获取分类列表
|
|
|
|
|
- if(count($cateList)){
|
|
|
|
|
- $tree = Phptree::makeTreeForHtml($cateList);
|
|
|
|
|
- if($pid){
|
|
|
|
|
- $pids = Util::getChildrenPid($tree,$pid);
|
|
|
|
|
- $where['cid'] = ltrim($pid.$pids);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $tree = sort_list_tier(ArticleCategoryModel::getArticleCategoryList());
|
|
|
$this->assign(compact('tree'));
|
|
$this->assign(compact('tree'));
|
|
|
$this->assign(ArticleModel::getAll($where));
|
|
$this->assign(ArticleModel::getAll($where));
|
|
|
return $this->fetch();
|
|
return $this->fetch();
|
|
@@ -56,7 +45,8 @@ class Article extends AuthController
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
* @throws \think\exception\DbException
|
|
* @throws \think\exception\DbException
|
|
|
*/
|
|
*/
|
|
|
- public function create(){
|
|
|
|
|
|
|
+ public function create()
|
|
|
|
|
+ {
|
|
|
$id = $this->request->param('id');
|
|
$id = $this->request->param('id');
|
|
|
$cid = $this->request->param('cid');
|
|
$cid = $this->request->param('cid');
|
|
|
$news = [];
|
|
$news = [];
|
|
@@ -71,26 +61,26 @@ class Article extends AuthController
|
|
|
$news['synopsis'] = '';
|
|
$news['synopsis'] = '';
|
|
|
$news['url'] = '';
|
|
$news['url'] = '';
|
|
|
$news['cid'] = [];
|
|
$news['cid'] = [];
|
|
|
- $select = 0;
|
|
|
|
|
- if($id){
|
|
|
|
|
- $news = ArticleModel::where('n.id',$id)->alias('n')->field('n.*,c.content')->join('ArticleContent c','c.nid=n.id','left')->find();
|
|
|
|
|
- if(!$news) return $this->failed('数据不存在!');
|
|
|
|
|
- $news['cid'] = explode(',',$news['cid']);
|
|
|
|
|
|
|
+ $select = 0;
|
|
|
|
|
+ if ($id) {
|
|
|
|
|
+ $news = ArticleModel::where('n.id', $id)->alias('n')->field('n.*,c.content')->join('ArticleContent c', 'c.nid=n.id', 'left')->find();
|
|
|
|
|
+ if (!$news) return $this->failed('数据不存在!');
|
|
|
|
|
+ $news['cid'] = explode(',', $news['cid']);
|
|
|
}
|
|
}
|
|
|
- if($cid && in_array($cid, ArticleCategoryModel::getArticleCategoryInfo(0,'id'))){
|
|
|
|
|
|
|
+ if ($cid && in_array($cid, ArticleCategoryModel::getArticleCategoryInfo(0, 'id'))) {
|
|
|
$all = ArticleCategoryModel::getArticleCategoryInfo($cid);
|
|
$all = ArticleCategoryModel::getArticleCategoryInfo($cid);
|
|
|
$select = 1;
|
|
$select = 1;
|
|
|
}
|
|
}
|
|
|
- if(!$select){
|
|
|
|
|
|
|
+ if (!$select) {
|
|
|
$list = ArticleCategoryModel::getTierList();
|
|
$list = ArticleCategoryModel::getTierList();
|
|
|
- foreach ($list as $menu){
|
|
|
|
|
- $all[$menu['id']] = $menu['html'].$menu['title'];
|
|
|
|
|
|
|
+ foreach ($list as $menu) {
|
|
|
|
|
+ $all[$menu['id']] = $menu['html'] . $menu['title'];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- $this->assign('all',$all);
|
|
|
|
|
- $this->assign('news',$news);
|
|
|
|
|
- $this->assign('cid',$cid);
|
|
|
|
|
- $this->assign('select',$select);
|
|
|
|
|
|
|
+ $this->assign('all', $all);
|
|
|
|
|
+ $this->assign('news', $news);
|
|
|
|
|
+ $this->assign('cid', $cid);
|
|
|
|
|
+ $this->assign('select', $select);
|
|
|
return $this->fetch();
|
|
return $this->fetch();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -98,20 +88,22 @@ class Article extends AuthController
|
|
|
* 上传图文图片
|
|
* 上传图文图片
|
|
|
* @return \think\response\Json
|
|
* @return \think\response\Json
|
|
|
*/
|
|
*/
|
|
|
- public function upload_image(){
|
|
|
|
|
- $res = Upload::instance()->setUploadPath('wechat/image/'.date('Ymd'))->image($_POST['file']);
|
|
|
|
|
- if(!is_array($res)) return Json::fail($res);
|
|
|
|
|
- SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],5,$res['image_type'],$res['time']);
|
|
|
|
|
- return Json::successful('上传成功!',['url'=>$res['dir']]);
|
|
|
|
|
|
|
+ public function upload_image()
|
|
|
|
|
+ {
|
|
|
|
|
+ $res = Upload::instance()->setUploadPath('wechat/image/' . date('Ymd'))->image($_POST['file']);
|
|
|
|
|
+ if (!is_array($res)) return Json::fail($res);
|
|
|
|
|
+ SystemAttachment::attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'], 5, $res['image_type'], $res['time']);
|
|
|
|
|
+ return Json::successful('上传成功!', ['url' => $res['dir']]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 添加和修改图文
|
|
* 添加和修改图文
|
|
|
*/
|
|
*/
|
|
|
- public function add_new(){
|
|
|
|
|
|
|
+ public function add_new()
|
|
|
|
|
+ {
|
|
|
$data = Util::postMore([
|
|
$data = Util::postMore([
|
|
|
- ['id',0],
|
|
|
|
|
- ['cid',[]],
|
|
|
|
|
|
|
+ ['id', 0],
|
|
|
|
|
+ ['cid', []],
|
|
|
'title',
|
|
'title',
|
|
|
'author',
|
|
'author',
|
|
|
'image_input',
|
|
'image_input',
|
|
@@ -119,47 +111,47 @@ class Article extends AuthController
|
|
|
'synopsis',
|
|
'synopsis',
|
|
|
'share_title',
|
|
'share_title',
|
|
|
'share_synopsis',
|
|
'share_synopsis',
|
|
|
- ['visit',0],
|
|
|
|
|
- ['sort',0],
|
|
|
|
|
|
|
+ ['visit', 0],
|
|
|
|
|
+ ['sort', 0],
|
|
|
'url',
|
|
'url',
|
|
|
- ['is_banner',0],
|
|
|
|
|
- ['is_hot',0],
|
|
|
|
|
- ['status',1],]);
|
|
|
|
|
- $data['cid'] = implode(',',$data['cid']);
|
|
|
|
|
|
|
+ ['is_banner', 0],
|
|
|
|
|
+ ['is_hot', 0],
|
|
|
|
|
+ ['status', 1],]);
|
|
|
|
|
+ $data['cid'] = implode(',', $data['cid']);
|
|
|
$content = $data['content'];
|
|
$content = $data['content'];
|
|
|
unset($data['content']);
|
|
unset($data['content']);
|
|
|
- if($data['id']){
|
|
|
|
|
|
|
+ if ($data['id']) {
|
|
|
$id = $data['id'];
|
|
$id = $data['id'];
|
|
|
unset($data['id']);
|
|
unset($data['id']);
|
|
|
$res = false;
|
|
$res = false;
|
|
|
ArticleModel::beginTrans();
|
|
ArticleModel::beginTrans();
|
|
|
- $res1 = ArticleModel::edit($data,$id,'id');
|
|
|
|
|
- $res2 = ArticleModel::setContent($id,$content);
|
|
|
|
|
- if($res1 && $res2){
|
|
|
|
|
|
|
+ $res1 = ArticleModel::edit($data, $id, 'id');
|
|
|
|
|
+ $res2 = ArticleModel::setContent($id, $content);
|
|
|
|
|
+ if ($res1 && $res2) {
|
|
|
$res = true;
|
|
$res = true;
|
|
|
}
|
|
}
|
|
|
ArticleModel::checkTrans($res);
|
|
ArticleModel::checkTrans($res);
|
|
|
- if($res)
|
|
|
|
|
- return Json::successful('修改图文成功!',$id);
|
|
|
|
|
|
|
+ if ($res)
|
|
|
|
|
+ return Json::successful('修改图文成功!', $id);
|
|
|
else
|
|
else
|
|
|
- return Json::fail('修改图文失败,您并没有修改什么!',$id);
|
|
|
|
|
- }else{
|
|
|
|
|
|
|
+ return Json::fail('修改图文失败,您并没有修改什么!', $id);
|
|
|
|
|
+ } else {
|
|
|
$data['add_time'] = time();
|
|
$data['add_time'] = time();
|
|
|
$data['admin_id'] = $this->adminId;
|
|
$data['admin_id'] = $this->adminId;
|
|
|
$res = false;
|
|
$res = false;
|
|
|
ArticleModel::beginTrans();
|
|
ArticleModel::beginTrans();
|
|
|
$res1 = ArticleModel::create($data);
|
|
$res1 = ArticleModel::create($data);
|
|
|
$res2 = false;
|
|
$res2 = false;
|
|
|
- if($res1)
|
|
|
|
|
- $res2 = ArticleModel::setContent($res1->id,$content);
|
|
|
|
|
- if($res1 && $res2){
|
|
|
|
|
|
|
+ if ($res1)
|
|
|
|
|
+ $res2 = ArticleModel::setContent($res1->id, $content);
|
|
|
|
|
+ if ($res1 && $res2) {
|
|
|
$res = true;
|
|
$res = true;
|
|
|
}
|
|
}
|
|
|
ArticleModel::checkTrans($res);
|
|
ArticleModel::checkTrans($res);
|
|
|
- if($res)
|
|
|
|
|
- return Json::successful('添加图文成功!',$res1->id);
|
|
|
|
|
|
|
+ if ($res)
|
|
|
|
|
+ return Json::successful('添加图文成功!', $res1->id);
|
|
|
else
|
|
else
|
|
|
- return Json::successful('添加图文失败!',$res1->id);
|
|
|
|
|
|
|
+ return Json::successful('添加图文失败!', $res1->id);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -171,17 +163,18 @@ class Article extends AuthController
|
|
|
public function delete($id)
|
|
public function delete($id)
|
|
|
{
|
|
{
|
|
|
$res = ArticleModel::del($id);
|
|
$res = ArticleModel::del($id);
|
|
|
- if(!$res)
|
|
|
|
|
|
|
+ if (!$res)
|
|
|
return Json::fail('删除失败,请稍候再试!');
|
|
return Json::fail('删除失败,请稍候再试!');
|
|
|
else
|
|
else
|
|
|
return Json::successful('删除成功!');
|
|
return Json::successful('删除成功!');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function merchantIndex(){
|
|
|
|
|
|
|
+ public function merchantIndex()
|
|
|
|
|
+ {
|
|
|
$where = Util::getMore([
|
|
$where = Util::getMore([
|
|
|
- ['title','']
|
|
|
|
|
- ],$this->request);
|
|
|
|
|
- $this->assign('where',$where);
|
|
|
|
|
|
|
+ ['title', '']
|
|
|
|
|
+ ], $this->request);
|
|
|
|
|
+ $this->assign('where', $where);
|
|
|
$where['cid'] = input('cid');
|
|
$where['cid'] = input('cid');
|
|
|
$where['merchant'] = 1;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
|
|
$where['merchant'] = 1;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
|
|
|
$this->assign(ArticleModel::getAll($where));
|
|
$this->assign(ArticleModel::getAll($where));
|
|
@@ -194,7 +187,7 @@ class Article extends AuthController
|
|
|
*/
|
|
*/
|
|
|
public function relation($id = 0)
|
|
public function relation($id = 0)
|
|
|
{
|
|
{
|
|
|
- $this->assign('id',$id);
|
|
|
|
|
|
|
+ $this->assign('id', $id);
|
|
|
return $this->fetch();
|
|
return $this->fetch();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -204,23 +197,24 @@ class Article extends AuthController
|
|
|
*/
|
|
*/
|
|
|
public function edit_article($id = 0)
|
|
public function edit_article($id = 0)
|
|
|
{
|
|
{
|
|
|
- if(!$id) return Json::fail('缺少参数');
|
|
|
|
|
|
|
+ if (!$id) return Json::fail('缺少参数');
|
|
|
list($product_id) = Util::postMore([
|
|
list($product_id) = Util::postMore([
|
|
|
- ['product_id',0]
|
|
|
|
|
- ],$this->request,true);
|
|
|
|
|
- if(ArticleModel::edit(['product_id'=>$product_id],['id'=>$id]))
|
|
|
|
|
|
|
+ ['product_id', 0]
|
|
|
|
|
+ ], $this->request, true);
|
|
|
|
|
+ if (ArticleModel::edit(['product_id' => $product_id], ['id' => $id]))
|
|
|
return Json::successful('保存成功');
|
|
return Json::successful('保存成功');
|
|
|
else
|
|
else
|
|
|
return Json::fail('保存失败');
|
|
return Json::fail('保存失败');
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 取消绑定的产品id
|
|
* 取消绑定的产品id
|
|
|
* @param int $id
|
|
* @param int $id
|
|
|
*/
|
|
*/
|
|
|
public function unrelation($id = 0)
|
|
public function unrelation($id = 0)
|
|
|
{
|
|
{
|
|
|
- if(!$id) return Json::fail('缺少参数');
|
|
|
|
|
- if(ArticleModel::edit(['product_id'=>0],$id))
|
|
|
|
|
|
|
+ if (!$id) return Json::fail('缺少参数');
|
|
|
|
|
+ if (ArticleModel::edit(['product_id' => 0], $id))
|
|
|
return Json::successful('取消关联成功!');
|
|
return Json::successful('取消关联成功!');
|
|
|
else
|
|
else
|
|
|
return Json::fail('取消失败');
|
|
return Json::fail('取消失败');
|