查看文件: wanpayret.php
大小: 20.07 KB
类型: application/octet-stream
<?php require_once('../Connections/BE2.php'); ?> <? $logpath="/www2/skybni/log/wanpaylog.txt"; $fp = fopen($logpath, "a"); //$_SERVER['HTTP_REFERER']; $ref=isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:""; fwrite($fp,"start log ".$ref." response " .date('Y-m-d H:i:s')."\r\n"); $a=count($_POST); fwrite($fp,"=====POST====================="."\r\n"); if($a>0){ foreach($_POST as $key=>$value){ // echo "$key=$value"; fwrite($fp,"$key=$value"."\r\n"); } //====== start respone====================// $pass_data=0; $td= isset($_POST['out_trade_no'])?$_POST['out_trade_no']:'0'; //out_trade_no=2025031416194900006 mysql_select_db($database_BE2, $BE2); //2025031307563300062 //2025031223104800431 $q1 = sprintf("SELECT * FROM order_tmp2 WHERE dcode='%s' order by did desc limit 1",$td); $Rq1 = mysql_query($q1, $BE2) or die(mysql_error()); $row_Rq1 = mysql_fetch_assoc($Rq1); $totalRows_Rq1 = mysql_num_rows($Rq1); //fwrite($fp,"found order_tmp2 $q1"."\r\n"); if($totalRows_Rq1==1){ if($row_Rq1['dwanpay']==1){ //fwrite($fp,"update order_tmp2 set dwanpay=2"."\r\n"); $UpSQL1 = sprintf("update order_tmp2 set dwanpay='2' where dcode='%s' AND did='%s'",$td,$row_Rq1['did'] ); mysql_select_db($database_BE2, $BE2); mysql_query($UpSQL1, $BE2) or die(mysql_error()); //fwrite($fp,$UpSQL1."\r\n"); $pass_data=1; } } mysql_free_result($Rq1); if($pass_data>0){ // start excel data // fwrite($fp,$td ."pass_data"."\r\n"); if( strlen($td)==19 ){ //fwrite($fp,$td ." ==>ok"."\r\n"); mysql_select_db($database_BE2, $BE2); $query_Rtn = sprintf("SELECT a.*,b.mem_num FROM order_tmp2 as a,member as b WHERE a.duser=b.mem_auto AND a.dcode='%s'",$td); $Rtn = mysql_query($query_Rtn, $BE2) or die(mysql_error()); $row_Rtn = mysql_fetch_assoc($Rtn); $ssid=$row_Rtn['dsess']; $dpay=$row_Rtn['dpay'];// ,1,2,3,4 $duser=$row_Rtn['duser']; // user id $puser=$row_Rtn['mem_num']; // par id $ppuser=0; // par id //fwrite($fp,"step 2 ==>".$query_Rtn ."\r\n"); mysql_free_result($Rtn); // 開發商 company_boss mysql_select_db($database_BE2, $BE2); // $query_Rtp1 = sprintf("SELECT a.mem_auto,a.mem_num as ppid FROM member as a, company as b WHERE a.mem_num=b.mid AND b.company_boss='Y' AND a.mem_auto='%s' " ,$puser); $query_Rtp1 = sprintf("SELECT mem_auto,mem_num FROM member WHERE mem_auto='%s' AND mem_check<>'N'" ,$puser); $Rtp1 = mysql_query($query_Rtp1, $BE2) or die(mysql_error()); $row_Rtp1 = mysql_fetch_assoc($Rtp1); $totalRows_Rtp1 = mysql_num_rows($Rtp1); // fwrite($fp,"step 3 ==>".$query_Rtp1 ."\r\n"); if($totalRows_Rtp1>0){ $ppuser=$row_Rtp1['mem_num'] ;} mysql_free_result($Rtp1); $testpay=isset($_POST['testpay'])?1:0; // esafe in $write=""; $errcode= isset($_POST['errcode'])?$_POST['errcode']:'XX'; //if(($errcode=='00')||($dpay>2)|| ($testpay>0) ){ // local pay mysql_select_db($database_BE2, $BE2); $query_Rtb = sprintf("SELECT * From order_bill WHERE dcode='%s'",$td) ; $Rtb = mysql_query($query_Rtb, $BE2) or die(mysql_error()); $row_Rtb = mysql_fetch_assoc($Rtb); if( $row_Rtb['ck']=='N'){ // 檢查發票檔 $buyid=$row_Rtb['mem_id']; // buyer id mysql_select_db($database_BE2, $BE2); $qr_paycoid = sprintf("SELECT distinct(coid) FROM order_tmp WHERE dcode='%s'",$td); $Rtco = mysql_query($qr_paycoid, $BE2) or die(mysql_error()); $row_Rtco = mysql_fetch_assoc($Rtco); $coid=$row_Rtco['coid']; // companyid mysql_free_result($Rtco); $write="Y"; $tdate=date('Y-m-d'); $pay1[0]='N' ;// 付款flag $pay1[1]='' ; // 付款銀行 紅陽金 dbank $pay1[2]='' ; // pay dpaydate if($dpay<3){ $pay1[0]='Y'; $pay1[1]='Wanpay金流' ;// 紅陽金流 付款銀行 紅陽金 dban $pay1[2]=$tdate ;// pay dpaydate } // 分頁 end $insertSQL1 = sprintf("insert into order_datam(dcode,dmoney,dexpess,dall,dcash,dsky,ddate,dpay,duser,dpaydate,dflag,dbank,coid)select dcode,dmoney,dexpess,dall,dcash,dsky,ddate,dpay,duser,concat('%s'),concat('%s'),concat('%s'),concat('%s') from order_tmp2 where dcode='%s'",$pay1[2],$pay1[0],$pay1[1],$coid,$td); //echo $insertSQL1 ."<br>"; mysql_select_db($database_BE2, $BE2); mysql_query($insertSQL1, $BE2) or die(mysql_error()); /* order_rtype 7 使用雲點數 did saveto eccid */ $insQ6 =sprintf("insert into order_point(eccid,euid,e_type,e_oval,e_date,e_flag) select did,duser,concat('7'),dsky,concat('%s'),concat('Y') from order_datam where dsky>0 AND dcode='%s'",date('Y-m-d'), $td); mysql_select_db($database_BE2, $BE2); mysql_query($insQ6 ,$BE2) or die(mysql_error()); fwrite($fp,$insQ6 ." ==> 7 使用雲點數"."\r\n"); //order_tmp p_percent p_percent31 //p_percent p_percent*p_count 推廣獎金 //p_percent2 p_percent2*p_count 開發獎金 //p_percent3 p_percent3 33 首次開店獎金 //p_percent4 p_percent4 34 推廣雲點 //p_percent5 p_percent5 35 開發雲點 //p_percent6 p_percent6 36 開發商續推獎金 //p_percent7 p_percent37 經銷獎金 //p_percent8 p_percent38 分享獎金 new 241209 //p_percent9 p_percent39 推薦獎金 new 241209 to sql tablename pptname //p_demoney p_demoney 繳金額 // 1 2 3 4 5 6 // $pp1=array("",'推廣獎金','開發獎金','開發商首推獎金','商品未付餘額','開發商續推獎金','經銷獎金'); // dis ,p_demoney $insertSQL2 = sprintf("insert into order_datas(dcode,mem_auto,p_money,p_count,p_size,p_percent,p_percent2,p_percent3,p_percent4,p_percent5,p_percent6,p_percent7,p_demoney,p_once)select dcode,mem_auto,p_money,p_count,p_size,p_percent*p_count,p_percent2*p_count,p_percent3,p_percent4,p_percent5,p_percent6,p_percent7,p_demoney,p_once from order_tmp where dcode='%s'",$td); // echo $insertSQL2 ."<br>"; mysql_select_db($database_BE2, $BE2); mysql_query($insertSQL2, $BE2) or die(mysql_error()); // 分頁 end $UpSQL1 = sprintf("update order_tmp2 set dsess='',dcode='' where dcode='%s'",$td ); //echo $UpSQL1 ."<br>"; mysql_select_db($database_BE2, $BE2); mysql_query($UpSQL1, $BE2) or die(mysql_error()); $UpSQL2 = sprintf("update order_tmp set p_sess='',dcode='' where dcode='%s'",$td ); //echo $UpSQL2 ."<br>"; mysql_select_db($database_BE2, $BE2); mysql_query($UpSQL2, $BE2) or die(mysql_error()); // p_percent31 // ccid data slave id , pid ,duid , money ,date , // pid ,ccid, puid ,duid, pmoney ,pdate ,pflag //mysql_free_result($Rtcp); $puser_mck = sprintf("select mem_check from member where mem_auto='%s'",$puser ); mysql_select_db($database_BE2, $BE2); $Rfck = mysql_query($puser_mck, $BE2) or die(mysql_error()); $row_Rfck = mysql_fetch_assoc($Rfck); $fpck=$row_Rfck['mem_check']; // companyid mysql_free_result($Rfck); /* p_percent ($row_Rqr1['p_percent31']==0)?round(($row_Rqr1['p_money']*0.03),0 ):"0"; p_percent2($row_Rqr1['p_percent31']==0)?round(($row_Rqr1['p_money']*0.02),0 ):"0"; p_percent3 =0 p_percent31 推廣獎金 p_percent32 開發獎金 p_percent33 首次特別開發費 單次 首次開店獎金 p_percent34 推廣雲點 p_percent35 開發雲點 p_demoney 未繳金額 */ // 首次(1年內)開店獎金 介紹人必需開發商 給上線 -->開發商直銷獎金 // 直推獎金 續約1年以後 開發商直銷獎金 if($fpck=='Y'|| $fpck=='V'){ // 1 2 3 4 5 6 //$pp1=array("",'推廣獎金','開發獎金','開發商直銷獎金','商品未付餘額','開發商續推獎金','直銷獎金'); $insertSQLp0 =sprintf("insert into order_percent(ccid,puid,duid,pmoney,pdate,pkid) select ccid,concat('%s'),concat('%s'),p_percent3,concat('%s'), concat('3') from order_datas where p_percent3>0 AND p_once=0 AND dcode='%s'",$puser,$duser,date('Y-m-d'),$td); mysql_select_db($database_BE2, $BE2); mysql_query($insertSQLp0, $BE2) or die(mysql_error()); $insertSQLp1 =sprintf("insert into order_percent(ccid,puid,duid,pmoney,pdate,pkid) select ccid,concat('%s'),concat('%s'),p_percent6,concat('%s'), concat('5') from order_datas where p_percent6>0 AND p_once=1 AND dcode='%s'",$puser,$duser,date('Y-m-d'),$td); mysql_select_db($database_BE2, $BE2); mysql_query($insertSQLp1, $BE2) or die(mysql_error()); //////////////////////////////// // 直銷獎金 $insertSQLp3 =sprintf("insert into order_percent(ccid,puid,duid,pmoney,pdate,pkid) select ccid,concat('%s'),concat('%s'),p_percent7,concat('%s'), concat('6') from order_datas where p_percent7>0 AND dcode='%s'",$puser,$duser,date('Y-m-d'),$td); mysql_select_db($database_BE2, $BE2); mysql_query($insertSQLp3, $BE2) or die(mysql_error()); } else{ //推廣獎金 (一般會員) 給上線 ->會員推廣獎金 $insertSQLp =sprintf("insert into order_percent(ccid,puid,duid,pmoney,pdate,pkid) select ccid,concat('%s'),concat('%s'),p_percent,concat('%s'),concat('1') from order_datas where p_percent>0 AND dcode='%s'",$puser,$duser,date('Y-m-d'),$td); mysql_select_db($database_BE2, $BE2); mysql_query($insertSQLp, $BE2) or die(mysql_error()); } /* //推廣獎金 (一般會員) 給上線 ->會員推廣獎金 $insertSQLp =sprintf("insert into order_percent(ccid,puid,duid,pmoney,pdate,pkid) select ccid,concat('%s'),concat('%s'),p_percent,concat('%s'),concat('1') from order_datas where p_percent>0 AND dcode='%s'",$puser,$duser,date('Y-m-d'),$td); mysql_select_db($database_BE2, $BE2); mysql_query($insertSQLp, $BE2) or die(mysql_error()); */ //開發獎金 p_percent2 必需開發商 給上線 -> 開發商開發獎金 if($ppuser>0){ //確定 開發商開發獎金 $insertSQLp2 =sprintf("insert into order_percent(ccid,puid,duid,pmoney,pdate,pkid) select ccid,concat('%s'),concat('%s'),p_percent2,concat('%s'),concat('2') from order_datas where p_percent2>0 AND dcode='%s'",$ppuser,$duser,date('Y-m-d'),$td); mysql_select_db($database_BE2, $BE2); mysql_query($insertSQLp2, $BE2) or die(mysql_error()); } // '推廣獎金','開發獎金','開發商直銷獎金','商品未付餘額','開發商續推獎金','直銷獎金'; $insertSQLp2a =sprintf("insert into order_percent(ccid,puid,duid,depmoney,pdate,pkid) select ccid,concat('%s'),concat('%s'),p_demoney,concat('%s'),concat('4') from order_datas where p_demoney>0 AND dcode='%s'",$duser,$duser,date('Y-m-d'),$td); mysql_select_db($database_BE2, $BE2); mysql_query($insertSQLp2a, $BE2) or die(mysql_error()); $order2 = sprintf("select * from order_datas where dcode='%s'",$td ); mysql_select_db($database_BE2, $BE2); $R2 = mysql_query($order2, $BE2) or die(mysql_error()); $row_R2 = mysql_fetch_assoc($R2); $fR2=0; $fR2=$row_R2['p_percent']+$row_R2['p_percent2']+$row_R2['p_percent3']+$row_R2['p_percent4']+$row_R2['p_percent5']+$row_R2['p_percent6']+$row_R2['p_percent7']; mysql_free_result($R2); //echo $fR2.' ,' .$td."<br>";; /* order_datas,mem_auto - 2% to 抽成 order_rtype */ if($fR2==0){ // 有獎金 無抽成,回饋 $insertSQL3 =sprintf("insert into order_point(eccid,euid,e_type,e_ival,e_date) select ccid,concat('%s'),concat('%s'),(p_money*0.03),concat('%s') from order_datas where p_percent=0 AND dcode='%s'",$puser,"1",date('Y-m-d'),$td); mysql_select_db($database_BE2, $BE2); mysql_query($insertSQL3, $BE2) or die(mysql_error()); /* 1 - 2% to 抽成 介紹人 */ $insertSQL4 =sprintf("insert into order_point(eccid,euid,e_type,e_ival,e_date) select ccid,concat('%s'),concat('%s'),(p_money*0.02),concat('%s') from order_datas where p_percent=0 AND dcode='%s'",$duser,"2",date('Y-m-d'),$td); mysql_select_db($database_BE2, $BE2); mysql_query($insertSQL4, $BE2) or die(mysql_error()); /* 2 - 3% to 回饋 自己 */ } $insertSQL4 =sprintf("insert into order_point(eccid,euid,e_type,e_ival,e_date) select ccid,concat('%s'),concat('%s'),p_percent4,concat('%s') from order_datas where p_percent4>0 AND dcode='%s'",$puser,"10",date('Y-m-d'),$td); mysql_select_db($database_BE2, $BE2); mysql_query($insertSQL4, $BE2) or die(mysql_error()); /* 10 - 3% to 推廣雲點 介紹人 order_rtype */ $insertSQL4 =sprintf("insert into order_point(eccid,euid,e_type,e_ival,e_date) select ccid,concat('%s'),concat('%s'),p_percent5,concat('%s') from order_datas where p_percent5>0 AND dcode='%s'",$ppuser,"11",date('Y-m-d'),$td); mysql_select_db($database_BE2, $BE2); mysql_query($insertSQL4, $BE2) or die(mysql_error()); /* 11 - to 開發雲點 介紹人 必需開發商 給上上線 order_rtype 1 未繳 x 上線 2 首次推動金,金額不對 3 購買購買 */ $insertSQL5 =sprintf("insert into order_point(eccid,euid,e_type,e_ival,e_date) select ccid,concat('%s'),concat('%s'),(p_money*0.05),concat('%s') from order_datas where dcode='%s'","1","3",date('Y-m-d'),$td); mysql_select_db($database_BE2, $BE2); mysql_query($insertSQL5, $BE2) or die(mysql_error()); /* 3 - 5% to 官網收 */ $insertSQL6 =sprintf("insert into order_point(eccid,euid,e_type,e_ival,e_date) select ccid,concat('%s'),concat('%s'),(p_money*0.05),concat('%s') from order_datas where dcode='%s'","1","4",date('Y-m-d'),$td); mysql_select_db($database_BE2, $BE2); mysql_query($insertSQL6, $BE2) or die(mysql_error()); /* 4 - 5% to 營業稅 */ $insertSQL7 =sprintf("insert into order_point(eccid,euid,e_type,e_ival,e_date) select ccid,concat('%s'),concat('%s'),(p_money*0.028),concat('%s') from order_datas where dcode='%s'","1","5",date('Y-m-d'),$td); mysql_select_db($database_BE2, $BE2); mysql_query($insertSQL7, $BE2) or die(mysql_error()); /* 5 - 2% to 紅陽金流 */ // mem_check N:無, Y:網店 , V:開發商網店 $update10 =sprintf("update member as a,order_datas as b,order_datam as c,sp_product as d SET a.mem_check=d.ss_ck WHERE b.mem_auto=d.ss_id AND b.dcode=c.dcode AND c.duser=a.mem_auto AND a.mem_auto='%s' AND a.mem_check='N' AND b.dcode='%s'",$buyid,$td); mysql_select_db($database_BE2, $BE2); mysql_query($update10, $BE2) or die(mysql_error()); fwrite($fp,$update10." ==> 更新網店資訊"."\r\n"); // m_addemo N:無, Y:廣告會員 , 廣告會員 // /* $update11 =sprintf("update member as a,order_datas as b,order_datam as c,sp_product as d SET a.mem_check=d.ss_ck WHERE b.mem_auto=d.ss_id AND b.dcode=c.dcode AND c.duser=a.mem_auto AND a.mem_auto='%s' AND a.mem_check='N' AND b.dcode='%s'",$buyid,$td); mysql_select_db($database_BE2, $BE2); mysql_query($update11, $BE2) or die(mysql_error()); fwrite($fp,$update10." ==> 更新網店獎金 尚未付款金額(開設開發商"."\r\n"); */ //開立發票檔 mysql_select_db($database_BE2, $BE2); $query_Rt2 = sprintf("SELECT * From order_bill WHERE dcode='%s'",$td) ; $Rt2 = mysql_query($query_Rt2, $BE2) or die(mysql_error()); $row_Rt2 = mysql_fetch_assoc($Rt2); //update order_bill set ck='Y',billcode='%s' //發票檔 // $enable_bill0=true; and($enable_bill0==true) if( $row_Rt2['ck']=='N'){ $url='https://www.giveme.com.tw/invoice.do?action=addB2C'; if($row_Rt2['selb2c']==0){ $url='https://www.giveme.com.tw/invoice.do?action=addB2B';} fwrite($fp,"======發票檔============"."\r\n"); // b2b if($row_Rt2['selb2c']==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); $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"]=$row_Rt2['email']; $pwd= "AX6789"; $sign= $decoded_json['timeStamp'].$decoded_json['idno'].$pwd ;// 822344324 $sign= strtoupper(md5($sign)); $decoded_json['sign']=$sign; // $rtInsertSQL2 = sprintf("select * From order_bill // (dcode,mem_id,selb2c,uncode,qphone,donationcode,email,ordertime,billcode,ck) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", if($row_Rt2['selb2c']==1){ $decoded_json["customerName"]=$td;//'82401230082' if($row_Rt2['donationcode']<>''){ $decoded_json["donationCode"]=$row_Rt2['donationcode']; $decoded_json["state"]="1"; $decoded_json["phone"]=""; $decoded_json["email"]=""; // "content":"82403270111", }else{ $decoded_json["state"]="0"; $decoded_json["phone"]= $row_Rt2['qphone']; $decoded_json["email"]= $row_Rt2['email']; } }else{ //content $decoded_json["content"]=$td;//'82401230082'; $decoded_json["phone"]= $row_Rt2['qphone']; } mysql_select_db($database_BE2, $BE2); $query_Rt3 =sprintf("SELECT a.*,b.p_title FROM order_datas as a,product_data as b WHERE a.mem_auto=b.mem_auto AND a.dcode='%s'",$td ); $Rt3 = mysql_query($query_Rt3, $BE2) or die(mysql_error()); $row_Rt3 = mysql_fetch_assoc($Rt3); $totalRows_Rt3 = mysql_num_rows($Rt3); $sales=0; $totalFee=0; do { $arrne['name'] = $row_Rt3['p_title'] ; $arrne['money'] = intval($row_Rt3['p_money']); $arrne['number'] = intval($row_Rt3['p_count']); $sales=$sales+$row_Rt3['p_money']; array_push( $decoded_json['items'], $arrne ); } while ($row_Rt3 = mysql_fetch_assoc($Rt3)); $decoded_json["sales"]= $sales; $decoded_json["totalFee"]= $sales; // print json_encode($decoded_json); fwrite($fp, json_encode($decoded_json) ."\r\n");// 822344324 $jss=json_encode($decoded_json); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: OAuth 2.0 token here")); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $jss); $result = curl_exec($ch); fwrite($fp,"=============giveme result ======="."\r\n"); fwrite($fp,$result."\r\n"); $test_dejson = json_decode($result, true); // echo 'billcode,'.$result_dejson['code'] ;//"code":"VJ59556740", if(isset($test_dejson['msg']) && $test_dejson['msg']=="開立成功!"){ $UpSQL2 = sprintf("update order_bill set ck='Y',billcode='%s' where dcode='%s'",$test_dejson['code'],$td ); //echo $UpSQL2 ."<br>"; mysql_select_db($database_BE2, $BE2); mysql_query($UpSQL2, $BE2) or die(mysql_error()); } // fclose($fp); } //$errcode=='00' } //發票檔 // } // 00 } // end excel data } //========end respone pos =============// } else { $b=count($_GET); fwrite($fp,"=====GET====================="."\r\n"); if($b>0){ foreach($_GET as $key=>$value){ // echo "$key=$value"; fwrite($fp,"$key=$value"."\r\n"); } } fwrite($fp,"==========信用卡-連線交易成功========="."\r\n"); echo "<script>alert('信用卡-連線交易成功');location.href='/';</script>"; } fclose($fp); ?>
保存
取消
返回文件列表