439 lines
18 KiB
PHP
439 lines
18 KiB
PHP
<?php
|
||
|
||
namespace addon\hyctransfer\model;
|
||
|
||
use app\model\BaseModel;
|
||
use think\facade\Log;
|
||
|
||
class ExternalApi extends BaseModel
|
||
{
|
||
public $table = false;
|
||
// 测试环境
|
||
// private $apiLink = 'https://bwmsweb.testpnr.com/bwmsweb';// 生产地址
|
||
// private $accessId = 'CQZL0606202306061047027822700798';// 接入ID
|
||
// private $accessSecret = '0sSEAHC80w3HJ55FLS0akVzIKR0TTH6S';// 请求密钥
|
||
// private $groundAgentId = 'L20221116094640944';// 落地公司机构号
|
||
// private $bmemberId = '942103656627706351';// 落地公司商户号
|
||
// private $coreAgentId = 'C20230109095415231';// 核心企业机构号
|
||
// private $memberId = '637870957126184445';// 核心企业商户号
|
||
// 生产环境
|
||
// private $apiLink = 'https://ms.xs-ygj.com/bwmsweb';// 生产地址
|
||
// private $accessId = 'ZLSS2023101015281525786620371101';// 接入ID
|
||
// private $accessSecret = 'ZGnDgGDSXeusnZjIWwzstRi4JgjwOS9M';// 请求密钥
|
||
// private $groundAgentId = 'L20230921161137004';// 落地公司机构号
|
||
// private $bmemberId = '763071836462340781';// 落地公司商户号
|
||
// private $coreAgentId = 'C20231130092957659';// 核心企业机构号
|
||
// private $memberId = '906487975715084884';// 核心企业商户号
|
||
// 使用
|
||
private $apiLink = 'https://bwmsweb.testpnr.com/bwmsweb', $accessId, $accessSecret, $groundAgentId, $bmemberId, $coreAgentId, $memberId, $site_id, $mer_id;// 核心企业商户号
|
||
|
||
public function __construct($site_id, $mer_id)
|
||
{
|
||
$config = new Config();
|
||
$info = $config->getConfig($site_id)['data']['value'];
|
||
$this->accessId = $info['accessId'];
|
||
$this->accessSecret = $info['accessSecret'];
|
||
$this->groundAgentId = $info['groundAgentId'];
|
||
$this->bmemberId = $info['bmemberId'];
|
||
$this->coreAgentId = $info['coreAgentId'];
|
||
$this->memberId = $info['memberId'];
|
||
$this->site_id = $site_id;
|
||
$this->mer_id = $mer_id;
|
||
//$this->apiLink = config('app.USE_STAFF_API_LINK');
|
||
}
|
||
|
||
/**
|
||
* Common: 发起请求 - 请求接口
|
||
* Author: wu-hui
|
||
* Time: 2023/10/08 15:46
|
||
* @param $api
|
||
* @param $params
|
||
* @return mixed|void
|
||
*/
|
||
private function requestApi($api, $params)
|
||
{
|
||
try {
|
||
// 获取签名
|
||
$sign = $this->getSign($params);
|
||
// 发起请求
|
||
$data = [
|
||
'jsonStr' => json_encode($params, JSON_UNESCAPED_UNICODE),
|
||
'sign' => $sign,
|
||
];
|
||
$header = [
|
||
'Content-Type: application/json; charset=utf-8',
|
||
'Cache-Control: no-cache',
|
||
'Pragma: no-cache'
|
||
];
|
||
$result = curlPost($this->apiLink . $api, $data, 30, $header, 'json');
|
||
$result = json_decode($result, true);
|
||
$result['jsonStr'] = json_decode($result['jsonStr'], true);
|
||
return $result['jsonStr'];
|
||
} catch (\Exception $e) {
|
||
Log::debug('------- 灵活务工 - 接口请求 - 失败原因 -----' . $e->getMessage());
|
||
return $e->getMessage();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Common: 发起请求 - 获取签名
|
||
* Author: wu-hui
|
||
* Time: 2023/10/08 14:41
|
||
* @param $params
|
||
* @return false|string
|
||
*/
|
||
private function getSign($params)
|
||
{
|
||
// 按照 key 的 ASCII 字符串顺序升序排列
|
||
ksort($params);
|
||
// 获取签名字符串
|
||
$signStr = '';
|
||
foreach ($params as $key => $val) {
|
||
$signStr .= is_array($val) ? json_encode($val) : $val;
|
||
}
|
||
// 获取签名
|
||
return hash_hmac("sha256", $signStr, $this->accessSecret);
|
||
}
|
||
|
||
/**
|
||
* Common: 根据方法名称 返回回调地址
|
||
* Author: wu-hui
|
||
* Time: 2023/10/09 11:24
|
||
* @param $funName
|
||
* @return string
|
||
* @throws Exception
|
||
*/
|
||
private function getNotifyUrl($funName)
|
||
{
|
||
$notifyUrl = addon_url('hyctransfer/api/notify/' . $funName, ['site_id' => $this->site_id, 'mer_id' => $this->mer_id]);
|
||
return $notifyUrl;
|
||
}
|
||
|
||
|
||
/**
|
||
* Common: 员工入驻 - 申请入驻
|
||
* Author: wu-hui
|
||
* Time: 2023/10/08 16:58
|
||
* @param $info
|
||
* @return mixed|void
|
||
* @throws Exception
|
||
*/
|
||
public function personnelAccess($info)
|
||
{
|
||
// 基本参数
|
||
$params = [
|
||
'accessId' => $this->accessId,// [必填]接入ID
|
||
'orderId' => date('Ymdis'),// [必填]请求流水号
|
||
'coreAgentId' => $this->coreAgentId,// [必填]核心企业机构号
|
||
'groundAgentId' => $this->groundAgentId,// [必填]落地公司机构号
|
||
'noticeUrl' => $this->getNotifyUrl('access'),// [必填]异步通知地址
|
||
'name' => $info['realname'],// [必填]账户名称
|
||
// 'jobNum' => '',// [选填]工号
|
||
'contactTelNo' => $info['mobile'],// [必填]手机号
|
||
// 'bankProvId' => '510000',// [必填]银行所在省
|
||
// 'bankCityId' => '510100',// [必填]银行所在市
|
||
'cardType' => $info['card_type'] ?? 1,// [必填]卡类型(1-对私/2-对公)
|
||
// 'bankName' => '',// [选填]银行名称
|
||
'bankSubName' => $info['branch_bank_name'] ?? '',// [条件必填]开户银行支行名称,卡类型为2-对公必填
|
||
'accountIdSdate' => date('Ymd', strtotime($info['startTime'])),// [必填]证件有效期开始时间 $info['startTime'],// [必填]证件有效期开始时间
|
||
// 'accountIdEdate' => '20401107',// [选填]证件有效期终止时间,YYYYMMDD或长期
|
||
'bankActName' => $info['realname'],// [必填]卡号姓名
|
||
'cardNum' => $info['bank_account'],// [必填]卡号
|
||
'accountIdNo' => $info['card_id'],// [必填]持卡人证件号
|
||
'accountIdType' => '1',// [选填]证件类型(1.身份证 9.其他类型)不填默认1
|
||
'merType' => $info['mer_type'] ?? 3,// [必填]商户类型 (1-个体户/3-个人)
|
||
// 'merName' => '',// [条件必填]商户注册名称
|
||
// 'merShortName' => '',// [条件必填]商户简称
|
||
// 'provId' => '',// [条件必填]商户经营所在省
|
||
// 'cityId' => '',// [条件必填]商户经营所在市
|
||
// 'areaId' => '',// [条件必填]商户经营所在区县
|
||
// 'merAddress' => '',// [条件必填]商户经营地址
|
||
// 'businessCode' => '',// [条件必填]营业执照号
|
||
// 'businessSdate' => '',// [条件必填]营业执照有效期开始日期
|
||
// 'businessEdate' => '',// [条件必填]营业执照有效期结束日期,YYYYMMDD或长期
|
||
];
|
||
// 发起请求
|
||
$result = $this->requestApi('/api/personnel/personnelAccess', $params);
|
||
if ((int)$result['respCode'] === 0) {
|
||
$param['hycmemberId'] = $result['memberId'];
|
||
$param['trans_seq_id'] = $result['transSeqId'];
|
||
$param['status'] = $result['state'] ?? 0;
|
||
return $this->success($param);
|
||
} else {
|
||
return $this->error($result['respDesc']);
|
||
}
|
||
}
|
||
|
||
public function updatePersonnel($info)
|
||
{
|
||
// 基本参数
|
||
$params = [
|
||
'accessId' => $this->accessId,// [必填]接入ID
|
||
'orderId' => date('Ymdis'),// [必填]请求流水号
|
||
'coreAgentId' => $this->coreAgentId,// [必填]核心企业机构号
|
||
'groundAgentId' => $this->groundAgentId,// [必填]落地公司机构号
|
||
'noticeUrl' => $this->getNotifyUrl('access'),// [必填]异步通知地址
|
||
'name' => $info['realname'],// [必填]账户名称
|
||
// 'jobNum' => '',// [选填]工号
|
||
'contactTelNo' => $info['mobile'],// [必填]手机号
|
||
// 'bankProvId' => '510000',// [必填]银行所在省
|
||
// 'bankCityId' => '510100',// [必填]银行所在市
|
||
'cardType' => $info['card_type'] ?? 1,// [必填]卡类型(1-对私/2-对公)
|
||
// 'bankName' => '',// [选填]银行名称
|
||
'bankSubName' => $info['branch_bank_name'] ?? '',// [条件必填]开户银行支行名称,卡类型为2-对公必填
|
||
'accountIdSdate' => date('Ymd', strtotime($info['startTime'])),// [必填]证件有效期开始时间 $info['startTime'],// [必填]证件有效期开始时间
|
||
// 'accountIdEdate' => '20401107',// [选填]证件有效期终止时间,YYYYMMDD或长期
|
||
'bankActName' => $info['realname'],// [必填]卡号姓名
|
||
'cardNum' => $info['bank_account'],// [必填]卡号
|
||
'accountIdNo' => $info['card_id'],// [必填]持卡人证件号
|
||
'accountIdType' => '1',// [选填]证件类型(1.身份证 9.其他类型)不填默认1
|
||
'merType' => $info['mer_type'] ?? 3,// [必填]商户类型 (1-个体户/3-个人)
|
||
// 'merName' => '',// [条件必填]商户注册名称
|
||
// 'merShortName' => '',// [条件必填]商户简称
|
||
// 'provId' => '',// [条件必填]商户经营所在省
|
||
// 'cityId' => '',// [条件必填]商户经营所在市
|
||
// 'areaId' => '',// [条件必填]商户经营所在区县
|
||
// 'merAddress' => '',// [条件必填]商户经营地址
|
||
// 'businessCode' => '',// [条件必填]营业执照号
|
||
// 'businessSdate' => '',// [条件必填]营业执照有效期开始日期
|
||
// 'businessEdate' => '',// [条件必填]营业执照有效期结束日期,YYYYMMDD或长期
|
||
];
|
||
// 发起请求
|
||
$result = $this->requestApi('/api/personnel/updatePersonnel', $params);
|
||
if ((int)$result['respCode'] === 0) {
|
||
$param['hycmemberId'] = $result['memberId'];
|
||
$param['trans_seq_id'] = $result['transSeqId'];
|
||
$param['status'] = $result['state'] ?? 0;
|
||
return $this->success($param);
|
||
} else {
|
||
return $this->error($result['respDesc']);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Common: 员工入驻 - 入驻结果查询
|
||
* Author: wu-hui
|
||
* Time: 2023/10/08 17:02
|
||
* @param $memberId
|
||
* @param $transSeqId
|
||
* @return mixed|void
|
||
* @throws Exception
|
||
*/
|
||
public function personnelResult($memberId, $transSeqId)
|
||
{
|
||
// 基本参数
|
||
$params = [
|
||
'accessId' => $this->accessId,// [必填]接入ID
|
||
'transSeqId' => $transSeqId,// [选填]系统流水号
|
||
'memberId' => $memberId,// [选填]会员号
|
||
];
|
||
// 发起请求
|
||
$result = $this->requestApi('/api/personnel/queryPersonnel', $params);
|
||
if ((int)$result['respCode'] === 0) {
|
||
|
||
return $this->success($result);
|
||
} else {
|
||
return $this->error($result['respDesc']);
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* Common: 员工签约
|
||
* Author: wu-hui
|
||
* Time: 2023/10/08 17:46
|
||
* @param $uid
|
||
* @return mixed|void
|
||
* @throws Exception
|
||
*/
|
||
public function personalContractCreate($id, $memberId)
|
||
{
|
||
// 获取员工信息
|
||
// 基本参数
|
||
$params = [
|
||
'accessId' => $this->accessId,// [必填]接入ID
|
||
'orderId' => date('Ymdis'),// [必填]请求流水号
|
||
'coreAgentId' => $this->coreAgentId,// [必填]核心企业机构号
|
||
'groundAgentId' => $this->groundAgentId,// [必填]落地公司机构号
|
||
'memberId' => $memberId,// [必填]个人会员号
|
||
'signResultViewUrl' => '',// [选填]签约结果提示显示页面
|
||
];
|
||
// 发起请求
|
||
$result = $this->requestApi('/api/contract/personalContractCreate', $params);
|
||
if ((int)$result['respCode'] === 0) {
|
||
$signState = $result['signState'] ?? 0;
|
||
if ($signState == 1) {
|
||
$signState = 4;
|
||
}
|
||
model('member_bank_account')->update([
|
||
'contractId' => $result['contractId'],
|
||
'status' => $signState,
|
||
], ['id' => $id]);
|
||
$result['downUrl'] = urldecode($result['downUrl']);
|
||
$result['signUrl'] = urldecode($result['signUrl']);
|
||
$result['viewUrl'] = urldecode($result['viewUrl']);
|
||
return $this->success($result);
|
||
} else {
|
||
return $this->error($result['respDesc']);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Common: 员工签约 - 签约结果查询
|
||
* Author: wu-hui
|
||
* Time: 2023/10/08 17:50
|
||
* @param $memberId
|
||
* @return mixed|void
|
||
* @throws Exception
|
||
*/
|
||
public function personalContractQuery($contract_id)
|
||
{
|
||
// 基本参数
|
||
$params = [
|
||
'accessId' => $this->accessId,// [必填]接入ID
|
||
'orderId' => date('Ymdis'),// [必填]请求流水号
|
||
'contractId' => $contract_id,// [必填]核心企业机构号
|
||
];
|
||
// 发起请求
|
||
$result = $this->requestApi('/api/contract/personalContractQuery', $params);
|
||
if ((int)$result['respCode'] === 0) {
|
||
return $this->success($result);
|
||
} else {
|
||
return $this->error($result['respDesc']);
|
||
}
|
||
}
|
||
|
||
|
||
public function queryTax($memberId,$startDate='',$endDate='')
|
||
{
|
||
// 基本参数
|
||
$params = [
|
||
'accessId' => $this->accessId,// [必填]接入ID
|
||
'memberId' => $memberId,// [必填]请求流水号
|
||
'startDate' => $startDate,// [必填]请求流水号yyyymmdd
|
||
'endDate' => $endDate,// [必填]请求流水号
|
||
];
|
||
// 发起请求
|
||
$result = $this->requestApi('/api/taxcertificate/queryTax', $params);
|
||
if ((int)$result['respCode'] === 0) {
|
||
return $this->success($result);
|
||
}else{
|
||
return $this->error($result['respDesc']);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Common: 获取税票
|
||
* Author: wu-hui
|
||
* Time: 2023/10/08 17:50
|
||
* @param $memberId
|
||
* @return mixed|void
|
||
* @throws Exception
|
||
*/
|
||
public function downCertificate($memberId, $taxId)
|
||
{
|
||
// 基本参数
|
||
$params = [
|
||
'accessId' => $this->accessId,// [必填]接入ID
|
||
'memberId' => $memberId,// [必填]请求流水号
|
||
'taxId' => $taxId,// [必填]请求流水号
|
||
];
|
||
// 发起请求
|
||
$result = $this->requestApi('/api/taxcertificate/downCertificate', $params);
|
||
if ((int)$result['respCode'] === 0) {
|
||
return $this->success($result);
|
||
}else{
|
||
return $this->error($result['respDesc']);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Common: 费用代发 - 申请代发
|
||
* Author: wu-hui
|
||
* Time: 2023/10/09 10:15
|
||
* @param $info
|
||
* @return mixed|void
|
||
* @throws Exception
|
||
*/
|
||
public function salaryModelOutOrder($info)
|
||
{
|
||
// 获取员工信息
|
||
$staff = UseStaff::getSingleInfo($info);
|
||
// 基本参数
|
||
$orderNo = createNo('YCH', 6, TRUE);
|
||
$params = [
|
||
'accessId' => $this->accessId,// [必填]接入ID
|
||
'orderId' => $orderNo,// [必填]请求流水号
|
||
'agentId' => $this->coreAgentId,// [必填]核心企业机构号
|
||
'bmemberId' => $this->bmemberId,// [必填]落地公司商户号,落地公司memberId
|
||
'salaryModle' => '2',// [必填]代发模式,1-普票 2-专票
|
||
'accountModle' => '2',// [必填]走账模式,2-代发
|
||
'modeIdcompany' => '1',// [必填]走账类型,1-单账户模式
|
||
'noticeUrl' => $this->getNotifyUrl('notify'),// [必填]异步通知地址
|
||
// [必填]代发费用明细
|
||
'batchSalaryOutOrderModleDtos' => [[
|
||
'memberId' => $staff['member_id'],// [必填]会员号
|
||
'outOrderId' => $orderNo,// [必填]外部订单号
|
||
'salary' => $info['salary'],// [必填]费用金额
|
||
'salaryMonth' => $info['month'],// [必填]月份,格式:YYYYMM
|
||
]],
|
||
];
|
||
// 发起请求
|
||
$result = $this->requestApi('/api/salaryInfo/salaryModleOutOrder', $params);
|
||
if ((int)$result['respCode'] === 2) {
|
||
$time = time();
|
||
// UseStaffSalary::insert([
|
||
// 'uniacid' => \YunShop::app()->uniacid,
|
||
// 'uid' => $info['uid'],
|
||
// 'order_no' => $orderNo,
|
||
// 'member_id' => $staff['member_id'],
|
||
// 'salary' => $info['salary'],
|
||
// 'salary_month' => $info['month'],
|
||
// 'attach_id' => $result['attachId'],
|
||
// 'created_at' => $time,
|
||
// 'updated_at' => $time,
|
||
// ]);
|
||
return $this->success($result);
|
||
} else {
|
||
return $this->error($result['respDesc']);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Common: 费用代发 - 结果查询
|
||
* Author: wu-hui
|
||
* Time: 2023/10/09 10:51
|
||
* @param $attachId
|
||
* @return mixed|void
|
||
* @throws Exception
|
||
*/
|
||
public function salaryOutOrderResult($attachId)
|
||
{
|
||
// 基本参数
|
||
$params = [
|
||
'accessId' => $this->accessId,// [必填]接入ID
|
||
'memberId' => $this->memberId,// [必填]智汇管家代理商会员号
|
||
'attachId' => $attachId,// [条件必填]若订单号未填,则批次号必填
|
||
// 'orderId' => $this->accessId,// [条件必填]若批次号未填,则订单号必填
|
||
];
|
||
// 发起请求
|
||
$result = $this->requestApi('/api/queryresult/salaryOutOrderResult', $params);
|
||
if ((int)$result['respCode'] === 0) {
|
||
// $salaryOutOrderRespDto = $result['salaryOutOrderRespDto'];
|
||
// $first = collect($salaryOutOrderRespDto)->first();
|
||
// UseStaffSalary::where('attach_id', $attachId)
|
||
// ->update([
|
||
// 'attach_state' => $result['attachState'],
|
||
// 'order_amt' => $first['orderAmt'],
|
||
// 'real_trans_amt' => $first['realTransAmt'],
|
||
// 'out_member_id' => $first['outMemberId'],
|
||
// 'salary_state' => $first['salaryState'],
|
||
// 'trans_fee' => $first['transFee'],
|
||
// ]);
|
||
return $this->success($result);
|
||
} else {
|
||
return $this->error($result['respDesc']);
|
||
}
|
||
}
|
||
}
|