TaskSystem/app/adminapi/controller/CompanyController.php

254 lines
10 KiB
PHP
Raw Normal View History

2023-07-15 14:46:25 +08:00
<?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;
2023-07-18 18:05:58 +08:00
use think\facade\Request;
use app\api\controller\JunziqianController;
2023-07-19 12:42:57 +08:00
use app\api\logic\SmsLogic;
use Cls\Log;
2023-07-19 17:42:15 +08:00
use com\junziqian\sdk\util\RequestUtils;
2023-07-18 18:05:58 +08:00
use think\App;
use think\facade\Db;
2023-07-19 12:42:57 +08:00
use think\facade\Log as FacadeLog;
use think\Log as ThinkLog;
2023-07-18 18:05:58 +08:00
use think\view\driver\Think;
2023-07-15 14:46:25 +08:00
/**
* 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');
2023-07-18 18:05:58 +08:00
$params['other_contacts'] = json_encode($params['other_contacts']);
$params['qualification'] = json_encode($params['qualification']);
2023-07-15 14:46:25 +08:00
$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');
2023-07-18 18:05:58 +08:00
$params['other_contacts'] = json_encode($params['other_contacts']);
$params['qualification'] = json_encode($params['qualification']);
2023-07-15 14:46:25 +08:00
$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);
}
2023-07-19 12:42:57 +08:00
// /**生成合同 */iHMb7rVj@service.ebaoquan.org
2023-07-18 18:05:58 +08:00
public function Draftingcontracts()
{
$params = (new CompanyValidate())->goCheck('detail');
$result = CompanyLogic::detail($params);
if ($result && $result['contract'] && $result['contract']['contract_type_two_url'] != '') {
$data = [
2023-07-19 17:42:15 +08:00
'name' => $result['company_name'] . '合同',
2023-07-19 12:42:57 +08:00
'signatories' => [['fullName' => $result['company_name'], 'identityType' => 12, 'identityCard' => $result['organization_code'], 'mobile' => $result['master_phone'], 'email' => $result['master_email'], 'noNeedVerify' => 1, 'signLevel' => 1]],
2023-07-18 18:05:58 +08:00
'url' => $result['contract']['contract_type_two_url']
];
$res = app(JunziqianController::class)->Signing($data);
if ($res->success == true) {
Db::name('contract')->where('id', $result['contract']['id'])->update(['contract_no' => $res->data]);
2023-07-19 12:42:57 +08:00
$company = Db::name('company')->where('id', $params['id'])->find();
if ($company && $company['contract_id']) {
2023-07-19 17:42:15 +08:00
$find = Db::name('contract')->where('id', $company['contract_id'])
->withAttr('contract_type_two_name', function ($value, $data) {
return Db::name('dict_data')->where('id', $data['contract_type_two'])->value('name');
})->find();
2023-07-19 12:42:57 +08:00
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', $company['contract_id'])->update(['url' => $res->data]);
2023-07-19 17:42:15 +08:00
$url = explode('https://h5.sandbox.junziqian.com/', $res->data);
2023-07-19 12:42:57 +08:00
//发送短信
2023-07-19 17:42:15 +08:00
$sms = [
'mobile' => $company['master_phone'],
'name' => $company['company_name'],
'type' => '《' . $find['contract_type_two_name'] . '》',
'code' => $url[1],
'scene' => 'WQ'
2023-07-19 12:42:57 +08:00
];
$result = SmsLogic::contractUrl($sms);
if (true === $result) {
return $this->success('发送成功');
2023-07-19 17:42:15 +08:00
} else {
2023-07-19 12:42:57 +08:00
return $this->fail(SmsLogic::getError());
}
} else {
return $this->fail($res->msg);
}
}
}
return $this->success('生成合同成功', [], 1, 1);
2023-07-18 18:05:58 +08:00
} else {
return $this->fail($res->msg);
}
} else {
2023-07-19 12:42:57 +08:00
return $this->fail('生成合同成功失败,联系管理员');
2023-07-18 18:05:58 +08:00
}
}
2023-07-19 12:42:57 +08:00
//**发送短信 */
2023-07-18 18:05:58 +08:00
public function postsms()
{
$params = (new CompanyValidate())->goCheck('detail');
$company = Db::name('company')->where('id', $params['id'])->find();
if ($company && $company['contract_id']) {
2023-07-19 17:42:15 +08:00
$find = Db::name('contract')->where('id', $company['contract_id'])
->withAttr('contract_type_two_name', function ($value, $data) {
return Db::name('dict_data')->where('id', $data['contract_type_two'])->value('name');
})
->find();
2023-07-18 18:05:58 +08:00
if ($find) {
$data = array(
"applyNo" => $find['contract_no'], //TODO *
2023-07-19 12:42:57 +08:00
"fullName" => $company['company_name'], //TODO *
2023-07-18 18:05:58 +08:00
"identityCard" => $company['organization_code'], //TODO *
"identityType" => 12, //TODO *
);
2023-07-19 17:42:15 +08:00
$res = app(JunziqianController::class)->sms($data);
if($res->success == true){
return $this->success('发送成功');
}else{
2023-07-18 18:05:58 +08:00
return $this->fail($res->msg);
}
}
}
}
2023-07-19 12:42:57 +08:00
//企业认证
2023-07-19 17:42:15 +08:00
public function authentication()
{
2023-07-19 12:42:57 +08:00
$params = (new CompanyValidate())->goCheck('detail');
$company = Db::name('company')->where('id', $params['id'])->find();
2023-07-19 17:42:15 +08:00
$qualification = json_decode($company['qualification'], true);
2023-07-19 12:42:57 +08:00
if ($company && $qualification['business_license']) {
2023-07-19 17:42:15 +08:00
$data = [
2023-07-19 12:42:57 +08:00
'name' => $company['company_name'],
'organization_code' => $company['organization_code'],
2023-07-19 17:42:15 +08:00
'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'],
2023-07-19 12:42:57 +08:00
];
$res = app(JunziqianController::class)->EnterpriseCertification($data);
if ($res->success == true) {
Db::name('company')->where('id', $params['id'])->update(['master_email' => $res->data]);
2023-07-19 17:42:15 +08:00
return $this->success('认证成功', ['email' => $res->data], 1, 1);
2023-07-19 12:42:57 +08:00
} else {
return $this->fail($res->msg);
}
}
}
//重新认证
2023-07-19 17:42:15 +08:00
public function organizationReapply()
{
2023-07-19 12:42:57 +08:00
$params = (new CompanyValidate())->goCheck('detail');
$company = Db::name('company')->where('id', $params['id'])->find();
2023-07-19 17:42:15 +08:00
$qualification = json_decode($company['qualification'], true);
2023-07-19 12:42:57 +08:00
if ($company && $qualification['business_license']) {
2023-07-19 17:42:15 +08:00
$data = [
2023-07-19 12:42:57 +08:00
'name' => $company['company_name'],
'organization_code' => $company['organization_code'],
2023-07-19 17:42:15 +08:00
'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'],
2023-07-19 12:42:57 +08:00
];
$res = app(JunziqianController::class)->organizationReapply($data);
if ($res->success == true) {
Db::name('company')->where('id', $params['id'])->update(['master_email' => $res->data]);
2023-07-19 17:42:15 +08:00
return $this->success('重新认证成功', ['em'], 1, 1);
2023-07-19 12:42:57 +08:00
} else {
return $this->fail($res->msg);
}
}
}
2023-07-18 18:05:58 +08:00
}