156 lines
4.8 KiB
PHP
Executable File
156 lines
4.8 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\common\model;
|
|
|
|
use think\Model;
|
|
use think\Request;
|
|
use think\Config;
|
|
use think\Db;
|
|
|
|
class Product extends Model {
|
|
|
|
use \app\common\traits\IndexModel;
|
|
|
|
public function getCateProductList($where = null, $order = null, $field = null, $limit = null) {
|
|
$this->alias('p')->join('product_category c', 'p.cid=c.id', 'LEFT');
|
|
if (is_array($where)) {
|
|
$where = array_merge(['p.stat' => ['eq', '0'],'p.is_show' =>'0'], $where);
|
|
}
|
|
if ($where) {
|
|
$this->where($where);
|
|
}
|
|
if ($order) {
|
|
$this->order($order);
|
|
}
|
|
if ($field) {
|
|
$this->field($field);
|
|
}
|
|
if ($limit) {
|
|
$this->limit($limit);
|
|
}
|
|
$data = $this->select();
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function getCateProductLists($where = null, $order = null, $field = null, $limit = null) {
|
|
$this->alias('p')->join('product_category c', 'p.cid=c.id', 'LEFT');
|
|
if (is_array($where)) {
|
|
$where = array_merge(['p.stat' => ['eq', '0']], $where);
|
|
}
|
|
if ($where) {
|
|
$this->where($where);
|
|
}
|
|
if ($order) {
|
|
$this->order($order);
|
|
}
|
|
if ($field) {
|
|
$this->field($field);
|
|
}
|
|
if (empty($limit)) {
|
|
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
|
|
}
|
|
$object = $this->paginate($limit);
|
|
return $object;
|
|
}
|
|
|
|
public function getRelatedProductList($where = null, $order = null, $field = null, $limit = null) {
|
|
$this->alias('p')->join('product_related pr', 'p.id=pr.related_product_id', 'LEFT');
|
|
if (is_array($where)) {
|
|
$where = array_merge(['p.stat' => ['eq', '0'], 'pr.stat' => ['eq', '0'], 'pr.product_id' => '0'], $where);
|
|
}
|
|
if ($where) {
|
|
$this->where($where);
|
|
}
|
|
if ($order) {
|
|
$this->order($order);
|
|
}
|
|
if ($field) {
|
|
$this->field($field);
|
|
}
|
|
if ($limit) {
|
|
$this->limit($limit);
|
|
}
|
|
$data = $this->select();
|
|
return $data;
|
|
}
|
|
public function productImg()
|
|
{
|
|
return $this->hasMany('ProductBkImg', 'product_id', 'id');
|
|
}
|
|
public function productTwoImg(){
|
|
return $this->hasMany('ProductTwoImg','product_id','id');
|
|
}
|
|
|
|
public function productCategory()
|
|
{
|
|
return $this->belongsTo('ProductCategory', "id", 'cid');
|
|
}
|
|
|
|
/******获取新品数据******/
|
|
public function getNewProductLists($where = null, $order = null, $field = null, $limit = null) {
|
|
$this->alias('p')->join('product_category c', 'p.cid=c.id', 'INNER')->join('product_category t', 'c.pid=t.id', 'INNER');
|
|
if (is_array($where)) {
|
|
$where = array_merge(['p.stat' => ['eq', '0'],'p.isnew' => ['eq', '1'],'p.is_show' => ['eq', '0'],'t.isshow' => ['eq', '1'],'p.country_code' => ['eq', 'US']], $where);
|
|
}
|
|
if ($where) {
|
|
$this->where($where);
|
|
}
|
|
if ($order) {
|
|
$this->order($order);
|
|
}
|
|
if ($field) {
|
|
$this->field($field);
|
|
}
|
|
if (empty($limit)) {
|
|
$this->limit($limit);
|
|
}
|
|
$data = $this->select();
|
|
return $data;
|
|
}
|
|
/******获取新品数据******/
|
|
public function getCnNewProductLists($where = null, $order = null, $field = null, $limit = null) {
|
|
$this->alias('p')->join('product_category c', 'p.cid=c.id', 'INNER')->join('product_category t', 'c.pid=t.id', 'INNER');
|
|
if (is_array($where)) {
|
|
$where = array_merge(['p.stat' => ['eq', '0'],'p.isnew' => ['eq', '1'],'p.is_show' => ['eq', '0'],'t.isshow' => ['eq', '1'],'p.country_code' => ['eq', 'ZH']], $where);
|
|
}
|
|
if ($where) {
|
|
$this->where($where);
|
|
}
|
|
if ($order) {
|
|
$this->order($order);
|
|
}
|
|
if ($field) {
|
|
$this->field($field);
|
|
}
|
|
if (empty($limit)) {
|
|
$this->limit($limit);
|
|
}
|
|
$data = $this->select();
|
|
return $data;
|
|
}
|
|
|
|
public function getNewItemLists($where = null, $order = null, $field = null, $limit = null) {
|
|
$this->alias('p')->join('product_category c', 'p.cid=c.id', 'INNER')->join('product_category t', 'c.pid=t.id', 'INNER');
|
|
if (is_array($where)) {
|
|
$where = array_merge(['p.stat' => ['eq', '0'],'p.isnew' => ['eq', '1'], 'p.is_show' => ['eq', '0'],'t.isshow' => ['eq', '1'],'p.country_code' => ['eq', 'ZH']], $where);
|
|
}
|
|
if ($where) {
|
|
$this->where($where);
|
|
}
|
|
if ($order) {
|
|
$this->order($order);
|
|
}
|
|
if ($field) {
|
|
$this->field($field);
|
|
}
|
|
if (empty($limit)) {
|
|
$this->limit($limit);
|
|
}
|
|
$data = $this->select();
|
|
return $data;
|
|
}
|
|
|
|
|
|
}
|