<commit_before><?php

namespace Guo\Wechat\Http\Controllers;

use Guo\Wechat\Model\Media;
use Guo\Wechat\Model\RuleSpecial;
use Guo\Wechat\Model\Rule;
use Guo\Wechat\Model\RuleCate;
use Guo\Wechat\Model\WechatToken;
use Validator;
use EasyWeChat\Core\AccessToken;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;

/**
 * Class WechatController
 * @package App\Http\Controllers
 *
 * 规则中有一些特殊规则的id限定死,安排如下
 * 1,关注回复
 * 2.默认回复(暂时未启用)
 * 3.投票口令 跟随投票口令一起修改,用户输入"投票口令",公众号返回具体的投票口令内容
 * 4.实际的投票口令内容
 */
class WechatController extends CommonController
{
    public $request;

    public function __construct(Request $request)
    {
        $this->request = $request;
    }

    public function rule()
    {
        $textType = config('wxconfig.mediaType.text');

        //规则列表数据准备
        $rules = Rule::orderBy('id', 'desc')->paginate(15);
        $ruleCates = RuleCate::all(['id', 'label']);

        $cates = array();
        foreach ($ruleCates as $k => $v) {
            $cates[$v->id] = $v->label;
        }
        //所有media准备
        $medias = Media::where(['multi_order' => '0'])->get(['id', 'content', 'title', 'media_type']);
        $mediasView = array();
        foreach ($medias as $k => $v) {
            if ($v->media_type == 6) {
                $mediasView[$v->id] = '[文本]' . $v->content;
            } else if ($v->media_type == 3) {
                $mediasView[$v->id] = '[图片]' . $v->title;
            } else {
                $mediasView[$v->id] = '[图文]' . $v->title;
            }

        }

        //单个规则数据准备
        $r = $this->request;
        $id = $r->id ? $r->id : 0;

        if ($id > 0) {
            $rule = Rule::find($id);
            if ($rule) {
                if ($rule->media_type == 2) {
                    $media = Media::where(['bundle_id' => $rule->media_id])->orderBy('multi_order', 'asc')->get();
                    $rule->media_id = $media[0]->id;
                }
            }
        }
        if (empty($rule)) {
            $rule = (object)array('id' => '新增', 'keyword' => '', 'cate_id' => 0, 'media_id' => 0);
        }

        //模版
        return view('wechat::wechat.rule', [
            'rules' => $rules,
            'cates' => $cates,
            'id' => $id,
            'rule' => $rule,
            'medias' => $mediasView,
            'textType' => $textType
        ]);
    }

    public function setRule()
    {
        $r = $this->request;
$arr=$r->toArray();
        $validator=Validator::make($arr, [
            'keyword' => 'required|string',
            'cate_id' => 'required|integer',
            'media_id' => 'required|integer',
            'media_type' => 'required|integer',
        ]);
        if ($validator->fails()) {
            return redirect('wechat/rule')
                ->withErrors($validator)
                ->withInput();
        }

        //判断是否有重复
        $ruleRepeat = Rule::where('keyword', $r->keyword)->first();
        $dbDR = 0;
        if (!empty($ruleRepeat)) {
            //不能与系统关键词冲突
            $ruleId = config('wxconfig.ruleId');
            if (in_array($ruleRepeat->id, $ruleId)) {
                return redirect('wechat/rule')->withErrors(array(
                    '输入关键词与系统保留关键词冲突:' . array_search($ruleRepeat->id, $ruleId)
                ));
            } else {
                $dbDR = $ruleRepeat->delete();
            }<commit_msg>no message<commit_after><?php

namespace Guo\Wechat\Http\Controllers;

use Guo\Wechat\Model\Media;
use Guo\Wechat\Model\RuleSpecial;
use Guo\Wechat\Model\Rule;
use Guo\Wechat\Model\RuleCate;
use Guo\Wechat\Model\WechatToken;
use Validator;
use EasyWeChat\Core\AccessToken;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;

/**
 * Class WechatController
 * @package App\Http\Controllers
 *
 * 规则中有一些特殊规则的id限定死,安排如下
 * 1,关注回复
 * 2.默认回复(暂时未启用)
 * 3.投票口令 跟随投票口令一起修改,用户输入"投票口令",公众号返回具体的投票口令内容
 * 4.实际的投票口令内容
 */
class WechatController extends CommonController
{
    public $request;

    public function __construct(Request $request)
    {
        $this->request = $request;
    }

    public function rule()
    {
        $textType = config('wxconfig.mediaType.text');

        //规则列表数据准备
        $rules = Rule::orderBy('id', 'desc')->paginate(15);
        $ruleCates = RuleCate::all(['id', 'label']);

        $cates = array();
        foreach ($ruleCates as $k => $v) {
            $cates[$v->id] = $v->label;
        }
        //所有media准备
        $medias = Media::where(['multi_order' => '0'])->get(['id', 'content', 'title', 'media_type']);
        $mediasView = array();
        foreach ($medias as $k => $v) {
            if ($v->media_type == 6) {
                $mediasView[$v->id] = '[文本]' . $v->content;
            } else if ($v->media_type == 3) {
                $mediasView[$v->id] = '[图片]' . $v->title;
            } else {
                $mediasView[$v->id] = '[图文]' . $v->title;
            }

        }

        //单个规则数据准备
        $r = $this->request;
        $id = $r->id ? $r->id : 0;

        if ($id > 0) {
            $rule = Rule::find($id);
            if ($rule) {
                if ($rule->media_type == 2) {
                    $media = Media::where(['bundle_id' => $rule->media_id])->orderBy('multi_order', 'asc')->get();
                    $rule->media_id = $media[0]->id;
                }
            }
        }
        if (empty($rule)) {
            $rule = (object)array('id' => '新增', 'keyword' => '', 'cate_id' => 0, 'media_id' => 0);
        }

        //模版
        return view('wechat::wechat.rule', [
            'rules' => $rules,
            'cates' => $cates,
            'id' => $id,
            'rule' => $rule,
            'medias' => $mediasView,
            'textType' => $textType
        ]);
    }

    public function setRule()
    {
        $r = $this->request;
        $arr=$r->toArray();
        $validator=Validator::make($arr, [
            'keyword' => 'required|string',
            'cate_id' => 'required|integer',
            'media_id' => 'required|integer',
            'media_type' => 'required|integer',
        ]);
        if ($validator->fails()) {
            return redirect('wechat/rule')
                ->withErrors($validator)
                ->withInput();
        }

        //判断是否有重复
        $ruleRepeat = Rule::where('keyword', $r->keyword)->first();
        $dbDR = 0;
        if (!empty($ruleRepeat)) {
            //不能与系统关键词冲突
            $ruleId = config('wxconfig.ruleId');
            if (in_array($ruleRepeat->id, $ruleId)) {
                return redirect('wechat/rule')->withErrors(array(
                    '输入关键词与系统保留关键词冲突:' . array_search($ruleRepeat->id, $ruleId)
                ));
            } else {
                $dbDR = $ruleRepeat->delete();
            }
{'fraction_non_alphanumeric': 0.17944535073409462, 'fraction_numerical': 0.004745662168174403, 'mean_word_length': 1.7913907284768211, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 107, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4613899', 'n_tokens_mistral': 2381, 'n_tokens_neox': 2463, 'n_words': 373}