2023-08-07 15:13:34 +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\common\logic\contract;
|
|
|
|
|
|
2023-08-07 16:28:09 +08:00
|
|
|
|
use app\api\controller\JunziqianController;
|
2023-08-07 15:13:34 +08:00
|
|
|
|
use app\common\model\contract\Contract;
|
|
|
|
|
use app\common\logic\BaseLogic;
|
|
|
|
|
use app\common\model\Company;
|
|
|
|
|
use app\common\model\user\User;
|
|
|
|
|
use think\facade\Db;
|
|
|
|
|
use app\api\logic\SmsLogic;
|
|
|
|
|
use app\common\logic\CompanyLogic;
|
|
|
|
|
use app\common\logic\UserLogic;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Contract逻辑
|
|
|
|
|
* Class ContractLogic
|
|
|
|
|
* @package app\adminapi\logic\contract
|
|
|
|
|
*/
|
|
|
|
|
class ContractLogic extends BaseLogic
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 添加
|
|
|
|
|
* @param array $params
|
|
|
|
|
* @return bool
|
|
|
|
|
* @author likeadmin
|
|
|
|
|
* @date 2023/07/18 14:28
|
|
|
|
|
*/
|
|
|
|
|
public static function add(array $params): bool
|
|
|
|
|
{
|
|
|
|
|
Db::startTrans();
|
|
|
|
|
try {
|
|
|
|
|
Contract::create([
|
|
|
|
|
'company_id' => $params['company_id'],
|
|
|
|
|
'contract_type' => $params['contract_type'],
|
|
|
|
|
'contract_no' => $params['contract_no'],
|
|
|
|
|
'file' => $params['file'],
|
|
|
|
|
'status' => $params['status'],
|
|
|
|
|
'party_a' => $params['party_a'],
|
|
|
|
|
'party_b' => $params['party_b'],
|
|
|
|
|
'area_manager' => $params['area_manager']
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
Db::commit();
|
|
|
|
|
return true;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
Db::rollback();
|
|
|
|
|
self::setError($e->getMessage());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 编辑
|
|
|
|
|
* @param array $params
|
|
|
|
|
* @return bool
|
|
|
|
|
* @author likeadmin
|
|
|
|
|
* @date 2023/07/18 14:28
|
|
|
|
|
*/
|
|
|
|
|
public static function edit(array $params): bool
|
|
|
|
|
{
|
|
|
|
|
Db::startTrans();
|
|
|
|
|
try {
|
|
|
|
|
Contract::where('id', $params['id'])->update([
|
|
|
|
|
'company_id' => $params['company_id'],
|
|
|
|
|
'contract_type' => $params['contract_type'],
|
|
|
|
|
'contract_no' => $params['contract_no'],
|
|
|
|
|
'file' => $params['file'],
|
|
|
|
|
'status' => $params['status'],
|
|
|
|
|
'party_a' => $params['party_a'],
|
|
|
|
|
'party_b' => $params['party_b'],
|
|
|
|
|
'area_manager' => $params['area_manager']
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
Db::commit();
|
|
|
|
|
return true;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
Db::rollback();
|
|
|
|
|
self::setError($e->getMessage());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 删除
|
|
|
|
|
* @param array $params
|
|
|
|
|
* @return bool
|
|
|
|
|
* @author likeadmin
|
|
|
|
|
* @date 2023/07/18 14:28
|
|
|
|
|
*/
|
|
|
|
|
public static function delete(array $params): bool
|
|
|
|
|
{
|
|
|
|
|
return Contract::destroy($params['id']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 获取详情
|
|
|
|
|
* @param $params
|
|
|
|
|
* @return array
|
|
|
|
|
* @author likeadmin
|
|
|
|
|
* @date 2023/07/18 14:28
|
|
|
|
|
*/
|
2023-08-07 16:28:09 +08:00
|
|
|
|
public static function detail($params)
|
2023-08-07 15:13:34 +08:00
|
|
|
|
{
|
|
|
|
|
$data = Db::name('contract')->where('id', $params['id'])
|
|
|
|
|
->withAttr('party_b_info', function ($value, $data) {
|
|
|
|
|
if ($data['type'] == 1) {
|
|
|
|
|
$field = ['id,company_name,company_type,company_type company_type_name,organization_code,
|
2023-08-07 16:28:09 +08:00
|
|
|
|
province,city,area,street,village,brigade,address,province province_name,city city_name,area area_name,street street_name,village village_name,brigade brigade_name,master_phone,
|
2023-08-07 15:13:34 +08:00
|
|
|
|
qualification'];
|
|
|
|
|
$company = Company::where(['id' => $data['party_b']])->field($field)->find();
|
|
|
|
|
$company['qualification'] = json_decode($company['qualification'], true);
|
|
|
|
|
return $company;
|
|
|
|
|
} else {
|
2023-08-07 18:46:50 +08:00
|
|
|
|
$filed = ['id,id_card,avatar,nickname,sex,mobile,
|
2023-08-07 15:13:34 +08:00
|
|
|
|
province,city,area,street,village,brigade,address,province province_name,city city_name,area area_name,street street_name,village village_name,brigade brigade_name,
|
|
|
|
|
qualification'];
|
|
|
|
|
$user = User::where('id', $data['party_b'])->field($filed)->find();
|
|
|
|
|
$user['qualification'] = json_decode($user['qualification'], true);
|
|
|
|
|
return $user;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
->withAttr('party_a_info', function ($value, $data) {
|
|
|
|
|
$field = ['id,company_name,company_type,company_type company_type_name,organization_code,
|
2023-08-07 16:28:09 +08:00
|
|
|
|
province,city,area,street,village,brigade,address,province province_name,city city_name,area area_name,street street_name,village village_name,brigade brigade_name,master_phone,
|
2023-08-07 15:13:34 +08:00
|
|
|
|
qualification'];
|
|
|
|
|
$company = Company::where(['id' => $data['party_a']])->field($field)->find();
|
|
|
|
|
$company['qualification'] = json_decode($company['qualification'], true);
|
|
|
|
|
return $company;
|
|
|
|
|
})
|
|
|
|
|
->withAttr('area_manager_name', function ($value, $data) {
|
|
|
|
|
return Db::name('admin')->where('id', $data['area_manager'])->value('name');
|
|
|
|
|
})
|
|
|
|
|
->withAttr('contract_type_name', function ($value, $data) {
|
|
|
|
|
return Db::name('dict_data')->where('id', $data['contract_type'])->value('name');
|
|
|
|
|
})
|
|
|
|
|
->withAttr('type_name', function ($value, $data) {
|
|
|
|
|
return $data['type'] == 1 ? '公司' : '个人';
|
|
|
|
|
})
|
|
|
|
|
->withAttr('status_name', function ($value, $data) {
|
|
|
|
|
return $data['status'] == 1 ? '已签约' : '未签约';
|
|
|
|
|
})
|
|
|
|
|
->find();
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//生成合同
|
|
|
|
|
public static function Initiate_contract($data)
|
|
|
|
|
{
|
|
|
|
|
$model = Contract::where(['party_b' => $data['party_b']])->find();
|
|
|
|
|
if (empty($model)) {
|
|
|
|
|
$model = new Contract();
|
|
|
|
|
$model->contract_no = time();
|
|
|
|
|
$model->create_time = time();
|
|
|
|
|
}
|
2023-08-07 18:18:17 +08:00
|
|
|
|
$model->check_status = 1;
|
2023-08-07 15:13:34 +08:00
|
|
|
|
$model->update_time = time();
|
|
|
|
|
$model->setAttrs($data);
|
|
|
|
|
return $model->save($data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// /**发送合同 */
|
|
|
|
|
public static function Draftingcontracts($params,$type=1)
|
|
|
|
|
{
|
|
|
|
|
if($type==1){
|
|
|
|
|
$result = CompanyLogic::detail($params);
|
|
|
|
|
}else{
|
|
|
|
|
$result = UserLogic::detail($params['id']);
|
|
|
|
|
}
|
|
|
|
|
if ($result && isset($result['contract']) && isset($result['contract']['file']) && $result['contract']['file'] != '') {
|
2023-08-07 16:38:56 +08:00
|
|
|
|
if ($result['contract']['check_status'] == 3) {
|
|
|
|
|
return self::setError('你已经生成过合同,请问重复生成');
|
|
|
|
|
}
|
2023-08-07 16:28:09 +08:00
|
|
|
|
if($type==1){
|
|
|
|
|
$name=$result['company_name'];
|
|
|
|
|
$data = [
|
|
|
|
|
'name' => $name . '的合同',
|
|
|
|
|
'signatories' => [
|
|
|
|
|
['fullName' => $name, 'identityType' => 12, 'identityCard' => $result['organization_code'], 'email' => $result['master_email'], 'noNeedVerify' => 1, 'signLevel' => 1],
|
|
|
|
|
['fullName' => $result['contract']['party_a_info']['company_name'], 'identityType' => 12, 'identityCard' => $result['contract']['party_a_info']['organization_code'], 'email' => $result['contract']['party_a_info']['master_email'], 'noNeedVerify' => 1, 'signLevel' => 1]
|
|
|
|
|
],
|
|
|
|
|
'url' => $result['contract']['file']
|
|
|
|
|
];
|
|
|
|
|
}else{
|
|
|
|
|
$name=$result['nickname'];
|
|
|
|
|
$data = [
|
|
|
|
|
'name' => $name . '的合同',
|
|
|
|
|
'signatories' => [
|
|
|
|
|
['fullName' => $name, 'identityType' => 1, 'identityCard' => $result['id_card'], 'mobile' => $result['mobile'], 'noNeedVerify' => 1, 'signLevel' => 1],
|
|
|
|
|
['fullName' => $result['contract']['party_a_info']['company_name'], 'identityType' => 12, 'identityCard' => $result['contract']['party_a_info']['organization_code'], 'email' => $result['contract']['party_a_info']['master_email'], 'noNeedVerify' => 1, 'signLevel' => 1]
|
|
|
|
|
],
|
|
|
|
|
'url' => $result['contract']['file']
|
|
|
|
|
];
|
2023-08-07 15:13:34 +08:00
|
|
|
|
}
|
|
|
|
|
$res = app(JunziqianController::class)->Signing($data, $result['contract']['id']);
|
|
|
|
|
if ($res->success == true) {
|
|
|
|
|
Db::name('contract')->where('id', $result['contract']['id'])->update(['contract_no' => $res->data, 'check_status' => 3]);
|
2023-08-07 16:28:09 +08:00
|
|
|
|
self::postsms(['id'=>$result['contract']['id']]);
|
2023-08-07 15:13:34 +08:00
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return self::setError($res->msg);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return self::setError('生成合同成功失败,联系管理员');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//**发送短信 */
|
|
|
|
|
public static function postsms($params)
|
|
|
|
|
{
|
|
|
|
|
$result = self::detail($params);
|
2023-08-07 16:28:09 +08:00
|
|
|
|
if ($result && $result['file'] != '') {
|
2023-08-07 15:13:34 +08:00
|
|
|
|
//发送短信
|
|
|
|
|
$data = [
|
|
|
|
|
[
|
|
|
|
|
"applyNo" => $result['contract_no'], //TODO *
|
2023-08-07 16:28:09 +08:00
|
|
|
|
"fullName" => $result['party_a_info']['company_name'], //TODO *
|
|
|
|
|
"identityCard" => $result['party_a_info']['organization_code'], //TODO *
|
2023-08-07 15:13:34 +08:00
|
|
|
|
"identityType" => 12, //TODO *
|
2023-08-07 16:28:09 +08:00
|
|
|
|
"master_phone" => $result['party_a_info']['master_phone'],
|
|
|
|
|
"type"=>"party_a"
|
2023-08-07 15:13:34 +08:00
|
|
|
|
],
|
2023-08-07 16:28:09 +08:00
|
|
|
|
];
|
|
|
|
|
if($result['type']==1){
|
|
|
|
|
$data[]= [
|
2023-08-07 15:13:34 +08:00
|
|
|
|
"applyNo" => $result['contract_no'], //TODO *
|
2023-08-07 16:28:09 +08:00
|
|
|
|
"fullName" => $result['party_b_info']['company_name'], //TODO *
|
|
|
|
|
"identityCard" => $result['party_b_info']['organization_code'], //TODO *
|
2023-08-07 15:13:34 +08:00
|
|
|
|
"identityType" => 12, //TODO *
|
2023-08-07 16:28:09 +08:00
|
|
|
|
"master_phone" => $result['party_b_info']['master_phone'],
|
|
|
|
|
"type"=>"party_b"
|
|
|
|
|
|
|
|
|
|
];
|
|
|
|
|
}else{
|
|
|
|
|
$data[]= [
|
|
|
|
|
"applyNo" => $result['contract_no'], //TODO *
|
|
|
|
|
"fullName" => $result['party_b_info']['nickname'], //TODO *
|
|
|
|
|
"identityCard" => $result['party_b_info']['id_card'], //TODO *
|
|
|
|
|
"identityType" => 1, //TODO *
|
|
|
|
|
"master_phone" => $result['party_b_info']['mobile'],
|
|
|
|
|
"type"=>"party_b"
|
|
|
|
|
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$find = Db::name('contract')->where('id', $params['id'])
|
2023-08-07 15:13:34 +08:00
|
|
|
|
->withAttr('contract_type_name', function ($value, $data) {
|
|
|
|
|
return Db::name('dict_data')->where('id', $data['contract_type'])->value('name');
|
|
|
|
|
})->find();
|
2023-08-07 16:28:09 +08:00
|
|
|
|
|
|
|
|
|
$url = [];
|
2023-08-07 15:13:34 +08:00
|
|
|
|
foreach ($data as $k => $v) {
|
2023-08-07 16:28:09 +08:00
|
|
|
|
$res = app(JunziqianController::class)->SigningLink($v);
|
2023-08-07 15:13:34 +08:00
|
|
|
|
if ($res->success == true) {
|
|
|
|
|
if ($v['type'] == 'party_a') {
|
|
|
|
|
$url['party_a'] =$res->data;
|
|
|
|
|
} else {
|
|
|
|
|
$url['party_b'] =$res->data;
|
|
|
|
|
}
|
|
|
|
|
//发送短信
|
|
|
|
|
$sms = [
|
|
|
|
|
'mobile' => $v['master_phone'],
|
|
|
|
|
'name' => $v['fullName'],
|
|
|
|
|
'type' => '《' . $find['contract_type_name'] . '》',
|
|
|
|
|
'code' => 'api/Hetong/url?id=' . $find['id'].'&type='.$v['type'],
|
|
|
|
|
'scene' => 'WQ'
|
|
|
|
|
];
|
|
|
|
|
$result = SmsLogic::contractUrl($sms);
|
|
|
|
|
if ($result != true) {
|
|
|
|
|
return self::setError(SmsLogic::getError());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return self::setError($res->msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-07 16:28:09 +08:00
|
|
|
|
Db::name('contract')->where('id', $find['id'])->update(['url' => json_encode($url)]);
|
2023-08-07 15:13:34 +08:00
|
|
|
|
}else{
|
|
|
|
|
return self::setError('没找到合同,联系管理员');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|