From f4a553e78e77c348681f63c25778323163449d9e Mon Sep 17 00:00:00 2001 From: weiz <736250432@qq.com> Date: Thu, 14 Mar 2024 15:34:33 +0800 Subject: [PATCH] update --- .../contract/ContractController.php | 5 ++ .../custom/CustomContactsController.php | 15 ---- .../controller/custom/CustomController.php | 27 +++--- .../custom/CustomFollowController.php | 15 ---- .../custom/CustomServiceController.php | 39 ++++---- .../controller/project/ProjectController.php | 5 ++ .../lists/custom/CustomContactsLists.php | 29 +----- .../lists/custom/CustomFollowLists.php | 44 +-------- app/adminapi/lists/custom/CustomLists.php | 46 +++------- .../lists/custom/CustomServiceLists.php | 77 ++++------------ app/adminapi/logic/contract/ContractLogic.php | 7 ++ .../logic/custom/CustomContactsLogic.php | 14 --- .../logic/custom/CustomFollowLogic.php | 24 ++--- app/adminapi/logic/custom/CustomLogic.php | 83 ++++++++--------- .../logic/custom/CustomServiceLogic.php | 56 ++++++++---- app/adminapi/logic/project/ProjectLogic.php | 7 ++ .../custom/CustomContactsValidate.php | 40 ++------- .../validate/custom/CustomFollowValidate.php | 41 ++------- .../validate/custom/CustomServiceValidate.php | 89 +++++++------------ .../validate/custom/CustomValidate.php | 65 +++++--------- app/common/model/custom/Custom.php | 43 --------- app/common/model/custom/CustomContacts.php | 4 - app/common/model/custom/CustomFollow.php | 19 ---- app/common/model/custom/CustomService.php | 21 +---- 24 files changed, 245 insertions(+), 570 deletions(-) diff --git a/app/adminapi/controller/contract/ContractController.php b/app/adminapi/controller/contract/ContractController.php index 46729fc90..fa4226140 100644 --- a/app/adminapi/controller/contract/ContractController.php +++ b/app/adminapi/controller/contract/ContractController.php @@ -123,6 +123,11 @@ class ContractController extends BaseAdminController } return $this->fail(ContractLogic::getError()); } + + public function datas() + { + return $this->data(ContractLogic::datas()); + } } \ No newline at end of file diff --git a/app/adminapi/controller/custom/CustomContactsController.php b/app/adminapi/controller/custom/CustomContactsController.php index f1730de55..d0c58af76 100644 --- a/app/adminapi/controller/custom/CustomContactsController.php +++ b/app/adminapi/controller/custom/CustomContactsController.php @@ -1,21 +1,6 @@ post()->goCheck('delete'); - CustomLogic::delete($params); - return $this->success('删除成功', [], 1, 1); + $result = CustomLogic::delete($params); + if (true === $result) { + return $this->success('删除成功', [], 1, 1); + } + return $this->fail(CustomLogic::getError()); } @@ -103,6 +91,11 @@ class CustomController extends BaseAdminController $result = CustomLogic::detail($params); return $this->data($result); } + + public function datas() + { + return $this->data(CustomLogic::datas()); + } } \ No newline at end of file diff --git a/app/adminapi/controller/custom/CustomFollowController.php b/app/adminapi/controller/custom/CustomFollowController.php index 9989effaa..7612c04aa 100644 --- a/app/adminapi/controller/custom/CustomFollowController.php +++ b/app/adminapi/controller/custom/CustomFollowController.php @@ -1,21 +1,6 @@ fail(CustomServiceLogic::getError()); } + + /** + * @notes 编辑 + * @return \think\response\Json + * @author likeadmin + * @date 2023/11/12 14:00 + */ + public function edit(): \think\response\Json + { + $params = (new CustomServiceValidate())->post()->goCheck('edit'); + $result = CustomServiceLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(CustomServiceLogic::getError()); + } /** - * @notes 编辑 + * @notes 处理 * @return \think\response\Json * @author likeadmin * @date 2023/11/12 14:00 */ public function solve(): \think\response\Json { - $params = (new CustomServiceValidate())->post()->goCheck('edit'); - $result = CustomServiceLogic::edit($params); + $params = (new CustomServiceValidate())->post()->goCheck('check'); + $result = CustomServiceLogic::check($params); if (true === $result) { - return $this->success('编辑成功', [], 1, 1); + return $this->success('处理成功', [], 1, 1); } return $this->fail(CustomServiceLogic::getError()); } diff --git a/app/adminapi/controller/project/ProjectController.php b/app/adminapi/controller/project/ProjectController.php index ee4483a0e..f9be13c2d 100644 --- a/app/adminapi/controller/project/ProjectController.php +++ b/app/adminapi/controller/project/ProjectController.php @@ -143,5 +143,10 @@ class ProjectController extends BaseAdminController ]; return $this->success('请求成功',$result); } + + public function datas() + { + return $this->data(ProjectLogic::datas()); + } } \ No newline at end of file diff --git a/app/adminapi/lists/custom/CustomContactsLists.php b/app/adminapi/lists/custom/CustomContactsLists.php index 43d80ba81..6cec53f52 100644 --- a/app/adminapi/lists/custom/CustomContactsLists.php +++ b/app/adminapi/lists/custom/CustomContactsLists.php @@ -1,17 +1,4 @@ request->get(['custom_name']); - $where = []; - if(isset($params['custom_name']) && $params['custom_name'] != ''){ - $custom_ids = Custom::where('name','like','%'.$params['custom_name'].'%')->column('id'); - $where[] = ['custom_id','in',$custom_ids]; - } - return CustomContacts::field('id,custom_id,name,position,phone,telephone,email,notes,annex')->where($this->searchWhere)->where($where) + return CustomContacts::field('id,custom_id,name,position,phone,telephone,email,notes')->where($this->searchWhere) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function($item){ @@ -90,13 +71,7 @@ class CustomContactsLists extends BaseAdminDataLists implements ListsSearchInter */ public function count(): int { - $params = $this->request->get(['custom_name']); - $where = []; - if(isset($params['custom_name']) && $params['custom_name'] != ''){ - $custom_ids = Custom::where('name','like','%'.$params['custom_name'].'%')->column('id'); - $where[] = ['custom_id','in',$custom_ids]; - } - return CustomContacts::where($this->searchWhere)->where($where)->count(); + return CustomContacts::where($this->searchWhere)->count(); } /** diff --git a/app/adminapi/lists/custom/CustomFollowLists.php b/app/adminapi/lists/custom/CustomFollowLists.php index 2b362212b..b450b4aff 100644 --- a/app/adminapi/lists/custom/CustomFollowLists.php +++ b/app/adminapi/lists/custom/CustomFollowLists.php @@ -1,24 +1,9 @@ request->get(['custom_name','contacts']); - $where = []; - if(isset($params['custom_name']) && $params['custom_name'] != ''){ - $custom_ids = Custom::where('name','like','%'.$params['custom_name'].'%')->column('id'); - $where[] = ['custom_id','in',$custom_ids]; - } - if(isset($params['contacts']) && $params['contacts'] != ''){ - $custom_ids = Custom::where('custom_name','like','%'.$params['contacts'].'%')->column('id'); - $where[] = ['custom_id','in',$custom_ids]; - } - return CustomFollow::field('id,custom_id,name,date,types,executor,description,annex,coordinate,next_follow_date,add_user,update_user,create_time,update_time') - ->where($this->searchWhere)->where($where) + return CustomFollow::field('id,custom_id,name,date,types,executor,description,annex,coordinate,next_follow_date') + ->where($this->searchWhere) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function($item){ $item['types_text'] = $item->types_text; $custom = Custom::field('name,master_name')->where('id',$item['custom_id'])->findOrEmpty(); - $admin = Admin::where('id','in',[$item['add_user'],$item['update_user']])->column('name','id'); $item['custom_name'] = $custom['name']; $item['custom_master_name'] = $custom['master_name']; - $item['add_user'] = $admin[$item['add_user']]; - $item['update_user'] = $admin[$item['update_user']]; return $item; }) ->toArray(); @@ -94,17 +66,7 @@ class CustomFollowLists extends BaseAdminDataLists implements ListsSearchInterfa */ public function count(): int { - $params = $this->request->get(['custom_name','contacts']); - $where = []; - if(isset($params['custom_name']) && $params['custom_name'] != ''){ - $custom_ids = Custom::where('name','like','%'.$params['custom_name'].'%')->column('id'); - $where[] = ['custom_id','in',$custom_ids]; - } - if(isset($params['contacts']) && $params['contacts'] != ''){ - $custom_ids = Custom::where('custom_name','like','%'.$params['contacts'].'%')->column('id'); - $where[] = ['custom_id','in',$custom_ids]; - } - return CustomFollow::where($this->searchWhere)->where($where)->count(); + return CustomFollow::where($this->searchWhere)->count(); } diff --git a/app/adminapi/lists/custom/CustomLists.php b/app/adminapi/lists/custom/CustomLists.php index 8af944ea0..bbccf2cf8 100644 --- a/app/adminapi/lists/custom/CustomLists.php +++ b/app/adminapi/lists/custom/CustomLists.php @@ -1,27 +1,12 @@ where($this->searchWhere)->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) - ->select()->each(function($item){ - $item['custom_type_text'] = $item->custom_type_text; - $admin = Admin::field('id,name')->where('id',$item['add_user'])->findOrEmpty(); - $province = GeoProvince::field('province_name')->where('province_code',$item['province'])->findOrEmpty(); - $city = GeoCity::field('city_name')->where('city_code',$item['city'])->findOrEmpty(); - $area = GeoArea::field('area_name')->where('area_code',$item['area'])->findOrEmpty(); - $customFollow = CustomFollow::field('date,next_follow_date')->where('custom_id', $item['id'])->order('id', 'desc')->limit(1)->findOrEmpty(); - $item['next_follow_date'] = $customFollow['next_follow_date']; - $item['last_follow_date'] = $customFollow['date']; - $item['follow_total'] = CustomFollow::where('custom_id', $item['id'])->count(); - $item['add_user_name'] = $admin['name']; - $item['province_name'] = $province['province_name']; - $item['city_name'] = $city['city_name']; - $item['area_name'] = $area['area_name']; - unset($item['province'],$item['city'],$item['area'],$item['add_user']); - return $item; + ->select()->each(function($data){ + $admin = Admin::field('id,name')->where('id',$data['add_user'])->findOrEmpty(); + $province = GeoProvince::field('province_name')->where('province_code',$data['province'])->findOrEmpty(); + $city = GeoCity::field('city_name')->where('city_code',$data['city'])->findOrEmpty(); + $customFollow = CustomFollow::field('date,next_follow_date')->where('custom_id', $data['id'])->order('id', 'desc')->limit(1)->findOrEmpty(); + $data['next_follow_date'] = $customFollow['next_follow_date']; + $data['last_follow_date'] = $customFollow['date']; + $data['follow_total'] = CustomFollow::where('custom_id', $data['id'])->count(); + $data['add_user_name'] = $admin['name']; + $data['province_name'] = $province['province_name']; + $data['city_name'] = $city['city_name']; + $data['custom_type_text'] = $data->custom_type_text; + unset($data['province'],$data['add_user']); }) ->toArray(); } diff --git a/app/adminapi/lists/custom/CustomServiceLists.php b/app/adminapi/lists/custom/CustomServiceLists.php index 18477fd88..a89a445d9 100644 --- a/app/adminapi/lists/custom/CustomServiceLists.php +++ b/app/adminapi/lists/custom/CustomServiceLists.php @@ -1,20 +1,6 @@ ['project_id', 'classification', 'urgency', 'processing_result', 'processed_user'], + '=' => ['project_id', 'contract_id', 'classification', 'urgency', 'processing_result', 'processed_user'], '%like%' => ['custom_service_code','name','receiver'] ]; } @@ -59,44 +45,31 @@ class CustomServiceLists extends BaseAdminDataLists implements ListsSearchInterf */ public function lists(): array { - $params = $this->request->get(['custom_id','project_code','custom_name','contract_code']); + $params = $this->request->get(['custom_name']); $where = []; - if(isset($params['custom_id']) && $params['custom_id'] != ''){ - $project_ids = Project::where('custom_id',$params['custom_id'])->column('id'); - $where[] = ['project_id','in',$project_ids]; - } - if(isset($params['project_code']) && $params['project_code'] != ''){ - $project_ids = Project::where('project_code','like','%'.$params['project_code'].'%')->column('id'); - $where[] = ['project_id','in',$project_ids]; - } if(isset($params['custom_name']) && $params['custom_name'] != ''){ $custom_ids = Custom::where('name','like','%'.$params['custom_name'].'%')->column('id'); $project_ids = Project::where('custom_id','in',$custom_ids)->column('id'); $where[] = ['project_id','in',$project_ids]; } - if(isset($params['contract_code']) && $params['contract_code'] != ''){ - $contract_ids = Contract::where('contract_code','like','%'.$params['contract_code'].'%')->column('id'); - $where[] = ['contract_id','in',$contract_ids]; - } return CustomService::field('id,custom_service_code,project_id,contract_id,name,receiver,date,classification,processing_result,urgency,processed_user,is_solve,done_date,score') ->where($this->searchWhere)->where($where)->limit($this->limitOffset, $this->limitLength)->order(['id' => 'desc']) - ->select()->each(function($item){ - $item['classification'] = $item->classification_text; - $item['processing_result'] = $item->processing_result_text; - $item['urgency'] = $item->urgency_text; - $item['is_solve_text'] = $item->is_solve_text; - $project = Project::field('custom_id,name,project_code')->where('id',$item['project_id'])->findOrEmpty(); - $custom = Custom::field('name,master_name,master_phone')->where('id',$project['custom_id'])->findOrEmpty(); - $contract = Contract::field('contract_code')->where('id',$item['contract_id'])->findOrEmpty(); - $admin = Admin::field('name')->where('id',$item['processed_user'])->findOrEmpty(); - $item['project_name'] = $project['name']; - $item['project_code'] = $project['project_code']; - $item['custom_name'] = $custom['name']; - $item['custom_master_name'] = $custom['master_name']; - $item['custom_master_phone'] = $custom['master_phone']; - $item['contract_code'] = $contract['contract_code']; - $item['processed_user'] = $admin['name']; - return $item; + ->select()->each(function($data){ + $project = Project::field('custom_id,name,project_code')->where('id',$data['project_id'])->findOrEmpty(); + $custom = Custom::field('name,master_name,master_phone')->where('id',$project['custom_id'])->findOrEmpty(); + $contract = Contract::field('contract_code')->where('id',$data['contract_id'])->findOrEmpty(); + $admin = Admin::field('name')->where('id',$data['processed_user'])->findOrEmpty(); + $data['project_name'] = $project['name']; + $data['project_code'] = $project['project_code']; + $data['custom_name'] = $custom['name']; + $data['custom_master_name'] = $custom['master_name']; + $data['custom_master_phone'] = $custom['master_phone']; + $data['contract_code'] = $contract['contract_code']; + $data['processed_user'] = $admin['name']; + $data['classification'] = $data->classification_text; + $data['processing_result'] = $data->processing_result_text; + $data['urgency'] = $data->urgency_text; + $data['is_solve_text'] = $data->is_solve_text; }) ->toArray(); } @@ -109,25 +82,13 @@ class CustomServiceLists extends BaseAdminDataLists implements ListsSearchInterf */ public function count(): int { - $params = $this->request->get(['custom_id','project_code','custom_name','contract_code']); + $params = $this->request->get(['custom_name']); $where = []; - if(isset($params['custom_id']) && $params['custom_id'] != ''){ - $project_ids = Project::where('custom_id',$params['custom_id'])->column('id'); - $where[] = ['project_id','in',$project_ids]; - } - if(isset($params['project_code']) && $params['project_code'] != ''){ - $project_ids = Project::where('project_code','like','%'.$params['project_code'].'%')->column('id'); - $where[] = ['project_id','in',$project_ids]; - } if(isset($params['custom_name']) && $params['custom_name'] != ''){ $custom_ids = Custom::where('name','like','%'.$params['custom_name'].'%')->column('id'); $project_ids = Project::where('custom_id','in',$custom_ids)->column('id'); $where[] = ['project_id','in',$project_ids]; } - if(isset($params['contract_code']) && $params['contract_code'] != ''){ - $contract_ids = Contract::where('contract_code','like','%'.$params['contract_code'].'%')->column('id'); - $where[] = ['contract_id','in',$contract_ids]; - } return CustomService::where($this->searchWhere)->where($where)->count(); } diff --git a/app/adminapi/logic/contract/ContractLogic.php b/app/adminapi/logic/contract/ContractLogic.php index cf218b4bf..cd4a4b7ee 100644 --- a/app/adminapi/logic/contract/ContractLogic.php +++ b/app/adminapi/logic/contract/ContractLogic.php @@ -260,4 +260,11 @@ class ContractLogic extends BaseLogic return false; } } + + public static function datas() + { + return Contract::field(['id','contract_name'])->order(['id' => 'desc'])->select()->each(function($data){ + $data['projectinfo'] = 'ID:' . $data['id'] . ' / 名称:' . $data['contract_name']; + })->toArray(); + } } \ No newline at end of file diff --git a/app/adminapi/logic/custom/CustomContactsLogic.php b/app/adminapi/logic/custom/CustomContactsLogic.php index 585a5bc2f..0a5368677 100644 --- a/app/adminapi/logic/custom/CustomContactsLogic.php +++ b/app/adminapi/logic/custom/CustomContactsLogic.php @@ -1,20 +1,6 @@ $params['custom_id'], 'name' => $params['name'], - 'date' => strtotime($params['date']), + 'date' => !empty($params['date']) ? strtotime($params['date']) : 0, 'types' => $params['types'], 'description' => $params['description'] ?? '', - 'annex' => $params['annex'] ?? null, + 'annex' => $params['annex'] ? json_encode($params['annex']) : null, 'coordinate' => $params['coordinate'] ?? '', 'executor' => $params['executor'] ?? '', - 'next_follow_date' => strtotime($params['next_follow_date']), + 'next_follow_date' => !empty($params['next_follow_date']) ? strtotime($params['next_follow_date']) : 0, 'add_user' => $admin_id, 'update_user' => $admin_id ]); @@ -78,13 +64,13 @@ class CustomFollowLogic extends BaseLogic CustomFollow::where('id', $params['id'])->update([ 'custom_id' => $params['custom_id'], 'name' => $params['name'], - 'date' => strtotime($params['date']), + 'date' => !empty($params['date']) ? strtotime($params['date']) : 0, 'types' => $params['types'], 'description' => $params['description'] ?? '', 'annex' => $params['annex']? json_encode($params['annex']) : null, 'coordinate' => $params['coordinate'] ?? '', 'executor' => $params['executor'] ?? '', - 'next_follow_date' => strtotime($params['next_follow_date']), + 'next_follow_date' => !empty($params['next_follow_date']) ? strtotime($params['next_follow_date']) : 0, 'update_user' => $admin_id, 'update_time' => time() ]); diff --git a/app/adminapi/logic/custom/CustomLogic.php b/app/adminapi/logic/custom/CustomLogic.php index bce4940aa..b0bbfd80a 100644 --- a/app/adminapi/logic/custom/CustomLogic.php +++ b/app/adminapi/logic/custom/CustomLogic.php @@ -1,27 +1,15 @@ $params['org_id'], 'dept_id' => $params['dept_id'], 'name' => $params['name'], @@ -72,10 +59,10 @@ class CustomLogic extends BaseLogic 'bank_account' => $params['bank_account'] ?? '', 'add_user' => $admin_id, ]); - if(!empty($other_contacts)){ - foreach($other_contacts as $v){ + if(!empty($params['other_contacts'])){ + foreach($params['other_contacts'] as $v){ CustomContacts::create([ - 'custom_id' => $customRes->id, + 'custom_id' => $res->id, 'name' => $v['name'], 'position' => $v['position'] ?? '', 'phone' => $v['phone'] ?? '', @@ -152,20 +139,17 @@ class CustomLogic extends BaseLogic */ public static function delete(array $params): bool { - Db::startTrans(); - try { - $custom_contacts_ids = CustomContacts::where('custom_id',$params['id'])->column('id'); - $custom_follow_ids = CustomFollow::where('custom_id',$params['id'])->column('id'); - Custom::destroy($params['id']); - CustomContacts::destroy($custom_contacts_ids); - CustomFollow::destroy($custom_follow_ids); - Db::commit(); - return true; - } catch (\Exception $e) { - Db::rollback(); - self::setError($e->getMessage()); + $contact = CustomContacts::where('custom_id','in',$params['id'])->findOrEmpty(); + if(!$contact->isEmpty()){ + self::setError('此数据关联了联系人信息,需删除联系人信息'); + return false; + } + $project = Project::where('custom_id','in',$params['id'])->findOrEmpty(); + if(!$project->isEmpty()){ + self::setError('此数据关联了项目信息,需删除项目信息'); return false; } + return Custom::destroy($params['id']); } @@ -178,18 +162,27 @@ class CustomLogic extends BaseLogic */ public static function detail($params): array { - $custom = Custom::findOrEmpty($params['id']); - $custom['org_name'] = $custom->org->name; - $custom['dept_name'] = $custom->dept->name; - $custom['custom_type_text'] = $custom->custom_type_text; - $custom['credit_rating_text'] = $custom->credit_rating_text; - $province = GeoProvince::field('province_name')->where('province_code',$custom['province'])->findOrEmpty(); - $city = GeoCity::field('city_name')->where('city_code',$custom['city'])->findOrEmpty(); - $area = GeoArea::field('area_name')->where('area_code',$custom['area'])->findOrEmpty(); - $custom['province_name'] = $province['province_name']; - $custom['city_name'] = $city['city_name']; - $custom['area_name'] = $area['area_name']; - unset($custom['org'],$custom['dept']); - return $custom->toArray(); + $data = Custom::findOrEmpty($params['id']); + $org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty(); + $dept = Dept::field('name')->where('id',$data['dept_id'])->findOrEmpty(); + $province = GeoProvince::field('province_name')->where('province_code',$data['province'])->findOrEmpty(); + $city = GeoCity::field('city_name')->where('city_code',$data['city'])->findOrEmpty(); + $area = GeoArea::field('area_name')->where('area_code',$data['area'])->findOrEmpty(); + $data['org_name'] = $org['name']; + $data['dept_name'] = $dept['name']; + $data['province_name'] = $province['province_name']; + $data['city_name'] = $city['city_name']; + $data['area_name'] = $area['area_name']; + $data['custom_type_text'] = $data->custom_type_text; + $data['credit_rating_text'] = $data->credit_rating_text; + unset($data['org'],$data['dept']); + return $data->toArray(); } + + public static function datas() + { + return Custom::field(['id','name'])->order(['id' => 'desc'])->select()->each(function($data){ + $data['projectinfo'] = 'ID:' . $data['id'] . ' / 名称:' . $data['name']; + })->toArray(); + } } \ No newline at end of file diff --git a/app/adminapi/logic/custom/CustomServiceLogic.php b/app/adminapi/logic/custom/CustomServiceLogic.php index ef5998416..08b3b4f21 100644 --- a/app/adminapi/logic/custom/CustomServiceLogic.php +++ b/app/adminapi/logic/custom/CustomServiceLogic.php @@ -1,20 +1,6 @@ data_unique_code('售后工单'), 'project_id' => $params['project_id'], 'contract_id' => $params['contract_id'], - 'date' => strtotime($params['date']), + 'date' => !empty($params['date']) ? strtotime($params['date']) : 0, 'classification' => $params['classification'], 'urgency' => $params['urgency'], 'receiver' => $params['receiver'], @@ -66,16 +52,50 @@ class CustomServiceLogic extends BaseLogic return false; } } + + /** + * @notes 编辑 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/11/12 14:00 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + CustomService::where('id',$params['id'])->update([ + 'project_id' => $params['project_id'], + 'contract_id' => $params['contract_id'], + 'date' => !empty($params['date']) ? strtotime($params['date']) : 0, + 'classification' => $params['classification'], + 'urgency' => $params['urgency'], + 'receiver' => $params['receiver'], + 'processed_user' => $params['processed_user'], + 'name' => $params['name'], + 'description' => $params['description'] ?? '', + 'notes' => $params['notes'] ?? '', + 'annex' => $params['annex'] ? json_encode($params['annex']) : null, + 'update_time' => time(), + ]); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } /** - * @notes 编辑 + * @notes 处理 * @param array $params * @return bool * @author likeadmin * @date 2023/11/12 14:00 */ - public static function edit(array $params): bool + public static function check(array $params): bool { Db::startTrans(); try { @@ -83,7 +103,7 @@ class CustomServiceLogic extends BaseLogic 'processing_result' => $params['processing_result'], 'processing_process' => $params['processing_process'] ?? '', 'processing_hours' => $params['processing_hours'], - 'done_date' => strtotime($params['done_date']), + 'done_date' => !empty($params['done_date']) ? strtotime($params['done_date']) : 0, 'score' => $params['score'], 'is_solve' => $params['is_solve'], 'feedback' => $params['feedback'] ?? '', diff --git a/app/adminapi/logic/project/ProjectLogic.php b/app/adminapi/logic/project/ProjectLogic.php index 95c87d3d6..4a99cbddc 100644 --- a/app/adminapi/logic/project/ProjectLogic.php +++ b/app/adminapi/logic/project/ProjectLogic.php @@ -188,4 +188,11 @@ class ProjectLogic extends BaseLogic $data['unit_nature_text'] = $data->unit_nature_text; return $data->toArray(); } + + public static function datas() + { + return Project::field(['id','name'])->order(['id' => 'desc'])->select()->each(function($data){ + $data['projectinfo'] = 'ID:' . $data['id'] . ' / 名称:' . $data['name']; + })->toArray(); + } } \ No newline at end of file diff --git a/app/adminapi/validate/custom/CustomContactsValidate.php b/app/adminapi/validate/custom/CustomContactsValidate.php index 80d1a9b02..66d4b7c3a 100644 --- a/app/adminapi/validate/custom/CustomContactsValidate.php +++ b/app/adminapi/validate/custom/CustomContactsValidate.php @@ -1,20 +1,6 @@ 'checkAnnex', ]; - protected $message = [ - 'id.require' => '缺少必要参数', - 'custom_id.require' => '请选择客户', - 'name.require' => '请填写姓名', - 'phone.mobile' => '手机号码格式错误', - 'phone.unique' => '手机号码已存在', - 'email.email' => '邮箱格式错误', + protected $field = [ + 'id' => '数据id', + 'custom_id' => '客户id', + 'name' => '姓名', + 'phone' => '手机', + 'email' => '邮箱', ]; - /** * @notes 添加场景 * @return CustomContactsValidate @@ -100,17 +84,7 @@ class CustomContactsValidate extends BaseValidate { $custom = Custom::where('id',$value)->findOrEmpty(); if($custom->isEmpty()){ - return '客户不存在'; - } - return true; - } - - public function checkAnnex($value): bool|string - { - if(!empty($value) && $value != ''){ - if(!is_array($value)){ - return '附件格式错误'; - } + return '客户信息不存在'; } return true; } diff --git a/app/adminapi/validate/custom/CustomFollowValidate.php b/app/adminapi/validate/custom/CustomFollowValidate.php index 71670285c..4403db4f2 100644 --- a/app/adminapi/validate/custom/CustomFollowValidate.php +++ b/app/adminapi/validate/custom/CustomFollowValidate.php @@ -1,20 +1,6 @@ 'checkAnnex', ]; - protected $message = [ - 'id.require' => '缺少必要参数', - 'name.require' => '请填写主题', - 'custom_id.require' => '请选择客户', - 'date.require' => '请选择日期', - 'date.dateFormat' => '日期格式错误', - 'types.require' => '请选择类型', - 'next_follow_date.dateFormat' => '下次回访日期格式错误', + protected $field = [ + 'id' => '数据id', + 'name' => '主题', + 'custom_id' => '客户id', + 'date' => '日期', + 'types' => '类型', + 'next_follow_date' => '下次回访日期', ]; /** @@ -101,7 +86,7 @@ class CustomFollowValidate extends BaseValidate { $custom = Custom::where('id',$value)->findOrEmpty(); if($custom->isEmpty()){ - return '客户不存在'; + return '客户信息不存在'; } return true; } @@ -115,16 +100,6 @@ class CustomFollowValidate extends BaseValidate return true; } - public function checkAnnex($value): bool|string - { - if(!empty($value) && $value != ''){ - if(!is_array($value)){ - return '附件格式错误'; - } - } - return true; - } - public function checkNext($value,$rule,$data): bool|string { if(!empty($value)){ diff --git a/app/adminapi/validate/custom/CustomServiceValidate.php b/app/adminapi/validate/custom/CustomServiceValidate.php index edef40880..bcb9dbdfa 100644 --- a/app/adminapi/validate/custom/CustomServiceValidate.php +++ b/app/adminapi/validate/custom/CustomServiceValidate.php @@ -1,20 +1,6 @@ 'require|in:0,1', ]; - protected $message = [ - 'id.require' => '缺少必要参数', - 'project_id.require' => '请选择项目', - 'contract_id.require' => '请选择项目合同', - 'date.require' => '请选择日期', - 'date.dateFormat' => '日期格式错误', - 'classification.require' => '请选择分类', - 'urgency.require' => '请选择紧急程度', - 'receiver.require' => '请填写接待人', - 'processed_user.require' => '请选择指定处理人', - 'name.require' => '请填写投诉主题', - 'annex' => 'checkAnnex', - 'processing_result.require' => '请填写处理结果', - 'processing_hours.require' => '请填写花费工时', - 'processing_hours.float' => '花费工时值必须是数字', - 'processing_hours.egt' => '花费工时值必须大于等于0', - 'done_date.require' => '请选择完成日期', - 'done_date.dateFormat' => '完成日期格式错误', - 'score.require' => '请填写评分', - 'score.integer' => '评分值必须是整数', - 'score.egt' => '评分值必须大于等于0', - 'is_solve.require' => '请选择问题是否解决', - 'is_solve.in' => '问题是否解决选项值错误', + protected $field = [ + 'id' => '数据id', + 'project_id' => '项目id', + 'contract_id' => '合同id', + 'date' => '日期', + 'classification' => '分类', + 'urgency' => '紧急程度', + 'receiver' => '接待人', + 'processed_user' => '指定处理人', + 'name' => '投诉主题', + 'processing_result' => '处理结果', + 'processing_hours' => '花费工时', + 'done_date' => '完成日期', + 'score' => '客户评分', + 'is_solve' => '是否解决', ]; @@ -92,15 +70,29 @@ class CustomServiceValidate extends BaseValidate ->remove('done_date',true) ->remove('score',true)->remove('is_solve',true); } + + /** + * @notes 编辑场景 + * @return CustomServiceValidate + * @author likeadmin + * @date 2023/11/12 14:00 + */ + public function sceneEdit() + { + return $this->remove('processing_result',true) + ->remove('processing_hours',true) + ->remove('done_date',true) + ->remove('score',true)->remove('is_solve',true); + } /** - * @notes 编辑场景 + * @notes 处理场景 * @return CustomServiceValidate * @author likeadmin * @date 2023/11/12 14:00 */ - public function sceneEdit() + public function sceneCheck() { return $this->only(['id','processing_result','processing_hours','done_date','score','is_solve']); } @@ -138,15 +130,12 @@ class CustomServiceValidate extends BaseValidate return true; } - public function checkContract($value,$rule,$data): bool|string + public function checkContract($value,$rule,$params): bool|string { - $contract = Contract::where('id',$value)->findOrEmpty(); + $contract = Contract::where('id',$value)->where('project_id',$params['project_id'])->findOrEmpty(); if($contract->isEmpty()){ return '项目合同不存在'; } - if($contract['project_id'] != $data['project_id']){ - return '该合同不属于选择的项目'; - } return true; } @@ -177,19 +166,9 @@ class CustomServiceValidate extends BaseValidate return true; } - public function checkAnnex($value): bool|string - { - if(!empty($value) && $value != ''){ - if(!is_array($value)){ - return '附件格式错误'; - } - } - return true; - } - public function checkProRes($value): bool|string { - $dictData = DictData::where('type_value','custom_service_solv_result')->column('value'); + $dictData = DictData::where('type_value','custom_service_solve_result')->column('value'); if(!in_array($value,$dictData)){ return '处理结果无效'; } diff --git a/app/adminapi/validate/custom/CustomValidate.php b/app/adminapi/validate/custom/CustomValidate.php index 44848c901..b39eca607 100644 --- a/app/adminapi/validate/custom/CustomValidate.php +++ b/app/adminapi/validate/custom/CustomValidate.php @@ -1,17 +1,4 @@ 'email', 'other_contacts' => 'checkContacts' ]; - - - protected $message = [ - 'id.require' => '缺少必要参数', - 'org_id.require' => '请选择组织', - 'dept_id.require' => '请选择部门', - 'name.require' => '请填写客户名称', - 'name.unique' => '客户名称已存在', - 'custom_type.require' => '请选择客户属性', - 'phone.require' => '请填写客户电话', - 'credit_rating.require' => '请选择信用度', - 'master_name.require' => '请填写主要负责人姓名', - 'master_phone.mobile' => '主要负责人手机号格式错误', - 'master_email.email' => '主要负责人邮箱格式错误', - ]; - - + + protected $field = [ + 'id' => '数据id', + 'org_id' => '组织id', + 'dept_id' => '部门id', + 'name' => '客户名称', + 'custom_type' => '客户属性', + 'phone' => '电话', + 'credit_rating' => '信用度', + 'master_name' => '主要负责人姓名', + 'master_phone' => '主要负责人手机', + 'master_email' => '主要负责人邮箱', + ]; + /** * @notes 添加场景 * @return CustomValidate @@ -114,19 +98,16 @@ class CustomValidate extends BaseValidate { $org = Orgs::where('id',$value)->findOrEmpty(); if($org->isEmpty()){ - return '组织不存在'; + return '组织信息不存在'; } return true; } - public function checkDept($value,$rule,$data): bool|string + public function checkDept($value,$rule,$params): bool|string { - $dept = Dept::where('id',$value)->findOrEmpty(); + $dept = Dept::where('id',$value)->where('org_id',$params['org_id'])->findOrEmpty(); if($dept->isEmpty()){ - return '部门不存在'; - } - if($dept['org_id'] != $data['org_id']){ - return '部门无效'; + return '部门信息不存在'; } return true; } @@ -152,15 +133,13 @@ class CustomValidate extends BaseValidate public function checkContacts($value): bool|string { if(empty($value) || !is_array($value)){ - return '其他联系人数据格式错误'; + return '其他联系人列表数据格式错误'; } - foreach($value as $v){ - if(empty($v['name'])){ - return '请填写联系人姓名'; - } + foreach($value as $k=>$v){ + if(empty($v['name'])) return '其他联系人列表第'.($k+1).'行姓名为空'; if(isset($v['annex']) && $v['annex'] != ''){ if(!is_array($v['annex'])){ - return '联系人附件格式错误'; + return '其他联系人列表第'.($k+1).'行附件格式错误'; } } } diff --git a/app/common/model/custom/Custom.php b/app/common/model/custom/Custom.php index d7db9cb4a..bd831684a 100644 --- a/app/common/model/custom/Custom.php +++ b/app/common/model/custom/Custom.php @@ -1,23 +1,8 @@ hasOne(GeoProvince::class, 'province_code','province'); - } - - /** - * @notes 关联org - * @return \think\model\relation\HasOne - * @author likeadmin - * @date 2023/12/20 11:01 - */ - public function org() - { - return $this->hasOne(\app\common\model\dept\Orgs::class, 'id', 'org_id'); - } - - /** - * @notes 关联dept - * @return \think\model\relation\HasOne - * @author likeadmin - * @date 2023/12/20 11:01 - */ - public function dept() - { - return $this->hasOne(\app\common\model\dept\Dept::class, 'id', 'dept_id'); - } public function getCustomTypeTextAttr($value,$data){ $dict = DictData::where('type_value','custom_type')->column('name','value'); diff --git a/app/common/model/custom/CustomContacts.php b/app/common/model/custom/CustomContacts.php index 1743e0176..35d7ea261 100644 --- a/app/common/model/custom/CustomContacts.php +++ b/app/common/model/custom/CustomContacts.php @@ -29,8 +29,4 @@ class CustomContacts extends BaseModel use SoftDelete; protected $name = 'custom_contacts'; protected $deleteTime = 'delete_time'; - - public function getAnnexAttr($value){ - return !empty($value) ? json_decode($value) : null; - } } \ No newline at end of file diff --git a/app/common/model/custom/CustomFollow.php b/app/common/model/custom/CustomFollow.php index 084fbc859..f1170c32b 100644 --- a/app/common/model/custom/CustomFollow.php +++ b/app/common/model/custom/CustomFollow.php @@ -1,20 +1,6 @@ column('name','value'); + $dict = DictData::where('type_value','custom_service_solve_result')->column('name','value'); return !empty($data['processing_result']) ? $dict[$data['processing_result']] : ''; } @@ -61,10 +47,5 @@ class CustomService extends BaseModel $is_solve = [0=>'未解决',1=>'已解决']; return $is_solve[$data['is_solve']]; } - - public function getAnnexAttr($value) - { - return !empty($value) ? json_decode($value,true) : ''; - } } \ No newline at end of file