159 lines
6.1 KiB
PHP
159 lines
6.1 KiB
PHP
<?php
|
|
declare (strict_types=1);
|
|
|
|
namespace app\home\controller;
|
|
|
|
use api\Httpcurl;
|
|
use app\BaseController;
|
|
use think\facade\Config;
|
|
use think\facade\Cookie;
|
|
use think\facade\Lang;
|
|
use think\facade\Log;
|
|
use think\facade\Request;
|
|
use think\facade\Session;
|
|
use think\facade\View;
|
|
|
|
/**
|
|
* 控制器基础类
|
|
*/
|
|
class Base extends BaseController
|
|
{
|
|
protected $_userId;
|
|
/**
|
|
* 构造方法
|
|
*/
|
|
public function initialize()
|
|
{
|
|
parent::initialize();
|
|
$source = Request::instance()->param('source', '');
|
|
if (!empty($source)) {
|
|
Session::set('source', $source);
|
|
} else {
|
|
$source = Session::get('source');
|
|
if (empty($source)) {
|
|
Session::set('source', $_SERVER['HTTP_HOST']);
|
|
} else {
|
|
Session::set('source', $source);
|
|
}
|
|
}
|
|
// 获取 当前用户ID
|
|
$this->_userId = cmf_get_current_user_id();
|
|
// 网站配置信息获取
|
|
if (!file_exists(app()->getRootPath().'data/config.json')) {
|
|
$domain = $_SERVER['HTTP_HOST'];
|
|
$domain ='evisa.hkpgsow.cn';
|
|
$web_config = Httpcurl::request(GET_WEB_CONFIG_URL . MODEL . '/domain/' . $domain, 'get');
|
|
if ($web_config[3]) {
|
|
abort(500, '网站配置信息获取失败');
|
|
}
|
|
$config_result = json_decode($web_config[0], true);
|
|
if (empty($config_result)) {
|
|
abort(500, '网站配置信息获取失败');
|
|
}
|
|
if ($config_result['code'] != 1) {
|
|
abort(500, '网站配置信息获取失败');
|
|
}
|
|
file_put_contents(app()->getRootPath().'data/config.json', json_encode($config_result));
|
|
} else {
|
|
$config_result = json_decode(file_get_contents(app()->getRootPath().'data/config.json'), true);
|
|
}
|
|
|
|
Lang::setLangSet(Cookie::get('think_var', 'zh-cn'));
|
|
View::assign('think_lang', Cookie::get('think_var'));
|
|
View::assign('menu_url', strtolower(Request::controller() . '/' . Request::action()));
|
|
|
|
/* URL 配置*/
|
|
Config::set(['GET_ORDER_DETAIL_URL' => $config_result['data']['get_order_detail_url']], 'app');
|
|
Config::set(['LOOKUP_URL' => $config_result['data']['lookup_url']], 'app');
|
|
Config::set(['CREATE_ORDER_URL' => $config_result['data']['create_order_url']], 'app');
|
|
Config::set(['NEWS_LIST' => $config_result['data']['news_list']], 'app');
|
|
Config::set(['NEWS_DETAIL' => $config_result['data']['news_detail']], 'app');
|
|
Config::set(['CREATE_CONTACT_URL' => $config_result['data']['create_contact_url']], 'app');
|
|
Config::set(['GET_ORDER_URL' => $config_result['data']['get_order_url']], 'app');
|
|
Config::set(['YZM_URL' => $config_result['data']['yzm_url']], 'app');
|
|
/*ocr 识别 配置参数 */
|
|
Config::set(['OCR_BASE_URL' => $config_result['data']['ocr_base_url']], 'app');
|
|
Config::set(['OCR_APP_ID' => $config_result['data']['ocr_app_id']], 'app');
|
|
Config::set(['OCR_SECRET' => $config_result['data']['ocr_secret']], 'app');
|
|
|
|
$ocr_config = build_ocr_signature($config_result['data']['ocr_app_id'], $config_result['data']['ocr_secret']);
|
|
View::assign('ocr_config', json_encode($ocr_config));
|
|
|
|
/* 国内支付配置*/
|
|
Config::set(['wechatpay' => $config_result['data']['pay']['wechatpay']], 'app');
|
|
Config::set(['wechath5pay' => $config_result['data']['pay']['wechath5pay']], 'app');
|
|
Config::set(['wechatpcpay' => $config_result['data']['pay']['wechatpcpay']], 'app');
|
|
Config::set(['alipcpay' => $config_result['data']['pay']['alipcpay']], 'app');
|
|
|
|
Config::set(['user_url' => $config_result['data']['user_url']], 'app');
|
|
Config::set(['order_url' => $config_result['data']['order_url']], 'app');
|
|
View::assign('company_address', $config_result['data']['company_address']);
|
|
View::assign('company_phone', $config_result['data']['phone'] ?? '');
|
|
View::assign('base_path', BASE_PATH);
|
|
View::assign('fapiao_kefu', $config_result['data']['fapiao_png']);
|
|
|
|
if (Cookie::get('think_var') == 'en-us') {
|
|
View::assign('footer', $config_result['data']['footer_en']);
|
|
View::assign('goods', $config_result['data']['TH_GOODS_EN']);
|
|
View::assign('country', COUNTRY_EN);
|
|
} else {
|
|
View::assign('country', COUNTRY);
|
|
View::assign('footer', $config_result['data']['footer']);
|
|
View::assign('goods', $config_result['data']['TH_GOODS']);
|
|
}
|
|
}
|
|
public function langs($lang='zh-cn')
|
|
{
|
|
Cookie::set('think_var', $lang);
|
|
return true;
|
|
}
|
|
|
|
public function success($msg = '操作成功', $url = '', $data = [], $wait = 3)
|
|
{
|
|
if (is_null($url) && isset($_SERVER["HTTP_REFERER"])) {
|
|
$url = $_SERVER["HTTP_REFERER"];
|
|
} elseif ('' !== $url && is_object($url)) {
|
|
$url = $url->build();
|
|
}
|
|
if (request()->isAjax()) {
|
|
return json([
|
|
'code' => 1,
|
|
'msg' => $msg,
|
|
'data' => $data,
|
|
'url' => $url
|
|
]);
|
|
} else {
|
|
return View::fetch('public/jump', [
|
|
'msg' => $msg,
|
|
'url' => $url,
|
|
'wait' => $wait,
|
|
'type' => 'success',
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function error($msg = '操作失败', $url = '', $wait = 3, $data = [])
|
|
{
|
|
if (is_null($url) && isset($_SERVER["HTTP_REFERER"])) {
|
|
$url = $_SERVER["HTTP_REFERER"];
|
|
} elseif ('' !== $url && is_object($url)) {
|
|
$url = $url->build();
|
|
}
|
|
if (request()->isAjax()) {
|
|
return json([
|
|
'code' => 0,
|
|
'msg' => $msg,
|
|
'data' => $data,
|
|
'url' => $url
|
|
]);
|
|
} else {
|
|
return View::fetch('public/jump', [
|
|
'msg' => $msg,
|
|
'url' => $url,
|
|
'wait' => $wait,
|
|
'type' => 'error',
|
|
]);
|
|
}
|
|
}
|
|
}
|