'required|numeric', 'uniacid' => 'required|numeric', 'module' => 'required', 'content' => 'required', 'type' => 'numeric|required', 'displayorder' => 'numeric', 'status' => 'numeric', ]; } /** * 定义字段名 * * @return array */ public function atributeNames() { return [ 'rid' => '规则id', 'uniacid' => '公众号id', 'module' => '模块', 'content' => '关键字内容', 'type' => '触发类型', 'displayorder' => '回复优先级', 'status' => '是否开启', ]; } public static function destroyKeywordByRuleId($roleId) { return static::uniacid() ->where('rid', $roleId) ->where('module', static::$module) ->delete(); } public static function updateKeywordByRoleId($roleId, $keyword) { return static::uniacid() ->where('rid', $roleId) ->where('module', static::$module) ->update(['content' => trim($keyword)]); } public function hasOneRule() { return $this->hasOne(Rule::class,'id','rid')->select('id','name'); } // 通过关键字获取规则 public static function getRuleKeywordByKeywords($keywords) { // 先找精准触发 $accurate = static::uniacid()->where('status','=',1) ->where('content','=',$keywords) ->where('type','=',1) ->orderBy('displayorder','desc') ->first(); // 再找模糊查询,正则匹配先不考虑 if (empty($accurate)) { return static::uniacid()->where('status','=',1) ->where('content','like',$keywords.'%') ->where('type','!=',1) ->orderBy('displayorder','desc') ->first(); } else { return $accurate; } } public static function hasKeyword($keyword) { $id = self::uniacid()->where('module', static::$module)->where('content', $keyword)->value('id'); return empty($id) ? false : $id; } public static function delKeyword($keyword) { return self::uniacid() ->where('module', static::$module) ->where('content', $keyword) ->delete(); } }