You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
4.0 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: huajie <banhuajie@163.com>
// +----------------------------------------------------------------------
namespace Admin\Model;
use Think\Model;
/**
* 福利广告模型
* @author 鹿文学
*/
class BoonModel extends Model{
/* 自动验证规则 */
protected $_validate = array(
array('title', '1,30', '广告标题不能超过30个字符', self::VALUE_VALIDATE, 'length', self::MODEL_BOTH),
array('reward','require','奖励积分不能为空',self::MUST_VALIDATE,'regex',self::MODEL_BOTH),
array('reward','/^[1-9]\d*$/','奖励积分为大于1的数字',self::EXISTS_VALIDATE,'regex',self::MODEL_BOTH),
array('show','require','展示时间不能为空',self::MUST_VALIDATE,'regex',self::MODEL_BOTH),
array('show','isZero','展示时间应大于0秒',self::VALUE_VALIDATE, 'callback', self::MODEL_BOTH),
array('show','/^([1-9](\.\d)?|10)$/','展示时间应不大于10秒',self::VALUE_VALIDATE, 'regex', self::MODEL_BOTH),
array('cover', 'require', '封面图不能为空', self::MUST_VALIDATE, 'regex', self::MODEL_BOTH),
array('cover','/^[1-9]\d*$/','封面图不能为空',self::EXISTS_VALIDATE,'regex',self::MODEL_BOTH),
/* array('material_url','require','素材不能为空',self::MUST_VALIDATE,'regex',self::MODEL_BOTH), */
);
/* 自动完成规则 */
protected $_auto = array(
array('create_time', 'getCreateTime', self::MODEL_BOTH,'callback'),
array('start_time', 'getStartTime', self::MODEL_BOTH, 'callback'),
array('end_time', 'getEndTime', self::MODEL_BOTH, 'callback'),
);
/**
* 构造函数
* @param string $name 模型名称
* @param string $tablePrefix 表前缀
* @param mixed $connection 数据库连接信息
*/
public function __construct($name = '', $tablePrefix = '', $connection = '') {
/* 设置默认的表前缀 */
$this->tablePrefix ='tab_';
/* 执行构造方法 */
parent::__construct($name, $tablePrefix, $connection);
}
/**
* 创建时间不写则取当前时间
* @return int 时间戳
* @author huajie <banhuajie@163.com>
*/
protected function getCreateTime(){
$create_time = I('post.create_time');
return $create_time?strtotime($create_time):NOW_TIME;
}
protected function getStartTime(){
$start_time = I('post.start_time');
return $start_time?strtotime($start_time):'';
}
protected function getEndTime(){
$end_time = I('post.end_time');
return $end_time?strtotime($end_time):'';
}
protected function isZero() {
$show = intval(I('post.show',0));
return $show>0?true:false;
}
/**
* 新增或更新一个游戏
* @param array $data 手动传入的数据
* @return boolean fasle 失败 int 成功 返回完整的数据
* @author 王贺
*/
public function update($data = null){
/* 获取数据对象 */
$data = $this->token(false)->create($data);
if(empty($data)){
return false;
}
/* 添加或新增基础内容 */
if(empty($data['id'])){ //新增数据
$id = $this->add($data); //添加基础内容
if(!$id){
$this->error = '新增基础内容出错!';
return false;
}
} else { //更新数据
$status = $this->save(); //更新基础内容
if(false === $status){
$this->error = '更新基础内容出错!';
return false;
}
}
return $data;
}
}