<commit_before><?php

// +----------------------------------------------------------------------
// | Think.Admin
// +----------------------------------------------------------------------
// | 版权所有 2014~2017 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | github开源项目：https://github.com/zoujingli/Think.Admin
// +----------------------------------------------------------------------

namespace app\wechat\controller;

use controller\BasicAdmin;
use service\LogService;
use service\WechatService;
use think\Db;

/**
 * 微信粉丝标签管理
 * Class Tags
 * @package app\wechat\controller
 * @author Anyon <<EMAIL>>
 * @date 2017/03/27 14:43
 */
class Tags extends BasicAdmin {

    /**
     * 定义当前默认数据表
     * @var string
     */
    protected $table = 'WechatFansTags';

    /**
     * 显示粉丝标签列表
     * @return array|string
     */
    public function index() {
        $this->title = '微信粉丝标签管理';
        $db = Db::name($this->table)->order('id asc');
        $get = $this->request->get();
        foreach (['name'] as $key) {
            if (isset($get[$key]) && $get[$key] !== '') {
                $db->where($key, 'like', "%{$get[$key]}%");
            }
        }
        return parent::_list($db);
    }

    /**
     * 添加粉丝标签
     */
    public function add() {
        if ($this->request->isGet()) {
            return parent::_form($this->table, 'form', 'id');
        }
    }

    /**
     * 编辑粉丝标签
     */
    public function edit() {
        // 显示编辑界面
        if ($this->request->isGet()) {
            return parent::_form($this->table, 'form', 'id');
        }
        // 接收提交的数据
        $name = $this->request->post('name', '');
        $id = $this->request->post('id', '0');
        $info = db($this->table)->where('name', $name)->find();
        if (!empty($info)) {
            if (intval($info['id']) === intval($id)) {
                $this->success('标签没有改变！');
            } else {
                $this->error('标签已经存在，请使用其它名称再试！');
            }
        }
        $wechat = &load_wechat('User', $this->real_appid);
        $data = array('id' => $id, 'name' => $name);
        if (FALSE !== $wechat->updateTag($id, $name) && FALSE !== Data::save($this->table, $data, 'id')) {
            $this->success('编辑标签成功!');
        } else {
            $this->error('编辑标签失败，请稍后再试！' . $wechat->errMsg);
        }
    }

    /**
     * 同步粉丝标签列表
     */
    public function sync() {
        Db::name($this->table)->where('1=1')->delete();
        if (WechatService::syncFansTags()) {
            LogService::write('微信管理', '同步全部微信粉丝标签成功');
            $this->success('同步获取所有粉丝标签成功！', '');
        }
        $this->error('同步获取粉丝标签失败，请稍候再试！');
    }

}<commit_msg>[更新]修改粉丝标签模块<commit_after><?php

// +----------------------------------------------------------------------
// | Think.Admin
// +----------------------------------------------------------------------
// | 版权所有 2014~2017 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | github开源项目：https://github.com/zoujingli/Think.Admin
// +----------------------------------------------------------------------

namespace app\wechat\controller;

use controller\BasicAdmin;
use service\DataService;
use service\LogService;
use service\WechatService;
use think\Db;

/**
 * 微信粉丝标签管理
 * Class Tags
 * @package app\wechat\controller
 * @author Anyon <<EMAIL>>
 * @date 2017/03/27 14:43
 */
class Tags extends BasicAdmin {

    /**
     * 定义当前默认数据表
     * @var string
     */
    protected $table = 'WechatFansTags';

    /**
     * 显示粉丝标签列表
     * @return array|string
     */
    public function index() {
        $this->title = '微信粉丝标签管理';
        $db = Db::name($this->table)->order('id asc');
        $get = $this->request->get();
        foreach (['name'] as $key) {
            if (isset($get[$key]) && $get[$key] !== '') {
                $db->where($key, 'like', "%{$get[$key]}%");
            }
        }
        return parent::_list($db);
    }

    /**
     * 添加粉丝标签
     */
    public function add() {
        if ($this->request->isGet()) {
            return parent::_form($this->table, 'form', 'id');
        }
    }

    /**
     * 编辑粉丝标签
     */
    public function edit() {
        // 显示编辑界面
        if ($this->request->isGet()) {
            return parent::_form($this->table, 'form', 'id');
        }
        // 接收提交的数据
        list($name, $id) = [$this->request->post('name', ''), $this->request->post('id', '0')];
        $info = Db::name($this->table)->where('name', $name)->find();
        if (!empty($info)) {
            if (intval($info['id']) === intval($id)) {
                $this->success('粉丝标签没有改变！', '');
            }
            $this->error('标签已经存在，请使用其它名称再试！');
        }
        $wechat = &load_wechat('User');
        $data = array('id' => $id, 'name' => $name);
        if (false !== $wechat->updateTag($id, $name) && false !== DataService::save($this->table, $data, 'id')) {
            $this->success('编辑标签成功!');
        }
        $this->error('编辑标签失败，请稍后再试！' . $wechat->errMsg);
    }

    /**
     * 同步粉丝标签列表
     */
    public function sync() {
        Db::name($this->table)->where('1=1')->delete();
        if (WechatService::syncFansTags()) {
            LogService::write('微信管理', '同步全部微信粉丝标签成功');
            $this->success('同步获取所有粉丝标签成功！', '');
        }
        $this->error('同步获取粉丝标签失败，请稍候再试！');
    }

}
{'fraction_non_alphanumeric': 0.32868085106382977, 'fraction_numerical': 0.007829787234042554, 'mean_word_length': 1.3354531001589824, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 74, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3090059', 'n_tokens_mistral': 1976, 'n_tokens_neox': 2105, 'n_words': 271}