TaskSystem/app/adminapi/controller/CompanyController.php
2023-07-21 08:57:46 +08:00

260 lines
10 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\controller\BaseAdminController;
use app\adminapi\lists\CompanyLists;
use app\adminapi\logic\CompanyLogic;
use app\adminapi\validate\CompanyValidate;
use app\api\controller\JunziqianController;
use app\api\logic\SmsLogic;
use app\common\model\auth\Admin;
use app\common\model\Company;
use think\facade\Db;
use think\view\driver\Think;
/**
* 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());
}
/**
* @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']);
$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']);
$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');
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 Draftingcontracts()
{
$params = (new CompanyValidate())->goCheck('detail');
$result = CompanyLogic::detail($params);
if ($result && $result['contract'] && $result['contract']['file'] != '') {
$data = [
'name' => $result['company_name'] . '合同',
'signatories' => [['fullName' => $result['company_name'], 'identityType' => 12, 'identityCard' => $result['organization_code'], 'mobile' => $result['master_phone'], 'email' => $result['master_email'], 'noNeedVerify' => 1, 'signLevel' => 1]],
'url' => $result['contract']['file']
];
$res = app(JunziqianController::class)->Signing($data);
if ($res->success == true) {
Db::name('contract')->where('id', $result['contract']['id'])->update(['contract_no' => $res->data]);
$company = Db::name('company')->where('id', $params['id'])->find();
if ($company) {
$find = Db::name('contract')->where('party_b', $company['id'])
->withAttr('contract_type_name', function ($value, $data) {
return Db::name('dict_data')->where('id', $data['contract_type'])->value('name');
})->find();
if ($find) {
$data = array(
"applyNo" => $find['contract_no'], //TODO *
"fullName" => $company['company_name'], //TODO *
"identityCard" => $company['organization_code'], //TODO *
"identityType" => 12, //TODO *
);
$res = app(JunziqianController::class)->SigningLink($data);
if ($res->success == true) {
Db::name('contract')->where('id', $find['id'])->update(['url' => $res->data]);
//发送短信
$sms = [
'mobile' => $company['master_phone'],
'name' => $company['company_name'],
'type' => '《' . $find['contract_type_name'] . '》',
'code' => 'api/Hetong/url?id='.$find['id'],
'scene' => 'WQ'
];
$result = SmsLogic::contractUrl($sms);
if (true === $result) {
return $this->success('发送成功');
} else {
return $this->fail(SmsLogic::getError());
}
} else {
return $this->fail($res->msg);
}
}
}
return $this->success('生成合同成功', [], 1, 1);
} else {
return $this->fail($res->msg);
}
} else {
return $this->fail('生成合同成功失败,联系管理员');
}
}
//**发送短信 */
public function postsms()
{
$params = (new CompanyValidate())->goCheck('detail');
$company = Db::name('company')->where('id', $params['id'])->find();
if ($company) {
$find = Db::name('contract')->where('party_b', $company['id'])
->withAttr('contract_type_name', function ($value, $data) {
return Db::name('dict_data')->where('id', $data['contract_type'])->value('name');
})
->find();
if ($find) {
//发送短信
$sms = [
'mobile' => $company['master_phone'],
'name' => $company['company_name'],
'type' => '《' . $find['contract_type_name'] . '》',
'code' => 'api/Hetong/url?id='.$find['id'],
'scene' => 'WQ'
];
$result = SmsLogic::contractUrl($sms);
if (true === $result) {
return $this->success('发送成功');
} else {
return $this->fail(SmsLogic::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'],
];
$res = app(JunziqianController::class)->EnterpriseCertification($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 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('重新认证成功', ['em'], 1, 1);
} else {
return $this->fail($res->msg);
}
}
}
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, 1, 1);
}
}