/** * 预览详情 */ public function actionDetail() { $id = $this->get('id'); $Product = new ModelProduct(); $model['product'] = $Product->Item($id); echo $this->renderPartial('detail', array('row' => $model['product']['row'], 'image' => $model['product']['image']), true); }
function add($productInfo) { $product = new ModelProduct(); $productItem = $product->getInfo($productInfo['id']); $info = array('id' => $productInfo['id'], 'product_name' => $productInfo['product_name'], 'attribute' => $productInfo['attribute'], 'price' => $productInfo['price'], 'sn' => $productItem['sn'], 'photoUrl' => CFG_URL . 'data/product/' . $productItem['photo'], 'number' => 1); $_SESSION['cartInfo'][$productInfo['id'] . '_' . $productInfo['attribute']] = $info; }
/** * 商城入口 */ public function actionIndex() { //分类列表 $Cat = new ModelCat(); $model['cat_list'] = $Cat->Items(); //最新上架 $Product = new ModelProduct(); $condition = "p.is_default = 'true'"; $model['new_list'] = $Product->getProducts('g.goods_id,g.name,g.image_default_id,g.price,p.uptime,p.product_id,p.bn', $condition, 'p.uptime DESC', 0, 10); $this->render('index', array('model' => $model)); }
/** * 列表 */ public function actionIndex() { $cid = $this->get('cid'); $page = isset($_GET['page']) ? $this->get('page') : 1; $model = array(); $Product = new ModelProduct(); $condition = "g.cat_id = {$cid} AND p.is_default = 'true'"; $model['count'] = $Product->getCount($condition); $start = ($page - 1) * $this->pagesize; $model['product_list'] = $Product->getProducts('g.goods_id,g.name,g.image_default_id,g.price,p.uptime,p.product_id,p.bn', $condition, 'p.uptime DESC', $start, $this->pagesize); $Cat = new ModelCat(); $model['cat'] = $Cat->Item("cat_id = {$cid}"); $model['parent_cat'] = $Cat->Item("cat_id = {$model['cat']['parent_id']}"); $mutli = Page::multi($page, $model['count'], $this->pagesize, '/category.html?cid=' . $cid); $this->render('index', array('model' => $model, 'cid' => $cid, 'mutli' => $mutli)); }
/** * 购物车列表 * * @param string $member_id * @return array */ public static function Cart($member_id = '') { $Product = new ModelProduct(); if ($member_id) { $Cart = new ModelCart(); //判断临时数据库信息 $num = $Cart->CartProductSum($member_id); $cart_list = $Cart->Rows($member_id); $cart_list_new = $Product->CartGoods($cart_list); $item = isset($cart_list_new['item']) ? $cart_list_new['item'] : array(); $amount = $Cart->CartProductAmount($member_id); } else { $CartCache = new ModelCartCache(); $product_list = $CartCache->Product(); $cart_list_new = $Product->CartGoodsCache($product_list); $item = isset($cart_list_new['item']) ? $cart_list_new['item'] : array(); $total = $CartCache->Total(); $num = isset($total['total_num']) ? $total['total_num'] : 0; $amount = isset($total['total_price']) ? $total['total_price'] : 0.0; } return array('item' => $item, 'num' => $num, 'amount' => $amount); }
/** * 购物车为空 */ public function actionEmpty() { if ($this->username) { $Cart = new ModelCart(); $Product = new ModelProduct(); $cart_list = $Cart->Rows($this->member_id); $cart_list_new = $Product->CartGoods($cart_list); if ($cart_list_new) { $this->redirect('index'); } } $this->render('empty'); }
/** * 订单商品 * * @param $order_idArr * @return array|bool|string */ public function OrderProduct($order_idArr) { if (!$order_idArr) { return ''; } $item_sql = "SELECT i.order_id,i.product_id,i.goods_id,i.bn,i.name,i.price,i.nums,i.addon,i.cost,p.mktprice\n FROM {{b2c_order_items}} as i left join {{b2c_products}}\n as p on p.product_id = i.product_id"; if (is_array($order_idArr)) { $order_ids = implode(',', $order_idArr); $item_sql .= " WHERE order_id IN ({$order_ids})"; } else { $item_sql .= " WHERE order_id = {$order_idArr}"; } $items = $this->ModelQueryAll($item_sql); $itemsOrder = $goods_ids = $goods_image = array(); foreach ($items as $k => $v) { $goods_ids[] = $v['goods_id']; $items[$k]['price'] = number_format($v['price'], '2', '.', ''); $items[$k]['cost'] = number_format($v['cost'], '2', '.', ''); $items[$k]['mktprice'] = number_format($v['mktprice'], '2', '.', ''); } $itemProduct = Help::ArrayListByKey($items, 'goods_id'); if (!$goods_ids) { return $itemsOrder; } $goods_str = implode(',', $goods_ids); $Product = new ModelProduct(); $goods_image = $Product->GoodsDefaultImage($goods_str); foreach ($goods_image as $k => $v) { $itemProduct[$k]['image'] = $this->img_url . $v['s_url']; } foreach ($items as $v) { $item = $v; $item['image'] = isset($itemProduct[$v['goods_id']]['image']) ? $itemProduct[$v['goods_id']]['image'] : ''; $itemsOrder[$v['order_id']][] = $item; } if (!is_array($order_idArr)) { return $itemsOrder[$order_idArr]; } return $itemsOrder; }
/** * 购物车订单信息 * * @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' => '生成失败'); }