UserRepository.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. * 管理员后台给用户增加的wdc
  49. * @param $user
  50. * $user 用户信息
  51. * @param $integral
  52. * $integral 增加的wdc
  53. */
  54. public static function adminAddwdc($user, $wdc)
  55. {
  56. }
  57. /**
  58. * 管理员后台给用户减少的积分
  59. * @param $user
  60. * $user 用户信息
  61. * @param $integral
  62. * $integral 减少的积分
  63. */
  64. public static function adminSubIntegral($user, $integral)
  65. {
  66. }
  67. /**
  68. * 获取授权信息
  69. * @param string $token
  70. * @return array
  71. * @throws AuthException
  72. * @throws DataNotFoundException
  73. * @throws DbException
  74. * @throws ModelNotFoundException
  75. */
  76. public static function parseToken($token): array
  77. {
  78. if (!$token || !$tokenData = UserToken::where('token', $token)->find())
  79. throw new AuthException('请登录', 410000);
  80. try {
  81. [$user, $type] = User::parseToken($token);
  82. } catch (\Throwable $e) {
  83. $tokenData->delete();
  84. throw new AuthException('登录已过期,请重新登录', 410001);
  85. }
  86. if (!$user || $user->uid != $tokenData->uid) {
  87. $tokenData->delete();
  88. throw new AuthException('登录状态有误,请重新登录', 410002);
  89. }
  90. $tokenData->type = $type;
  91. return compact('user', 'tokenData');
  92. }
  93. /**
  94. * 订单创建成功后
  95. * @param $order
  96. * @param $group
  97. */
  98. public static function storeProductOrderCreateEbApi($order,$group)
  99. {
  100. if(!UserAddress::be(['is_default'=>1,'uid'=>$order['uid']])) UserAddress::setDefaultAddress($group['addressId'],$order['uid']);
  101. }
  102. }