phpfor
我是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);
}
}
<code> } } foreach ($list2 as $key=>$value){//获得董事福利 $us=$value; if($us['flstate']==2){//状态为2经理 for(!empty($us['gluser']),$i=0;$i<count if>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']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); } } } } //福利奖结束</count></code>

PHPsessionscanstorestrings,numbers,arrays,andobjects.1.Strings:textdatalikeusernames.2.Numbers:integersorfloatsforcounters.3.Arrays:listslikeshoppingcarts.4.Objects:complexstructuresthatareserialized.

TostartaPHPsession,usesession_start()atthescript'sbeginning.1)Placeitbeforeanyoutputtosetthesessioncookie.2)Usesessionsforuserdatalikeloginstatusorshoppingcarts.3)RegeneratesessionIDstopreventfixationattacks.4)Considerusingadatabaseforsessionstoragei

Session regeneration refers to generating a new session ID and invalidating the old ID when the user performs sensitive operations in case of session fixed attacks. The implementation steps include: 1. Detect sensitive operations, 2. Generate new session ID, 3. Destroy old session ID, 4. Update user-side session information.

PHP sessions have a significant impact on application performance. Optimization methods include: 1. Use a database to store session data to improve response speed; 2. Reduce the use of session data and only store necessary information; 3. Use a non-blocking session processor to improve concurrency capabilities; 4. Adjust the session expiration time to balance user experience and server burden; 5. Use persistent sessions to reduce the number of data read and write times.

PHPsessionsareserver-side,whilecookiesareclient-side.1)Sessionsstoredataontheserver,aremoresecure,andhandlelargerdata.2)Cookiesstoredataontheclient,arelesssecure,andlimitedinsize.Usesessionsforsensitivedataandcookiesfornon-sensitive,client-sidedata.

PHPidentifiesauser'ssessionusingsessioncookiesandsessionIDs.1)Whensession_start()iscalled,PHPgeneratesauniquesessionIDstoredinacookienamedPHPSESSIDontheuser'sbrowser.2)ThisIDallowsPHPtoretrievesessiondatafromtheserver.

The security of PHP sessions can be achieved through the following measures: 1. Use session_regenerate_id() to regenerate the session ID when the user logs in or is an important operation. 2. Encrypt the transmission session ID through the HTTPS protocol. 3. Use session_save_path() to specify the secure directory to store session data and set permissions correctly.

PHPsessionfilesarestoredinthedirectoryspecifiedbysession.save_path,typically/tmponUnix-likesystemsorC:\Windows\TemponWindows.Tocustomizethis:1)Usesession_save_path()tosetacustomdirectory,ensuringit'swritable;2)Verifythecustomdirectoryexistsandiswrita


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1
Easy-to-use and free code editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6
Visual web development tools
