User.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\common\model\store;
  13. use app\common\model\BaseModel;
  14. /**
  15. * 商家用户模型
  16. * Class User
  17. * @package app\common\model
  18. */
  19. class User extends BaseModel
  20. {
  21. // 定义表名
  22. protected $name = 'store_user';
  23. // 定义主键
  24. protected $pk = 'store_user_id';
  25. /**
  26. * 关联商家记录表
  27. * @return \think\model\relation\BelongsTo
  28. */
  29. public function store()
  30. {
  31. $module = self::getCalledModule();
  32. return $this->belongsTo("app\\{$module}\\model\\Store", 'store_id');
  33. }
  34. /**
  35. * 关联用户角色表表
  36. * @return \think\model\relation\BelongsToMany
  37. */
  38. public function role()
  39. {
  40. return $this->belongsToMany('Role', 'StoreUserRole');
  41. }
  42. /**
  43. * 验证用户名是否重复
  44. * @param string $userName
  45. * @return bool
  46. */
  47. public static function checkExist(string $userName)
  48. {
  49. return (bool)static::withoutGlobalScope()
  50. ->where('user_name', '=', $userName)
  51. ->where('is_delete', '=', 0)
  52. ->value('store_user_id');
  53. }
  54. /**
  55. * 商家用户详情
  56. * @param $where
  57. * @param array $with
  58. * @return array|static|null
  59. */
  60. public static function detail($where, array $with = [])
  61. {
  62. return static::get($where, $with);
  63. }
  64. }