function createOrder() { $post = $this->req->post; $user_id = (int) $this->session->data['user']['user_id']; $cart = $post['cart']; $address_id = (int) $post['radio']; $payway = $post['payway']; if (strlen($cart) < 3) { setHint('您的购物车中还没有商品,不能提交订单', 'bad'); $this->res->redirect('checkout/productList'); } if ($payway == 'alipay') { if (isMobil()) { $payway = 'ali_wap_pay'; } else { $payway = 'ali_pc_pay'; } } else { if ($payway == 'weixinpay') { $payway = 'weixin_pay'; } else { if (!empty($payway)) { $paycode = strtoupper($payway); $payway = 'ali_bank_pay'; } else { setHint('请选择支付方式', 'bad'); $this->res->redirect('checkout/productList'); } } } //暂时只能使用此方式 $payway = 'ali_pc_pay'; //检查地址是否存在 $address = $this->load->model('address'); $result_address = $address->findById($address_id, $user_id); if ($result_address) { $address->updateUsed($user_id, 0); $address->updateUsing($address_id, 1); } else { setHint('地址不存在,不能提交订单', 'bad'); $this->res->redirect('checkout/productList'); } /*偏远地区省份id 内蒙古,青海,宁夏,甘肃,广西,海南*/ $remote_arr = array('150000', '630000', '640000', '620000', '450000', '460000'); $is_remote = in_array($result_address['provinceid'], $remote_arr); //查询商品 $product_id_arr = array(); $product_num_arr = array(); preg_match_all('/(\\d+)[:](\\d+)/', $cart, $arr); $product_id_arr = $arr[1]; $product_num_arr = $arr[2]; $products = array(); if (count($product_id_arr) > 0 && count($product_id_arr) == count($product_num_arr)) { $product = $this->load->model('product'); foreach ($product_id_arr as $key => $value) { $result = $product->findById((int) $value); if (!$result || empty($product_num_arr[$key])) { setHint('非法的商品信息,不能提交订单', 'bad'); $this->res->redirect('checkout/productList'); break; } else { $result['piece'] = $product_num_arr[$key]; } $products[] = $result; } //生成订单 //事务 $this->db->begin(); $order = $this->load->model('order'); $order_info = $this->load->model('orderInfo'); $ret = $order->add(array("pay" => 0, "send" => 0, "user_id" => $user_id, "address_id" => $address_id, 'address' => $result_address['province'] . $result_address['city'] . $result_address['area'] . $result_address['zip'] . $result_address['detail'], "date" => timenow())); if (!$ret) { $this->db->rollback(); setHint('生成订单失败'); $this->res->redirect('checkout/productList'); } $lastId = (int) $this->db->lastId(); $total_money = 0; foreach ($products as $key => $value) { $money = $value['piece'] * $value['price']; if ($value['free_postage'] == 1) { if ($is_remote) { $fee = $value['postage_remote']; } else { $fee = $value['postage']; } $money = $money + $value['piece'] * $fee; } $total_money = $total_money + $money; $ret = $order_info->add(array('order_id' => $lastId, "product_id" => (int) $value['product_id'], 'piece' => (int) $value['piece'], "postage" => empty($value['free_postage']) ? 0 : (double) $fee, "price" => (double) $value['price'], "money" => (double) $money)); if (!$ret) { $this->db->rollback(); setHint('生成订单失败'); $this->res->redirect('checkout/productList'); } } $orderNum = createOrderNum(); $ret = $order->update($lastId, $orderNum . $lastId, $total_money); if (!$ret) { $this->db->rollback(); setHint('生成订单失败'); $this->res->redirect('checkout/productList'); } $this->db->commit(); //订单生成后清空cookie // setcookie('cart','',time()-3600); //订单已经提交,查询订单并返回结果 $product_subject = ''; foreach ($products as $key => $value) { $product_subject = $product_subject . $value['name'] . "(" . $value['piece'] . ")"; } $data = $order->findById($lastId); $data['subject'] = $product_subject; $data['body'] = '购物愉快'; $data['url'] = HOSTNAME . 'product/' . $products[0]['product_id']; //生成清单后删除此用户所有其他未付款订单 $order->deleteNotPay($lastId, $user_id); return $this->load->view('checkout_createorder', array('order' => $data, 'products' => $products, 'payway' => $payway, 'paycode' => $paycode)); } else { setHint('非法的商品信息,不能提交订单', 'bad'); } }
function history($uid) { $arr = get_ip_address(); $data["uid"] = $uid; $data["login_ip"] = $arr->ip; $data["login_country"] = $arr->country; $data["login_province"] = $arr->region; $data["login_city"] = $arr->city; $data["login_isp"] = $arr->isp; $data["login_time"] = NOW_TIME; /* 登录方式 */ $data["login_way"] = isMobil(); $history = M("history"); $history->create(); $history->add($data); }