123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?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` where order_balance_at>=:stime and order_balance_at<:etime and status=2 and maintain_power<3 and type!=7 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 where type=:type and user_id=:user_id and create_at>:etime and create_at<:ntime and is_red=0";
- $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;
- }
- try{
- $sql = "UPDATE account_detail 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{
- $fail++;
- }
- }catch(Exception $e){
- echo "err_msg:".$e->getMessage()." user_id".$v['user_id']."\n";
- $fail++;
- continue;
- }
- }
- echo "成功结算笔数:".$success."\n";
- echo "失败结算笔数:".$fail."\n";
- echo "黑名单用户数:".$blackcount."\n";
-
|