133 lines
4.5 KiB
PHP
133 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace app\middleapi\controller;
|
|
|
|
use app\adminapi\logic\auth\AdminLogic;
|
|
use app\common\controller\BaseLikeAdminController;
|
|
use app\common\logic\CompanyLogic;
|
|
use app\common\model\auth\Admin;
|
|
use app\common\model\Company;
|
|
use app\common\model\task_scheduling\TaskScheduling;
|
|
use app\common\model\user\User;
|
|
use think\facade\Db;
|
|
use think\response\Json;
|
|
|
|
class CompanyController extends BaseLikeAdminController
|
|
{
|
|
//公司列表
|
|
public function lists(): Json
|
|
{
|
|
if(!$this->request->isPost()){
|
|
return $this->fail('请求方式错误');
|
|
}
|
|
$params=$this->request->post(['page_no','page_size','company_name','area_name','street_name','area_manager','company_type','is_contract']);
|
|
$where = [];
|
|
if(!empty($params['company_name'])){
|
|
$where[] = ['company','like','%'.$params['company_name'].'%'];
|
|
}
|
|
if(!empty($params['area_name'])){
|
|
$arr= Db::name('geo_area')->where('area_name','like','%'.$params['area_name'].'%')->column('area_code');
|
|
if($arr){
|
|
$where[]=['area','in',$arr];
|
|
}
|
|
}
|
|
if(!empty($params['street_name'])){
|
|
$arr= Db::name('geo_street')->where('street_name','like','%'.$params['street_name'].'%')->column('street_code');
|
|
if($arr){
|
|
$where[]=['street','in',$arr];
|
|
}
|
|
}
|
|
if(!empty($params['area_manager'])){
|
|
$arr= Admin::where('name','like','%'.$params['area_manager'].'%')->column('id');
|
|
if($arr){
|
|
$where[]=['area_manager','in',$arr];
|
|
}
|
|
}
|
|
if(!empty($params['company_type'])){
|
|
$where[] = ['company_type','=',$params['company_type']];
|
|
}
|
|
if(!empty($params['is_contract'])){
|
|
$where[] = ['is_contract','=',$params['is_contract']];
|
|
}
|
|
$pageNo = !empty($params['page_no']) ? $params['page_no'] : 1;
|
|
$pageSize = !empty($params['page_size']) ? $params['page_size'] : 20;
|
|
$data = Company::where($where)
|
|
->field(['is_authentication','id', 'id contract', 'company_name', 'organization_code', 'city', 'area', 'street', 'company_type', 'master_name', 'master_position', 'master_phone', 'master_email', 'area_manager', 'is_contract', 'deposit', 'company_money', 'shareholder_money', 'deposit_time', 'status', 'face_create_status'])
|
|
->page($pageNo, $pageSize)
|
|
->order(['id' => 'desc'])
|
|
->append(['notes'], true)
|
|
->withAttr('company_type',function($value,$data){
|
|
return Db::name('dict_data')->where('id',$value)->value('name');
|
|
})
|
|
->withAttr('area',function($value,$data){
|
|
return Db::name('geo_area')->where('area_code',$value)->value('area_name');
|
|
})
|
|
->withAttr('street',function($value,$data){
|
|
return Db::name('geo_street')->where('street_code',$value)->value('street_name');
|
|
})
|
|
->withAttr('area_manager',function($value,$data){
|
|
return Db::name('admin')->where('id',$value)->value('name');
|
|
})
|
|
->withAttr('notes',function($value,$data){
|
|
if ($data['is_authentication'] == 1) {
|
|
return Db::name('company_authentication_fail_log')->where('company_id',$data['id'])->where('log_type', 2)->order(['id'=>'desc'])->limit(1)->value('fail_reason');
|
|
} else {
|
|
return Db::name('company_authentication_fail_log')->where('company_id',$data['id'])->where('log_type', 1)->order(['id'=>'desc'])->limit(1)->value('fail_reason');
|
|
}
|
|
|
|
})->select()->toArray();
|
|
$count = Company::where($where)->count();
|
|
$result = [
|
|
'lists' => $data,
|
|
'count' => $count
|
|
];
|
|
return $this->success('请求成功',$result);
|
|
}
|
|
|
|
//公司详情
|
|
public function detail(): Json
|
|
{
|
|
if(!$this->request->isPost()){
|
|
return $this->fail('请求方式错误');
|
|
}
|
|
$params=$this->request->post(['id']);
|
|
if(empty($params['id'])){
|
|
return $this->fail('缺少必要参数');
|
|
}
|
|
$result = CompanyLogic::detail($params);
|
|
return $this->data($result);
|
|
}
|
|
|
|
//公司删除
|
|
public function delete(): Json
|
|
{
|
|
if(!$this->request->isPost()){
|
|
return $this->fail('请求方式错误');
|
|
}
|
|
$params=$this->request->post(['id']);
|
|
if(empty($params['id'])){
|
|
return $this->fail('缺少必要参数');
|
|
}
|
|
$admin_id = Company::where('id', $params['id'])->value('admin_id');
|
|
User::where('company_id', $params['id'])->update(['delete_time' => time()]);
|
|
TaskScheduling::where('company_id', $params['id'])->update(['delete_time' => time()]);
|
|
AdminLogic::delete(['id' => $admin_id]);
|
|
CompanyLogic::delete($params);
|
|
return $this->success('删除成功', [], 1, 1);
|
|
}
|
|
|
|
//公司认证
|
|
public function enterpriseCertification() {
|
|
|
|
}
|
|
|
|
//生成合同
|
|
public function generateContract() {
|
|
|
|
}
|
|
|
|
//下属公司
|
|
public function subsidiaryCompany() {
|
|
|
|
}
|
|
} |