202 行
7.6 KiB
PHP
可执行文件
202 行
7.6 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Common\Model;
|
||
|
||
use Think\Model;
|
||
|
||
//[1.8.20]
|
||
class SubCardModel extends BaseModel
|
||
{
|
||
protected $tableName = 'retail_sub_card';
|
||
const ID = 'id'; //int(11) NOT NULL AUTO_INCREMENT,
|
||
const MERCHANT_ID = 'merchantid'; //`merchantid` int(10) DEFAULT '0' COMMENT '商户id',
|
||
const NAME = 'name'; //`name` varchar(255) DEFAULT NULL COMMENT '次卡标题',
|
||
const STOCK = 'stock'; // `stock` int(10) DEFAULT '0' COMMENT '库存',
|
||
const SUR_PLUS = 'surplus'; // `surplus` int(10) DEFAULT '0' COMMENT '剩余数量',
|
||
const USE_TYPE = 'use_type'; // `use_type` tinyint(1) DEFAULT '1' COMMENT '使用类型 1.每天一次 2.自定义 3.几天使用一次',
|
||
const FREQUENCY = 'frequency'; // `frequency` int(10) DEFAULT '0' COMMENT '自定义次数',
|
||
const LIMIT = 'limit'; // `limit` tinyint(255) DEFAULT '0' COMMENT '每天使用次数/几天可以使用一次 ',
|
||
const TIME_INTERVAL = 'time_interval'; // `time_interval` varchar(255) DEFAULT '00:00:00-23:59:59' COMMENT '使用时段',
|
||
const TYPE = 'type'; // `type` tinyint(1) DEFAULT '1' COMMENT '次卡类型 1.自主发放2.充值赠送3.消费赠送3.购买使用',
|
||
const MONEY = 'money'; // `money` decimal(10,2) DEFAULT '0.00' COMMENT '充值、消费需达到的金额',
|
||
const GIVE_NUM = 'give_num'; // `give_num` int(10) DEFAULT '1' COMMENT '充值、消费赠送次数',
|
||
const GRADE_IDS = 'gradeids'; // `gradeids` varchar(255) DEFAULT '0' COMMENT '指定会员等级, '','' 拼接 0为不限制等级',
|
||
const VIP_TYPE = 'vip_type'; // `vip_type` tinyint(1) DEFAULT '1' COMMENT '允许购买类型 1.所有类型会员 2.plus会员',
|
||
const STORE_IDS = 'storeids'; // `storeids` varchar(255) DEFAULT '0' COMMENT '指定门店 , '','' 拼接 0为不限制门店',
|
||
const END_TIME = 'end_time'; // `end_time` varchar(20) DEFAULT '' COMMENT '有效时间(止)',
|
||
const INTRODUCE = 'introduce'; // `introduce` text COMMENT '使用介绍',
|
||
const ADD_TIME = 'addtime'; // `addtime` varchar(20) DEFAULT '' COMMENT '添加时间',
|
||
const STATUS = 'status'; // `status` tinyint(1) DEFAULT '0' COMMENT '状态 0.正常 1.失效',
|
||
const CARD_TYPE = 'card_type'; // `card_type` tinyint(1) DEFAULT '1' COMMENT '次卡类型 1.普通次卡 2.卡包次卡',
|
||
const BAG_ID = 'bag_id'; // `bag_id` int(10) DEFAULT '0' COMMENT '卡包id',
|
||
const IMAGE = 'image'; // `image` varchar(255) DEFAULT '' COMMENT '图片url',
|
||
const GALLERY_ID = 'gallery_id'; // `gallery_id` int(10) DEFAULT '0' COMMENT '图库对应id',
|
||
const EFFECTIVE_START = 'effective_start'; // `effective_start` varchar(20) DEFAULT '' COMMENT '有效时间(开始)',
|
||
const EFFECTIVE_END = 'effective_end'; // `effective_end` varchar(20) DEFAULT '' COMMENT '有效时间(结束)',
|
||
const CARD_NAME_COLOR = 'card_name_color'; // `card_name_color` varchar(10) DEFAULT '#FFFFFF' COMMENT '卡面名称颜色',
|
||
const BTN_BACKGROUND = 'btn_background'; // `btn_background` varchar(10) DEFAULT '#ffd100' COMMENT '按钮背景颜色',
|
||
const BTN_TEXT_COLOR = 'btn_text_color'; // `btn_text_color` varchar(10) DEFAULT '#333333' COMMENT '按钮文字颜色',
|
||
const LINE_STATE = 'line_state'; // tinyint(1) DEFAULT '1' COMMENT '线下状态 1.开启 0.关闭 (充值 消费 购买 消费指定商品)',
|
||
const ONLINE_STATE = 'online_state'; // tinyint(1) DEFAULT '1' COMMENT '线上状态 1.开启 0.关闭 充值 消费 购买 消费指定商品',
|
||
const EFFECTIVE_TIME_TYPE = 'effective_time_type'; // `effective_time_type` tinyint(1) DEFAULT '1' COMMENT '有效期类型:1固定时间 2领卡当日生效 3领卡次日生效',
|
||
const EFFECTIVE_DAY = 'effective_day'; // `effective_day` tinyint(10) 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 $map
|
||
* @param $up
|
||
* @return bool
|
||
*/
|
||
public function toSave($map, $up)
|
||
{
|
||
if (!$map || !$up) {
|
||
return false;
|
||
}
|
||
$save = $this->where($map)->save($up);
|
||
return $save;
|
||
}
|
||
|
||
/**
|
||
* @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)
|
||
* @param [array] $map 条件
|
||
* @return [int] $total
|
||
*/
|
||
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;
|
||
}
|
||
|
||
/**
|
||
* 查询某个字段(getField)
|
||
* @param array $map 条件
|
||
* @param string $field 字段
|
||
* @param bool $bol
|
||
* @return array|bool
|
||
*/
|
||
public function toFindField($map, $field = 'id', $bol = false)
|
||
{
|
||
if (!$map) {
|
||
return false;
|
||
}
|
||
$findField = $this->where($map)->getField($field, $bol);
|
||
return $findField;
|
||
}
|
||
|
||
/**
|
||
* 获取某字段
|
||
* @param $map
|
||
* @param string $fields
|
||
* @param $bol //true为获取多条
|
||
* @return mixed
|
||
*/
|
||
public function getFindField($map, $fields = 'id', $bol = false)
|
||
{
|
||
$res = $this->where($map)->getField($fields, $bol);
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 删除记录
|
||
* @param $map
|
||
* @return mixed
|
||
*/
|
||
public function deleteOrder($map)
|
||
{
|
||
$res = $this->where($map)->delete();
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 多条查询,限制数量(select)
|
||
* @param [array] $map 查询条件
|
||
* @param [int] $limit 数量
|
||
* @param [int] $order 排序
|
||
* @return array
|
||
*/
|
||
public function toSelectLimit($map, $limit = 10, $field = '*', $order = 'addtime desc')
|
||
{
|
||
|
||
$select = $this->field($field)->where($map)->limit($limit)->order($order)->select();
|
||
return $select;
|
||
}
|
||
} |