From 433e5cc8e5597d70dae9e41d6370a63259056a45 Mon Sep 17 00:00:00 2001 From: weiz Date: Thu, 4 Jan 2024 14:12:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9D=90=E6=96=99=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../material/MaterialClassifyController.php | 105 +++++++++++++ .../material/MaterialController.php | 108 +++++++++++++ .../lists/material/MaterialClassifyLists.php | 79 ++++++++++ app/adminapi/lists/material/MaterialLists.php | 85 ++++++++++ .../logic/material/MaterialClassifyLogic.php | 107 +++++++++++++ app/adminapi/logic/material/MaterialLogic.php | 143 +++++++++++++++++ .../project/ProjectPreSalesMembersLogic.php | 3 +- .../material/MaterialClassifyValidate.php | 102 ++++++++++++ .../validate/material/MaterialValidate.php | 147 ++++++++++++++++++ app/common/model/material/Material.php | 37 +++++ .../model/material/MaterialClassify.php | 34 ++++ 11 files changed, 949 insertions(+), 1 deletion(-) create mode 100644 app/adminapi/controller/material/MaterialClassifyController.php create mode 100644 app/adminapi/controller/material/MaterialController.php create mode 100644 app/adminapi/lists/material/MaterialClassifyLists.php create mode 100644 app/adminapi/lists/material/MaterialLists.php create mode 100644 app/adminapi/logic/material/MaterialClassifyLogic.php create mode 100644 app/adminapi/logic/material/MaterialLogic.php create mode 100644 app/adminapi/validate/material/MaterialClassifyValidate.php create mode 100644 app/adminapi/validate/material/MaterialValidate.php create mode 100644 app/common/model/material/Material.php create mode 100644 app/common/model/material/MaterialClassify.php diff --git a/app/adminapi/controller/material/MaterialClassifyController.php b/app/adminapi/controller/material/MaterialClassifyController.php new file mode 100644 index 000000000..3bd9d125d --- /dev/null +++ b/app/adminapi/controller/material/MaterialClassifyController.php @@ -0,0 +1,105 @@ +dataLists(new MaterialClassifyLists()); + } + + + /** + * @notes 添加材料分类 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/04 09:47 + */ + public function add() + { + $params = (new MaterialClassifyValidate())->post()->goCheck('add'); + $result = MaterialClassifyLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(MaterialClassifyLogic::getError()); + } + + + /** + * @notes 编辑材料分类 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/04 09:47 + */ + public function edit() + { + $params = (new MaterialClassifyValidate())->post()->goCheck('edit'); + $result = MaterialClassifyLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(MaterialClassifyLogic::getError()); + } + + + /** + * @notes 获取材料分类详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/04 09:47 + */ + public function detail() + { + $params = (new MaterialClassifyValidate())->goCheck('detail'); + $result = MaterialClassifyLogic::detail($params); + return $this->data($result); + } + + public function datas(): \think\response\Json + { + $pid = $this->request->get('pid'); + if(!isset($pid) || $pid == ''){ + return $this->fail('缺少必要参数'); + } + $data = MaterialClassify::field('id,name')->where('pid',$pid)->select()->toArray(); + return $this->success('请求成功',$data); + } + + +} \ No newline at end of file diff --git a/app/adminapi/controller/material/MaterialController.php b/app/adminapi/controller/material/MaterialController.php new file mode 100644 index 000000000..0cd4490e8 --- /dev/null +++ b/app/adminapi/controller/material/MaterialController.php @@ -0,0 +1,108 @@ +dataLists(new MaterialLists()); + } + + + /** + * @notes 添加自购材料 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/04 10:59 + */ + public function add() + { + $params = (new MaterialValidate())->post()->goCheck('add'); + $result = MaterialLogic::add($params,$this->adminId); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(MaterialLogic::getError()); + } + + + /** + * @notes 编辑自购材料 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/04 10:59 + */ + public function edit() + { + $params = (new MaterialValidate())->post()->goCheck('edit'); + $result = MaterialLogic::edit($params,$this->adminId); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(MaterialLogic::getError()); + } + + + /** + * @notes 删除自购材料 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/04 10:59 + */ + public function delete() + { + $params = (new MaterialValidate())->post()->goCheck('delete'); + MaterialLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取自购材料详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/04 10:59 + */ + public function detail() + { + $params = (new MaterialValidate())->goCheck('detail'); + $result = MaterialLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/material/MaterialClassifyLists.php b/app/adminapi/lists/material/MaterialClassifyLists.php new file mode 100644 index 000000000..51967086d --- /dev/null +++ b/app/adminapi/lists/material/MaterialClassifyLists.php @@ -0,0 +1,79 @@ + ['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 09:47 + */ + public function lists(): array + { + $data = MaterialClassify::where($this->searchWhere) + ->field(['id', 'pid', 'name']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'asc']) + ->select() + ->toArray(); + $tree = buildTree($data,'pid'); + return $tree; + } + + + /** + * @notes 获取材料分类数量 + * @return int + * @author likeadmin + * @date 2024/01/04 09:47 + */ + public function count(): int + { + return MaterialClassify::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/lists/material/MaterialLists.php b/app/adminapi/lists/material/MaterialLists.php new file mode 100644 index 000000000..70d39cba5 --- /dev/null +++ b/app/adminapi/lists/material/MaterialLists.php @@ -0,0 +1,85 @@ + ['first_level', 'second_level', 'three_level'], + '%like%' => ['code', 'brand', '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 10:59 + */ + public function lists(): array + { + return Material::where($this->searchWhere) + ->field(['id', 'first_level', 'second_level', 'three_level', 'code', 'brand', 'name', 'specs', 'unit', 'parameter_description', 'inventory', 'sales_price', 'cost_price', 'annex']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($item){ + $classify = MaterialClassify::where('id','in',[$item['first_level'],$item['second_level'],$item['three_level']])->column('name','id'); + $item['first_level_name'] = $classify[$item['first_level']]; + $item['second_level_name'] = !empty($classify[$item['second_level']]) ? $classify[$item['second_level']] : ''; + $item['three_level_name'] = !empty($classify[$item['three_level']]) ? $classify[$item['three_level']] : ''; + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取自购材料数量 + * @return int + * @author likeadmin + * @date 2024/01/04 10:59 + */ + public function count(): int + { + return Material::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/material/MaterialClassifyLogic.php b/app/adminapi/logic/material/MaterialClassifyLogic.php new file mode 100644 index 000000000..13f61fd89 --- /dev/null +++ b/app/adminapi/logic/material/MaterialClassifyLogic.php @@ -0,0 +1,107 @@ + $params['pid'], + 'name' => $params['name'], + ]); + 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 09:47 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + MaterialClassify::where('id', $params['id'])->update([ + 'pid' => $params['pid'], + 'name' => $params['name'], + '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 09:47 + */ + public static function delete(array $params): bool + { + return MaterialClassify::destroy($params['id']); + } + + + /** + * @notes 获取材料分类详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/01/04 09:47 + */ + public static function detail($params): array + { + return MaterialClassify::field('id,pid,name,create_time')->findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/logic/material/MaterialLogic.php b/app/adminapi/logic/material/MaterialLogic.php new file mode 100644 index 000000000..513ea91d2 --- /dev/null +++ b/app/adminapi/logic/material/MaterialLogic.php @@ -0,0 +1,143 @@ + $params['first_level'], + 'second_level' => $params['second_level'] ?? 0, + 'three_level' => $params['three_level'] ?? 0, + 'code' => $params['code'], + 'brand' => $params['brand'] ?? '', + 'name' => $params['name'], + 'specs' => $params['specs'], + 'unit' => $params['unit'], + 'parameter_description' => $params['parameter_description'] ?? '', + 'inventory' => $params['inventory'] ?? 0, + 'sales_price' => $params['sales_price'] ?? 0, + 'cost_price' => $params['cost_price'] ?? 0, + 'annex' => !empty($params['annex']) ? $params['annex'] : null, + 'add_user' => $admin_id, + 'update_user' => $admin_id, + ]); + 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 10:59 + */ + public static function edit(array $params,$admin_id): bool + { + Db::startTrans(); + try { + Material::where('id', $params['id'])->update([ + 'first_level' => $params['first_level'], + 'second_level' => $params['second_level'] ?? 0, + 'three_level' => $params['three_level'] ?? 0, + 'code' => $params['code'], + 'brand' => $params['brand'] ?? '', + 'name' => $params['name'], + 'specs' => $params['specs'], + 'unit' => $params['unit'], + 'parameter_description' => $params['parameter_description'] ?? '', + 'inventory' => $params['inventory'] ?? 0, + 'sales_price' => $params['sales_price'] ?? 0, + 'cost_price' => $params['cost_price'] ?? 0, + 'annex' => !empty($params['annex']) ? $params['annex'] : null, + 'update_user' => $admin_id, + '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 10:59 + */ + public static function delete(array $params): bool + { + return Material::destroy($params['id']); + } + + + /** + * @notes 获取自购材料详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/01/04 10:59 + */ + public static function detail($params): array + { + $field = 'id,first_level,second_level,three_level,code,brand,name,specs,unit,parameter_description,inventory,sales_price,cost_price,annex,add_user,update_user,create_time,update_time'; + $data = Material::field($field)->findOrEmpty($params['id'])->toArray(); + $classify = MaterialClassify::where('id','in',[$data['first_level'],$data['second_level'],$data['three_level']])->column('name','id'); + $admin = Admin::where('id','in',[$data['add_user'],$data['update_user']])->column('name','id'); + $data['first_level_name'] = $classify[$data['first_level']]; + $data['second_level_name'] = !empty($classify[$data['second_level']]) ? $classify[$data['second_level']] : ''; + $data['three_level_name'] = !empty($classify[$data['three_level']]) ? $classify[$data['three_level']] : ''; + $data['add_user_name'] = $admin[$data['add_user']]; + $data['update_user_name'] = $admin[$data['update_user']]; + return $data; + } +} \ No newline at end of file diff --git a/app/adminapi/logic/project/ProjectPreSalesMembersLogic.php b/app/adminapi/logic/project/ProjectPreSalesMembersLogic.php index 57f538680..5134906ba 100644 --- a/app/adminapi/logic/project/ProjectPreSalesMembersLogic.php +++ b/app/adminapi/logic/project/ProjectPreSalesMembersLogic.php @@ -111,13 +111,14 @@ class ProjectPreSalesMembersLogic extends BaseLogic public static function detail($params): array { $data = ProjectPreSalesMembers::field('id,project_id,technician_ids,business_people_ids,cross_departmental_personnel_ids,add_user,create_time')->findOrEmpty($params['id'])->toArray(); - $project = Project::field('id,custom_id,name')->where('id',$data['project_id'])->findOrEmpty(); + $project = Project::field('id,custom_id,name,project_code')->where('id',$data['project_id'])->findOrEmpty(); $custom = Custom::field('id,name')->where('id',$project['custom_id'])->findOrEmpty(); $technician = Admin::where('id','in',$data['technician_ids'])->column('name'); $business_people = Admin::where('id','in',$data['business_people_ids'])->column('name'); $cross_departmental_personnel = Admin::where('id','in',$data['cross_departmental_personnel_ids'])->column('name'); $add_user = Admin::field('name')->where('id',$data['add_user'])->findOrEmpty(); $data['project_name'] = $project['name']; + $data['project_code'] = $project['project_code']; $data['custom_name'] = $custom['name']; $data['technician'] = implode(',',$technician); $data['business_people'] = implode(',',$business_people); diff --git a/app/adminapi/validate/material/MaterialClassifyValidate.php b/app/adminapi/validate/material/MaterialClassifyValidate.php new file mode 100644 index 000000000..df2efb62b --- /dev/null +++ b/app/adminapi/validate/material/MaterialClassifyValidate.php @@ -0,0 +1,102 @@ + 'require', + 'pid' => 'require', + 'name' => 'require|checkName', + ]; + + protected $message = [ + 'id.require' => '缺少必要参数', + 'pid.require' => '请选择上级分类', + 'name.require' => '请填写分类名称', + ]; + + /** + * @notes 添加场景 + * @return MaterialClassifyValidate + * @author likeadmin + * @date 2024/01/04 09:47 + */ + public function sceneAdd() + { + return $this->only(['pid','name']); + } + + + /** + * @notes 编辑场景 + * @return MaterialClassifyValidate + * @author likeadmin + * @date 2024/01/04 09:47 + */ + public function sceneEdit() + { + return $this->only(['id','pid','name']); + } + + + /** + * @notes 删除场景 + * @return MaterialClassifyValidate + * @author likeadmin + * @date 2024/01/04 09:47 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return MaterialClassifyValidate + * @author likeadmin + * @date 2024/01/04 09:47 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + public function checkName($value,$rule,$data): bool|string + { + $data = MaterialClassify::where('pid',$data['pid'])->where('name',$value)->findOrEmpty(); + if(!$data->isEmpty()){ + return '该分类名称已存在'; + } + return true; + } + +} \ No newline at end of file diff --git a/app/adminapi/validate/material/MaterialValidate.php b/app/adminapi/validate/material/MaterialValidate.php new file mode 100644 index 000000000..c045971e0 --- /dev/null +++ b/app/adminapi/validate/material/MaterialValidate.php @@ -0,0 +1,147 @@ + 'require', + 'first_level' => 'require|checkFirstLevel', + 'second_level' => 'checkSecondLevel', + 'three_level' => 'checkThreeLevel', + 'code' => 'require', + 'name' => 'require', + 'specs' => 'require', + 'unit' => 'require', + 'inventory' => 'integer|egt:0', + 'sales_price' => 'float|egt:0', + 'cost_price' => 'float|egt:0', + 'annex' => 'checkAnnex' + ]; + + protected $message = [ + 'id.require' => '缺少必要参数', + 'first_level.require' => '请选择材料大类', + 'code.require' => '请填写材料编码', + 'name.require' => '请填写材料名称', + 'specs.require' => '请填写规格型号', + 'unit.require' => '请填写单位', + 'inventory.integer' => '安全库存量值必须是整数', + 'inventory.egt' => '安全库存量值必须大于等于0', + 'sales_price.float' => '销售指导价值必须是数字', + 'sales_price.egt' => '销售指导价值必须大于等于0', + 'cost_price.float' => '预算成本价值必须是数字', + 'cost_price.egt' => '预算成本价值必须大于等于0', + ]; + + /** + * @notes 添加场景 + * @return MaterialValidate + * @author likeadmin + * @date 2024/01/04 10:59 + */ + public function sceneAdd() + { + return $this->remove('id',true); + } + + + /** + * @notes 编辑场景 + * @return MaterialValidate + * @author likeadmin + * @date 2024/01/04 10:59 + */ + public function sceneEdit() + {} + + + /** + * @notes 删除场景 + * @return MaterialValidate + * @author likeadmin + * @date 2024/01/04 10:59 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return MaterialValidate + * @author likeadmin + * @date 2024/01/04 10:59 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + public function checkFirstLevel($value): bool|string + { + $classify = MaterialClassify::where('id',$value)->where('pid',0)->findOrEmpty(); + if($classify->isEmpty()){ + return '材料大类不存在'; + } + return true; + } + + public function checkSecondLevel($value,$rule,$data): bool|string + { + $classify = MaterialClassify::where('id',$value)->where('pid',$data['first_level'])->findOrEmpty(); + if($classify->isEmpty()){ + return '材料中类不存在'; + } + return true; + } + + public function checkThreeLevel($value,$rule,$data): bool|string + { + $classify = MaterialClassify::where('id',$value)->where('pid',$data['second_level'])->findOrEmpty(); + if($classify->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; + } + +} \ No newline at end of file diff --git a/app/common/model/material/Material.php b/app/common/model/material/Material.php new file mode 100644 index 000000000..e93ad7a4a --- /dev/null +++ b/app/common/model/material/Material.php @@ -0,0 +1,37 @@ +