239 lines
5.6 KiB
PHP
239 lines
5.6 KiB
PHP
<?php
|
|
/**
|
|
* Notes:商品表
|
|
* Created on: 2021/7/14 15:30
|
|
* Created by: dengbw
|
|
*/
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class Items_model extends HD_Model
|
|
{
|
|
private $table_name = 'lc_items';
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct($this->table_name, 'default');
|
|
}
|
|
|
|
/**
|
|
* 精品筛选数量
|
|
* @param array $where
|
|
* @return mixed
|
|
*/
|
|
function count_fine($where = array()){
|
|
$join_on = "j.item_id=m.id and j.type=1 and j.status=1";
|
|
$this->db->from("lc_items as m");
|
|
$this->db->join("lc_items_relate as j", $join_on, 'left');
|
|
|
|
$this->db->group_by('id');
|
|
|
|
if($where['having']){
|
|
$this->db->having($where['having']);
|
|
unset($where['having']);
|
|
}
|
|
|
|
if($where)
|
|
{
|
|
$this->db->where($where);
|
|
}
|
|
|
|
$this->db->select('id, count(type_id) as fine_num', false);
|
|
|
|
return $this->db->count_all_results();
|
|
}
|
|
|
|
/**
|
|
* 联表订单
|
|
* @param array $where
|
|
* @return mixed
|
|
*/
|
|
function count_order($where = array()){
|
|
$join_on = "j.item_id=m.id";
|
|
$this->db->from("lc_items as m");
|
|
$this->db->join("lc_receiver_orders as j", $join_on, 'left');
|
|
|
|
if($where)
|
|
{
|
|
$this->db->where($where);
|
|
}
|
|
|
|
$this->db->select('id', false);
|
|
|
|
return $this->db->count_all_results();
|
|
}
|
|
|
|
/**
|
|
* 条件筛选订单和精品
|
|
* @param array $where
|
|
* @return mixed
|
|
*/
|
|
function count_order_fine($where = array()){
|
|
$join_on = "j.item_id=m.id";
|
|
$join_on2 = "j2.item_id=m.id and j2.type=1 and j2.status=1";
|
|
$this->db->from("lc_items as m");
|
|
$this->db->join("lc_receiver_orders as j", $join_on, 'left');
|
|
$this->db->join("lc_items_relate as j2", $join_on2, 'left');
|
|
|
|
$this->db->group_by('m.id');
|
|
|
|
if($where['having']){
|
|
$this->db->having($where['having']);
|
|
unset($where['having']);
|
|
}
|
|
|
|
if($where)
|
|
{
|
|
$this->db->where($where);
|
|
}
|
|
|
|
$this->db->select('m.id, count(j2.type_id) as fine_num', false);
|
|
|
|
return $this->db->count_all_results();
|
|
}
|
|
|
|
/**
|
|
* 精品筛选数据列表
|
|
* @param array $where
|
|
* @param string $order
|
|
* @param int $page
|
|
* @param int $page_size
|
|
* @param string $select
|
|
* @return mixed
|
|
*/
|
|
function select_fine($where = array(), $order = '', $page = 0, $page_size = 20, $select = ''){
|
|
$join_on = "j.item_id=m.id and j.type=1 and j.status=1";
|
|
$this->db->from("lc_items as m");
|
|
$this->db->join("lc_items_relate as j", $join_on, 'left');
|
|
|
|
$this->db->group_by('id');
|
|
|
|
if($where['having']){
|
|
$this->db->having($where['having']);
|
|
unset($where['having']);
|
|
}
|
|
|
|
if($select)
|
|
{
|
|
$this->db->select($select, false);
|
|
}
|
|
|
|
if($where)
|
|
{
|
|
$this->db->where($where);
|
|
}
|
|
|
|
if($order)
|
|
{
|
|
$this->db->order_by($order);
|
|
}
|
|
|
|
if($page)
|
|
{
|
|
$offset = ($page - 1) * $page_size;
|
|
$limit = $page_size;
|
|
}
|
|
else
|
|
{
|
|
$offset = null;
|
|
$limit = null;
|
|
}
|
|
|
|
return $this->db->get(null, $limit, $offset)->result_array();
|
|
}
|
|
|
|
/**
|
|
* 订单筛选
|
|
* @param array $where
|
|
* @param string $order
|
|
* @param int $page
|
|
* @param int $page_size
|
|
* @param string $select
|
|
* @return mixed
|
|
*/
|
|
function select_order($where = array(), $order = '', $page = 0, $page_size = 20, $select = ''){
|
|
$join_on = "j.item_id=m.id";
|
|
$this->db->from("lc_items as m");
|
|
$this->db->join("lc_receiver_orders as j", $join_on, 'left');
|
|
|
|
if($select)
|
|
{
|
|
$this->db->select($select, false);
|
|
}
|
|
|
|
if($where)
|
|
{
|
|
$this->db->where($where);
|
|
}
|
|
|
|
if($order)
|
|
{
|
|
$this->db->order_by($order);
|
|
}
|
|
|
|
if($page)
|
|
{
|
|
$offset = ($page - 1) * $page_size;
|
|
$limit = $page_size;
|
|
}
|
|
else
|
|
{
|
|
$offset = null;
|
|
$limit = null;
|
|
}
|
|
|
|
return $this->db->get(null, $limit, $offset)->result_array();
|
|
}
|
|
|
|
/**
|
|
* 关联订单和精品
|
|
* @param array $where
|
|
* @param string $order
|
|
* @param int $page
|
|
* @param int $page_size
|
|
* @param string $select
|
|
* @return mixed
|
|
*/
|
|
function select_order_fine($where = array(), $order = '', $page = 0, $page_size = 20, $select = ''){
|
|
$join_on = "j.item_id=m.id";
|
|
$join_on2 = "j2.item_id=m.id and j2.type=1 and j2.status=1";
|
|
$this->db->from("lc_items as m");
|
|
$this->db->join("lc_receiver_orders as j", $join_on, 'left');
|
|
$this->db->join("lc_items_relate as j2", $join_on2, 'left');
|
|
|
|
$this->db->group_by('m.id');
|
|
|
|
if($where['having']){
|
|
$this->db->having($where['having']);
|
|
unset($where['having']);
|
|
}
|
|
|
|
if($select)
|
|
{
|
|
$this->db->select($select, false);
|
|
}
|
|
|
|
if($where)
|
|
{
|
|
$this->db->where($where);
|
|
}
|
|
|
|
if($order)
|
|
{
|
|
$this->db->order_by($order);
|
|
}
|
|
|
|
if($page)
|
|
{
|
|
$offset = ($page - 1) * $page_size;
|
|
$limit = $page_size;
|
|
}
|
|
else
|
|
{
|
|
$offset = null;
|
|
$limit = null;
|
|
}
|
|
|
|
return $this->db->get(null, $limit, $offset)->result_array();
|
|
}
|
|
}
|