129 行
3.6 KiB
PHP
可执行文件
129 行
3.6 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Common\Model;
|
||
|
||
use Think\Model;
|
||
//[1.3.13]
|
||
class VipCardRecordModel extends Model
|
||
{
|
||
protected $tableName = 'retail_vip_card_record';
|
||
protected $fields = array(
|
||
'id', // `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||
'merchantid', // `merchantid` int(10) DEFAULT '0' COMMENT '商户id',
|
||
'vip_id', // `vip_id` int(10) DEFAULT NULL COMMENT '会员id',
|
||
'vip_card_id', // `vip_card_id` int(10) DEFAULT NULL COMMENT '会员次卡id',
|
||
'addtime', // `addtime` varchar(20) DEFAULT NULL COMMENT '添加时间',
|
||
'use_store_id',
|
||
'cashier_id'
|
||
);
|
||
|
||
/**
|
||
* 添加(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)
|
||
{
|
||
if(!$map){
|
||
return 0;
|
||
}
|
||
$total = $this->where($map)->count();
|
||
return $total;
|
||
}
|
||
|
||
/**
|
||
* 删除记录
|
||
* @param $map
|
||
* @return mixed
|
||
*/
|
||
public function deleteOrder($map)
|
||
{
|
||
$res = $this->where($map)->delete();
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 三表联查 核销记录表 次卡表 会员表
|
||
* @param $map array 条件
|
||
* @param $field array|string 字段
|
||
* @param $page int 分页
|
||
* @param $limit int 数量
|
||
* @param $order string 排序
|
||
* @return array
|
||
*/
|
||
public function selectVipCardRecord($map,$field='*',$page=1,$limit=10,$order='vcr.addtime desc')
|
||
{
|
||
$data = $this->alias('vcr')
|
||
->join('ls_retail_vip_card as vc on vc.id=vcr.vip_card_id')
|
||
->join('ls_retail_vip as v on v.id=vcr.vip_id')
|
||
->field($field)
|
||
->where($map)
|
||
->page(intval($page),intval($limit))
|
||
->order($order)
|
||
->select();
|
||
return $data;
|
||
}
|
||
|
||
/**
|
||
* 三表统计 核销记录表 次卡表 会员表
|
||
* @param $map array 条件
|
||
* @return int
|
||
*/
|
||
public function totalVipCardRecord($map)
|
||
{
|
||
$total= $this->alias('vcr')
|
||
->join('ls_retail_vip_card as vc on vc.id=vcr.vip_card_id')
|
||
->join('ls_retail_vip as v on v.id=vcr.vip_id')
|
||
->where($map)
|
||
->count();
|
||
return $total;
|
||
}
|
||
} |