OrangeSitePromotionService.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace App\Modules\OrangeSite\Services;
  3. use Illuminate\Support\Facades\DB;
  4. class OrangeSitePromotionService
  5. {
  6. public static function getCurrentPromotionProtectNum($channelId, $promotionId)
  7. {
  8. return DB::table('orange_site_recharge_report_protect_records')
  9. ->where([
  10. ['channel_id', '=', $channelId],
  11. ['use_type', '=', 'promotionId'],
  12. ['use_type_id', '=', $promotionId],
  13. ['is_enabled', '=', 1]
  14. ])->orderBy('id', 'desc')
  15. ->first()->current_protect_num ?? 0;
  16. }
  17. public static function setCurrentPromotionProtectNum($channelId, $promotionId, $maxNum)
  18. {
  19. $now = date('Y-m-d H:i:s');
  20. $exists = DB::table('orange_site_recharge_report_protect_records')
  21. ->where([
  22. 'channel_id' => $channelId,
  23. 'use_type' => 'promotionId',
  24. 'use_type_id' => $promotionId,
  25. 'is_enabled' => 1
  26. ])->exists();
  27. if ($exists) {
  28. DB::table('orange_site_recharge_report_protect_records')
  29. ->where([
  30. 'channel_id' => $channelId,
  31. 'use_type' => 'promotionId',
  32. 'use_type_id' => $promotionId,
  33. 'is_enabled' => 1,
  34. ])->where('current_protect_num', '<', $maxNum)
  35. ->increment('current_protect_num', 1, ['updated_at' => $now]);
  36. } else {
  37. DB::table('orange_site_recharge_report_protect_records')
  38. ->insert([
  39. 'channel_id' => $channelId,
  40. 'use_type' => 'promotionId',
  41. 'use_type_id' => $promotionId,
  42. 'is_enabled' => 1,
  43. 'current_protect_num' => 1,
  44. 'created_at' => $now,
  45. 'updated_at' => $now,
  46. ]);
  47. }
  48. }
  49. /**
  50. * 获取用户匹配信息
  51. * @param $uid
  52. * @return mixed
  53. */
  54. public static function getUserBindInfo($uid)
  55. {
  56. return DB::table('report_user_bind_records')
  57. ->where(['uid' => $uid])
  58. ->select('platform', 'uid', 'promotion_id')
  59. ->first();
  60. }
  61. /**
  62. * 判断是否有用户匹配track , true-无用户匹配,false-有用户匹配
  63. * @param $userBindRecord
  64. * @return bool
  65. */
  66. public static function judgeNoUserMatch($userBindRecord)
  67. {
  68. if (!$userBindRecord) {
  69. return true;
  70. }
  71. if ('no_track' == $userBindRecord->platform) {
  72. return true;
  73. }
  74. if ('orange' != $userBindRecord->platform) {
  75. return true;
  76. }
  77. return false;
  78. }
  79. }