2019-06-06 15:07:21 +08:00

132 lines
4.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | framework
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://framework.thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/framework
// +----------------------------------------------------------------------
namespace app\wechat\controller;
use app\admin\service\Queue;
use app\wechat\queue\Jobs;
use app\wechat\service\Wechat;
use library\Controller;
use think\Db;
use think\exception\HttpResponseException;
/**
* 微信粉丝管理
* Class Fans
* @package app\wechat\controller
*/
class Fans extends Controller
{
/**
* 绑定数据表
* @var string
*/
protected $table = 'WechatFans';
/**
* 微信粉丝管理
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function index()
{
$this->title = '微信粉丝管理';
$query = $this->_query($this->table)->like('nickname')->equal('subscribe,is_black');
$query->dateBetween('subscribe_at')->order('subscribe_time desc')->page();
}
/**
* 列表数据处理
* @param array $data
*/
protected function _index_page_filter(array &$data)
{
$tags = Db::name('WechatFansTags')->column('id,name');
foreach ($data as &$user) {
$user['tags'] = [];
foreach (explode(',', $user['tagid_list']) as $tagid) {
if (isset($tags[$tagid])) $user['tags'][] = $tags[$tagid];
}
foreach (['country', 'province', 'city', 'nickname', 'remark'] as $k) {
if (isset($user[$k])) $user[$k] = emoji_decode($user[$k]);
}
}
}
/**
* 批量拉黑粉丝
*/
public function setBlack()
{
$this->applyCsrfToken();
try {
foreach (array_chunk(explode(',', $this->request->post('openid')), 20) as $openids) {
Wechat::WeChatUser()->batchBlackList($openids);
Db::name('WechatFans')->whereIn('openid', $openids)->update(['is_black' => '1']);
}
$this->success('拉黑粉丝信息成功!');
} catch (HttpResponseException $exception) {
throw $exception;
} catch (\Exception $e) {
$this->error("拉黑粉丝信息失败,请稍候再试!{$e->getMessage()}");
}
}
/**
* 取消拉黑粉丝
*/
public function delBlack()
{
$this->applyCsrfToken();
try {
foreach (array_chunk(explode(',', $this->request->post('openid')), 20) as $openids) {
Wechat::WeChatUser()->batchUnblackList($openids);
Db::name('WechatFans')->whereIn('openid', $openids)->update(['is_black' => '0']);
}
$this->success('取消拉黑粉丝信息成功!');
} catch (HttpResponseException $exception) {
throw $exception;
} catch (\Exception $e) {
$this->error("取消拉黑粉丝信息失败,请稍候再试!{$e->getMessage()}");
}
}
/**
* 同步粉丝列表
*/
public function sync()
{
try {
Queue::add('同步粉丝列表', Jobs::URI, 0, [], 0);
$this->success('创建同步粉丝任务成功,需要时间来完成。<br>请到系统任务管理查看进度!');
} catch (HttpResponseException $exception) {
throw $exception;
} catch (\Exception $e) {
$this->error("创建同步粉丝任务失败,请稍候再试!<br> {$e->getMessage()}");
}
}
/**
* 删除粉丝信息
*/
public function del()
{
$this->applyCsrfToken();
$this->_delete($this->table);
}
}