count(); $list = WechatReply::where($where) ->order([ 'sort' => 'asc', 'id' => 'desc' ]) ->page($get['page'],$get['limit']) ->select() ->toArray(); foreach ($list as $key => $reply) { // 内容类型 $reply['content_type'] && $list[$key]['content_type'] = '文本'; // 匹配类型 switch ($reply['matching_type']){ case 1: $list[$key]['matching_type'] = '全匹配'; break; case 2: $list[$key]['matching_type'] = '模糊匹配'; break; } } return ['count'=>$count,'list'=>$list]; } public static function add($post) { $post['create_time'] = time(); $post['del'] = 0; if($post['reply_type'] !== WeChat::msg_type_text && $post['status']){ // 除了关键词回复,其他回复类型开启记录只允许一条,若当前正在新增的记录将是开启状态,则该回复类型下的现有记录需先更新为停用状态 WechatReply::where(['reply_type'=>$post['reply_type']])->update(['update_time'=>time(),'status'=>0]); } return WechatReply::insert($post); } public static function getReply($id) { $detail = WechatReply::findOrEmpty($id); $detail = $detail->isEmpty() ? [] : $detail->toArray(); return $detail; } public static function edit($post){ $post['update_time'] = time(); if($post['reply_type'] !== WeChat::msg_type_text && $post['status']){ WechatReply::where(['reply_type'=>$post['reply_type']])->update(['update_time'=>time(),'status'=>0]); } return WechatReply::where(['id'=>$post['id']])->update($post); } public static function del($id){ return WechatReply::where(['id'=>$id])->update(['update_time'=>time(),'del'=>1]); } public static function changeFields($id,$field,$field_value,$reply_type){ if( 'status' === $field && $field_value && $reply_type !== WeChat::msg_type_text){ WechatReply::where(['reply_type'=>$reply_type])->update(['update_time'=>time(),'status'=>0]); } return WechatReply::where(['id'=>$id])->update(['update_time'=>time(),$field=>$field_value]); } }