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

178 行
5.4 KiB
PHP
可执行文件

<?php
namespace Common\Model;
//[1.4.36]
class RetailCollectModel extends BaseModel
{
protected $tableName = 'retail_collect';
const ID = 'id'; //int(11) NOT NULL AUTO_INCREMENT,
const GOODS_ID = 'goods_id'; //int(11) DEFAULT NULL COMMENT '商品id',
const STORE_ID = 'storeid'; //int(11) DEFAULT NULL COMMENT '门店id',
const MERCHANT_ID = 'merchantid'; //int(11) DEFAULT NULL COMMENT '商户id',
const ADD_TIME = 'addtime'; //varchar(0) DEFAULT NULL COMMENT '添加时间',
const UID = 'uid'; //int(11) DEFAULT NULL COMMENT '用户Id',
const ACTIVITY_ID='activity_id'; //活动id
const TYPE='type'; //1普通商品 2拼团 3秒杀 4预售
/**
*
*/
public function getGoods($where, $field, $order, $page)
{
if (!empty($page)) {
$collect = $this->alias('c')
->join('ls_retail_goods as g on c.' . $this::GOODS_ID . '=g.id')
->where($where)
->field($field)
->page($page)
->order($order)
->select();
} else {
$collect = $this->alias('c')
->join('ls_retail_goods as g on c.' . $this::GOODS_ID . '=g.id')
->where($where)
->field($field)
->order($order)
->select();
}
return $collect;
}
/**
* 获取商品列表及促销信息
* @param $map
* @param string $fields
* @param string $order
* @param string $page
* @return array
*/
public function getPromotionGoods($map, $fields = '*', $order = 'c.id desc', $page = '1,10')
{
if (empty($map)) {
return array();
}
$time = time();
$list = $this->alias('c')
->join("ls_retail_goods as g on g.id=c.goods_id")
->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')
->where($map)
->order($order)
->group('g.id')
->page($page)
->field($fields)
->select();
return $list;
}
/**
* 验证收藏或取消收藏参数
*/
protected function verify_parameter($parameter)
{
if(empty($parameter['goods_id'])){
$res = array(
'status'=>0,
'msg'=>'缺少商品信息'
);
return $res;
}
if (empty($parameter['uid'])) {
$res['status'] = -1;
$res['msg'] = '用户未登录';
return $res;
}
if(!empty($parameter['activity_id'])){
if(empty($parameter['type'])){
$res = array(
'status'=>0,
'msg'=>'缺少活动类型'
);
return $res;
}
}
$res = array(
'status'=>1,
'msg'=>'验证成功'
);
return $res;
}
/**
* 添加收藏
*/
public function addCollect($parameter)
{
$verify = $this->verify_parameter($parameter);
if($verify['status'] != 1){
return $verify;
}
$content = array(
self::GOODS_ID=>$parameter['goods_id'],
self::STORE_ID=>$parameter['store_id'],
self::MERCHANT_ID=>$parameter['merchant_id'],
self::UID=>$parameter['uid'],
self::ADD_TIME=>time()
);
$where = array(
self::GOODS_ID => $content[self::GOODS_ID],
self::UID => $content[self::UID]
);
if(!empty($parameter['activity_id'])){
$content[self::ACTIVITY_ID] = $parameter['activity_id'];
$content[self::TYPE] = $parameter['type'];
$where[self::ACTIVITY_ID] = $parameter['activity_id'];
$where[self::TYPE] = $parameter['type'];
}
$exist = $this->getFind($where);
if ($exist) {
$res = array(
'status'=>0,
'msg'=>'您已收藏'
);
return $res;
}
$add_collect = $this->addOrder($content);
if ($add_collect) {
$res = array(
'status'=>1,
'msg'=>'收藏成功',
'data'=>array(
'id'=>$add_collect
)
);
} else {
$res = array(
'status'=>0,
'msg'=>'收藏失败'
);
}
return $res;
}
/**
* 取消收藏
*/
public function cancelCollect($parameter)
{
$verify = $this->verify_parameter($parameter);
if($verify['status'] != 1){
return $verify;
}
$where = array(
self::GOODS_ID=>$parameter['goods_id'],
self::STORE_ID=>$parameter['store_id'],
self::UID=>$parameter['uid']
);
if(!empty($parameter['activity_id'])){
$where[self::ACTIVITY_ID] = $parameter['activity_id'];
$where[self::TYPE] = $parameter['type'];
}
$cancel = $this->deleteOrder($where);
if ($cancel) {
$res['status'] = 1;
$res['msg'] = '取消成功';
} else {
$res['status'] = 0;
$res['msg'] = '取消失败';
}
return $res;
}
}