0, 'insert_num' => 0, 'fail_num' => 0, 'update_num' => 0, 'nshoud_update_num' =>0 , ); #初始化pdo $_PDO=DB_PDO::getInstance( conf::$DB_CONF ); foreach($orderResult as $k=>$orderDetail){ $res_count['total_num']++; echo "/ ************************ order{$res_count['total_num']}-Start ************************* / \n"; if(!isset($orderDetail['tk_earning_time'])) $orderDetail['tk_earning_time'] = '2000-00-00 00:00:00'; if(!isset($orderDetail['click_time'])) $orderDetail['click_time'] = $orderDetail['tk_create_time']; if(!isset($orderDetail['special_id'])) $orderDetail['special_id'] = 0; if(!isset($orderDetail['relation_id'])) $orderDetail['relation_id'] = 0; if(!isset($orderDetail['total_commission_fee'])) $orderDetail['total_commission_fee'] = 0; if(!isset($orderDetail['subsidy_fee'])) $orderDetail['subsidy_fee'] = 0; if(!isset($orderDetail['pay_price'])) $orderDetail['pay_price'] = 0; if(!isset($orderDetail['pub_share_fee'])) $orderDetail['pub_share_fee'] = 0; if(!isset($orderDetail['subsidy_type'])) $orderDetail['subsidy_type'] = 0; if(!isset($orderDetail['flow_source'])) $orderDetail['flow_source'] = '--'; if(!isset($orderDetail['site_name'])) $orderDetail['site_name'] = ''; if(!isset($orderDetail['adzone_name'])) $orderDetail['adzone_name'] = ''; echo 'order_id:'.$orderDetail['trade_id'].'|| goods_id:'.$orderDetail['item_id'].'|| orderstatus:'.$orderDetail['tk_status'].'|| order_balance_at:'.$orderDetail['tk_earning_time'].'|| order_create_time:'.$orderDetail['tk_create_time']; if( DETAILDEBUG == 1){ echo 'orderDetail:'; var_dump($orderDetail); } # 花生联盟活跃relation逻辑 if($orderDetail['adzone_id'] == '102465800487'){ $hs_res = hslmSyncOrder($orderDetail); continue; } $sql = "select id,tk_status from liedou_taoke_orders where trade_id = '".$orderDetail['trade_id']."' and num_iid = '".$orderDetail['item_id']."' limit 1"; $stmt = $_PDO->prepare($sql); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); if(!empty($result)){ echo "\n 该订单已存在,更新操作"; if($orderDetail['tk_status'] != $result['tk_status']){ //更新操作 $sql = "update liedou_taoke_orders set tk_status={$orderDetail['tk_status']},earning_time='".$orderDetail['tk_earning_time']."' WHERE trade_id = '".$orderDetail['trade_id']."' and num_iid = '".$orderDetail['item_id']."'"; $stmt = $_PDO->prepare($sql); $stmt->execute(); $res = $stmt->rowCount(); if($res){ echo "\n 更新成功 +1"; $res_count['update_num']++; }else{ echo "\n 更新失败 +1"; $res_count['fail_num']++; } }else{ echo "\n 状态未变,不做处理 +1"; $res_count['nshoud_update_num']++; } }else{ //create_time,click_time,item_title,num_iid,seller_nick,seller_shop_title,item_num,price,tk_status,order_type,income_rate,commission_rate,pay_price,pub_share_pre_fee,alipay_total_price,commission,earning_time,total_commission_rate,total_commission_fee,subsidy_rate,subsidy_fee,subsidy_type,terminal_type,tk3rd_type,trade_parent_id,trade_id,auction_category,site_id,site_name,adzone_id,adzone_name,relation_id,special_id $res = insertOrder($orderDetail,$res_count); } echo "\n/ ** order{$res_count['total_num']}-End ** /"; } echo "\n同步订单:"; var_dump($res_count); } /** * 同步结算订单 */ function sync_balances($_time,$now){ //同步订单脚本 # 1.同步3分钟内结算订单 $stime = date("Y-m-d H:i:s", $now-$_time); $etime = date("Y-m-d H:i:s"); $orderResult = array(); $time_type = 3;//按结算时间查 $tk_status = 3;//查询结算状态订单 $position_index = '';//查下一页必要参数 //渠道 for($i=1;$i<100;$i++){ $res = TBK::syncOrderNew($i,$stime, $etime, $time_type ,$tk_status,2,$position_index); if(empty($res)){ break; }else{ $orderData = $res['data']; $position_index = $res['position_index']; } $orderResult = array_merge($orderResult, $orderData); } $position_index = ''; //会员 for($i=1;$i<100;$i++){ $res = TBK::syncOrderNew($i,$stime, $etime, $time_type ,$tk_status,3,$position_index); if(empty($res)){ break; }else{ $orderData = $res['data']; $position_index = $res['position_index']; } $orderResult = array_merge($orderResult, $orderData); } # 统计 $res_count = array( 'total_num' => 0, 'insert_num' => 0, 'update_num' => 0, 'fail_num' => 0, 'nshoud_update_num' =>0 , ); #初始化pdo $_PDO=DB_PDO::getInstance( conf::$DB_CONF ); foreach($orderResult as $k=>$orderDetail){ $res_count['total_num']++; echo "/ ************************ order{$res_count['total_num']}-Start ************************* / \n"; # 花生联盟活跃relation逻辑 //结算逻辑跳过 if($orderDetail['adzone_id'] == '102465800487'){ echo "\n花生订单跳过\n"; continue; } if(!isset($orderDetail['tk_earning_time'])) $orderDetail['tk_earning_time'] = '2000-00-00 00:00:00'; if(!isset($orderDetail['click_time'])) $orderDetail['click_time'] = $orderDetail['tk_create_time']; if(!isset($orderDetail['special_id'])) $orderDetail['special_id'] = 0; if(!isset($orderDetail['relation_id'])) $orderDetail['relation_id'] = 0; if(!isset($orderDetail['total_commission_fee'])) $orderDetail['total_commission_fee'] = 0; if(!isset($orderDetail['subsidy_fee'])) $orderDetail['subsidy_fee'] = 0; if(!isset($orderDetail['pay_price'])) $orderDetail['pay_price'] = 0; if(!isset($orderDetail['pub_share_fee'])) $orderDetail['pub_share_fee'] = 0; if(!isset($orderDetail['subsidy_type'])) $orderDetail['subsidy_type'] = 0; if(!isset($orderDetail['flow_source'])) $orderDetail['flow_source'] = '--'; if(!isset($orderDetail['site_name'])) $orderDetail['site_name'] = ''; if(!isset($orderDetail['adzone_name'])) $orderDetail['adzone_name'] = ''; if(!isset($orderDetail['pub_share_pre_fee'])) $orderDetail['pub_share_pre_fee'] = 0; if(!isset($orderDetail['alipay_total_price'])) $orderDetail['alipay_total_price'] = 0; echo 'order_id:'.$orderDetail['trade_id'].'|| goods_id:'.$orderDetail['item_id'].'|| orderstatus:'.$orderDetail['tk_status'].'|| order_balance_at:'.$orderDetail['tk_earning_time']; if( DETAILDEBUG == 1){ echo 'orderDetail:'; var_dump($orderDetail); } $sql = "select id,tk_status from liedou_taoke_orders where trade_id = '".$orderDetail['trade_id']."' and num_iid = '".$orderDetail['item_id']."' limit 1"; $stmt = $_PDO->prepare($sql); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); if(!empty($result)){ if($orderDetail['tk_status'] != $result['tk_status']){ //更新操作 $sql = "update liedou_taoke_orders set tk_status={$orderDetail['tk_status']},earning_time='".$orderDetail['tk_earning_time']."' WHERE trade_id = '".$orderDetail['trade_id']."' and num_iid = '".$orderDetail['item_id']."'"; $stmt = $_PDO->prepare($sql); $stmt->execute(); $res = $stmt->rowCount(); if($res){ echo "\n 处理成功 +1"; $res_count['update_num']++; }else{ echo "\n 处理失败 +1"; $res_count['fail_num']++; } }else{ echo "\n 状态未变,不做处理 +1"; $res_count['nshoud_update_num']++; } }else{ //create_time,click_time,item_title,num_iid,seller_nick,seller_shop_title,item_num,price,tk_status,order_type,income_rate,commission_rate,pay_price,pub_share_pre_fee,alipay_total_price,commission,earning_time,total_commission_rate,total_commission_fee,subsidy_rate,subsidy_fee,subsidy_type,terminal_type,tk3rd_type,trade_parent_id,trade_id,auction_category,site_id,site_name,adzone_id,adzone_name,relation_id,special_id $res = insertOrder($orderDetail, $res_count); } echo "\n/ ** order{$res_count['total_num']}-End ** /"; } echo "\n结算订单:"; var_dump($res_count); } function insertOrder($orderDetail, &$res_count){ $orderDetail['item_title'] = addslashes($orderDetail['item_title']); $orderDetail['seller_nick'] = addslashes($orderDetail['seller_nick']); $orderDetail['seller_shop_title'] = addslashes($orderDetail['seller_shop_title']); $sql = "insert into liedou_taoke_orders(create_time,click_time,item_title,num_iid,seller_nick,seller_shop_title,item_num,price,tk_status,order_type,income_rate,commission_rate,pay_price,pub_share_pre_fee,alipay_total_price,commission,earning_time,total_commission_rate,total_commission_fee,subsidy_rate,subsidy_fee,subsidy_type,terminal_type,tk3rd_type,trade_parent_id,trade_id,auction_category,site_id,site_name,adzone_id,adzone_name,relation_id,special_id,tb_paid_time) values('".$orderDetail['tk_create_time']."', '". $orderDetail['click_time']."', '". $orderDetail['item_title']."', '". $orderDetail['item_id']."', '". $orderDetail['seller_nick']."', '". $orderDetail['seller_shop_title']."', '". $orderDetail['item_num']."', '". $orderDetail['item_price']."', '". $orderDetail['tk_status']."', '". $orderDetail['order_type']."', '". $orderDetail['income_rate']."', '". $orderDetail['pub_share_rate']."', '". $orderDetail['pay_price']."', '". $orderDetail['pub_share_pre_fee']."', '". $orderDetail['alipay_total_price']."', '". $orderDetail['pub_share_fee']."', '". $orderDetail['tk_earning_time']."', '". $orderDetail['total_commission_rate']."', '". $orderDetail['total_commission_fee']."', '". $orderDetail['subsidy_rate']."', '". $orderDetail['subsidy_fee']."', '". $orderDetail['subsidy_type']."', '". $orderDetail['terminal_type']."', '". $orderDetail['flow_source']."', '". $orderDetail['trade_parent_id']."', '". $orderDetail['trade_id']."', '". $orderDetail['item_category_name']."', '". $orderDetail['site_id']."', '". $orderDetail['site_name']."', '". $orderDetail['adzone_id']."', '". $orderDetail['adzone_name']."', '". $orderDetail['relation_id']."', '". $orderDetail['special_id']."', '". $orderDetail['tb_paid_time']."')"; $_PDO=DB_PDO::getInstance( conf::$DB_CONF ); $stmt = $_PDO->prepare($sql); $stmt->execute(); $res = $_PDO->lastinsertid(); if($res){ echo "\n 插入成功 +1"; $res_count['insert_num']++; }else{ echo "\n 插入失败 +1"; $res_count['fail_num']++; } return $res; } function hslmSyncOrder($orderDetail){ $_PDO=DB_PDO::getInstance( conf::$DB_CONF ); $sql = "select id,tk_status from hslm_taoke_orders where trade_id = '".$orderDetail['trade_id']."' and num_iid = '".$orderDetail['item_id']."' limit 1"; $stmt = $_PDO->prepare($sql); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); if(!empty($result)){ if($orderDetail['tk_status'] != $result['tk_status']){ //更新操作 $sql = "update hslm_taoke_orders set tk_status={$orderDetail['tk_status']},earning_time='".$orderDetail['tk_earning_time']."' WHERE trade_id = '".$orderDetail['trade_id']."' and num_iid = '".$orderDetail['item_id']."'"; $stmt = $_PDO->prepare($sql); $stmt->execute(); $res = $stmt->rowCount(); if($res){ echo "\n 处理成功 +1"; }else{ echo "\n 处理失败 +1"; } }else{ echo "\n 状态未变,不做处理 +1"; } }else{ //create_time,click_time,item_title,num_iid,seller_nick,seller_shop_title,item_num,price,tk_status,order_type,income_rate,commission_rate,pay_price,pub_share_pre_fee,alipay_total_price,commission,earning_time,total_commission_rate,total_commission_fee,subsidy_rate,subsidy_fee,subsidy_type,terminal_type,tk3rd_type,trade_parent_id,trade_id,auction_category,site_id,site_name,adzone_id,adzone_name,relation_id,special_id $res = hslminsertOrder($orderDetail); } } function hslminsertOrder($orderDetail){ $orderDetail['item_title'] = addslashes($orderDetail['item_title']); $orderDetail['seller_nick'] = addslashes($orderDetail['seller_nick']); $orderDetail['seller_shop_title'] = addslashes($orderDetail['seller_shop_title']); $sql = "insert into hslm_taoke_orders(create_time,click_time,item_title,num_iid,seller_nick,seller_shop_title,item_num,price,tk_status,order_type,income_rate,commission_rate,pay_price,pub_share_pre_fee,alipay_total_price,commission,earning_time,total_commission_rate,total_commission_fee,subsidy_rate,subsidy_fee,subsidy_type,terminal_type,tk3rd_type,trade_parent_id,trade_id,auction_category,site_id,site_name,adzone_id,adzone_name,relation_id,special_id, tb_paid_time) values('".$orderDetail['tk_create_time']."', '". $orderDetail['click_time']."', '". $orderDetail['item_title']."', '". $orderDetail['item_id']."', '". $orderDetail['seller_nick']."', '". $orderDetail['seller_shop_title']."', '". $orderDetail['item_num']."', '". $orderDetail['item_price']."', '". $orderDetail['tk_status']."', '". $orderDetail['order_type']."', '". $orderDetail['income_rate']."', '". $orderDetail['pub_share_rate']."', '". $orderDetail['pay_price']."', '". $orderDetail['pub_share_pre_fee']."', '". $orderDetail['alipay_total_price']."', '". $orderDetail['pub_share_fee']."', '". $orderDetail['tk_earning_time']."', '". $orderDetail['total_commission_rate']."', '". $orderDetail['total_commission_fee']."', '". $orderDetail['subsidy_rate']."', '". $orderDetail['subsidy_fee']."', '". $orderDetail['subsidy_type']."', '". $orderDetail['terminal_type']."', '". $orderDetail['flow_source']."', '". $orderDetail['trade_parent_id']."', '". $orderDetail['trade_id']."', '". $orderDetail['item_category_name']."', '". $orderDetail['site_id']."', '". $orderDetail['site_name']."', '". $orderDetail['adzone_id']."', '". $orderDetail['adzone_name']."', '". $orderDetail['relation_id']."', '". $orderDetail['special_id']."', '". $orderDetail['tb_paid_time']."')"; $_PDO=DB_PDO::getInstance( conf::$DB_CONF ); $stmt = $_PDO->prepare($sql); $stmt->execute(); $res = $_PDO->lastinsertid(); if($res){ //更新redis $redis = RedisModel::srem( 'PEANUT_LIEDOU_RELATION_ID', $orderDetail['relation_id'] ); echo "\n 插入成功 +1"; }else{ echo "\n 插入失败 +1"; } return $res; }