User.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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\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. * 新增商家用户记录
  23. * @param int $storeId
  24. * @param array $data
  25. * @return bool|false
  26. */
  27. public function add(int $storeId, array $data): bool
  28. {
  29. return $this->save([
  30. 'user_name' => $data['user_name'],
  31. 'password' => encryption_hash($data['password']),
  32. 'is_super' => 1,
  33. 'store_id' => $storeId,
  34. ]);
  35. }
  36. /**
  37. * 商家用户登录
  38. * @param int $storeId
  39. * @throws \cores\exception\BaseException
  40. * @throws \think\Exception
  41. */
  42. public function login(int $storeId)
  43. {
  44. // 获取该商户管理员用户信息
  45. $userInfo = $this->getSuperStoreUser($storeId);
  46. if (empty($userInfo)) {
  47. throwError('超级管理员用户信息不存在');
  48. }
  49. }
  50. /**
  51. * 获取该商户管理员用户信息
  52. * @param int $storeId
  53. * @return static|null
  54. */
  55. private function getSuperStoreUser(int $storeId): ?User
  56. {
  57. return static::detail(['store_id' => $storeId, 'is_super' => 1], ['wxapp']);
  58. }
  59. /**
  60. * 删除小程序下的商家用户
  61. * @param int $storeId
  62. * @return bool|false
  63. */
  64. public static function setDelete(int $storeId): bool
  65. {
  66. static::update(['is_delete' => '1'], ['store_id' => $storeId]);
  67. return true;
  68. }
  69. }