在使用轮询AB站跳转时会遇到提现时银行和商户提供商需要对对接的网站后台订单进行核验,
这个时候,我们就需要上面的功能了
如何在wp中建立订单,先用过系统调出订单信息,通过订单信息来建立订单,具体核心代码如下!
<?php
require($_SERVER['DOCUMENT_ROOT'].'/wp-config.php');
$plex = "wp_";
$parm = json_decode(file_get_contents("php://input"),true);
//$parm = json_decode('{"oid":"312","order_currceny":"USD","order_amount":"85.00","oadmin_id":"20","order_product":"[{\"name\":\"D??ANGELICO PREMIER TD TEARDROP ELECTRIC GUITAR W\\\/GIG BAG, TRANS WINE (Copy)\",\"model\":\"\",\"price\":\"1.00\",\"quantity\":1,\"option\":[],\"weight\":0,\"products_image\":\"http:\\\/\\\/woo.weituanlianmeng.top\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/0ffc4f6048dec92699b5c58077af9750.jpg\"}]","billing_first_name":"tese@qq.com","order_number":"D202211231554089039","id":"315","billing_last_name":"tese@qq.com","billing_address1":"tese@qq.com","billing_address2":"","billing_city":"tese@qq.com","billing_state":"AZ","billing_country":"US","billing_zip":"10001","billing_email":"tese@test.com","billing_phone":"12361564312","shipping_first_name":"tese@qq.com","shipping_last_name":"tese@qq.com","shipping_address1":"tese@qq.com","shipping_address2":null,"shipping_city":"tese@qq.com","shipping_state":"AZ","shipping_country":"US","shipping_zip":"10001","shipping_email":"tese@test.com","shipping_phone":"12361564312","order_id":"312","datetime":"2022-11-23 15:54:08","ip":"185.127.19.127","lan":"en-GB,en;q=0.9","user_agent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/93.0.4577.82 Safari\/537.36","admin_id":"20","domain_name":"woo.weituanlianmeng.top","payment_form_uri":"https:\/\/info.suuerca.xyz\/Isabella"}');
$parm =(Object)$parm;
//var_dump($parm);die;
//var_dump($file_get_contents("php://input"));die;
$pro = [];
if((int)$parm->order_amount<10){
$pro = ['pro'=>['id'=>73,'price'=>6.00]];
}
if((int)$parm->order_amount>=10 && (int)$parm->order_amount<20){
$pro = [['id'=>160,'price'=>10.75],['id'=>17,'price'=>12.70],['id'=>33,'price'=>15.80]];
}
if((int)$parm->order_amount>=20 && (int)$parm->order_amount<30){
$pro = [['id'=>104,'price'=>26.00],['id'=>137,'price'=>26.00],['id'=>41,'price'=>28.70]];
}
if((int)$parm->order_amount>=30 && (int)$parm->order_amount<40){
$pro = [['id'=>104,'price'=>26.00],['id'=>137,'price'=>26.00],['id'=>41,'price'=>28.70]];
}
if((int)$parm->order_amount>=30 && (int)$parm->order_amount<40){
$pro = [[['id'=>104,'price'=>26.00],['id'=>160,'price'=>10.75]],
[['id'=>137,'price'=>26.00],['id'=>160,'price'=>10.75]],
[['id'=>41,'price'=>28.70],['id'=>160,'price'=>10.75]],
['id'=>152,'price'=>35.00],
['id'=>87,'price'=>35.20],
];
}
if((int)$parm->order_amount>=40 && (int)$parm->order_amount<50){
$pro = [
[['id'=>87,'price'=>35.20],['id'=>160,'price'=>10.75]],
[['id'=>152,'price'=>35.00],['id'=>160,'price'=>10.75]],
];
}
if((int)$parm->order_amount>=50 && (int)$parm->order_amount<60){
$pro = [
[['id'=>87,'price'=>35.20],['id'=>104,'price'=>26.00]],
[['id'=>152,'price'=>35.00],['id'=>104,'price'=>26.00]],
[['id'=>87,'price'=>35.20],['id'=>41,'price'=>28.70]],
[['id'=>152,'price'=>35.00],['id'=>144,'price'=>27.30]],
];
}
if((int)$parm->order_amount>=60 && (int)$parm->order_amount<70){
$pro = [
[['id'=>87,'price'=>35.20],['id'=>152,'price'=>35.00]],
['id'=>95,'price'=>70.00],
];
}
if((int)$parm->order_amount>=70 && (int)$parm->order_amount<80){
$pro = [
[['id'=>95,'price'=>70.00],['id'=>160,'price'=>10.75]],
[['id'=>95,'price'=>70.00],['id'=>33,'price'=>15.80],],
];
}
if((int)$parm->order_amount>=80 && (int)$parm->order_amount<100){
$pro = [
[['id'=>95,'price'=>70.00],['id'=>41,'price'=>28.70]],
[['id'=>95,'price'=>70.00],['id'=>137,'price'=>26.00]],
[['id'=>95,'price'=>70.00],['id'=>144,'price'=>27.30]],
];
}
$pros = $pro[array_rand($pro)];
//var_dump($pros);die;
global $wpdb;
if($parm->order_status ==1){
$order_status = 'wc-processing';
}else{
$order_status = 'wc-cancelled';
}
//$sql = "select wp.id,wp.post_name,price,wp.post_content,wp.post_title from ".$plex."posts wp left join (select post_id,meta_value price from ".$plex."postmeta where meta_key = '_price' ) pr on pr.post_id =wp.id group by wp.post_parent limit 1";
//var_dump($sql);
//$res =$wpdb->get_row($wpdb->prepare($sql));
// var_dump($res);die;
//var_dump("insert into ".$plex."wc_customer_lookup( `first_name`, `last_name`, `email`, `date_last_active`, `date_registered`, `country`, `postcode`, `city`, `state`) VALUES ('".$parm->billing_first_name."','".$parm->billing_last_name."','".$parm->billing_email."','".date('Y-m-d H:i:s')."','".date('Y-m-d H:i:s')."','".$parm->billing_country."','".$parm->billing_zip."','".$parm->billing_city."','".$parm->billing_state."')");die;
$data = ['first_name'=>$parm->billing_first_name,
'last_name'=>$parm->billing_last_name,
'email'=>$parm->billing_email,
'date_last_active'=>date('Y-m-d H:i:s'),
'date_registered'=>date('Y-m-d H:i:s'),
'country'=>$parm->billing_country,
'postcode'=>$parm->billing_zip,
'city'=>$parm->billing_city,
'state'=>$parm->billing_state
];
$wpdb->insert($plex."wc_customer_lookup",$data);
$custom_id = $wpdb->insert_id;
$key = 'wc_order_'.uniqid();
$data = ['post_author'=>1,
'post_date'=>date('Y-m-d H:i:s'),
'post_date_gmt'=>date('Y-m-d H:i:s'),
'post_content'=>'',
'post_title'=>'Order '.date('Y-m-d H:i:s'),
'post_excerpt'=>'',
'post_status'=>$order_status,
'comment_status'=>'open',
'ping_status'=>'closed',
'post_password'=>$key,
'post_name'=>'order-'.date('Y-m-d-H-i-s'),
'to_ping'=>'',
'pinged'=>'',
'post_modified'=>date('Y-m-d H:i:s'),
'post_modified_gmt'=>date('Y-m-d H:i:s'),
'post_content_filtered'=>'',
'post_parent'=>0,
'guid'=>'',
'menu_order'=>0,
'post_type'=>'shop_order',
'post_mime_type'=>'',
'comment_count'=>1
];
$wpdb->insert($plex."posts",$data);
$order_id = $wpdb->insert_id;
$wpdb-> query("update ".$plex."post` set guid = 'https://".$_SERVER['HTTP_HOST']."/?post_type=shop_order&p=".$order_id."'");
//$pros = (object)$pros;
//if(empty($res)){
//$sql = "select wp.id,wp.post_name,price,wp.post_content,wp.post_title from ".$plex."posts wp left join (select post_id,meta_value price from ".$plex."postmeta where meta_key = '_price' ) pr on pr.post_id =wp.id where wp.post_type='product' and wp.create_order ='0' group by wp.post_parent limit 1";
//$res =$wpdb->get_row($wpdb->prepare($sql));
//$wpdb-> query("update ".$plex."postmeta set meta_value = '".$parm->order_amount."' where meta_key='_price' and post_id='".$res->id."'");
//$wpdb-> query("update ".$plex."posts set create_order = '1' where post_id='".$res->id."'");
//var_dump("update ".$plex."postmeta set meta_value = '".$parm->order_amount."' where meta_key='_price' and post_id='".$res->id."'");die;
//}
//var_dump(($pros));die;
if( count($pros)== count($pros,1)){
$sql = "select wp.id,wp.post_name,price,wp.post_content,wp.post_title from ".$plex."posts wp left join (select post_id,meta_value price from ".$plex."postmeta where meta_key = '_price' ) pr on pr.post_id =wp.id where wp.post_type='product' and wp.id ='".$pros['id']."' group by wp.post_parent limit 1"; //and wp.create_order ='0'
$res =$wpdb->get_row($wpdb->prepare($sql));
$pros = (object)$pros;
$data = ['order_item_name'=>$res->post_title,
'order_item_type'=>'line_item',
'order_id'=>$order_id,
];
$order_item =$wpdb->insert($plex."woocommerce_order_items",$data);
$order_item_id = $wpdb->insert_id;
$data = [ 'order_item_id'=>$order_item_id,
'order_id'=>$order_id,
'product_id'=>$pros->id,
'variation_id'=>0,
'customer_id'=>$custom_id,
'date_created'=>date('Y-m-d H:i:s'),
'product_qty'=>1,
'product_net_revenue'=>$pros->price,
'product_gross_revenue'=>$pros->price,
'coupon_amount'=>0,
'tax_amount'=>0,
'shipping_amount'=>2.50,
'shipping_tax_amount'=>0
];
$wpdb->insert($plex."wc_order_product_lookup",$data);
$data = serialize(['total'=>0,
'subtotal'=>0
]);
$sql = "insert into ".$plex."woocommerce_order_itemmeta(`order_item_id`,`meta_key`,`meta_value`) VALUES
('".$order_item_id."','_product_id','".$pros->id."'),
('".$order_item_id."','_variation_id',0),
('".$order_item_id."','_qty',1),
('".$order_item_id."','_tax_class',''),
('".$order_item_id."','_line_subtotal','".$pros->price."'),
('".$order_item_id."','_line_subtotal_tax','0'),
('".$order_item_id."','_line_total','".$pros->price."'),
('".$order_item_id."','_line_tax','0'),
('".$order_item_id."','_line_tax_data','".$data."')
";
$wpdb-> query($sql);
$amount = round($parm->order_amount - $pros->price,2);
}else{
foreach($pros as $key =>$value){
$sql = "select wp.id,wp.post_name,price,wp.post_content,wp.post_title from ".$plex."posts wp left join (select post_id,meta_value price from ".$plex."postmeta where meta_key = '_price' ) pr on pr.post_id =wp.id where wp.post_type='product' and wp.id ='".$value['id']."' group by wp.post_parent limit 1"; //and wp.create_order ='0'
$res =$wpdb->get_row($wpdb->prepare($sql));
$data = ['order_item_name'=>$res->post_title,
'order_item_type'=>'line_item',
'order_id'=>$order_id,
];
$order_item =$wpdb->insert($plex."woocommerce_order_items",$data);
$order_item_id = $wpdb->insert_id;
//var_dump($order_item_id);
$data = [ 'order_item_id'=>$order_item_id,
'order_id'=>$order_id,
'product_id'=>$value['id'],
'variation_id'=>0,
'customer_id'=>$custom_id,
'date_created'=>date('Y-m-d H:i:s'),
'product_qty'=>1,
'product_net_revenue'=>$value['price'],
'product_gross_revenue'=>$value['price'],
'coupon_amount'=>0,
'tax_amount'=>0,
'shipping_amount'=>0,
'shipping_tax_amount'=>0
];
$wpdb->insert($plex."wc_order_product_lookup",$data);
$data = serialize(['total'=>0,
'subtotal'=>0
]);
$sql = "insert into ".$plex."woocommerce_order_itemmeta(`order_item_id`,`meta_key`,`meta_value`) VALUES
('".$order_item_id."','_product_id','".$value['id']."'),
('".$order_item_id."','_variation_id',0),
('".$order_item_id."','_qty',1),
('".$order_item_id."','_tax_class',''),
('".$order_item_id."','_line_subtotal','".$value['price']."'),
('".$order_item_id."','_line_subtotal_tax','0'),
('".$order_item_id."','_line_total','".$value['price']."'),
('".$order_item_id."','_line_tax','0'),
('".$order_item_id."','_line_tax_data','".$data."')
";
$wpdb-> query($sql);
}
//$amount = round($parm->order_amount - $pros->price,2);
}
//$amount=0;
//$cart_discount = 0;
//$order_shipping =0;
//if($amount<0){
// $cart_discount = $amount;
//}
//if($amount>0){
// $order_shipping = $amount;
//}
$sql = "insert into ".$plex."postmeta(`post_id`,`meta_key`,`meta_value`) VALUES
('".$order_id."','_order_key','".$key."'),
('".$order_id."','_customer_user','0'),
('".$order_id."','_payment_method','niumu_paypal'),
('".$order_id."','_payment_method_title','Paypal'),
('".$order_id."','_customer_ip_address','".$parm->ip."'),
('".$order_id."','_customer_user_agent','".$parm->user_agent."'),
('".$order_id."','_created_via','checkout'),
('".$order_id."','_cart_hash','".md5(date('Y-m-d H:i:s'))."'),
('".$order_id."','_billing_first_name','".$parm->billing_first_name."'),
('".$order_id."','_billing_last_name','".$parm->billing_last_name."'),
('".$order_id."','_billing_company',''),
('".$order_id."','_billing_address_1','".$parm->billing_address1."'),
('".$order_id."','_billing_address_2','".$parm->billing_address2."'),
('".$order_id."','_billing_city','".$parm->billing_city."'),
('".$order_id."','_billing_state','".$parm->billing_state."'),
('".$order_id."','_billing_postcod','".$parm->billing_zip."'),
('".$order_id."','_billing_country','".$parm->billing_country."'),
('".$order_id."','_billing_email','".$parm->billing_email."'),
('".$order_id."','_billing_phone','".$parm->billing_phone."'),
('".$order_id."','_order_currency','".$parm->order_currceny."'),
('".$order_id."','_cart_discount','0'),
('".$order_id."','_cart_discount_tax','0'),
('".$order_id."','_order_shipping','0'),
('".$order_id."','_order_shipping_tax','0'),
('".$order_id."','_order_tax','0'),
('".$order_id."','_order_total','".$parm->order_amount."'),
('".$order_id."','_order_version','6.7.0'),
('".$order_id."','_prices_include_tax','no'),
('".$order_id."','_billing_address_index','".$parm->billing_first_name.' '.$parm->billing_last_name.' '.$parm->billing_address1.' '.$parm->billing_address2.' '.$parm->billing_city.' '.$parm->billing_state.' '.$parm->billing_country.' '.$parm->billing_zip.' '.$parm->billing_email.' '.$parm->billing_phone."'),
('".$order_id."','_shipping_address_index',''),
('".$order_id."','is_vat_exempt','no')
";
//var_dump($sql);
$wpdb-> query($sql);
echo 'ok';