function action_act_account() { $user = $GLOBALS['user']; $_CFG = $GLOBALS['_CFG']; $_LANG = $GLOBALS['_LANG']; $smarty = $GLOBALS['smarty']; $db = $GLOBALS['db']; $ecs = $GLOBALS['ecs']; $user_id = $_SESSION['user_id']; include_once ROOT_PATH . 'includes/lib_clips.php'; include_once ROOT_PATH . 'includes/lib_order.php'; $amount = isset($_POST['amount']) ? floatval($_POST['amount']) : 0; if ($amount <= 0) { show_message($_LANG['amount_gt_zero']); } /* 变量初始化 */ $surplus = array('user_id' => $user_id, 'rec_id' => !empty($_POST['rec_id']) ? intval($_POST['rec_id']) : 0, 'process_type' => isset($_POST['surplus_type']) ? intval($_POST['surplus_type']) : 0, 'payment_id' => isset($_POST['payment_id']) ? intval($_POST['payment_id']) : 0, 'user_note' => isset($_POST['user_note']) ? trim($_POST['user_note']) : '', 'amount' => $amount); /* 退款申请的处理 */ if ($surplus['process_type'] == 1) { /* 判断是否有足够的余额的进行退款的操作 */ $sur_amount = get_user_surplus($user_id); if ($amount > $sur_amount) { $content = $_LANG['surplus_amount_error']; show_message($content, $_LANG['back_page_up'], '', 'info'); } // 插入会员账目明细 $amount = '-' . $amount; $surplus['payment'] = ''; $surplus['rec_id'] = insert_user_account($surplus, $amount); /* 如果成功提交 */ if ($surplus['rec_id'] > 0) { $content = $_LANG['surplus_appl_submit']; show_message($content, $_LANG['back_account_log'], 'user.php?act=account_log', 'info'); } else { $content = $_LANG['process_false']; show_message($content, $_LANG['back_page_up'], '', 'info'); } } else { if ($surplus['payment_id'] <= 0) { show_message($_LANG['select_payment_pls']); } include_once ROOT_PATH . 'includes/lib_payment.php'; // 获取支付方式名称 $payment_info = array(); $payment_info = payment_info($surplus['payment_id']); $surplus['payment'] = $payment_info['pay_name']; if ($surplus['rec_id'] > 0) { // 更新会员账目明细 $surplus['rec_id'] = update_user_account($surplus); } else { // 插入会员账目明细 $surplus['rec_id'] = insert_user_account($surplus, $amount); } // 取得支付信息,生成支付代码 $payment = unserialize_config($payment_info['pay_config']); // 生成伪订单号, 不足的时候补0 $order = array(); $order['order_sn'] = $surplus['rec_id']; $order['user_name'] = $_SESSION['user_name']; $order['surplus_amount'] = $amount; // 计算支付手续费用 $payment_info['pay_fee'] = pay_fee($surplus['payment_id'], $order['surplus_amount'], 0); // 计算此次预付款需要支付的总金额 $order['order_amount'] = $amount + $payment_info['pay_fee']; // 记录支付log $order['log_id'] = insert_pay_log($surplus['rec_id'], $order['order_amount'], $type = PAY_SURPLUS, 0); /* 调用相应的支付方式文件 */ include_once ROOT_PATH . 'includes/modules/payment/' . $payment_info['pay_code'] . '.php'; /* 取得在线支付方式的支付按钮 */ $pay_obj = new $payment_info['pay_code'](); $payment_info['pay_button'] = $pay_obj->get_code($order, $payment); /* 模板赋值 */ $smarty->assign('payment', $payment_info); $smarty->assign('pay_fee', price_format($payment_info['pay_fee'], false)); $smarty->assign('amount', price_format($amount, false)); $smarty->assign('order', $order); $smarty->display('user_transaction.dwt'); } }
//插入会员账目明细 $surplus['rec_id'] = insert_user_account($surplus, $amount); } //取得支付信息,生成支付代码 $payment = unserialize_config($payment_info['pay_config']); //生成伪订单号, 不足的时候补0 $order = array(); $order['order_sn'] = $surplus['rec_id']; $order['user_name'] = $_SESSION['user_name']; $order['surplus_amount'] = $amount; //计算支付手续费用 $payment_info['pay_fee'] = pay_fee($surplus['payment_id'], $order['surplus_amount'], 0); //计算此次预付款需要支付的总金额 $order['order_amount'] = $amount + $payment_info['pay_fee']; //记录支付log $order['log_id'] = insert_pay_log($surplus['rec_id'], $order['order_amount'], $type = PAY_SURPLUS, 0); /* 调用相应的支付方式文件 */ include_once ROOT_PATH . 'includes/modules/payment/' . $payment_info['pay_code'] . '.php'; /* 取得在线支付方式的支付按钮 */ $pay_obj = new $payment_info['pay_code'](); $payment_info['pay_button'] = $pay_obj->get_code($order, $payment); /* 模板赋值 */ $smarty->assign('payment', $payment_info); $smarty->assign('pay_fee', price_format($payment_info['pay_fee'], false)); $smarty->assign('amount', price_format($amount, false)); $smarty->assign('order', $order); $smarty->display('user_transaction.dwt'); } } elseif ($action == 'cancel') { include_once ROOT_PATH . 'includes/lib_clips.php'; $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
/** * 合并订单 * @param string $from_order_sn 从订单号 * @param string $to_order_sn 主订单号 * @return 成功返回true,失败返回错误信息 */ function merge_order($from_order_sn, $to_order_sn) { /* 订单号不能为空 */ if (trim($from_order_sn) == '' || trim($to_order_sn) == '') { return $GLOBALS['_LANG']['order_sn_not_null']; } /* 订单号不能相同 */ if ($from_order_sn == $to_order_sn) { return $GLOBALS['_LANG']['two_order_sn_same']; } /* 取得订单信息 */ $from_order = order_info(0, $from_order_sn); $to_order = order_info(0, $to_order_sn); /* 检查订单是否存在 */ if (!$from_order) { return sprintf($GLOBALS['_LANG']['order_not_exist'], $from_order_sn); } elseif (!$to_order) { return sprintf($GLOBALS['_LANG']['order_not_exist'], $to_order_sn); } /* 检查合并的订单是否为普通订单,非普通订单不允许合并 */ if ($from_order['extension_code'] != '' || $to_order['extension_code'] != 0) { return $GLOBALS['_LANG']['merge_invalid_order']; } /* 检查订单状态是否是已确认或未确认、未付款、未发货 */ if ($from_order['order_status'] != OS_UNCONFIRMED && $from_order['order_status'] != OS_CONFIRMED) { return sprintf($GLOBALS['_LANG']['os_not_unconfirmed_or_confirmed'], $from_order_sn); } elseif ($from_order['pay_status'] != PS_UNPAYED) { return sprintf($GLOBALS['_LANG']['ps_not_unpayed'], $from_order_sn); } elseif ($from_order['shipping_status'] != SS_UNSHIPPED) { return sprintf($GLOBALS['_LANG']['ss_not_unshipped'], $from_order_sn); } if ($to_order['order_status'] != OS_UNCONFIRMED && $to_order['order_status'] != OS_CONFIRMED) { return sprintf($GLOBALS['_LANG']['os_not_unconfirmed_or_confirmed'], $to_order_sn); } elseif ($to_order['pay_status'] != PS_UNPAYED) { return sprintf($GLOBALS['_LANG']['ps_not_unpayed'], $to_order_sn); } elseif ($to_order['shipping_status'] != SS_UNSHIPPED) { return sprintf($GLOBALS['_LANG']['ss_not_unshipped'], $to_order_sn); } /* 检查订单用户是否相同 */ if ($from_order['user_id'] != $to_order['user_id']) { return $GLOBALS['_LANG']['order_user_not_same']; } /* 合并订单 */ $order = $to_order; $order['order_id'] = ''; $order['add_time'] = gmtime(); // 合并商品总额 $order['goods_amount'] += $from_order['goods_amount']; // 合并折扣 $order['discount'] += $from_order['discount']; if ($order['shipping_id'] > 0) { // 重新计算配送费用 $weight_price = order_weight_price($to_order['order_id']); $from_weight_price = order_weight_price($from_order['order_id']); $weight_price['weight'] += $from_weight_price['weight']; $weight_price['amount'] += $from_weight_price['amount']; $weight_price['number'] += $from_weight_price['number']; $region_id_list = array($order['country'], $order['province'], $order['city'], $order['district']); $shipping_area = shipping_area_info($order['shipping_id'], $region_id_list); $order['shipping_fee'] = shipping_fee($shipping_area['shipping_code'], unserialize($shipping_area['configure']), $weight_price['weight'], $weight_price['amount'], $weight_price['number']); // 如果保价了,重新计算保价费 if ($order['insure_fee'] > 0) { $order['insure_fee'] = shipping_insure_fee($shipping_area['shipping_code'], $order['goods_amount'], $shipping_area['insure']); } } // 重新计算包装费、贺卡费 if ($order['pack_id'] > 0) { $pack = pack_info($order['pack_id']); $order['pack_fee'] = $pack['free_money'] > $order['goods_amount'] ? $pack['pack_fee'] : 0; } if ($order['card_id'] > 0) { $card = card_info($order['card_id']); $order['card_fee'] = $card['free_money'] > $order['goods_amount'] ? $card['card_fee'] : 0; } // 红包不变,合并积分、余额、已付款金额 $order['integral'] += $from_order['integral']; $order['integral_money'] = value_of_integral($order['integral']); $order['surplus'] += $from_order['surplus']; $order['money_paid'] += $from_order['money_paid']; // 计算应付款金额(不包括支付费用) $order['order_amount'] = $order['goods_amount'] - $order['discount'] + $order['shipping_fee'] + $order['insure_fee'] + $order['pack_fee'] + $order['card_fee'] - $order['bonus'] - $order['integral_money'] - $order['surplus'] - $order['money_paid']; // 重新计算支付费 if ($order['pay_id'] > 0) { // 货到付款手续费 $cod_fee = $shipping_area ? $shipping_area['pay_fee'] : 0; $order['pay_fee'] = pay_fee($order['pay_id'], $order['order_amount'], $cod_fee); // 应付款金额加上支付费 $order['order_amount'] += $order['pay_fee']; } /* 插入订单表 */ do { $order['order_sn'] = get_order_sn(); if ($GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('order_info'), addslashes_deep($order), 'INSERT')) { break; } else { if ($GLOBALS['db']->errno() != 1062) { die($GLOBALS['db']->errorMsg()); } } } while (true); // 防止订单号重复 /* 订单号 */ $order_id = $GLOBALS['db']->insert_id(); /* 更新订单商品 */ $sql = 'UPDATE ' . $GLOBALS['ecs']->table('order_goods') . " SET order_id = '{$order_id}' " . "WHERE order_id " . db_create_in(array($from_order['order_id'], $to_order['order_id'])); $GLOBALS['db']->query($sql); include_once ROOT_PATH . 'includes/lib_clips.php'; /* 插入支付日志 */ insert_pay_log($order_id, $order['order_amount'], PAY_ORDER); /* 删除原订单 */ $sql = 'DELETE FROM ' . $GLOBALS['ecs']->table('order_info') . " WHERE order_id " . db_create_in(array($from_order['order_id'], $to_order['order_id'])); $GLOBALS['db']->query($sql); /* 删除原订单支付日志 */ $sql = 'DELETE FROM ' . $GLOBALS['ecs']->table('pay_log') . " WHERE order_id " . db_create_in(array($from_order['order_id'], $to_order['order_id'])); $GLOBALS['db']->query($sql); /* 返还 from_order 的红包,因为只使用 to_order 的红包 */ if ($from_order['bonus_id'] > 0) { unuse_bonus($from_order['bonus_id']); } /* 返回成功 */ return true; }
if ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_PLACE) { change_order_goods_storage($order['order_id'], true, SDT_PLACE); } /* 清空购物车 */ clear_cart($flow_type); /* 清除缓存,否则买了商品,但是前台页面读取缓存,商品数量不减少 */ clear_all_files(); if (!empty($order['shipping_name'])) { $order['shipping_name'] = trim(stripcslashes($order['shipping_name'])); } /* 取得支付信息,生成支付代码 */ if ($order['order_amount'] > 0) { $payment = payment_info($order['pay_id']); include_once 'includes/modules/payment/' . $payment['pay_code'] . '.php'; $pay_obj = new $payment['pay_code'](); $order['log_id'] = insert_pay_log($new_order_id, $order['order_amount'], PAY_ORDER); $pay_online = $pay_obj->get_code($order, unserialize_config($payment['pay_config'])); $order['pay_desc'] = $payment['pay_desc']; $smarty->assign('pay_online', $pay_online); } /* 订单信息 */ $smarty->assign('order', $order); $smarty->assign('total', $total); $smarty->assign('goods_list', $cart_goods); $smarty->assign('order_submit_back', sprintf('您可以 %s 或去 %s', '<a href="index.php">返回首页</a>', '<a href="user.php">用户中心</a>')); // 返回提示 unset($_SESSION['flow_consignee']); // 清除session中保存的收货人信息 unset($_SESSION['flow_order']); unset($_SESSION['direct_shopping']); if ($_SESSION['user_id'] > 0) {
/* 如果需要,发短信 */ if (count($split_order['suborder_list']) > 0) { foreach ($split_order['suborder_list'] as $key => $val) { $supplier_ids[$key] = $val['order_sn']; } } //$supplier_ids = array_keys(); include_once 'send.php'; send_sms($supplier_ids, '您有一条新订单,订单号为:ordersn请注意查看。【shopname】', 1); $order['order_amount'] = $all_order_amount; //替换为总金额去支付 /* 取得支付信息,生成支付代码 */ if ($split_order['sub_order_count'] > 1) { $order['order_sn'] = $parent_order_id; /* 插入支付日志 */ $order['log_id'] = insert_pay_log($order['order_sn'], $order['order_amount'], PAY_ORDER); } else { /* 插入支付日志 */ //$order['log_id'] = insert_pay_log($order['order_id'], $order['order_amount'], PAY_ORDER); } if ($order['order_amount'] > 0) { $payment = payment_info($order['pay_id']); include_once 'includes/modules/payment/' . $payment['pay_code'] . '.php'; $pay_obj = new $payment['pay_code'](); $pay_online = array('online' => 1); //$pay_obj->get_code($order, unserialize_config($payment['pay_config'])); $order['pay_desc'] = $payment['pay_desc']; $smarty->assign('pay_online', $pay_online); } if (!empty($order['shipping_name'])) { $order['shipping_name'] = trim(stripcslashes($order['shipping_name']));
/* 发放红包 send_order_bonus($order['order_id']); } } } } } /* 清空购物车 clear_cart($flow_type); /* 清除缓存,否则买了商品,但是前台页面读取缓存,商品数量不减少 */ clear_all_files(); /* 插入支付日志 */ $order['log_id'] = insert_pay_log($order['order_sn'], $order['order_price'], PAY_ORDER); /* 取得支付信息,生成支付代码 */ /*if ($order['order_amount'] > 0) { $payment = payment_info($order['pay_id']); include_once('includes/modules/payment/' . $payment['pay_code'] . '.php'); $pay_obj = new $payment['pay_code']; $pay_online = $pay_obj->get_code($order, unserialize_config($payment['pay_config'])); $order['pay_desc'] = $payment['pay_desc']; $smarty->assign('pay_online', $pay_online); }
/** * 退款流程 * * @param array $order_id * @param array $payment * @param decimal $refund_amount */ public function refund($order, $payment, $refund_amount = 0) { global $db, $ecs; //获取pay_log记录 $sql = "SELECT * FROM " . $ecs->table('pay_log') . " WHERE order_id = '{$order['order_id']}' AND pay_id = '{$order['pay_id']}' AND is_paid = 1 ORDER BY log_id DESC LIMIT 1"; $log = $db->getRow($sql); if (empty($log)) { return false; } $wxtk = read_config('wxtoken'); $payment = array_merge($payment, $wxtk); $amount = $refund_amount > 0 && $refund_amount < $log['order_amount'] ? $refund_amount : $log['order_amount']; $refund = array('appid' => $payment['appid'], 'mch_id' => $payment['wxpay_mchid'], 'op_user_id' => $payment['wxpay_mchid'], 'nonce_str' => rands(32), 'out_refund_no' => $order['order_sn'], 'out_trade_no' => $order['order_sn'], 'refund_fee' => $amount * 100, 'total_fee' => $log['order_amount'] * 100, 'transaction_id' => $log['outer_sn']); $refund['sign'] = $this->sign($refund, $payment['wxpay_key']); // 调用微信退款接口 require_once ROOT_PATH . 'include/cls_curl.php'; $curl = new Curl(array('server' => 'https://api.mch.weixin.qq.com', 'ssl_verify_peer' => FALSE)); $curl->option(CURLOPT_SSLCERTTYPE, 'PEM'); $curl->option(CURLOPT_SSLCERT, ROOT_PATH . '../data/cert/wxpay_cert.pem'); $curl->option(CURLOPT_SSLKEYTYPE, 'PEM'); $curl->option(CURLOPT_SSLKEY, ROOT_PATH . '../data/cert/wxpay_key.pem'); $xml = array2xml($refund); //echo htmlspecialchars($xml);exit; $response = $curl->post('secapi/pay/refund', $xml, 'xml'); // 检查错误 if ($response['return_code'] == 'FAIL' || $response['result_code'] == 'FAIL') { $response['paytype'] = 'wxpay'; $response['order_id'] = $order['order_id']; insert_error_log('refund', $response, __FILE__); return false; } //pay_log 插入退款记录 insert_pay_log($order['order_id'], $amount, $order['pay_id'], PAY_ORDER, 3); return true; }