update
This commit is contained in:
parent
24a4e1f3b1
commit
03c6e5f51e
@ -0,0 +1,78 @@
|
||||
<?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\MaterialPurchaseRequestLists;
|
||||
use app\adminapi\logic\material\MaterialPurchaseRequestLogic;
|
||||
use app\adminapi\validate\material\MaterialPurchaseRequestValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 材料采购申请控制器
|
||||
* Class MaterialPurchaseRequestController
|
||||
* @package app\adminapi\controller\material
|
||||
*/
|
||||
class MaterialPurchaseRequestController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取材料采购申请列表
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new MaterialPurchaseRequestLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加材料采购申请
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new MaterialPurchaseRequestValidate())->post()->goCheck('add');
|
||||
$result = MaterialPurchaseRequestLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(MaterialPurchaseRequestLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取材料采购申请详情
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new MaterialPurchaseRequestValidate())->goCheck('detail');
|
||||
$result = MaterialPurchaseRequestLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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\controller\material;
|
||||
|
||||
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\lists\material\MaterialPurchaseRequestDetailLists;
|
||||
use app\adminapi\logic\material\MaterialPurchaseRequestDetailLogic;
|
||||
use app\adminapi\validate\material\MaterialPurchaseRequestDetailValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 材料采购申请明细控制器
|
||||
* Class MaterialPurchaseRequestDetailController
|
||||
* @package app\adminapi\controller\material
|
||||
*/
|
||||
class MaterialPurchaseRequestDetailController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取材料采购申请明细列表
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new MaterialPurchaseRequestDetailLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑材料采购申请明细
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new MaterialPurchaseRequestDetailValidate())->post()->goCheck('edit');
|
||||
$result = MaterialPurchaseRequestDetailLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(MaterialPurchaseRequestDetailLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取材料采购申请明细详情
|
||||
* @return \think\response\Json
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new MaterialPurchaseRequestDetailValidate())->goCheck('detail');
|
||||
$result = MaterialPurchaseRequestDetailLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
<?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\material\Material;
|
||||
use app\common\model\material\MaterialClassify;
|
||||
use app\common\model\material\MaterialPurchaseRequest;
|
||||
use app\common\model\material\MaterialPurchaseRequestDetail;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\project\Project;
|
||||
use app\common\model\project\ProjectMaterialBudgetDetail;
|
||||
|
||||
|
||||
/**
|
||||
* 材料采购申请明细列表
|
||||
* Class MaterialPurchaseRequestDetailLists
|
||||
* @package app\adminapi\listsmaterial
|
||||
*/
|
||||
class MaterialPurchaseRequestDetailLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['project_material_budget_detail_id'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取材料采购申请明细列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return MaterialPurchaseRequestDetail::where($this->searchWhere)
|
||||
->field(['id', 'project_material_budget_detail_id', 'num'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($data){
|
||||
$material_purchase_request = MaterialPurchaseRequest::field('material_purchase_request_code,project_id,apply_date,arrival_date')->where('id',$data['material_purchase_request_id'])->findOrEmpty();
|
||||
$project = Project::field('name,project_code')->where('id',$material_purchase_request['project_id'])->findOrEmpty();
|
||||
$project_material_budget_detail = ProjectMaterialBudgetDetail::field('material_id')->where('id',$data['project_material_budget_detail_id'])->findOrEmpty();
|
||||
$material = Material::field('first_level,second_level,three_level,name,code,specs,brand,parameter_description,unit')->where('id',$project_material_budget_detail['material_id'])->findOrEmpty();
|
||||
$material_classify = MaterialClassify::where('id','in',[$material['first_level'],$material['second_level'],$material['three_level']])->column('name','id');
|
||||
$data['material_purchase_request_code'] = $material_purchase_request['material_purchase_request_code'];
|
||||
$data['project_name'] = $project['name'];
|
||||
$data['project_code'] = $project['project_code'];
|
||||
$data['apply_date'] = $material_purchase_request['apply_date'];
|
||||
$data['arrival_date'] = $material_purchase_request['arrival_date'];
|
||||
$data['material_first_level'] = $material_classify[$material['first_level']];
|
||||
$data['material_second_level'] = !empty($material_classify[$material['second_level']]) ? $material_classify[$material['second_level']] : '';
|
||||
$data['material_three_level'] = !empty($material_classify[$material['three_level']]) ? $material_classify[$material['three_level']] : '';
|
||||
$data['material_name'] = $material['name'];
|
||||
$data['material_code'] = $material['code'];
|
||||
$data['material_specs'] = $material['specs'];
|
||||
$data['material_brand'] = $material['brand'];
|
||||
$data['material_parameter_description'] = $material['parameter_description'];
|
||||
$data['material_unit'] = $material['unit'];
|
||||
//已采购数量
|
||||
$data['has_procure_num'] = 0;
|
||||
//未采购数量
|
||||
$data['not_procure_num'] = $data['num'] - $data['has_procure_num'];
|
||||
return $data;
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取材料采购申请明细数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return MaterialPurchaseRequestDetail::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
84
app/adminapi/lists/material/MaterialPurchaseRequestLists.php
Normal file
84
app/adminapi/lists/material/MaterialPurchaseRequestLists.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?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\material\MaterialPurchaseRequest;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\project\Project;
|
||||
|
||||
|
||||
/**
|
||||
* 材料采购申请列表
|
||||
* Class MaterialPurchaseRequestLists
|
||||
* @package app\adminapi\listsmaterial
|
||||
*/
|
||||
class MaterialPurchaseRequestLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['project_id'],
|
||||
'%like%' => ['material_purchase_request_code'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取材料采购申请列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return MaterialPurchaseRequest::where($this->searchWhere)
|
||||
->field('id,project_id,material_purchase_request_code,apply_date,arrival_date,remark')
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($data){
|
||||
$project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty();
|
||||
$data['project_name'] = $project['name'];
|
||||
$data['project_code'] = $project['project_code'];
|
||||
return $data;
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取材料采购申请数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return MaterialPurchaseRequest::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
@ -18,6 +18,7 @@ namespace app\adminapi\lists\project;
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\model\material\Material;
|
||||
use app\common\model\material\MaterialClassify;
|
||||
use app\common\model\material\MaterialPurchaseRequestDetail;
|
||||
use app\common\model\project\Project;
|
||||
use app\common\model\project\ProjectMaterialBudget;
|
||||
use app\common\model\project\ProjectMaterialBudgetDetail;
|
||||
@ -81,7 +82,7 @@ class ProjectMaterialBudgetDetailLists extends BaseAdminDataLists implements Lis
|
||||
$data['material_parameter_description'] = $material['parameter_description'];
|
||||
$data['material_unit'] = $material['unit'];
|
||||
//申购数量
|
||||
$data['apply_num'] = 0;
|
||||
$data['apply_num'] = MaterialPurchaseRequestDetail::where('project_material_budget_detail_id',$data['id'])->sum('num');;
|
||||
//剩余预算数量
|
||||
$data['residual_num'] = $data['num'] - $data['apply_num'];
|
||||
return $data;
|
||||
|
@ -16,6 +16,7 @@ namespace app\adminapi\lists\project;
|
||||
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\model\material\MaterialPurchaseRequestDetail;
|
||||
use app\common\model\project\Project;
|
||||
use app\common\model\project\ProjectMaterialBudget;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
@ -70,7 +71,8 @@ class ProjectMaterialBudgetLists extends BaseAdminDataLists implements ListsSear
|
||||
//预算总金额
|
||||
$data['total_amount'] = ProjectMaterialBudgetDetail::where('material_budget_id',$data['id'])->sum('amount');
|
||||
//申购总数量
|
||||
$data['total_apply_num'] = 0;
|
||||
$ProjectMaterialBudgetDetailIds = ProjectMaterialBudgetDetail::where('material_budget_id',$data['id'])->column('id');
|
||||
$data['total_apply_num'] = MaterialPurchaseRequestDetail::where('project_material_budget_detail_id','in',$ProjectMaterialBudgetDetailIds)->sum('num');
|
||||
//剩余预算总数量
|
||||
$data['total_residual_num'] = $data['total_num'] - $data['total_apply_num'];
|
||||
return $data;
|
||||
|
@ -0,0 +1,141 @@
|
||||
<?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\material\Material;
|
||||
use app\common\model\material\MaterialClassify;
|
||||
use app\common\model\material\MaterialPurchaseRequest;
|
||||
use app\common\model\material\MaterialPurchaseRequestDetail;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\project\Project;
|
||||
use app\common\model\project\ProjectMaterialBudgetDetail;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 材料采购申请明细逻辑
|
||||
* Class MaterialPurchaseRequestDetailLogic
|
||||
* @package app\adminapi\logic\material
|
||||
*/
|
||||
class MaterialPurchaseRequestDetailLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加材料采购申请明细
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
MaterialPurchaseRequestDetail::create([
|
||||
'num' => $params['num'],
|
||||
]);
|
||||
|
||||
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/09 13:47
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
$data = MaterialPurchaseRequestDetail::where('id',$params['id'])->findOrEmpty();
|
||||
Db::startTrans();
|
||||
try {
|
||||
MaterialPurchaseRequestDetail::where('id', $params['id'])->update([
|
||||
'num' => $params['num'],
|
||||
'remark' => $params['remark'] ?? '',
|
||||
'update_time' => time()
|
||||
]);
|
||||
//预算数量
|
||||
$project_material_budget_detail = ProjectMaterialBudgetDetail::field('num')->where('id',$data['project_material_budget_detail_id'])->findOrEmpty();
|
||||
//已经申购的数量
|
||||
$purchase_request_num = MaterialPurchaseRequestDetail::where('project_material_budget_detail_id',$data['project_material_budget_detail_id'])->where('id','<>',$params['id'])->sum('num');
|
||||
if($project_material_budget_detail['num'] - $purchase_request_num - $params['num'] <=0){
|
||||
ProjectMaterialBudgetDetail::where('id',$data['project_material_budget_detail_id'])->update(['is_residual'=>1,'update_time'=>time()]);
|
||||
}else{
|
||||
ProjectMaterialBudgetDetail::where('id',$data['project_material_budget_detail_id'])->update(['is_residual'=>0,'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/09 13:47
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return MaterialPurchaseRequestDetail::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取材料采购申请明细详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$data = MaterialPurchaseRequestDetail::field('id,material_purchase_request_id,project_material_budget_detail_id,num')->findOrEmpty($params['id']);
|
||||
$material_purchase_request = MaterialPurchaseRequest::field('project_id,apply_date,arrival_date')->where('id',$data['material_purchase_request_id'])->findOrEmpty();
|
||||
$project = Project::field('name,project_code')->where('id',$material_purchase_request['project_id'])->findOrEmpty();
|
||||
$project_material_budget_detail = ProjectMaterialBudgetDetail::field('material_id')->where('id',$data['project_material_budget_detail_id'])->findOrEmpty();
|
||||
$material = Material::field('first_level,second_level,three_level,name,code,specs,brand,parameter_description,unit')->where('id',$project_material_budget_detail['material_id'])->findOrEmpty();
|
||||
$material_classify = MaterialClassify::where('id','in',[$material['first_level'],$material['second_level'],$material['three_level']])->column('name','id');
|
||||
$data['project_name'] = $project['name'];
|
||||
$data['project_code'] = $project['project_code'];
|
||||
$data['apply_date'] = $material_purchase_request['apply_date'];
|
||||
$data['arrival_date'] = $material_purchase_request['arrival_date'];
|
||||
$data['material_first_level'] = $material_classify[$material['first_level']];
|
||||
$data['material_second_level'] = !empty($material_classify[$material['second_level']]) ? $material_classify[$material['second_level']] : '';
|
||||
$data['material_three_level'] = !empty($material_classify[$material['three_level']]) ? $material_classify[$material['three_level']] : '';
|
||||
$data['material_name'] = $material['name'];
|
||||
$data['material_code'] = $material['code'];
|
||||
$data['material_specs'] = $material['specs'];
|
||||
$data['material_brand'] = $material['brand'];
|
||||
$data['material_parameter_description'] = $material['parameter_description'];
|
||||
$data['material_unit'] = $material['unit'];
|
||||
return $data->toArray();
|
||||
}
|
||||
}
|
147
app/adminapi/logic/material/MaterialPurchaseRequestLogic.php
Normal file
147
app/adminapi/logic/material/MaterialPurchaseRequestLogic.php
Normal file
@ -0,0 +1,147 @@
|
||||
<?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\dept\Dept;
|
||||
use app\common\model\dept\Orgs;
|
||||
use app\common\model\material\MaterialPurchaseRequest;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\material\MaterialPurchaseRequestDetail;
|
||||
use app\common\model\project\Project;
|
||||
use app\common\model\project\ProjectMaterialBudgetDetail;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 材料采购申请逻辑
|
||||
* Class MaterialPurchaseRequestLogic
|
||||
* @package app\adminapi\logic\material
|
||||
*/
|
||||
class MaterialPurchaseRequestLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加材料采购申请
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
$detail = json_decode($params['purchase_request_detail'],true);
|
||||
Db::startTrans();
|
||||
try {
|
||||
$MaterialPurchaseRequestRes = MaterialPurchaseRequest::create([
|
||||
'material_purchase_request_code' => data_unique_code('采购申请'),
|
||||
'org_id' => $params['org_id'],
|
||||
'dept_id' => $params['dept_id'],
|
||||
'project_id' => $params['project_id'],
|
||||
'apply_date' => strtotime($params['apply_date']),
|
||||
'arrival_date' => strtotime($params['arrival_date']),
|
||||
'remark' => $params['remark'] ?? '',
|
||||
'annex' => !empty($params['annex']) ? $params['annex'] : null,
|
||||
]);
|
||||
foreach ($detail as $item)
|
||||
{
|
||||
MaterialPurchaseRequestDetail::create([
|
||||
'project_material_budget_detail_id' => $item['project_material_budget_detail_id'],
|
||||
'material_purchase_request_id' => $MaterialPurchaseRequestRes->id,
|
||||
'num' => $item['num'],
|
||||
'remark' => $item['remark'] ?? '',
|
||||
]);
|
||||
//预算数量
|
||||
$project_material_budget_detail = ProjectMaterialBudgetDetail::field('num')->where('id',$item['project_material_budget_detail_id'])->findOrEmpty();
|
||||
//已经申购的数量
|
||||
$purchase_request_num = MaterialPurchaseRequestDetail::where('project_material_budget_detail_id',$item['project_material_budget_detail_id'])->sum('num');
|
||||
if($project_material_budget_detail['num'] - $purchase_request_num - $item['num'] <=0){
|
||||
ProjectMaterialBudgetDetail::where('id',$item['project_material_budget_detail_id'])->update(['is_residual'=>1,'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/09 13:47
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
MaterialPurchaseRequest::where('id', $params['id'])->update([
|
||||
'org_id' => $params['org_id'],
|
||||
'dept_id' => $params['dept_id'],
|
||||
'project_id' => $params['project_id'],
|
||||
'apply_date' => strtotime($params['apply_date']),
|
||||
'arrival_date' => strtotime($params['arrival_date']),
|
||||
'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/09 13:47
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return MaterialPurchaseRequest::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取材料采购申请详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$data = MaterialPurchaseRequest::field('id,org_id,dept_id,project_id,material_purchase_request_code,apply_date,arrival_date,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();
|
||||
$data['org_name'] = $org['name'];
|
||||
$data['dept_name'] = $dept['name'];
|
||||
$data['project_name'] = $project['name'];
|
||||
$data['project_code'] = $project['project_code'];
|
||||
return $data->toArray();
|
||||
}
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
<?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\material\MaterialPurchaseRequestDetail;
|
||||
use app\common\model\project\ProjectMaterialBudgetDetail;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 材料采购申请明细验证器
|
||||
* Class MaterialPurchaseRequestDetailValidate
|
||||
* @package app\adminapi\validate\material
|
||||
*/
|
||||
class MaterialPurchaseRequestDetailValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require|checkId',
|
||||
'num' => 'require|integer|gt:0|checkNum',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '缺少必要参数',
|
||||
'num.require' => '请填写申请采购数量',
|
||||
'num.integer' => '申请采购数量值必须是整数',
|
||||
'num.gt' => '申请采购数量之必须大于0',
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return MaterialPurchaseRequestDetailValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->remove('id',true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return MaterialPurchaseRequestDetailValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id','num']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return MaterialPurchaseRequestDetailValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return MaterialPurchaseRequestDetailValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function checkId($value): bool|string
|
||||
{
|
||||
$data = MaterialPurchaseRequestDetail::where('id',$value)->findOrEmpty();
|
||||
if($data->isEmpty()){
|
||||
return '数据不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkNum($value,$rule,$data){
|
||||
//总预算数量 - 已申购数量 + 当前数据申购数量
|
||||
$MaterialPurchaseRequestDetail = MaterialPurchaseRequestDetail::where('id',$data['id'])->findOrEmpty();
|
||||
$project_material_budget_detail = ProjectMaterialBudgetDetail::where('id',$MaterialPurchaseRequestDetail['project_material_budget_detail_id'])->findOrEmpty();
|
||||
//已经申购的数量
|
||||
$PurchaseRequestNum = MaterialPurchaseRequestDetail::where('project_material_budget_detail_id',$MaterialPurchaseRequestDetail['project_material_budget_detail_id'])->sum('num');
|
||||
if($value > ($project_material_budget_detail['num'] - $PurchaseRequestNum + $MaterialPurchaseRequestDetail['num'])){
|
||||
return '申请采购数量不能大于剩余预算数量';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,178 @@
|
||||
<?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\dept\Dept;
|
||||
use app\common\model\dept\Orgs;
|
||||
use app\common\model\material\MaterialPurchaseRequestDetail;
|
||||
use app\common\model\project\Project;
|
||||
use app\common\model\project\ProjectMaterialBudgetDetail;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 材料采购申请验证器
|
||||
* Class MaterialPurchaseRequestValidate
|
||||
* @package app\adminapi\validate\material
|
||||
*/
|
||||
class MaterialPurchaseRequestValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'org_id' => 'require|checkOrg',
|
||||
'dept_id' => 'require|checkDept',
|
||||
'project_id' => 'require|checkProject',
|
||||
'apply_date' => 'require|dateFormat:Y-m-d',
|
||||
'arrival_date' => 'require|dateFormat:Y-m-d',
|
||||
'annex' => 'checkAnnex',
|
||||
'purchase_request_detail' => 'require|checkPurchaseRequestDetail'
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '缺少必要参数',
|
||||
'org_id.require' => '请选择组织',
|
||||
'dept_id.require' => '请选择部门',
|
||||
'project_id.require' => '请选择项目',
|
||||
'apply_date.require' => '请选择申请日期',
|
||||
'apply_date.dateFormat' => '申请日期数据格式错误',
|
||||
'arrival_date.require' => '请选择希望到货日期',
|
||||
'arrival_date.dateFormat' => '希望到货日期数据格式错误',
|
||||
'purchase_request_detail.require' => '申购明细内容不能为空',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return MaterialPurchaseRequestValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->remove('id',true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return MaterialPurchaseRequestValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return MaterialPurchaseRequestValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return MaterialPurchaseRequestValidate
|
||||
* @author likeadmin
|
||||
* @date 2024/01/09 13:47
|
||||
*/
|
||||
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 checkAnnex($value): bool|string
|
||||
{
|
||||
if(!empty($value) && $value != ''){
|
||||
$annex = json_decode($value,true);
|
||||
if(empty($annex) || !is_array($annex)){
|
||||
return '附件格式错误';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkPurchaseRequestDetail($value): bool|string
|
||||
{
|
||||
$detail = json_decode($value,true);
|
||||
if(empty($detail) || !is_array($detail)){
|
||||
return '申购明细数据格式错误';
|
||||
}
|
||||
foreach($detail as $v) {
|
||||
$project_material_budget_detail = ProjectMaterialBudgetDetail::where('id',$v['project_material_budget_detail_id'])->findOrEmpty();
|
||||
if(empty($v['project_material_budget_detail_id'])){
|
||||
return '请选择材料预算明细';
|
||||
}else{
|
||||
if($project_material_budget_detail->isEmpty()){
|
||||
return '材料预算明细信息不存在';
|
||||
}
|
||||
}
|
||||
if(empty($v['num'])){
|
||||
return '数量不能为空';
|
||||
}else{
|
||||
if(!is_numeric($v['num']) || $v['num'] < 0){
|
||||
return '数量必须是大于0的数字';
|
||||
}
|
||||
$PurchaseRequestNum = MaterialPurchaseRequestDetail::where('project_material_budget_detail_id',$v['project_material_budget_detail_id'])->sum('num');
|
||||
if($v['num'] > ($project_material_budget_detail['num'] - $PurchaseRequestNum)){
|
||||
return '申请采购数量不能大于剩余预算数量';
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
46
app/common/model/material/MaterialPurchaseRequest.php
Normal file
46
app/common/model/material/MaterialPurchaseRequest.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?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 MaterialPurchaseRequest
|
||||
* @package app\common\model\material
|
||||
*/
|
||||
class MaterialPurchaseRequest extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'material_purchase_request';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
public function getAnnexAttr($value){
|
||||
return !empty($value) ? json_decode($value) : '';
|
||||
}
|
||||
|
||||
public function getApplyDateAttr($value): string
|
||||
{
|
||||
return !empty($value) ? date('Y-m-d',$value) : '';
|
||||
}
|
||||
|
||||
public function getArrivalDateAttr($value): string
|
||||
{
|
||||
return !empty($value) ? date('Y-m-d',$value) : '';
|
||||
}
|
||||
}
|
34
app/common/model/material/MaterialPurchaseRequestDetail.php
Normal file
34
app/common/model/material/MaterialPurchaseRequestDetail.php
Normal 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\material;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
/**
|
||||
* 材料采购申请明细模型
|
||||
* Class MaterialPurchaseRequestDetail
|
||||
* @package app\common\model\material
|
||||
*/
|
||||
class MaterialPurchaseRequestDetail extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'material_purchase_request_detail';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user