This commit is contained in:
yaooo 2023-12-20 16:06:24 +08:00
commit 6829b9245c
5 changed files with 468 additions and 0 deletions

View File

@ -0,0 +1,108 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\controller\quality;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\quality\QualityProfessionalCategoryLists;
use app\adminapi\logic\quality\QualityProfessionalCategoryLogic;
use app\adminapi\validate\quality\QualityProfessionalCategoryValidate;
/**
* 专业类别控制器
* Class QualityProfessionalCategoryController
* @package app\adminapi\controller\quality
*/
class QualityProfessionalCategoryController extends BaseAdminController
{
/**
* @notes 获取专业类别列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/20 14:50
*/
public function lists()
{
return $this->dataLists(new QualityProfessionalCategoryLists());
}
/**
* @notes 添加专业类别
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/20 14:50
*/
public function add()
{
$params = (new QualityProfessionalCategoryValidate())->post()->goCheck('add');
$result = QualityProfessionalCategoryLogic::add($params,$this->adminId);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(QualityProfessionalCategoryLogic::getError());
}
/**
* @notes 编辑专业类别
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/20 14:50
*/
public function edit()
{
$params = (new QualityProfessionalCategoryValidate())->post()->goCheck('edit');
$result = QualityProfessionalCategoryLogic::edit($params,$this->adminId);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(QualityProfessionalCategoryLogic::getError());
}
/**
* @notes 删除专业类别
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/20 14:50
*/
public function delete()
{
$params = (new QualityProfessionalCategoryValidate())->post()->goCheck('delete');
QualityProfessionalCategoryLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取专业类别详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/20 14:50
*/
public function detail()
{
$params = (new QualityProfessionalCategoryValidate())->goCheck('detail');
$result = QualityProfessionalCategoryLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,86 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\lists\quality;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\model\quality\QualityProfessionalCategory;
use app\common\lists\ListsSearchInterface;
/**
* 专业类别列表
* Class QualityProfessionalCategoryLists
* @package app\adminapi\listsquality
*/
class QualityProfessionalCategoryLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/12/20 14:50
*/
public function setSearch(): array
{
return [
'%like%' => ['classify_name'],
];
}
/**
* @notes 获取专业类别列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/12/20 14:50
*/
public function lists(): array
{
return QualityProfessionalCategory::where($this->searchWhere)
->field(['id', 'org_id', 'dept_id', 'classify_name', 'remark'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($item){
$org = Orgs::field('name')->where('id',$item['org_id'])->findOrEmpty();
$dept = Dept::field('name')->where('id',$item['dept_id'])->findOrEmpty();
$item['org_name'] = $org['name'];
$item['dept_name'] = $dept['name'];
return $item;
})
->toArray();
}
/**
* @notes 获取专业类别数量
* @return int
* @author likeadmin
* @date 2023/12/20 14:50
*/
public function count(): int
{
return QualityProfessionalCategory::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,125 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\quality;
use app\common\model\auth\Admin;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\model\quality\QualityProfessionalCategory;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 专业类别逻辑
* Class QualityProfessionalCategoryLogic
* @package app\adminapi\logic\quality
*/
class QualityProfessionalCategoryLogic extends BaseLogic
{
/**
* @notes 添加专业类别
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/20 14:50
*/
public static function add(array $params,$admin_id): bool
{
Db::startTrans();
try {
QualityProfessionalCategory::create([
'org_id' => $params['org_id'],
'dept_id' => $params['dept_id'],
'classify_name' => $params['classify_name'],
'remark' => $params['remark'],
'add_user' => $admin_id,
'update_user' => $admin_id,
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑专业类别
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/20 14:50
*/
public static function edit(array $params,$admin_id): bool
{
Db::startTrans();
try {
QualityProfessionalCategory::where('id', $params['id'])->update([
'org_id' => $params['org_id'],
'dept_id' => $params['dept_id'],
'classify_name' => $params['classify_name'],
'remark' => $params['remark'],
'update_user' => $admin_id,
'update_time' => time(),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除专业类别
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/20 14:50
*/
public static function delete(array $params): bool
{
return QualityProfessionalCategory::destroy($params['id']);
}
/**
* @notes 获取专业类别详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/12/20 14:50
*/
public static function detail($params): array
{
$data = QualityProfessionalCategory::findOrEmpty($params['id'])->toArray();
$org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty();
$dept = Dept::field('name')->where('id',$data['dept_id'])->findOrEmpty();
$admin = Admin::where('id','in',[$data['add_user'],$data['update_user']])->column('name','id');
$data['org_name'] = $org['name'];
$data['dept_name'] = $dept['name'];
$data['add_user_name'] = $admin[$data['add_user']];
$data['update_user_name'] = $admin[$data['update_user']];
return $data;
}
}

View File

@ -0,0 +1,115 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\quality;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\validate\BaseValidate;
/**
* 专业类别验证器
* Class QualityProfessionalCategoryValidate
* @package app\adminapi\validate\quality
*/
class QualityProfessionalCategoryValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'org_id' => 'require|checkOrg',
'dept_id' => 'require|checkDept',
'classify_name' => 'require',
];
protected $message = [
'id.require' => '缺少必要参数',
'org_id.require' => '请选择组织',
'dept_id.require' => '请选择部门',
'classify_name.require' => '请填写分类名',
];
/**
* @notes 添加场景
* @return QualityProfessionalCategoryValidate
* @author likeadmin
* @date 2023/12/20 14:50
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return QualityProfessionalCategoryValidate
* @author likeadmin
* @date 2023/12/20 14:50
*/
public function sceneEdit()
{}
/**
* @notes 删除场景
* @return QualityProfessionalCategoryValidate
* @author likeadmin
* @date 2023/12/20 14:50
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return QualityProfessionalCategoryValidate
* @author likeadmin
* @date 2023/12/20 14:50
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkOrg($value): bool|string
{
$data = Orgs::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '组织不存在';
}
return true;
}
public function checkDept($value,$rule,$data): bool|string
{
$dept = Dept::where('id',$value)->findOrEmpty();
if($dept->isEmpty()){
return '部门不存在';
}
if($dept['org_id'] != $data['org_id']){
return '部门不属于当前选择的组织';
}
return true;
}
}

View File

@ -0,0 +1,34 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\common\model\quality;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 专业类别模型
* Class QualityProfessionalCategory
* @package app\common\model\quality
*/
class QualityProfessionalCategory extends BaseModel
{
use SoftDelete;
protected $name = 'quality_professional_category';
protected $deleteTime = 'delete_time';
}