文件
mashangyoujiu/Application/Common/Model/RetailHostModel.class.php

154 行
5.3 KiB
PHP
可执行文件

<?php
namespace Common\Model;
//[1.4.36]
class RetailHostModel extends BaseModel
{
protected $tableName = 'retail_host';
const ID = 'id'; //int(11) NOT NULL AUTO_INCREMENT,
const STORE_ID = 'storeid'; //int(11) DEFAULT NULL,
const MERCHANT_ID = 'merchantid'; //int(11) DEFAULT NULL,
const GOODS_ID = 'goods_id'; //int(11) DEFAULT NULL COMMENT '商品id',
const ADD_TIME = 'addtime'; //varchar(255) DEFAULT NULL COMMENT '添加时间',
const STATUS = 'status'; //varchar(255) DEFAULT '1' COMMENT '0关闭1开启',
const TYPE = 'type'; //tinyint(1) DEFAULT '1' COMMENT '1推荐商品 2促销商品 3最新商品',
const OLD_MONEY = 'old_money'; //decimal(10,2) DEFAULT NULL COMMENT '原零售价',
const START_TIME = 'starttime'; // varchar(11) DEFAULT NULL COMMENT '促销活动开始时间',
const END_TIME = 'endtime'; // varchar(11) DEFAULT NULL COMMENT '促销活动结束时间',
const SORT = 'sort'; // int(11) DEFAULT '1' COMMENT '小程序推荐商品排序',
const ACT_PRICE = 'act_price'; //decimal(10,2) DEFAULT NULL COMMENT '促销价',
const SKU_ID = 'sku_id'; //int(11) DEFAULT NULL COMMENT '规格id',
const STATE = 'state'; //tinyint(2) DEFAULT '1' COMMENT '1正常 0删除',
public function getHostGoods($map, $fields, $order)
{
$goods = $this->alias('h')
->join('ls_retail_goods as g on g.id=h.' . $this::GOODS_ID)
->where($map)
->group($this::GOODS_ID)
->order($order)
->field($fields)
->select();
return $goods;
}
/**
* @param $map
* @param $fields
* @param $order
* @return mixed
*/
public function getHostGoods_v1($map, $fields, $order, $page)
{
if ($page) {
$goods = $this->alias('h')
->join('ls_retail_goods as g on g.id=h.' . $this::GOODS_ID)
->join('ls_retail_store_sale_goods as s on g.id=s.goods_id')
->where($map)
->group('h.' . $this::GOODS_ID)
->order($order)
->page($page)
->field($fields)
->select();
} else {
$goods = $this->alias('h')
->join('ls_retail_goods as g on g.id=h.' . $this::GOODS_ID)
->join('ls_retail_store_sale_goods as s on g.id=s.goods_id')
->where($map)
->group('h.' . $this::GOODS_ID)
->order($order)
->field($fields)
->select();
}
return $goods;
}
/**
* 获取推荐、最新商品
* @param $map
* @param string $fields
* @param string $order
* @param string $page
* @return mixed
*/
public function getActGoods($map, $fields = 'h.*,g.goods_name,g.goods_num,g.attribute_state,g.online_price', $order = 'h.id asc', $page = '1,10')
{
$goods = $this->alias('h')
->join('ls_retail_goods as g on g.id=h.' . $this::GOODS_ID)
->where($map)
->group($this::GOODS_ID)
->order($order)
->page($page)
->field($fields)
->select();
return $goods;
}
/**
* 商城获取最新商品
* @param $map
* @param string $fields
* @param string $order
* @param string $page
* @return array
*/
public function getOtherGoods($map, $fields = '*', $order = 'g.goods_order asc,g.id desc', $page = '1,10')
{
if (empty($map)) {
return array();
}
$time = time();
$list = $this->alias('h')
->join("ls_retail_goods as g on g.id=h.goods_id")
->join("ls_retail_host as h1 on g.id=h1.goods_id AND h1.type=2 AND h1.starttime<={$time} AND h1.endtime>={$time} AND h1.state=1 AND h1.status=1", 'LEFT')
->where($map)
->order($order)
->group('g.id')
->page($page)
->field($fields)
->select();
return $list;
}
/**
* 查询促销、推荐、最新商品及名称列表
* @param $map 搜索条件
* @param string $fields 所需字段
* @param string $order 排序方式
* @param string $page 分页
* @return mixed
*/
public function getGoodsList($map, $fields = 'h.*,g.goods_name,g.goods_code,g.goods_number,s.sku_id_list,s.sku_goods_number,s.sku_code', $order = 'h.id desc', $page = '1,10')
{
if (empty($map)) {
return array();
}
$list = $this->alias('h')
->join('ls_retail_goods as g on g.id=h.' . $this::GOODS_ID)
->join('ls_retail_sku_goods as s on s.id=h.' . $this::SKU_ID, 'LEFT')
->where($map)
->order($order)
->page($page)
->field($fields)
->select();
return $list;
}
/**
* 查询促销、推荐、最新商品及名称数量
* @param $map 搜索条件
* @return mixed
*/
public function getGoodsCount($map)
{
if (empty($map)) {
return 0;
}
$count = $this->alias('h')
->join('ls_retail_goods as g on g.id=h.' . $this::GOODS_ID)
->where($map)
->count();
return intval($count);
}
}