uid = $uid; $this->amount = $amount; $this->time = $time; } /** * Execute the job. * * @return void */ public function handle() { $client = new Client(); if(empty($this->time)){ \Log::info('origin_params:'.$this->time); $this->time = date('Y-m-d H:i:s'); } $params = [ 'uid' => $this->uid, 'amount' => $this->amount, 'time' => $this->time, 'source' => 'wdy' ]; \Log::info('TikTokUserCharge:'.json_encode($params)); // if( date('Y-m-d',strtotime( $this->time )) != date('Y-m-d')){ // return ; // } $user = User::find($this->uid); $order = Order::where('uid', $this->uid)->where('status', 'PAID')->orderBy('id', 'desc')->first(); $current_day_register = date('Y-m-d', strtotime($order->created_at)) == date('Y-m-d', strtotime($user->created_at)); if ($order && $current_day_register && $order->price >= 30) { if(!$this->reportRate($user->distribution_channel_id)){ return ; } $count = Order::where('uid', $this->uid)->where('status', 'PAID')->where('price', '>=', '30')->count(); if ($count == 1) { } else { return; } } else { return; } $params['sign'] = _sign($params, SysConsts::TIKTOK_KEY); $url = 'https://newtrackapi.zhuishuyun.com/api/user/tiktokUserChargePush'; $response = $client->request('post', $url, ['form_params' => $params])->getBody()->getContents(); myLog('tiktok_push_charge')->info($response); $result = json_decode($response); if ($result) { if ($result->code != 0) { myLog('tiktok_push_charge')->info($response); } } } private function reportRate($channel_id){ //OceanengineRechargeRecord:: $rate = Redis::hget('channel:setting:'.$channel_id,'orange_site_report_rate'); $rate = (int)$rate; if(!$rate || $rate == 100){ return true; } $config = OceanengineReportRateConfig::where('channel_id',$channel_id)->first(); if(!$config){ OceanengineReportRateConfig::create(['channel_id'=>$channel_id,'report_rate'=>$rate,'report_num'=>1,'report_success_num'=>1]); return true; }else{ if($config->report_rate == $rate){ $now_report_num = $config->report_num+1; $now_rate = round($config->report_success_num/$now_report_num,4)*100; if($now_rate <= $rate){ $config->report_num = $config->report_num+1; $config->report_success_num = $config->report_success_num+1; $config->save(); return true; } $config->report_num = $config->report_num+1; $config->save(); return false; }else{ $config->report_rate = $rate; $config->report_num = 1; $config->report_success_num = 1; $config->save(); return true; } } } }