Home > Backend Development > PHP Tutorial > php for 循环思路有关问题

php for 循环思路有关问题

WBOY
Release: 2016-06-13 12:14:13
Original
1052 people have browsed it

php for 循环思路问题
我是PHP新手,最近开发项目求二叉树体系的福利奖。写完后执行效率太低。求高手大神指点一下思路。图片说明
1.左右业绩达到1W就是主管。 管理体系下有2个主管就是经理。管理体系下有2个经理就是董事。 0会员,1主管,2经理,3董事。
我写的代码如下:
//福利奖开始
unset($map);//销毁map变量值
$map['_string']=" datediff(curday,'".$beginday."') //查询所有会员业绩
$hyyjlist=$hyyj->where($map)->field(' userid,sum(leftyj1)+sum(leftyj2) as sumleft')->group('userid')->select();
$glrCountArry=array();//key:主管name+flrjl value:人数  保存主管人数的 数组
foreach ($hyyjlist as $hkey=>$hvalue){//循环更新用户的主管福利
if($hvalue['sumleft']>=10000){
$us=$userListArry[$hvalue['userid']];//3根据ID获得会员
if($us['flstate']==0){//状态是0 会员
if($salary1->where(array('periods'=>$periods,'userid'=>$us['id']))->setField(array('flj'=>'z主管奖内容z'))===false){
$salary->rollback();
$this->error('福利奖更新失败');
}
for(!empty($us['gluser']),$i=0;$i if(!array_key_exists($us['gluser']."flrzg", $glrCountArry)){
$glrCountArry[$us['gluser']."flrzg"]=1;
}else{
$glrCountArry[$us['gluser']."flrzg"]+=1;
}
$us=$userNameListArry[$us['gluser']];
if(empty($us)){
$i=count($userlist);
}
}
}
}
}
$find['state']=array('eq',1);//状态=1激活
$find['_string']="from_unixtime(confirmtime,'%Y-%m-%d') $list2=$users->where($find)->select();//查询会员列表
$glrCountArry2=array();// key:经理name+flrjl value:人数  保存经理人数的 数组
foreach ($list2 as $key=>$value){//获得经理福利
$us=$value;
if($us['flstate']==1){
for(!empty($us['gluser']),$i=0;$i if($glrCountArry[$us['username']."flrzg"]>0){//会员是主管级别,主管数组的人数大于0 更新会员的经理福利
if($salary1->where(array('periods'=>$periods,'userid'=>$us['id']))->setField(array('flj'=>'z经理奖内容z'))===false){
$salary->rollback();
$this->error('福利奖更新失败2');
}
}
if(!array_key_exists($us['gluser']."flrjl", $glrCountArry2)){//使会员的上层经理+1
$glrCountArry2[$us['gluser']."flrjl"]=1;
}else{
$glrCountArry2[$us['gluser']."flrjl"]+=1;
}
$us=$userNameListArry[$us['gluser']];
if(empty($us)){
$i=count($userlist);
}
}
}else if($value['flstate']==0){//会员等级不是主管,主管数组的人数大于1 更新会员的经理福利
for(!empty($us['gluser']),$i=0;$i if($glrCountArry[$us['username']."flrzg"]>1){//会员是主管级别,主管数组的人数大于0 更新会员的经理福利
if($salary1->where(array('periods'=>$periods,'userid'=>$us['id']))->setField(array('flj'=>'z经理奖内容z'))===false){
$salary->rollback();
$this->error('福利奖更新失败2');
}
}
if(!array_key_exists($us['gluser']."flrjl", $glrCountArry2)){//使会员的上层经理+1
$glrCountArry2[$us['gluser']."flrjl"]=1;
}else{
$glrCountArry2[$us['gluser']."flrjl"]+=1;
}
$us=$userNameListArry[$us['gluser']];
if(empty($us)){
$i=count($userlist);
}
}

}
}
foreach ($list2 as $key=>$value){//获得董事福利
$us=$value;
if($us['flstate']==2){//状态为2经理
for(!empty($us['gluser']),$i=0;$i if($glrCountArry2[$us['username']."flrjl"]>0){//会员是经理级别,经理数组的人数大于0 更新会员的董事福利
if($salary1->where(array('periods'=>$periods,'userid'=>$us['id']))->setField(array('flj'=>'z董事奖内容z'))===false){
$salary->rollback();
$this->error('福利奖更新失败3');
}
}
$us=$userNameListArry[$us['gluser']];
if(empty($us)){
$i=count($userlist);
}
}
}else if($value['flstate'] for(!empty($us['gluser']),$i=0;$i if($glrCountArry2[$us['username']."flrjl"]>1){//会员是经理级别,经理数组的人数大于1 更新会员的董事福利
if($salary1->where(array('periods'=>$periods,'userid'=>$us['id']))->setField(array('flj'=>'z董事奖内容z'))===false){
$salary->rollback();
$this->error('福利奖更新失败3');
}
}
$us=$userNameListArry[$us['gluser']];
if(empty($us)){
$i=count($userlist);
}
}
}
}
//福利奖结束
------解决思路----------------------
表结构是怎样的?应该用 update 指令就可完成的

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template