文件
MiAn fafddceaf2 feat: 新增发票抬头、晒单、钱包日志等模型及后台管理功能
- 新增 invoice_title、showcase、wallet_log 模型及对应语言包
- 新增后台控制器、视图及搜索字段配置
- 修复服务类目删除保护逻辑
- 优化后台登录页面文案及样式
- 新增前端角色切换逻辑及页面拦截
- 新增 SVG 图标及样式变量
- 修复接口权限及下拉框默认值问题
2026-11-11 17:02:35 +08:00

174 行
5.6 KiB
PHP

<?php
namespace app\admin\controller;
use app\common\controller\Backend;
use think\Db;
/**
* 技能列表管理
*
* @icon fa fa-tags
*/
class SkillDict extends Backend
{
/**
* SkillDict模型对象
* @var \app\admin\model\SkillDict
*/
protected $model = null;
protected $relationSearch = true;
protected $searchFields = 'id,name,category,master.realname';
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\SkillDict;
// 从真实技能分类表中拉取分类列表
$categoryList = Db::name('skill_category')
->where('status', 'normal')
->order('weigh desc, id asc')
->column('name', 'id');
$categorySearchList = [];
foreach ($categoryList as $catName) {
$categorySearchList[$catName] = $catName;
}
$this->view->assign("categoryList", $categoryList);
$this->assignconfig("categorySearchList", $categorySearchList);
$this->view->assign("sourceList", $this->model->getSourceList());
$this->view->assign("statusList", $this->model->getStatusList());
}
/**
* 查看技能列表(支持 category_id 跳转过滤,并统计持证师傅人数)
*/
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();
}
$catIdParam = (int)$this->request->get('category_id', 0);
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
$query = $this->model
->with(['master'])
->where($where);
if ($catIdParam > 0) {
$query->where('skill_dict.category_id', $catIdParam);
}
$list = $query->order($sort, $order)->paginate($limit);
$rows = $list->items();
$names = [];
foreach ($rows as $r) {
if (!empty($r['name'])) {
$names[] = (string)$r['name'];
}
}
$masterCountMap = [];
if ($names) {
$stats = Db::name('master_skill')
->where('skill_name', 'in', array_unique($names))
->field('skill_name, COUNT(DISTINCT master_id) AS cnt')
->group('skill_name')
->select();
foreach ($stats as $st) {
$masterCountMap[$st['skill_name']] = (int)$st['cnt'];
}
}
foreach ($rows as &$item) {
$item['master_count'] = $masterCountMap[$item['name']] ?? 0;
}
unset($item);
return json(['total' => $list->total(), 'rows' => $rows]);
}
/**
* 添加技能
*/
public function add()
{
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
if (!empty($params['category_id'])) {
$cat = Db::name('skill_category')->where('id', $params['category_id'])->find();
if ($cat) {
$params['category'] = $cat['name'];
}
}
$result = $this->model->allowField(true)->save($params);
if ($result !== false) {
$this->success();
} else {
$this->error($this->model->getError());
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
$this->view->assign('defaultCategoryId', (int)$this->request->get('category_id', 0) ?: '');
return $this->view->fetch();
}
/**
* 编辑技能
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
if (!empty($params['category_id'])) {
$cat = Db::name('skill_category')->where('id', $params['category_id'])->find();
if ($cat) {
$params['category'] = $cat['name'];
}
}
$result = $row->allowField(true)->save($params);
if ($result !== false) {
$this->success();
} else {
$this->error($row->getError());
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
$this->view->assign("row", $row);
return $this->view->fetch();
}
/**
* 删除保护:已被师傅绑定的技能禁止物理删除
*/
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'));
}
$names = Db::name('skill_dict')->where('id', 'in', $idArr)->column('name');
if ($names) {
$usedCnt = (int)Db::name('master_skill')->where('skill_name', 'in', $names)->count();
if ($usedCnt > 0) {
$this->error('所选技能已被 ' . $usedCnt . ' 条师傅档案绑定,禁止物理删除,请改为「隐藏停用」');
}
}
return parent::del($ids);
}
}