St_area_country.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Sports\Model;
  3. use \System\Model;
  4. /**
  5. * Class St_country
  6. * @package App\Sports\Model
  7. * 国家 地区 关系
  8. */
  9. class St_area_country extends Model
  10. {
  11. protected $table = 'st_area_country';
  12. //获取国家或地区 id
  13. public static function getID($opt = ''){
  14. $name = $opt;//国家或地区名称
  15. $ret = self::select('id','pid')
  16. ->where(['name'=>$name])
  17. ->first();
  18. if($ret->pid > 0){
  19. $data['area_id'] = $ret->pid;
  20. $data['country_id'] = $ret->id;
  21. }else{
  22. $data['area_id'] = $ret->id;
  23. $data['country_id'] = 0;
  24. }
  25. return $data;
  26. }
  27. /**
  28. * @param string $id 地区/国家 id
  29. * @param string $level 层级 1 地区 2国家
  30. * @return mixed
  31. * 根据条件获取地区/国家数据
  32. */
  33. public static function getName($id = '',$level=''){
  34. $where = [];
  35. //拼装查询条件
  36. if(!empty($id)){
  37. $where[] = ['id','=',$id];
  38. }
  39. if(!empty($level)){
  40. $where[] = ['level','=',$level];
  41. }
  42. $name = self::select('id','name')
  43. ->where($where)
  44. ->get()
  45. ->toArray();
  46. return $name;
  47. }
  48. }