微信模块优化

This commit is contained in:
Anyon 2020-10-28 16:20:50 +08:00
parent 7b15976afb
commit 9b1051e27b
3 changed files with 40 additions and 43 deletions

View File

@ -63,8 +63,8 @@ class Keys extends Controller
}
// 数据列表分页处理
$this->title = '回复规则管理';
$query = $this->_query($this->table)->like('keys,type')->equal('status')->dateBetween('create_at');
$query->whereNotIn('keys', ['subscribe', 'default'])->order('sort desc,id desc')->page();
$query = $this->_query($this->table)->whereNotIn('keys', ['subscribe', 'default']);
$query->equal('status')->like('keys,type')->dateBetween('create_at')->order('sort desc,id desc')->page();
}
/**
@ -168,17 +168,14 @@ class Keys extends Controller
*/
protected function _form_filter(array &$data)
{
if ($this->request->isPost() && isset($data['keys'])) {
$db = $this->app->db->name($this->table)->where('keys', $data['keys']);
empty($data['id']) || $db->where('id', '<>', $data['id']);
if ($db->count() > 0) {
$this->error('关键字已经存在,请使用其它关键字!');
if ($this->request->isPost()) {
$map = [['keys', '=', $data['keys']], ['id', '<>', $data['id'] ?? 0]];
if ($this->app->db->name($this->table)->where($map)->count() > 0) {
$this->error('该关键字已经存在!');
}
}
if ($this->request->isGet()) {
$this->msgTypes = $this->types;
$root = rtrim(dirname($this->request->basefile(true)), '\\/');
$this->defaultImage = "{$root}/static/theme/img/image.png";
} elseif ($this->request->isGet()) {
$public = dirname($this->request->basefile(true));
$this->defaultImage = "{$public}/static/theme/img/image.png";
}
}

View File

@ -60,15 +60,32 @@ class Menu extends Controller
public function index()
{
if ($this->request->get('output') === 'json') {
$where = [['keys', 'notin', ['subscribe', 'default']], ['status', '=', '1']];
$keys = $this->app->db->name('WechatKeys')->where($where)->order('sort desc,id desc')->select();
$this->success('获取数据成功!', ['menudata' => sysdata($this->ckey), 'keysdata' => $keys]);
$map = [['keys', 'notin', ['subscribe', 'default']], ['status', '=', 1]];
$result = $this->app->db->name('WechatKeys')->where($map)->order('sort desc,id desc')->select();
$this->success('获取数据成功!', ['menudata' => sysdata($this->ckey), 'keysdata' => $result->toArray()]);
} else {
$this->title = '微信菜单定制';
$this->fetch();
}
}
/**
* 取消微信菜单
* @auth true
*/
public function cancel()
{
try {
WechatService::WeChatMenu()->delete();
$this->success('菜单取消成功,重新关注可立即生效!');
} catch (HttpResponseException $exception) {
sysoplog('微信管理', '取消微信菜单成功');
throw $exception;
} catch (\Exception $exception) {
$this->error("菜单取消失败,请稍候再试!<br> {$exception->getMessage()}");
}
}
/**
* 编辑微信菜单
* @auth true
@ -107,17 +124,15 @@ class Menu extends Controller
*/
private function _buildMenuData(array $list): array
{
foreach ($list as &$vo) {
unset($vo['active'], $vo['show']);
if (empty($vo['sub_button'])) {
$vo = $this->_buildMenuItemData($vo);
foreach ($list as $key => &$item) {
if (empty($item['sub_button'])) {
$item = $this->_buildMenuDataItem($item);
} else {
$item = ['name' => $vo['name'], 'sub_button' => []];
foreach ($vo['sub_button'] as &$sub) {
unset($sub['active'], $sub['show']);
array_push($item['sub_button'], $this->_buildMenuItemData($sub));
$button = ['name' => $item['name'], 'sub_button' => []];
foreach ($item['sub_button'] as &$sub) {
$button['sub_button'][] = $this->_buildMenuDataItem($sub);
}
$vo = $item;
$item = $button;
}
}
return $list;
@ -128,7 +143,7 @@ class Menu extends Controller
* @param array $item
* @return array
*/
private function _buildMenuItemData(array $item)
private function _buildMenuDataItem(array $item): array
{
switch (strtolower($item['type'])) {
case 'pic_weixin':
@ -145,23 +160,8 @@ class Menu extends Controller
return ['name' => $item['name'], 'type' => $item['type'], 'url' => $item['url']];
case 'miniprogram':
return ['name' => $item['name'], 'type' => $item['type'], 'url' => $item['url'], 'appid' => $item['appid'], 'pagepath' => $item['pagepath']];
}
}
/**
* 取消微信菜单
* @auth true
*/
public function cancel()
{
try {
WechatService::WeChatMenu()->delete();
$this->success('菜单取消成功,重新关注可立即生效!');
} catch (HttpResponseException $exception) {
sysoplog('微信管理', '取消微信菜单成功');
throw $exception;
} catch (\Exception $exception) {
$this->error("菜单取消失败,请稍候再试!<br> {$exception->getMessage()}");
default:
return [];
}
}

View File

@ -60,7 +60,7 @@
<div class="layui-form-item">
<label class="layui-form-label label-required">消息类型</label>
<div class="layui-input-block">
{foreach $msgTypes as $k=>$v}
{foreach $types as $k=>$v}
<label class="think-radio">
<!--{if (!isset($vo.type) and $k eq 'text') or (isset($vo.type) and$vo.type eq $k)}-->
<input name="type" checked type="radio" value="{$k}"> {$v}