12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?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 );
- #排除黑名单用户
- $black_users = [];
- /*
- $sql = "SELECT value FROM global_variable WHERE variable_key ='relation_blacklist' ";
- $stmt = $_PDO->prepare($sql);
- $stmt->execute();
- $black = $stmt->fetch(PDO::FETCH_ASSOC);
- if( !empty($black) ){
- $blacklist = trim($black['value']);
- $sql = " SELECT user_id from user_special_relation where relation_id in (".$blacklist.") ";
- $stmt = $_PDO->prepare($sql);
- $stmt->execute();
- $black_user = $stmt->fetchAll(PDO::FETCH_ASSOC);
- if( !empty($black_user) ){
- $black_users = array_column($black_user, 'user_id');
- }
- }
- */
- #查询上月份结算信息
- $stime = date('2019-12-01').' 00:00:00';
- $etime = date('2020-01-01').' 00:00:00';
- $ntime = date('2020-01-26').' 00:00:00';
- $sql = "SELECT user_id,sum(rebate) as money from `order_rebate_profit` where order_balance_at>=:stime and order_balance_at<:etime and status=2 and maintain_power<3 group by user_id ";
- echo "beginTime:".$stime." -> endTime:".$etime."\n";
- $stmt = $_PDO->prepare($sql);
- $stmt->execute(array(':stime'=>$stime,':etime'=>$etime));
- $rebateInfo = $stmt->fetchAll(PDO::FETCH_ASSOC);
- if( empty($rebateInfo) ){
- exit('未获取到上月结算信息'."\n");
- }
- $totalcount = count($rebateInfo);
- $success = 0;
- $fail = 0;
- $already = 0;
- $blackcount = 0;
- foreach( $rebateInfo as $k=>$v){
- if( in_array($v['user_id'], $black_users) ){
- //黑名单用户跳过
- $blackcount++;
- echo "黑名单用户跳过user_id:".$v['user_id']."\n";
- continue;
- }
- $sql = "SELECT id from account_detail_profit where type=:type and user_id=:user_id and create_at>:etime and create_at<:ntime";
- $stmt = $_PDO->prepare($sql);
- $stmt->execute(array(':user_id'=>$v['user_id'],':type'=>1,':etime'=>$etime, ':ntime'=>$ntime));
- $res = $stmt->fetch(PDO::FETCH_ASSOC);
- if( empty($res) ){
- echo "多多!!!用户跳过user_id:".$v['user_id']."\n";
- continue;
- }
- $id = $res['id'];
- try{
- $sql = "UPDATE account_detail_profit set rebate=:rebate where id=:id";
- $stmt = $_PDO->prepare($sql);
- $stmt->execute(array(':id'=>$res['id'],':rebate'=>$v['money']));
- $res = $stmt->rowCount();
- echo "更新结果:".$res."\n";
- if($res){
- $success++;
- }else{
- echo "失败".$id.' '.$v['money']."\n";
- $fail++;
- }
- }catch(Exception $e){
- echo "未知异常 user_id".$v['user_id']."\n";
- $fail++;
- continue;
- }
- }
- echo "成功结算笔数:".$success."\n";
- echo "失败结算笔数:".$fail."\n";
- echo "黑名单用户数:".$blackcount."\n";
-
|