/** * 订单确认 * * @param $member_id * @return array */ public function Confirm($member_id) { header("Pragma:no-cache"); header("Cache-Control:no-cache,must-revalidate,no-store"); header("Expires:-1"); $order_info = Yii::app()->cache->get('b2c-cart-product-set-' . $member_id); if ($order_info) { return $order_info; } $Cart = new ModelCart(); $Product = new ModelProduct(); $Addr = new ModelAddr(); $cart_list = $Cart->Rows($member_id); $cart_list_new = $Product->CartGoods($cart_list); $item = $cart_list_new['item']; $num = $Cart->CartProductSum($member_id); $amount = $Cart->CartProductAmount($member_id); //收货地址 $addr_row = $Addr->AddrOrderDefault($member_id); return array('item' => $item, 'num' => $num, 'amount' => $amount, 'addr_row' => $addr_row); }
/** * 购物车订单信息 * * @param $member_id * @return array */ public function CardIdentProduct($member_id) { $Product = new ModelProduct(); $cart_list = $Product->CartGoods($this->Rows($member_id)); if (empty($cart_list['item'])) { return false; } $product_list = $cart_list['item']; $quantity_sum = 0; foreach ($product_list as $k => $v) { $ident[] = "'" . 'goods_' . $v['goods_id'] . '_' . $v['product_id'] . "'"; $quantity_sum += $v['quantity']; $sql = "SELECT p.product_id,p.goods_id,p.bn,p.price,p.cost,p.mktprice,p.name,p.store,p.spec_info,g.type_id\n FROM {{b2c_products}} p LEFT JOIN {{b2c_goods}} g ON p.goods_id = g.goods_id\n WHERE p.product_id =" . $v['product_id']; $product_info = $this->ModelQueryRow($sql); $product_list[$k]['name'] = $product_info['name']; $product_list[$k]['bn'] = $product_info['bn']; $product_list[$k]['price'] = number_format($product_info['price'], '2', '.', ''); $product_list[$k]['cost'] = number_format($product_info['cost'], '2', '.', ''); $product_list[$k]['mktprice'] = number_format($product_info['mktprice'], '2', '.', ''); $product_list[$k]['store'] = $product_info['store']; $product_list[$k]['spec_info'] = $product_info['spec_info']; $product_list[$k]['type_id'] = $product_info['type_id']; } $identStr = implode(',', $ident); $condition = ''; $condition .= " AND obj_ident IN ({$identStr})"; //商品总额 $amount = $this->CartProductAmount($member_id, 'goods', $condition); $id = 'b2c-cart-product-set-' . $member_id; $cart_cache = Yii::app()->cache->get($id); if (empty($cart_cache['addr'])) { //收货地址 $Addr = new ModelAddr(); $member_addr = $Addr->AddrOrderDefault($member_id); $addr = $member_addr ? $member_addr : array(); $cart_cache['addr'] = $addr; } if (empty($cart_cache['dly'])) { //配送方式 $dly_sql = "SELECT dt_id,dt_name,firstprice FROM {{b2c_dlytype}} limit 1"; $cart_cache['dly'] = $this->ModelQueryRow($dly_sql); $cart_cache['dly']['firstprice'] = 5.0; } if (empty($cart_cache['payment'])) { //支付方式 $cart_cache['payment'] = 'alipay'; } //订单总额 $total = $amount + $cart_cache['dly']['firstprice']; //快递费用 $result['cache_id'] = $id; $result['ident'] = $identStr; $result['amount'] = $amount; $result['total'] = $total; $result['quantity_sum'] = $quantity_sum; $result['cart_list'] = $product_list; $result['dly'] = $cart_cache['dly']; $result['addr'] = $cart_cache['addr']; $result['payment'] = $cart_cache['payment']; if (Yii::app()->cache->set($id, $result, $this->cart_expire)) { return array('code' => 200, 'data' => $result); } return array('code' => 400, 'msg' => '生成失败'); }