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; } }