='{$stime}' order by id "; echo "beginTime:".$stime." -> endTime:now"."\n"; $stmt = $_PDO->prepare($sql); $stmt->execute(); $accountInfo = $stmt->fetchAll(PDO::FETCH_ASSOC); echo "共:".count($accountInfo)."\n"; sleep(1); if( empty($accountInfo) ){ exit('未获取到需要清洗数据'."\n"); } $x = 0; foreach($accountInfo as $account){ #查余额,对比 $user_id = $account['user_id']; $id = $account['id']; $balance = get_balance($user_id, $id); if($balance < $account['rebate']){ if($balance < 0 ){ echo "\n 负值意外!! id:".$id; continue; } //提现过多,清洗 if($balance>2){ $ideal = $balance - 2; //预留0.2元以防意外 } else { $ideal = $balance; } $result = acc_xi($id, $ideal, $account['rebate']); $x++; } } echo "\n 总共清洗:".$x; function acc_xi($id, $ideal, $old){ $_PDO=DB_PDO::getInstance( conf::$DB_ONLINE_CONF ); try{ $sql = "UPDATE account_detail_profit set rebate=:rebate where id=:id"; $stmt = $_PDO->prepare($sql); $stmt->execute(array(':id'=>$id,':rebate'=>$ideal)); $res = $stmt->rowCount(); if(!$res){ echo "更新失败: iD:".$id. ' 结果:'.$res."\n"; } else { $money = $ideal/100; $sql = "UPDATE account_alipay_detail_profit set money = {$money} where detail_id = {$id}"; $stmt = $_PDO->prepare($sql); $stmt->execute(); $res = $stmt->rowCount(); echo "更新成功:iD:".$id. ' 钱: '.$old. '=> '. $ideal.'<->'.$money.' 结果:'.$res."\n"; } }catch(Exception $e){ echo "err_msg:".$e->getMessage()." id:".$id."\n"; } } function get_balance($user_id, $id){ $_PDO=DB_PDO::getInstance( conf::$DB_ONLINE_CONF ); $sql = " select sum(rebate) as money from account_detail_profit where user_id = {$user_id} and type=1 and id< {$id} "; $stmt = $_PDO->prepare($sql); $stmt->execute(); $a1 = $stmt->fetch(PDO::FETCH_ASSOC); $sql = "SELECT sum(rebate) as money from account_detail_profit where user_id = {$user_id} and type=2 and state_of_embodiment in(0,1) and id<{$id} "; $stmt = $_PDO->prepare($sql); $stmt->execute(); $a2 = $stmt->fetch(PDO::FETCH_ASSOC); $money2 = 0; if( isset($a2['money']) ){ $money2 = $a2['money']; } $balance = $a1['money'] - $money2; return $balance; }