123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- /**
- *
- *
- * @category xxx
- * @package PSR
- * @subpackage Documentation\API
- * @author xxx <xxx@xxx.com>
- * @license GPL https://xxx.com
- * @link https://xxx.com
- * @ctime: 2020/4/15 14:26
- */
- namespace App\Repositories;
- use App\Models\InviteNewUsersGiveGiftLog;
- class InviteNewUsersGiveGiftLogRepository extends BaseRepository
- {
- public $cardRidingUserBagsRepository;
- public $couponUserBagsRepository;
- public $userRepository;
- public function __construct(InviteNewUsersGiveGiftLog $inviteNewUsersGiveGiftLog, CardRidingUserBagsRepository $cardRidingUserBagsRepository, CouponUserBagsRepository $couponUserBagsRepository, UserRepository $userRepository)
- {
- $this->model = $inviteNewUsersGiveGiftLog;
- $this->cardRidingUserBagsRepository = $cardRidingUserBagsRepository;
- $this->couponUserBagsRepository = $couponUserBagsRepository;
- $this->userRepository = $userRepository;
- }
- /**
- * 获取得过奖励的id getRewardsByUserId
- *
- * @param $user_id
- * @return \Illuminate\Support\Collection
- * @author Fx
- *
- */
- public function getRewardsByUserId($user_id)
- {
- return $this->model->query()
- ->where('user_id', $user_id)
- ->pluck('invite_new_users_configs_id');
- }
- /**
- * 是否领取过礼物 checkExist
- *
- * @param $data
- * @return bool
- * @author Fx
- *
- */
- public function checkExist($data)
- {
- $is = $this->model->where($data)->first();
- if (empty($is)) {
- return false;
- } else {
- return true;
- }
- }
- public function logs($data)
- {
- $logs = $this->model->query()->create($data);
- switch ($data['gift_type']) {
- case $this->model::GIFT_TYPE_COUPON:
- $this->couponUserBagsRepository->inviteNewRewardCoupon($data['gift_id'], $data['user_id'], $data['gift_num']);
- break;
- case $this->model::GIFT_TYPE_CARD:
- $this->cardRidingUserBagsRepository->inviteNewRewardCard($data['gift_id'], $data['user_id']);
- break;
- case $this->model::GIFT_TYPE_BALANCE:
- $this->userRepository->inviteNewRewardBalance($data['gift_id'], $data['user_id'], $logs->id);
- break;
- default:
- return false;
- }
- return $logs;
- }
- }
|