Exemplo n.º 1
0
function pay($mchid, $appid, $no, $payurl, $openid, $money, $desc = '美啦啦砸金蛋活动')
{
    //签名参与参数
    $parameters = ['partner_trade_no' => $mchid . date('Ymd') . $no, 'mchid' => $mchid, 'mch_appid' => $appid, 'openid' => $openid, 'check_name' => 'NO_CHECK', 'amount' => $money, 'desc' => $desc, 'spbill_create_ip' => '124.172.237.174', 'nonce_str' => createNoncestr()];
    $sign = getSign($parameters);
    //获取签名
    $parameters['sign'] = $sign;
    $xml = arrayToXml($parameters);
    //生成请求XML
    return postXmlSSLCurl($xml, $payurl);
}
Exemplo n.º 2
0
function getSign($data, $salt)
{
    foreach ($data as $key => $value) {
        if (is_array($value)) {
            $validate[$key] = getSign($value, $salt);
        } else {
            $validate[$key] = $value;
        }
    }
    $validate['salt'] = $salt;
    sort($validate, SORT_STRING);
    return sha1(implode($validate));
}
Exemplo n.º 3
0
/**
 * 增强验签
 * @param type $data
 * @param type $enhancedKey
 * @return boolean
 */
function checkEnhancedSign($data, $enhancedKey)
{
    if (empty($data) || !isset($data['enhanced_sign']) || empty($enhancedKey)) {
        return false;
    }
    $enhancedSign = $data['enhanced_sign'];
    //sign及enhanced_sign 不参与签名
    unset($data['sign'], $data['enhanced_sign']);
    $_enhancedSign = getSign($data, $enhancedKey);
    if ($_enhancedSign != $enhancedSign) {
        return false;
    }
    return true;
}
Exemplo n.º 4
0
/*$appid= AppId;
$secret= AppSecret;
$appkey= 支付专用签名串PaySignKey*/
$appid = 'wxfea3e92ddf4936d5';
$secret = '674828c37381378ba816825c3d533a82';
$appkey = 'd1qOVI3KEMQWz2uX2koFros8U2NZpTN5CX8JU6cN50UU4SO38fqRKZ3GD8jv3Ut6UzMmChnc1JerftH1Opdg0hnCW4GC35f09HCkqad3ashj9MVJVVSglknlMZMsJCgi';
$url_get = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $secret;
$json = json_decode(curlGet($url_get));
$access_token = $json->access_token;
$openid = $postObj->OpenId;
$deliver_msg = "ok";
$deliver_status = "1";
$deliver_timestamp = time();
$out_trade_no = $_GET['out_trade_no'];
$transid = $_GET['transaction_id'];
$sign = getSign($appid, $appkey, $deliver_msg, $deliver_status, $deliver_timestamp, $openid, $out_trade_no, $transid);
$url = "https://api.weixin.qq.com/pay/delivernotify?access_token=" . $access_token;
$data = '{
		"appid" : "' . $appid . '",
		"openid" : "' . $openid . '",
		"transid" : "' . $transid . '",
		"out_trade_no" : "' . $out_trade_no . '",
		"deliver_timestamp" : "' . $deliver_timestamp . '",
		"deliver_status" : "' . $deliver_status . '",
		"deliver_msg" : "' . $deliver_msg . '",
		"app_signature" : "' . $sign . '",
		"sign_method" : "sha1"
	}';
$result = json_decode(api_notice_increment($url, $data));
if ($result->errmsg == "ok") {
    //如果发货成功,则向客服发送微信文本信息
Exemplo n.º 5
0
//替换appkey
$partner2 = "1220019101";
//替换partnerid
$partnerKey2 = "b01d961b83bd549b5593f0f0a41b18a2";
//替换partnerkey
$notify_url2 = "http://www.jinguishop.com/auth/wxpaynotify.php";
$input_charset2 = "UTF-8";
//传递下列参数
$body2 = !empty($_GET['orderName']) ? $_GET['orderName'] : '';
$out_trade_no2 = !empty($_GET['orderid']) ? $_GET['orderid'] : '';
//订单号,商户需要保证该字段对于本商户的唯一性
$total_fee2 = !empty($_GET['price']) ? $_GET['price'] : '';
$packageString = getPackage($body2, $input_charset2, $notify_url2, $out_trade_no2, $partner2, $spbill_create_ip2, $total_fee2, $partnerKey2);
$time_stamp = time();
$nonce_str = randomkeys();
$sign = getSign($appid2, $appkey2, $nonce_str, $packageString, $time_stamp);
function getPackage($body2, $input_charset2, $notify_url2, $out_trade_no2, $partner2, $spbill_create_ip2, $total_fee2, $partnerKey2)
{
    $banktype = "WX";
    $fee_type = "1";
    //费用类型,这里1为默认的人民币
    $body = $body2;
    $input_charset = $input_charset2;
    $notify_url = $notify_url2;
    $out_trade_no = $out_trade_no2;
    $partner = $partner2;
    $spbill_create_ip = $spbill_create_ip2;
    $total_fee = $total_fee2;
    $partnerKey = $partnerKey2;
    $signString = "bank_type=" . $banktype . "&body=" . $body . "&fee_type=" . $fee_type . "&input_charset=" . $input_charset . "&notify_url=" . $notify_url . "&out_trade_no=" . $out_trade_no . "&partner=" . $partner . "&spbill_create_ip=" . $spbill_create_ip . "&total_fee=" . $total_fee . "&key=" . $partnerKey;
    $md5SignValue = strtoupper(md5($signString));
Exemplo n.º 6
0
/**
 * Склеить из массива SQL-выражение для фильтра
 * @param array $arFilter
 * @param array $arTables
 * @return string
 */
function filterGlue($arFilter, $arTables = false)
{
    //d($arFilter);
    $cnt = 0;
    $str = '';
    $signs = array('=', '!', '!=', '<', '>', '<=', '>=');
    if (is_array($arFilter['CATALOG_ID']) and !empty($arFilter['CATALOG_ID'])) {
        $arCatalogIDs = $arFilter['CATALOG_ID'];
        unset($arFilter['CATALOG_ID']);
    }
    foreach ($arFilter as $key => $value) {
        if ($value == "" and !in_array($key, $signs)) {
            unset($arFilter[$key]);
        }
    }
    foreach ($arFilter as $key => $value) {
        $cnt++;
        $sign = getSign($key);
        $key = str_replace($signs, '', $key);
        $arConstants = array("NULL", "null", "FALSE", "false", "TRUE", "true");
        if ($value === "NULL" or $value === "null") {
            switch ($sign) {
                case '=':
                    $sign = 'IS';
                    break;
                case '!=':
                    $sign = 'IS NOT';
                    break;
                default:
                    $sign = $sign;
                    break;
            }
        }
        $bTbl = false;
        if ($arTables and is_array($arTables)) {
            foreach ($arTables as $t => $v) {
                if (strstr($value, $t . '.')) {
                    $bTbl = true;
                }
            }
        }
        if ($arTables and $bTbl or in_array($value, $arConstants)) {
            $str .= sSql($key) . " " . $sign . " " . sSql($value);
        } else {
            $str .= sSql($key) . " " . $sign . " '" . sSql($value) . "'";
        }
        if ($cnt != count($arFilter)) {
            $str .= " AND ";
        }
    }
    if (is_array($arCatalogIDs) and !empty($arCatalogIDs)) {
        if (!empty($str)) {
            $str .= " AND";
        }
        $str .= " (";
        $cntr = 1;
        foreach ($arCatalogIDs as $catID) {
            if ($arTables === false) {
                $str .= "CATALOG_ID = '" . intVal($catID) . "'";
            } else {
                $str .= "ELEMENT.CATALOG_ID = '" . intVal($catID) . "'";
            }
            if ($cntr != count($arCatalogIDs)) {
                $str .= " OR ";
                $cntr++;
            }
        }
        $str .= ') GROUP BY ';
        if ($arTables === false) {
            $str .= "ID";
        } else {
            $str .= "ELEMENT.ID";
        }
    }
    return $str;
}
Exemplo n.º 7
0
$where_sql_list = array();
foreach ($filter_list as $filter) {
    $field = getClmnName($filter['field']);
    $data = $filter['data'];
    if ($data['type'] == 'string') {
        array_push($where_sql_list, " {$field} LIKE '%{$data['value']}%'");
    }
    if ($data['type'] == 'numeric') {
        $sign = getSign($data['comparison']);
        array_push($where_sql_list, " {$field} {$sign} {$data['value']}");
    }
    if ($data['type'] == 'list') {
        array_push($where_sql_list, " {$field} IN ({$data['value']})");
    }
    if ($data['type'] == 'date') {
        $sign = getSign($data['comparison']);
        $date = str_replace('/', '-', $data['value']);
        if ($sign == '=') {
            $sdate = "{$date} 00:00:00";
            $edate = date('Y-m-d H:i:s', strtotime("{$date} 00:00:00 +1 day"));
            array_push($where_sql_list, " {$field} >= '{$sdate}' AND {$field} < '{$edate}'");
        } else {
            array_push($where_sql_list, " {$field} {$sign} '{$date}'");
        }
    }
}
$where_sql = implode(" AND ", $where_sql_list);
// --- ORDER BY 句
$sort_prop = 'user_id';
$sort_dir = 'ASC';
if ($sort != '') {
Exemplo n.º 8
0
/**
 * Created by PhpStorm.
 * User: xiehaowei
 * Date: 2016/11/8
 * Time: 下午8:01
 */
require_once 'config.php';
$user_id = isset($_GET['uid']) ? $_GET['uid'] : (isset($argv[1]) ? $argv[1] : 1610202);
$device = isset($argv[2]) ? $argv[2] : 'a6ee478108b348ef96a2f75747e7c54a';
$i = 2500;
while ($i > 1000) {
    $user_sig = getUserSign($user_id);
    $content = isset($_GET['content']) ? $_GET['content'] : '{"h":{"u":' . $user_id . ',"s":"' . $user_sig . '","v":2,"t":"json","d":"' . $device . '","os":"IOS","av":"2.3.2","dt":"phone","target":"main","thumb":"l","ts":"timestamp"},"ptype":"' . mt_rand(1, 2) . '","pid":"' . $i . '"}';
    $timestamp = time();
    $content = str_replace('timestamp', $timestamp, $content);
    $sign = getSign($content);
    $ch = curl_init('https://dedao.igetget.com/v3/badge/sharedida?sign=' . $sign);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
    $ret = curl_exec($ch);
    echo $ret . PHP_EOL;
    $i--;
    sleep(1);
}
//file_put_contents('','',FILE_APPEND);
exit(PHP_EOL);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '192.168.100.30:7777/achievement/calendar');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
Exemplo n.º 9
0
<?php

require_once '../components/Config.php';
if (Config::$sCurrentEnvironment == Config::ENVIRONMENT_PRODUCTION) {
    $aConfig = (require_once '../config/production/config.php');
} else {
    $aConfig = (require_once '../config/local/config.php');
}
Config::init()->setCurrentConfig($aConfig);
if (!empty($_POST)) {
    header(sprintf("location: %s/?action=recurringPaymentSecondary&token=%s&biller_client_id=%s&amount=%s&currency=%s&timestamp=%s&sign=%s", Config::init()->get('bridge_url'), $_POST['token'], $_POST['biller_client_id'], $_POST['amount'], $_POST['currency'], $_POST['timestamp'], getSign($_POST['token'] . $_POST['biller_client_id'] . $_POST['amount'] . $_POST['currency'] . $_POST['timestamp'])));
}
function getSign($sMessage)
{
    $sPrivateKey = file_get_contents('private.pem');
    $rPrivateKey = openssl_pkey_get_private($sPrivateKey);
    openssl_sign($sMessage, $sSign, $rPrivateKey, OPENSSL_ALGO_SHA1);
    return bin2hex($sSign);
}
?>

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
	<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap.no-responsive.no-icons.min.css">
</head>
<body>
<div class="container span8">
	<!-- START: Recurring form -->
	<div class="clearfix"></div>
Exemplo n.º 10
0
<?php

require_once '../components/Config.php';
if (Config::$sCurrentEnvironment == Config::ENVIRONMENT_PRODUCTION) {
    $aConfig = (require_once '../config/production/config.php');
} else {
    $aConfig = (require_once '../config/local/config.php');
}
Config::init()->setCurrentConfig($aConfig);
if (!empty($_POST)) {
    header(sprintf("location: %s/?action=authPaymentCompletion&token=%s&type=%s&timestamp=%s&sign=%s", Config::init()->get('bridge_url'), $_POST['token'], $_POST['type'], $_POST['timestamp'], getSign($_POST['token'] . $_POST['type'] . $_POST['timestamp'])));
}
function getSign($sMessage)
{
    $sPrivateKey = file_get_contents('private.pem');
    $rPrivateKey = openssl_pkey_get_private($sPrivateKey);
    openssl_sign($sMessage, $sSign, $rPrivateKey, OPENSSL_ALGO_SHA1);
    return bin2hex($sSign);
}
?>

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
	<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap.no-responsive.no-icons.min.css">
</head>
<body>
<div class="container span8">
	<!-- START: Payment form -->
	<div class="clearfix"></div>
Exemplo n.º 11
0
        array_push($query_string, $key . '=' . $val);
    }
    $query_string = join('&', $query_string);
    return $query_string;
}
function https_get($url, $timeout = 10)
{
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // 要求结果为字符串且输出到屏幕上
    curl_setopt($ch, CURLOPT_HEADER, 0);
    // 不要http header 加快效率
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    // https请求 不验证证书和hosts
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}
// $uri = 'gmtype=adddiamond&uin=10050&value=20';
$uri = array('gmtype' => 'adddiamond', 'uin' => 10000014, 'value' => 20);
$str = getDataStr($uri);
$uri['sign'] = urlencode(getSign($str, $priKey));
//必需urlencode
$str = getDataStr($uri);
$url = 'http://10.10.2.39/gm/magic.php?' . $str;
echo "url is {$url}\n";
echo https_get($url);
Exemplo n.º 12
0
Arquivo: info.php Projeto: ehmedov/www
					</td>
		        </tr>
		    </table>
		</td>
	<td valign="top" width=100%>
		<table cellspacing=0 cellpadding=0 border=0 width=600>
		<tr>
			<td align=right valign=bottom><img src="img/design/border-1x1.gif" width=10 height=10 border=0 hspace=0 vspace=0></td>
			<td style="background:url(img/design/border-h.gif) repeat-x bottom left"></td>
			<td align=left valign=bottom><img src="img/design/border-3x1.gif" width=10 height=10 border=0 hspace=0 vspace=0></td>
		</tr>
		<tr>
			<td style="background:url(img/design/border-v.gif) repeat-y top right"></td>
			<td style="padding: 3px;">
			<?php 
echo "<img src=img/zodiac/" . getSign($zd, $zm) . ">&nbsp;";
if ($db["marry"] != "") {
    if ($db["sex"] == "male") {
        $pol = "Женат на: " . $db["marry"];
    } else {
        if ($db["sex"] == "female") {
            $pol = "Замужем за: " . $db["marry"];
        }
    }
    echo "<a href='info.php?log=" . str_replace(" ", "%20", $db["marry"]) . "' target='_blank'><img src='img/index/married.gif' title='{$pol}' border=0></a>&nbsp;";
}
if ($db["vip"] > time()) {
    echo "<img src='img/naqrada/vip.gif' border=0 alt='V.I.P Клуб WWW.OlDmeydan.Pe.Hu. \nЕще: " . convert_time($db["vip"]) . "'>&nbsp;";
}
if ($db["dealer"]) {
    echo "<img src='img/naqrada/dealer.gif' alt='Персонаж является ДИЛЛЕРОМ' border=0>&nbsp;";
Exemplo n.º 13
0
function pay_notice_call($payInfo, $ok_msg = 'success', $err_msg = 'fail')
{
    if ($payInfo['err_code'] === 0) {
        $database_order = D('Order');
        $product_model = M('Product');
        $product_sku = M('Product_sku');
        $condition_order['trade_no'] = $payInfo['order_param']['trade_no'];
        $nowOrder = $database_order->where($condition_order)->find();
        if ($nowOrder && $nowOrder['status'] == 1) {
            $data_order['third_id'] = $payInfo['order_param']['third_id'];
            $data_order['payment_method'] = $payInfo['order_param']['pay_type'];
            $data_order['pay_money'] = $payInfo['order_param']['pay_money'];
            $data_order['paid_time'] = $_SERVER['REQUEST_TIME'];
            $data_order['status'] = 2;
            if (D('Order')->where($condition_order)->data($data_order)->save()) {
                if (is_array($payInfo['order_param']['third_data'])) {
                    $data_order_trade['order_id'] = $nowOrder['order_id'];
                    $data_order_trade['third_data'] = serialize($payInfo['order_param']['third_data']);
                    D('Order_trade')->data($data_order_trade)->add();
                    /*如果是活动的订单 将返回订单状态*/
                    if ($nowOrder['bak'] != '') {
                        $bak = unserialize($nowOrder['bak']);
                        if ($bak && isset($bak['from'])) {
                            if (strpos($bak['from'], 'pigcms') !== false) {
                                $apiUrl = rtrim(option('config.syn_domain'), '/') . '/';
                                $salt = option('config.encryption') ? option('config.encryption') : 'pigcms';
                                $postData = array('option' => array('where' => array('orderid' => $bak['orderid'])), 'data' => array('paid' => '1', 'paytype' => $data_order['payment_method']), 'model' => str_replace('pigcms_', '', $bak['from']), 'toOrder' => '1', 'token' => $bak['token']);
                                $postData['sign'] = getSign($postData, $salt);
                                $url = $apiUrl . '/index.php?g=Home&m=Auth&a=update';
                                api_curl_post($url, $postData);
                            }
                        }
                    }
                }
                $nowStore = D('Store')->field('`income`,`unbalance`')->where(array('store_id' => $nowOrder['store_id']))->find();
                if (empty($nowOrder['useStorePay'])) {
                    $data_store['income'] = $nowStore['income'] + $payInfo['order_param']['pay_money'];
                    $data_store['unbalance'] = $nowStore['unbalance'] + $payInfo['order_param']['pay_money'];
                }
                $data_store['last_edit_time'] = time();
                //店铺收入
                if (D('Store')->where(array('store_id' => $nowOrder['store_id']))->data($data_store)->save()) {
                    //收入记录
                    $data_financial_record['store_id'] = $nowOrder['store_id'];
                    $data_financial_record['order_id'] = $nowOrder['order_id'];
                    $data_financial_record['order_no'] = $nowOrder['order_no'];
                    $data_financial_record['income'] = $payInfo['order_param']['pay_money'];
                    $data_financial_record['type'] = '1';
                    $data_financial_record['balance'] = $nowStore['income'];
                    $data_financial_record['payment_method'] = $payInfo['order_param']['pay_type'];
                    $data_financial_record['trade_no'] = $nowOrder['trade_no'];
                    $data_financial_record['add_time'] = $_SERVER['REQUEST_TIME'];
                    $data_financial_record['user_order_id'] = $nowOrder['order_id'];
                    $data_financial_record['storeOwnPay'] = $nowOrder['useStorePay'];
                    $financial_record_id = D('Financial_record')->data($data_financial_record)->add();
                }
                if (!empty($nowOrder['uid'])) {
                    M('Store_user_data')->upUserData($nowOrder['store_id'], $nowOrder['uid'], 'unsend');
                }
                //减少库存 因为支付的特殊性,不处理是否有过修改
                $database_order_product = D('Order_product');
                $condition_order_product['order_id'] = $nowOrder['order_id'];
                $orderProductList = $database_order_product->where($condition_order_product)->select();
                $database_product = D('Product');
                $database_product_sku = D('Product_sku');
                //分销商品
                $fx_product = array();
                foreach ($orderProductList as $value) {
                    //分销订单处理
                    $product = M('Product')->get(array('product_id' => $value['product_id']));
                    if (!empty($product['supplier_id'])) {
                        //分销商品
                        $fx_product[$product['supplier_id']][] = array('product_id' => $value['product_id'], 'sku_id' => $value['sku_id'], 'sku_data' => $value['sku_data'], 'quantity' => $value['pro_num'], 'price' => $value['pro_price'], 'cost_price' => $product['cost_price'], 'postage_type' => $product['postage_type'], 'postage' => $product['postage'], 'postage_template_id' => $product['postage_template_id'], 'source_product_id' => $product['source_product_id'], 'original_product_id' => $product['original_product_id'], 'comment' => $value['comment']);
                        //获取分销商品(同步库存)
                        if (!empty($product['original_product_id'])) {
                            $where = array();
                            $where['_string'] = "product_id = '" . $product['original_product_id'] . "' OR original_product_id = '" . $product['original_product_id'] . "'";
                            $tmp_fx_products = M('Product')->getFxProducts($where);
                            $tmp_properties = '';
                            if (!empty($value['sku_data'])) {
                                $sku_data = unserialize($value['sku_data']);
                                $skus = array();
                                foreach ($sku_data as $sku) {
                                    $skus[] = $sku['pid'] . ':' . $sku['vid'];
                                }
                                $tmp_properties = implode(';', $skus);
                            }
                            if (!empty($tmp_fx_products)) {
                                foreach ($tmp_fx_products as $tmp_fx_product) {
                                    $database_product->where(array('product_id' => $tmp_fx_product['product_id']))->setDec('quantity', $value['pro_num']);
                                    if (!empty($tmp_properties)) {
                                        //更新商品属性库存
                                        $database_product_sku->where(array('product_id' => $tmp_fx_product['product_id'], 'properties' => $tmp_properties))->setDec('quantity', $value['pro_num']);
                                    }
                                    if ($tmp_fx_product['product_id'] == $product['original_product_id'] || $tmp_fx_product['product_id'] == $value['product_id']) {
                                        //源商品或当前购买的商品
                                        $database_product->where(array('product_id' => $tmp_fx_product['product_id']))->setInc('sales', $value['pro_num']);
                                        //更新销量
                                        if (!empty($tmp_properties)) {
                                            //更新商品属性库存
                                            $database_product_sku->where(array('product_id' => $tmp_fx_product['product_id'], 'properties' => $tmp_properties))->setInc('sales', $value['pro_num']);
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        //普通商品
                        if ($value['sku_id']) {
                            $condition_product_sku['sku_id'] = $value['sku_id'];
                            $database_product_sku->where($condition_product_sku)->setInc('sales', $value['pro_num']);
                            $database_product_sku->where($condition_product_sku)->setDec('quantity', $value['pro_num']);
                        }
                        $condition_product['product_id'] = $value['product_id'];
                        $database_product->where($condition_product)->setInc('sales', $value['pro_num']);
                        $database_product->where($condition_product)->setDec('quantity', $value['pro_num']);
                        if (!empty($product['is_fx'])) {
                            //允许分销商品
                            $where = array();
                            $where['_string'] = "original_product_id = '" . $product['product_id'] . "'";
                            $tmp_fx_products = M('Product')->getFxProducts($where);
                            $tmp_properties = '';
                            if (!empty($value['sku_data'])) {
                                $sku_data = unserialize($value['sku_data']);
                                $skus = array();
                                foreach ($sku_data as $sku) {
                                    $skus[] = $sku['pid'] . ':' . $sku['vid'];
                                }
                                $tmp_properties = implode(';', $skus);
                            }
                            if (!empty($tmp_fx_products)) {
                                foreach ($tmp_fx_products as $tmp_fx_product) {
                                    $database_product->where(array('product_id' => $tmp_fx_product['product_id']))->setDec('quantity', $value['pro_num']);
                                    if (!empty($tmp_properties)) {
                                        //更新商品属性库存
                                        $database_product_sku->where(array('product_id' => $tmp_fx_product['product_id'], 'properties' => $tmp_properties))->setDec('quantity', $value['pro_num']);
                                    }
                                }
                            }
                        }
                    }
                }
                if (!empty($fx_product)) {
                    //订单中有分销商品
                    $fx_order = M('Fx_order');
                    $fx_order_product = M('Fx_order_product');
                    $nowAddress = unserialize($nowOrder['address']);
                    //默认使用用户收货地址
                    foreach ($fx_product as $key => $products) {
                        $supplier_id = $key;
                        //供货商id
                        $fx_order_no = date('YmdHis', $_SERVER['REQUEST_TIME']) . mt_rand(100000, 999999);
                        //分销订单号
                        $sub_total = 0;
                        $cost_sub_total = 0;
                        $postage = 0;
                        $total = 0;
                        $cost_total = 0;
                        $quantity = 0;
                        $hasTplPostage = false;
                        $postage_arr = array();
                        foreach ($products as $key => $product) {
                            //订单商品
                            $properties = '';
                            if (!empty($product['sku_data'])) {
                                $sku_data = unserialize($product['sku_data']);
                                $skus = array();
                                foreach ($sku_data as $sku) {
                                    $skus[] = $sku['pid'] . ':' . $sku['vid'];
                                }
                                $properties = implode(';', $skus);
                            }
                            $source_product_id = $product['source_product_id'];
                            //分销来源商品
                            if (!empty($properties)) {
                                //有属性
                                $sku = $product_sku->getSku($source_product_id, $properties);
                                $cost_price = $sku['cost_price'];
                                //分销来源商品的成本价格
                            } else {
                                //无属性
                                $source_product_info = $product_model->get(array('product_id' => $source_product_id), 'cost_price');
                                $cost_price = $source_product_info['cost_price'];
                                //分销来源商品的成本价格
                            }
                            $price = $product['price'];
                            $products[$key]['cost_price'] = $cost_price;
                            $sub_total += $price * $product['quantity'];
                            //订单商品总金额
                            $cost_sub_total += $cost_price * $product['quantity'];
                            //订单商品成本总金额
                            $quantity += $product['quantity'];
                            //订单商品总数量
                            //来源商品供货商
                            $product_info = $product_model->get(array('product_id' => $source_product_id), 'store_id');
                            $original_supplier_id = $product_info['store_id'];
                        }
                        //订单运费
                        $fx_postages = array();
                        if (!empty($nowOrder['fx_postage'])) {
                            $fx_postages = unserialize($nowOrder['fx_postage']);
                        }
                        $postage = !empty($fx_postages[$supplier_id]) ? $fx_postages[$supplier_id] : 0;
                        //供货商运费
                        //订单总金额
                        $total = $sub_total + $postage;
                        //订单成本总金额
                        $cost_total = $cost_sub_total + $postage;
                        $data = array('fx_order_no' => $fx_order_no, 'uid' => $nowOrder['uid'], 'session_id' => $nowOrder['session_id'], 'order_id' => $nowOrder['order_id'], 'order_no' => $nowOrder['order_no'], 'fx_trade_no' => date('YmdHis', $_SERVER['REQUEST_TIME']) . mt_rand(100000, 999999), 'supplier_id' => $supplier_id, 'store_id' => $nowOrder['store_id'], 'quantity' => $quantity, 'sub_total' => $sub_total, 'cost_sub_total' => $cost_sub_total, 'postage' => $postage, 'total' => $total, 'cost_total' => $cost_total, 'delivery_user' => $nowOrder['address_user'], 'delivery_tel' => $nowOrder['address_tel'], 'delivery_address' => $nowOrder['address'], 'add_time' => time(), 'user_order_id' => $nowOrder['order_id'], 'fx_postage' => $nowOrder['fx_postage'], 'status' => 2);
                        if ($fx_order_id = $fx_order->add($data)) {
                            //添加分销商订单
                            //标识订单为分销订单(包含分销商品)
                            M('Order')->setFxOrder($nowOrder['store_id'], $nowOrder['order_id']);
                            $suppliers = array();
                            //添加订单商品
                            foreach ($products as $product) {
                                if (!empty($product['original_product_id'])) {
                                    $product_info = $database_product->field('store_id, original_product_id')->where(array('product_id' => $product['original_product_id']))->find();
                                    $tmp_supplier_id = $product_info['store_id'];
                                } else {
                                    $product_info = $database_product->field('store_id')->where(array('product_id' => $product['product_id']))->find();
                                    $tmp_supplier_id = $product_info['store_id'];
                                }
                                $suppliers[] = $tmp_supplier_id;
                                $fx_order_product->add(array('fx_order_id' => $fx_order_id, 'product_id' => $product['product_id'], 'source_product_id' => $product['product_id'], 'price' => $product['price'], 'cost_price' => $product['cost_price'], 'quantity' => $product['quantity'], 'sku_id' => $product['sku_id'], 'sku_data' => $product['sku_data'], 'comment' => $product['comment']));
                            }
                            $suppliers = array_unique($suppliers);
                            //分销商
                            $suppliers = implode(',', $suppliers);
                            if (!empty($suppliers)) {
                                //修改订单,设置分销商
                                D('Fx_order')->where(array('fx_order_id' => $fx_order_id))->data(array('suppliers' => $suppliers))->save();
                            }
                        }
                    }
                    //获取分销利润
                    if (!empty($financial_record_id) && !empty($cost_total)) {
                        $profit = $total - $cost_total;
                        if ($profit > 0) {
                            D('Financial_record')->where(array('pigcms_id' => $financial_record_id))->data(array('profit' => $profit))->save();
                        }
                    }
                    //逐级提交订单
                    $drp_level = $nowStore['drp_level'];
                    //当前分销等级
                    $supplier_chain = D('Store_supplier')->where(array('seller_id' => $nowOrder['store_id']))->find();
                    $supply_chain = $supplier_chain['supply_chain'];
                    if ($supplier_chain['type'] == 1) {
                        //排他分销
                        $suppliers = explode(',', $supply_chain);
                        sort($suppliers);
                        $suppliers = array_reverse($suppliers);
                        array_pop($suppliers);
                        if (!empty($suppliers)) {
                            foreach ($suppliers as $supplier) {
                                $fx_order_info = D('Fx_order')->where(array('supplier_id' => $supplier, 'user_order_id' => $nowOrder['order_id']))->find();
                                if (!empty($fx_order_info)) {
                                    $tmp_data['trade_no'] = date('YmdHis', $_SERVER['REQUEST_TIME']) . mt_rand(100000, 999999);
                                    $tmp_data['total'] = $fx_order_info['cost_total'];
                                    $tmp_data['postage'] = $fx_order_info['postage'];
                                    $tmp_data['order_id'] = $fx_order_info['fx_order_id'];
                                    $tmp_data['supplier_id'] = $supplier;
                                    $tmp_data['seller_id'] = $fx_order_info['store_id'];
                                    pay($tmp_data);
                                }
                            }
                        }
                    }
                }
                // 更改赠送的优惠券为可用
                M('User_coupon')->save(array('is_valid' => 1), array('give_order_id' => $nowOrder['order_id']));
                exit($ok_msg);
            } else {
                exit($err_msg);
            }
        } else {
            exit($err_msg);
        }
    } else {
        exit($ok_msg);
    }
}