User.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2025 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\admin\model\store;
  13. use app\common\model\store\User as StoreUserModel;
  14. /**
  15. * 商家用户模型
  16. * Class StoreUser
  17. * @package app\admin\model
  18. */
  19. class User extends StoreUserModel
  20. {
  21. // 隐藏的字段
  22. protected $hidden = ['password'];
  23. /**
  24. * 新增商家用户记录 (超级管理员)
  25. * @param int $storeId
  26. * @param array $data
  27. * @return bool|false
  28. */
  29. public function add(int $storeId, array $data): bool
  30. {
  31. return $this->save([
  32. 'user_name' => $data['user_name'],
  33. 'password' => encryption_hash($data['password']),
  34. 'is_super' => 1,
  35. 'store_id' => $storeId,
  36. ]);
  37. }
  38. /**
  39. * 更新商家用户记录 (超级管理员)
  40. * @param int $storeId
  41. * @param array $data
  42. * @return bool|false
  43. */
  44. public function edit(int $storeId, array $data): bool
  45. {
  46. $form = ['user_name' => $data['user_name']];
  47. !empty($data['password']) && $form['password'] = \encryption_hash($data['password']);
  48. return static::updateBase($form, [
  49. ['is_super', '=', 1],
  50. ['store_id', '=', $storeId]
  51. ]);
  52. }
  53. /**
  54. * 商家用户登录
  55. * @param int $storeId
  56. * @throws \cores\exception\BaseException
  57. * @throws \think\Exception
  58. */
  59. public function login(int $storeId)
  60. {
  61. // 获取该商户管理员用户信息
  62. $userInfo = $this->getSuperStoreUser($storeId);
  63. if (empty($userInfo)) {
  64. throwError('超级管理员用户信息不存在');
  65. }
  66. }
  67. /**
  68. * 获取该商户管理员用户信息
  69. * @param int $storeId
  70. * @return static|null
  71. */
  72. private function getSuperStoreUser(int $storeId): ?User
  73. {
  74. return static::detail(['store_id' => $storeId, 'is_super' => 1], ['wxapp']);
  75. }
  76. /**
  77. * 删除小程序下的商家用户
  78. * @param int $storeId
  79. * @return bool|false
  80. */
  81. public static function setDelete(int $storeId): bool
  82. {
  83. static::update(['is_delete' => '1'], ['store_id' => $storeId]);
  84. return true;
  85. }
  86. }