update
This commit is contained in:
parent
be796ba02b
commit
64d954d7a1
@ -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\project;
|
||||||
|
|
||||||
|
|
||||||
|
use app\adminapi\controller\BaseAdminController;
|
||||||
|
use app\adminapi\lists\project\ProjectMaterialBudgetLists;
|
||||||
|
use app\adminapi\logic\project\ProjectMaterialBudgetLogic;
|
||||||
|
use app\adminapi\validate\project\ProjectMaterialBudgetValidate;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 材料预算控制器
|
||||||
|
* Class ProjectMaterialBudgetController
|
||||||
|
* @package app\adminapi\controller\project
|
||||||
|
*/
|
||||||
|
class ProjectMaterialBudgetController extends BaseAdminController
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 获取材料预算列表
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2024/01/08 16:30
|
||||||
|
*/
|
||||||
|
public function lists()
|
||||||
|
{
|
||||||
|
return $this->dataLists(new ProjectMaterialBudgetLists());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 添加材料预算
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2024/01/08 16:30
|
||||||
|
*/
|
||||||
|
public function add()
|
||||||
|
{
|
||||||
|
$params = (new ProjectMaterialBudgetValidate())->post()->goCheck('add');
|
||||||
|
$result = ProjectMaterialBudgetLogic::add($params);
|
||||||
|
if (true === $result) {
|
||||||
|
return $this->success('添加成功', [], 1, 1);
|
||||||
|
}
|
||||||
|
return $this->fail(ProjectMaterialBudgetLogic::getError());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 编辑材料预算
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2024/01/08 16:30
|
||||||
|
*/
|
||||||
|
public function edit()
|
||||||
|
{
|
||||||
|
$params = (new ProjectMaterialBudgetValidate())->post()->goCheck('edit');
|
||||||
|
$result = ProjectMaterialBudgetLogic::edit($params);
|
||||||
|
if (true === $result) {
|
||||||
|
return $this->success('编辑成功', [], 1, 1);
|
||||||
|
}
|
||||||
|
return $this->fail(ProjectMaterialBudgetLogic::getError());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 删除材料预算
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2024/01/08 16:30
|
||||||
|
*/
|
||||||
|
public function delete()
|
||||||
|
{
|
||||||
|
$params = (new ProjectMaterialBudgetValidate())->post()->goCheck('delete');
|
||||||
|
ProjectMaterialBudgetLogic::delete($params);
|
||||||
|
return $this->success('删除成功', [], 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 获取材料预算详情
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2024/01/08 16:30
|
||||||
|
*/
|
||||||
|
public function detail()
|
||||||
|
{
|
||||||
|
$params = (new ProjectMaterialBudgetValidate())->goCheck('detail');
|
||||||
|
$result = ProjectMaterialBudgetLogic::detail($params);
|
||||||
|
return $this->data($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
77
app/adminapi/lists/project/ProjectMaterialBudgetLists.php
Normal file
77
app/adminapi/lists/project/ProjectMaterialBudgetLists.php
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?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\project;
|
||||||
|
|
||||||
|
|
||||||
|
use app\adminapi\lists\BaseAdminDataLists;
|
||||||
|
use app\common\model\project\ProjectMaterialBudget;
|
||||||
|
use app\common\lists\ListsSearchInterface;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 材料预算列表
|
||||||
|
* Class ProjectMaterialBudgetLists
|
||||||
|
* @package app\adminapi\listsproject
|
||||||
|
*/
|
||||||
|
class ProjectMaterialBudgetLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 设置搜索条件
|
||||||
|
* @return \string[][]
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2024/01/08 16:30
|
||||||
|
*/
|
||||||
|
public function setSearch(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'=' => ['project_id', 'material_id', 'budget_type'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 获取材料预算列表
|
||||||
|
* @return array
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2024/01/08 16:30
|
||||||
|
*/
|
||||||
|
public function lists(): array
|
||||||
|
{
|
||||||
|
return ProjectMaterialBudget::where($this->searchWhere)
|
||||||
|
->field(['id', 'project_id', 'material_id', 'budget_type', 'num', 'price', 'amount', 'remark'])
|
||||||
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
|
->order(['id' => 'desc'])
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 获取材料预算数量
|
||||||
|
* @return int
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2024/01/08 16:30
|
||||||
|
*/
|
||||||
|
public function count(): int
|
||||||
|
{
|
||||||
|
return ProjectMaterialBudget::where($this->searchWhere)->count();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
113
app/adminapi/logic/project/ProjectMaterialBudgetLogic.php
Normal file
113
app/adminapi/logic/project/ProjectMaterialBudgetLogic.php
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
<?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\project;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\model\project\ProjectMaterialBudget;
|
||||||
|
use app\common\logic\BaseLogic;
|
||||||
|
use think\facade\Db;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 材料预算逻辑
|
||||||
|
* Class ProjectMaterialBudgetLogic
|
||||||
|
* @package app\adminapi\logic\project
|
||||||
|
*/
|
||||||
|
class ProjectMaterialBudgetLogic extends BaseLogic
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 添加材料预算
|
||||||
|
* @param array $params
|
||||||
|
* @return bool
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2024/01/08 16:30
|
||||||
|
*/
|
||||||
|
public static function add(array $params): bool
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
ProjectMaterialBudget::create([
|
||||||
|
'org_id' => $params['org_id'],
|
||||||
|
'dept_id' => $params['dept_id'],
|
||||||
|
'project_id' => $params['project_id'],
|
||||||
|
'material_budget_code' => data_unique_code('项目材料预算'),
|
||||||
|
'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/08 16:30
|
||||||
|
*/
|
||||||
|
public static function edit(array $params): bool
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
ProjectMaterialBudget::where('id', $params['id'])->update([
|
||||||
|
'org_id' => $params['org_id'],
|
||||||
|
'dept_id' => $params['dept_id'],
|
||||||
|
'project_id' => $params['project_id'],
|
||||||
|
'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/08 16:30
|
||||||
|
*/
|
||||||
|
public static function delete(array $params): bool
|
||||||
|
{
|
||||||
|
return ProjectMaterialBudget::destroy($params['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 获取材料预算详情
|
||||||
|
* @param $params
|
||||||
|
* @return array
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2024/01/08 16:30
|
||||||
|
*/
|
||||||
|
public static function detail($params): array
|
||||||
|
{
|
||||||
|
return ProjectMaterialBudget::findOrEmpty($params['id'])->toArray();
|
||||||
|
}
|
||||||
|
}
|
175
app/adminapi/validate/project/ProjectMaterialBudgetValidate.php
Normal file
175
app/adminapi/validate/project/ProjectMaterialBudgetValidate.php
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
<?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\project;
|
||||||
|
|
||||||
|
use app\common\model\dept\Dept;
|
||||||
|
use app\common\model\dept\Orgs;
|
||||||
|
use app\common\model\material\Material;
|
||||||
|
use app\common\model\project\Project;
|
||||||
|
use app\common\validate\BaseValidate;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 材料预算验证器
|
||||||
|
* Class ProjectMaterialBudgetValidate
|
||||||
|
* @package app\adminapi\validate\project
|
||||||
|
*/
|
||||||
|
class ProjectMaterialBudgetValidate extends BaseValidate
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置校验规则
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
protected $rule = [
|
||||||
|
'id' => 'require',
|
||||||
|
'org_id' => 'require|checkOrg',
|
||||||
|
'dept_id' => 'require|checkDept',
|
||||||
|
'project_id' => 'require|checkProject',
|
||||||
|
'annex' => 'checkAnnex',
|
||||||
|
'material_budget_detail' => 'require|checkMaterialBudgetDetail'
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $message = [
|
||||||
|
'id.require' => '缺少必要参数',
|
||||||
|
'project_id.require' => '请选择项目',
|
||||||
|
'material_budget_detail.require' => '请填写材料预算清单'
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 添加场景
|
||||||
|
* @return ProjectMaterialBudgetValidate
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2024/01/08 16:30
|
||||||
|
*/
|
||||||
|
public function sceneAdd()
|
||||||
|
{
|
||||||
|
return $this->remove('id',true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 编辑场景
|
||||||
|
* @return ProjectMaterialBudgetValidate
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2024/01/08 16:30
|
||||||
|
*/
|
||||||
|
public function sceneEdit()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 删除场景
|
||||||
|
* @return ProjectMaterialBudgetValidate
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2024/01/08 16:30
|
||||||
|
*/
|
||||||
|
public function sceneDelete()
|
||||||
|
{
|
||||||
|
return $this->only(['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 详情场景
|
||||||
|
* @return ProjectMaterialBudgetValidate
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2024/01/08 16:30
|
||||||
|
*/
|
||||||
|
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 '项目信息不存在';
|
||||||
|
}
|
||||||
|
if($project['is_budget'] != 1){
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function checkMaterialBudgetDetail($value): bool|string
|
||||||
|
{
|
||||||
|
$detail = json_decode($value,true);
|
||||||
|
if(empty($detail) || !is_array($detail)){
|
||||||
|
return '材料预算清单数据格式错误';
|
||||||
|
}
|
||||||
|
foreach($detail as $v) {
|
||||||
|
if(empty($v['material_id'])){
|
||||||
|
return '请选择材料';
|
||||||
|
}else{
|
||||||
|
$product = Material::where('id',$v['material_id'])->findOrEmpty();
|
||||||
|
if($product->isEmpty()){
|
||||||
|
return '材料信息不存在';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(empty($v['num'])){
|
||||||
|
return '数量不能为空';
|
||||||
|
}else{
|
||||||
|
if(!is_numeric($v['num']) || $v['num'] < 0){
|
||||||
|
return '数量必须是大于0的数字';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(empty($v['price'])){
|
||||||
|
return '单价不能为空';
|
||||||
|
}else{
|
||||||
|
if(!is_numeric($v['price']) || $v['price'] < 0){
|
||||||
|
return '单价必须是大于0的数字';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
37
app/common/model/project/ProjectMaterialBudget.php
Normal file
37
app/common/model/project/ProjectMaterialBudget.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?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\project;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\model\BaseModel;
|
||||||
|
use app\common\model\dict\DictData;
|
||||||
|
use think\model\concern\SoftDelete;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 材料预算模型
|
||||||
|
* Class ProjectMaterialBudget
|
||||||
|
* @package app\common\model\project
|
||||||
|
*/
|
||||||
|
class ProjectMaterialBudget extends BaseModel
|
||||||
|
{
|
||||||
|
use SoftDelete;
|
||||||
|
protected $name = 'project_material_budget';
|
||||||
|
protected $deleteTime = 'delete_time';
|
||||||
|
|
||||||
|
public function getAnnexAttr($value){
|
||||||
|
return !empty($value) ? json_decode($value) : '';
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user