InviteNewUsersGiveGiftLogRepository.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. *
  4. *
  5. * @category xxx
  6. * @package PSR
  7. * @subpackage Documentation\API
  8. * @author xxx <xxx@xxx.com>
  9. * @license GPL https://xxx.com
  10. * @link https://xxx.com
  11. * @ctime: 2020/4/15 14:26
  12. */
  13. namespace App\Repositories;
  14. use App\Models\InviteNewUsersGiveGiftLog;
  15. class InviteNewUsersGiveGiftLogRepository extends BaseRepository
  16. {
  17. public $cardRidingUserBagsRepository;
  18. public $couponUserBagsRepository;
  19. public $userRepository;
  20. public function __construct(InviteNewUsersGiveGiftLog $inviteNewUsersGiveGiftLog, CardRidingUserBagsRepository $cardRidingUserBagsRepository, CouponUserBagsRepository $couponUserBagsRepository, UserRepository $userRepository)
  21. {
  22. $this->model = $inviteNewUsersGiveGiftLog;
  23. $this->cardRidingUserBagsRepository = $cardRidingUserBagsRepository;
  24. $this->couponUserBagsRepository = $couponUserBagsRepository;
  25. $this->userRepository = $userRepository;
  26. }
  27. /**
  28. * 获取得过奖励的id getRewardsByUserId
  29. *
  30. * @param $user_id
  31. * @return \Illuminate\Support\Collection
  32. * @author Fx
  33. *
  34. */
  35. public function getRewardsByUserId($user_id)
  36. {
  37. return $this->model->query()
  38. ->where('user_id', $user_id)
  39. ->pluck('invite_new_users_configs_id');
  40. }
  41. /**
  42. * 是否领取过礼物 checkExist
  43. *
  44. * @param $data
  45. * @return bool
  46. * @author Fx
  47. *
  48. */
  49. public function checkExist($data)
  50. {
  51. $is = $this->model->where($data)->first();
  52. if (empty($is)) {
  53. return false;
  54. } else {
  55. return true;
  56. }
  57. }
  58. public function logs($data)
  59. {
  60. $logs = $this->model->query()->create($data);
  61. switch ($data['gift_type']) {
  62. case $this->model::GIFT_TYPE_COUPON:
  63. $this->couponUserBagsRepository->inviteNewRewardCoupon($data['gift_id'], $data['user_id'], $data['gift_num']);
  64. break;
  65. case $this->model::GIFT_TYPE_CARD:
  66. $this->cardRidingUserBagsRepository->inviteNewRewardCard($data['gift_id'], $data['user_id']);
  67. break;
  68. case $this->model::GIFT_TYPE_BALANCE:
  69. $this->userRepository->inviteNewRewardBalance($data['gift_id'], $data['user_id'], $logs->id);
  70. break;
  71. default:
  72. return false;
  73. }
  74. return $logs;
  75. }
  76. }