TrainApplyModel.class.php 2.8 KB
<?php
/**
 * Created by PhpStorm.
 * User: 29925
 * Date: 2018/3/14
 * Time: 8:53
 */

namespace Common\Model;

use Common\Model\CommonModel;

class TrainApplyModel extends CommonModel {

    // 自动验证
    protected $_validate = array(
        //array(验证字段,验证规则,错误提示,验证条件,附加规则,验证时间)
        array('tid', 'number', '体验培训ID不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('user_id', 'number', '用户ID不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('name', 'require', '报名人不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('province', 'require', '所在省不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('city', 'require', '城市不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('birth', 'require', '出生年月不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('sex', array(0,1,2), '性别格式错误', 1, 'in', CommonModel::MODEL_BOTH),
        array('mobile', 'require', '手机号码不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('mobile', 'mobile', '手机号码格式错误', 1, 'regex', CommonModel::MODEL_BOTH),
        array('email', 'require', '邮箱不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('email', 'email', '邮箱格式错误', 1, 'regex', CommonModel::MODEL_BOTH),
        array('lesson', 'require', '培训课程描述不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('experience', 'require', '体验方式描述不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('travel', 'require', '旅行方式描述不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
    );

    // 获取体验培训报名列表
    public function getList($page_num, $keyword = null, $start_time = null, $end_time = null) {
        $perPage = 25;
        $where['is_del'] = 0;
        if($keyword) {
            $where['name'] = array('like', '%'.$keyword.'%');
        }
        if($start_time && $end_time) {
            $where['ctime'] = array('between', array($start_time,$end_time));
        }
        return $this->where($where)->select();
    }

    // 获取体验培训报名详情
    public function getInfo($id) {
        $where['is_del'] = 0;
        $where['id'] = $id;
        return $this->where($where)->find();
    }

    /**
     * 获取数据总数
     * @author Liuzhen
     */
    public function getCount($keyword = null, $start_time = null, $end_time = null) {
        $where['is_del'] = 0;
        if($keyword) {
            $where['name'] = array('like', '%'.$keyword.'%');
        }
        if($start_time && $end_time) {
            $where['ctime'] = array('between', array($start_time,$end_time));
        }
        $count = $this->where($where)
            ->count();
        return $count;
    }
}