123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- namespace app\service\controller;
- use app\service\queue\WechatQueue;
- use app\service\service\WechatService;
- use library\Controller;
- use think\Db;
- use think\exception\HttpResponseException;
- class Fans extends Controller
- {
- protected $appid = '';
-
- protected $table = 'WechatFans';
-
- protected function initialize()
- {
- $this->appid = input('appid', session('current_appid'));
- if (empty($this->appid)) {
- $this->where = ['status' => '1', 'service_type' => '2', 'is_deleted' => '0', 'verify_type' => '0'];
- $this->appid = Db::name('WechatServiceConfig')->where($this->where)->value('authorizer_appid');
- }
- if (empty($this->appid)) {
- $this->fetch('/not-auth');
- } else {
- session('current_appid', $this->appid);
- }
- if ($this->request->isGet()) {
- $this->where = ['status' => '1', 'service_type' => '2', 'is_deleted' => '0', 'verify_type' => '0'];
- $this->wechats = Db::name('WechatServiceConfig')->where($this->where)->order('id desc')->column('authorizer_appid,nick_name');
- }
- }
-
- public function index()
- {
- $this->title = '微信粉丝管理';
- $query = $this->_query($this->table)->like('nickname')->equal('subscribe,is_black');
- $query->dateBetween('subscribe_at')->where(['appid' => $this->appid])->order('subscribe_time desc')->page();
- }
-
- 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];
- }
- }
- }
-
- public function setBlack()
- {
- try {
- $this->applyCsrfToken();
- foreach (array_chunk(explode(',', $this->request->post('openid')), 20) as $openids) {
- WechatService::WeChatUser($this->appid)->batchBlackList($openids);
- Db::name('WechatFans')->where(['appid' => $this->appid])->whereIn('openid', $openids)->update(['is_black' => '1']);
- }
- $this->success('拉黑粉丝信息成功!');
- } catch (HttpResponseException $exception) {
- throw $exception;
- } catch (\Exception $e) {
- $this->error("拉黑粉丝信息失败,请稍候再试!{$e->getMessage()}");
- }
- }
-
- public function delBlack()
- {
- try {
- $this->applyCsrfToken();
- foreach (array_chunk(explode(',', $this->request->post('openid')), 20) as $openids) {
- WechatService::WeChatUser($this->appid)->batchUnblackList($openids);
- Db::name('WechatFans')->where(['appid' => $this->appid])->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 {
- sysoplog('微信管理', "创建微信[{$this->appid}]粉丝同步任务");
- sysqueue("同步[{$this->appid}]粉丝列表", WechatQueue::URI, 0, ['appid' => $this->appid], 0);
- $this->success('创建同步粉丝任务成功,需要时间来完成。<br>请到 系统管理 > 任务管理 查看执行进度!');
- } catch (HttpResponseException $exception) {
- throw $exception;
- } catch (\Exception $e) {
- $this->error("创建同步粉丝任务失败,请稍候再试!<br> {$e->getMessage()}");
- }
- }
-
- public function remove()
- {
- $this->applyCsrfToken();
- $this->_delete($this->table);
- }
- }
|