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

437 行
17 KiB
PHP
可执行文件

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

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

<?php
namespace Common\Model;
use Think\Model;
//[1.4.13]
/**
* 大转盘- 数据对象模型
* @author ocean
* @version LV1.0
*/
class TurntableUseModel extends BaseModel
{
protected $tableName = 'turntable_use'; // 大转盘
protected $fields = array(
'id',// int(11) NOT NULL AUTO_INCREMENT,
'user_id',// int(11) NOT NULL COMMENT '中奖用户ID',
'add_time',// int(11) NOT NULL COMMENT '中奖时间',
'receive_time',// int(11) DEFAULT NULL COMMENT '奖品领取时间',
'status',// tinyint(1) NOT NULL COMMENT '状态:1,未领取,2,已领取',
'merchant_id',// int(11) NOT NULL COMMENT '活动所属商户ID',
'turntable_prize_id',// int(11) NOT NULL COMMENT '奖品id',
'store_id',// int(11) DEFAULT NULL COMMENT '限制门店的活动中奖时对应的门店ID 不限制时为空',
'turntable_id',// int(11) NOT NULL COMMENT '大转盘id',
'bill_id',// int(11) DEFAULT NULL COMMENT 'bill_order表id,支付时',
'receive_code',// varchar(100) DEFAULT NULL COMMENT '自提时所生成的核销码',
'delivery_status',//tinyint(1) NOT NULL COMMENT '配送方式下的配送状态:1待配送 2已发放',
'order_num',// varchar(255) NOT NULL COMMENT '中奖订单号',
'username',// varchar(45) DEFAULT NULL COMMENT '中奖人姓名',
'phone',// varchar(255) DEFAULT NULL COMMENT '中奖人手机号',
'address',// varchar(255) DEFAULT NULL COMMENT '中奖人收货地址',
'delivery_type',// tinyint(1) NOT NULL COMMENT '配送方式:1配送 2自提 3自动发放',
'prize_type',// tinyint(1) NOT NULL COMMENT '奖品类型:1实物 2门店商品 3积分 4余额 5谢谢惠顾',
);
/**
* 添加中奖记录
*/
public function addTurntableUse($data)
{
$ret = $this->add($data);
return $ret;
}
/**
* 修改中奖记录
*/
public function saveTurntableUse($id, $data)
{
$w['id'] = $id;
$ret = $this->where($w)->save($data);
return $ret;
}
/*
* 获取中奖记录列表
* param $merchant_id 商户ID
* param $title 搜索字段
* param $turntable_id 活动ID
* param $grant_type 发放方式1配送 2自提 3自动发放
* param $grant_status 发放状态1待配送 2已发放
* param $prize_type 奖品类型:1实物 2门店商品 3积分 4余额 5谢谢惠顾
* param $start_time 开始时间
* param $end_time 结束时间
* param $page 当前页数
* param $page_size 每页记录数,
* */
public function getWinList($merchant_id, $title, $turntable_id, $grant_type, $grant_status, $prize_type, $start_time, $end_time, $page, $page_size)
{
$where['a.merchant_id'] = $merchant_id;
if (!empty($turntable_id)) {
$where['a.turntable_id'] = $turntable_id;
}
if (!empty($grant_type)) {
$where['a.delivery_type'] = $grant_type;
}
if (!empty($grant_status)) {
$where['a.delivery_status'] = $grant_status;
}
if (!empty($prize_type)) {
$where['a.prize_type'] = $prize_type;
}
if (!empty($start_time) and !empty($end_time)) {
$where['a.add_time'] = array('between', $start_time . ',' . $end_time);
}
if (!empty($title)) {
$map['a.username'] = array('like', '%' . $title . '%');
$map['a.phone'] = array('like', '%' . $title . '%');
$map['_logic'] = 'or';
$where['_complex'] = $map;
}
$list = $this->alias('a')
->join('ls_turntable as b on a.turntable_id=b.id', 'LEFT')
->join('ls_retail_store as c on a.store_id=c.id', 'LEFT')
->join('ls_turntable_prize as d on a.turntable_prize_id=d.id', 'LEFT')
->join('ls_retail_vip as e on a.user_id=e.id', 'LEFT')
->field('a.id,a.order_num,a.phone,a.add_time,a.delivery_type,a.delivery_status,a.receive_time,b.turntable_name,c.storetag,d.id as prize_id,d.prize_name,e.name,e.nickname')
->where($where)
->page($page, $page_size)
->order('a.add_time desc')
->select();
return $list;
}
/*
* 获取中奖记录总数
* param $merchant_id 商户ID
* param $title 搜索字段
* param $turntable_id 活动ID
* param $grant_type 发放方式1配送 2自提 3自动发放
* param $grant_status 发放状态1待配送 2已发放
* param $prize_type 奖品类型:1实物 2门店商品 3积分 4余额 5谢谢惠顾
* param $start_time 开始时间
* param $end_time 结束时间
* param $page 当前页数
* param $page_size 每页记录数,
* */
public function getWinCount($merchant_id, $title, $turntable_id, $grant_type, $grant_status, $prize_type, $start_time, $end_time)
{
$where['a.merchant_id'] = $merchant_id;
if (!empty($turntable_id)) {
$where['a.turntable_id'] = $turntable_id;
}
if (!empty($grant_type)) {
$where['a.delivery_type'] = $grant_type;
}
if (!empty($grant_status)) {
$where['a.delivery_status'] = $grant_status;
}
if (!empty($prize_type)) {
$where['a.prize_type'] = $prize_type;
}
if (!empty($start_time) and !empty($end_time)) {
$where['a.add_time'] = array('between', $start_time . ',' . $end_time);
}
if (!empty($title)) {
$map['a.username'] = array('like', '%' . $title . '%');
$map['a.phone'] = array('like', '%' . $title . '%');
$map['_logic'] = 'or';
$where['_complex'] = $map;
}
$list = $this->alias('a')
->join('ls_turntable as b on a.turntable_id=b.id', 'LEFT')
->join('ls_retail_store as c on a.store_id=c.id', 'LEFT')
->join('ls_turntable_prize as d on a.turntable_prize_id=d.id', 'LEFT')
->field('a.id,a.order_num,a.username,a.phone,a.add_time,a.delivery_type,a.delivery_status,a.receive_time,b.turntable_name,c.storetag,d.prize_name')
->where($where)
->count();
return $list;
}
/*
* 获取门店中奖记录列表
* param $store_id 门店ID
* param $merchant_id 商户ID
* param $title 搜索字段
* param $turntable_id 活动ID
* param $grant_type 发放方式1配送 2自提 3自动发放
* param $grant_status 发放状态1待配送 2已发放
* param $prize_type 奖品类型:1实物 2门店商品 3积分 4余额 5谢谢惠顾
* param $start_time 开始时间
* param $end_time 结束时间
* param $page 当前页数
* param $page_size 每页记录数,
* */
public function getWinRecordStoreList($store_id, $merchant_id, $title, $turntable_id, $grant_type, $grant_status, $prize_type, $start_time, $end_time, $page, $page_size)
{
$where['a.store_id'] = $store_id;
if (!empty($merchant_id)) {
$where['a.merchant_id'] = $merchant_id;
}
if (!empty($turntable_id)) {
$where['a.turntable_id'] = $turntable_id;
}
if (!empty($grant_type)) {
$where['a.delivery_type'] = $grant_type;
}
if (!empty($grant_status)) {
$where['a.delivery_status'] = $grant_status;
}
if (!empty($prize_type)) {
$where['a.prize_type'] = $prize_type;
}
if (!empty($start_time) and !empty($end_time)) {
$where['a.add_time'] = array('between', $start_time . ',' . $end_time);
}
if (!empty($title)) {
$map['a.username'] = array('like', '%' . $title . '%');
$map['a.phone'] = array('like', '%' . $title . '%');
$map['_logic'] = 'or';
$where['_complex'] = $map;
}
$list = $this->alias('a')
->join('ls_turntable as b on a.turntable_id=b.id', 'LEFT')
->join('ls_retail_store as c on a.store_id=c.id', 'LEFT')
->join('ls_turntable_prize as d on a.turntable_prize_id=d.id', 'LEFT')
->field('a.id,a.order_num,a.username,a.phone,a.add_time,a.delivery_type,a.delivery_status,a.receive_time,b.turntable_name,c.storetag,d.id as prize_id,d.prize_name')
->where($where)
->page($page, $page_size)
->order('a.add_time desc')
->select();
return $list;
}
/*
* 获取门店中奖记录总数
* param $store_id 门店ID
* param $merchant_id 商户ID
* param $title 搜索字段
* param $turntable_id 活动ID
* param $grant_type 发放方式1配送 2自提 3自动发放
* param $grant_status 发放状态1待配送 2已发放
* param $prize_type 奖品类型:1实物 2门店商品 3积分 4余额 5谢谢惠顾
* param $start_time 开始时间
* param $end_time 结束时间
* param $page 当前页数
* param $page_size 每页记录数,
* */
public function getWinRecordStoreCount($store_id, $merchant_id, $title, $turntable_id, $grant_type, $grant_status, $prize_type, $start_time, $end_time)
{
$where['a.store_id'] = $store_id;
if (!empty($merchant_id)) {
$where['a.merchant_id'] = $merchant_id;
}
if (!empty($turntable_id)) {
$where['a.turntable_id'] = $turntable_id;
}
if (!empty($grant_type)) {
$where['a.delivery_type'] = $grant_type;
}
if (!empty($grant_status)) {
$where['a.delivery_status'] = $grant_status;
}
if (!empty($prize_type)) {
$where['a.prize_type'] = $prize_type;
}
if (!empty($start_time) and !empty($end_time)) {
$where['a.add_time'] = array('between', $start_time . ',' . $end_time);
}
if (!empty($title)) {
$map['a.username'] = array('like', '%' . $title . '%');
$map['a.phone'] = array('like', '%' . $title . '%');
$map['_logic'] = 'or';
$where['_complex'] = $map;
}
$list = $this->alias('a')
->join('ls_turntable as b on a.turntable_id=b.id', 'LEFT')
->join('ls_retail_store as c on a.store_id=c.id', 'LEFT')
->join('ls_turntable_prize as d on a.turntable_prize_id=d.id', 'LEFT')
->field('a.id,a.order_num,a.username,a.phone,a.add_time,a.delivery_type,a.delivery_status,a.receive_time,b.turntable_name,c.storetag,d.prize_name')
->where($where)
->count();
return $list;
}
/*
* 获取中奖记录详情名单列表
* param $merchant_id 商户ID
* param $title 搜索字段
* param $turntable_id 活动ID
* param $grant_status 发放状态1待配送 2已发放
* param $prize_type 奖品类型:1实物 2门店商品 3积分 4余额 5谢谢惠顾
* param $start_time 开始时间
* param $end_time 结束时间
* param $page 当前页数
* param $page_size 每页记录数,
* */
public function getWinDetail($merchant_id, $title, $turntable_id, $grant_status, $prize_type, $start_time, $end_time, $page, $page_size)
{
$where['a.merchant_id'] = $merchant_id;
if (!empty($turntable_id)) {
$where['a.turntable_id'] = $turntable_id;
}
if (!empty($grant_status)) {
$where['a.delivery_status'] = $grant_status;
}
if (!empty($prize_type)) {
$where['a.prize_type'] = $prize_type;
}
if (!empty($start_time) and !empty($end_time)) {
$where['a.add_time'] = array('between', $start_time . ',' . $end_time);
}
if (!empty($title)) {
$map['a.username'] = array('like', '%' . $title . '%');
$map['a.phone'] = array('like', '%' . $title . '%');
$map['_logic'] = 'or';
$where['_complex'] = $map;
}
$list = $this->alias('a')
->join('ls_turntable as b on a.turntable_id=b.id', 'LEFT')
->join('ls_retail_store as c on a.store_id=c.id', 'LEFT')
->join('ls_turntable_prize as d on a.turntable_prize_id=d.id', 'LEFT')
->field('a.id,a.order_num,a.username,a.phone,a.add_time,a.delivery_type,a.delivery_status,a.receive_time,b.turntable_name,c.storetag,d.prize_name')
->where($where)
->page($page, $page_size)
->select();
return $list;
}
/*
* 获取中奖记录详情名单总数
* param $merchant_id 商户ID
* param $title 搜索字段
* param $turntable_id 活动ID
* param $grant_status 发放状态1待配送 2已发放
* param $prize_type 奖品类型:1实物 2门店商品 3积分 4余额 5谢谢惠顾
* param $start_time 开始时间
* param $end_time 结束时间
* param $page 当前页数
* param $page_size 每页记录数,
* */
public function getWinDetailCount($merchant_id, $title, $turntable_id, $grant_status, $prize_type, $start_time, $end_time)
{
$where['a.merchant_id'] = $merchant_id;
if (!empty($turntable_id)) {
$where['a.turntable_id'] = $turntable_id;
}
if (!empty($grant_status)) {
$where['a.delivery_status'] = $grant_status;
}
if (!empty($prize_type)) {
$where['a.prize_type'] = $prize_type;
}
if (!empty($start_time) and !empty($end_time)) {
$where['a.add_time'] = array('between', $start_time . ',' . $end_time);
}
if (!empty($title)) {
$map['a.username'] = array('like', '%' . $title . '%');
$map['a.phone'] = array('like', '%' . $title . '%');
$map['_logic'] = 'or';
$where['_complex'] = $map;
}
$list = $this->alias('a')
->join('ls_turntable as b on a.turntable_id=b.id', 'LEFT')
->join('ls_retail_store as c on a.store_id=c.id', 'LEFT')
->join('ls_turntable_prize as d on a.turntable_prize_id=d.id', 'LEFT')
->field('a.id,a.order_num,a.username,a.phone,a.add_time,a.delivery_type,a.delivery_status,a.receive_time,b.turntable_name,c.storetag,d.prize_name')
->where($where)
->count();
return $list;
}
//小程序端 我的中奖记录
/* param $merchant_id 商户ID
/* param $turntable_id 转盘ID
* param $user_id 用户ID
* param $page 当前页数
* param $page_size 每页记录数,
* */
public function getTurntableWinList($merchant_id, $turntable_id, $user_id, $page, $page_size)
{
$where['a.user_id'] = $user_id;
$where['a.prize_type'] = ['lt', 5];//过滤 谢谢惠顾
if (!empty($merchant_id)) {
$where['a.merchant_id'] = $merchant_id;
}
if (!empty($turntable_id)) {
$where['a.turntable_id'] = $turntable_id;
}
$list = $this->alias('a')
->join('ls_turntable_prize as d on a.turntable_prize_id=d.id', 'LEFT')
->field('a.id,a.order_num,a.status,a.add_time,a.delivery_type,d.id as prize_id,d.prize_name,d.type')
->where($where)
->page($page, $page_size)
->order('a.add_time desc')
->select();
return $list;
}
//小程序端 我的中奖记录总数
/* param $merchant_id 商户ID
/* param $turntable_id 转盘ID
/* param $merchant_id 商户ID
* param $user_id 用户ID
* */
public function getTurntableWinCount($merchant_id, $turntable_id, $user_id)
{
$where['a.user_id'] = $user_id;
$where['a.prize_type'] = ['lt', 5];//过滤 谢谢惠顾
if (!empty($merchant_id)) {
$where['a.merchant_id'] = $merchant_id;
}
if (!empty($turntable_id)) {
$where['a.turntable_id'] = $turntable_id;
}
$list = $this->alias('a')
->join('ls_turntable_prize as d on a.turntable_prize_id=d.id', 'LEFT')
->field('a.id,a.order_num,a.status,a.add_time,d.id as prize_id,d.prize_name,d.type')
->where($where)
->order('a.add_time desc')
->count();
return $list;
}
//小程序端 查看实物奖品详情
/* param $win_id 中奖记录ID
* param $user_id 用户ID
* */
public function getPrizeDetail($win_id, $user_id)
{
$where['a.user_id'] = $user_id;
$where['a.id'] = $win_id;
$list = $this->alias('a')
->join('ls_turntable_prize as d on a.turntable_prize_id=d.id', 'LEFT')
->field('a.id,a.order_num,a.status,a.add_time,a.delivery_type,d.id as prize_id,d.prize_name,d.prize_img,d.grant_type')
->where($where)
->find();
return $list;
}
}