竞争对手模块功能完善
This commit is contained in:
parent
608cfdb38a
commit
4ed160cf7e
@ -16,8 +16,13 @@ namespace app\adminapi\lists\project;
|
|||||||
|
|
||||||
|
|
||||||
use app\adminapi\lists\BaseAdminDataLists;
|
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\model\project\Competitor;
|
||||||
use app\common\lists\ListsSearchInterface;
|
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
|
public function setSearch(): array
|
||||||
{
|
{
|
||||||
return [
|
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
|
public function lists(): array
|
||||||
{
|
{
|
||||||
return Competitor::where($this->searchWhere)
|
$params = $this->request->param();
|
||||||
->field(['id', 'org_id', 'department_id', 'project_id', 'customer_demand_id', 'competitor_name', 'competitor_contacts', 'competitor_contacts_phone', 'competitive_power'])
|
$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)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order(['id' => 'desc'])
|
->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();
|
->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +101,22 @@ class CompetitorLists extends BaseAdminDataLists implements ListsSearchInterface
|
|||||||
*/
|
*/
|
||||||
public function count(): int
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -15,11 +15,15 @@
|
|||||||
namespace app\adminapi\logic\project;
|
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\model\project\Competitor;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
|
use app\common\model\project\Project;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 竞争对手逻辑
|
* 竞争对手逻辑
|
||||||
* Class CompetitorLogic
|
* Class CompetitorLogic
|
||||||
@ -27,8 +31,6 @@ use think\facade\Db;
|
|||||||
*/
|
*/
|
||||||
class CompetitorLogic extends BaseLogic
|
class CompetitorLogic extends BaseLogic
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notes 添加竞争对手
|
* @notes 添加竞争对手
|
||||||
* @param array $params
|
* @param array $params
|
||||||
@ -42,7 +44,7 @@ class CompetitorLogic extends BaseLogic
|
|||||||
try {
|
try {
|
||||||
Competitor::create([
|
Competitor::create([
|
||||||
'org_id' => $params['org_id'],
|
'org_id' => $params['org_id'],
|
||||||
'department_id' => $params['department_id'],
|
'dept_id' => $params['dept_id'],
|
||||||
'project_id' => $params['project_id'],
|
'project_id' => $params['project_id'],
|
||||||
'customer_demand_id' => $params['customer_demand_id'],
|
'customer_demand_id' => $params['customer_demand_id'],
|
||||||
'competitor_name' => $params['competitor_name'],
|
'competitor_name' => $params['competitor_name'],
|
||||||
@ -54,7 +56,6 @@ class CompetitorLogic extends BaseLogic
|
|||||||
'remark' => $params['remark'],
|
'remark' => $params['remark'],
|
||||||
'annex' => $params['annex']
|
'annex' => $params['annex']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -78,7 +79,7 @@ class CompetitorLogic extends BaseLogic
|
|||||||
try {
|
try {
|
||||||
Competitor::where('id', $params['id'])->update([
|
Competitor::where('id', $params['id'])->update([
|
||||||
'org_id' => $params['org_id'],
|
'org_id' => $params['org_id'],
|
||||||
'department_id' => $params['department_id'],
|
'dept_id' => $params['dept_id'],
|
||||||
'project_id' => $params['project_id'],
|
'project_id' => $params['project_id'],
|
||||||
'customer_demand_id' => $params['customer_demand_id'],
|
'customer_demand_id' => $params['customer_demand_id'],
|
||||||
'competitor_name' => $params['competitor_name'],
|
'competitor_name' => $params['competitor_name'],
|
||||||
@ -123,6 +124,19 @@ class CompetitorLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function detail($params): array
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,6 +15,10 @@
|
|||||||
namespace app\adminapi\validate\project;
|
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;
|
use app\common\validate\BaseValidate;
|
||||||
|
|
||||||
|
|
||||||
@ -32,8 +36,23 @@ class CompetitorValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
protected $rule = [
|
protected $rule = [
|
||||||
'id' => 'require',
|
'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' => '联系电话格式错误'
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 参数描述
|
* 参数描述
|
||||||
@ -63,9 +82,7 @@ class CompetitorValidate extends BaseValidate
|
|||||||
* @date 2023/11/24 22:01
|
* @date 2023/11/24 22:01
|
||||||
*/
|
*/
|
||||||
public function sceneEdit()
|
public function sceneEdit()
|
||||||
{
|
{}
|
||||||
return $this->only(['id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -91,4 +108,46 @@ class CompetitorValidate extends BaseValidate
|
|||||||
return $this->only(['id']);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user