OrangeSiteReportRateService.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace App\Modules\OrangeSite\Services;
  3. use Illuminate\Support\Facades\DB;
  4. use Redis;
  5. class OrangeSiteReportRateService
  6. {
  7. public static function getCurrentChannelReportRate($channelId)
  8. {
  9. $record = DB::table('orange_site_recharge_report_records')
  10. ->where([
  11. ['channel_id', '=', $channelId],
  12. ['is_enabled', '=', 1]
  13. ])->orderBy('id', 'desc')
  14. ->first();
  15. if (!$record) {
  16. return 0;
  17. } else {
  18. if (!$record->rate_total_num) {
  19. return 0;
  20. }
  21. return min(1, round($record->rate_success_num / $record->rate_total_num, 4)) * 100;
  22. }
  23. }
  24. public static function increaseSuccessNum($channelId, $channelSettingRate)
  25. {
  26. $now = date('Y-m-d H:i:s');
  27. $exists = DB::table('orange_site_recharge_report_records')
  28. ->where([
  29. ['channel_id', '=', $channelId],
  30. ['is_enabled', '=', 1]
  31. ])->orderBy('id', 'desc')->first();
  32. if ($exists) {
  33. DB::table('orange_site_recharge_report_records')
  34. ->where([
  35. ['channel_id', '=', $channelId],
  36. ['is_enabled', '=', 1]
  37. ])->update([
  38. 'rate_total_num' => $exists->rate_total_num + 1,
  39. 'rate_success_num' => $exists->rate_success_num + 1,
  40. 'updated_at' => $now
  41. ]);
  42. } else {
  43. DB::table('orange_site_recharge_report_records')
  44. ->insert([
  45. 'channel_id' => $channelId,
  46. 'is_enabled' => 1,
  47. 'rate_total_num' => 1,
  48. 'rate_success_num' => 1,
  49. 'channel_setting_rate' => $channelSettingRate,
  50. 'created_at' => $now,
  51. 'updated_at' => $now
  52. ]);
  53. }
  54. }
  55. public static function increaseFailNum($channelId, $channelSettingRate)
  56. {
  57. $now = date('Y-m-d H:i:s');
  58. $exists = DB::table('orange_site_recharge_report_records')
  59. ->where([
  60. ['channel_id', '=', $channelId],
  61. ['is_enabled', '=', 1]
  62. ])->orderBy('id', 'desc')->first();
  63. if ($exists) {
  64. DB::table('orange_site_recharge_report_records')
  65. ->where([
  66. ['channel_id', '=', $channelId],
  67. ['is_enabled', '=', 1]
  68. ])->update([
  69. 'rate_total_num' => $exists->rate_total_num + 1,
  70. 'updated_at' => $now
  71. ]);
  72. } else {
  73. DB::table('orange_site_recharge_report_records')
  74. ->insert([
  75. 'channel_id' => $channelId,
  76. 'is_enabled' => 1,
  77. 'rate_total_num' => 1,
  78. 'rate_success_num' => 0,
  79. 'channel_setting_rate' => $channelSettingRate,
  80. 'created_at' => $now,
  81. 'updated_at' => $now,
  82. ]);
  83. }
  84. }
  85. /**
  86. * 获取站点当前的橙子建站的回传比例
  87. * @param $channelId
  88. * @return int
  89. */
  90. public static function getChannelSettingReportRate($channelId)
  91. {
  92. $rate = Redis::hget('channel:setting:' . $channelId, 'orange_site_report_rate');
  93. if (!$rate) {
  94. $rate = 100;
  95. }
  96. return (int)$rate;
  97. }
  98. }