| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace app\admin\model;
- use app\BaseModel;
- class Admin extends BaseModel
- {
-
- protected $autoWriteTimestamp = true;
- protected $createTime = 'created_at';
- protected $updateTime = 'updated_at';
- public function role()
- {
- return $this->hasOne(Role::class, 'id', 'role_id')->field(['id', 'name']);
- }
- public function department()
- {
- return $this->hasOne(Department::class, 'id', 'department_id')->field(['id', 'name']);
- }
- public static function inOnline($id)
- {
- return self::where('id', $id)->value('is_online');
- }
- public static function setOnline($id, $is_online)
- {
- if ($is_online == 0) {
- //结束今日的签到
- $sign = Sign::where('admin_id', $id)->where('created_at', '>=', date('Y-m-d'))->order('id', 'desc')->find();
- if ($sign && $sign->time == 0) {
- $sign->time = time() - strtotime($sign->created_at);
- $sign->updated_at = date('Y-m-d H:i:s');
- $sign->save();
- }
- }
- return self::where('id', $id)->update(['is_online' => $is_online]);
- }
- }
|