You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

226 lines
7.0 KiB

  1. <?php
  2. /**
  3. * 首页及其他页面数据读取
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 倪宗锋
  12. * PhpStorm HomeController.php
  13. * Create By 2017/6/20 16:19 $
  14. */
  15. namespace zzcx\controllers\home;
  16. use common\util\Util;
  17. use yii\web\Controller;
  18. use zzcx\service\home\Home;
  19. class HomeController extends Controller
  20. {
  21. public $service = null;
  22. /**
  23. * Des:获取service
  24. * Name: service
  25. * @return Home
  26. * @author 倪宗锋
  27. */
  28. public function service()
  29. {
  30. if ($this->service == null) {
  31. $this->service = new Home();
  32. }
  33. return $this->service;
  34. }
  35. /**
  36. * Des:获取热门搜索
  37. * Name: actionGetHot
  38. * @return string
  39. * @author 倪宗锋
  40. */
  41. public function actionGetHot()
  42. {
  43. $return = $this->service()->getHost();
  44. return Util::returnJsSu('', ['list' => $return]);
  45. }
  46. /**
  47. * Des:获取查询列表
  48. * Name: actionSearch
  49. * @return string
  50. * @author 倪宗锋
  51. */
  52. public function actionSearch()
  53. {
  54. $param = [
  55. 'prod_name' => $this->_post('prod_name', ''),//查询关键字
  56. ];
  57. $return = $this->service()->search($param);
  58. if ($return['flag'] == false) {
  59. return Util::returnJsEr($return['msg']);
  60. }
  61. return Util::returnJsSu('', $return['data'], $return['url'], $return['code']);
  62. }
  63. /**
  64. * Des:首页数据
  65. * Name: actionSearch
  66. * @return string
  67. * @author zhangsq
  68. */
  69. public function actionHomeList()
  70. {
  71. $result = $this->service()->getHomeList();
  72. return json_encode($result);
  73. }
  74. /**
  75. * Des:首页数据
  76. * Name: actionSearch
  77. * @return string
  78. * @author zhangsq
  79. */
  80. public function actionProdList()
  81. {
  82. $prodIds = $this->_post('prodIds', '');//查询关键字
  83. $result = $this->service()->getProdList($prodIds);
  84. return Util::returnJsSu('', $result['data']);
  85. }
  86. /**
  87. * Des:获取底部菜单
  88. * Name: actionGetBottom
  89. * @return string
  90. * @author 倪宗锋
  91. */
  92. public function actionGetBottom()
  93. {
  94. $config = require APP_PATH . '/config/home_' . YII_ENV . '_config.php';
  95. //底部菜单
  96. $bottom_menu = $config['bottom_menu'];
  97. return Util::returnJsSu('', ['list' => $bottom_menu]);
  98. }
  99. /**
  100. * Des:获取热门搜索poi
  101. * Name: actionGetHostStations
  102. * @return string
  103. * @author 倪宗锋
  104. */
  105. public function actionGetHotStation()
  106. {
  107. $param = [
  108. 'station_id' => $this->_post('station_id', ''),//已选站点ID
  109. 'inout_type' => $this->_post('inout_type', 'in'),//上下车类型 上in,下out
  110. 'category_id' => $this->_post('category_id', '')//菜单ID
  111. ];
  112. $return = $this->service()->getHotStation($param);
  113. return Util::returnJsSu('', $return);
  114. }
  115. /**
  116. * Des:获取站点列表
  117. * Name: actionGetStation
  118. * @return string
  119. * @author 倪宗锋
  120. */
  121. public function actionGetStation()
  122. {
  123. $param = [
  124. 'poi_type' => $this->_post('poi_type', ''),//站点类型
  125. 'station_id' => $this->_post('station_id', ''),//已选站点ID
  126. 'inout_type' => $this->_post('inout_type', 'in'),//上下车类型 上in,下out
  127. 'category_id' => $this->_post('category_id', ''),//菜单ID
  128. 'poi_name' => trim($this->_post('poi_name', '')),//搜索的关键字
  129. ];
  130. $return = $this->service()->getStation($param);//获取站点列表
  131. return Util::returnJsSu('', $return);
  132. }
  133. /**
  134. * Des:根据POI获取产品列表
  135. * Name: actionGetProdByPoi
  136. * @return string
  137. * @author 倪宗锋
  138. */
  139. public function actionGetProdByPoi()
  140. {
  141. $params = [
  142. 'init_flag' => $this->_post('init_flag', 0),
  143. 'poi' => $this->_post('poi', ''),//景区POI
  144. 'cate_id' => $this->_post('cate_id', 1),//菜单ID
  145. 'date' => $this->_post('date', date('Y-m-d', time())),//日期
  146. 'other_poi' => $this->_post('other_poi', 0),//另一个POI
  147. 'start_station_arr' => $this->_post('start_station_arr', ''),//起始站点数组
  148. 'end_station_arr' => $this->_post('end_station_arr', ''),//终点站点数组
  149. ];
  150. #获取最近有班次的日期
  151. $new_run_date = $this->service()->getNewRunDate($params);
  152. $params['date'] = $new_run_date;
  153. $return = $this->service()->getProdByPoi($params);//根据POI获取产品列表
  154. if ($params['start_station_arr'] != '') {
  155. //根据所选的起始站点处理数据集
  156. $start_station_arr = explode(',', $params['start_station_arr']);
  157. foreach ($return['data']['ticket'] as $key => $value) {
  158. // if($value['poi_id']==$params['poi']){
  159. foreach ($value['ticket_list'] as $k => $val) {
  160. if (!in_array($val['start_res_id'], $start_station_arr)) {
  161. unset($return['data']['ticket'][$key]['ticket_list'][$k]);
  162. }
  163. }
  164. // }
  165. }
  166. }
  167. if ($params['end_station_arr'] != '') {
  168. //根据所选的起始站点处理数据集
  169. $end_station_arr = explode(',', $params['end_station_arr']);
  170. foreach ($return['data']['ticket'] as $key => $value) {
  171. foreach ($value['ticket_list'] as $k => $val) {
  172. if (!in_array($val['end_res_id'], $end_station_arr)) {
  173. unset($return['data']['ticket'][$key]['ticket_list'][$k]);
  174. }
  175. }
  176. }
  177. }
  178. $today = date("Y-m-d");
  179. switch ($new_run_date) {
  180. case $today:
  181. $date_name = '(今天)';break;
  182. case date('Y-m-d',strtotime("+1 day")):
  183. $date_name = '(明天)';break;
  184. case date('Y-m-d',strtotime("+2 day")):
  185. $date_name = '(后天)';break;
  186. default:
  187. $date_name = '';
  188. }
  189. $return['data']['date'] = [
  190. 'date' => $new_run_date,
  191. 'date_name' => $date_name,
  192. 'year' => date('Y', strtotime($new_run_date)),
  193. 'month' => date('n', strtotime($new_run_date)),
  194. 'day' => date('d', strtotime($new_run_date)),
  195. ];
  196. if ($return['flag'] == false) {
  197. return Util::returnJsEr($return['msg']);
  198. } else {
  199. return Util::returnJsSu('', $return['data']);
  200. }
  201. }
  202. }