Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

312 rader
16 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 张帅
  5. * Date: 2016/10/15
  6. * Time: 17:50
  7. */
  8. /**
  9. * Class singleProduct 线路选择产品相关
  10. */
  11. class lineProduct extends base
  12. {
  13. /**
  14. * 获取单一线路产品
  15. */
  16. public function getProductList($param)
  17. {
  18. #region 获取渠道权限
  19. $user_id = $this->user_id;
  20. $opera_org_id_sql = "select opera_org_id,main_corp_id from base_user where id = " . $user_id . " and cancel_flag = 0";
  21. $opera_org_id_result = $this->query($opera_org_id_sql);
  22. $opera_org_id = $opera_org_id_result[0]['opera_org_id'];
  23. $main_corp_id = $opera_org_id_result[0]['main_corp_id'];
  24. $and_sql = '';
  25. if ($opera_org_id != '') {
  26. $and_sql .= " and a.org_id in (" . $opera_org_id . ") ";
  27. }
  28. if($main_corp_id != 0){
  29. $and_sql .= " and a.main_corp_id in (" . $main_corp_id . ") ";
  30. }
  31. #endregion
  32. $page_size = isset($param['page_size']) ? trim($param['page_size']) : false;//每页展示条数
  33. $current_page = isset($param['current_page']) ? trim($param['current_page']) : false;//当前页
  34. $line_code = isset($param['line_code']) ? (empty($param['line_code']) ? '' : trim($param['line_code'])) : false;//线路编码或名称
  35. $start_area = isset($param['start_area']) ? (empty($param['start_area']) ? "''" : "'" . trim($param['start_area']) . "'") : false;//出发地
  36. $end_area = isset($param['end_area']) ? (empty($param['end_area']) ? "''" : "'" . trim($param['end_area']) . "'") : false;//目的地
  37. $run_date = isset($param['run_date']) ? (empty($param['run_date']) ? date('Y-m-d', time()) : trim($param['run_date'])) : false;//出发日期
  38. $line_type = isset($param['line_type']) ? trim($param['line_type']) : false;//线路类型
  39. $now_date = date('Y-m-d', time());
  40. if (false===$line_code || false===$start_area || false===$end_area || false===$run_date || false===$line_type) {
  41. $json['code'] = '2';
  42. $json['info'] = '缺少必要参数';
  43. return $json;
  44. }
  45. $extra_sql = "";
  46. if (isset($_COOKIE["opera_org_id"]) && mb_strlen($_COOKIE["opera_org_id"]) > 0) {
  47. $extra_sql = ' AND p.ORG_ID IN( ' . $_COOKIE["opera_org_id"] . ' ) ';
  48. }
  49. $search_line_sql = " and p.line_type = " . $line_type;
  50. if( $line_type == 255 ) {
  51. $search_line_sql = " and p.line_type IN (255,368)";
  52. }
  53. $start_row = ($current_page - 1) * $page_size;
  54. $sql = "select a.run_id,
  55. a.prod_id,
  56. a.start_area_id,
  57. (select area_name from base_area where id = a.start_area_id LIMIT 1) as start_area_name,
  58. a.end_area_id,
  59. (select area_name from base_area where id = a.end_area_id LIMIT 1) as end_area_name,
  60. a.property,
  61. a.prod_name,
  62. a.run_date,
  63. if(INSTR(a.start_time,',')>0,concat(substring_index(a.start_time,',',1),'-',substring_index(a.start_time,',',-1)),a.start_time) as start_time,
  64. if(INSTR(a.end_time,',')>0,concat(substring_index(a.end_time,',',1),'-',substring_index(a.end_time,',',-1)),a.end_time) as end_time,
  65. (select type_name from dict_type where id = a.seat_type ) as seat,
  66. max(a.price) as price,
  67. (select min(total_count-saled_count) from run_stock where run_id = a.run_id and cancel_flag = 0 and seq_id >= a.start_order_id and seq_id < a.end_order_id and seat_type = a.seat_type) as stock
  68. from (
  69. select distinct m.run_id,
  70. p.org_id,
  71. p.main_corp_id,
  72. p.line_id as prod_id,
  73. p.line_code as property,
  74. p.line_name as prod_name,
  75. m.run_date,
  76. r.start_station_area_id as start_area_id,
  77. r.end_station_area_id as end_area_id,
  78. r.seat_type,
  79. (select min(station_order_id) from run_station where run_id = m.run_id and area_id = r.start_station_area_id) as start_order_id,
  80. (select max(station_order_id) from run_station where run_id = m.run_id and area_id = r.end_station_area_id) as end_order_id,
  81. (select group_concat(distinct start_time) from run_station where run_id = m.run_id and area_id = r.start_station_area_id ) as start_time,
  82. (select group_concat(distinct start_time) from run_station where run_id = m.run_id and area_id = r.end_station_area_id ) as end_time,
  83. (select max(cus_price) from opera_tickets where ticket_id = r.prod_id and cancel_flag = 0) as price
  84. from opera_line p, run_main m, run_prod r
  85. where
  86. p.line_id = m.prod_id
  87. and m.run_id = r.run_id
  88. and p.line_id = r.parent_prod_id
  89. {$search_line_sql}
  90. and p.cancel_flag = 0
  91. and p.is_onsale = 1
  92. and p.if_disabled = 0
  93. and r.cancel_flag = 0" . $extra_sql . "
  94. and m.run_status not in(137,142)
  95. and m.run_date = '" . $run_date . "'
  96. and IF('" . $line_code . "'='',0=0,(p.line_name LIKE CONCAT('%','" . $line_code . "','%') OR p.line_code LIKE CONCAT('%','" . $line_code . "','%')))
  97. and r.start_station_area_id in (select id from base_area where cancel_flag = 0 and area_name like CONCAT('%'," . $start_area . ",'%'))
  98. and r.end_station_area_id in (select id from base_area where cancel_flag = 0 and area_name like CONCAT('%'," . $end_area . ",'%'))
  99. ) a
  100. where 0=0 " . $and_sql . "
  101. group by a.prod_id,a.start_area_id,a.end_area_id,a.run_date,a.start_time,a.end_time,a.seat_type
  102. LIMIT " . $start_row . "," . $page_size;
  103. /*原where条件
  104. where
  105. p.line_id = m.prod_id
  106. and m.run_id = r.run_id
  107. and p.line_id = r.parent_prod_id
  108. and p.line_type = " . $line_type . "
  109. and p.cancel_flag = 0
  110. and p.is_onsale = 1
  111. and p.if_disabled = 0
  112. and r.cancel_flag = 0" . $extra_sql . "
  113. and m.run_status = 138
  114. and m.run_date >= '" . $now_date . "'
  115. and m.run_date = '" . $run_date . "'
  116. and case p.sale_expired_type when 321 then if(date_add(date_add(m.run_date,interval -1 day), interval (substring_index(p.sale_expired_time,':',1)*60 + substring_index(p.sale_expired_time,':',-1)) minute) > now(),0=0,0=1)
  117. when 322 then if(date_add(m.run_date, interval m.run_minutes -(substring_index(p.sale_expired_time,':',1)*60 + substring_index(p.sale_expired_time,':',-1)) minute)>= now(),0=0,0=1)
  118. else 0=0 end
  119. and IF('" . $line_code . "'='',0=0,(p.line_name LIKE CONCAT('%','" . $line_code . "','%') OR p.line_code LIKE CONCAT('%','" . $line_code . "','%')))
  120. and r.start_station_area_id in (select id from base_area where cancel_flag = 0 and area_name like CONCAT('%'," . $start_area . ",'%'))
  121. and r.end_station_area_id in (select id from base_area where cancel_flag = 0 and area_name like CONCAT('%'," . $end_area . ",'%'))
  122. ) a
  123. */
  124. $product_list = $this->query($sql);
  125. if (count($product_list) == 0) {
  126. $json['code'] = '0';
  127. $json['info'] = '没有符合的线路';
  128. $json['product_list'] = array();
  129. $json['page']['page_size'] = $page_size;
  130. $json['page']['current_page'] = "0";
  131. $json['page']['total_count'] = "0";
  132. $json['page']['total_page'] = "0";
  133. return $json;
  134. }
  135. foreach ($product_list as $k => $v) {
  136. if (!$v['price']) {
  137. $product_list[$k]['price'] = '0.00';
  138. }
  139. if ($v['stock'] < 0) {
  140. $product_list[$k]['stock'] = 0;
  141. }
  142. if ($v['stock'] > 20) {
  143. $product_list[$k]['stock'] = '充足';
  144. }
  145. }
  146. $count_sql = "select count(run_id) as total_count
  147. from
  148. (select
  149. run_id
  150. from (
  151. select distinct m.run_id,
  152. p.line_id as prod_id,
  153. r.start_station_area_id as start_area_id,
  154. r.end_station_area_id as end_area_id,
  155. r.seat_type,
  156. (select group_concat(distinct start_time) from run_station where run_id = m.run_id and area_id = r.start_station_area_id ) as start_time,
  157. (select group_concat(distinct start_time) from run_station where run_id = m.run_id and area_id = r.end_station_area_id ) as end_time
  158. from opera_line p, run_main m, run_prod r
  159. where
  160. p.line_id = m.prod_id
  161. and m.run_id = r.run_id
  162. and p.line_id = r.parent_prod_id
  163. {$search_line_sql}
  164. and p.cancel_flag = 0
  165. and r.cancel_flag = 0
  166. and p.is_onsale = 1
  167. and p.if_disabled = 0
  168. and m.run_status not in(137,142)
  169. and m.run_date = '" . $run_date . "'
  170. and IF('" . $line_code . "'='',0=0,(p.line_name LIKE CONCAT('%','" . $line_code . "','%') OR p.line_code LIKE CONCAT('%','" . $line_code . "','%')))
  171. and r.start_station_area_id in (select id from base_area where cancel_flag = 0 and area_name like CONCAT('%'," . $start_area . ",'%'))
  172. and r.end_station_area_id in (select id from base_area where cancel_flag = 0 and area_name like CONCAT('%'," . $end_area . ",'%'))
  173. ) a
  174. group by a.prod_id,a.start_area_id,a.end_area_id,a.start_time,a.end_time,a.seat_type) as b";
  175. $total_count = $this->query($count_sql);
  176. $total_count = $total_count[0]['total_count'];
  177. $total_page = ceil($total_count / $page_size);
  178. $json['code'] = '0';
  179. $json['info'] = '返回产品列表';
  180. $json['product_list'] = $product_list;
  181. $json['page']['page_size'] = $page_size;
  182. $json['page']['current_page'] = $current_page;
  183. $json['page']['total_count'] = $total_count;
  184. $json['page']['total_page'] = $total_page;
  185. return $json;
  186. }
  187. /**
  188. * 获取巴士线路产品基础配置
  189. */
  190. public function getProductListBase($param)
  191. {
  192. $line_type = isset($param['line_type']) ? trim($param['line_type']) : false;//线路类型
  193. if (!$line_type) {
  194. $json['code'] = '2';
  195. $json['info'] = '缺少必要参数';
  196. return $json;
  197. }
  198. $sql = "SELECT
  199. area_id,
  200. inout_type,
  201. (select area_name from base_area where id = area_id LIMIT 1) as area_name
  202. FROM
  203. opera_line AS l
  204. LEFT JOIN opera_station AS s ON l.line_id = s.line_id
  205. WHERE
  206. l.cancel_flag = 0
  207. AND l.if_disabled = 0
  208. AND l.is_onsale = 1
  209. AND s.cancel_flag = 0
  210. AND l.line_type = " . $line_type . "
  211. GROUP BY
  212. area_id,inout_type";
  213. $area_list = $this->query($sql);
  214. foreach ($area_list as $k => $v) {
  215. if ($v['inout_type'] == 108 || $v['inout_type'] == 108) {
  216. $area_one['id'] = $v['area_id'];
  217. $area_one['name'] = $v['area_name'];
  218. $start_area[$v['area_id']] = $area_one;
  219. }
  220. if ($v['inout_type'] == 109 || $v['inout_type'] == 110) {
  221. $area_one['id'] = $v['area_id'];
  222. $area_one['name'] = $v['area_name'];
  223. $end_area[$v['area_id']] = $area_one;
  224. }
  225. }
  226. $json['code'] = '0';
  227. $json['info'] = '返回可选地点列表成功';
  228. $json['start_area'] = array_merge($start_area);
  229. $json['end_area'] = array_merge($end_area);
  230. return $json;
  231. }
  232. /**
  233. * 获取组合线路产品线
  234. * @return mixed
  235. */
  236. function groupProductHeadInfo()
  237. {
  238. //得到产品线
  239. $res = $this->productLine();
  240. if ($res) {
  241. //无信息
  242. $json["code"] = '0';
  243. $json["info"] = '产品线返回';
  244. $json["product_line"] = $res;
  245. return $json;
  246. } else {
  247. $json["code"] = '1';
  248. $json["info"] = '数据库异常';
  249. return $json;
  250. }
  251. }
  252. /**
  253. * hyk
  254. * 组合线路产品列表
  255. * @param $web_data
  256. * @return array
  257. */
  258. function groupProductList($web_data)
  259. {
  260. //hyk
  261. //组合线路产品列表
  262. $run_date = isset($web_data["run_date"]) ? trim($web_data["run_date"]) : false;
  263. $current_page = isset($web_data['current_page']) ? trim($web_data['current_page']) : false;
  264. $page_size = isset($web_data['page_size']) ? trim($web_data['page_size']) : false;
  265. $product_type = isset($web_data['product_type']) ? trim($web_data['product_type']) : false;
  266. $line = isset($web_data['line']) ? trim($web_data['line']) : false;
  267. if ($product_type === false || $current_page === false || $page_size === false || $run_date === false || $product_type === false || $line === false) {
  268. //参数不完整;
  269. $json["code"] = '2';
  270. $json["info"] = "缺少必要参数";
  271. return $json;
  272. }
  273. if (empty($product_type)) {
  274. $product_type = 0;
  275. }
  276. $json = array();
  277. $sql = "call sp_choice_kicket_group (" . $this->user_id . "," . $current_page . "," . $page_size . ",'" . $line . "'," . $product_type . ",'" . $run_date . "')";
  278. zzcsUtils::writeLog($sql);
  279. $reset = $this->procQuery($sql);
  280. if ($reset === false) {
  281. $json["code"] = $reset['code'];
  282. $json["info"] = $reset['info'];
  283. return $json;
  284. } else {
  285. //数据查询成功
  286. $json["code"] = '0';
  287. $json["info"] = '组合产品列表';
  288. $json['page'] = array(
  289. 'current_page' => $reset['data'][0][0]["currpage"],
  290. 'total_page' => $reset['data'][0][0]["total_page"],
  291. 'total_count' => $reset['data'][0][0]["total"],
  292. 'page_size' => $reset['data'][0][0]["page_size"]
  293. );
  294. if (isset($reset['data'][1])) {
  295. $json["product_list"] = $reset['data'][1];
  296. } else {
  297. $json["product_list"] = array();
  298. }
  299. return $json;
  300. }
  301. }
  302. }
  303. ?>