123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace App\Modules\OrangeSite\Services;
- use Illuminate\Support\Facades\DB;
- use Redis;
- class OrangeSiteReportRateService
- {
- public static function getCurrentChannelReportRate($channelId)
- {
- $record = DB::table('orange_site_recharge_report_records')
- ->where([
- ['channel_id', '=', $channelId],
- ['is_enabled', '=', 1]
- ])->orderBy('id', 'desc')
- ->first();
- if (!$record) {
- return 0;
- } else {
- if (!$record->rate_total_num) {
- return 0;
- }
- return min(1, round($record->rate_success_num / $record->rate_total_num, 4)) * 100;
- }
- }
- public static function increaseSuccessNum($channelId, $channelSettingRate)
- {
- $now = date('Y-m-d H:i:s');
- $exists = DB::table('orange_site_recharge_report_records')
- ->where([
- ['channel_id', '=', $channelId],
- ['is_enabled', '=', 1]
- ])->orderBy('id', 'desc')->first();
- if ($exists) {
- DB::table('orange_site_recharge_report_records')
- ->where([
- ['channel_id', '=', $channelId],
- ['is_enabled', '=', 1]
- ])->update([
- 'rate_total_num' => $exists->rate_total_num + 1,
- 'rate_success_num' => $exists->rate_success_num + 1,
- 'updated_at' => $now
- ]);
- } else {
- DB::table('orange_site_recharge_report_records')
- ->insert([
- 'channel_id' => $channelId,
- 'is_enabled' => 1,
- 'rate_total_num' => 1,
- 'rate_success_num' => 1,
- 'channel_setting_rate' => $channelSettingRate,
- 'created_at' => $now,
- 'updated_at' => $now
- ]);
- }
- }
- public static function increaseFailNum($channelId, $channelSettingRate)
- {
- $now = date('Y-m-d H:i:s');
- $exists = DB::table('orange_site_recharge_report_records')
- ->where([
- ['channel_id', '=', $channelId],
- ['is_enabled', '=', 1]
- ])->orderBy('id', 'desc')->first();
- if ($exists) {
- DB::table('orange_site_recharge_report_records')
- ->where([
- ['channel_id', '=', $channelId],
- ['is_enabled', '=', 1]
- ])->update([
- 'rate_total_num' => $exists->rate_total_num + 1,
- 'updated_at' => $now
- ]);
- } else {
- DB::table('orange_site_recharge_report_records')
- ->insert([
- 'channel_id' => $channelId,
- 'is_enabled' => 1,
- 'rate_total_num' => 1,
- 'rate_success_num' => 0,
- 'channel_setting_rate' => $channelSettingRate,
- 'created_at' => $now,
- 'updated_at' => $now,
- ]);
- }
- }
- /**
- * 获取站点当前的橙子建站的回传比例
- * @param $channelId
- * @return int
- */
- public static function getChannelSettingReportRate($channelId)
- {
- $rate = Redis::hget('channel:setting:' . $channelId, 'orange_site_report_rate');
- if (!$rate) {
- $rate = 100;
- }
- return (int)$rate;
- }
- }
|