//跟据帐号来查询出重复的订单
$sql_accounts = ‘select `wish_account` from wish_accounts where t_id=0‘;
$res = mysql_query($sql_accounts);
while($row = mysql_fetch_array($res)){
//这个跟据卖家id(其实就是一个唯一值)来筛选出重复的数据。
$sql = "SELECT count(0) as num,erp_orders_id,buyer_id,sales_account,orders_export_time
FROM erp_orders
WHERE sales_account=‘".$row[‘wish_account‘]."‘
AND orders_export_time>‘".date(‘Y-m-d H:i:s‘,time()-86400*3)."‘
AND orders_status in (1,3)
AND orders_total>0
GROUP BY sales_account,buyer_id
HAVING num>1
ORDER BY erp_orders_id ASC";
echo $sql."\n";
echo "<br />";
$result=mysql_query($sql);
//print_r($result);exit;
//跟据上面的重复的数据,我们又在筛选出重复数据中的那些重复数据。
while($order_list=mysql_fetch_array($result)){
$sql = "SELECT erp_orders_id,buyer_id,orders_type,sales_account,orders_export_time
FROM erp_orders
WHERE sales_account=‘".$order_list[‘sales_account‘]."‘
AND buyer_id=‘".$order_list[‘buyer_id‘]."‘
AND orders_export_time>‘".date(‘Y-m-d H:i:s‘,time()-86400*3)."‘
AND orders_status in(1,3)
AND orders_total>0
ORDER BY erp_orders_id ASC";
echo $sql."\n";
echo "<br />";
$_result=mysql_query($sql);
/*过滤第一条*/
mysql_fetch_array($_result);
while($order_list_temp=mysql_fetch_array($_result)){
echo "-----------------------------------------------\n";
echo "erp_orders_id:".$order_list_temp[‘erp_orders_id‘].
" orders_type:".$order_list_temp[‘orders_type‘].
" buyer_id:".$order_list_temp[‘buyer_id‘];
echo "\n";
// $sql="update erp_orders set orders_type=-1,buyer_id=‘".$order_list_temp[‘buyer_id‘].
// "_del‘ where erp_orders_id=‘".$order_list_temp[‘erp_orders_id‘]."‘";
// $sql ="delete from erp_orders where erp_orders_id=‘".$order_list_temp[‘erp_orders_id‘]."‘ ";
// echo $sql."\n";
// mysql_query($sql);
// $sql_products = "delete from erp_orders_products where erp_orders_id=‘".$order_list_temp[‘erp_orders_id‘]."‘ ";
// mysql_query($sql_products);
// echo $sql_products."\n";
$sql ="DELETE erp_orders,erp_orders_products FROM erp_orders LEFT JOIN erp_orders_products ON erp_orders.erp_orders_id = erp_orders_products.erp_orders_id WHERE erp_orders.erp_orders_id=‘".$order_list_temp[‘erp_orders_id‘]."‘ ";
echo $sql."\n";exit;
mysql_query($sql);
echo "-----------------------------------------------\n";
}
}
}