St_team.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Http\Model;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App\Http\Response\Response;
  5. /**
  6. * Class Account
  7. * @package App\Sports\Model
  8. * 数据源球队model
  9. */
  10. class St_team extends Model
  11. {
  12. protected $table = 'st_team';
  13. public $timestamps = false;
  14. /**
  15. * 写入数据源球队数据
  16. * $game_code 球类代码
  17. * $team 球队名称
  18. * $source 数据来源
  19. */
  20. public static function setTeam($game_code,$teamNameArr=[],$source){
  21. if(!empty($game_code) and !empty($teamNameArr) and !empty($source)){
  22. //拼装数据
  23. foreach($teamNameArr as $k => $teamName){
  24. $set_arr[] = [
  25. 'game_type' => $game_code,
  26. 'team_name_cn' => $teamName,
  27. 'status' => 1,
  28. 'source' => $source,
  29. 'update_time' => date('Y-m-d H:i:s')
  30. ];
  31. }
  32. //循环写入/更新
  33. foreach($set_arr as $k =>$set){
  34. $ret = self::updateOrInsert(
  35. ['game_type' => $game_code, 'team_name_cn' => $set['team_name_cn'],'source'=>$set['source']],
  36. ['status' => $set['status'],'update_time' => $set['update_time']]
  37. );
  38. if(empty($ret)) return Response::generate('',Response::SET_TEAM_ERR);
  39. }
  40. }
  41. }
  42. }