User.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\admin\model\store;
  3. use app\common\exception\BaseException;
  4. use app\common\model\store\User as StoreUserModel;
  5. /**
  6. * 商家用户模型
  7. * Class StoreUser
  8. * @package app\admin\model
  9. */
  10. class User extends StoreUserModel
  11. {
  12. /**
  13. * 新增商家用户记录
  14. * @param int $wxappId
  15. * @param array $data
  16. * @return bool|false|int
  17. */
  18. public function add($wxappId, $data)
  19. {
  20. return $this->save([
  21. 'user_name' => $data['user_name'],
  22. 'password' => yoshop_hash($data['password']),
  23. 'is_super' => 1,
  24. 'wxapp_id' => $wxappId,
  25. ]);
  26. }
  27. /**
  28. * 商家用户登录
  29. * @param int $wxappId
  30. * @throws \think\Exception
  31. * @throws \think\exception\DbException
  32. */
  33. public function login($wxappId)
  34. {
  35. // 获取获取商城超级管理员用户信息
  36. $user = $this->getSuperStoreUser($wxappId);
  37. if (empty($user)) {
  38. throw new BaseException(['msg' => '超级管理员用户信息不存在']);
  39. }
  40. $this->loginState($user);
  41. }
  42. /**
  43. * 获取获取商城超级管理员用户信息
  44. * @param $wxappId
  45. * @return User|null
  46. * @throws \think\exception\DbException
  47. */
  48. private function getSuperStoreUser($wxappId)
  49. {
  50. return static::detail(['wxapp_id' => $wxappId, 'is_super' => 1], ['wxapp']);
  51. }
  52. /**
  53. * 删除小程序下的商家用户
  54. * @param $wxappId
  55. * @return false|int
  56. */
  57. public function setDelete($wxappId)
  58. {
  59. return $this->save(['is_delete' => 1], ['wxapp_id' => $wxappId]);
  60. }
  61. }