diff --git a/app/adminapi/lists/project/ProjectLists.php b/app/adminapi/lists/project/ProjectLists.php index 3a599b462..b8b0cb1ac 100644 --- a/app/adminapi/lists/project/ProjectLists.php +++ b/app/adminapi/lists/project/ProjectLists.php @@ -16,6 +16,7 @@ namespace app\adminapi\lists\project; use app\adminapi\lists\BaseAdminDataLists; +use app\common\model\custom\Custom; use app\common\model\project\Project; use app\common\lists\ListsSearchInterface; @@ -38,7 +39,8 @@ class ProjectLists extends BaseAdminDataLists implements ListsSearchInterface public function setSearch(): array { return [ - '=' => ['custom_id', 'project_type', 'project_code', 'project_content', 'project_estimation', 'project_address', 'estimated_construction', 'bidding_time', 'bidding_method', 'contacts', 'position', 'telephone', 'department', 'person', 'relationship', 'discovery_time', 'information_sources', 'competitor', 'construction_funds_sources', 'construction_payment_method', 'construction_financial_status', 'construction_recognition', 'my_construction_recognition', 'strategic_significance', 'industry', 'unit_nature', 'annex', 'status'], + '=' => ['project_type', 'project_content', 'project_estimation', 'estimated_construction', 'bidding_time', 'bidding_method', 'contacts', 'position', 'telephone', 'department', 'person', 'relationship', 'discovery_time', 'information_sources', 'competitor', 'construction_funds_sources', 'construction_payment_method', 'construction_financial_status', 'construction_recognition', 'my_construction_recognition', 'strategic_significance', 'industry', 'unit_nature', 'annex', 'status'], + '%like%' => ['project_code','project_address'] ]; } @@ -54,11 +56,21 @@ class ProjectLists extends BaseAdminDataLists implements ListsSearchInterface */ public function lists(): array { - return Project::where($this->searchWhere) + $params = $this->request->param(); + $condition = []; + if(isset($params['custom_id']) && $params['custom_id'] != ''){ + $customIds = Custom::where('name','like','%'.$params['custom_id'].'%')->column('id'); + $condition[] = ['custom_id','in',$customIds]; + } + return Project::where($this->searchWhere)->where($condition) ->field(['id', 'custom_id', 'project_type', 'project_code', 'project_content', 'project_estimation', 'project_address', 'estimated_construction', 'bidding_time', 'bidding_method', 'contacts', 'position', 'telephone', 'department', 'person', 'relationship', 'discovery_time', 'information_sources', 'competitor', 'construction_funds_sources', 'construction_payment_method', 'construction_financial_status', 'construction_recognition', 'my_construction_recognition', 'strategic_significance', 'industry', 'unit_nature', 'annex', 'status']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) - ->select() + ->select()->each(function($item){ + $custom = Custom::field('name')->where('id',$item['custom_id'])->findOrEmpty(); + $item['custom_name'] = $custom->isEmpty() ? '' : $custom['name']; + return $item; + }) ->toArray(); } diff --git a/app/adminapi/logic/project/ProjectLogic.php b/app/adminapi/logic/project/ProjectLogic.php index 09c20d2fd..d889c7b55 100644 --- a/app/adminapi/logic/project/ProjectLogic.php +++ b/app/adminapi/logic/project/ProjectLogic.php @@ -15,6 +15,7 @@ namespace app\adminapi\logic\project; +use app\common\model\custom\Custom; use app\common\model\project\Project; use app\common\logic\BaseLogic; use think\facade\Db; @@ -42,6 +43,7 @@ class ProjectLogic extends BaseLogic try { Project::create([ 'custom_id' => $params['custom_id'], + 'name' => $params['name'], 'project_type' => $params['project_type'], 'project_code' => $params['project_code'], 'project_content' => $params['project_content'], @@ -94,6 +96,7 @@ class ProjectLogic extends BaseLogic try { Project::where('id', $params['id'])->update([ 'custom_id' => $params['custom_id'], + 'name' => $params['name'], 'project_type' => $params['project_type'], 'project_code' => $params['project_code'], 'project_content' => $params['project_content'], @@ -155,6 +158,9 @@ class ProjectLogic extends BaseLogic */ public static function detail($params): array { - return Project::findOrEmpty($params['id'])->toArray(); + $data = Project::findOrEmpty($params['id'])->toArray(); + $custom = Custom::field('name')->where('id',$data['custom_id'])->findOrEmpty(); + $data['custom_name'] = $custom->isEmpty() ? '' : $custom['name']; + return $data; } } \ No newline at end of file diff --git a/app/adminapi/validate/project/ProjectValidate.php b/app/adminapi/validate/project/ProjectValidate.php index 6a7b2e7f1..dcb422b50 100644 --- a/app/adminapi/validate/project/ProjectValidate.php +++ b/app/adminapi/validate/project/ProjectValidate.php @@ -32,6 +32,10 @@ class ProjectValidate extends BaseValidate */ protected $rule = [ 'id' => 'require', + 'custom_id' => 'require', + 'project_code' => 'require', + 'project_type' => 'require', + 'name' => 'require', ]; diff --git a/app/common/model/project/Project.php b/app/common/model/project/Project.php index 605dc8096..7afbd3c6e 100644 --- a/app/common/model/project/Project.php +++ b/app/common/model/project/Project.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,14 @@ class Project extends BaseModel use SoftDelete; protected $name = 'project'; protected $deleteTime = 'delete_time'; - - + + public function getStatusAttr($value) + { + $project_status = DictData::field('name,value')->where('type_id',39)->select(); + $status = []; + foreach ($project_status as $v) { + $status[$v['value']] = $v['name']; + } + return $status[$value]; + } } \ No newline at end of file