普通网友 2019-11-03 11:23 采纳率: 60%
浏览 217
已采纳

PHP数据逻辑处理数据耗时长,有什么方法处理得更快?

PHP业务逻辑处理数据库耗时长达超1分钟,如何修改才能处理的更快?请高手看看下?

function getodds($played,$user,$number=0,$ltyid=0,$lmoney=0,$PeriodsNumber=''){
//$commission=json_decode($user['commission'],true);
//$sjcommission=json_decode($user['sjcommission'],true);
$typearr=array(1,2,3,4,5,6,7);
$ltyid=in_array($ltyid,$typearr) ? $ltyid:1;
$zjpl=json_decode($user['commission'],true);
$commission=$zjpl[$ltyid];
$sjpl=json_decode($user['sjcommission'],true);
$sjcommission=$sjpl[$ltyid];
$bjresult=0;
$dfg=getodds_hm(strtoupper($number),$played,$user['id'],1,$ltyid,$lmoney);
if($dfg){
$bjresult=(float)$dfg;
}
else{
$dfg=getoddsend($played,$user['id'],1,$ltyid,0,$lmoney,$number,$PeriodsNumber);
if($dfg){
$bjresult=(float)$dfg;
}
}
$list=explode('/',$played['bonusprop']);
$clist=explode('/',$played['cbonusprop']);
if(count($list)==1){
$bonusprop=$list[0];
$cbonusprop=$clist[0];
}
else{
$number=$number;
$nlist=str_split($number);
$c=array_count_values($nlist);
$cfnum=count($nlist)-count($c);
$bonusprop=$list[$cfnum];
$cbonusprop=$clist[$cfnum];
}
$result=(float)($bonusprop-$cbonusprop*$sjcommission[$played['bettypeid']]['Commission']);

if($bjresult>0){
if(in_array($played['bettypeid'],array(2,3,4,5,6,7,17,18,25,26))){
$bjresult=$bjresult*100;
}
elseif(in_array($played['bettypeid'],array(9,10,11,12))){
$bjresult=$bjresult*1000;
}
elseif(in_array($played['bettypeid'],array(20,21,22,23,24))){
$bjresult=$bjresult*10;
}
elseif($played['bettypeid']==13){
$bjresult=$bjresult*10000;
}
elseif($played['bettypeid']==14){
$bjresult=$bjresult*10;
}
elseif($played['bettypeid']==15){
$bjresult=$bjresult*100;
}
elseif($played['bettypeid']==16){
$bjresult=$bjresult*1000;
}

$result=$result-$bjresult;

}
return $result;
}
function getodds_hm($hnumber='',$played,$userid,$isuser=0,$ltyid=0,$lmoney=0){
if($hnumber!=''){
if($played['bettypeid']==14 || $played['bettypeid']==15 || $played['bettypeid']==16){
$hnumber=preg_replace('/\D/','',$hnumber);
$jdfg=str_split($hnumber);
sort($jdfg);
$hnumber=implode('',$jdfg);
}
$where['lxid']=$ltyid;
$where['uid']=$userid;
$where['haoma']=$hnumber;
$where['flag']=1;
$where['playid']=$played['bettypeid'];

if($isuser){
    $where['isuser']=1;
    $user=M('user');
     $agent=$user->find($userid);
     $whereddc['user_login']=$agent['parent_user'];
     $parent=M('agent')->where($whereddc)->find();
}
else{
    $where['isuser']=0;
     $user=M('agent');
     $agent=$user->find($userid);
     $parent=M('agent')->find($agent['parent']);
 }

$dfg=M('peilv_biandong')->where($where)->find();

if($dfg){
    return $dfg['peilv'];
}
else{
    if(!$isuser && !$agent['parent']){
        return false;
    }
    return getodds_hm($hnumber,$played,$parent['id'],0,$ltyid,$lmoney);
}

}
return false;
}
function getoddsend($played,$userid,$isuser=0,$ltyid=0,$agentid=0,$lmoney=0,$hnumber='',$PeriodsNumber=''){
if($isuser){
$user=M('user');
$agent=$user->find($userid);
$whereddc['user_login']=$agent['parent_user'];
$parent=M('agent')->where($whereddc)->find();
}
else{
$user=M('agent');
$agent=$user->find($agentid);
$parent=M('agent')->find($agent['parent']);
}
$userw['playedId']=$played['id'];
$userw['typeid']=$ltyid;
$userw['sftm']=0;
if($PeriodsNumber!=''){
$userw['PeriodsNumber']=$PeriodsNumber;
}
if($hnumber!=''){
if($played['bettypeid']==14 || $played['bettypeid']==15 || $played['bettypeid']==16){
$hnumber=preg_replace('/\D/','',$hnumber);
$jdfg=str_split($hnumber);
sort($jdfg);
$hnumber=implode('',$jdfg);
}
//$userw['BetNumber']=$hnumber;
}
$mem=M('userbet'.$userid)->field("sum(BetAmount) as membetamt")->where($userw)->find();
//echo M('userbet'.$userid)->getLastSql();exit;
$dbfw=($mem['membetamt']) ? $mem['membetamt']+$lmoney:0+$lmoney;
if($dbfw>0){
$where['starxzl'] = array('lt',$dbfw);//小于
$where['endxzl'] = array('egt',$dbfw);//大于等于
}else{
$where['starxzl']=0;
}
$where['uid']=$agentid? $agentid:$userid;
$where['lxid']=$ltyid;
$where['playedId']=$played['bettypeid'];
$where['isuser']=0;
if($isuser){
$where['isuser']=1;
}
$dingpanlist=M('dingpan')->where($where)->order('peilv asc')->find();

if($dingpanlist){
    $result=$dingpanlist['peilv'];
    return $result;
}
else{
    if(!$number && !$agent['parent']){
        return false;
    }
    $whered['uid']=$agentid? $agentid:$userid;
    $whered['starxzl']  = array('gt',$dbfw);
    $whered['endxzl']  = array('elt',$dbfw);//大于等于
    $whered['lxid']=$ltyid;
    $whered['playedId']=$played['bettypeid'];
    $whered['isuser']=1;
    $dingpanlist=M('dingpan')->where($whered)->order('peilv asc')->find();
    if(!$dingpanlist){

        $isuser=0;
        $agentid=$parent['id'];
    }
    return getoddsend($played,$userid,$isuser,$ltyid,$agentid,$lmoney,$hnumber,$PeriodsNumber);
}

}
function getoddsup($played,$user,$number=0,$ltyid=0){
//$commission=json_decode($user['commission'],true);
//$sjcommission=json_decode($user['sjcommission'],true);
$typearr=array(1,2,3,4,5,6,7);
$ltyid=in_array($ltyid,$typearr) ? $ltyid:1;
$zjpl=json_decode($user['commission'],true);
$commission=$zjpl[$ltyid];
$sjpl=json_decode($user['sjcommission'],true);
$sjcommission=$sjpl[$ltyid];
$list=explode('/',$played['bonusprop']);
$clist=explode('/',$played['cbonusprop']);
if(count($list)==1){
$bonusprop=$list[0];
$cbonusprop=$clist[0];
}
else{
$number=$number;
$nlist=str_split($number);
$c=array_count_values($nlist);
$cfnum=count($nlist)-count($c);
$bonusprop=$list[$cfnum];
$cbonusprop=$clist[$cfnum];
}
return (float)($cbonusprop*$sjcommission[$played['bettypeid']]['Commission']);

展开全部

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-11-03 12:17
    关注

    getodds_hm
    这个存在递归调用,你在每个函数开头结束输出下时间,看每个函数调用的时间和次数,找到哪里耗时多,然后看看查询是否可以优化,比如加上索引或者简化查询

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 pycharm倒入虚拟环境的时候,显示这个,但是我的虚拟环境已经创建了
  • ¥15 FPGA芯片60进制计数器
  • ¥15 前端js怎么实现word的.doc后缀文件在线预览
  • ¥20 macmin m 4连接iPad
  • ¥15 DBIF_REPO_SQL_ERROR
  • ¥15 根据历年月数据,用Stata预测未来六个月汇率
  • ¥15 DevEco studio开发工具 真机联调找不到手机设备
  • ¥15 请教前后端分离的问题
  • ¥100 冷钱包突然失效,急寻解决方案
  • ¥15 下载honeyd时报错 configure: error: you need to instal a more recent version of libdnet
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部