194 行
7.5 KiB
PHP
可执行文件
194 行
7.5 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Common\Model;
|
||
|
||
use Think\Model;
|
||
|
||
//[1.8.50]
|
||
|
||
/**
|
||
* 购物车表
|
||
* Class RetailShoppingModel
|
||
* @package Common\Model
|
||
*/
|
||
class RetailShoppingModel extends BaseModel
|
||
{
|
||
protected $tableName = 'retail_shopping';
|
||
const ID = 'id'; //int(11) NOT NULL AUTO_INCREMENT,
|
||
const UID = 'uid'; //int(11) DEFAULT NULL COMMENT '用户id',
|
||
const GOODS_ID = 'goods_id';//int(11) DEFAULT NULL COMMENT '商品id',
|
||
const NUM = 'num'; //decimal(10,3) DEFAULT '0.000' COMMENT '数量',
|
||
const MERCHANT_ID = 'merchantid';//int(11) DEFAULT NULL,
|
||
const STORE_ID = 'storeid'; //int(11) DEFAULT NULL,
|
||
const ADD_TIME = 'addtime'; //varchar(255) DEFAULT NULL COMMENT '加入时间',
|
||
const TYPE = 'type'; //tinyint(1) NOT NULL DEFAULT '1' COMMENT '购物车商品来源:1,加入购物车,2,立即购买。',
|
||
const SKU_ID = 'sku_id'; //int(11) DEFAULT '0' COMMENT '新规格id',
|
||
const STATE = 'state'; //tinyint(1) NOT NULL DEFAULT '1' COMMENT '1正常 0删除',
|
||
const CHANGE_STATE = 'can_change_num';// tinyint(1) DEFAULT '1' COMMENT '0不能修改数量 1能修改数量',
|
||
const GIFTS_ACTIVITY_ID = 'gifts_activity_id';// int(11) NOT NULL DEFAULT '0' COMMENT '促销赠送活动ID',
|
||
|
||
/**
|
||
* @param $uid 小程序用户id
|
||
* @param $store_id 门店id
|
||
* @param $fields 选取字段
|
||
* @param string $ids 购物车表id
|
||
* @param $type 1购物车 1立即购买
|
||
* @return mixed
|
||
*/
|
||
public function getShoppingGoods($uid, $store_id, $fields, $ids = '', $type = '2')
|
||
{
|
||
$GoodsModel = D('RetailGoods');
|
||
$HostModel = D('RetailHost');
|
||
$map = array(
|
||
's.' . $this::UID => $uid,
|
||
's.' . $this::STORE_ID => $store_id,
|
||
's.' . $this::STATE => 1,
|
||
'g.' . $GoodsModel::ONLINE_STATE => 1,
|
||
'g.' . $GoodsModel::STATUS => 0
|
||
);
|
||
if (!empty($type)) {
|
||
$map['s.' . $this::TYPE] = array('in', $type);
|
||
}
|
||
if (!empty($ids)) {
|
||
$map['s.' . $this::ID] = array('in', $ids);
|
||
}
|
||
if (empty($fields)) {
|
||
$fields = array(
|
||
's.*',
|
||
'h.' . $HostModel::STATUS . ' as h_status',
|
||
'h.' . $HostModel::ACT_PRICE,
|
||
'g.' . $GoodsModel::GOODS_NAME,
|
||
'g.' . $GoodsModel::GOODS_IMG_ID,
|
||
'g.' . $GoodsModel::ONLINE_PRICE,
|
||
'g.' . $GoodsModel::VIP_ONLINE_STATE,
|
||
'g.' . $GoodsModel::SHOP_MEM_STATUS,
|
||
'g.' . $GoodsModel::SHOP_MEM_PRICE,
|
||
'g.' . $GoodsModel::ATTRIBUTE_STATE,
|
||
'g.' . $GoodsModel::PRICING_METHOD,
|
||
'g.' . $GoodsModel::PLUS_MEM_STATUS,
|
||
'g.' . $GoodsModel::PLUS_PRICE,
|
||
'g.' . $GoodsModel::SHOP_MEM_INTEGRAL,
|
||
'g.' . $GoodsModel::PLUS_MEM_INTEGRAL,
|
||
'g.company'
|
||
);
|
||
}
|
||
$time = time();
|
||
$goods_list = $this->alias('s')
|
||
->join('ls_retail_goods as g on g.' . $GoodsModel::ID . '=s.' . $this::GOODS_ID)
|
||
->join("ls_retail_host as h on h.goods_id=g.id AND h.state=1 AND h.sku_id=s.sku_id AND h.type=2 AND h.starttime<={$time} AND h.endtime>{$time}", 'LEFT')
|
||
->field($fields)
|
||
->where($map)
|
||
->group('s.id')
|
||
->order('s.' . $HostModel::ADD_TIME . ' desc')->select();
|
||
return $goods_list;
|
||
}
|
||
|
||
/**
|
||
* @param $uid 小程序用户id
|
||
* @param $store_id 门店id
|
||
* @param $fields 选取字段
|
||
* @param string $ids 购物车表id
|
||
* @param $type 1购物车 1立即购买
|
||
* @return mixed
|
||
*/
|
||
public function getShoppingGoods_v1($uid, $store_id, $fields, $ids = '', $type = '2')
|
||
{
|
||
$GoodsModel = D('RetailGoods');
|
||
$HostModel = D('RetailHost');
|
||
$map = array(
|
||
's.' . $this::UID => $uid,
|
||
's.' . $this::STORE_ID => $store_id,
|
||
's.' . $this::STATE => 1,
|
||
'g.' . $GoodsModel::ONLINE_STATE => 1,
|
||
'g.' . $GoodsModel::STATUS => 0
|
||
);
|
||
if (!empty($type)) {
|
||
$map['s.' . $this::TYPE] = array('in', $type);
|
||
}
|
||
if (!empty($ids)) {
|
||
$map['s.' . $this::ID] = array('in', $ids);
|
||
}
|
||
if (empty($fields)) {
|
||
$fields = array(
|
||
's.*',
|
||
'h.' . $HostModel::STATUS . ' as promotion_status',
|
||
'h.' . $HostModel::ACT_PRICE,
|
||
'g.' . $GoodsModel::GOODS_NAME,
|
||
'g.' . $GoodsModel::GOODS_IMG_ID,
|
||
'g.' . $GoodsModel::ONLINE_PRICE,
|
||
'g.' . $GoodsModel::VIP_ONLINE_STATE,
|
||
'g.' . $GoodsModel::SHOP_MEM_STATUS,
|
||
'g.' . $GoodsModel::SHOP_MEM_PRICE,
|
||
'g.' . $GoodsModel::ATTRIBUTE_STATE,
|
||
'g.' . $GoodsModel::PRICING_METHOD,
|
||
'g.' . $GoodsModel::PLUS_MEM_STATUS,
|
||
'g.' . $GoodsModel::PLUS_PRICE,
|
||
);
|
||
}
|
||
$time = time();
|
||
$goods_list = $this->alias('s')
|
||
->join('ls_retail_goods as g on g.' . $GoodsModel::ID . '=s.' . $this::GOODS_ID)
|
||
->join("ls_retail_host as h on h.goods_id=g.id AND h.state=1 AND h.sku_id=s.sku_id AND h.type=2 AND h.starttime<={$time} AND h.endtime>{$time}", 'LEFT')
|
||
->field($fields)
|
||
->where($map)
|
||
->group('s.id')
|
||
->order('s.' . $HostModel::ADD_TIME . ' desc')->select();
|
||
|
||
// 赠品数据显示
|
||
|
||
return $goods_list;
|
||
}
|
||
|
||
|
||
/**
|
||
* @param $uid 小程序用户id
|
||
* @param $store_id 门店id
|
||
* @param string $fields 选取字段
|
||
* @param string $page 页
|
||
* @param string $limit 数量
|
||
* @return mixed
|
||
*/
|
||
public function getShoppingGoods_v2($uid, $store_id, $fields = '', $page = '1', $limit = '10')
|
||
{
|
||
$GoodsModel = D('RetailGoods');
|
||
$HostModel = D('RetailHost');
|
||
$map = array(
|
||
's.' . $this::UID => $uid,
|
||
's.' . $this::STORE_ID => $store_id,
|
||
's.' . $this::STATE => 1,
|
||
's.' . $this::TYPE => 1,
|
||
'g.' . $GoodsModel::ONLINE_STATE => 1,
|
||
'g.' . $GoodsModel::STATUS => 0,
|
||
);
|
||
if (empty($fields)) {
|
||
$fields = array(
|
||
's.*',
|
||
'h.' . $HostModel::STATUS . ' as promotion_status',
|
||
'h.' . $HostModel::ACT_PRICE,
|
||
'g.' . $GoodsModel::GOODS_NAME,
|
||
'g.' . $GoodsModel::GOODS_IMG_ID,
|
||
'g.' . $GoodsModel::ONLINE_PRICE,
|
||
'g.' . $GoodsModel::VIP_ONLINE_STATE,
|
||
'g.' . $GoodsModel::SHOP_MEM_STATUS,
|
||
'g.' . $GoodsModel::SHOP_MEM_PRICE,
|
||
'g.' . $GoodsModel::ATTRIBUTE_STATE,
|
||
'g.' . $GoodsModel::PRICING_METHOD,
|
||
'g.' . $GoodsModel::PLUS_MEM_STATUS,
|
||
'g.' . $GoodsModel::PLUS_PRICE,
|
||
'g.delivery_type',
|
||
'g.third_goods_code'
|
||
);
|
||
}
|
||
$time = time();
|
||
$goods_list = $this->alias('s')
|
||
->join('ls_retail_goods as g on g.' . $GoodsModel::ID . '=s.' . $this::GOODS_ID)
|
||
->join("ls_retail_host as h on h.goods_id=g.id AND h.state=1 AND h.sku_id=s.sku_id AND h.type=2 AND h.starttime<={$time} AND h.endtime>{$time}", 'LEFT')
|
||
->field($fields)
|
||
->where($map)
|
||
->group('s.id')
|
||
->order('s.' . $HostModel::ADD_TIME . ' desc')
|
||
->page($page, $limit)
|
||
->select();
|
||
return $goods_list;
|
||
}
|
||
} |