TaskSystem/app/adminapi/controller/CompanyController.php

354 lines
13 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\controller;
use app\adminapi\lists\CompanyLists;
use app\adminapi\logic\auth\AdminLogic;
use app\common\logic\CompanyLogic;
use app\adminapi\validate\CompanyValidate;
use app\api\controller\JunziqianController;
use app\common\model\auth\Admin;
use app\common\model\Company;
use think\facade\Db;
use app\common\logic\contract\ContractLogic;
use app\common\model\contract\Contract;
use app\common\model\task_scheduling\TaskScheduling;
use app\common\model\user\User;
/**
* Company控制器
* Class CompanyController
* @package app\adminapi\controller
*/
class CompanyController extends BaseAdminController
{
/**
* @notes 获取列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/07/15 14:43
*/
public function lists()
{
return $this->dataLists(new CompanyLists());
}
public function list_two()
{
return $this->success('ok', (new CompanyLists())->list_two());
}
/**
* @notes 添加
* @return \think\response\Json
* @author likeadmin
* @date 2023/07/15 14:43
*/
public function add()
{
$params = (new CompanyValidate())->post()->goCheck('add');
$params['other_contacts'] = json_encode($params['other_contacts']);
$params['qualification'] = json_encode($params['qualification']);
$params['area_manager'] = $this->adminId;
if (isset($params['responsible_area'])) {
$params['responsible_area'] = implode(',', $params['responsible_area']);
}
$result = CompanyLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(CompanyLogic::getError());
}
/**
* @notes 编辑
* @return \think\response\Json
* @author likeadmin
* @date 2023/07/15 14:43
*/
public function edit()
{
$params = (new CompanyValidate())->post()->goCheck('edit');
$params['other_contacts'] = json_encode($params['other_contacts']);
$params['qualification'] = json_encode($params['qualification']);
if (isset($params['responsible_area'])) {
$params['responsible_area'] = implode(',', $params['responsible_area']);
}
$result = CompanyLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(CompanyLogic::getError());
}
/**
* @notes 删除
* @return \think\response\Json
* @author likeadmin
* @date 2023/07/15 14:43
*/
public function delete()
{
$params = (new CompanyValidate())->post()->goCheck('delete');
$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);
}
/**
* @notes 获取详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/07/15 14:43
*/
public function detail()
{
$params = (new CompanyValidate())->goCheck('detail');
$result = CompanyLogic::detail($params);
return $this->data($result);
}
//**发起合同 */
public function initiate_contract()
{
$params = $this->request->param();
if (isset($params['party_a']) && $params['party_a'] > 0) {
$params['party_a'] = $params['party_a'];
} else {
$params['party_a'] = $this->adminInfo['company_id'];
}
//判断是否是租赁合同
//如果是租赁合同则必须传递租赁数量参数
// if($params['contract_type'] == 29) {
// if(empty($params['num'])){
// return $this->fail('缺少必要参数');
// }
// }
$area_manager = Company::where('id', $params['party_a'])->value('area_manager');
$params['area_manager'] = $area_manager;
$params['type'] = 1;
$params['party_b'] = $params['id'];
unset($params['id']);
$result = ContractLogic::initiate_contract($params);
if ($result['code'] == 1) {
return $this->success($result['msg'], $result['data']);
}
return $this->fail(ContractLogic::getError());
}
// /**生成合同 */
public function Draftingcontracts()
{
$params = $this->request->param();
$result = ContractLogic::Draftingcontracts($params);
if ($result == true) {
return $this->success('生成合同成功', [], 1, 1);
}
return $this->fail(ContractLogic::getError());
}
//**发送短信 */
public function postsms()
{
$params = (new CompanyValidate())->goCheck('detail');
$id = Contract::where('party_b', $params['id'])->value('id');
$res = ContractLogic::postsms(['id' => $id]);
if ($res == true) {
return $this->success('发送成功', [], 1, 1);
} else {
return $this->fail(ContractLogic::getError());
}
}
//企业认证
public function authentication()
{
$params = (new CompanyValidate())->goCheck('detail');
$company = Db::name('company')->where('id', $params['id'])->find();
$qualification = json_decode($company['qualification'], true);
if ($company && $qualification['business_license']) {
$data = [
'name' => $company['company_name'],
'organization_code' => $company['organization_code'],
'business_license' => 'https://lihai001.oss-cn-chengdu.aliyuncs.com/def/561f8202305171526091317.png', //$qualification['business_license'],
'master_name' => $company['master_name'],
'master_email' => $company['master_email'],
'id' => $company['id'],
];
$res = app(JunziqianController::class)->EnterpriseCertification($data);
if ($res->success == true) {
Db::name('company')->where('id', $params['id'])->update(['master_email' => $res->data,'is_authentication'=>1]);
return $this->success('认证成功',[],1, 1);
// return $this->success('系统认证中,请稍后刷新页面查看', ['email' => $res->data], 1, 1);
} else {
return $this->fail($res->msg);
}
} else {
return $this->fail("公司不存在");
}
}
//重新认证
public function organizationReapply()
{
$params = (new CompanyValidate())->goCheck('detail');
$company = Db::name('company')->where('id', $params['id'])->find();
$qualification = json_decode($company['qualification'], true);
if ($company && $qualification['business_license']) {
$data = [
'name' => $company['company_name'],
'organization_code' => $company['organization_code'],
'business_license' => 'https://lihai001.oss-cn-chengdu.aliyuncs.com/def/561f8202305171526091317.png', //$qualification['business_license'],
'master_name' => $company['master_name'],
'master_email' => $company['master_email'],
];
$res = app(JunziqianController::class)->organizationReapply($data);
if ($res->success == true) {
Db::name('company')->where('id', $params['id'])->update(['master_email' => $res->data]);
return $this->success('系统认证中,请稍后刷新页面查看', ['email' => $res->data], 1, 1);
} else {
return $this->fail($res->msg);
}
}
}
// 企业人脸校验上传
public function organizationFaceCreate()
{
$params = (new CompanyValidate())->goCheck('detail');
$company = Db::name('company')->where('id', $params['id'])->find();
// 公司数据合法性校验
$this->companyCheck($company);
$data = [
'company_name' => $company['company_name'],
'organization_code' => $company['organization_code'],
'master_name' => $company['master_name'],
'master_id_card' => $company['master_id_card'],
'master_email' => $company['master_email'],
'master_phone' => $company['master_phone'],
'id' => $company['id'],
];
$res = app(JunziqianController::class)->organizationFaceCreate($data);
if ($res->success == true && !empty($res->data)) {
return $this->success('成功',["faceCreateUrl"=>$res->data],1, 1);
} else {
return $this->fail($res->msg);
}
}
private function companyCheck($company) {
if (empty($company)) {
return $this->fail("公司不存在");
}
if (empty($company['master_face'])) {
return $this->fail("未上传主联系人头像信息,无法上传企业人脸");
}
if(empty($company['master_id_card'])) {
return $this->fail("主联系人证件号为空,无法上传企业人脸");
}
if(empty($company['master_email'])) {
return $this->fail("主联系人邮箱为空,无法上传企业人脸");
}
}
public function userList()
{
$existUsers = Company::where('status', '<>', -1)->column('admin_id');
$existUsers = array_unique($existUsers);
$users = Admin::whereNotIn('id', $existUsers)->field('id,name,avatar')->select()->toArray();
return $this->success('success', $users);
}
/**
* 所有成员公司
* @param $id
* @return \think\response\Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function subordinate($company_id)
{
$ids = Contract::where('party_a', $company_id)->where('status', 1)->where('type', 1)->column('party_b');
if ($ids) {
$result = Company::where('id', 'in', $ids)->field('company_name,id,company_type,company_type company_type_name,area,area area_name,street,street street_name,is_contract,area_manager,area_manager area_manager_name,master_name,master_phone,is_authentication')->select();
} else {
$result = [];
}
$data['lists'] = $result;
return $this->success('success', $data);
}
public function responsible_area()
{
$parmas = $this->request->param();
if (!isset($parmas['key']) && isset($parmas['key']) == '' || !isset($parmas['value']) && isset($parmas['value']) == '') {
return $this->fail('参数错误');
}
if ($parmas['key'] == 'city') {
$where[] = ['area', '=', 0];
}
if ($parmas['value'] == '') {
return $this->fail('参数不能为空');
}
$where[] = [$parmas['key'], '=', $parmas['value']];
switch ($parmas['key']) {
case 'city':
// $geo_area=Db::name('geo_area')->where('city_code', '=', $parmas['value'])->column('area_code');
// $where[] = ['area', 'in', $geo_area];
break;
case 'area':
$street_code = Db::name('geo_street')->where('area_code', '=', $parmas['value'])->column('street_code');
$where[] = ['street', 'in', $street_code];
$where[] = ['village', '=', 0];
break;
case 'street':
$street_code = Db::name('geo_village')->where('street_code', '=', $parmas['value'])->column('village_code');
$where[] = ['village', 'in', $street_code];
$where[] = ['brigade', '=', 0];
break;
case 'village':
// $street_code = Db::name('geo_brigade')->where('street_code', '=', $parmas['value'])->column('village_code');
$where[] = ['village', '=', $parmas['value']];
// $where[] = ['brigade', '=', 0];
break;
}
$res = Company::where($where)->column('responsible_area');
foreach ($res as $k => $v) {
$res[$k] = explode(',', $v);
}
$data = [];
foreach ($res as $k => $v) {
foreach ($v as $kk => $vv) {
if ($vv != '') {
$data[] = $vv;
}
}
}
return $this->success('success', array_unique($data));
}
}