Blame view

addons/exam/model/UserInfoModel.php 1.01 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  <?php

  

  namespace addons\exam\model;

  

  use addons\exam\enum\UserType;

  

  class UserInfoModel extends \app\admin\model\exam\UserInfoModel

  {

  

      public function user()

      {

          return $this->belongsTo(UserModel::class, 'user_id');

      }

  

      /**

       * 初始化用户扩展信息

       * @param $user_id

       * @param $type

       * @return UserInfoModel

       */

      public static function initInfo($user_id, $type = UserType::NORMAL)

      {

          return self::create([

              'user_id'          => $user_id,

              'type'             => $type,

              'score'            => 0,

              'expire_time'      => 0,

              'member_config_id' => 0,

          ]);

      }

  

      /**

       * 获取用户扩展信息

       * @param $user_id

       * @return UserInfoModel

       */

      public static function getUserInfo($user_id)

      {

          if ($info = self::where('user_id', $user_id)->find()) {

              return $info;

          }

  

          return self::initInfo($user_id);

      }

  }