User.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 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 cores\BaseModel;
  14. use think\model\relation\BelongsTo;
  15. use think\model\relation\BelongsToMany;
  16. /**
  17. * 商家用户模型
  18. * Class User
  19. * @package app\common\model
  20. */
  21. class User extends BaseModel
  22. {
  23. // 定义表名
  24. protected $name = 'store_user';
  25. // 定义主键
  26. protected $pk = 'store_user_id';
  27. /**
  28. * 关联商家记录表
  29. * @return BelongsTo
  30. */
  31. public function store(): BelongsTo
  32. {
  33. $module = self::getCalledModule();
  34. return $this->belongsTo("app\\{$module}\\model\\Store", 'store_id');
  35. }
  36. /**
  37. * 关联用户角色表表
  38. * @return BelongsToMany
  39. */
  40. public function role(): BelongsToMany
  41. {
  42. return $this->belongsToMany('Role', 'StoreUserRole');
  43. }
  44. /**
  45. * 验证用户名是否重复
  46. * @param string $userName
  47. * @return bool
  48. */
  49. public static function checkExist(string $userName): bool
  50. {
  51. return (bool)static::withoutGlobalScope()
  52. ->where('user_name', '=', $userName)
  53. ->where('is_delete', '=', 0)
  54. ->value('store_user_id');
  55. }
  56. /**
  57. * 商家用户详情
  58. * @param $where
  59. * @param array $with
  60. * @return static|array|null
  61. */
  62. public static function detail($where, array $with = [])
  63. {
  64. return static::get($where, $with);
  65. }
  66. }