202 行
7.7 KiB
PHP
可执行文件
202 行
7.7 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Common\Model;
|
||
//[1.7.14]
|
||
|
||
/**
|
||
* VipMCouponModel 删除
|
||
* Class GoodsModel
|
||
* @package Common\Model
|
||
*/
|
||
class RetailVipMCouponModel extends BaseModel
|
||
{
|
||
protected $tableName = 'retail_vipmcoupon';
|
||
const ID = 'id'; //int(11) NOT NULL AUTO_INCREMENT,
|
||
const VID = 'vid'; //int(11) NOT NULL DEFAULT '0' COMMENT '会员id',
|
||
const MCOUPON_ID = 'mcouponid'; //int(11) NOT NULL DEFAULT '0' COMMENT '商家优惠券id。',
|
||
const START_TIME = 'starttime'; //varchar(13) NOT NULL DEFAULT '' COMMENT '优惠券生效时间。',
|
||
const END_TIME = 'endtime'; //varchar(13) NOT NULL DEFAULT '' COMMENT '优惠券过期时间。',
|
||
const NEED_MONEY = 'needmoney'; //decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '优惠券使用门槛。',
|
||
const REDUCE_MONEY = 'reducemoney'; //decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '优惠券面额。',
|
||
const IS_USE = 'isuse'; //tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否使用:1,未使用。2,已使用,3,已过期(未使用的优惠券过期将改变该字段未3)',
|
||
const USE_TIME = 'usetime'; //varchar(13) NOT NULL DEFAULT '' COMMENT '使用时间',
|
||
const CAN_USE_STORE_IDS = 'canusestoreids'; //text NOT NULL COMMENT '能使用该优惠券的门店 。 以 ‘,’连接',
|
||
const MERCHANT_ID = 'merchantid'; //int(11) NOT NULL DEFAULT '0' COMMENT '商户id。',
|
||
const STORE_ID = 'storeid'; //int(11) NOT NULL DEFAULT '0' COMMENT '使用门店的id',
|
||
const LESS_MONEY = 'lessmoney'; //decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '使用时抵扣的金额。(部分优惠券金额未完全抵扣完)。',
|
||
const ADD_TIME = 'addtime'; //varchar(13) NOT NULL DEFAULT '' COMMENT '会员获得优惠券的时间。',
|
||
const STATUS = 'status'; //tinyint(3) DEFAULT '2' COMMENT '优惠券状态 1下架 2开启 3删除(不读取)',
|
||
const TYPE = 'type'; //tinyint(1) DEFAULT '1' COMMENT '类型1.普通优惠券2.券包优惠券',
|
||
const MCOUPON_GROUP_ID = 'mcoupon_group_id'; //int(10) DEFAULT NULL COMMENT '券包id',
|
||
const RECHARGE_ORDER_ID = 'recharge_order_id'; //int(10) DEFAULT NULL COMMENT '充值订单id',
|
||
const BILL_ID = 'bill_id'; //int(10) DEFAULT NULL COMMENT '充值订单id',
|
||
|
||
/**
|
||
* 获取正在使用的优惠券,并判断该优惠券是否可以在当前门店使用
|
||
* @param $map
|
||
* @param $store_id
|
||
* @param $fields
|
||
* @return mixed
|
||
*/
|
||
public function getFindUseCoupon($map, $store_id, $fields)
|
||
{
|
||
$coupon = $this->alias('v')
|
||
->join('ls_retail_mcoupon as m on m.id=v.' . $this::MCOUPON_ID)
|
||
->field($fields)
|
||
->where($map)
|
||
->find();
|
||
if (!empty($coupon)) {
|
||
if ($coupon[$this::CAN_USE_STORE_IDS] != 0) {
|
||
//限制了使用门店
|
||
$canUseStore = explode(',', trim($coupon[$this::CAN_USE_STORE_IDS], ','));
|
||
if (!in_array($store_id, $canUseStore)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '该优惠券不能在当前门店使用';
|
||
return $res;
|
||
}
|
||
}
|
||
if (!is_numeric($coupon[$this::NEED_MONEY])) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '优惠券设置有误';
|
||
return $res;
|
||
}
|
||
$res['status'] = 1;
|
||
$res['coupon'] = $coupon;
|
||
$res['msg'] = '查询成功';
|
||
return $res;
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '优惠券信息有误';
|
||
return $res;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取多条可使用的优惠券
|
||
* @param $map
|
||
* @param $store_id
|
||
* @param $fields
|
||
* @return mixed
|
||
*/
|
||
public function getSelectUseCoupon($map, $store_id, $fields = null)
|
||
{
|
||
$MCouponModel = D('RetailMCoupon');
|
||
if (empty($fields)) {
|
||
$fields = array(
|
||
'v.' . $this::ID,
|
||
'v.' . $this::NEED_MONEY . ' as need_money',
|
||
'v.' . $this::REDUCE_MONEY . ' as reduce_money',
|
||
'v.' . $this::START_TIME,
|
||
'v.' . $this::END_TIME,
|
||
'v.' . $this::CAN_USE_STORE_IDS,
|
||
'm.' . $MCouponModel::COUPON_NAME . ' as coupon_name',
|
||
);
|
||
}
|
||
$coupon = $this->alias('v')
|
||
->join('ls_retail_mcoupon as m on m.id=v.' . $this::MCOUPON_ID)
|
||
->field($fields)
|
||
->where($map)
|
||
->select();
|
||
if (!empty($coupon)) {
|
||
$temp = array();
|
||
foreach ($coupon as &$value) {
|
||
$value['coupon_choice_type'] = 2;//商户优惠券
|
||
$value['begin_time'] = date('Y-m-d', $value[$this::START_TIME]);
|
||
$value['end_time'] = date('Y-m-d', $value[$this::END_TIME]);
|
||
$value['reducemoney'] = round($value['reducemoney'], 2);
|
||
$value['needmoney'] = round($value['needmoney'], 2);
|
||
if ($value[$this::CAN_USE_STORE_IDS] != 0) {
|
||
//限制了使用门店
|
||
$canUseStore = explode(',', trim($value[$this::CAN_USE_STORE_IDS], ','));
|
||
if (in_array($store_id, $canUseStore)) {
|
||
$temp[] = $value;
|
||
}
|
||
} else {
|
||
$temp[] = $value;
|
||
}
|
||
}
|
||
if (!empty($temp)) {
|
||
return $temp;
|
||
} else {
|
||
return false;
|
||
}
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
//发放记录
|
||
public function getGrantRecord($where, $fields, $order, $page, $limit)
|
||
{
|
||
$list = $this->alias('r')
|
||
->join('ls_retail_mcoupon as c on c.id=r.mcouponid')
|
||
->join('ls_retail_vip as v on r.vid=v.id')
|
||
->field($fields)
|
||
->where($where)
|
||
->order($order)
|
||
->page($page, $limit)
|
||
->select();
|
||
return $list;
|
||
}
|
||
|
||
//发放记录
|
||
public function getGrantRecordCount($where)
|
||
{
|
||
$count = $this->alias('r')
|
||
->join('ls_retail_mcoupon as c on c.id=r.mcouponid')
|
||
->join('ls_retail_vip as v on r.vid=v.id')
|
||
->where($where)
|
||
->count();
|
||
return $count;
|
||
}
|
||
|
||
|
||
/**
|
||
* 会员优惠券记录
|
||
* @param $where
|
||
* @param $fields
|
||
* @param $order
|
||
* @param $page
|
||
* @param $limit
|
||
* @return mixed
|
||
*/
|
||
public function getVipCouponList($where, $fields, $order = 'c.id desc', $page = '', $limit = '')
|
||
{
|
||
if (!empty($page) && !empty($limit)) {
|
||
$list = $this->alias('r')
|
||
->join('ls_retail_mcoupon as c on r.mcouponid=c.id')
|
||
->field($fields)
|
||
->where($where)
|
||
->order($order)
|
||
->page($page, $limit)
|
||
->select();
|
||
} else {
|
||
$list = $this->alias('r')
|
||
->join('ls_retail_mcoupon as c on r.mcouponid=c.id')
|
||
->field($fields)
|
||
->where($where)
|
||
->order($order)
|
||
->select();
|
||
}
|
||
return $list;
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取单张优惠券
|
||
* @param $where
|
||
* @param $fields
|
||
* @return mixed
|
||
*/
|
||
public function getSingleCoupon($where, $fields)
|
||
{
|
||
$coupon = $this->alias('r')
|
||
->join('ls_retail_mcoupon as c on c.id=r.mcouponid')
|
||
->field($fields)
|
||
->where($where)
|
||
->find();
|
||
return $coupon;
|
||
}
|
||
} |