UserRepository.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace crmeb\repositories;
  3. use app\admin\model\system\SystemAttachment;
  4. use app\models\user\User;
  5. use app\models\user\UserAddress;
  6. use app\models\user\UserToken;
  7. use crmeb\exceptions\AuthException;
  8. use think\db\exception\ModelNotFoundException;
  9. use think\db\exception\DataNotFoundException;
  10. use think\exception\DbException;
  11. /**
  12. * Class UserRepository
  13. * @package crmeb\repositories
  14. */
  15. class UserRepository
  16. {
  17. /**
  18. * 管理员后台给用户添加金额
  19. * @param $user
  20. * $user 用户信息
  21. * @param $money
  22. * $money 添加的金额
  23. */
  24. public static function adminAddMoney($user, $money)
  25. {
  26. }
  27. /**
  28. * 管理员后台给用户减少金额
  29. * @param $user
  30. * $user 用户信息
  31. * @param $money
  32. * $money 减少的金额
  33. */
  34. public static function adminSubMoney($user, $money)
  35. {
  36. }
  37. /**
  38. * 管理员后台给用户增加的积分
  39. * @param $user
  40. * $user 用户信息
  41. * @param $integral
  42. * $integral 增加的积分
  43. */
  44. public static function adminAddIntegral($user, $integral)
  45. {
  46. }
  47. /**
  48. * 管理员后台给用户减少的积分
  49. * @param $user
  50. * $user 用户信息
  51. * @param $integral
  52. * $integral 减少的积分
  53. */
  54. public static function adminSubIntegral($user, $integral)
  55. {
  56. }
  57. /**
  58. * 获取授权信息
  59. * @param string $token
  60. * @return array
  61. * @throws AuthException
  62. * @throws DataNotFoundException
  63. * @throws DbException
  64. * @throws ModelNotFoundException
  65. */
  66. public static function parseToken($token): array
  67. {
  68. if (!$token || !$tokenData = UserToken::where('token', $token)->find())
  69. throw new AuthException('请登录', 410000);
  70. try {
  71. [$user, $type] = User::parseToken($token);
  72. } catch (\Throwable $e) {
  73. $tokenData->delete();
  74. throw new AuthException('登录已过期,请重新登录', 410001);
  75. }
  76. if (!$user || $user->uid != $tokenData->uid) {
  77. $tokenData->delete();
  78. throw new AuthException('登录状态有误,请重新登录', 410002);
  79. }
  80. $tokenData->type = $type;
  81. return compact('user', 'tokenData');
  82. }
  83. /**
  84. * 订单创建成功后
  85. * @param $order
  86. * @param $group
  87. */
  88. public static function storeProductOrderCreateEbApi($order,$group)
  89. {
  90. if(!UserAddress::be(['is_default'=>1,'uid'=>$order['uid']])) UserAddress::setDefaultAddress($group['addressId'],$order['uid']);
  91. }
  92. }