init: import production code mss.nahaichuan.com (exclude Runtime/Uploads/backups/logs)
这个提交包含在:
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
|
||||
namespace Common\Business;
|
||||
|
||||
use LittleGift\Business\LittleGift;
|
||||
use Retail\Model\ThirdConfigModel;
|
||||
use Super\Model\ThirdErpSetModel;
|
||||
//[1.8.50]
|
||||
/**
|
||||
* 第三方平台类
|
||||
* Class Third
|
||||
*[
|
||||
* 微礼平台门店编码验证 storeCodeVerify
|
||||
* 获取请求必传参数token与接口链接 getMust
|
||||
* 微礼平台访问接口所需参数 littleGiftConfig
|
||||
* 获取请求接口列表 getUrl
|
||||
*]
|
||||
* @package Common\Business
|
||||
*/
|
||||
class Third
|
||||
{
|
||||
/**
|
||||
* 门店编码验证
|
||||
* @param $param
|
||||
* [
|
||||
* merchant_id
|
||||
* platform_type 2微礼平台
|
||||
* 微礼平台littlegift->type 1登录 2门店编码验证
|
||||
* third_code 门店编码
|
||||
* ]
|
||||
* @return mixed
|
||||
*/
|
||||
public function storeCodeVerify($param)
|
||||
{
|
||||
$result = $this->getMust($param); //获取所需参数
|
||||
if ($result['status'] != 1) {
|
||||
return $result;
|
||||
}
|
||||
$token = $result['data']['token']; //token
|
||||
$url = $result['data']['url']; //接口链接
|
||||
$third_domain_url = $result['data']['third_domain_url']; //域名
|
||||
$LittleClass = new LittleGift([
|
||||
'domain_url' => $third_domain_url,
|
||||
'cookie' => $token
|
||||
]);
|
||||
$result = $LittleClass->checkCode($param['third_code'], $url);
|
||||
if (!empty($result['error']) || empty($result['id']) || !$result['result']) {
|
||||
return callBack(statusCode()['error'], $result['error']['message']);
|
||||
} else {
|
||||
return callBack(statusCode()['success'], '验证成功');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取请求必传参数token与接口链接
|
||||
* @param $param
|
||||
* [
|
||||
* merchant_id
|
||||
* platform_type 2微礼平台
|
||||
* 微礼平台littlegift->type 1登录 2门店编码验证 3商品编码验证 4会员手机号验证
|
||||
* ]
|
||||
* @return mixed
|
||||
* [
|
||||
* status 0失败 1成功 2无需请求
|
||||
* token
|
||||
* third_domain_url
|
||||
* url
|
||||
* ]
|
||||
*/
|
||||
public function getMust($param)
|
||||
{
|
||||
//获取token
|
||||
$tokenResult = $this->littleGiftConfig($param);
|
||||
if ($tokenResult['status'] != 1) {
|
||||
return $tokenResult;
|
||||
}
|
||||
switch ($param['platform_type']) {
|
||||
case 2:
|
||||
$identification = 'littlegift';
|
||||
break;
|
||||
}
|
||||
//接口链接
|
||||
$urlResult = $this->getUrl([
|
||||
'merchant_id' => $param['merchant_id'],
|
||||
'type' => $param['type'],
|
||||
'identification' => $identification
|
||||
]);
|
||||
if ($urlResult['status'] != 1) {
|
||||
return $urlResult;
|
||||
}
|
||||
if (empty($urlResult['data'])) {
|
||||
return callBack(2, '无需请求');
|
||||
}
|
||||
$data = [
|
||||
'token' => $tokenResult['data']['token'],
|
||||
'third_domain_url' => $tokenResult['data']['third_domain_url'],
|
||||
'url' => $urlResult['data']
|
||||
];
|
||||
return callBack(statusCode()['success'], '查询成功', $data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 微礼平台访问接口所需参数
|
||||
* @param $param
|
||||
* [
|
||||
* merchant_id
|
||||
* platform_type 2微礼平台
|
||||
* ]
|
||||
* @return mixed
|
||||
* [
|
||||
* token 20分钟必须更新一次
|
||||
* ]
|
||||
*/
|
||||
public function littleGiftConfig($param)
|
||||
{
|
||||
if (empty($param['merchant_id'])) {
|
||||
return callBack(statusCode()['error'], '缺少唯一标识');
|
||||
}
|
||||
$where = [
|
||||
'merchant_id' => $param['merchant_id'],
|
||||
'platform_type' => $param['platform_type']
|
||||
];
|
||||
try {
|
||||
$ThirdConfigModel = new ThirdConfigModel();
|
||||
$info = $ThirdConfigModel->getFind($where, 'third_domain_url,third_account_number,third_password,token,third_update_time');
|
||||
if (empty($info)) {
|
||||
return callBack(2, '无需请求', []);
|
||||
}
|
||||
$time = time();
|
||||
//时间比较
|
||||
if ($info['third_update_time'] + (60 * 18) <= $time) {
|
||||
//已过期
|
||||
switch ($param['platform_type']) {
|
||||
case 2:
|
||||
$identification = 'littlegift';
|
||||
break;
|
||||
}
|
||||
$result = $this->getUrl([
|
||||
'merchant_id' => $param['merchant_id'],
|
||||
'type' => 1,
|
||||
'identification' => $identification
|
||||
]);
|
||||
if ($result['status'] != 1) {
|
||||
return callBack(statusCode()['error'], '暂无登录接口权限');
|
||||
}
|
||||
if (empty($result['data'])) {
|
||||
return callBack(2, '无需请求');
|
||||
}
|
||||
$LittleClass = new LittleGift([
|
||||
'domain_url' => $info['third_domain_url'],
|
||||
]);
|
||||
$result = $LittleClass->login([
|
||||
'method' => $result['data'],
|
||||
'account_number' => $info['third_account_number'],
|
||||
'password' => $info['third_password']
|
||||
]);
|
||||
if ($result['status'] != 1) {
|
||||
return callBack(statusCode()['error'], '获取失败' . $result['error']['message']);
|
||||
}
|
||||
$ThirdConfigModel->updateOrder([
|
||||
'merchant_id' => $param['merchant_id'],
|
||||
'platform_type' => 2
|
||||
], [
|
||||
'token' => $result['token'],
|
||||
'third_update_time' => $time
|
||||
]);
|
||||
$data = [
|
||||
'token' => $result['token'],
|
||||
'third_domain_url' => $info['third_domain_url']
|
||||
];
|
||||
} else {
|
||||
$data = [
|
||||
'token' => $info['token'],
|
||||
'third_domain_url' => $info['third_domain_url']
|
||||
];
|
||||
}
|
||||
return callBack(statusCode()['success'], '查询成功', $data);
|
||||
} catch (\Exception $e) {
|
||||
return callBack(statusCode()['error'], '查询失败', []);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取请求接口列表
|
||||
* @param $param
|
||||
* [
|
||||
* merchant_id
|
||||
* type 1登录
|
||||
* identification 插件标识
|
||||
* ]
|
||||
* @return mixed
|
||||
*/
|
||||
public function getUrl($param)
|
||||
{
|
||||
$where = [
|
||||
't.status' => 1,
|
||||
't.type' => $param['type'],
|
||||
't.identification' => $param['identification'],
|
||||
'm.status' => 1,
|
||||
'm.merchant_id' => $param['merchant_id']
|
||||
];
|
||||
try {
|
||||
$ThirdSetModel = new ThirdErpSetModel();
|
||||
$url = $ThirdSetModel->ThirdSetInfo($where, 't.route_url');
|
||||
return callBack(statusCode()['success'], '查询成功', $url);
|
||||
} catch (\Exception $e) {
|
||||
return callBack(statusCode()['error'], '查询失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户