112 lines
3.4 KiB
PHP
112 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace Yunshop\Decorate\admin;
|
|
|
|
use app\common\facades\Setting;
|
|
use app\common\components\BaseController;
|
|
use app\common\helpers\Cache;
|
|
use app\common\services\YunqianRequest;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Yunshop\Decorate\common\services\AddCktService;
|
|
use Yunshop\Decorate\models\ckt\ClassModel;
|
|
use Yunshop\Decorate\models\DecorateModel;
|
|
|
|
class DecorateSetController extends BaseController
|
|
{
|
|
/**
|
|
* 基础设置详情
|
|
*/
|
|
public function setInfo()
|
|
{
|
|
$set = Setting::get('plugin.decorate');
|
|
if ($set['is_open'] != '1') {
|
|
$set['is_open'] = '2';
|
|
}
|
|
$res = $this->getApiFrequency($set);
|
|
$set['yun_form'] = [
|
|
'expireDate' => $res['data']['end_time'] ?: '未知'
|
|
];
|
|
return view('Yunshop\Decorate::admin.set', [
|
|
'set' => $set,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 插件开关
|
|
*/
|
|
public function open()
|
|
{
|
|
$is_open = request()->is_open;
|
|
|
|
if ($is_open) {
|
|
Cache::flush();
|
|
Setting::set('plugin.decorate.is_open', $is_open);
|
|
}
|
|
|
|
|
|
return $this->successJson('设置保存成功');
|
|
}
|
|
|
|
/**
|
|
* [urlReplace 客户更换域名是调用进行替换]
|
|
* @return [type] [description]
|
|
*/
|
|
public function urlReplace()
|
|
{
|
|
$oldDomain = request()->oldDomain; //旧域名不加http:://
|
|
$newDomain = request()->newDomain; //新域名不加http:://
|
|
|
|
if (!$oldDomain || !$newDomain) {
|
|
return $this->errorJson('请填写旧域名和需要被替换的域名');
|
|
}
|
|
|
|
$decorate = DecorateModel::where('id', '>', 0)->get()->toArray();
|
|
|
|
foreach ($decorate as $key => $value) {
|
|
|
|
$page_info = str_replace($oldDomain, $newDomain, $value['page_info']);
|
|
$data = str_replace($oldDomain, $newDomain, $value['datas']);
|
|
|
|
$editData = ['page_info' => $page_info, 'datas' => $data];
|
|
DecorateModel::where('id', $value['id'])->update($editData);
|
|
}
|
|
\Log::debug('装修替换数据', [$oldDomain, $newDomain]);
|
|
return $this->successJson('替换成功');
|
|
}
|
|
|
|
public function cktSet()
|
|
{
|
|
$ckt = request()->input('ckt');
|
|
foreach ($ckt as $key => $item) {
|
|
Setting::set('plugin.decorate.' . $key, $item);
|
|
}
|
|
if (!Schema::hasTable('yz_ckt_class')) {
|
|
return $this->errorJson('数据表不存在');
|
|
}
|
|
$class_data = ClassModel::get();
|
|
if ($class_data->isEmpty()) {
|
|
AddCktService::addData();
|
|
}
|
|
return $this->successJson('保存成功');
|
|
}
|
|
|
|
private function getApiFrequency($data)
|
|
{
|
|
$reqURL = 'https://www.yunqiankeji.com/addons/yun_shop/api.php?i=1&uuid=0&type=5&shop_id=null&validate_page=1&scope=home&route=plugin.yunqian-api.api.ckt.getUserInfo';
|
|
|
|
$server_name = $_SERVER['SERVER_NAME'];
|
|
if (strexists($server_name, 'dev')) {
|
|
//dev环境用本地
|
|
$reqURL = 'https://dev1.cloudeapi.com/addons/yun_shop/api.php?i=2&uuid=0&type=5&shop_id=null&validate_page=1&scope=home&route=plugin.yunqian-api.api.ckt.getUserInfo';
|
|
}
|
|
|
|
$pa = json_encode([]);
|
|
$app_id = trim($data['yun_app_id']);
|
|
$app_secret = trim($data['yun_app_secret']);
|
|
|
|
$yq = new YunqianRequest($pa, $reqURL, $app_id, $app_secret);
|
|
$result = $yq->getResult();
|
|
return $result ?: [];
|
|
}
|
|
}
|