2019独角兽企业重金招聘Python工程师标准>>>
以下并不是插件原理,而是继承方法,首先确认需求,签到的话,我只需要保存 如下信息
用户模型设计
add ( $this->_amuppler, $params );
}
public function getUserByWhere($where) {
return $this->getOne ( $this->_amuppler, $where );
}
/**
* 返回时间
* Enter description here ...
* @param unknown_type $days
*/
public function getListByDays($days) {
$sql = "SELECT a.uid,a.add_time,b.username,b.real_name,b.face,b.area FROM $this->_amuppler a LEFT JOIN $this->_member_list b ON a.uid=b.uid WHERE a.days='$days'";
return $this->fetchAll ( $sql );
}
/**
*
* @return AmupperModel
*/
public static function instance() {
return parent::_instance ( __CLASS__ );
}
}
业务逻辑设计
checkToday ( $uid )) {
return "你已经签到过了哦!";
}
$rs = AmupperModel::instance ()->save ( array ('uid' => $uid, 'add_time' => time (), 'days' => date ( "Ymd", time () ) ) );
return $rs > 0 ? self::SUCCESS : self::ERROR;
}
/**
*
* @param int $day 1今天 2昨天
* @return Array
*/
public function getListByDays($day) {
switch ($day) {
case 1 :
$time = date ( "Ymd", time () );
break;
case 2 :
$time = date ( "Ymd", strtotime ( '-1 day' ) );
break;
default :
$time = date ( "Ymd", time () );
break;
}
return AmupperModel::instance ()->getListByDays ( $time );
}
/**
* 检查是否已经打过卡
* @return boolean true 没有 false 已经打过卡
*/
public function checkToday($uid) {
$rs = AmupperModel::instance ()->getUserByWhere ( array ('days' => date ( "Ymd", time () ), 'uid' => $uid ) );
return empty ( $rs );
}
}
控制器设计
addUser ( $this->_user_global ['uid'] );
if ($rs == self::SUCEESS) {
self::getLogService ()->add ( $this->_user_global ['username'], "签到成功" );
} else {
self::getLogService ()->add ( $this->_user_global ['username'], "签到失败$rs" );
}
$this->sendNotice ( $rs );
}
public function check() {
$rs = self::getAmupperService ()->checkToday ( $this->_user_global ['uid'] );
$message = ! $rs ? self::SUCEESS : self::ERROR;
$this->sendNotice ( $message );
}
/**
* 查看列表
* */
public function listing() {
$rs = self::getAmupperService ()->getListByDays ( $_GET ['days'] );
$this->view()->assign('user',$rs);
$this->view()->display("mysql:amupper.tpl");
}
public static function getAmupperService() {
return new AmupperService ();
}
public static function getLogService() {
return new LogService ();
}
}