diff --git a/app/adminapi/controller/project/ProjectEquipmentBudgetController.php b/app/adminapi/controller/project/ProjectEquipmentBudgetController.php new file mode 100644 index 000000000..f167142c2 --- /dev/null +++ b/app/adminapi/controller/project/ProjectEquipmentBudgetController.php @@ -0,0 +1,108 @@ +dataLists(new ProjectEquipmentBudgetLists()); + } + + + /** + * @notes 添加机具预算 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/16 11:40 + */ + public function add() + { + $params = (new ProjectEquipmentBudgetValidate())->post()->goCheck('add'); + $result = ProjectEquipmentBudgetLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ProjectEquipmentBudgetLogic::getError()); + } + + + /** + * @notes 编辑机具预算 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/16 11:40 + */ + public function edit() + { + $params = (new ProjectEquipmentBudgetValidate())->post()->goCheck('edit'); + $result = ProjectEquipmentBudgetLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ProjectEquipmentBudgetLogic::getError()); + } + + + /** + * @notes 删除机具预算 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/16 11:40 + */ + public function delete() + { + $params = (new ProjectEquipmentBudgetValidate())->post()->goCheck('delete'); + ProjectEquipmentBudgetLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取机具预算详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/16 11:40 + */ + public function detail() + { + $params = (new ProjectEquipmentBudgetValidate())->goCheck('detail'); + $result = ProjectEquipmentBudgetLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/controller/project/ProjectEquipmentBudgetDetailController.php b/app/adminapi/controller/project/ProjectEquipmentBudgetDetailController.php new file mode 100644 index 000000000..9dcc060d0 --- /dev/null +++ b/app/adminapi/controller/project/ProjectEquipmentBudgetDetailController.php @@ -0,0 +1,108 @@ +dataLists(new ProjectEquipmentBudgetDetailLists()); + } + + + /** + * @notes 添加机具预算明细 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/16 11:40 + */ + public function add() + { + $params = (new ProjectEquipmentBudgetDetailValidate())->post()->goCheck('add'); + $result = ProjectEquipmentBudgetDetailLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ProjectEquipmentBudgetDetailLogic::getError()); + } + + + /** + * @notes 编辑机具预算明细 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/16 11:40 + */ + public function edit() + { + $params = (new ProjectEquipmentBudgetDetailValidate())->post()->goCheck('edit'); + $result = ProjectEquipmentBudgetDetailLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ProjectEquipmentBudgetDetailLogic::getError()); + } + + + /** + * @notes 删除机具预算明细 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/16 11:40 + */ + public function delete() + { + $params = (new ProjectEquipmentBudgetDetailValidate())->post()->goCheck('delete'); + ProjectEquipmentBudgetDetailLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取机具预算明细详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/16 11:40 + */ + public function detail() + { + $params = (new ProjectEquipmentBudgetDetailValidate())->goCheck('detail'); + $result = ProjectEquipmentBudgetDetailLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/project/ProjectEquipmentBudgetDetailLists.php b/app/adminapi/lists/project/ProjectEquipmentBudgetDetailLists.php new file mode 100644 index 000000000..3fa7eced7 --- /dev/null +++ b/app/adminapi/lists/project/ProjectEquipmentBudgetDetailLists.php @@ -0,0 +1,87 @@ + ['project_id', 'equipment_budget_id'], + '%like%' => ['type', 'name'], + ]; + } + + + /** + * @notes 获取机具预算明细列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/01/16 11:40 + */ + public function lists(): array + { + return ProjectEquipmentBudgetDetail::where($this->searchWhere) + ->field('id,project_id,equipment_budget_id,type,name,spec,unit,num,price,amount,remark') + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($data){ + $equipment_budget = ProjectEquipmentBudget::field('equipment_budget_code')->where('id',$data['equipment_budget_id'])->findOrEmpty(); + $project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty(); + $data['equipment_budget_code'] = $equipment_budget['equipment_budget_code']; + $data['project_name'] = $project['name']; + $data['project_code'] = $project['project_code']; + return $data; + }) + ->toArray(); + } + + + /** + * @notes 获取机具预算明细数量 + * @return int + * @author likeadmin + * @date 2024/01/16 11:40 + */ + public function count(): int + { + return ProjectEquipmentBudgetDetail::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/lists/project/ProjectEquipmentBudgetLists.php b/app/adminapi/lists/project/ProjectEquipmentBudgetLists.php new file mode 100644 index 000000000..f5ad78a5b --- /dev/null +++ b/app/adminapi/lists/project/ProjectEquipmentBudgetLists.php @@ -0,0 +1,90 @@ + ['project_id'], + '%like%' => ['equipment_budget_code'], + + ]; + } + + + /** + * @notes 获取机具预算列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/01/16 11:40 + */ + public function lists(): array + { + return ProjectEquipmentBudget::where($this->searchWhere) + ->field(['id', 'project_id', 'equipment_budget_code', 'remark', 'annex']) + ->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']; + //预算总量 + $data['total_num'] = ProjectEquipmentBudgetDetail::where('equipment_budget_id',$data['id'])->sum('num'); + //预算总金额 + $data['total_amount'] = ProjectEquipmentBudgetDetail::where('equipment_budget_id',$data['id'])->sum('amount'); + return $data; + }) + ->toArray(); + } + + + /** + * @notes 获取机具预算数量 + * @return int + * @author likeadmin + * @date 2024/01/16 11:40 + */ + public function count(): int + { + return ProjectEquipmentBudget::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/project/ProjectEquipmentBudgetDetailLogic.php b/app/adminapi/logic/project/ProjectEquipmentBudgetDetailLogic.php new file mode 100644 index 000000000..ca04f1cb0 --- /dev/null +++ b/app/adminapi/logic/project/ProjectEquipmentBudgetDetailLogic.php @@ -0,0 +1,132 @@ +where('id',$params['equipment_budget_id'])->findOrEmpty(); + Db::startTrans(); + try { + ProjectEquipmentBudgetDetail::create([ + 'project_id' => $equipment_budget['project_id'], + 'equipment_budget_id' => $params['equipment_budget_id'], + 'type' => $params['type'], + 'name' => $params['name'], + 'spec' => $params['spec'] ?? '', + 'unit' => $params['unit'], + 'num' => $params['num'], + 'price' => $params['price'], + 'amount' => $params['amount'], + 'remark' => $params['remark'] ?? '', + ]); + 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/16 11:40 + */ + public static function edit(array $params): bool + { + $equipment_budget = ProjectEquipmentBudget::field('project_id')->where('id',$params['equipment_budget_id'])->findOrEmpty(); + Db::startTrans(); + try { + ProjectEquipmentBudgetDetail::where('id', $params['id'])->update([ + 'project_id' => $equipment_budget['project_id'], + 'equipment_budget_id' => $params['equipment_budget_id'], + 'type' => $params['type'], + 'name' => $params['name'], + 'spec' => $params['spec'] ?? '', + 'unit' => $params['unit'], + 'num' => $params['num'], + 'price' => $params['price'], + 'amount' => $params['amount'], + 'remark' => $params['remark'] ?? '', + ]); + 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/16 11:40 + */ + public static function delete(array $params): bool + { + return ProjectEquipmentBudgetDetail::destroy($params['id']); + } + + + /** + * @notes 获取机具预算明细详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/01/16 11:40 + */ + public static function detail($params): array + { + $data = ProjectEquipmentBudgetDetail::field('id,project_id,equipment_budget_id,type,name,spec,unit,num,price,amount,remark')->findOrEmpty($params['id']); + $equipment_budget = ProjectEquipmentBudget::field('equipment_budget_code')->where('id',$data['equipment_budget_id'])->findOrEmpty(); + $project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty(); + $data['equipment_budget_code'] = $equipment_budget['equipment_budget_code']; + $data['project_name'] = $project['name']; + $data['project_code'] = $project['project_code']; + return $data->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/logic/project/ProjectEquipmentBudgetLogic.php b/app/adminapi/logic/project/ProjectEquipmentBudgetLogic.php new file mode 100644 index 000000000..2487da8a2 --- /dev/null +++ b/app/adminapi/logic/project/ProjectEquipmentBudgetLogic.php @@ -0,0 +1,170 @@ + $params['org_id'], + 'dept_id' => $params['dept_id'], + 'project_id' => $params['project_id'], + 'equipment_budget_code' => data_unique_code('项目机具预算'), + 'remark' => $params['remark'] ?? '', + 'annex' => $params['annex'] ? json_encode($params['annex']) : null, + ]); + foreach ($params['equipment_budget_detail'] as $item) + { + ProjectEquipmentBudgetDetail::create([ + 'project_id' => $params['project_id'], + 'equipment_budget_id' => $res->id, + 'type' => $item['type'], + 'name' => $item['name'], + 'spec' => $item['spec'] ?? '', + 'unit' => $item['unit'], + 'price' => $item['price'], + 'num' => $item['num'], + 'amount' => $item['price'] * $item['num'], + 'remark' => $item['remark'] ?? '', + ]); + } + 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/16 11:40 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + ProjectEquipmentBudget::where('id', $params['id'])->update([ + 'org_id' => $params['org_id'], + 'dept_id' => $params['dept_id'], + 'project_id' => $params['project_id'], + 'remark' => $params['remark'] ?? '', + 'annex' => $params['annex'] ? json_encode($params['annex']) : null, + ]); + foreach ($params['equipment_budget_detail'] as $item) + { + if(isset($item['id']) && $item['id'] != ''){ + ProjectEquipmentBudgetDetail::where('id',$item['id'])->update([ + 'project_id' => $params['project_id'], + 'equipment_budget_id' => $params['id'], + 'type' => $item['type'], + 'name' => $item['name'], + 'spec' => $item['spec'] ?? '', + 'unit' => $item['unit'], + 'price' => $item['price'], + 'num' => $item['num'], + 'amount' => $item['price'] * $item['num'], + 'remark' => $item['remark'] ?? '', + ]); + }else{ + ProjectEquipmentBudgetDetail::create([ + 'project_id' => $params['project_id'], + 'equipment_budget_id' => $params['id'], + 'type' => $item['type'], + 'name' => $item['name'], + 'spec' => $item['spec'] ?? '', + 'unit' => $item['unit'], + 'price' => $item['price'], + 'num' => $item['num'], + 'amount' => $item['price'] * $item['num'], + 'remark' => $item['remark'] ?? '', + ]); + } + } + 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/16 11:40 + */ + public static function delete(array $params): bool + { + return ProjectEquipmentBudget::destroy($params['id']); + } + + + /** + * @notes 获取机具预算详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/01/16 11:40 + */ + public static function detail($params): array + { + $data = ProjectEquipmentBudget::field('id,org_id,dept_id,project_id,equipment_budget_code,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(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/project/ProjectEquipmentBudgetDetailValidate.php b/app/adminapi/validate/project/ProjectEquipmentBudgetDetailValidate.php new file mode 100644 index 000000000..ce700683a --- /dev/null +++ b/app/adminapi/validate/project/ProjectEquipmentBudgetDetailValidate.php @@ -0,0 +1,114 @@ + 'require', + 'equipment_budget_id' => 'require|checkEquipmentBudget', + 'type' => 'require', + 'name' => 'require', + 'unit' => 'require', + 'num' => 'require|float|gt:0', + 'price' => 'require|float|gt:0', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'equipment_budget_id' => '机具预算id', + 'type' => '机具类别', + 'name' => '机具名称', + 'unit' => '单位', + 'num' => '数量', + 'price' => '单价', + ]; + + + /** + * @notes 添加场景 + * @return ProjectEquipmentBudgetDetailValidate + * @author likeadmin + * @date 2024/01/16 11:40 + */ + public function sceneAdd() + { + return $this->remove('id',true); + } + + + /** + * @notes 编辑场景 + * @return ProjectEquipmentBudgetDetailValidate + * @author likeadmin + * @date 2024/01/16 11:40 + */ + public function sceneEdit() + {} + + + /** + * @notes 删除场景 + * @return ProjectEquipmentBudgetDetailValidate + * @author likeadmin + * @date 2024/01/16 11:40 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return ProjectEquipmentBudgetDetailValidate + * @author likeadmin + * @date 2024/01/16 11:40 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + public function checkEquipmentBudget($value): bool|string + { + $data = ProjectEquipmentBudget::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '机具预算信息不存在'; + } + return true; + } + +} \ No newline at end of file diff --git a/app/adminapi/validate/project/ProjectEquipmentBudgetValidate.php b/app/adminapi/validate/project/ProjectEquipmentBudgetValidate.php new file mode 100644 index 000000000..dec88eaaf --- /dev/null +++ b/app/adminapi/validate/project/ProjectEquipmentBudgetValidate.php @@ -0,0 +1,182 @@ + 'require', + 'org_id' => 'require|checkOrg', + 'dept_id' => 'require|checkDept', + 'project_id' => 'require|checkProject', + 'annex' => 'checkAnnex', + 'equipment_budget_detail' => 'require|checkEquipmentBudgetDetail' + ]; + + protected $message = [ + 'id.require' => '缺少必要参数', + 'org_id.require' => '请选择组织', + 'dept_id.require' => '请选择部门', + 'project_id.require' => '请选择项目', + 'equipment_budget_detail.require' => '请填机具预算清单' + ]; + + + /** + * @notes 添加场景 + * @return ProjectEquipmentBudgetValidate + * @author likeadmin + * @date 2024/01/16 11:40 + */ + public function sceneAdd() + { + return $this->remove('id',true); + } + + + /** + * @notes 编辑场景 + * @return ProjectEquipmentBudgetValidate + * @author likeadmin + * @date 2024/01/16 11:40 + */ + public function sceneEdit() + {} + + + /** + * @notes 删除场景 + * @return ProjectEquipmentBudgetValidate + * @author likeadmin + * @date 2024/01/16 11:40 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return ProjectEquipmentBudgetValidate + * @author likeadmin + * @date 2024/01/16 11:40 + */ + 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 != ''){ + if(!is_array($value)){ + return '附件格式错误'; + } + } + return true; + } + + public function checkEquipmentBudgetDetail($value): bool|string + { + if(empty($value) || !is_array($value)){ + return '机具预算清单数据格式错误'; + } + foreach($value as $v) { + if(isset($v['id']) && $v['id'] != ''){ + $data = ProjectEquipmentBudgetDetail::where('id',$v['id'])->findOrEmpty(); + if($data->isEmpty()){ + return '机具预算明细信息不存在'; + } + } + if(empty($v['type'])){ + return '机具类别不能为空'; + } + if(empty($v['name'])){ + return '机具名称不能为空'; + } + if(empty($v['unit'])){ + 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; + } + +} \ No newline at end of file diff --git a/app/common/model/project/ProjectEquipmentBudget.php b/app/common/model/project/ProjectEquipmentBudget.php new file mode 100644 index 000000000..ec9d69ec8 --- /dev/null +++ b/app/common/model/project/ProjectEquipmentBudget.php @@ -0,0 +1,36 @@ +