/** * 创建订单并用户支付。 * @param string $agencyId 机构ID * @param string $userId 用户ID * @param string $productId 产品ID * @param integer $type 产品类型 * @return string 订单号 */ public function createPayOrder($agencyId = '', $userId = '', $productId = '', $type = 1) { if (APP_DEBUG) { trace("创建订单[{$agencyId},{$userId},{$type},{$productId}]..."); } //加载用户数据 $user = M('User')->where(array('UserID' => $userId))->find(); //加载机构折扣 $discount = M('jigou')->where(array('JGID', $agencyId))->getField('Dicount'); //加载产品 $product = $this->loadProduct($agencyId, $type, $productId, $discount); if (empty($product)) { return false; } //生成订单号 $order_no = create_order($userId); //创建订单 $db = M('Orders'); $data['OrderID'] = $order_no; $data['UID'] = $userId; $data['UserName'] = $user['UserName']; $data['Mobile'] = $user['Mobile']; $data['JGID'] = $agencyId; $data['create_time'] = date('Y-m-d H:i:s', time()); $data['OldPrice'] = $product['oldprice']; $data['CostPrice'] = $product['cost_price'] * $discount; $data['TotalPrice'] = $product['totalprice']; $data['SalesPrice'] = $product['goodprice']; $data['OrderType'] = 2; //1:机构付费,2:学员付费 $data['OrderState'] = 1; //0:未付费订单,1:已付费,2:已开通,-1:已关闭,-2:已删除 //$data['OpenTime'] = date('Y-m-d H:i:s'); $data['PayState'] = 1; //0:未支付,1:已支付,2:退款申请,3:部分退款,4:全部退款 $data['PayTime'] = date('Y-m-d H:i:s'); $data['Operator'] = 'ios'; //用户余额 if ($user['Money'] < $product['goodprice']) { return 0; } //创建订单 if ($db->add($data)) { //创建订单明细 if ($this->createOrderDetail($agencyId, $user, $order_no, $type, $product, $discount)) { //创建支付流水 $accId = M('UserAccount')->add(array('JGID' => $agencyId, 'UID' => $userId, 'OrderID' => $order_no, 'Channel' => -2, 'MoneyFlow' => 1, 'TradeType' => 1, 'StateTF' => 1, 'Money' => $product['goodprice'], 'Note' => 'ios付款', 'AddTime' => date('Y-m-d h:i:s'))); if ($accId) { //更新用户余额(支付订单) M('user')->where(array('JGID' => $agencyId, 'UserID' => $userId))->setDec('Money', $product['goodprice']); //返回订单号 return $order_no; } } } return 0; }
$mccurrency = $_POST['mc_currency']; // số lượng sản phẩm dduwwc giao dịch $itemnumber = $_POST['item_number']; // số lượng tiền thanh toán của khách hàng đã giao dịch $paymentgross = $_POST['payment_gross']; //mail buyer $tobuyer = $mail_buyer; $subjectbuyer = 'The Payment'; $headersbuyer = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); //mail seller $toseller = '*****@*****.**'; $subjectseller = 'The Payment'; $messageseller = 'hello Seller'; $headersseller = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); if (strcmp($paymentstatus, 'Completed') == 0) { create_order($_POST); //luu cac thong tin ve giao dich xuong database //send mail to buyer $messagebuyer = 'hello Buyer the payment is Success'; mail($tobuyer, $subjectbuyer, $messagebuyer, $headersbuyer); mail($toseller, $subjectseller, $messageseller, $headersseller); //wp_mail('*****@*****.**', 'hello thanh binh', 'payment success'); } else { $messagebuyer = 'hello Buyer the payment is Failure'; //mail($toseller, $subjectseller, $messageseller, $headersseller); mail($tobuyer, $subjectbuyer, $messagebuyer, $headersbuyer); } //Ham này dùng để insert dữ liệu xuống database function create_order() { }
$size = sizeof($order); $ara = array(); // $order=$order[0]; for ($i = 0; $i < $size; $i++) { $x = $order[$i]; $single_order = array(); foreach ($x as $key => $value) { if ($key == "item" || $key == "price" || $key == "quantity") { $single_order[$key] = $value; } } array_push($ara, $single_order); // echo "<br>-----------------<br>"; } // print_r($ara); create_order($ara); function create_order($ara) { $order_id = get_order_number() + 1; foreach ($ara as $x) { mysql_query("INSERT INTO `order`(`id`,`item_id`, `quantity`, `price`) \n\t\t\t\t\t\t\t\t\tVALUES({$order_id},{$x['item']},{$x['quantity']},{$x['price']})") or die(mysql_error()); } } function get_order_number() { $z = mysql_query("select max(id) as maxi from `order`"); while ($y = mysql_fetch_assoc($z)) { return $y['maxi']; } } ?>