This commit is contained in:
weiz 2024-02-19 17:57:02 +08:00
parent c4e27aaceb
commit b67fc3956e
3 changed files with 76 additions and 8 deletions

View File

@ -20,6 +20,8 @@ use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\material\MaterialPurchaseRequestLists;
use app\adminapi\logic\material\MaterialPurchaseRequestLogic;
use app\adminapi\validate\material\MaterialPurchaseRequestValidate;
use app\common\model\oa\Flow;
use app\common\model\oa\FlowType;
/**
@ -73,6 +75,24 @@ class MaterialPurchaseRequestController extends BaseAdminController
$result = MaterialPurchaseRequestLogic::detail($params);
return $this->data($result);
}
public function flows(): \think\response\Json
{
$flow_type = FlowType::where('type',5)->where('name','clsg')->findOrEmpty();
$data = Flow::field('id,name')->where('flow_cate',$flow_type['id'])->where('status',2)->select();
return $this->success('请求成功',$data->toArray());
}
//添加审批
public function approve(): \think\response\Json
{
$params = (new MaterialPurchaseRequestValidate())->post()->goCheck('approve');
$result = MaterialPurchaseRequestLogic::approve($params,$this->adminId);
if (true === $result) {
return $this->success('提交审核信息成功', [], 1, 1);
}
return $this->fail(MaterialPurchaseRequestLogic::getError());
}
}

View File

@ -134,7 +134,7 @@ class MaterialPurchaseRequestLogic extends BaseLogic
*/
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']);
$data = MaterialPurchaseRequest::field('id,org_id,dept_id,project_id,material_purchase_request_code,apply_date,arrival_date,remark,annex,approve_id')->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();
@ -142,10 +142,39 @@ class MaterialPurchaseRequestLogic extends BaseLogic
$data['dept_name'] = $dept['name'];
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
$approve_info = FlowApprove::field('id')->where('content_id',$params['id'])
->where('content_model','app\common\model\material\MaterialPurchaseRequest')
->where('content_logic','app\adminapi\logic\material\MaterialPurchaseRequestLogic')->findOrEmpty();
$data['approve_id'] = $approve_info['id'];
$approve_data = FlowApprove::where('id',$data['approve_id'])->findOrEmpty();
$data['approve_check_status'] = $approve_data['check_status'];
return $data->toArray();
}
public static function approve($params,$admin_id): bool{
$data = MaterialPurchaseRequest::where('id',$params['id'])->findOrEmpty();
$approve_data = FlowApprove::where('id',$data['approve_id'])->findOrEmpty();
if(!empty($data['approve_id']) && $approve_data['check_status'] != 3){
self::setError('当前内容存在审核信息,请勿重复提交');
return false;
}
Db::startTrans();
try {
$res = addApprove(
'材料申购',
$params['id'],
'app\common\model\material\MaterialPurchaseRequest',
$params['path'],
$params['flow_id'],
$admin_id
);
if($res){
MaterialPurchaseRequest::where('id',$params['id'])->update([
'approve_id' => $res,
]);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}

View File

@ -17,6 +17,7 @@ namespace app\adminapi\validate\material;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\model\material\MaterialPurchaseRequest;
use app\common\model\material\MaterialPurchaseRequestDetail;
use app\common\model\project\Project;
use app\common\model\project\ProjectMaterialBudgetDetail;
@ -36,7 +37,7 @@ class MaterialPurchaseRequestValidate extends BaseValidate
* @var string[]
*/
protected $rule = [
'id' => 'require',
'id' => 'require|checkData',
'org_id' => 'require|checkOrg',
'dept_id' => 'require|checkDept',
'project_id' => 'require|checkProject',
@ -44,6 +45,8 @@ class MaterialPurchaseRequestValidate extends BaseValidate
'arrival_date' => 'require|dateFormat:Y-m-d',
'annex' => 'checkAnnex',
'purchase_request_detail' => 'require|checkPurchaseRequestDetail',
'flow_id' => 'require|checkFlow',
'path' => 'require',
];
protected $message = [
@ -67,7 +70,7 @@ class MaterialPurchaseRequestValidate extends BaseValidate
*/
public function sceneAdd()
{
return $this->remove('id',true);
return $this->remove('id',true)->remove('flow_id',true)->remove('path',true);
}
@ -78,7 +81,9 @@ class MaterialPurchaseRequestValidate extends BaseValidate
* @date 2024/01/09 13:47
*/
public function sceneEdit()
{}
{
return $this->remove('flow_id',true)->remove('path',true);
}
/**
@ -104,6 +109,20 @@ class MaterialPurchaseRequestValidate extends BaseValidate
return $this->only(['id']);
}
public function sceneApprove()
{
return $this->only(['id','flow_id','path']);
}
public function checkData($value): bool|string
{
$data = MaterialPurchaseRequest::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '数据不存在';
}
return true;
}
public function checkOrg($value): bool|string
{
$org = Orgs::where('id',$value)->findOrEmpty();