85 lines
2.3 KiB
PHP
85 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace common\modules\sign\vo;
|
|
|
|
use common\modules\sign\SignUtil;
|
|
use yii\behaviors\TimestampBehavior;
|
|
use yii\db\ActiveRecord;
|
|
|
|
/**
|
|
*
|
|
CREATE TABLE `sign` (
|
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
`user_id` int(11) NOT NULL,
|
|
`sign_time` int(11) NOT NULL COMMENT '签到时间',
|
|
`is_remedy` int(11) NOT NULL COMMENT '是否为补签',
|
|
`week` varchar(45) NOT NULL COMMENT '周一时间,标记每周',
|
|
`day` varchar(45) NOT NULL COMMENT '日时间,标记每日',
|
|
`created_at` int(11) DEFAULT NULL,
|
|
`updated_at` int(11) DEFAULT NULL,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `un` (`day`,`user_id`),
|
|
KEY `user_id` (`user_id`),
|
|
KEY `sign_time` (`sign_time`),
|
|
KEY `week` (`week`),
|
|
KEY `day` (`day`)
|
|
) ENGINE=InnoDB AUTO_INCREMENT=41 DEFAULT CHARSET=utf8 COMMENT='签到'
|
|
*/
|
|
|
|
/**
|
|
* 签到
|
|
* @property int $id
|
|
* @property int $user_id
|
|
* @property int $sign_time //签到时间
|
|
* @property int $is_remedy //是否为补签
|
|
* @property string $week //周一时间,标记每周
|
|
* @property string $day //日时间,标记每日
|
|
* @property int $created_at
|
|
* @property int $updated_at
|
|
*/
|
|
class Sign extends ActiveRecord
|
|
{
|
|
|
|
public function behaviors()
|
|
{
|
|
return [
|
|
TimestampBehavior::className(),
|
|
];
|
|
}
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
['id', 'default', 'value' => 0],
|
|
|
|
['user_id', 'required'],
|
|
['user_id', 'exist', 'targetClass' => '\common\models\User', 'targetAttribute' => 'id'],
|
|
|
|
['sign_time', 'default', 'value' => 0],
|
|
|
|
['is_remedy', 'default', 'value' => SignUtil::NOT_REMEDY],
|
|
['is_remedy', 'in', 'range' => SignUtil::REMEDY_LIST],
|
|
|
|
['week', 'default', 'value' => ''],
|
|
['day', 'default', 'value' => ''],
|
|
|
|
['created_at', 'default', 'value' => 0],
|
|
['updated_at', 'default', 'value' => 0],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param $userID
|
|
* @return static[]
|
|
*/
|
|
public static function findAllByUserIDAndWeek($userID, $week, $sort = SORT_ASC)
|
|
{
|
|
return self::find()->andWhere(['user_id' => $userID, 'week' => $week])->orderBy(['sign_time' => $sort])->all();
|
|
}
|
|
|
|
public static function findByUserIDAndDay($userID, $day)
|
|
{
|
|
return self::findAll(['user_id' => $userID, 'day' => $day]);
|
|
}
|
|
}
|