public function confirm() { $user = get_user() or $this->error('请先登录!', '/login'); $contract = M('loan_user_contract')->find($user['uid']); if (!$contract) { header('Location: /user/contract'); exit; } $goodsModel = new ShopGoodsModel(); $this->assign('contract', $contract); $this->assign('month_money', $goodsModel->getMonthMoney(I('money') - I('first_money'), I('month'), I('type'))); $this->display(); }
public function getGoods($id) { $model = D('Loan/shop_goods'); $goods = $model->alias('g')->join('__LOAN_SHOP_GOODS_DETAIL__ d on d.id = g.id')->join('__LOAN_SHOP_COLUMN__ c on c.id = g.column_id', 'left')->where(['g.status' => 1, 'd.id' => $id])->field('g.*, d.*, c.name as column_name')->find() or $this->error('此商品已下架!'); if ($goods['column_name']) { $goods['title'] = "【{$goods['column_name']}】{$goods['title']}"; } $goods['tag'] = explode(',', $goods['tag']); $goods['icon'] = ShopGoodsModel::getIconUrl($goods['icon_id']); $goods['property'] = json_decode($goods['property'], true); $goods['property_info'] = json_decode($goods['property_info'], true); return $goods; }
public function __construct() { parent::__construct(); $goodsModel = D('Loan/shop_goods'); $list = M('loan_web_index i')->join('__LOAN_SHOP_GOODS__ g on g.id = i.goods_id', 'left')->where(['i.city_id' => ['in', [0, I('cookie.city_id')]], 'position_id' => ['in', 'banner,dn,fqg,hot,hw,jrth,jxzq,login,ly,reg,sh,sj,sm,xb,xh']])->field(' i.position_id, i.goods_id, i.pic, i.url, i.sort, i.city_id, g.pic as goods_pic, g.title, g.price, g.max_month, g.fix_month, g.fee_id, g.icon_id')->select(); foreach ($list as $item) { if (!$item['url']) { if ($item['price']) { $item['max_month'] = $goodsModel->getMaxMonth(0, $item['price'], 0, $item['max_month'], $item['fix_month']); $item['month_money'] = $goodsModel->getMonthMoney($item['price'], $item['max_month'], $item['fee_id']); $item['url'] = U('/' . $item['goods_id']); $item['icon'] = ShopGoodsModel::getIconUrl($item['icon_id']); } else { $item['url'] = 'javascript:'; } } $_item = isset($this->categories[$item['position_id']][$item['sort'] - 1]) ? $this->categories[$item['position_id']][$item['sort'] - 1] : null; if (!$_item || $_item['city_id'] == 0 && ($item['pic'] || $item['goods_pic'])) { $this->categories[$item['position_id']][$item['sort'] - 1] = $item; } } }
public static function getGoods($options) { $model = new ShopGoodsModel(); $model->join('__LOAN_SHOP_COLUMN__ c on c.id = g.column_id', 'left')->alias('g')->field(' g.id, title, subhead, pic, icon_id, max_month, fix_month, fee_id, price, is_promotion, promotion_price'); foreach ($options as $name => $value) { $model->{$name}($value); } $list = $model->select(); foreach ($list as &$goods) { $goods['icon'] = self::getIconUrl($goods['icon_id']); $goods['url'] = U('/' . $goods['id']); if ($goods['is_promotion']) { $goods['max_month'] = $model->getMaxMonth(0, $goods['promotion_price'], 0, $goods['max_month'], $goods['fix_month']); $goods['month_money'] = $model->getMonthMoney($goods['promotion_price'], $goods['max_month'], $goods['fee_id']); } else { $goods['max_month'] = $model->getMaxMonth(0, $goods['price'], 0, $goods['max_month'], $goods['fix_month']); $goods['month_money'] = $model->getMonthMoney($goods['price'], $goods['max_month'], $goods['fee_id']); } } return $list; }
/** * 获取指定专题分类商品 * @param $cid * @return array */ protected function get_category_goods($cid) { $model = new ShopGoodsModel(); $list = M('loan_shop_goods goods')->join('__LOAN_WEB_TOPIC_GOODS__ topic_goods on topic_goods.goods_id = goods.id')->join('__LOAN_WEB_TOPIC_CATEGORY__ category on category.id = topic_goods.topic_category_id')->where(['category.id' => $cid])->field(' goods.id, goods.title, goods.pic, goods.price, goods.is_promotion, goods.promotion_price, goods.max_month, goods.fix_month, goods.fee_id, category.name as category_name')->order('topic_goods.sort')->select(); foreach ($list as &$goods) { $goods['price_original'] = $goods['price']; if ($goods['is_promotion']) { $goods['price'] = $goods['promotion_price']; } $goods['max_month'] = $model->getMaxMonth(0, $goods['price'], 0, $goods['max_month'], $goods['fix_month']); $goods['month_money'] = $model->getMonthMoney($goods['price'], $goods['max_month'], $goods['fee_id']); } return $list; }
public function index() { // 显示范围参数 $cid = I('cid', 0, 'intval'); $search = I('search'); $price_min = I('price_min', 0, 'intval'); $price_max = I('price_max', 0, 'intval'); // 初始化排序 $sort_config = ['default' => 'sort_weight desc,id DESC', 'price' => 'price', 'price_desc' => 'price DESC', 'sales' => 'total_order', 'sales_desc' => 'total_order DESC']; // 排序方式,可选值:price(价格正序)、price_desc(价格倒序)、sales(销量正序)、sales_desc(销量倒序)、 $sort = I('sort'); $sort = isset($sort_config[$sort]) ? $sort : 'default'; $order = $sort_config[$sort]; $this->assign('sort', $sort); // 读取分类 $category = []; $categoryModel = M('loan_shop_category'); $categorys = $categoryModel->field('id,name,parent_id')->where('status=1')->order('parent_id,sort')->select(); foreach ($categorys as $cate) { $id = $cate['id']; $pid = $cate['parent_id']; unset($cate['parent_id']); if ($pid <= 0) { $category[$id] = $cate; $category[$id]['child'] = []; } elseif (isset($category[$pid])) { $category[$pid]['child'][] = $cate; } } $this_category = M('loan_shop_category')->find($cid); $this->assign('pid', $this_category['parent_id'] == 0 ? $this_category['id'] : $this_category['parent_id']); $this->assign('_category', $category); // 初始化搜索条件 $where = ['g.status' => 1]; if ($cid > 0) { $category_list = array_column($categorys, null, 'id'); isset($category_list[$cid]) or $this->error('无此分类信息!'); $where[$category_list[$cid]['parent_id'] <= 0 ? 'g.pid' : 'g.cid'] = $cid; } if ($price_min > 0) { $where['g.price'] = ['egt', $price_min]; } if ($price_max > 0) { $where['g.price'] = ['elt', $price_max]; } $city_id = intval($_COOKIE['city_id']); if ($city_id) { $where['g.city_id'] = ['in', "(0, {$city_id})"]; } if ($search) { $where['g.title'] = ['like', '%' . $search . '%']; $where = ['_string' => "c.name like '%{$search}%' and g.status = 1", '_logic' => 'or', '_complex' => $where]; } // 检索数据 $page_size = 24; $total = D('Loan/shop_goods')->join('__LOAN_SHOP_COLUMN__ c on c.id = g.column_id', 'left')->alias('g')->where($where)->count(); $page = new \Think\Page($total, $page_size, (array) I('request.')); if ($total > $page_size) { $page->setConfig('theme', '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%'); } $p = $page->show(); $this->assign('_page', $p ? $p : ''); $this->assign('_total', $total); $this->assign('list', ShopGoodsModel::getGoods(['where' => $where, 'order' => $order, 'limit' => $page->firstRow . ',' . $page->listRows])); $this->display(); }