cxhxy/app/applet/controller/Wechat.php
test_service d3170b4d1c 1
2023-12-01 15:43:29 +08:00

1 line
1.7 KiB
PHP
Executable File

<?php
namespace app\applet\controller;
use app\applet\model\Wechat as WechatModel;
use app\applet\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($this->applet_id);
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($this->applet_id,1);
}
return View::fetch('../../admin/view/wechat/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,$this->applet_id);
if($key == 'menus'){
$model = json_encode($model);
}
return View::fetch('../../admin/view/wechat/' . $key, compact('model'));
}
$model = new SettingModel;
if ($model->edit($key,$this->postData('data'),$this->applet_id)){
return $this->renderSuccess('更新成功');
}
$error = $model->getError() ?: '更新失败';
return $this->renderError($error);
}
}