Merge pull request '新增仓库管理模块' (#112) from zhangwei into dev

Reviewed-on: #112
This commit is contained in:
weiz 2024-01-04 15:19:24 +08:00
commit a4b076de60
5 changed files with 547 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\material;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\material\MaterialWarehouseLists;
use app\adminapi\logic\material\MaterialWarehouseLogic;
use app\adminapi\validate\material\MaterialWarehouseValidate;
/**
* 仓库管理控制器
* Class MaterialWarehouseController
* @package app\adminapi\controller\material
*/
class MaterialWarehouseController extends BaseAdminController
{
/**
* @notes 获取仓库管理列表
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/04 14:23
*/
public function lists()
{
return $this->dataLists(new MaterialWarehouseLists());
}
/**
* @notes 添加仓库管理
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/04 14:23
*/
public function add()
{
$params = (new MaterialWarehouseValidate())->post()->goCheck('add');
$result = MaterialWarehouseLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(MaterialWarehouseLogic::getError());
}
/**
* @notes 编辑仓库管理
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/04 14:23
*/
public function edit()
{
$params = (new MaterialWarehouseValidate())->post()->goCheck('edit');
$result = MaterialWarehouseLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(MaterialWarehouseLogic::getError());
}
/**
* @notes 删除仓库管理
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/04 14:23
*/
public function delete()
{
$params = (new MaterialWarehouseValidate())->post()->goCheck('delete');
MaterialWarehouseLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取仓库管理详情
* @return \think\response\Json
* @author likeadmin
* @date 2024/01/04 14:23
*/
public function detail()
{
$params = (new MaterialWarehouseValidate())->goCheck('detail');
$result = MaterialWarehouseLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,101 @@
<?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\material;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\auth\Admin;
use app\common\model\material\MaterialWarehouse;
use app\common\lists\ListsSearchInterface;
use app\common\model\project\Project;
/**
* 仓库管理列表
* Class MaterialWarehouseLists
* @package app\adminapi\listsmaterial
*/
class MaterialWarehouseLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/01/04 14:23
*/
public function setSearch(): array
{
return [
'=' => ['is_mrp'],
'%like%' => ['code', 'name'],
];
}
/**
* @notes 获取仓库管理列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/01/04 14:23
*/
public function lists(): array
{
$params = $this->request->get(['project_name']);
$where = [];
if(isset($params['project_name']) && $params['project_name'] != ''){
$project_ids = Project::where('name','like','%'.$params['project_name'].'%')->column('id');
$where[] = ['project_id','in',$project_ids];
}
return MaterialWarehouse::where($this->searchWhere)->where($where)
->field(['id', 'org_id', 'dept_id', 'project_id', 'code', 'name', 'is_mrp', 'head_user', 'address', 'telephone', 'remark', 'annex'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($item){
$project = Project::field('name,project_code')->where('id',$item['project_id'])->findOrEmpty();
$admin = Admin::field('name')->where('id',$item['head_user'])->findOrEmpty();
$item['project_name'] = $project['name'];
$item['project_code'] = $project['project_code'];
$item['head_user'] = $admin['name'];
$item['is_mrp'] = $item->is_mrp_text;
unset($item['org_id'],$item['dept_id'],$item['project_id']);
return $item;
})
->toArray();
}
/**
* @notes 获取仓库管理数量
* @return int
* @author likeadmin
* @date 2024/01/04 14:23
*/
public function count(): int
{
$params = $this->request->get(['project_name']);
$where = [];
if(isset($params['project_name']) && $params['project_name'] != ''){
$project_ids = Project::where('name','like','%'.$params['project_name'].'%')->column('id');
$where[] = ['project_id','in',$project_ids];
}
return MaterialWarehouse::where($this->searchWhere)->where($where)->count();
}
}

View File

@ -0,0 +1,140 @@
<?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\material;
use app\common\model\auth\Admin;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\model\material\MaterialWarehouse;
use app\common\logic\BaseLogic;
use app\common\model\project\Project;
use think\facade\Db;
/**
* 仓库管理逻辑
* Class MaterialWarehouseLogic
* @package app\adminapi\logic\material
*/
class MaterialWarehouseLogic extends BaseLogic
{
/**
* @notes 添加仓库管理
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/04 14:23
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
MaterialWarehouse::create([
'org_id' => $params['org_id'],
'dept_id' => $params['dept_id'],
'project_id' => $params['project_id'],
'code' => data_unique_code('CK'),
'name' => $params['name'],
'is_mrp' => $params['is_mrp'],
'head_user' => $params['head_user'],
'address' => $params['address'] ?? '',
'telephone' => $params['telephone'],
'remark' => $params['remark'] ?? '',
'annex' => !empty($params['annex']) ? $params['annex'] : null,
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑仓库管理
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/01/04 14:23
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
MaterialWarehouse::where('id', $params['id'])->update([
'org_id' => $params['org_id'],
'dept_id' => $params['dept_id'],
'project_id' => $params['project_id'],
'code' => data_unique_code('CK'),
'name' => $params['name'],
'is_mrp' => $params['is_mrp'],
'head_user' => $params['head_user'],
'address' => $params['address'] ?? '',
'telephone' => $params['telephone'],
'remark' => $params['remark'] ?? '',
'annex' => !empty($params['annex']) ? $params['annex'] : null,
'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 2024/01/04 14:23
*/
public static function delete(array $params): bool
{
return MaterialWarehouse::destroy($params['id']);
}
/**
* @notes 获取仓库管理详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/01/04 14:23
*/
public static function detail($params): array
{
$data = MaterialWarehouse::field('id,org_id,dept_id,project_id,code,name,is_mrp,head_user,address,telephone,remark,annex')->findOrEmpty($params['id']);
$org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty();
$dept = Dept::field('name')->where('id',$data['dept_id'])->findOrEmpty();
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
$admin = Admin::field('name')->where('id',$data['head_user'])->findOrEmpty();
$data['org_name'] = $org['name'];
$data['dept_name'] = $dept['name'];
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
$data['head_user_name'] = $admin['name'];
$data['is_mrp_text'] = $data->is_mrp_text;
return $data->toArray();
}
}

View File

@ -0,0 +1,155 @@
<?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\material;
use app\common\model\auth\Admin;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\model\project\Project;
use app\common\validate\BaseValidate;
/**
* 仓库管理验证器
* Class MaterialWarehouseValidate
* @package app\adminapi\validate\material
*/
class MaterialWarehouseValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'org_id' => 'require|checkOrg',
'dept_id' => 'require|checkDept',
'project_id' => 'require|checkProject',
'name' => 'require',
'is_mrp' => 'require|in:0,1',
'head_user' => 'require|checkUser',
'annex' => 'checkAnnex'
];
protected $message = [
'id.require' => '缺少必要参数',
'org_id.require' => '请选择组织',
'dept_id.require' => '请选择部门',
'project_id.require' => '请选择项目',
'name.require' => '请填写仓库名称',
'is_mrp.require' => '请选择是否是MRP仓库',
'is_mrp.in' => '是否是MRP仓库选项值无效',
'head_user.require' => '请选择负责人',
];
/**
* @notes 添加场景
* @return MaterialWarehouseValidate
* @author likeadmin
* @date 2024/01/04 14:23
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return MaterialWarehouseValidate
* @author likeadmin
* @date 2024/01/04 14:23
*/
public function sceneEdit()
{}
/**
* @notes 删除场景
* @return MaterialWarehouseValidate
* @author likeadmin
* @date 2024/01/04 14:23
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return MaterialWarehouseValidate
* @author likeadmin
* @date 2024/01/04 14:23
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkOrg($value): bool|string
{
$org = Orgs::where('id',$value)->findOrEmpty();
if($org->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;
}
public function checkProject($value): bool|string
{
$project = Project::where('id',$value)->findOrEmpty();
if($project->isEmpty()){
return '项目不存在';
}
return true;
}
public function checkUser($value): bool|string
{
$user = Admin::where('id',$value)->findOrEmpty();
if($user->isEmpty()){
return '负责人信息不存在';
}
return true;
}
public function checkAnnex($value): bool|string
{
if(!empty($value) && $value != ''){
$annex = json_decode($value,true);
if(empty($annex) || !is_array($annex)){
return '附件格式错误';
}
}
return true;
}
}

View File

@ -0,0 +1,43 @@
<?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\material;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 仓库管理模型
* Class MaterialWarehouse
* @package app\common\model\material
*/
class MaterialWarehouse extends BaseModel
{
use SoftDelete;
protected $name = 'material_warehouse';
protected $deleteTime = 'delete_time';
public function getAnnexAttr($value)
{
return empty($value) ? null : json_decode($value,true);
}
public function getIsMrpTextAttr($value,$data): string
{
$mrp = [0=>'否',1=>'是'];
return $mrp[$data['is_mrp']];
}
}