exit;
if (!isset($_SESSION)){ session_start(); }
if(isset($_POST['myb2cpost']) && $_POST['myb2cpost']=='mypost' ){
// $selfile=($_POST['sel_b2c']==0)?"bib2b":"bib2c";
$url='https://www.giveme.com.tw/invoice.do?action=addB2C';
if($_POST['sel_b2c']==0){ $url='https://www.giveme.com.tw/invoice.do?action=addB2B';}
/*
if(strlen($decoded_json['phone'])==8 ){
if(substr($decoded_json['phone'],0,1)<>'/') {
$url='https://www.giveme.com.tw/invoice.do?action=addB2B';
fwrite($fp,"====addB2B==\r\n");
}
} */
$logpath="/www2/skybni/log/bill_log.txt";
$fp = fopen($logpath, "a");
// b2b
if($_POST['sel_b2c']==0){
$data = '{"timeStamp":"","uncode":"","idno":"","sign":"","customerName":"","phone":"","datetime":"","email":"","taxState":"0","taxType":0,"sales":0,"amount":0,"totalFee":0,"content":"","items":[]}';
} else { $data = '{"timeStamp":"","uncode":"","idno":"","sign":"","customerName":"","phone":"","orderCode":"","datetime":"","email":"","state":"0","donationCode":"","taxType":0,"sales":0,"amount":0,"totalFee":0,"content":"","items":[]}'; }
$decoded_json = json_decode($data, true);
//$manage = json_decode($data, true);
$decoded_json["timeStamp"]=time().rand(100,999);
$decoded_json["uncode"]="42656789";
$decoded_json["idno"]="A126569032";
$decoded_json["datetime"]=date('Y-m-d');
$decoded_json["email"]=$_POST['q_email'];
$pwd= "AX6789";
$sign= $decoded_json['timeStamp'].$decoded_json['idno'].$pwd ;// 822344324
$sign= strtoupper(md5($sign));
$decoded_json['sign']=$sign;
if($_POST['sel_b2c']==1){
$decoded_json["customerName"]=$_POST['q_customerName'];//'82401230082'
if($_POST['q_donationCode']<>''){
$decoded_json["donationCode"]=$_POST['q_donationCode'];
$decoded_json["state"]="1";
$decoded_json["phone"]="";
$decoded_json["email"]="";
// "content":"82403270111",
}else{
$decoded_json["state"]="0";
$decoded_json["phone"]= $_POST['q_phone'];
$decoded_json["email"]= $_POST['q_email'];
}
}else{
//content
$decoded_json["content"]=$_POST['q_customerName'];//'82401230082';
$decoded_json["phone"]= $_POST['q_phone'];
}
mysql_select_db($database_BE2, $BE2);
//$query_Rt2 =sprintf("SELECT a.*,b.p_title FROM order_datas as a,product_data as b WHERE a.dcode='%s' AND a.mem_auto=b.mem_auto ",$_POST['q_customerName'] );
$query_Rt2 = "SELECT a.*,b.p_title FROM order_datas as a,product_data as b WHERE a.mem_auto=b.mem_auto order by a.dcode desc limit 5 " ;
$Rt2 = mysql_query($query_Rt2, $BE2) or die(mysql_error());
$row_Rt2 = mysql_fetch_assoc($Rt2);
$totalRows_Rt2 = mysql_num_rows($Rt2);
// echo $query_Rt2."
";
//taxState 單價是否含稅 0:含稅(默認) 1: 未稅
$sales=0;
$totalFee=0;
do {
$arrne['name'] = $row_Rt2['p_title'] ;
$arrne['money'] = intval($row_Rt2['p_money']);
$arrne['number'] = intval($row_Rt2['p_count']);
$sales=$sales+$row_Rt2['p_money'];
array_push( $decoded_json['items'], $arrne );
} while ($row_Rt2 = mysql_fetch_assoc($Rt2));
$decoded_json["sales"]= $sales;
$decoded_json["totalFee"]= $sales;
$sales=$sales+$row_Rt2['p_money'];
// $array = json_decode($json,true);
// $string = implode(",",$decoded_json);
fwrite($fp, json_encode($decoded_json) ."\r\n");// 822344324
// print json_encode($decoded_json);
echo("==========end==========
");
// echo($json);
// fwrite($fp, var_dump($decoded_json) ."\r\n");// 822344324
// 發票檔
// $pay_num=111111;
// $InsertSQL2 = sprintf("INSERT INTO order_bill(dcode,mem_id,selb2c,uncode,qphone,donationcode,email,ordertime,billcode,ck) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
// $pay_num,$_SESSION['login_memid'],$_POST['sel_b2c'],$_POST["q_uncode"],$_POST["q_phone"],$_POST["q_donationCode"],$_POST["q_email"],date('Y-m-d'),"","N");
// mysql_query( $InsertSQL2, $BE2) or die(mysql_error());
// mysql_select_db($database_BE2, $BE2);
fwrite($fp, "========================\r\n");// 822344324
fclose($fp);
}
?>