diff --git a/app/adminapi/lists/project/CompetitorLists.php b/app/adminapi/lists/project/CompetitorLists.php index e495f4e96..4df674f71 100644 --- a/app/adminapi/lists/project/CompetitorLists.php +++ b/app/adminapi/lists/project/CompetitorLists.php @@ -16,8 +16,13 @@ namespace app\adminapi\lists\project; use app\adminapi\lists\BaseAdminDataLists; +use app\common\model\custom\Custom; +use app\common\model\custom\CustomerDemand; +use app\common\model\dept\Dept; +use app\common\model\dept\Orgs; use app\common\model\project\Competitor; use app\common\lists\ListsSearchInterface; +use app\common\model\project\Project; /** @@ -38,7 +43,7 @@ class CompetitorLists extends BaseAdminDataLists implements ListsSearchInterface public function setSearch(): array { return [ - '=' => ['project_id', 'competitor_name'], + '%like%' => ['competitor_name','competitor_contacts','competitor_contacts_phone'], ]; } @@ -54,11 +59,36 @@ class CompetitorLists extends BaseAdminDataLists implements ListsSearchInterface */ public function lists(): array { - return Competitor::where($this->searchWhere) - ->field(['id', 'org_id', 'department_id', 'project_id', 'customer_demand_id', 'competitor_name', 'competitor_contacts', 'competitor_contacts_phone', 'competitive_power']) + $params = $this->request->param(); + $where = []; + if(isset($params['project_name']) && $params['project_name'] != ''){ + $projectIds = Project::where('name','like','%'.$params['project_name'].'%')->column('id'); + $where[] = ['project_id','in',$projectIds]; + } + if(isset($params['custom_name']) && $params['custom_name'] != ''){ + $customIds = Custom::where('name','like','%'.$params['custom_name'].'%')->column('id'); + $projectIds = Project::where('custom_id','in',$customIds)->column('id'); + $where[] = ['project_id','in',$projectIds]; + } + if(isset($params['customer_demand_name']) && $params['customer_demand_name'] != ''){ + $demandIds = CustomerDemand::where('theme','like','%'.$params['customer_demand_name'].'%')->column('id'); + $where[] = ['customer_demand_id','in',$demandIds]; + } + return Competitor::where($this->searchWhere)->where($where) + ->field(['id','project_id','customer_demand_id','competitor_name','competitor_contacts','competitor_contacts_phone','competitive_power','remark']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) - ->select() + ->select()->each(function($item){ + $org = Orgs::field('name')->where('id',$item['org_id'])->findOrEmpty(); + $dept = Dept::field('name')->where('id',$item['dept_id'])->findOrEmpty(); + $project = Project::field('name,custom_id')->where('id',$item['project_id'])->findOrEmpty(); + $custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty(); + $demand = CustomerDemand::field('theme')->where('id',$item['customer_demand_id'])->findOrEmpty(); + $item['project_name'] = $project['name']; + $item['custom_name'] = $custom['name']; + $item['customer_demand_name'] = $demand['theme']; + return $item; + }) ->toArray(); } @@ -71,7 +101,22 @@ class CompetitorLists extends BaseAdminDataLists implements ListsSearchInterface */ public function count(): int { - return Competitor::where($this->searchWhere)->count(); + $params = $this->request->param(); + $where = []; + if(isset($params['project_name']) && $params['project_name'] != ''){ + $projectIds = Project::where('name','like','%'.$params['project_name'].'%')->column('id'); + $where[] = ['project_id','in',$projectIds]; + } + if(isset($params['custom_name']) && $params['custom_name'] != ''){ + $customIds = Custom::where('name','like','%'.$params['custom_name'].'%')->column('id'); + $projectIds = Project::where('custom_id','in',$customIds)->column('id'); + $where[] = ['project_id','in',$projectIds]; + } + if(isset($params['customer_demand_name']) && $params['customer_demand_name'] != ''){ + $demandIds = CustomerDemand::where('theme','like','%'.$params['customer_demand_name'].'%')->column('id'); + $where[] = ['customer_demand_id','in',$demandIds]; + } + return Competitor::where($this->searchWhere)->where($where)->count(); } } \ No newline at end of file diff --git a/app/adminapi/lists/project/ProjectEstimateLists.php b/app/adminapi/lists/project/ProjectEstimateLists.php index 7aea51947..20dd796d4 100644 --- a/app/adminapi/lists/project/ProjectEstimateLists.php +++ b/app/adminapi/lists/project/ProjectEstimateLists.php @@ -16,6 +16,11 @@ namespace app\adminapi\lists\project; use app\adminapi\lists\BaseAdminDataLists; +use app\common\model\auth\Admin; +use app\common\model\custom\Custom; +use app\common\model\custom\CustomContacts; +use app\common\model\custom\CustomerDemand; +use app\common\model\project\Project; use app\common\model\project\ProjectEstimate; use app\common\lists\ListsSearchInterface; @@ -38,7 +43,8 @@ class ProjectEstimateLists extends BaseAdminDataLists implements ListsSearchInte public function setSearch(): array { return [ - '=' => ['project_id'], + '=' => ['estimate_source','invoice_type'], + '%like%' => ['create_user'], ]; } @@ -54,11 +60,56 @@ class ProjectEstimateLists extends BaseAdminDataLists implements ListsSearchInte */ public function lists(): array { - return ProjectEstimate::where($this->searchWhere) - ->field(['id', 'org_id', 'department_id', 'project_id', 'customer_demand_id', 'estimate_source', 'create_user', 'quotation_date', 'invoice_type', 'technician', 'estimate_amount']) + $params = $this->request->param(); + $where = []; + if(isset($params['project_name']) && $params['project_name'] != ''){ + $projectIds = Project::where('name','like','%'.$params['project_name'].'%')->column('id'); + $where[] = ['project_id','in',$projectIds]; + } + if(isset($params['custom_name']) && $params['custom_name'] != ''){ + $customIds = Custom::where('name','like','%'.$params['custom_name'].'%')->column('id'); + $projectIds = Project::where('custom_id','in',$customIds)->column('id'); + $where[] = ['project_id','in',$projectIds]; + } + if(isset($params['customer_demand_name']) && $params['customer_demand_name'] != ''){ + $demandIds = CustomerDemand::where('theme','like','%'.$params['customer_demand_name'].'%')->column('id'); + $where[] = ['customer_demand_id','in',$demandIds]; + } + if(isset($params['contact_name']) && $params['contact_name'] != ''){ + $customIds = CustomContacts::where('name','like','%'.$params['contact_name'].'%')->column('custom_id'); + $projectIds = Project::where('custom_id','in',$customIds)->column('id'); + $where[] = ['project_id','in',$projectIds]; + } + if(isset($params['contact_phone']) && $params['contact_phone'] != ''){ + $customIds = CustomContacts::where('phone','like','%'.$params['contact_phone'].'%')->column('custom_id'); + $projectIds = Project::where('custom_id','in',$customIds)->column('id'); + $where[] = ['project_id','in',$projectIds]; + } + if(isset($params['technician_name']) && $params['technician_name'] != ''){ + $adminIds = Admin::where('name','like','%'.$params['technician_name'].'%')->column('id'); + $where[] = ['technician','in',$adminIds]; + } + return ProjectEstimate::where($this->searchWhere)->where($where) + ->field(['id','project_id','customer_demand_id','contact_id','estimate_source','create_user','quotation_date','invoice_type','technician','estimate_amount']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) - ->select() + ->select()->each(function($item){ + $item['quotation_date'] = date('Y-m-d H:i:s',$item['quotation_date']); + $item['estimate_source_text'] = $item->estimate_source_text; + $item['invoice_type_text'] = $item->invoice_type_text; + $project = Project::field('name,custom_id')->where('id',$item['project_id'])->findOrEmpty(); + $custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty(); + $demand = CustomerDemand::field('theme')->where('id',$item['customer_demand_id'])->findOrEmpty(); + $contract = CustomContacts::field('name,phone')->where('id',$item['contact_id'])->findOrEmpty(); + $technician = Admin::field('name')->where('id',$item['technician'])->findOrEmpty(); + $item['project_name'] = $project['name']; + $item['custom_name'] = $custom['name']; + $item['customer_demand_name'] = $demand['theme']; + $item['contact_name'] = $contract['name']; + $item['contact_phone'] = $contract['phone']; + $item['technician_name'] = $technician['name']; + return $item; + }) ->toArray(); } @@ -71,7 +122,36 @@ class ProjectEstimateLists extends BaseAdminDataLists implements ListsSearchInte */ public function count(): int { - return ProjectEstimate::where($this->searchWhere)->count(); + $params = $this->request->param(); + $where = []; + if(isset($params['project_name']) && $params['project_name'] != ''){ + $projectIds = Project::where('name','like','%'.$params['project_name'].'%')->column('id'); + $where[] = ['project_id','in',$projectIds]; + } + if(isset($params['custom_name']) && $params['custom_name'] != ''){ + $customIds = Custom::where('name','like','%'.$params['custom_name'].'%')->column('id'); + $projectIds = Project::where('custom_id','in',$customIds)->column('id'); + $where[] = ['project_id','in',$projectIds]; + } + if(isset($params['customer_demand_name']) && $params['customer_demand_name'] != ''){ + $demandIds = CustomerDemand::where('theme','like','%'.$params['customer_demand_name'].'%')->column('id'); + $where[] = ['customer_demand_id','in',$demandIds]; + } + if(isset($params['contact_name']) && $params['contact_name'] != ''){ + $customIds = CustomContacts::where('name','like','%'.$params['contact_name'].'%')->column('custom_id'); + $projectIds = Project::where('custom_id','in',$customIds)->column('id'); + $where[] = ['project_id','in',$projectIds]; + } + if(isset($params['contact_phone']) && $params['contact_phone'] != ''){ + $customIds = CustomContacts::where('phone','like','%'.$params['contact_phone'].'%')->column('custom_id'); + $projectIds = Project::where('custom_id','in',$customIds)->column('id'); + $where[] = ['project_id','in',$projectIds]; + } + if(isset($params['technician_name']) && $params['technician_name'] != ''){ + $adminIds = Admin::where('name','like','%'.$params['technician_name'].'%')->column('id'); + $where[] = ['technician','in',$adminIds]; + } + return ProjectEstimate::where($this->searchWhere)->where($where)->count(); } } \ No newline at end of file diff --git a/app/adminapi/lists/project/ProjectFollowUpLists.php b/app/adminapi/lists/project/ProjectFollowUpLists.php index 4bdbe37da..1fc0f59bd 100644 --- a/app/adminapi/lists/project/ProjectFollowUpLists.php +++ b/app/adminapi/lists/project/ProjectFollowUpLists.php @@ -42,7 +42,7 @@ class ProjectFollowUpLists extends BaseAdminDataLists implements ListsSearchInte { return [ '=' => ['follow_type', 'project_assurance', 'follow_status', 'follow_stage'], - '%like%' => ['theme','contacts','contact_information'], + '%like%' => ['executor','theme','contacts','contact_information'], ]; } @@ -69,10 +69,6 @@ class ProjectFollowUpLists extends BaseAdminDataLists implements ListsSearchInte $projectIds = Project::where('custom_id','in',$customIds)->column('id'); $where[] = ['project_id','in',$projectIds]; } - if(isset($params['executor']) && $params['executor'] != ''){ - $adminIds = Admin::where('name','like','%'.$params['executor'].'%')->column('id'); - $where[] = ['executor','in',$adminIds]; - } return ProjectFollowUp::where($this->searchWhere)->where($where) ->field(['id', 'project_id', 'executor', 'follow_date', 'follow_type', 'theme', 'project_assurance', 'follow_status', 'follow_stage', 'next_follow_up_date', 'create_time']) ->limit($this->limitOffset, $this->limitLength) @@ -86,8 +82,6 @@ class ProjectFollowUpLists extends BaseAdminDataLists implements ListsSearchInte $item['next_follow_up_date'] = !empty($item['next_follow_up_date']) ? date('Y-m-d',$item['next_follow_up_date']) : ''; $project = Project::field('id,custom_id,name')->where('id',$item['project_id'])->findOrEmpty(); $custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty(); - $executor = Admin::field('name')->where('id',$item['executor'])->findOrEmpty(); - $item['executor'] = $executor['name']; $item['project_name'] = $project['name']; $item['custom_name'] = $custom['name']; return $item; @@ -115,10 +109,6 @@ class ProjectFollowUpLists extends BaseAdminDataLists implements ListsSearchInte $projectIds = Project::where('custom_id','in',$customIds)->column('id'); $where[] = ['project_id','in',$projectIds]; } - if(isset($params['executor']) && $params['executor'] != ''){ - $adminIds = Admin::where('name','like','%'.$params['executor'].'%')->column('id'); - $where[] = ['executor','in',$adminIds]; - } return ProjectFollowUp::where($this->searchWhere)->where($where)->count(); } diff --git a/app/adminapi/logic/project/CompetitorLogic.php b/app/adminapi/logic/project/CompetitorLogic.php index a2174ca47..5a006ff8f 100644 --- a/app/adminapi/logic/project/CompetitorLogic.php +++ b/app/adminapi/logic/project/CompetitorLogic.php @@ -15,11 +15,15 @@ namespace app\adminapi\logic\project; +use app\common\model\custom\Custom; +use app\common\model\custom\CustomerDemand; +use app\common\model\dept\Dept; +use app\common\model\dept\Orgs; use app\common\model\project\Competitor; use app\common\logic\BaseLogic; +use app\common\model\project\Project; use think\facade\Db; - /** * 竞争对手逻辑 * Class CompetitorLogic @@ -27,8 +31,6 @@ use think\facade\Db; */ class CompetitorLogic extends BaseLogic { - - /** * @notes 添加竞争对手 * @param array $params @@ -42,7 +44,7 @@ class CompetitorLogic extends BaseLogic try { Competitor::create([ 'org_id' => $params['org_id'], - 'department_id' => $params['department_id'], + 'dept_id' => $params['dept_id'], 'project_id' => $params['project_id'], 'customer_demand_id' => $params['customer_demand_id'], 'competitor_name' => $params['competitor_name'], @@ -54,7 +56,6 @@ class CompetitorLogic extends BaseLogic 'remark' => $params['remark'], 'annex' => $params['annex'] ]); - Db::commit(); return true; } catch (\Exception $e) { @@ -78,7 +79,7 @@ class CompetitorLogic extends BaseLogic try { Competitor::where('id', $params['id'])->update([ 'org_id' => $params['org_id'], - 'department_id' => $params['department_id'], + 'dept_id' => $params['dept_id'], 'project_id' => $params['project_id'], 'customer_demand_id' => $params['customer_demand_id'], 'competitor_name' => $params['competitor_name'], @@ -123,6 +124,19 @@ class CompetitorLogic extends BaseLogic */ public static function detail($params): array { - return Competitor::findOrEmpty($params['id'])->toArray(); + $field = 'id,org_id,dept_id,project_id,customer_demand_id,competitor_name,competitor_contacts,competitor_contacts_phone,competitive_power,competitor_advantages,competitor_disadvantages,remark,annex'; + $data = Competitor::field($field)->findOrEmpty($params['id'])->toArray(); + $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,custom_id')->where('id',$data['project_id'])->findOrEmpty(); + $custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty(); + $demand = CustomerDemand::field('theme')->where('id',$data['customer_demand_id'])->findOrEmpty(); + $data['org_name'] = $org['name']; + $data['dept_name'] = $dept['name']; + $data['project_name'] = $project['name']; + $data['project_code'] = $project['project_code']; + $data['custom_name'] = $custom['name']; + $data['customer_demand_name'] = $demand['theme']; + return $data; } } \ No newline at end of file diff --git a/app/adminapi/logic/project/ProjectEstimateLogic.php b/app/adminapi/logic/project/ProjectEstimateLogic.php index a69a04318..f1cffc754 100644 --- a/app/adminapi/logic/project/ProjectEstimateLogic.php +++ b/app/adminapi/logic/project/ProjectEstimateLogic.php @@ -15,6 +15,13 @@ namespace app\adminapi\logic\project; +use app\common\model\auth\Admin; +use app\common\model\custom\Custom; +use app\common\model\custom\CustomContacts; +use app\common\model\custom\CustomerDemand; +use app\common\model\dept\Dept; +use app\common\model\dept\Orgs; +use app\common\model\project\Project; use app\common\model\project\ProjectEstimate; use app\common\logic\BaseLogic; use think\facade\Db; @@ -42,10 +49,11 @@ class ProjectEstimateLogic extends BaseLogic try { ProjectEstimate::create([ 'org_id' => $params['org_id'], - 'department_id' => $params['department_id'], + 'dept_id' => $params['dept_id'], 'project_id' => $params['project_id'], 'customer_demand_id' => $params['customer_demand_id'], 'estimate_source' => $params['estimate_source'], + 'contact_id' => $params['contact_id'], 'create_user' => $params['create_user'], 'quotation_date' => strtotime($params['quotation_date']), 'invoice_type' => $params['invoice_type'], @@ -54,7 +62,6 @@ class ProjectEstimateLogic extends BaseLogic 'ask' => $params['ask'], 'annex' => $params['annex'] ]); - Db::commit(); return true; } catch (\Exception $e) { @@ -78,10 +85,11 @@ class ProjectEstimateLogic extends BaseLogic try { ProjectEstimate::where('id', $params['id'])->update([ 'org_id' => $params['org_id'], - 'department_id' => $params['department_id'], + 'dept_id' => $params['dept_id'], 'project_id' => $params['project_id'], 'customer_demand_id' => $params['customer_demand_id'], 'estimate_source' => $params['estimate_source'], + 'contact_id' => $params['contact_id'], 'create_user' => $params['create_user'], 'quotation_date' => strtotime($params['quotation_date']), 'invoice_type' => $params['invoice_type'], @@ -90,7 +98,6 @@ class ProjectEstimateLogic extends BaseLogic 'ask' => $params['ask'], 'annex' => $params['annex'] ]); - Db::commit(); return true; } catch (\Exception $e) { @@ -123,6 +130,27 @@ class ProjectEstimateLogic extends BaseLogic */ public static function detail($params): array { - return ProjectEstimate::findOrEmpty($params['id'])->toArray(); + $field = 'id,org_id,dept_id,project_id,customer_demand_id,contact_id,estimate_source,create_user,quotation_date,invoice_type,technician,estimate_amount,ask,annex'; + $data = ProjectEstimate::field($field)->findOrEmpty($params['id']); + $data['quotation_date'] = date('Y-m-d H:i:s',$data['quotation_date']); + $data['estimate_source_text'] = $data->estimate_source_text; + $data['invoice_type_text'] = $data->invoice_type_text; + $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,custom_id')->where('id',$data['project_id'])->findOrEmpty(); + $custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty(); + $demand = CustomerDemand::field('theme')->where('id',$data['customer_demand_id'])->findOrEmpty(); + $contract = CustomContacts::field('name,phone')->where('id',$data['contact_id'])->findOrEmpty(); + $technician = Admin::field('name')->where('id',$data['technician'])->findOrEmpty(); + $data['org_name'] = $org['name']; + $data['dept_name'] = $dept['name']; + $data['project_name'] = $project['name']; + $data['project_code'] = $project['project_code']; + $data['custom_name'] = $custom['name']; + $data['customer_demand_name'] = $demand['theme']; + $data['contact_name'] = $contract['name']; + $data['contact_phone'] = $contract['phone']; + $data['technician_name'] = $technician['name']; + return $data->toArray(); } } \ No newline at end of file diff --git a/app/adminapi/logic/project/ProjectFollowUpLogic.php b/app/adminapi/logic/project/ProjectFollowUpLogic.php index 0803495f8..bcbae7827 100644 --- a/app/adminapi/logic/project/ProjectFollowUpLogic.php +++ b/app/adminapi/logic/project/ProjectFollowUpLogic.php @@ -140,8 +140,6 @@ class ProjectFollowUpLogic extends BaseLogic $data['next_follow_up_date'] = !empty($data['next_follow_up_date']) ? date('Y-m-d',$data['next_follow_up_date']) : ''; $project = Project::field('id,custom_id,name,project_code')->where('id',$data['project_id'])->findOrEmpty(); $custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty(); - $executor = Admin::field('name')->where('id',$data['executor'])->findOrEmpty(); - $data['executor'] = $executor['name']; $data['project_name'] = $project['name']; $data['project_code'] = $project['project_code']; $data['custom_name'] = $custom['name']; diff --git a/app/adminapi/logic/project/ProjectPreSalesMembersLogic.php b/app/adminapi/logic/project/ProjectPreSalesMembersLogic.php index 20719e752..be1dc6102 100644 --- a/app/adminapi/logic/project/ProjectPreSalesMembersLogic.php +++ b/app/adminapi/logic/project/ProjectPreSalesMembersLogic.php @@ -122,7 +122,6 @@ class ProjectPreSalesMembersLogic extends BaseLogic $data['business_people'] = implode(',',$business_people); $data['cross_departmental_personnel'] = implode(',',$cross_departmental_personnel); $data['add_people'] = $add_people['name']; - unset($data['technician_ids'],$data['business_people_ids'],$data['cross_departmental_personnel_ids']); return $data; } } \ No newline at end of file diff --git a/app/adminapi/validate/project/CompetitorValidate.php b/app/adminapi/validate/project/CompetitorValidate.php index a055ab94d..45577389c 100644 --- a/app/adminapi/validate/project/CompetitorValidate.php +++ b/app/adminapi/validate/project/CompetitorValidate.php @@ -15,6 +15,10 @@ namespace app\adminapi\validate\project; +use app\common\model\custom\CustomerDemand; +use app\common\model\dept\Dept; +use app\common\model\dept\Orgs; +use app\common\model\project\Project; use app\common\validate\BaseValidate; @@ -32,9 +36,24 @@ class CompetitorValidate extends BaseValidate */ protected $rule = [ 'id' => 'require', + 'org_id' => 'require|checkOrg', + 'dept_id' => 'require|checkDept', + 'project_id' => 'require|checkProject', + 'customer_demand_id' => 'require|checkCustomerDemand', + 'competitor_name' => 'require', + 'competitor_contacts_phone' =>'mobile' ]; - - + + protected $message = [ + 'id.require' => '缺少必要参数', + 'org_id.require' => '请选择组织', + 'dept_id.require' => '请选择部门', + 'project_id.require' => '请选择项目', + 'customer_demand_id.require' => '请选择客户需求', + 'competitor_name.require' => '请填写竞争对手名称', + 'competitor_contacts_phone.mobile' => '联系电话格式错误' + ]; + /** * 参数描述 * @var string[] @@ -63,9 +82,7 @@ class CompetitorValidate extends BaseValidate * @date 2023/11/24 22:01 */ public function sceneEdit() - { - return $this->only(['id']); - } + {} /** @@ -90,5 +107,47 @@ class CompetitorValidate extends BaseValidate { 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 checkCustomerDemand($value,$rule,$data): bool|string + { + $customDemand = CustomerDemand::where('id',$value)->findOrEmpty(); + if($customDemand->isEmpty()){ + return '客户需求不存在'; + } + if($customDemand['project_id'] != $data['project_id']){ + return '客户需求与项目信息不一致'; + } + return true; + } } \ No newline at end of file diff --git a/app/adminapi/validate/project/ProjectEstimateValidate.php b/app/adminapi/validate/project/ProjectEstimateValidate.php index 9e2a9a51d..a0b6faa6a 100644 --- a/app/adminapi/validate/project/ProjectEstimateValidate.php +++ b/app/adminapi/validate/project/ProjectEstimateValidate.php @@ -15,6 +15,14 @@ namespace app\adminapi\validate\project; +use app\common\model\auth\Admin; +use app\common\model\custom\Custom; +use app\common\model\custom\CustomContacts; +use app\common\model\custom\CustomerDemand; +use app\common\model\dept\Dept; +use app\common\model\dept\Orgs; +use app\common\model\dict\DictData; +use app\common\model\project\Project; use app\common\validate\BaseValidate; @@ -32,7 +40,26 @@ class ProjectEstimateValidate extends BaseValidate */ protected $rule = [ 'id' => 'require', + 'org_id' => 'require|checkOrg', + 'dept_id' => 'require|checkDept', + 'project_id' => 'require|checkProject', + 'customer_demand_id' => 'require|checkCustomerDemand', + 'estimate_source' => 'require|checkEstimateSource', + 'contact_id' => 'checkContact', + 'quotation_date' => 'date', + 'invoice_type' => 'checkInvoiceType', + 'technician' => 'checkTechnician', ]; + + protected $message = [ + 'id.require' => '缺少必要参数', + 'org_id.require' => '请选择组织', + 'dept_id.require' => '请选择部门', + 'project_id.require' => '请选择项目', + 'customer_demand_id.require' => '请选择客户需求', + 'estimate_source.require' => '请选择概算来源', + 'quotation_date.date' => '报价日期格式错误' + ]; /** @@ -63,9 +90,7 @@ class ProjectEstimateValidate extends BaseValidate * @date 2023/11/24 21:42 */ public function sceneEdit() - { - return $this->only(['id']); - } + {} /** @@ -90,5 +115,87 @@ class ProjectEstimateValidate extends BaseValidate { 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 checkCustomerDemand($value,$rule,$data): bool|string + { + $customDemand = CustomerDemand::where('id',$value)->findOrEmpty(); + if($customDemand->isEmpty()){ + return '客户需求不存在'; + } + if($customDemand['project_id'] != $data['project_id']){ + return '客户需求与项目信息不一致'; + } + return true; + } + + public function checkEstimateSource($value): bool|string + { + $dictDate = DictData::where('type_value','estimate_source')->column('value'); + if(!in_array($value,$dictDate)){ + return '概算来源数据值错误'; + } + return true; + } + + public function checkContact($value,$rule,$data): bool|string + { + $customContract = CustomContacts::where('id',$value)->findOrEmpty(); + if($customContract->isEmpty()){ + return '联系人不存在'; + } + $project = Project::field('custom_id')->where('id',$data['project_id'])->findOrEmpty(); + if($customContract['custom_id'] != $project['custom_id']){ + return '联系人不是当前客户的联系人'; + } + return true; + } + + function checkInvoiceType($value): bool|string + { + $dictDate = DictData::where('type_value','invoice_type')->column('value'); + if(!in_array($value,$dictDate)){ + return '发票类型数据值错误'; + } + return true; + } + + public function checkTechnician($value): bool|string + { + $admin = Admin::where('id',$value)->findOrEmpty(); + if($admin->isEmpty()){ + return '人员不存在'; + } + return true; + } } \ No newline at end of file diff --git a/app/adminapi/validate/project/ProjectFollowUpValidate.php b/app/adminapi/validate/project/ProjectFollowUpValidate.php index f6a27d8e0..1c5d6b76b 100644 --- a/app/adminapi/validate/project/ProjectFollowUpValidate.php +++ b/app/adminapi/validate/project/ProjectFollowUpValidate.php @@ -36,7 +36,6 @@ class ProjectFollowUpValidate extends BaseValidate protected $rule = [ 'id' => 'require', 'project_id' => 'require|checkProject', - 'executor' => 'require|integer|checkExecutor', 'theme' => 'require', 'follow_date' => 'require|date', 'follow_type' => 'require|checkType', @@ -49,8 +48,6 @@ class ProjectFollowUpValidate extends BaseValidate protected $message = [ 'id.require' => '缺少必要参数', 'project_id.require' => '请选择项目', - 'executor.require' => '请选择执行人', - 'executor.integer' => '执行人数据格式错误', 'theme.require' => '请填写主题', 'follow_date.require' => '请选择日期', 'follow_date.date' => '日期格式错误', @@ -125,14 +122,6 @@ class ProjectFollowUpValidate extends BaseValidate } return true; } - public function checkExecutor($value): bool|string - { - $admin = Admin::where('id',$value)->findOrEmpty(); - if($admin->isEmpty()){ - return '执行人不存在'; - } - return true; - } public function checkType($value): bool|string { $dictData = DictData::where('type_value','follow_type')->column('value'); diff --git a/app/common/model/project/ProjectEstimate.php b/app/common/model/project/ProjectEstimate.php index dda135a41..b4f8c37ec 100644 --- a/app/common/model/project/ProjectEstimate.php +++ b/app/common/model/project/ProjectEstimate.php @@ -16,6 +16,7 @@ namespace app\common\model\project; use app\common\model\BaseModel; +use app\common\model\dict\DictData; use think\model\concern\SoftDelete; @@ -29,6 +30,15 @@ class ProjectEstimate extends BaseModel use SoftDelete; protected $name = 'project_estimate'; protected $deleteTime = 'delete_time'; - - + + public function getEstimateSourceTextAttr($value,$data) + { + $dictData = DictData::where('type_value','estimate_source')->column('name','value'); + return $dictData[$data['estimate_source']]; + } + public function getInvoiceTypeTextAttr($value,$data) + { + $dictData = DictData::where('type_value','invoice_type')->column('name','value'); + return $dictData[$data['invoice_type']]; + } } \ No newline at end of file