<!-- 前端代码部分-->
<div class="pop-movegroup" id="salesmanBox"> <dl> <dt>选择推广账号:</dt> <dd>
<!-- 一级联动的数据先查询遍历出来--> <select name="salesman" id="salesman"> <volist name="salesman" id="vo"> <option value="{$vo.id}">{$vo.uname}</option> </volist> </select> <!-- 二级联动--> <select name="lib" id="libs"> </select> </dd> <dd class="center"> <input type="hidden" id=‘uid‘ value="{$_GET[‘uid‘]|intval}"> <input type="button" class="btn_b mr10" value="确认" onclick="admin.domoveSalesUser()"> <input type="button" class="btn_w" value="取消" onclick="ui.box.close()"> </dd> </dl> </div>
js部分:
<script type="text/javascript">
//点击一级联动里面的选项 获取id 然后去查询对应的数据
$("#salesman").change(function(){
//获取id var catid=$("#salesman").val(); //将id提交到后台 $.post("{:U(‘admin/User/doAddSalesUsers‘)}","id="+catid,function(data){ //清空二级联动 $("#libs").empty(); //console.log(data); var count = data.data.length; var i = 0; var b="";
//根据后端所返回的数据 去展示对应的数据 for(i=0;i<count;i++){ b+="<option value=‘"+data.data[i].uid+"‘>"+data.data[i].uname+"</option>"; } $("#libs").append(b); }); }); //点击二级菜单里面的数据 admin.domoveSalesUser = function(){
//获取id var id = $(‘#libs‘).val(); if(!id){ ui.error( ‘没有选中推广账户‘ );return false; }
//开始进行绑定 var uid = $(‘#uid‘).val(); $.post(U(‘admin/User/doAddSalesUser‘),{uid:uid,sid:id},function(msg){ ajaxReload(msg); //location.href = U(‘admin/User/index‘); },‘json‘); }; </script>
后端代码部分:
public function doAddSalesUsers() { $id = $_POST[‘id‘]; $data = model("SalesmanEntity")->where("sid = " . $id)->select(); $this->ajaxReturn($data, "JSON"); } public function doAddSalesUser() { $return = array(‘status‘ => ‘0‘, ‘data‘ => ‘绑定推广账号失败‘); $uid = !empty($_POST[‘uid‘])? intval($_POST[‘uid‘]) : 0; //yonghuid // var_dump($uid); $sid = !empty($_POST[‘sid‘])? intval($_POST[‘sid‘]) : 0; //suoshuzuid //var_dump($sid); // var_dump($dataArray); if(empty($uid) || empty($sid)){ $return[‘data‘] = "数据无效!"; exit(json_encode($return)); } //去salesman_entity表中去查询该女性id所属用户组 $dataArray = M(‘salesman_entity‘)->where("uid=". $_POST[‘sid‘])->field("sid")->select(); //var_dump($dataArray); $idss = array_column($dataArray,‘sid‘); //invite_id $yqId = $idss[0]; //女性用户id $user = model(‘User‘)->where(‘uid=‘.$uid)->find(); if($user[‘invite_id‘]>0){ $this->error("该用户已被绑定!"); } $datas = array(‘invite_id‘=>$yqId,‘sid‘=>$sid); //开始绑定 if(model(‘User‘)->where(‘uid=‘.$uid)->setField(‘invite_id‘,$yqId) && model(‘User‘)->where(‘uid=‘.$uid)->setField(‘sid‘,$sid)){ $return = array(‘status‘ => 1, ‘data‘ => ‘用户绑定成功‘); } exit(json_encode($return)); }