HostServer.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/6/11
  6. * Time: ����9:28
  7. * �����ת����
  8. */
  9. namespace common\api;
  10. use Yii;
  11. use common\models\CategoryCity;
  12. class HostServer
  13. {
  14. public $hostA;
  15. public $hostId = 0;
  16. //2020-4-29 陈方利要求修改
  17. public $shangwu = '<script>(function() {var _53code = document.createElement("script");_53code.src = "https://www111.53kf.com/code/code/610925db680654214fdfc80e706668a57/2";var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(_53code, s);})();</script>';
  18. public $webconfig;
  19. public function __construct()
  20. {
  21. $name = Yii::$app->request->getHostName();
  22. $name = explode('.', $name);
  23. $this->hostA = $name[0];
  24. $this->CityPid();
  25. //�����š�logo��53���
  26. $this->webconfig = $this->getWebCofig();
  27. !empty($this->webconfig['bridge_link']) ? $this->shangwu = $this->webconfig['bridge_link'] : '';
  28. }
  29. public function CityPid()
  30. {
  31. $model = new \common\models\CategoryCity();
  32. $model->pid = 0;
  33. $rows = $model->getList([]);
  34. $A = array_column($rows, 'id', 'a');
  35. if (isset($A[$this->hostA])) {
  36. $this->hostId = $A[$this->hostA];
  37. return;
  38. }
  39. if ($this->hostA[0] == 'm') {
  40. $this->hostA = substr($this->hostA, 1);
  41. if (isset($A[$this->hostA])) {
  42. $this->hostId = $A[$this->hostA];
  43. }
  44. }
  45. }
  46. // /**
  47. // * �ض�����������ض�������ͨ
  48. // * */
  49. // public function Cityshangwu()
  50. // {
  51. // //�ض�����id
  52. // //���� 39���麣�� 69����ɽ�� 74
  53. // $data = false;
  54. // $input = \Yii::$app->request->get();
  55. // $city = ['������','������','��ָɽ��','��ͤ��'];
  56. // $model = new \common\models\CategoryCity();
  57. // if (!empty($input['city'])){
  58. // $row = $model->FindById($input['city']);
  59. // if ($row){
  60. // $data = $row->city_name;
  61. // }
  62. // }
  63. //
  64. // if (!empty($input['hid'])) {
  65. // if (!is_numeric($input['hid'])) {
  66. // $ex = explode('-', $input['hid']);
  67. // if (!empty($ex[1]) && is_numeric($ex[1])) {
  68. // $input['hid'] = $ex[1];
  69. // }
  70. // }
  71. // $row = \common\models\House::find()->select(['pfg_category_city.city_name'])->where(['pfg_house.id' => $input['hid'],])->innerJoin('pfg_category_city', 'pfg_house.city=pfg_category_city.id')->asArray()->one();
  72. // if ($row) {
  73. // $data = $row['city_name'];
  74. // }
  75. // }
  76. // if ($data){
  77. // $bool = in_array($data,$city);
  78. // if ($bool){
  79. // $this->shangwu = '<script language="javascript" src="http://swt.shunfangw.com/JS/LsJS.aspx?siteid=MRG74456440&float=1&lng=cn"></script>';
  80. //
  81. // }
  82. // }
  83. // return $this->shangwu;
  84. // }
  85. /**
  86. * ��������ҳ���������ͨ
  87. * */
  88. public function Cityshangwu()
  89. {
  90. $input = \Yii::$app->request->get();
  91. $model = new \common\models\CategoryCity();
  92. //��������
  93. if (Yii::$app->hostserver->hostId != 0 && empty($input['city'])) {
  94. $shangwu = $this->getShangWuTong(Yii::$app->hostserver->hostId);
  95. if (!empty($shangwu)) {
  96. $this->shangwu = $shangwu;
  97. }
  98. }
  99. //�����
  100. if (!empty($input['city'])) {
  101. $shangwu = $this->getShangWuTong($input['city']);
  102. if (!empty($shangwu)) {
  103. $this->shangwu = $shangwu;
  104. }
  105. }
  106. //�жϸ�¥������
  107. if (!empty($input['hid'])) {
  108. if (!is_numeric($input['hid'])) {
  109. $ex = explode('-', $input['hid']);
  110. if (!empty($ex[1]) && is_numeric($ex[1])) {
  111. $input['hid'] = $ex[1];
  112. }
  113. }
  114. $row = \common\models\House::find()->select(['pfg_house.city', 'pfg_house.customer_service'])->where(['pfg_house.id' => $input['hid']])->asArray()->one();
  115. if (!empty($row['customer_service'])) {
  116. $this->shangwu = $row['customer_service'];
  117. } else {
  118. $city = \common\models\CategoryCity::find()->andWhere(['id' => $row['city']])->asArray()->one();
  119. if ($city['pid'] != 0) {
  120. $shangwu = CategoryCity::find()->select(['dialogue'])->andWhere(['id' => $city['id']])->asArray()->one()['dialogue'];
  121. if (!empty($shangwu)) {
  122. $this->shangwu = $shangwu;
  123. } else {
  124. $shangwu = CategoryCity::find()->select(['dialogue'])->andWhere(['id' => $city['pid']])->asArray()->one()['dialogue'];
  125. !empty($shangwu) ? $this->shangwu = $shangwu : '';
  126. }
  127. }
  128. }
  129. }
  130. return $this->shangwu;
  131. }
  132. public function getShangWuTong($city)
  133. {
  134. $model = new \common\models\CategoryCity();
  135. $row = $model->FindById($city);
  136. $shangwu = $model::find()->select(['dialogue'])->andWhere(['id' => $row['id']])->asArray()->one()['dialogue'];
  137. if (empty($shangwu) && $row['pid'] != 0) {
  138. $shangwu = $model::find()->select(['dialogue'])->andWhere(['id' => $row['pid']])->asArray()->one()['dialogue'];
  139. }
  140. return $shangwu;
  141. }
  142. public function getWebCofig()
  143. {
  144. $cofigmodel = new \common\models\Config();
  145. $wconfig = $cofigmodel::find()->asArray()->one();
  146. if (!empty($wconfig)) {
  147. empty($wconfig['logo']) ? '' : $wconfig['logo'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['setsite'] . $wconfig['logo'];
  148. empty($wconfig['wechat']) ? '' : $wconfig['wechat'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['setsite'] . $wconfig['wechat'];
  149. }
  150. return $wconfig;
  151. }
  152. }