CountryConfModel.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * CountryConfModel.php UTF-8
  4. *
  5. *
  6. * @date : 2017/12/19 11:18
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : liguanglong <lgl@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\model\district;
  13. use huo\model\common\CommonModel;
  14. use think\Request;
  15. class CountryConfModel extends CommonModel {
  16. protected $name = 'country_conf';
  17. protected $field='mobile_prefix';
  18. protected $field_txt = 'country';
  19. /**
  20. * @param $_data
  21. *
  22. * @return array
  23. */
  24. public function addCountryName($_data = array()) {
  25. if (!is_array($_data)) {
  26. return $_data;
  27. }
  28. $_where = [];
  29. if (is_array($_data)) {
  30. if (isset($_data[$this->field]) && !empty($_data[$this->field])) {
  31. $_where[] = $_data[$this->field];
  32. }
  33. foreach ($_data as $_k=>$_v) {
  34. if (!is_array($_v)) {
  35. break;
  36. }
  37. if (is_array($_v) && !empty($_v[$this->field])) {
  38. $_where[] = $_v[$this->field];
  39. }
  40. }
  41. }
  42. $_map['id'] = array('in', $_where);
  43. $request = Request::instance();
  44. $langSet = $request->langset();
  45. if ('zh-cn' == $langSet) {
  46. $_name = $this->where($_map)->column('id, cn_name_abbr');
  47. } else if ('en-us' == $langSet) {
  48. $_name = $this->where($_map)->column('id, en_name_abbr');
  49. }
  50. if (is_array($_data)) {
  51. if (isset($_data[$this->field]) && !empty($_data[$this->field])) {
  52. $_data[$this->field_txt] = $_name[$_data[$this->field]];
  53. }
  54. foreach ($_data as $_k=>$_v) {
  55. if (!is_array($_v)) {
  56. break;
  57. }
  58. if (is_array($_v) && !empty($_v[$this->field])) {
  59. $_data[$_k][$this->field_txt] = $_name[$_v[$this->field]];
  60. }
  61. }
  62. }
  63. return $_data;
  64. }
  65. /**
  66. * 获取所有国家的名称
  67. */
  68. public function getAllCountry() {
  69. $_lang = cmf_current_lang();
  70. if ('zh-cn' == $_lang) {
  71. $_field = 'id country_id, cn_name_abbr country';
  72. } else if ('en-us' == $_lang) {
  73. $_field = 'id country_id, en_name_abbr country';
  74. }
  75. $_countries_data = $this->column($_field);
  76. return $_countries_data;
  77. }
  78. /**
  79. * 获取地址
  80. */
  81. public function getCountryAddr($_param) {
  82. if(isset($_param['id']) && !empty($_param['id'])) {
  83. $_map['id'] = $_param['id'];
  84. } else {
  85. return false;
  86. }
  87. $_data = $this->where($_map)->value('currency_abbr');
  88. return $_data;
  89. }
  90. }