User.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. $model = (new static)->with($with);
  63. if (is_array($where)) {
  64. return $model->where($where)->find();
  65. }
  66. return $model->find($where);
  67. }
  68. }