153 行
4.5 KiB
PHP
可执行文件
153 行
4.5 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Common\Model;
|
||
|
||
use Think\Model;
|
||
|
||
//[1.8.20]
|
||
class VipCardModel extends Model
|
||
{
|
||
protected $tableName = 'retail_vip_card';
|
||
protected $fields = array(
|
||
'id', // `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||
'vip_id', // `vip_id` int(10) DEFAULT '0' COMMENT '会员id',
|
||
'merchantid', // `merchantid` int(10) DEFAULT '0' COMMENT '商户id',
|
||
'type', // `type` tinyint(1) DEFAULT '1' COMMENT '次卡类型 1.普通次卡 2.卡包次卡',
|
||
'sub_card_id', // `sub_card_id` int(10) DEFAULT '0' COMMENT '次卡id',
|
||
'card_bag_id', // `card_bag_id` int(10) DEFAULT '0' COMMENT '卡包id',
|
||
'use_num', // `use_num` int(10) DEFAULT '0' COMMENT '已用次数',
|
||
'addtime', // `addtime` varchar(20) DEFAULT '' COMMENT '添加时间',
|
||
'status', // `status` tinyint(1) DEFAULT '0' COMMENT '状态 0.正常 1.删除',
|
||
'recharge_order_id', // `recharge_order_id` int(10) DEFAULT '0' COMMENT '充值订单id',
|
||
'pay_order_id', // `pay_order_id` int(10) DEFAULT '0' COMMENT 'pay_order表主键id',
|
||
'bill_id', // `bill_id` int(10) DEFAULT '0' COMMENT 'bill_order表主键id',
|
||
'start_time', // varchar(12) DEFAULT NULL COMMENT '可核销的开始时间',
|
||
'end_time', // varchar(12) DEFAULT NULL COMMENT '可核销的结束时间',
|
||
);
|
||
|
||
/**
|
||
* 添加(add)
|
||
* @param [array] $cr
|
||
* @return [int|bool] $add|false
|
||
*/
|
||
public function toAdd($cr)
|
||
{
|
||
if (!$cr) {
|
||
return false;
|
||
}
|
||
$add = $this->add($cr);
|
||
return $add;
|
||
}
|
||
|
||
/**
|
||
* @param [array] $map 条件
|
||
* @param [string] $field 字段
|
||
* @return [array|bool] $find|false
|
||
*/
|
||
public function toFind($map, $field = '*')
|
||
{
|
||
if (!$map) {
|
||
return false;
|
||
}
|
||
$find = $this->field($field)->where($map)->find();
|
||
return $find;
|
||
}
|
||
|
||
/**
|
||
* 多条查询(select)
|
||
* @param [array] $map 查询条件
|
||
* @param [int] $page 分页 default ''
|
||
* @param [int] $limit 数量 default ''
|
||
* @param [string] $field 字段 default '*'
|
||
* @param [string] $order 排序 default 'addtime desc'
|
||
* @return [array|bool] $select|false
|
||
*/
|
||
public function toSelect($map, $page = '', $limit = '', $field = '*', $order = 'addtime desc')
|
||
{
|
||
if (!$map) {
|
||
return false;
|
||
}
|
||
if (!$page || !$limit) {
|
||
$select = $this->field($field)->where($map)->order($order)->select();
|
||
} else {
|
||
$select = $this->field($field)->where($map)->page((int)$page, (int)$limit)->order($order)->select();
|
||
}
|
||
return $select;
|
||
}
|
||
|
||
/**
|
||
* 统计数量(count)
|
||
*/
|
||
public function total($map)
|
||
{
|
||
$total = $this->where($map)->count();
|
||
return $total;
|
||
}
|
||
|
||
/**
|
||
* @param array $map
|
||
* @param string $up_field
|
||
* @param int $num
|
||
* @return bool
|
||
*/
|
||
public function toSetInc($map = array(), $up_field = '', $num = 1)
|
||
{
|
||
if (!$map || !$up_field) {
|
||
return false;
|
||
}
|
||
$up = $this->where($map)->setInc($up_field, $num);
|
||
return $up;
|
||
}
|
||
|
||
/**
|
||
* @param array $map
|
||
* @param string $up_field
|
||
* @param int $num
|
||
* @return bool
|
||
*/
|
||
public function toSetDec($map = array(), $up_field = '', $num = 1)
|
||
{
|
||
if (!$map || !$up_field) {
|
||
return false;
|
||
}
|
||
$up = $this->where($map)->setDec($up_field, $num);
|
||
return $up;
|
||
}
|
||
|
||
/**
|
||
* 删除记录
|
||
* @param $map
|
||
* @return mixed
|
||
*/
|
||
public function deleteOrder($map)
|
||
{
|
||
$res = $this->where($map)->delete();
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 查询根据某个字段排序的列表
|
||
* @param $map
|
||
* @param string $group_field
|
||
* @param string $field
|
||
* @return mixed
|
||
*/
|
||
public function toGroupSelect($map, $group_field, $field = '*')
|
||
{
|
||
$res = $this->field($field)->where($map)->group($group_field)->select();
|
||
return $res;
|
||
}
|
||
|
||
|
||
/**
|
||
* 更新
|
||
* @param $map
|
||
* @param $save
|
||
* @return mixed
|
||
*/
|
||
public function toSave($map, $save)
|
||
{
|
||
$res = $this->where($map)->save($save);
|
||
return $res;
|
||
}
|
||
} |