批量修改粉絲分組,粉絲分組
1:全選和反選
全選:
<input type="checkbox" id="selectAll">
列表:
<input type="checkbox" name="ids" value="'+data.openid+'" >'
js效果:
//全選、反選$(function() { $("#selectAll").click(function() { $("input[name='ids']").prop("checked", this.checked); }); $("input[name='ids']").click(function() { var $ids = $("input[name='ids']"); $("#selectAll").prop("checked",$ids.length ==$ids.filter(":checked").length ? true :false); }); });function _bindCheckboxClick(){ $("input[name='ids']").click(function() { var $ids = $("input[name='ids']"); $("#selectAll").prop("checked",$ids.length ==$ids.filter(":checked").length ? true :false); });}
修改:
function batchMove(){ //擷取最新分組id var wxGroupId = $("#groupBathList").val(); //擷取選擇的粉絲集合 var openidArr = new Array; $("input[type=checkbox][name=ids]:checked").each(function(i){ openidArr[i] = $(this).val(); }); //轉換為逗號隔開的字串 var openids = openidArr.join(','); //提交動作 var url = "<%=basePath%>"; url = url + "fan/op/batchUpdateFan.shtml"; var params = {}; params.openids = openids; params.wxGroupId = wxGroupId; $.post(url, params, function (data) { if (data.success == 1) { $('#errmsg').calert('alert',"修改成功!"); query(); } },"json"); }
幕後處理:
public String batchUpdateFan(){ try { map = new HashMap<String, Object>(); map.put("success", 1); // 需要同步的公眾號id WxAccount wxAccount_session = getSessUser().getWxAccount_session(); String access_token =WxConstant.getRealAccessToken(wxAccount_session.getAccountappid()); if(StringUtils.isNotNull(openids)){ List<String> openidList = StringUtils.stringToListStr(openids, ","); if(openidList != null && openidList.size() >0){ for(String openid :openidList){ Fan fan = new Fan(); fan.setOpenid(openid); fan = fanService.getFan(fan); if(fan!= null){ fan.setWxGroupId(Integer.parseInt(wxGroupId)); fanService.updateFan(fan); } } } // 同步處理的使用者分組 String batchMoveUserToGroupUrl = WxConstant.getBatchMoveUserToGroupUrl(access_token); JSONObject jsonObject = new JSONObject(); jsonObject.put("openid_list", openidList); HttpUtils.post(batchMoveUserToGroupUrl, g.toJson(jsonObject)); } } catch (Exception e) { e.printStackTrace(); map.put("success", 0); map.put("errMsg", e.getMessage()); } return "toResult"; }
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。