function create_the_order() { $redirect = 0; $success = 0; $msg = ''; $order_note = ''; $order_id = 0; if (!wp_verify_nonce(trim($_POST['wp_nonce']), 'order-nonce')) { $msg = 'NonceIsInvalid'; } else { $price = product_smallest_price($_POST['product_id']); // 获取折扣后总价 $cost = $price[5] * $_POST['order_quantity']; // 获取使用优惠码后总价 $promote_support = get_post_meta($_POST['product_id'], 'product_promote_code_support', true); if ($promote_support == 1 && !empty($_POST['promote_code'])) { $cost_promoted = update_promote_code_total_price($_POST['promote_code'], $cost, 0); $order_note = json_encode(array('promote_code' => $_POST['promote_code'])); } else { $cost_promoted = $cost; } $currency = get_post_meta($_POST['product_id'], 'pay_currency', true); $current_user = wp_get_current_user(); $uid = $current_user->ID; if ($currency == 0) { // 使用积分直接支付 // 获取用户当前积分并判断是否足够消费 $credit = (int) get_user_meta($uid, 'tin_credit', true); if ($credit < $cost) { // 积分不足 $msg = '积分不足,立即<a href="' . tin_get_user_url('credit') . '" target="_blank">充值积分</a>'; } else { // 插入数据库记录 $insert = insert_order($_POST['product_id'], $_POST['order_name'], $price[5], $_POST['order_quantity'], $cost, 4, $order_note, $uid, $_POST['receive_name'], $_POST['receive_email'], $_POST['receive_address'], $_POST['receive_zip'], $_POST['receive_phone'], $_POST['receive_mobile'], $_POST['order_msg']); if ($insert) { // 扣除积分//发送站内信 update_tin_credit($uid, $cost, 'cut', 'tin_credit', '下载资源消费' . $cost . '积分'); // 更新已消费积分 if (get_user_meta($uid, 'tin_credit_void', true)) { $void = get_user_meta($uid, 'tin_credit_void', true); $void = $void + $cost; update_user_meta($uid, 'tin_credit_void', $void); } else { add_user_meta($uid, 'tin_credit_void', $cost, true); } // 给资源发布者添加积分并更新积分消息记录 $author = get_post_field('post_author', $_POST['product_id']); update_tin_credit($author, $cost, 'add', 'tin_credit', sprintf(__('你发布收费商品资源《%1$s》被其他用户购买,获得售价%2$s积分', 'tinection'), get_post_field('post_title', $_POST['product_id']), $cost)); //出售获得积分 // 更新资源购买次数与剩余数量 update_success_order_product($_POST['product_id'], $_POST['order_quantity']); // 发送邮件 $to = $_POST['receive_email']; $dl_links = get_post_meta($_POST['product_id'], 'product_download_links', true); $pay_content = get_post_meta($_POST['product_id'], 'product_pay_content', true); // 如果包含付费可见下载链接则附加链接内容至邮件 if (!empty($dl_links) || !empty($pay_content)) { $title = '你在' . get_bloginfo('name') . '购买的内容'; $content = '<p>你在' . get_bloginfo('name') . '使用积分购买了以下内容:</p>'; $content .= deal_pay_dl_content($dl_links); $content .= '<p style="margin-top:10px;">' . $pay_content . '</p><p>感谢你的来访与支持,祝生活愉快!</p>'; } else { $title = '感谢你在' . get_bloginfo('name') . '使用积分付费购买资源'; $content = '<p>你在' . get_bloginfo('name') . '使用积分付费购买资源' . $_POST['order_name'] . '</p><p>支付已成功,扣除了你' . $cost . '积分。</p><p>感谢你的来访与支持,祝生活愉快!</p>'; } $type = '积分商城'; tin_basic_mail('', $to, $title, $content, $type); $msg = '购买成功,已扣除' . $cost . '积分'; $success = 1; } else { $msg = '创建订单失败,请重新再试'; } } } else { // 现金支付方式,首先插入数据库订单记录 $insert = insert_order($_POST['product_id'], $_POST['order_name'], $price[5], $_POST['order_quantity'], $cost_promoted, 1, $order_note, $uid, $_POST['receive_name'], $_POST['receive_email'], $_POST['receive_address'], $_POST['receive_zip'], $_POST['receive_phone'], $_POST['receive_mobile'], $_POST['order_msg']); if ($insert) { $redirect = 1; $success = 1; $order_id = $insert; if (!empty($_POST['receive_email'])) { store_email_template($order_id, '', $_POST['receive_email']); } } else { $msg = '创建订单失败,请重新再试'; } } } $return = array('success' => $success, 'msg' => $msg, 'redirect' => $redirect, 'order_id' => $order_id); echo json_encode($return); exit; }
if ($row_new->order_status <= 2) { $wpdb->query("UPDATE {$table} SET order_status=3 WHERE order_id='{$out_trade_no}'"); store_email_template($out_trade_no, '', $email); } } } } elseif ($_GET['trade_status'] == 'TRADE_FINISHED' || $_GET['trade_status'] == 'TRADE_SUCCESS') { //判断该笔订单是否在商户网站中已经做过处理 global $wpdb; $row = $wpdb->get_row("select * from " . $table . " where order_id=" . $out_trade_no); $product_id = $row->product_id; if ($row) { if ($row->order_status <= 3) { $success_time = $_POST['notify_time']; $wpdb->query("UPDATE {$table} SET order_status=4, trade_no='{$trade_no}', order_success_time='{$success_time}', user_alipay='{$buyer_alipay}' WHERE order_id='{$out_trade_no}'"); update_success_order_product($row->product_id, $row->order_quantity); if (!empty($row->user_email)) { $email = $row->user_email; } //发送订单状态变更email store_email_template($out_trade_no, '', $email); //发送购买可见内容或下载链接或会员状态变更 send_goods_by_order($out_trade_no, '', $email); } } //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序 //如果有做过处理,不执行商户的业务程序 } else { echo "<br /><br />"; } echo "<br /><br />";