187 行
7.2 KiB
PHP
可执行文件
187 行
7.2 KiB
PHP
可执行文件
<?php
|
||
/*
|
||
* 商户库存状况模型 - 数据对象模型
|
||
*/
|
||
|
||
namespace Common\Model;
|
||
|
||
use Think\Model;
|
||
|
||
//[1.8.50]
|
||
|
||
/**
|
||
* 商户商品库存表
|
||
* Class SaleMGoodsModel
|
||
* @package Common\Model
|
||
*/
|
||
class SaleMGoodsModel extends JBaseModel
|
||
{
|
||
protected $tableName = 'retail_sale_goods';
|
||
protected $fields = array(
|
||
'id', //int(11) NOT NULL AUTO_INCREMENT,
|
||
'merchant_id', //int(11) DEFAULT '0' COMMENT '商户id',
|
||
'warehouse_id', //int(11) DEFAULT '0' COMMENT '仓库id',
|
||
'goods_class_id', //int(11) DEFAULT '0' COMMENT '分类id',
|
||
'goods_id', //int(11) DEFAULT '0' COMMENT '商品id',
|
||
'sku_id', //int(11) DEFAULT '0' COMMENT '规格id',
|
||
'goods_name', //varchar(255) DEFAULT '' COMMENT '商品名称',
|
||
'sku_name', //varchar(1000) DEFAULT '' COMMENT '规格名称',
|
||
'sku_id_list', //规格名称id
|
||
'goods_number', //varchar(30) DEFAULT NULL,
|
||
'sku_goods_number', //varchar(30) DEFAULT '' COMMENT '规格货号',
|
||
'goods_code', //varchar(30) DEFAULT '' COMMENT '商品条码',
|
||
'sku_code', //varchar(30) DEFAULT '' COMMENT '规格条码',
|
||
'company', //varchar(255) DEFAULT '' COMMENT '单位',
|
||
'specifications', //varchar(255) DEFAULT '' COMMENT '规格',
|
||
'attribute_state', //tinyint(1) DEFAULT '1' COMMENT '是否开启sku 1关闭 2开启',
|
||
'pricing_method', //tinyint(1) DEFAULT '1' COMMENT '1无称重 2称重 ',
|
||
'goods_brand_id', // int(11) DEFAULT '0' COMMENT '商品品牌id',
|
||
'goods_yieldly_id', //int(11) DEFAULT '0' COMMENT '产地id',
|
||
'goods_num', // decimal(10,3) DEFAULT '0.000' COMMENT '可售库存',
|
||
'sku_num', //decimal(10,3) DEFAULT '0.000' COMMENT '规格商品单件对应库存',
|
||
'more_num', //decimal(10,3) DEFAULT NULL COMMENT '库存上限',
|
||
'less_num', //decimal(10,3) DEFAULT NULL COMMENT '库存下限',
|
||
'status', //tinyint(1) DEFAULT '0' COMMENT '状态:0,上架,1,下架 2删除',
|
||
'cost_price', //decimal(10,2) DEFAULT '0.00' COMMENT '成本价',
|
||
'add_time', //varchar(10) DEFAULT '' COMMENT '添加时间',
|
||
'serial_number_state', //商品串码状态 0关闭 1开启,
|
||
'third_goods_code', //第三方平台的商品编码
|
||
);
|
||
|
||
/**
|
||
* 门店同步商户普通商品的库存报表的查询条件
|
||
* @param $parameter
|
||
* @return array
|
||
*/
|
||
public function getStoreSyncGoodsInventoryTerm($parameter)
|
||
{
|
||
$where = array(
|
||
'a.merchant_id' => $parameter['merchant_id'],
|
||
'a.status' => array('in', '0,1'),
|
||
'g.m_goods_id' => array('gt', 0),
|
||
'g.status' => array('in', '0,1'),
|
||
's.status' => array('in', '0,1')
|
||
);
|
||
if (!empty($parameter['searchText'])) {
|
||
$where['a.goods_name|a.goods_number|a.goods_code'] = array('like', '%' . trim($parameter['searchText']) . '%');
|
||
}
|
||
if (!empty($parameter['store_id'])) {
|
||
$where['g.store_id'] = $parameter['store_id'];
|
||
}
|
||
return $where;
|
||
}
|
||
|
||
/**
|
||
* 门店同步商户普通商品的库存报表(已作废)
|
||
* @param $parameter
|
||
* @return mixed
|
||
*/
|
||
public function getStoreSyncGoodsInventoryList($parameter)
|
||
{
|
||
if (empty($parameter)) {
|
||
return [];
|
||
}
|
||
$where = $this->getStoreSyncGoodsInventoryTerm($parameter);
|
||
$where['a.attribute_state'] = 1;
|
||
$page = $parameter['page'] ? $parameter['page'] : 1;
|
||
$limit = $parameter['limit'] ? $parameter['limit'] : 10;
|
||
$list = $this->alias('a')
|
||
->join('ls_retail_goods as g on a.goods_id = g.m_goods_id')
|
||
->join('ls_retail_store_sale_goods as s on g.id=s.goods_id')
|
||
->field('sum(s.goods_num) as goods_num,a.goods_id as merchant_goods_id,a.goods_name,a.goods_number,a.goods_code,g.id as store_goods_id,a.company,s.attribute_state')
|
||
->where($where)
|
||
->page($page, $limit)
|
||
->order('a.id desc')
|
||
->group('a.goods_id')
|
||
->select();
|
||
return $list;
|
||
|
||
|
||
}
|
||
|
||
/**
|
||
* 门店同步商户普通商品的库存报表(已作废)
|
||
* @param $parameter
|
||
* @return mixed
|
||
*/
|
||
public function getStoreSyncGoodsInventoryCount($parameter)
|
||
{
|
||
if (empty($parameter)) {
|
||
return 0;
|
||
}
|
||
$where = $this->getStoreSyncGoodsInventoryTerm($parameter);
|
||
$where['a.attribute_state'] = 1;
|
||
$count = $this->alias('a')
|
||
->join('ls_retail_goods as g on a.goods_id = g.m_goods_id')
|
||
->join('ls_retail_store_sale_goods as s on g.id=s.goods_id')
|
||
->where($where)
|
||
->count('distinct(a.goods_id)');
|
||
return $count;
|
||
}
|
||
|
||
/**
|
||
* 门店同步商户规格商品的库存报表的查询条件
|
||
* @param $parameter
|
||
* @return array
|
||
*/
|
||
public function getStoreSyncGoodsSkuInventoryTerm($parameter)
|
||
{
|
||
$where = array(
|
||
'a.merchant_id' => $parameter['merchant_id'],
|
||
'a.status' => array('in', '0,1'),
|
||
's.sku_mgoods_id' => array('gt', 0),
|
||
's.state' => 0,
|
||
);
|
||
if (!empty($parameter['searchText'])) {
|
||
$where['a.goods_name|a.sku_name|a.goods_number|a.goods_code|a.sku_goods_number|a.sku_code'] = array('like', '%' . trim($parameter['searchText']) . '%');
|
||
}
|
||
if (!empty($parameter['store_id'])) {
|
||
$where['s.store_id'] = $parameter['store_id'];
|
||
}
|
||
return $where;
|
||
}
|
||
|
||
/**
|
||
* 门店同步商户规格商品的库存报表(已作废)
|
||
* @param $parameter
|
||
* @return array
|
||
*/
|
||
public function getStoreSyncGoodsSkuInventoryList($parameter)
|
||
{
|
||
if (empty($parameter)) {
|
||
return [];
|
||
}
|
||
$where = $this->getStoreSyncGoodsSkuInventoryTerm($parameter);
|
||
$where['a.attribute_state'] = 2;
|
||
$page = $parameter['page'] ? $parameter['page'] : 1;
|
||
$limit = $parameter['limit'] ? $parameter['limit'] : 10;
|
||
$list = $this->alias('a')
|
||
->join('ls_retail_sku_goods as s on a.sku_id = s.sku_mgoods_id')
|
||
->field('a.goods_id as merchant_goods_id,a.sku_id as merchant_goods_sku_id,a.goods_name,a.sku_name,a.sku_goods_number,a.sku_code,a.company')
|
||
->where($where)
|
||
->page($page, $limit)
|
||
->order('a.id desc')
|
||
->group('a.sku_id')
|
||
->select();
|
||
return $list;
|
||
}
|
||
|
||
/**
|
||
* 门店同步商户规格商品的库存报表
|
||
* @param $parameter
|
||
* @return array
|
||
*/
|
||
public function getStoreSyncGoodsSkuInventoryCount($parameter)
|
||
{
|
||
if (empty($parameter)) {
|
||
return [];
|
||
}
|
||
$where = $this->getStoreSyncGoodsSkuInventoryTerm($parameter);
|
||
$where['a.attribute_state'] = 2;
|
||
$count = $this->alias('a')
|
||
->join('ls_retail_sku_goods as s on a.sku_id = s.sku_mgoods_id')
|
||
->where($where)
|
||
->count('distinct(a.sku_id)');
|
||
return $count;
|
||
}
|
||
} |