syncOdds(); } public function syncOdds() { /** @var AlStatService $alStatService */ $alStatService = app(AlStatService::class); $odds = $alStatService->getZqGuanYa(); if (!$odds) { return; } foreach ($odds as $item) { $id = $item['id']; $odd = JczqGuanYa::where('guan_ya_id', $id)->first(); if (!$odd) { $odd = new JczqGuanYa(); } $options = Arr::get($item, 'options'); $odd->guan_ya_id = $id; $odd->competition = intval(Arr::get($item, 'competition')); $odd->competition_name = strval(Arr::get($item, 'competitionName')); $odd->season = strval(Arr::get($item, 'season')); $odd->type = strval(Arr::get($item, 'type')); $odd->sales_state = strval(Arr::get($item, 'salesState')); $odd->lott_state = strval(Arr::get($item, 'lottState')); $odd->close_time = strval(Arr::get($item, 'closeTime')); $odd->options = $options; $odd->save(); $this->saveGuanOdds($odd->id, $options); } } protected function saveGuanOdds($jczqGuanYaId, $options) { if (!is_array($options)) { return; } foreach ($options as $item) { $id = $item['id']; $odd = JczqGuanYaOdds::where('odds_id', $id)->where('jczq_guan_ya_id', $jczqGuanYaId)->first(); if (!$odd) { $odd = new JczqGuanYaOdds(); } $odd->jczq_guan_ya_id = $jczqGuanYaId; $odd->odds_id = $id; $odd->team_a_id = intval(Arr::get($item, 'teamAId')); $odd->team_a_name = strval(Arr::get($item, 'teamAName')); $odd->team_b_id = intval(Arr::get($item, 'teamBId')); $odd->team_b_name = strval(Arr::get($item, 'teamBName')); $odd->option_num = intval(Arr::get($item, 'optionNum')); $odd->odds = Arr::get($item, 'odds'); $odd->season = strval(Arr::get($item, 'season')); $odd->sales_state = strval(Arr::get($item, 'salesState')); $odd->show_state = strval(Arr::get($item, 'showState')); $odd->order_state = strval(Arr::get($item, 'orderState')); $odd->save(); if ($odd->show_state == 'win' || $odd->show_state == 'out') { Log::info('guanyakaijiang will dispath RefreshOrderGuanYaResult, guanOddsId:' .$odd->id); RefreshOrderGuanYaResult::dispatch($odd->id); } } } }