You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
134 lines
3.8 KiB
134 lines
3.8 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
|
// +----------------------------------------------------------------------
|
|
// | Author: CRMEB Team <admin@crmeb.com>
|
|
// +----------------------------------------------------------------------
|
|
namespace app\controller\supplier\file;
|
|
|
|
use app\controller\supplier\AuthController;
|
|
use app\services\system\attachment\SystemAttachmentCategoryServices;
|
|
use think\facade\App;
|
|
|
|
/**
|
|
* 图片分类管理类
|
|
* Class SystemAttachmentCategory
|
|
* @package app\controller\supplier\file
|
|
*/
|
|
class SystemAttachmentCategory extends AuthController
|
|
{
|
|
|
|
protected $service;
|
|
|
|
public function __construct(App $app, SystemAttachmentCategoryServices $service)
|
|
{
|
|
parent::__construct($app);
|
|
$this->service = $service;
|
|
}
|
|
|
|
/**
|
|
* 显示资源列表
|
|
*
|
|
* @return \think\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$where = $this->request->getMore([
|
|
['name', ''],
|
|
['pid', 0],
|
|
['file_type', 1]
|
|
]);
|
|
$where['type'] = 4;
|
|
$where['relation_id'] = $this->supplierId;
|
|
if ($where['name'] != '') $where['pid'] = '';
|
|
return app('json')->success($this->service->getAll($where));
|
|
}
|
|
|
|
/**
|
|
* 新增表单
|
|
* @return mixed
|
|
* @throws \FormBuilder\Exception\FormBuilderException
|
|
*/
|
|
public function create($id)
|
|
{
|
|
[$file_type] = $this->request->postMore([
|
|
['file_type', 1]
|
|
], true);
|
|
return app('json')->success($this->service->createForm($id, 4, $this->supplierId, (int)$file_type));
|
|
}
|
|
|
|
/**
|
|
* 保存新增
|
|
* @return mixed
|
|
*/
|
|
public function save()
|
|
{
|
|
$data = $this->request->postMore([
|
|
['pid', 0],
|
|
['name', ''],
|
|
['file_type', 1]
|
|
]);
|
|
if (!$data['name']) {
|
|
return app('json')->fail('请输入分类名称');
|
|
}
|
|
$data['type'] = 4;
|
|
$data['relation_id'] = $this->supplierId;
|
|
$this->service->save($data);
|
|
return app('json')->success('添加成功');
|
|
}
|
|
|
|
/**
|
|
* 编辑表单
|
|
* @param $id
|
|
* @return mixed
|
|
* @throws \FormBuilder\Exception\FormBuilderException
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
[$file_type] = $this->request->postMore([
|
|
['file_type', 1]
|
|
], true);
|
|
return app('json')->success($this->service->editForm($id, 4, $this->supplierId, (int)$file_type));
|
|
}
|
|
|
|
/**
|
|
* 保存更新的资源
|
|
*
|
|
* @param \think\Request $request
|
|
* @param int $id
|
|
* @return \think\Response
|
|
*/
|
|
public function update($id)
|
|
{
|
|
$data = $this->request->postMore([
|
|
['pid', 0],
|
|
['name', ''],
|
|
['file_type', 1]
|
|
]);
|
|
if (!$data['name']) {
|
|
return app('json')->fail('请输入分类名称');
|
|
}
|
|
$info = $this->service->get($id);
|
|
$data['relation_id'] = $this->supplierId;
|
|
$count = $this->service->count(['pid' => $id]);
|
|
if ($count && $info['pid'] != $data['pid']) return app('json')->fail('该分类有下级分类,无法修改上级');
|
|
$this->service->update($id, $data);
|
|
return app('json')->success('分类编辑成功!');
|
|
}
|
|
|
|
/**
|
|
* 删除指定资源
|
|
*
|
|
* @param int $id
|
|
* @return \think\Response
|
|
*/
|
|
public function delete($id)
|
|
{
|
|
$this->service->del($id);
|
|
return app('json')->success('删除成功!');
|
|
}
|
|
}
|
|
|