InviteNewUsersGiveGiftLogRepository.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. return $this->model->query()
  37. ->where('user_id',$user_id)
  38. ->pluck('invite_new_users_configs_id');
  39. }
  40. /**
  41. * 是否领取过礼物 checkExist
  42. *
  43. * @param $data
  44. * @return bool
  45. * @author Fx
  46. *
  47. */
  48. public function checkExist($data)
  49. {
  50. $is = $this->model->where($data)->first();
  51. if (empty($is)) {
  52. return false;
  53. } else {
  54. return true;
  55. }
  56. }
  57. public function logs($data){
  58. $logs = $this->model->query()->create($data);
  59. switch ($data['gift_type']){
  60. case $this->model::GIFT_TYPE_COUPON:
  61. $this->couponUserBagsRepository->inviteNewRewardCoupon($data['gift_id'],$data['user_id'],$data['gift_num']);
  62. break;
  63. case $this->model::GIFT_TYPE_CARD:
  64. $this->cardRidingUserBagsRepository->inviteNewRewardCard($data['gift_id'],$data['user_id']);
  65. break;
  66. case $this->model::GIFT_TYPE_BALANCE:
  67. $this->userRepository->inviteNewRewardBalance($data['gift_id'],$data['user_id'],$logs->id);
  68. break;
  69. default:
  70. return false;
  71. }
  72. return $logs;
  73. }
  74. }