[更新]添加粉丝黑名单操作

This commit is contained in:
Anyon 2017-05-05 16:32:09 +08:00
parent 20108bc9df
commit ed2e937256
5 changed files with 134 additions and 4 deletions

View File

@ -40,7 +40,7 @@ class Fans extends BasicAdmin {
*/
public function index() {
$this->title = '微信粉丝管理';
$db = Db::name($this->table)->order('id desc');
$db = Db::name($this->table)->where('is_back', '0')->order('id desc');
$get = $this->request->get();
foreach (['nickname'] as $key) {
if (isset($get[$key]) && $get[$key] !== '') {
@ -50,12 +50,60 @@ class Fans extends BasicAdmin {
return parent::_list($db);
}
/**
* 黑名单列表
*/
public function back() {
$this->title = '微信粉丝黑名单管理';
$db = Db::name($this->table)->where('is_back', '1')->order('id desc');
$get = $this->request->get();
foreach (['nickname'] as $key) {
if (isset($get[$key]) && $get[$key] !== '') {
$db->where($key, 'like', "%{$get[$key]}%");
}
}
return parent::_list($db);
}
/**
* 设置黑名单
*/
public function backadd() {
$ids = $this->request->post('id', '');
empty($ids) && $this->error('没有需要操作的数据!');
$openids = Db::name($this->table)->where('id', 'in', explode(',', $ids))->column('openid');
empty($openids) && $this->error('没有需要操作的数据!');
$wechat = & load_wechat('User');
if (false !== $wechat->addBacklist($openids)) {
Db::name($this->table)->where('openid', 'in', $openids)->setField('is_back', '1');
$this->success("已成功将 " . count($openids) . " 名粉丝移到黑名单!", '');
}
$this->error("设备黑名单失败,请稍候再试!{$wechat->errMsg}[{$wechat->errCode}]");
}
/**
* 取消黑名
*/
public function backdel() {
$ids = $this->request->post('id', '');
empty($ids) && $this->error('没有需要操作的数据!');
$openids = Db::name($this->table)->where('id', 'in', explode(',', $ids))->column('openid');
empty($openids) && $this->error('没有需要操作的数据!');
$wechat = & load_wechat('User');
if (false !== $wechat->delBacklist($openids)) {
Db::name($this->table)->where('openid', 'in', $openids)->setField('is_back', '0');
$this->success("已成功将 " . count($openids) . " 名粉丝从黑名单中移除!", '');
}
$this->error("设备黑名单失败,请稍候再试!{$wechat->errMsg}[{$wechat->errCode}]");
}
/**
* 同步粉丝列表
*/
public function sync() {
Db::name($this->table)->where('1=1')->delete();
if (WechatService::syncAllFans('')) {
WechatService::syncBlackFans('');
LogService::write('微信管理', '同步全部微信粉丝成功');
$this->success('同步获取所有粉丝成功!', '');
}

View File

@ -41,8 +41,8 @@ class Tags extends BasicAdmin {
*/
public function index() {
$this->title = '微信粉丝标签管理';
$db = Db::name($this->table)->order('id asc');
$get = $this->request->get();
$db = Db::name($this->table)->order('id asc');
foreach (['name'] as $key) {
if (isset($get[$key]) && $get[$key] !== '') {
$db->where($key, 'like', "%{$get[$key]}%");

View File

@ -0,0 +1,69 @@
{extend name='extra@admin/content' /}
{block name="button"}
<div class="nowrap pull-right" style="margin-top:10px">
<button data-load="{:url('sync')}" class='layui-btn layui-btn-small'>同步粉丝</button>
</div>
<div class="nowrap pull-right" style="margin-top:10px;margin-right:10px">
<button data-update="" data-action="{:url('backdel')}" class='layui-btn layui-btn-small'>移出黑名单</button>
</div>
{/block}
{block name="content"}
<!-- 表单搜索 开始 -->
<form class="animated form-search" action="__SELF__" onsubmit="return false" method="get">
<div class="row">
<div class="col-xs-3">
<div class="form-group">
<input type="text" name="nickname" value="{$Think.get.nickname|default=''}" placeholder="昵称" class="input-sm form-control">
</div>
</div>
<div class="col-xs-1">
<div class="form-group">
<button type="submit" class="btn btn-sm btn-white"><i class="fa fa-search"></i> 搜索</button>
</div>
</div>
</div>
</form>
<!-- 表单搜索 结束 -->
<form onsubmit="return false;" data-auto="" method="POST">
<input type="hidden" value="resort" name="action"/>
<table class="table table-hover">
<thead>
<tr>
<th class='list-table-check-td'>
<input data-none-auto="" data-check-target='.list-check-box' type='checkbox'/>
</th>
<th class='text-left'>用户昵称</th>
<th class='text-center'>性别</th>
<th class='text-center'>区域</th>
<th class='text-center'>关注时间</th>
</tr>
</thead>
<tbody>
{foreach $list as $key=>$vo}
<tr>
<td class='list-table-check-td'>
<input class="list-check-box" value='{$vo.id}' type='checkbox'/>
</td>
<td class='text-left'>
<img style="width:25px;height:25px;border-radius:50%;margin-right:10px" data-tips-image src="{$vo.headimgurl}"/>
{$vo.nickname|default="<span style='color:#999'>未设置微信昵称</span>"}
</td>
<td class='text-center'>{$vo.sex==1?'男':($vo.sex==2?'女':'未知')}</td>
<td class='text-center'>{$vo.country|default='<span style="color:#999">未设置区域信息</span>'}{$vo.province}{$vo.city}</td>
<td class='text-center'>{$vo.subscribe_at}</td>
</tr>
{/foreach}
</tbody>
</table>
{if isset($page)}<p>{$page}</p>{/if}
</form>
{/block}

View File

@ -1,9 +1,15 @@
{extend name='extra@admin/content' /}
{block name="button"}
<div class="nowrap pull-right" style="margin-top:10px">
<button data-load="{:url('sync')}" class='layui-btn layui-btn-small'><i class='fa fa-referer'></i> 同步粉丝</button>
<button data-load="{:url('sync')}" class='layui-btn layui-btn-small'>同步粉丝</button>
</div>
<div class="nowrap pull-right" style="margin-top:10px;margin-right:10px">
<button data-update="" data-action="{:url('backadd')}" class='layui-btn layui-btn-small'>移入黑名单</button>
</div>
{/block}
{block name="content"}

View File

@ -54,13 +54,19 @@
</td>
<td class='text-center'>{$vo.id|default='0'}</td>
<td class='text-center'>{$vo.name|default=''}</td>
<td class='text-center'>{$vo.id<100 ? "系统标签" : "自定义标签"}</td>
<td class='text-center'>{$vo.id < 100 ? "系统标签" : "自定义标签"}</td>
<td class='text-center'>{$vo.count|default=''}</td>
<td class='text-center nowrap'>
{if auth("$classuri/edit")}
{if $vo.id >= 100}
<span class="text-explode">|</span>
<a data-modal='{:url("$classuri/edit")}?id={$vo.id}' data-title="编辑标签" href="javascript:void(0)">编辑</a>
{else}
<a href="javascript:void(0)" style="color:#999">编辑</a>
{/if}
{/if}
{if auth("$classuri/del")}
<span class="text-explode">|</span>
{if $vo.id >= 100}
@ -69,6 +75,7 @@
<a href="javascript:void(0)" style="color:#999">删除</a>
{/if}
{/if}
</td>
</tr>
{/foreach}