UserRepository.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. public function inviteNewRewardBalance($money, $user_id, $logs_id)
  35. {
  36. // 钱包记录
  37. WalletLog::log(WalletLog::OPERATE_TYPE_ADD, $money, $user_id,
  38. WalletLog::TYPE_ADD_INVITE_NEW_TO_WELLET, $this->model->register_area_id, $logs_id, InviteNewUsersGiveGiftLog::class);
  39. // 增加余额
  40. $wallet_money = $this->model->wallet_money;
  41. $wallet_money = bcadd($wallet_money, $money, 2);
  42. $this->model->update(['wallet_money' => $wallet_money]);
  43. }
  44. /**
  45. * 判断免押金卡是否到期 并更新 isDepositCardExpired
  46. *
  47. * @param $user_id
  48. * @return bool false 已过期 | true 正常
  49. * @author Fx
  50. *
  51. */
  52. public function isDepositCardExpired($user_id)
  53. {
  54. $user = $this->model->find($user_id);
  55. $deposit_expire_time = Carbon::parse($user->deposit_expire_time);
  56. if (Carbon::now()->gt($deposit_expire_time)) {
  57. //判断第一个日期是否比第二个日期大
  58. $user->is_deposit = User::DEPOSIT_NO;
  59. $user->deposit_type = User::DEPOSIT_TYPE_NO;
  60. $user->save();
  61. return false;
  62. }
  63. return true;
  64. }
  65. }