ret
*
*
*
*/
require_once( 'cfg.config.php' );
require_once( 'cls.info.php' );
class ws_alipay_db_parser{
private $tpl;
private $css;
public $ret;
public function __construct( $proid = 0 ){
global $wpdb;
if( (int)$proid == 0 ){
$this->ret = "【提示】:商品参数不合法,未知的商品ID
";
return;
}
// $sql = "SELECT *
// FROM $wpdb->wsaliproducts
// WHERE proid = $proid;";
// $proInfo = $wpdb->get_results( $sql );
$pro = new ws_alipay_product();
$proInfo = $pro->get_info($proid);
//print_r($proInfo);
if( empty( $proInfo ) ){
$this->ret = "【提示】:该商品不存在
";
return;
}
if( empty($proInfo['protype']) ){
$pro->set('protype','CUSTOM');
$proInfo['protype'] = 'CUSTOM';
}
$oriKeys = array_keys($proInfo);
//$proInfo = (array)$proInfo[0];
//FORMAT: array('in_{field}') || array('out_{field}', {default});
$shortCodes = array(
array('in_pay'),
array('in_num'),
array('in_email'),
array('in_msg'),
array('in_extra'),
array('in_addr'),
array('in_tel'),
array('in_ordname'),
array('in_postcode'),
array('out_oprice'),
array('out_cprice'),
array('out_sprice', 0),
);
$shortCodes = apply_filters( 'ws_alipay_short_codes', $shortCodes );
//Format
//$proInfo['short_code'] = 'classname_frontpage' ;
//USAGE:
//
//$tbl = $wpdb->wsalitemplates;
//$pro = $wpdb->wsaliproducts;
//GET THE TPL HTML
$tplid = $proInfo['tplid'];
$proname = $proInfo['name'];
$probtime = $proInfo['probtime'];
$tplinfo = $wpdb->get_results( "SELECT * FROM {$wpdb->wsalitemplates} WHERE tplid=$tplid;" );
if( empty( $tplinfo[0] ) ){
$this->ret = '【提示】:该商品未指定模版,请点此购买
';
return;
}
$tplinfo = (array)$tplinfo[0];
$btime = strtotime( $proInfo['btime'] );
if( time() < $btime && !empty($btime) ){
$this->ret = "【支付宝】:商品\"{$proname}\"还未上架!";
return;
}
$etime = strtotime( $proInfo['etime'] );
if( $etime < time() && !empty($etime) ){
$this->ret = "【支付宝】:商品\"{$proname}\"已下架!";
return;
}
//促销价格重载
if( $proInfo['promote'] == 1 &&
$proInfo['probdate'] < date( 'Ymd' ) &&
date( 'Ymd' ) < $proInfo['proedate'] &&
$proInfo['discountb'] == 1 )
{
if( ($proInfo['protime'] == 1 &&
$proInfo['probtime'] < date( 'His' ) &&
date( 'His' ) < $proInfo['proetime'] ) ||
$proInfo['protime'] == 0)
{
$proInfo['price'] *= $proInfo['discount'];
$proInfo['price'] = round( $proInfo['price'], 2 );
$proInfo['cprice'] = $proInfo['price'] ;
$proInfo['sprice'] = $proInfo['oprice'] - $proInfo['cprice'];
}
}
//运费价格重载
if( $proInfo['spfre'] == 1 ){
$proInfo['price'] += $proInfo['freight'];
}
foreach( $shortCodes as $v ){
$type = preg_split( '@_@', $v[0], 2 );
if( empty($type[1]) ) continue;
$type[0] = strtolower($type[0]);
$type[1] = strtolower($type[1]);
if( $type[0] == 'in'){
//Make it like :$proInfo['in_pay'] = 'ws_alipay_buy_pay';
$proInfo[$v[0]] = ( !empty($v[1]) )?$v[1]:'ws_alipay_buy_' . $type[1];
$postField[$type[1]] = '';
}elseif( $type[0] == 'out' ){
if( !empty($v[1]) ){
$proInfo[$v[0]] = $v[1];
}elseif( isset($proInfo[$type[1]]) ){
$proInfo[$v[0]] = $proInfo[$type[1]];
}
}
}
##GET THE ROW BY tplnum
##HERE ARE TPL_CSS TPL_HTML
$postField['nonce'] = '';
$postField['proid'] = '';
$postField['protype'] = '';
$postFieldStr = implode( ',', array_keys($postField) );
$css = stripslashes( $tplinfo['tplcss'] );
$html = stripslashes( $tplinfo['tplhtml'] );
$js = stripslashes( $tplinfo['tpljs'] );
$nonce = wp_create_nonce( 'ws_alipay_front_nonce_action', 'ws_alipay_front_nonce_name' );
$html1 = '