$_SESSION['order_sn'] = $order_sn; //订单结算 if ($status == 4) { $log->record('计算三级分销'); //计算三级分销 $log->record('计算分销奖金:' . $cart['total_reward']); distribution_settle($cart['total_reward'], $user_info['path'], $order_sn); //计算赠送积分 if ($total_integral_given) { add_memeber_exchange_log($_SESSION['account'], 0, 0, 0, $cart['total_integral_given'], 0, 'settle', '系统结算'); add_member_reward($_SESSION['account'], 0, $cart['total_integral_given'], '订单' . $order_sn . '赠送积分'); } //计入商家收入 $business_income = $cart['total_product_amount'] + $cart['total_delivery_fee'] - $cart['total_reward']; if (add_business_exchange($cart['business_account'], 0, $business_income, $_SESSION['account'], $order_sn . '支付成功')) { add_business_trade($cart['business_account'], $business_income, $order_sn); } else { //增加商家收入失败 $log->record($order_sn . '计入商家收入失败'); } //如果会员购买了activity=4的产品,则升级 $check_can_levelup = 'select am.`activity_id` from ' . $db->table('activity_mapper') . ' as am left join ' . $db->table('order_detail') . ' using (`product_sn`) where `order_sn`=\'' . $order_sn . '\' and `activity_id`=4'; if ($db->fetchOne($check_can_levelup)) { $member_data = array('level_id' => 1); $db->autoUpdate('member', $member_data, '`account`=\'' . $_SESSION['account'] . '\''); } } } else { $db->rollback(); $response['msg'] = '提交订单信息失败,请稍后再试'; }
private function _pay_order($sn, $data) { global $db, $log; //产品订单 $get_order_info = 'select `amount`,`account`,`business_account`,`product_amount`,`mobile`,`delivery_fee` from ' . $db->table('order') . ' where `order_sn`=\'' . $sn . '\''; $order = $db->fetchRow($get_order_info); add_order_log($sn, $order['account'], 3, "在线支付"); if ($order && $order['amount'] * 100 == $data->total_fee && $data->sign == tenpay_sign($data, $this->mch_key)) { //验证订单金额正确 //1. 设置订单为已付款 $order_data = array('status' => 3, 'pay_time' => time()); $flag = $db->autoUpdate('order', $order_data, '`order_sn`=\'' . $sn . '\' and `status`<>3'); if ($flag && $db->get_affect_rows()) { $log->record($sn . '支付成功'); //2. 订单结算 $get_path = 'select `path` from ' . $db->table('member') . ' where `account`=\'' . $order['account'] . '\''; $path = $db->fetchOne($get_path); distribution_settle($order['reward_amount'], $path, $sn); //3. 新增商家收入 $business_income = $order['product_amount'] + $order['delivery_fee'] - $order['reward_amount']; if (add_business_exchange($order['business_account'], 0, $business_income, $order['account'], '用户在线支付')) { add_business_trade($order['business_account'], $business_income, $sn); } else { //增加商家收入失败 } $get_order_detail = 'select `product_sn`,`product_name`,`count`,`is_virtual`,`attributes` from ' . $db->table('order_detail') . ' where `order_sn`=\'' . $sn . '\''; $order_detail = $db->fetchAll($get_order_detail); foreach ($order_detail as $od) { //扣减库存 consume_inventory($od['product_sn'], $od['attributes'], $od['count']); //如果是虚拟产品,则生成预约券 if ($od['is_virtual']) { $get_virtual_contents = 'select `content`,`count`,`total` from ' . $db->table('virtual_content') . ' where `product_sn`=\'' . $od['product_sn'] . '\''; $virtual_contents = $db->fetchAll($get_virtual_contents); $virtual_content = ''; if ($virtual_contents) { $virtual_content = serialize($virtual_contents); } add_order_content($order['business_account'], $order['account'], $order['mobile'], $sn, $od['product_sn'], $od['product_name'], $virtual_content, 2); } } //如果会员购买了activity=4的产品,则升级 $check_can_levelup = 'select am.`activity_id` from ' . $db->table('activity_mapper') . ' as am left join ' . $db->table('order_detail') . ' using (`product_sn`) where `order_sn`=\'' . $sn . '\' and `activity_id`=4'; if ($db->fetchOne($check_can_levelup)) { $member_data = array('level_id' => 1); $db->autoUpdate('member', $member_data, '`account`=\'' . $order['account'] . '\''); } } } else { //金额不正确 } }
add_order_log($sn, $order['account'], 3, "在线支付"); if ($order && $order['amount'] == $total_fee) { //验证订单金额正确 //1. 设置订单为已付款 $order_data = array('status' => 3, 'pay_time' => time()); $flag = $db->autoUpdate('order', $order_data, '`order_sn`=\'' . $sn . '\' and `status`<3'); if ($flag && $db->get_affect_rows()) { $log->record($sn . '支付成功'); //2. 订单结算 $get_path = 'select `path` from ' . $db->table('member') . ' where `account`=\'' . $order['account'] . '\''; $path = $db->fetchOne($get_path); distribution_settle($order['reward_amount'], $path, $sn); //3. 新增商家收入 $business_income = $order['product_amount'] + $order['delivery_fee'] - $order['reward_amount']; if (add_business_exchange($order['business_account'], 0, $business_income, $order['account'], '用户在线支付')) { add_business_trade($order['business_account'], $business_income, $sn); } else { //增加商家收入失败 } $get_order_detail = 'select `product_sn`,`product_name`,`count`,`is_virtual`,`attributes` from ' . $db->table('order_detail') . ' where `order_sn`=\'' . $sn . '\''; $order_detail = $db->fetchAll($get_order_detail); foreach ($order_detail as $od) { //状态变为已发货 $delivery = false; //扣减库存 consume_inventory($od['product_sn'], $od['attributes'], $od['count']); //如果是虚拟产品,则生成预约券 if ($od['is_virtual']) { $get_virtual_contents = 'select `content`,`count`,`total` from ' . $db->table('virtual_content') . ' where `product_sn`=\'' . $od['product_sn'] . '\''; $virtual_contents = $db->fetchAll($get_virtual_contents); $virtual_content = '';