cxhxy/app/admin/controller/Wechat.php
2023-11-21 15:14:59 +08:00

75 lines
1.7 KiB
PHP

<?php
namespace app\admin\controller;
use app\admin\model\Wechat as WechatModel;
use app\admin\model\Setting as SettingModel;
use think\facade\View;
use hema\wechat\Driver;
/**
* 公众号管理
*/
class Wechat extends Controller
{
private $wechat;
/**
* 构造方法
*/
public function initialize()
{
parent::initialize();
$this->wechat = WechatModel::detail();
View::assign('wechat', $this->wechat);
}
/**
* 公众号信息
*/
public function index()
{
$wechat = $this->wechat;
$url = '';
if(!$wechat or $wechat['status']['value'] == 0){
$wx = new Driver;
$url = $wx->authUrl(0,1);
}
return View::fetch('index', compact('url'));
}
/**
* 被关注回复设置
*/
public function subscribe()
{
return $this->updateEvent('subscribe');
}
/**
* 公众号菜单设置
*/
public function menus()
{
return $this->updateEvent('menus');
}
/**
* 更新设置事件
*/
private function updateEvent($key)
{
if (!$this->request->isAjax()) {
$model = SettingModel::getItem($key,0);
if($key == 'menus'){
$model = json_encode($model);
}
return View::fetch($key, compact('model'));
}
$model = new SettingModel;
if ($model->edit($key,$this->postData('data'))){
return $this->renderSuccess('更新成功');
}
$error = $model->getError() ?: '更新失败';
return $this->renderError($error);
}
}