You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
152 lines
4.4 KiB
152 lines
4.4 KiB
<?php
|
|
|
|
namespace app\base\controller\wechat\admin;
|
|
|
|
use app\base\logic\Wechat;
|
|
use app\base\model\wechat\WechatClassify;
|
|
use app\base\model\wechat\WechatReply;
|
|
use app\BaseController;
|
|
use think\App;
|
|
|
|
class Classify extends BaseController
|
|
{
|
|
/**
|
|
* 获取自定义菜单
|
|
* @date 2020-10-19
|
|
*/
|
|
public function lists()
|
|
{
|
|
$weixin_classify_model = new WechatClassify();
|
|
|
|
$data = $weixin_classify_model->getOneData(['uid' => UID]);
|
|
if(empty($data)){
|
|
$data['id'] = '';
|
|
$data['content'] = [];
|
|
}
|
|
$rdata = [
|
|
'data' => $data
|
|
];
|
|
return sendSuccessMessage($rdata);
|
|
}
|
|
|
|
/**
|
|
* 保存自定义菜单
|
|
* @date 2020-10-21
|
|
*/
|
|
public function dataAdd()
|
|
{
|
|
$param = input('post.');
|
|
|
|
$weixin_classify_model = new WechatClassify();
|
|
|
|
$classify = [];
|
|
if (isset($param['name_0'])) {
|
|
$classify_one_name = $param['name_0'];
|
|
foreach ($classify_one_name as $k => $v) {
|
|
$button = [];
|
|
if (!isset($param['sub_type_' . $k])) { //二级菜单不存在
|
|
if (!$param['type_0'][$k]) {
|
|
return sendErrorMessage(4002,'请将自定义菜单填写完整');
|
|
}
|
|
$button = ['name' => $v, 'type' => $param['type_0'][$k], 'content' => $param['content_0'][$k]];
|
|
} else { //二级菜单存在
|
|
$button['name'] = $v;
|
|
foreach ($param['sub_type_' . $k] as $k1 => $v1) {
|
|
if (!$v1) {
|
|
return sendErrorMessage(4002,'请将自定义菜单填写完整');
|
|
} else {
|
|
$button['sub_button'][] = ['name' => $param['sub_name_' . $k][$k1], 'type' => $v1, 'content' => $param['sub_content_' . $k][$k1]];
|
|
}
|
|
}
|
|
}
|
|
$classify[] = $button;
|
|
}
|
|
}
|
|
|
|
$data = [
|
|
'id'=>$param['id'],
|
|
'uid'=>UID,
|
|
'content'=>$classify
|
|
];
|
|
// dump($data);exit;
|
|
$res = $weixin_classify_model->dataUpdate($data);
|
|
if(!$res){
|
|
return sendErrorMessage(4001,'操作失败');
|
|
}
|
|
|
|
return sendSuccessMessage([],'操作成功');
|
|
}
|
|
|
|
/**
|
|
* 发布菜单
|
|
* @date 2020-10-21
|
|
*/
|
|
public function classifyPublish()
|
|
{
|
|
$weixin_classify_model = new WechatClassify();
|
|
$wechat_logic = new Wechat();
|
|
|
|
//自定义菜单格式化
|
|
$data = $weixin_classify_model->getOneData(['uid' => UID]);
|
|
foreach ($data['content'] as $k => $v) {
|
|
$button = [];
|
|
if (isset($v['sub_button'])) { //二级菜单存在
|
|
$button['name'] = $v['name'];
|
|
foreach ($v['sub_button'] as $vv) {
|
|
$button['sub_button'][] = $weixin_classify_model->buttonFormat($vv['name'], $vv['type'], $vv['content']);
|
|
}
|
|
} else { //二级菜单不存在
|
|
$button = $weixin_classify_model->buttonFormat($v['name'], $v['type'], $v['content']);
|
|
}
|
|
$classify[] = $button;
|
|
}
|
|
|
|
//发布菜单
|
|
$res = $wechat_logic->classifyPublish($classify);
|
|
if ($res['errcode'] == 0) {
|
|
return sendSuccessMessage([],'菜单发布成功');
|
|
} else {
|
|
return sendErrorMessage(4001,$res['errmsg']);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除菜单
|
|
* @date 2020-10-19
|
|
*/
|
|
public function classifydel()
|
|
{
|
|
$weixin_classify_model = new WechatClassify();
|
|
$wechat_logic = new Wechat();
|
|
|
|
$res = $wechat_logic->classifyDel();
|
|
if ($res['errcode'] == 0) {
|
|
return sendSuccessMessage([],'菜单删除成功');
|
|
} else {
|
|
return sendErrorMessage(4001,$res['errmsg']);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取自动回复列表
|
|
* @date 2020-10-20
|
|
*/
|
|
public function replyList()
|
|
{
|
|
$wechat_reply_model = new WechatReply();
|
|
|
|
$reply_list = $wechat_reply_model->getAllData([
|
|
['uid', '=', UID]
|
|
])->each(function ($item, $key){
|
|
$item['type_text'] = $item->type_text;
|
|
return $item;
|
|
});
|
|
|
|
$rdata = [
|
|
'list' => $reply_list
|
|
];
|
|
return sendSuccessMessage($rdata);
|
|
}
|
|
|
|
}
|