public function create_account() { $now = time(); $weixin = D('Weixin_bind')->where(array('store_id' => $_SESSION['store']['store_id']))->find(); //公众号类型4认证订阅号 3认证服务号 2服务号 1订阅号 -1未绑定公众号 if (empty($weixin)) { $wxtype = -1; } else { if (($weixin['service_type_info'] == 0 || $weixin['service_type_info'] == 1) && $weixin['verify_type_info'] == 0) { $wxtype = 4; } else { if ($weixin['service_type_info'] == 2 && $weixin['verify_type_info'] == 0) { $wxtype = 3; } else { if ($weixin['service_type_info'] == 2 && $weixin['verify_type_info'] == -1) { $wxtype = 2; } else { if (($weixin['service_type_info'] == 0 || $weixin['service_type_info'] == 1) && $verify_type == -1) { $wxtype = 1; } } } } } $post_data = array('userid' => $_SESSION['user']['uid'], 'username' => $this->getUserName($_SESSION['user']['uid']), 'type' => $this->synType, 'time' => $now, 'randstr' => $this->randString(10, 'mixed'), 'wxuserid' => $_SESSION['store']['store_id'], 'domain' => option('config.site_url'), 'wxtype' => $wxtype); $post_data['sign'] = $this->getSign($post_data); $url = $this->apiUrl . '/index.php?g=Home&m=Auth&a=signup'; $return = api_curl_post($url, $post_data); if ($return['errcode'] > 0) { exit($return['errmsg']); } else { if (empty($_SESSION['session_id']) || $_SESSION['session_id_expire'] < $now) { $session_data = array('username' => $post_data['username'], 'userid' => $post_data['userid'], 'type' => $this->synType); $session_data['sign'] = $this->getSign($session_data); $session_url = $this->apiUrl . '/index.php?g=Home&m=Auth&a=signin'; $result = api_curl_post($session_url, $session_data); //创建公众号 if ('0' == $result['status']) { if (!isset($_SESSION['store']['pigcmsToken']) || $_SESSION['store']['pigcmsToken'] == '') { $_SESSION['store']['pigcmsToken'] = $pigcmsToken = $this->getToken($_SESSION['store']['store_id']); D('Store')->where(array('store_id' => $_SESSION['store']['store_id']))->data(array('pigcmsToken' => $pigcmsToken))->save(); } $_SESSION['session_id'] = $result['session_id']; $_SESSION['session_id_expire'] = $now + 1200; } else { //var_dump($result); } } } }
switch ($_GET['source']) { case 'pigcms': $apiUrl = option('config.syn_domain') ? rtrim(option('config.syn_domain'), '/') . '/' : 'http://svn.404.cn/'; $salt = option('config.encryption') ? option('config.encryption') : 'pigcms'; $token = htmlspecialchars($_GET['token']); $return['wecha_id'] = $_SESSION['openid']; $return['token'] = $token; $return['sex'] = $_SESSION['wap_user']['sex']; $return['issub'] = isSub($_SESSION['openid']); $return['portrait'] = $_SESSION['wap_user']['avatar']; $return['wechaname'] = $return['truename'] = $_SESSION['wap_user']['nickname']; $return['province'] = $_SESSION['wap_user']['province']; $return['city'] = $_SESSION['wap_user']['city']; $postData = array('option' => array('where' => array('wecha_id' => $return['wecha_id'], 'token' => $token), 'order' => 'id DESC', 'limit' => '1'), 'data' => $return, 'model' => 'Userinfo', 'token' => $token, 'debug' => true); $postData['sign'] = getSign($postData, $salt); $result = api_curl_post($apiUrl . 'index.php?g=Home&m=Auth&a=insert', $postData); if ($result['status'] == 0) { header('Location:' . $apiUrl . 'index.php?g=Home&m=Auth&a=oauth2&token=' . $token . '&wechat_id=' . $return['wecha_id']); } else { pigcms_tips($result['message'], 'none'); } break; } function getSign($data, $salt) { foreach ($data as $key => $value) { if (is_array($value)) { $validate[$key] = getSign($value, $salt); } else { $validate[$key] = $value; }
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); } }