UserRepository.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Mead
  5. * Date: 2019/8/6
  6. * Time: 9:16 PM
  7. */
  8. namespace App\Repositories;
  9. use App\Models\InviteNewUsersGiveGiftLog;
  10. use App\Models\User;
  11. use App\Models\WalletLog;
  12. use Carbon\Carbon;
  13. class UserRepository extends BaseRepository
  14. {
  15. public function __construct(User $user)
  16. {
  17. $this->model = $user;
  18. }
  19. public function getRandomUserInfo()
  20. {
  21. return [
  22. ];
  23. }
  24. /**
  25. * 获取用户状态
  26. * @param $user_id
  27. * @return mixed
  28. * User: Mead
  29. */
  30. public function byIdGetUserStatus($user_id)
  31. {
  32. return $this->model->where('id', $user_id)->first();
  33. }
  34. /**
  35. * 是否正常
  36. * @param $user_id
  37. * @return mixed
  38. * Author: Mead
  39. */
  40. public function byIdCheckStatusOk($user_id)
  41. {
  42. return $this->model->where('id', $user_id)->value('status');
  43. }
  44. public function inviteNewRewardBalance($money, $user_id, $logs_id)
  45. {
  46. // 钱包记录
  47. WalletLog::log(WalletLog::OPERATE_TYPE_ADD, $money, $user_id,
  48. WalletLog::TYPE_ADD_INVITE_NEW_TO_WELLET, $this->model->register_area_id, $logs_id, InviteNewUsersGiveGiftLog::class);
  49. // 增加余额
  50. $wallet_money = $this->model->wallet_money;
  51. $wallet_money = bcadd($wallet_money, $money, 2);
  52. $this->model->update(['wallet_money' => $wallet_money]);
  53. }
  54. /**
  55. * 判断免押金卡是否到期 并更新 isDepositCardExpired
  56. *
  57. * @param $user_id
  58. * @return bool false 已过期 | true 正常
  59. * @author Fx
  60. *
  61. */
  62. public function isDepositCardExpired($user_id)
  63. {
  64. $user = $this->model->find($user_id);
  65. $deposit_expire_time = Carbon::parse($user->deposit_expire_time);
  66. if (Carbon::now()->gt($deposit_expire_time)) {
  67. //判断第一个日期是否比第二个日期大
  68. $user->is_deposit = User::DEPOSIT_NO;
  69. $user->deposit_type = User::DEPOSIT_TYPE_NO;
  70. $user->save();
  71. return false;
  72. }
  73. return true;
  74. }
  75. }