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.
 
 
 
 

355 lines
18 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 .= " p.main_corp_id in ( 0, " . $main_corp_id . ") ";
  30. } else {
  31. $and_sql .= " p.main_corp_id in ( 0, 1 ) ";
  32. }
  33. $to_main_corp_id = $main_corp_id == 0 ? 1 : $main_corp_id;
  34. $select_agent_sql = " SELECT line_id,ticket_id FROM opera_tickets_agent WHERE to_main_corp_id={$to_main_corp_id} AND authority_status=1 AND is_onsale=1 ";
  35. $agent_array = $this->query($select_agent_sql);
  36. $agent_ticket_array = array();
  37. foreach( $agent_array as $agent_info ) {
  38. $agent_ticket_array[] = $agent_info["ticket_id"];
  39. }
  40. if( count($agent_ticket_array) > 0 ) {
  41. $and_sql = "( ".$and_sql." OR r.prod_id IN(".implode(",", $agent_ticket_array).") )";
  42. }
  43. #endregion
  44. $page_size = isset($param['page_size']) ? trim($param['page_size']) : false;//每页展示条数
  45. $current_page = isset($param['current_page']) ? trim($param['current_page']) : false;//当前页
  46. $line_code = isset($param['line_code']) ? (empty($param['line_code']) ? '' : trim($param['line_code'])) : false;//线路编码或名称
  47. $start_area = isset($param['start_area']) ? (empty($param['start_area']) ? "''" : "'" . trim($param['start_area']) . "'") : false;//出发地
  48. $end_area = isset($param['end_area']) ? (empty($param['end_area']) ? "''" : "'" . trim($param['end_area']) . "'") : false;//目的地
  49. $run_date = isset($param['run_date']) ? (empty($param['run_date']) ? date('Y-m-d', time()) : trim($param['run_date'])) : false;//出发日期
  50. $line_type = isset($param['line_type']) ? trim($param['line_type']) : false;//线路类型
  51. $now_date = date('Y-m-d', time());
  52. if (false===$line_code || false===$start_area || false===$end_area || false===$run_date || false===$line_type) {
  53. $json['code'] = '2';
  54. $json['info'] = '缺少必要参数';
  55. return $json;
  56. }
  57. $extra_sql = "";
  58. //
  59. // if (isset($_COOKIE["opera_org_id"]) && mb_strlen($_COOKIE["opera_org_id"]) > 0) {
  60. // $extra_sql = ' AND p.ORG_ID IN( ' . $_COOKIE["opera_org_id"] . ' ) ';
  61. // }
  62. $search_line_sql = " and p.line_type = " . $line_type;
  63. if( $line_type == 255 ) {
  64. $search_line_sql = " and p.line_type IN (255,368)";
  65. }
  66. $search_line_sql .= " and ".$and_sql;
  67. $start_row = ($current_page - 1) * $page_size;
  68. $run_x='run_'.date('Ym',strtotime($run_date));
  69. $sql = "select a.run_id,
  70. a.prod_id,
  71. a.start_area_id,
  72. (select area_name from base_area where id = a.start_area_id LIMIT 1) as start_area_name,
  73. a.end_area_id,
  74. (select area_name from base_area where id = a.end_area_id LIMIT 1) as end_area_name,
  75. a.property,
  76. a.prod_name,
  77. a.run_date,
  78. 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,
  79. 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,
  80. (select type_name from dict_type where id = a.seat_type ) as seat,
  81. max(a.price) as price,
  82. (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
  83. from (
  84. select distinct m.run_id,
  85. p.org_id,
  86. p.main_corp_id,
  87. p.line_id as prod_id,
  88. p.line_code as property,
  89. p.line_name as prod_name,
  90. m.run_date,
  91. r.start_station_area_id as start_area_id,
  92. r.end_station_area_id as end_area_id,
  93. r.seat_type,
  94. (select min(station_order_id) from run_station where run_id = m.run_id and area_id = r.start_station_area_id and station_inout_type <> 114 ) as start_order_id,
  95. (select max(station_order_id) from run_station where run_id = m.run_id and area_id = r.end_station_area_id and station_inout_type <> 114 ) as end_order_id,
  96. (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,
  97. (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,
  98. (select max(cus_price) from opera_tickets where ticket_id = r.prod_id and cancel_flag = 0) as price
  99. from opera_line p, run_main m, run_prod r, opera_tickets as ot
  100. where
  101. p.line_id = m.prod_id
  102. and m.run_id = r.run_id
  103. and p.line_id = r.parent_prod_id
  104. and ot.ticket_id = r.prod_id
  105. {$search_line_sql}
  106. and p.cancel_flag = 0
  107. and p.is_onsale = 1
  108. and p.if_disabled = 0
  109. and ot.is_onsale = 1
  110. and r.cancel_flag = 0" . $extra_sql . "
  111. and m.run_status not in(137,142)
  112. and m.run_date = '" . $run_date . "'
  113. and IF('" . $line_code . "'='',0=0,(p.line_name LIKE CONCAT('%','" . $line_code . "','%') OR p.line_code LIKE CONCAT('%','" . $line_code . "','%')))
  114. and r.start_station_area_id in (select id from base_area where cancel_flag = 0 and area_name like CONCAT('%'," . $start_area . ",'%'))
  115. and r.end_station_area_id in (select id from base_area where cancel_flag = 0 and area_name like CONCAT('%'," . $end_area . ",'%'))
  116. ) a
  117. 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
  118. order by a.prod_name,run_date,start_time,end_time
  119. LIMIT " . $start_row . "," . $page_size;
  120. /*原where条件
  121. where
  122. p.line_id = m.prod_id
  123. and m.run_id = r.run_id
  124. and p.line_id = r.parent_prod_id
  125. and p.line_type = " . $line_type . "
  126. and p.cancel_flag = 0
  127. and p.is_onsale = 1
  128. and p.if_disabled = 0
  129. and r.cancel_flag = 0" . $extra_sql . "
  130. and m.run_status = 138
  131. and m.run_date >= '" . $now_date . "'
  132. and m.run_date = '" . $run_date . "'
  133. 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)
  134. 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)
  135. else 0=0 end
  136. and IF('" . $line_code . "'='',0=0,(p.line_name LIKE CONCAT('%','" . $line_code . "','%') OR p.line_code LIKE CONCAT('%','" . $line_code . "','%')))
  137. and r.start_station_area_id in (select id from base_area where cancel_flag = 0 and area_name like CONCAT('%'," . $start_area . ",'%'))
  138. and r.end_station_area_id in (select id from base_area where cancel_flag = 0 and area_name like CONCAT('%'," . $end_area . ",'%'))
  139. ) a
  140. */
  141. zzcsUtils::writeLog($sql);
  142. $product_list = $this->query($sql);
  143. if (count($product_list) == 0) {
  144. $json['code'] = '0';
  145. $json['info'] = '没有符合的线路';
  146. $json['product_list'] = array();
  147. $json['page']['page_size'] = $page_size;
  148. $json['page']['current_page'] = "0";
  149. $json['page']['total_count'] = "0";
  150. $json['page']['total_page'] = "0";
  151. return $json;
  152. }
  153. foreach ($product_list as $k => $v) {
  154. if (!$v['price']) {
  155. $product_list[$k]['price'] = '0.00';
  156. }
  157. $tmp_stock=999;
  158. //库存判断
  159. $sql="select station_order_id,(select res_name from base_resource where res_id=station_res_id) station_name from run_station where area_id= {$v['start_area_id']} and run_id ={$v['run_id']}";
  160. $start_area_list = $this->query($sql);
  161. $sql="select station_order_id,(select res_name from base_resource where res_id=station_res_id) station_name from run_station where area_id= {$v['end_area_id']} and run_id ={$v['run_id']}";
  162. $end_area_list = $this->query($sql);
  163. foreach($start_area_list as $start_k=>$start_v){
  164. foreach($end_area_list as $end_k=>$end_v){
  165. if($start_v<$end_v) {
  166. $tmp_cnt_use = $end_v['station_order_id'] - $start_v['station_order_id'];
  167. $sql = "select count(1) ct from (select count(1) as cnt from {$run_x} where run_id={$v['run_id']} and order_id>={$start_v['station_order_id']} and order_id <{$end_v['station_order_id']} and seat_type=72 and seat_status=0 GROUP BY seat_seq_id) a where a.cnt={$tmp_cnt_use}";
  168. $tmp_cnt = $this->query($sql);
  169. $product_list[$k]['station_stock_list'][] = array(
  170. 'station_name' => $start_v['station_name'] . '——' . $end_v['station_name'],
  171. 'stock' => $tmp_cnt[0]['ct'],
  172. );
  173. if($tmp_stock>=$tmp_cnt[0]['ct']){
  174. $tmp_stock=$tmp_cnt[0]['ct'];
  175. }
  176. }
  177. }
  178. }
  179. $product_list[$k]['stock']=$tmp_stock;
  180. if ($tmp_stock < 0) {
  181. $product_list[$k]['stock'] = 0;
  182. }
  183. if ($v['stock'] > 20) {
  184. $product_list[$k]['stock'] = '充足';
  185. }
  186. }
  187. $count_sql = "select count(run_id) as total_count
  188. from
  189. (select
  190. run_id
  191. from (
  192. select distinct m.run_id,
  193. p.line_id as prod_id,
  194. r.start_station_area_id as start_area_id,
  195. r.end_station_area_id as end_area_id,
  196. r.seat_type,
  197. (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,
  198. (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
  199. from opera_line p, run_main m, run_prod r
  200. where
  201. p.line_id = m.prod_id
  202. and m.run_id = r.run_id
  203. and p.line_id = r.parent_prod_id
  204. {$search_line_sql}
  205. and p.cancel_flag = 0
  206. and r.cancel_flag = 0
  207. and p.is_onsale = 1
  208. and p.if_disabled = 0
  209. and m.run_status not in(137,142)
  210. and m.run_date = '" . $run_date . "'
  211. and IF('" . $line_code . "'='',0=0,(p.line_name LIKE CONCAT('%','" . $line_code . "','%') OR p.line_code LIKE CONCAT('%','" . $line_code . "','%')))
  212. and r.start_station_area_id in (select id from base_area where cancel_flag = 0 and area_name like CONCAT('%'," . $start_area . ",'%'))
  213. and r.end_station_area_id in (select id from base_area where cancel_flag = 0 and area_name like CONCAT('%'," . $end_area . ",'%'))
  214. ) a
  215. group by a.prod_id,a.start_area_id,a.end_area_id,a.start_time,a.end_time,a.seat_type) as b";
  216. $total_count = $this->query($count_sql);
  217. $total_count = $total_count[0]['total_count'];
  218. $total_page = ceil($total_count / $page_size);
  219. $json['code'] = '0';
  220. $json['info'] = '返回产品列表';
  221. $json['product_list'] = $product_list;
  222. $json['page']['page_size'] = $page_size;
  223. $json['page']['current_page'] = $current_page;
  224. $json['page']['total_count'] = $total_count;
  225. $json['page']['total_page'] = $total_page;
  226. return $json;
  227. }
  228. /**
  229. * 获取巴士线路产品基础配置
  230. */
  231. public function getProductListBase($param)
  232. {
  233. $line_type = isset($param['line_type']) ? trim($param['line_type']) : false;//线路类型
  234. if (!$line_type) {
  235. $json['code'] = '2';
  236. $json['info'] = '缺少必要参数';
  237. return $json;
  238. }
  239. $sql = "SELECT
  240. area_id,
  241. inout_type,
  242. (select area_name from base_area where id = area_id LIMIT 1) as area_name
  243. FROM
  244. opera_line AS l
  245. LEFT JOIN opera_station AS s ON l.line_id = s.line_id
  246. WHERE
  247. l.cancel_flag = 0
  248. AND l.if_disabled = 0
  249. AND l.is_onsale = 1
  250. AND s.cancel_flag = 0
  251. AND l.line_type = " . $line_type . "
  252. GROUP BY
  253. area_id,inout_type";
  254. $area_list = $this->query($sql);
  255. foreach ($area_list as $k => $v) {
  256. if ($v['inout_type'] == 108 || $v['inout_type'] == 108) {
  257. $area_one['id'] = $v['area_id'];
  258. $area_one['name'] = $v['area_name'];
  259. $start_area[$v['area_id']] = $area_one;
  260. }
  261. if ($v['inout_type'] == 109 || $v['inout_type'] == 110) {
  262. $area_one['id'] = $v['area_id'];
  263. $area_one['name'] = $v['area_name'];
  264. $end_area[$v['area_id']] = $area_one;
  265. }
  266. }
  267. $json['code'] = '0';
  268. $json['info'] = '返回可选地点列表成功';
  269. $json['start_area'] = array_merge($start_area);
  270. $json['end_area'] = array_merge($end_area);
  271. return $json;
  272. }
  273. /**
  274. * 获取组合线路产品线
  275. * @return mixed
  276. */
  277. function groupProductHeadInfo()
  278. {
  279. //得到产品线
  280. $res = $this->productLine();
  281. if ($res) {
  282. //无信息
  283. $json["code"] = '0';
  284. $json["info"] = '产品线返回';
  285. $json["product_line"] = $res;
  286. return $json;
  287. } else {
  288. $json["code"] = '1';
  289. $json["info"] = '数据库异常';
  290. return $json;
  291. }
  292. }
  293. /**
  294. * hyk
  295. * 组合线路产品列表
  296. * @param $web_data
  297. * @return array
  298. */
  299. function groupProductList($web_data)
  300. {
  301. //hyk
  302. //组合线路产品列表
  303. $run_date = isset($web_data["run_date"]) ? trim($web_data["run_date"]) : false;
  304. $current_page = isset($web_data['current_page']) ? trim($web_data['current_page']) : false;
  305. $page_size = isset($web_data['page_size']) ? trim($web_data['page_size']) : false;
  306. $product_type = isset($web_data['product_type']) ? trim($web_data['product_type']) : false;
  307. $line = isset($web_data['line']) ? trim($web_data['line']) : false;
  308. if ($product_type === false || $current_page === false || $page_size === false || $run_date === false || $product_type === false || $line === false) {
  309. //参数不完整;
  310. $json["code"] = '2';
  311. $json["info"] = "缺少必要参数";
  312. return $json;
  313. }
  314. if (empty($product_type)) {
  315. $product_type = 0;
  316. }
  317. $json = array();
  318. $sql = "call sp_choice_kicket_group (" . $this->user_id . "," . $current_page . "," . $page_size . ",'" . $line . "'," . $product_type . ",'" . $run_date . "')";
  319. zzcsUtils::writeLog($sql);
  320. $reset = $this->procQuery($sql);
  321. if ($reset === false) {
  322. $json["code"] = $reset['code'];
  323. $json["info"] = $reset['info'];
  324. return $json;
  325. } else {
  326. //数据查询成功
  327. $json["code"] = '0';
  328. $json["info"] = '组合产品列表';
  329. $json['page'] = array(
  330. 'current_page' => $reset['data'][0][0]["currpage"],
  331. 'total_page' => $reset['data'][0][0]["total_page"],
  332. 'total_count' => $reset['data'][0][0]["total"],
  333. 'page_size' => $reset['data'][0][0]["page_size"]
  334. );
  335. if (isset($reset['data'][1])) {
  336. $json["product_list"] = $reset['data'][1];
  337. } else {
  338. $json["product_list"] = array();
  339. }
  340. return $json;
  341. }
  342. }
  343. }
  344. ?>