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

626 行
25 KiB
PHP
可执行文件

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace Common\Model;
use Think\Model;
//[1.8.50]
/**
* 门店商品档案表 GoodsModel删除
* Class RetailGoodsModel
* @package Common\Model
*/
class RetailGoodsModel extends BaseModel
{
protected $tableName = 'retail_goods';
const ID = 'id'; //int(11) NOT NULL AUTO_INCREMENT,
const GOODS_NAME = 'goods_name'; //varchar(255) DEFAULT NULL COMMENT '零售货物名称。',
const SUB_HEADING = 'subheading'; //varchar(255) DEFAULT NULL COMMENT '副标题',
const GOODS_CLASS_ID = 'goods_class_id'; //int(11) DEFAULT NULL COMMENT '货物所属类别id',
const GOODS_NUMBER = 'goods_number'; //varchar(15) DEFAULT NULL COMMENT '货号',
const PURCHASE_PRICE = 'purchase_price'; //decimal(20,2) DEFAULT '0.00' COMMENT '成本价格',
const RETAIL_PRICE = 'retail_price'; //decimal(20,2) DEFAULT '0.00' COMMENT '零售价',
const PLUS_PRICE = 'plus_price'; //decimal(20,2) DEFAULT NULL COMMENT 'plus会员价',
const ONLINE_PRICE = 'online_price'; //decimal(20,2) DEFAULT NULL COMMENT '小程序商城价格',
const VIP_ONLINE_STATE = 'vip_online_state'; //varchar(255) DEFAULT '0' COMMENT 'vip是否打折 0关闭 1开启',
const VIP_RETAIL_STATE = 'vip_retail_state'; //int(1) DEFAULT '0' COMMENT '允许vip线下积分抵现: 0不允许 1允许',
const ADD_TIME = 'add_time'; //int(11) DEFAULT NULL COMMENT '添加时间',
const STATUS = 'status'; //int(1) DEFAULT NULL COMMENT '状态:0,正常,1,下架,2,删除。',
const GOODS_NUM = 'goods_num'; //decimal(11,3) DEFAULT '0.000' COMMENT '商品库存',
const GOODS_ORDER = 'goods_order'; //int(11) DEFAULT '1' COMMENT '商品排序',
const MORE_NUM = 'more_num'; //decimal(11,3) DEFAULT NULL COMMENT '商品超量;超过该字段的库存数量即为超量',
const LESS_NUM = 'less_num'; //decimal(11,3) DEFAULT NULL COMMENT '库存预警',
const SELL_NUM = 'sell_num'; //decimal(11,3) DEFAULT '0.000' COMMENT '出售数量',
const FICTITIOUS_NUM = 'fictitious_num'; //int(11) DEFAULT NULL COMMENT '虚拟销量',
const COMPANY = 'company'; //varchar(255) DEFAULT '' COMMENT '单位',
const SPECIFICATIONS = 'specifications'; //varchar(255) DEFAULT '' COMMENT '规格',
const MERCHANT_ID = 'merchant_id'; //int(11) DEFAULT '0' COMMENT '商户id。',
const STORE_ID = 'store_id'; //int(11) DEFAULT NULL COMMENT '门店id',
const GOODS_CODE = 'goods_code'; //varchar(20) DEFAULT '' COMMENT '商品条码。',
const ONLINE_STATE = 'online_state'; //int(1) DEFAULT '0' COMMENT '是否在商城中出售:0,不在,1,在商城出售。',
const PRICING_METHOD = 'pricing_method'; //tinyint(1) DEFAULT '1' COMMENT '该商品是否称重计价 1:不称重 2:称重',
const DETAILS = 'details'; //text COMMENT '商品图文详情',
const CHECK_NUM = 'check_num'; //varchar(11) DEFAULT '' COMMENT '盘点数量',
const SUPPLIER_ID = 'supplier_id'; //int(11) DEFAULT '0',
const SPLIT_STATE = 'split_state'; //tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否可拆分:0,不可以。1,可以。',
const SPLIT_GOODS_ID = 'split_goods_id'; //int(11) NOT NULL DEFAULT '0' COMMENT '拆分后的商品id',
const SPLIT_GOODS_NUM = 'split_goods_num'; //int(11) NOT NULL DEFAULT '0' COMMENT '拆分子商品的数量。',
const LABEL_ID = 'label_id'; //int(11) DEFAULT '0' COMMENT '标签id 默认0:没有绑定',
const M_GOODS_ID = 'm_goods_id'; //int(11) DEFAULT '0' COMMENT '调拨商户的商品id',
const ATTRIBUTE_STATE = 'attribute_state'; //tinyint(1) DEFAULT '1' COMMENT '是否开启sku 1不开启 2开启',
const USUAL_STATE = 'usual_state'; //tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否是常用商品:1,不是,2,是。',
const SYNC_STATE = 'sync_state'; //tinyint(1) DEFAULT '0' COMMENT '0未更新 1已更新',
const PRODUCTION_DATE = 'production_date'; //varchar(15) DEFAULT NULL COMMENT '商品生产日期',
const SHELF_LIFE = 'shelf_life'; //varchar(15) DEFAULT NULL COMMENT '商品到期日期',
const SHOP_MEM_STATUS = 'shop_mem_status'; //tinyint(1) DEFAULT '2' COMMENT '是否开启商城会员价1.开启2.关闭',
const SHOP_MEM_PRICE = 'shop_mem_price'; //decimal(10,2) DEFAULT NULL COMMENT '商城会员价格',
const STORE_MEM_STATUS = 'store_mem_status'; //tinyint(1) DEFAULT '2' COMMENT '是否开启商城会员价1.开启2.关闭',
const STORE_MEM_PRICE = 'store_mem_price'; //decimal(10,2) DEFAULT NULL COMMENT '店内会员价格',
const INTEGRAL_MEM_STATUS = 'integral_mem_status'; //tinyint(1) DEFAULT '2' COMMENT '1开启积分 2关闭积分 购买获得积分',
const INTEGRAL = 'integral'; //int(11) DEFAULT NULL COMMENT '会员消费送积分',
const PLUS_MEM_STATUS = 'plus_mem_status'; //tinyint(1) DEFAULT '2' COMMENT '1开启 2关闭 plus会员价',
const GOODS_BRAND_ID = 'goods_brand_id'; //int(11) DEFAULT '0' COMMENT '商品品牌id',
const PLU_CODE = 'plu_code'; //int(4) DEFAULT NULL,
const GOODS_YIELDLY_ID = 'goods_yieldly_id'; //int(10) DEFAULT '0' COMMENT '产地id',
const GOODS_IMG_ID = 'goods_img_id'; // goods_img_id varchar(255) DEFAULT '0',
const SOURCE_TYPE = 'source_type'; //新:(1店长添加 2商户同步 3收银员添加)
const CASHIER_ID = 'cashier_id'; //int(11) DEFAULT NULL COMMENT '收银员id',
const GUIDE_ROYALTY_STATE = 'guide_royalty_state'; // tinyint(1) DEFAULT '0' COMMENT '购买该商品获得提成的状态 0关闭 1开启',
const GUIDE_ROYALTY_CUSTOM_STATE = 'guide_royalty_custom_state'; // tinyint(1) DEFAULT '0' COMMENT '导购员获得提成自定义状态 0关闭 1开启(开启则表示使用自定义的金额,关闭则表示使用默认的全局百分比)',
const GUIDE_ROYALTY_PRICE = 'guide_royalty_price'; // decimal(10,2) DEFAULT '0.00' COMMENT '导购员线下固定金提成',
const GUIDE_ROYALTY_ONLINE_PRICE = 'guide_royalty_online_price'; // decimal(10,2) DEFAULT '0.00' COMMENT '导购员线上固定金提成'
const ADVANCE_SALE_STATUS = 'advance_sale_status'; //tinyint(1) 商城预售 0关闭 1开启
const REFUND_STATE = 'refund_state'; //tinyint(1) DEFAULT '1' COMMENT '允许退款 1允许 0不允许',
const EXCHANGE_STATE = 'exchange_state'; //tinyint(1) DEFAULT '1' COMMENT '允许换货 1允许 0不允许',
const DELIVERY_TEMPLATE_ID = 'delivery_template_id'; //使用的配送模板ID
const DELIVERY_TYPE = 'delivery_type'; //配送方式 ,拼接
const SHOP_MEM_INTEGRAL = 'shop_mem_integral'; //商城会员价自定义营销的积
const PLUS_MEM_INTEGRAL = 'plus_mem_integral'; //plus会员价自定义营销的积分
const STORE_MEM_INTEGRAL = 'store_mem_integral'; //店内会员价自定义营销的积分
const WEIGHT_VALUE = 'weight_value'; //重量
const SIMPLE_SPELLING = 'simple_spelling'; //简拼
const VIDEO_ID = 'video_id'; //商品视频id
const SERIAL_NUMBER_STATE = 'serial_number_state'; //商品串码状态 0关闭 1开启
//收银员获取商品列表
public function getCashierGoodsList($where, $field, $order = '', $page = '')
{
if ($page != '') {
$list = $this->alias('g')
->join('ls_retail_goods_class as c on g.' . $this::GOODS_CLASS_ID . '=c.id')
->where($where)
->field($field)
->page($page)
->order($order)
->select();
$count = $this->alias('g')
->join('ls_retail_goods_class as c on g.' . $this::GOODS_CLASS_ID . '=c.id')
->where($where)
->field($field)
->page($page)
->order($order)
->count();
$goods = array(
'list' => $list,
'count' => $count,
);
} else {
$goods = $this->alias('g')
->join('ls_retail_goods_class as c on g.' . $this::GOODS_CLASS_ID . '=c.id')
->where($where)
->field($field)
->order($order)
->select();
}
return $goods;
}
/*商品数量作为条件查询商品列表
*
* @param $where 条件
* @param $field 查询的字段
*/
public function getGoodsList($where, $field, $order)
{
$field = $field ? $field : 'g.*';
$order = $order ? $order : 'g.id desc';
$info = $this->alias('g')
->join('ls_retail_store_sale_goods as s on g.id=s.goods_id', 'LEFT')
->where($where)
->field($field)
->select();
return $info;
}
/**
* 商城商品列表获取
*/
public function getOnlineGoods($where, $fileds, $order, $page)
{
$fileds = $fileds ? $fileds : 'g.*';
$order = $order ? $order : 'g.id desc';
$info = $this->alias('g')
->join('ls_retail_store_sale_goods as s on g.id=s.goods_id and s.attribute_state=1', 'LEFT')
->field($fileds)
->where($where)
->order($order)
->page($page)
->select();
return $info;
}
/**
* 商城商品列表获取
*/
public function getOnlineCount($where)
{
$info = $this->alias('g')
->join('ls_retail_store_sale_goods as s on g.id=s.goods_id and s.attribute_state=1', 'LEFT')
->where($where)
->count();
return $info;
}
/**
* 获取分类及商品
* @param $map 查询条件
* @param $fields 选取字段
* @param $page 页码
* @param $limit 页数
* @return array
*/
public function getClassGoodsList($map, $fields, $page, $limit)
{
$list = $this->alias('g')
->join('ls_retail_goods_class as c on g.' . $this::GOODS_CLASS_ID . '=c.id')
->join('ls_retail_store_sale_goods as s on g.id=s.goods_id and s.attribute_state=1', 'LEFT')
->where($map)
->field($fields)
->order('c.code asc,g.goods_order asc,g.id desc')
->page($page, $limit)
->select();
return $list ? $list : array();
}
/**
* 获取分类及商品
* @param $map 查询条件
* @param $fields 选取字段
* @param $page 页码
* @param $limit 页数
* @return array
*/
public function getSaleGoodsList($map, $fields, $page, $limit)
{
$list = $this->alias('g')
->join('ls_retail_store_sale_goods as s on g.id=s.goods_id and s.attribute_state=1', 'LEFT')
->where($map)
->field($fields)
->order('g.goods_order asc,g.id desc')
->page($page, $limit)
->select();
return $list ? $list : array();
}
/**
* 获取分类及商品
* @param $map 查询条件
* @param $fields 选取字段
* @param $page 页码
* @param $limit 页数
* @return array
*/
public function getSaleGoodsCount($map)
{
$count = $this->alias('g')
->join('ls_retail_store_sale_goods as s on g.id=s.goods_id and s.attribute_state=1', 'LEFT')
->where($map)
->count();
return $count;
}
/**
* 查询多条
* @param $map 查询条件
* @param string $field 获取的字段类型
* @param string $order 排序规则
* @param int $limit 获取的数量
* @return mixed
*/
public function getLimitSelect($map, $field = '*', $order = 'id asc', $limit = 20)
{
$res = $this->field($field)->where($map)->order($order)->limit($limit)->select();
return $res;
}
/**
* 获取商品列表,如果商品在参加促销则把促销状态及价格返回
* @param $map
* @param string $fields
* @param string $order
* @param string $page
* @return array
*/
public function getHostGoods($map, $fields = '*', $order = 'g.goods_order asc,g.id desc', $page = '1,10')
{
if (empty($map)) {
return array();
}
$time = time();
$list = $this->alias('g')
->join("ls_retail_host as h on g.id=h.goods_id AND h.type=2 AND h.starttime<={$time} AND h.endtime>={$time} AND h.state=1 AND h.status=1", 'LEFT')
->join('ls_goods_label_link as link on link.goods_id = g.id', 'LEFT')
->join('ls_label_inventory as inve on inve.id = link.label_id', '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 array
*/
public function getUnHostGoods($map, $fields = '*', $order = 'g.goods_order asc,g.id desc', $page = '1,10')
{
if (empty($map)) {
return array();
}
$list = $this->alias('g')
->join('ls_goods_label_link as link on link.goods_id = g.id', 'LEFT')
->join('ls_label_inventory as inve on inve.id = link.label_id', 'LEFT')
->where($map)
->order($order)
->group('g.id')
->page($page)
->field($fields)
->select();
return $list;
}
public function getGoodsBrand($map)
{
if (empty($map)) {
return [];
}
return $this->alias('g')
->join('ls_goods_label_link as link on link.goods_id = g.id', 'LEFT')
->join('ls_label_inventory as inve on inve.id = link.label_id', 'LEFT')
->join('ls_retail_goods_brand as brand on g.goods_brand_id = brand.id', 'LEFT')
->where($map)
->group('g.goods_brand_id')
->field('brand.id, brand.name')
->select();
}
/**
* 配送模板-批量使用-获取商品(普通、拼团、秒杀)信息
* @param $store_id
* @param $keyword
* @param $goods_type 类型 1普通商品 2拼团 3秒杀
* @param $template_id
* @param $pricing_method
* @param $page
* @param $limit
* @return mixed
*/
public function batchUsageGoodsInfo($store_id, $keyword, $goods_type, $template_id, $pricing_method, $page, $limit)
{
$map = array(
'g.store_id' => $store_id,
'g.status' => array('in', '0,1'),
);
if ($keyword != '' && $keyword != null) {
$map['g.goods_name|g.goods_number|g.goods_code'] = array('like', '%' . $keyword . '%');
}
if (!empty($pricing_method)) {
$map[] = array(
'g.pricing_method' => $pricing_method,
'g.weight_value' => array('gt', 0),
'_logic' => 'OR'
);
}
$join_name = 'g';
$join = null;
$fields = 'g.goods_name,g.goods_number,g.goods_code,g.pricing_method,g.retail_price,t.title';
$order = 'g.id desc';
switch ($goods_type) {
case '1':
//普通商品
$fields = 'g.id,g.delivery_type,' . $fields;
break;
case '2':
//拼团
$join = 'ls_retail_spellgroup as s on s.gid = g.id';
$join_name = 's';
$order = 's.id desc';
$fields = 's.id,s.actname as act_name,s.actprice as act_price,s.send_type as delivery_type,' . $fields;
$map['s.acttype'] = 1; //拼团活动正常
break;
case '3':
//秒杀
$join = 'ls_retail_seckill as s on s.gid = g.id';
$join_name = 's';
$order = 's.id desc';
$fields = 's.id,s.active_title as act_name,s.goods_seckill_price as act_price,s.send_type as delivery_type,' . $fields;
$map['s.active_status'] = 1; //秒杀活动正常
break;
case '4':
//预售
$join = 'ls_retail_advance_goods as a on a.goods_id = g.id';
$join_name = 'a';
$order = 'a.id desc';
$fields = 'a.id,a.advance_price as act_price,a.delivery_type,' . $fields;
$map['a.advance_state'] = 1; //预售活动正常
break;
}
if (!empty($template_id)) {
$map[$join_name . '.delivery_template_id'] = $template_id;
}
$sql = $this->alias('g');
if ($join) {
$sql = $sql->join($join);
}
$list = $sql->join("ls_delivery_template as t on {$join_name}.delivery_template_id = t.id AND (t.status=1 OR t.status=2) AND t.state=1", 'LEFT')
->field($fields)
->where($map)
->order($order)
->page($page, $limit)
->select();
$sql = $this->alias('g');
if ($join) {
$sql = $sql->join($join);
}
$count = $sql->join("ls_delivery_template as t on {$join_name}.delivery_template_id = t.id AND (t.status=1 OR t.status=2) AND t.state=1", 'LEFT')
->where($map)
->count();
foreach ($list as &$value) {
$value['delivery_type'] = $value['delivery_type'] ? json_decode('[' . $value['delivery_type'] . ']', true) : array();
if ($goods_type == 4) {
$value['act_price'] = $value['act_price'] ? $value['act_price'] : '规格活动价';
}
}
return array(
'list' => $list,
'count' => $count,
);
}
/**
* 更新商品所在的模板
* @param $goodsList 商品、拼团、秒杀ID, json数组[{"id":"1","delivery_type":"1,2,3"}]
* @param $templateId 模板ID
* @param $goods_type 类型 1普通商品 2拼团 3秒杀
* @return mixed
*/
public function batchUsage($goodsList, $templateId, $goods_type)
{
$goodsList = json_decode($goodsList, true);
if (!$goodsList) {
return false;
}
$res = array();
switch ($goods_type) {
case '1':
$activity_model = $this;
break;
case '2':
$activity_model = new RetailGroupModel();
break;
case '3':
$activity_model = new RetailSpikeModel();
break;
case '4':
$activity_model = new AdvanceGoodsModel();
break;
}
$up = array('delivery_template_id' => $templateId);
foreach ($goodsList as $value) {
$map = array(
'id' => array('in', $value['id'])
);
$updateRet = false;
switch ($goods_type) {
case '1':
//普通商品
$up['delivery_type'] = $value['delivery_type'];
break;
case '2':
//拼团
$up['send_type'] = $value['delivery_type'];
break;
case '3':
//秒杀
$up['send_type'] = $value['delivery_type'];
break;
case '4':
$up['delivery_type'] = $value['delivery_type'];
break;
}
$updateRet = $activity_model->updateOrder($map, $up);
if ($updateRet) {
$res[] = 1;
}
}
return count($res);
}
/**
* 查询门店商品 分页
* @param $where 查询条件
* @param $page 当前页
* @param $limit 每页记录数
* @return $list
*/
public function selectStoreGoods($where, $page, $limit)
{
$list = $this->field('id,goods_name')
->where($where)
->page($page, $limit)
->order('add_time desc')
->select();
return $list;
}
/**
* 编辑商品时验证开启预售该商品是否参与促销秒杀拼团活动
* @param $parameter
* @return mixed
*/
public function advance_open_verify($parameter)
{
if (is_array($parameter)) {
$store_id = $parameter['store_id'];
$goods_id = $parameter['goods_id'];
if (empty($store_id) || empty($goods_id)) {
$res = array('status' => 0, 'msg' => '参数缺失');
return $res;
}
$host_map = array(
'storeid' => $store_id,
'goods_id' => $goods_id,
'type' => 2,
'state' => 1,
'status' => 1,
'endtime' => array('gt', time()),
);
$host_info = D("RetailHost")->getFind($host_map);
if ($host_info) {
$res = array('status' => 0, 'msg' => '该商品已参与促销,不能与预售同时参与');
return $res;
}
$group_map = array(
'storeid' => $store_id,
'gid' => $goods_id,
'acttype' => 1,
'endtime' => array('gt', time()),
);
$group_info = D("RetailGroup")->getFind($group_map);
if ($group_info) {
$res = array('status' => 0, 'msg' => '该商品已参与拼团,不能与预售同时参与');
return $res;
}
$seckill_map = array(
'storeid' => $store_id,
'gid' => $goods_id,
'active_status' => 1,
'active_endtime' => array('gt', time())
);
$seckill_info = D("RetailSeckill")->getFind($seckill_map);
if ($seckill_info) {
$res = array('status' => 0, 'msg' => '该商品已参与秒杀,不能与预售同时参与');
return $res;
}
$res = array('status' => 1, 'msg' => '验证成功');
} else {
$res = array('status' => 0, 'msg' => '验证失败,参数类型错误');
}
return $res;
}
/**
* 编辑商品档案时验证是否可以关闭预售
*/
public function advance_close_verify($parameter)
{
if (is_array($parameter)) {
$store_id = $parameter['store_id'];
$goods_id = $parameter['goods_id'];
$AdvanceGoodsModel = D("AdvanceGoods");
$advance_map = array(
'store_id' => $store_id,
'goods_id' => $goods_id,
'advance_state' => 1
);
$advance_end_time = $AdvanceGoodsModel->getOrderFindField($advance_map,'advance_end_time','id desc');
if (!empty($advance_end_time) && $advance_end_time > time()) {
$res['status'] = 0;
$res['msg'] = "该商品已参与预售,请先关闭该商品预售活动";
return $res;
}
$res['status'] = 1;
$res['msg'] = '验证成功';
} else {
$res['status'] = 0;
$res['msg'] = '参数类型错误';
}
return $res;
}
/**
* 商户调拨门店的普通商品库存详情
* @param $parameter
* [
* merchant_goods_id 商户商品id
* merchant_id
* ]
* @return mixed
*/
public function getSyncMerchantGoodsInfo($parameter)
{
$where = array(
'g.merchant_id' => $parameter['merchant_id'],
'g.status' => array('in', '0,1'),
'g.m_goods_id' => $parameter['merchant_goods_id'],
's.status' => array('in', '0,1')
);
$page = $parameter['page'] ? $parameter['page'] : 1;
$limit = $parameter['limit'] ? $parameter['limit'] : 10;
$list = $this->alias('g')
->join('ls_retail_store_sale_goods as s on g.id=s.goods_id')
->field("s.store_id,s.goods_num,s.id,s.goods_id,s.serial_number_state")
->where($where)
->page($page, $limit)
->select();
return $list;
}
/**
* 商户调拨门店的普通商品库存详情
* @param $parameter
* [
* merchant_goods_id 商户商品id
* merchant_id
* ]
* @return mixed
*/
public function getSyncMerchantGoodsCount($parameter)
{
$where = array(
'g.merchant_id' => $parameter['merchant_id'],
'g.status' => array('in', '0,1'),
'g.m_goods_id' => $parameter['merchant_goods_id'],
's.status' => array('in', '0,1')
);
$count = $this->alias('g')
->join('ls_retail_store_sale_goods as s on g.id=s.goods_id')
->where($where)
->count();
return $count ? $count : 0;
}
/**
* 判断该门店的商品是否有使用的分类属于该行业的
*/
public function getStoreIsUseClassIndustry($where)
{
$result = $this->alias('goods')
->join('ls_retail_goods_class as class on class.id = goods.goods_class_id')
->join('ls_store_industry as industry on industry.id = class.industry_id')
->where($where)
->count();
return $result;
}
}