- 新增 invoice_title、showcase、wallet_log 模型及对应语言包 - 新增后台控制器、视图及搜索字段配置 - 修复服务类目删除保护逻辑 - 优化后台登录页面文案及样式 - 新增前端角色切换逻辑及页面拦截 - 新增 SVG 图标及样式变量 - 修复接口权限及下拉框默认值问题
101 行
3.1 KiB
PHP
101 行
3.1 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use app\common\controller\Backend;
|
|
|
|
/**
|
|
* 技能分类管理
|
|
*
|
|
* @icon fa fa-th-large
|
|
*/
|
|
class SkillCategory extends Backend
|
|
{
|
|
/**
|
|
* SkillCategory模型对象
|
|
* @var \app\admin\model\SkillCategory
|
|
*/
|
|
protected $model = null;
|
|
protected $searchFields = 'id,name';
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
$this->model = new \app\admin\model\SkillCategory;
|
|
$this->view->assign("statusList", $this->model->getStatusList());
|
|
}
|
|
|
|
/**
|
|
* 查看分类列表
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->request->filter(['strip_tags', 'trim']);
|
|
if (false === $this->request->isAjax()) {
|
|
return $this->view->fetch();
|
|
}
|
|
if ($this->request->request('keyField')) {
|
|
return $this->selectpage();
|
|
}
|
|
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
|
|
$list = $this->model
|
|
->withCount('skills')
|
|
->where($where)
|
|
->order($sort, $order)
|
|
->paginate($limit);
|
|
|
|
$result = ['total' => $list->total(), 'rows' => $list->items()];
|
|
return json($result);
|
|
}
|
|
|
|
/**
|
|
* 编辑分类(当分类名称变更时同步更新技能字典冗余分类名)
|
|
*/
|
|
public function edit($ids = null)
|
|
{
|
|
$row = $this->model->get($ids);
|
|
if (!$row) {
|
|
$this->error(__('No Results were found'));
|
|
}
|
|
$oldName = (string)$row['name'];
|
|
if (false === $this->request->isPost()) {
|
|
$this->view->assign('row', $row);
|
|
return $this->view->fetch();
|
|
}
|
|
$params = $this->request->post('row/a', []);
|
|
if (!$params) {
|
|
$this->error(__('Parameter %s can not be empty', ''));
|
|
}
|
|
$params = $this->preExcludeFields($params);
|
|
$result = $row->allowField(true)->save($params);
|
|
if ($result !== false) {
|
|
$newName = isset($params['name']) ? trim((string)$params['name']) : $oldName;
|
|
if ($newName !== '' && $newName !== $oldName) {
|
|
\think\Db::name('skill_dict')->where('category_id', (int)$row['id'])->update(['category' => $newName]);
|
|
}
|
|
$this->success();
|
|
}
|
|
$this->error($row->getError() ?: __('No rows were updated'));
|
|
}
|
|
|
|
/**
|
|
* 删除保护:分类下仍有关联技能时禁止物理删除
|
|
*/
|
|
public function del($ids = null)
|
|
{
|
|
if (false === $this->request->isPost()) {
|
|
$this->error(__('Invalid parameters'));
|
|
}
|
|
$ids = $ids ?: $this->request->post('ids');
|
|
$idArr = array_values(array_filter(array_map('intval', explode(',', (string)$ids))));
|
|
if (!$idArr) {
|
|
$this->error(__('Parameter %s can not be empty', 'ids'));
|
|
}
|
|
$cnt = (int)\think\Db::name('skill_dict')->where('category_id', 'in', $idArr)->count();
|
|
if ($cnt > 0) {
|
|
$this->error('所选分类下仍包含 ' . $cnt . ' 项技能标签,请先迁移或删除下属技能后再操作');
|
|
}
|
|
return parent::del($ids);
|
|
}
|
|
}
|