123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- #佣金结算脚本
- define( "ROOT_PATH", dirname(dirname(__FILE__)) );
- require_once ROOT_PATH.'/DB_PDO.class.php';
- require_once ROOT_PATH.'/confv2.class.php';
- #连接数据库
- $_PDO=DB_PDO::getInstance( conf::$DB_ONLINE_CONF );
- $stime = !empty($argv[1]) ? $argv[1] : date('Y-m-d H:i:s', strtotime('-1 hour'));
- $sql = "SELECT id, user_id, rebate from `account_detail_profit` where type=2 and state_of_embodiment in(0,1) and update_at>='{$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;
- }
|