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

135 行
5.5 KiB
PHP
可执行文件

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

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

<?php
/**
* 插件模型 - 数据对象模型
* @author zaiyuliya
* @version LV1.0
*/
namespace Common\Model;
use Think\Model;
//[1.4.13]
class RewardModel extends BaseModel
{
protected $tableName = 'reward';
protected $fields = array(
'id',//int(11) NOT NULL AUTO_INCREMENT COMMENT '红包id',
'merchant_id',//int(11) DEFAULT NULL COMMENT '商户id',
'money',//decimal(20,2) DEFAULT NULL COMMENT '红包金额',
'less_money',//decimal(20,2) DEFAULT NULL COMMENT '剩余金额',
'number',//int(10) DEFAULT NULL COMMENT '红包数量',
'less_number',//int(10) DEFAULT NULL COMMENT '剩余红包个数',
'need_money',//decimal(20,2) DEFAULT NULL COMMENT '消费金额',
'min_money',//decimal(20,2) DEFAULT NULL COMMENT '红包最小值',
'max_money',//decimal(20,2) DEFAULT NULL COMMENT '红包最大值',
'add_time',//varchar(20) DEFAULT NULL COMMENT '商户添加红包的时间',
'status',//int(2) DEFAULT '1' COMMENT '1 开启红包 0关闭红包',
'start_time',//varchar(20) DEFAULT NULL COMMENT '红包开启时间',
'end_time',//varchar(20) DEFAULT NULL COMMENT '红包结束时间',
'phase',//int(11) DEFAULT '1' COMMENT '红包期数:每修改一次红包,即开始新的红包期数。',
'type',//int(1) DEFAULT NULL COMMENT '红包场景类型 1 公众号红包 2 线下支付红包 3 小程序首页红包 4 线上支付红包',
'day_restrict_type',//tinyint(1) DEFAULT '0' COMMENT '每日领取限制 0不限制 1限制次数 2限制金额',
'day_max_time',//int(11) DEFAULT '0' COMMENT '每天最多能领取多少次 不填默认为不限制只在is_everyday为1时有效',
'sum_max_time',//int(11) DEFAULT '0' COMMENT '每个用户能领取的最大总次数 不填默认为不限制只在is_everyday为1时有效',
'reward_list',//longtext,
'name',//varchar(16) DEFAULT NULL COMMENT '活动名称',
'reward_type',//tinyint(1) DEFAULT '2' COMMENT '红包发放类型:1 固定 2 随机 3 梯度',
'is_limit_store',//tinyint(1) DEFAULT '0' COMMENT '是否限制门店:0 不限制 1 限制',
'limit_store_id',//varchar(32) DEFAULT NULL COMMENT '限制参加门店的所有门店id',
'is_vip',//tinyint(1) DEFAULT '1' COMMENT '是否是会员活动:0 否 1 是',
'is_class_limit',//tinyint(1) DEFAULT '0' COMMENT '是否有会员等级限制:0 否 1 是',
'class_type',//varchar(32) DEFAULT NULL COMMENT '会员等级',
'fixed_money',//decimal(20,2) DEFAULT NULL COMMENT '固定金额',
'day_max_money',//decimal(20,2) DEFAULT NULL COMMENT '每日最大金额',
'is_del',//tinyint(1) DEFAULT '0' COMMENT '是否删除(0否 1是)',
'is_number',//tinyint(1) DEFAULT '1' COMMENT '是否限制数量(0否 1是)',
'is_money',//tinyint(1) DEFAULT '1' COMMENT '是否限制金额(0否 1是)',
);
/**
* @param $merchant_id
* @param $type 红包类型 1 公众号红包 2 刷卡支付红包 3 小程序首页红包 4 线上支付红包
* @return mixed
*/
public function getReward($merchant_id, $type)
{
$res = $this->where(array('merchant_id' => $merchant_id, 'status' => 1, 'type' => $type))->find();
return $res;
}
/**
* 获取正在开启中的同类型红包
* @param $merchant_id 商户id
* @param $type 类型
* @return mixed
*/
/**
* 获取正在开启中的同时段同类型红包
* @param $merchant_id 商户id
* @param $type 类型
* @param $start_time 开始时间
* @param $end_time 结束时间
* @return mixed
*/
public function getStartingReward($merchant_id, $type, $start_time, $end_time)
{
$map = array(
'merchant_id' => $merchant_id,
'status' => 1,
'is_del' => 0,
'type' => $type,
array(
array(
'less_number' => array('gt', 0),
'is_number' => 1,
),
array(
'less_money' => array('gt', 0),
'is_money' => 1,
),
'end_time' => array('between', "{$start_time},{$end_time}"),
'start_time' => array('between', "{$start_time},{$end_time}"),
array(
'start_time' => array('elt', $start_time),
'end_time' => array('egt', $end_time),
),
'_logic' => 'OR'
),
);
$reward = $this->getFind($map);
return $reward;
}
/**
* 关闭已失效的红包
* @param $merchant_id 商户id
* @param $type 类型
* @return mixed
*/
public function closeInvalidReward($merchant_id, $type = null)
{
$map = array(
'merchant_id' => $merchant_id,
'status' => 1,
'is_del' => 0,
array(
array(
'less_number' => array('elt', 0),
'is_number' => 1,
),
array(
'less_money' => array('elt', 0),
'is_money' => 1,
),
'end_time' => array('lt', time()),
'_logic' => 'OR'
),
);
if (!empty($type)) {
$map['type'] = $type;
}
$close = $this->updateOrder($map, array('status' => 0));
return $close;
}
}