FirstRechargeGifts.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Services;
  3. use App\Http\logic\api\BaseApiLogic;
  4. use App\Models\AccountsInfo;
  5. use App\Models\Order;
  6. use Illuminate\Support\Facades\DB;
  7. class FirstRechargeGifts extends BaseApiLogic
  8. {
  9. // 礼包类型
  10. public function buyGifts($GiftsID, $userId)
  11. {
  12. if (!empty($GiftsID)) {
  13. $Gifts = DB::connection('write')->table('QPAccountsDB.dbo.FirstRechargeGifts')->where('GiftsID', $GiftsID)->first();
  14. if (!$Gifts) {
  15. $this->error = '礼包类型错误';
  16. return false;
  17. }
  18. if ($Gifts->GiftsState != 1) {
  19. $this->error = '礼包关闭';
  20. return false;
  21. }
  22. // 判断首冲礼包类型
  23. if ($Gifts->TimeLimit > 0) { // 注册时间大于这段时间 不能购买
  24. $RegisterDate = DB::connection('write')->table('QPAccountsDB.dbo.AccountsInfo')->where('UserID', $userId)->select('RegisterDate')->first()->RegisterDate;
  25. if ((strtotime(date('Y-m-d H:i:s')) - strtotime($RegisterDate)) > $Gifts->TimeLimit) {
  26. $this->error = '超出有效购买日期';
  27. return false;
  28. }
  29. }
  30. if ($Gifts->CountLimit > 0) { // 每人数量限制
  31. $orderGifts = DB::connection('write')->table('agent.dbo.order')->where('GiftsID', $GiftsID)->where('user_id', $userId)->where('pay_status', 1)->count();
  32. if ($orderGifts >= $Gifts->CountLimit) {
  33. $this->error = '超出最大购买数量';
  34. return false;
  35. }
  36. }
  37. }
  38. return true;
  39. }
  40. }