调整内容

This commit is contained in:
liaofei 2020-01-04 10:55:40 +08:00
parent b27fe89fff
commit d8c86a5d5f
3 changed files with 93 additions and 70 deletions

View File

@ -29,21 +29,11 @@ class Article extends AuthController
{ {
$where = Util::getMore([ $where = Util::getMore([
['title', ''], ['title', ''],
['cid',''] ['cid', $this->request->param('pid', '')]
], $this->request); ], $this->request);
$pid = $this->request->param('pid');
$this->assign('where', $where); $this->assign('where', $where);
$where['merchant'] = 0;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1 $where['merchant'] = 0;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
$cateList = ArticleCategoryModel::getArticleCategoryList(); $tree = sort_list_tier(ArticleCategoryModel::getArticleCategoryList());
$tree = [];
//获取分类列表
if(count($cateList)){
$tree = Phptree::makeTreeForHtml($cateList);
if($pid){
$pids = Util::getChildrenPid($tree,$pid);
$where['cid'] = ltrim($pid.$pids);
}
}
$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 +46,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 = [];
@ -98,7 +89,8 @@ class Article extends AuthController
* 上传图文图片 * 上传图文图片
* @return \think\response\Json * @return \think\response\Json
*/ */
public function upload_image(){ public function upload_image()
{
$res = Upload::instance()->setUploadPath('wechat/image/' . date('Ymd'))->image($_POST['file']); $res = Upload::instance()->setUploadPath('wechat/image/' . date('Ymd'))->image($_POST['file']);
if (!is_array($res)) return Json::fail($res); 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']); SystemAttachment::attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'], 5, $res['image_type'], $res['time']);
@ -108,7 +100,8 @@ class Article extends AuthController
/** /**
* 添加和修改图文 * 添加和修改图文
*/ */
public function add_new(){ public function add_new()
{
$data = Util::postMore([ $data = Util::postMore([
['id', 0], ['id', 0],
['cid', []], ['cid', []],
@ -177,7 +170,8 @@ class Article extends AuthController
return Json::successful('删除成功!'); return Json::successful('删除成功!');
} }
public function merchantIndex(){ public function merchantIndex()
{
$where = Util::getMore([ $where = Util::getMore([
['title', ''] ['title', '']
], $this->request); ], $this->request);
@ -213,6 +207,7 @@ class Article extends AuthController
else else
return Json::fail('保存失败'); return Json::fail('保存失败');
} }
/** /**
* 取消绑定的产品id * 取消绑定的产品id
* @param int $id * @param int $id

View File

@ -13,7 +13,7 @@
<div class="ibox-content"> <div class="ibox-content">
<ul class="folder-list m-b-md"> <ul class="folder-list m-b-md">
{volist name="tree" id="vo"} {volist name="tree" id="vo"}
<li class="p-xxs"><a href="{:Url('article.article/index',array('pid'=>$vo.id))}">{$vo.level|str_repeat='.....',###}{$vo.title}</a></li> <li class="p-xxs"><a href="{:Url('article.article/index',array('pid'=>$vo.id))}">{$vo.html}{$vo.title}</a></li>
{/volist} {/volist}
</ul> </ul>
</div> </div>

View File

@ -194,3 +194,31 @@ if (!function_exists('set_file_url')) {
return $siteUrl . $image; return $siteUrl . $image;
} }
} }
if (!function_exists('sort_list_tier')) {
/**
* 分级排序
* @param $data
* @param int $pid
* @param string $field
* @param string $pk
* @param string $html
* @param int $level
* @param bool $clear
* @return array
*/
function sort_list_tier($data, $pid = 0, $field = 'pid', $pk = 'id', $html = '|-----', $level = 1, $clear = true)
{
static $list = [];
if ($clear) $list = [];
foreach ($data as $k => $res) {
if ($res[$field] == $pid) {
$res['html'] = str_repeat($html, $level);
$list[] = $res;
unset($data[$k]);
sort_list_tier($data, $res[$pk], $field, $pk, $html, $level + 1, false);
}
}
return $list;
}
}