Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

2194 righe
102 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Steven
  5. * Date: 2016/10/15
  6. * Time: 17:41
  7. */
  8. //一下公用库文件需要用到的两个常量
  9. define( "TICKET_QR_URL", "http://ticket.zhizhuchuxing.com/ticket.php?orderid=" );
  10. define("SEND_MESSAGE", true);
  11. //为了和原cs和微信等模块统一,引入共通的短信和新浪短网址库文件
  12. require_once ROOT_PATH . '/ZZCS/coding/st-xm/Common/Function.php';
  13. require_once ROOT_PATH . '/ZZCS/coding/st-xm/Common/sinaAPI.php';
  14. /**
  15. * Class singleOrder 单一线路订单相关
  16. */
  17. class singleOrder extends base
  18. {
  19. /**
  20. * 获取产品详细信息
  21. * @param $param
  22. */
  23. public function getProductDetail($param)
  24. {
  25. $run_id = isset($param['run_id']) ? trim($param['run_id']) : false;//班次id;
  26. // $start_area_id = isset($param['start_area_id'])?trim($param['start_area_id']):false;//出发地id;
  27. // $end_area_id = isset($param['end_area_id'])?trim($param['end_area_id']):false;//目的地id;
  28. if (!$run_id) {
  29. $json['code'] = '2';
  30. $json['info'] = '缺少必要参数';
  31. return $json;
  32. }
  33. /*$sql = "SELECT
  34. r.run_id,r.run_date,r.run_time,l.line_name,l.line_code,l.line_id
  35. FROM
  36. run_main AS r,
  37. opera_line AS l
  38. WHERE
  39. r.prod_id = l.line_id
  40. AND r.run_id = " . $run_id . "
  41. and l.cancel_flag = 0
  42. and l.is_onsale = 1
  43. and l.if_disabled = 0
  44. and r.run_status = 138";*/
  45. $sql = "SELECT
  46. r.run_id,r.run_date,r.run_time,l.line_name,l.line_code,l.line_id
  47. FROM
  48. run_main AS r,
  49. opera_line AS l
  50. WHERE
  51. r.prod_id = l.line_id
  52. AND r.run_id = " . $run_id . "
  53. and l.cancel_flag = 0
  54. and l.is_onsale = 1
  55. and l.if_disabled = 0
  56. and r.run_status not in(137,142)";
  57. $line_info = $this->query($sql);
  58. if (count($line_info) == 0) {
  59. $json['code'] = '1';
  60. $json['info'] = '该产品已不存在';
  61. return $json;
  62. }
  63. //机场接驳,出发时间自由选择
  64. // if(in_array($line_info[0]['line_id'], array('450916', '450917'))){
  65. // $line_id = $line_info[0]['line_id'];
  66. // $run_date = $line_info[0]['run_date'];
  67. // $sql = "select prod_id line_id, run_time from run_main r where r.prod_id = $line_id and r.run_date = '$run_date' and r.run_status = 138 group by run_time";
  68. // $res = $this->query($sql);
  69. // if($res && !empty($res)){
  70. // $line_info[0]['run_time'] = $res;
  71. // }
  72. // }
  73. //在这里得到该班次的站点区域数量,如果大于0则隐藏返程选择
  74. $res = $this->judgeArea($param);
  75. if ($res['code'] != '0') {
  76. $json['code'] = '2';
  77. $json['info'] = $res['info'];
  78. } else {
  79. $area_num = $res['num'];
  80. }
  81. $json['code'] = '0';
  82. $json['info'] = '返回产品数据成功';
  83. $json['area_num'] = $area_num;
  84. $json['list'] = $line_info[0];
  85. return $json;
  86. }
  87. /**
  88. * 上车下车站点为区域,获取该区域内的站点信息
  89. * 温依莅
  90. * @param $param
  91. */
  92. public function getDetailStation($param)
  93. {
  94. //根据传过来的区域res_id,得到下属的站点信息列表
  95. $valid = zzcsUtils::validateParams(
  96. array('res_id' => 'amount'), $param); //参数验证
  97. $res_id = trim($param['res_id']);
  98. if (!$valid['status']) {
  99. $json['code'] = (string)$valid['status'];
  100. $json['info'] = $json['info'];
  101. return $json;
  102. }
  103. $sql = "select res_id as sub_res_id,parent_id as parent_res_id,res_name as sub_res_name from base_resource where parent_id=$res_id and CANCEL_FLAG=0 and ZONE_MARK=0;";
  104. $res = $this->query($sql);
  105. if (false === $res) {
  106. $json['code'] = '1';
  107. $json['info'] = '获取失败' . $sql;
  108. return $json;
  109. } else if (count($res) == 0) {
  110. $json['code'] = '2';
  111. $json['info'] = '此区域无站点信息';
  112. $json['list'] = array();
  113. return $json;
  114. } else {
  115. $json['code'] = '0';
  116. $json['info'] = '返回区域站点信息成功';
  117. $json['list'] = $res;
  118. return $json;
  119. }
  120. }
  121. /**
  122. * Function Description:根据user_id获取所属的运营主体main_corp_id
  123. * Function Name: getMainCorpId
  124. * @param int $user_id 用户id
  125. *
  126. * @return int 运营主体id
  127. *
  128. * @author 温依莅
  129. */
  130. public function getMainCorpId($user_id=-1)
  131. {
  132. //如果未传user_id,使用cookie中的user_id
  133. if($user_id==-1){
  134. $user_id=$this->user_id;
  135. }
  136. $user_id=$user_id+0;
  137. //如果根据user_id未查到相应的main_corp_id,则使用cookie中的main_corp_id,如果cookie中没有,返回-1
  138. $sql = 'select id,main_corp_id from base_user where id=' . $user_id . ' limit 1';
  139. $res = $this->query($sql);
  140. if (count($res) == 0) {
  141. $real_main_corp_id=isset($_COOKIE['user_main_corp'])?$_COOKIE['user_main_corp']:-1;
  142. }else{
  143. $real_main_corp_id = $res[0]['main_corp_id'];
  144. }
  145. return $real_main_corp_id;
  146. }
  147. /**
  148. * Function Description:根据运营主体获取班次可售票种信息(判断是自营还是代收)
  149. * Function Name: getAgentTicket
  150. * @param int $run_id
  151. * @param int $main_corp_id
  152. *
  153. * @return array
  154. *
  155. * @author 温依莅
  156. */
  157. public function getAgentTicket($run_id, $main_corp_id = -1)
  158. {
  159. $user_id = $this->user_id + 0;
  160. //如果未传main_corp_id,则使用user_id所属的main_corp_id
  161. if ($main_corp_id == -1) {
  162. $sql = 'select id,main_corp_id from base_user where id=' . $user_id . ' limit 1';
  163. $res = $this->query($sql);
  164. if (count($res) == 0) {
  165. $json['code'] = '1';
  166. $json['info'] = '用户信息错误';
  167. return $json;
  168. }
  169. $real_main_corp_id = $res[0]['main_corp_id'];
  170. } else {
  171. $real_main_corp_id = $main_corp_id;
  172. }
  173. if($real_main_corp_id==0){
  174. $real_main_corp_id=1;//main_corp_id是0的视为 蜘蛛国旅运营主体
  175. }
  176. //根据线路的运营主体判断是自营线路还是代售线路,根据运营主体,和班次得到该线路可售票种(自营线路或代收线路的票种)
  177. $sql = 'select a.line_id,b.run_id,b.run_date,a.main_corp_id from opera_line a left join run_main b on a.line_id=b.prod_id where b.run_id=' . $run_id . ' limit 1';
  178. $res2 = $this->query($sql);
  179. if (count($res) == 0) {
  180. $json['code'] = '2';
  181. $json['info'] = '班次信息错误';
  182. return $json;
  183. }
  184. #如果是自营线路->opera_tickets,代售->opera_tickets_agent
  185. $is_agent = 0;
  186. if ($res2[0]['main_corp_id'] == $real_main_corp_id) {
  187. $sql_alt = 'select group_concat(ticket_id) as tickets from opera_tickets where cancel_flag=0 and is_onsale=1 and line_id=' . $res2[0]['line_id'];
  188. //$res_self = $this->query($sql_self);
  189. } else {
  190. $is_agent = 1;
  191. $sql_alt = 'select group_concat(ticket_id) as tickets from opera_tickets_agent where cancel_flag=0 and authority_status=1 and is_onsale=1 and line_id=' . $res2[0]['line_id'] . ' and to_main_corp_id=' . $real_main_corp_id;
  192. //$res_self = $this->query($sql_agent);
  193. }
  194. $res3 = $this->query($sql_alt);
  195. if (!$res3[0]['tickets']) {
  196. $json['code'] = '3';
  197. $json['info'] = '该班次无有效票种';
  198. return $json;
  199. }
  200. $json['code'] = '0';
  201. $json['info'] = '返回可用票种成功';
  202. $json['is_agent'] = $is_agent;
  203. $json['tickets'] = $res3[0]['tickets'];
  204. return $json;
  205. }
  206. /**
  207. * 获取上车站点
  208. * @param $param
  209. */
  210. public function getStartStation($param)
  211. {
  212. $run_id = isset($param['run_id']) ? trim($param['run_id']) : false;//班次id;
  213. $start_area_id = isset($param['start_area_id']) ? trim($param['start_area_id']) : false;//出发地id;
  214. if (!$run_id || !$start_area_id) {
  215. $json['code'] = '2';
  216. $json['info'] = '缺少必要参数';
  217. return $json;
  218. }
  219. //根据run_id,和main_corp_id得到,可售票种(自营或代售的票种)
  220. $arr = $this->getAgentTicket($run_id);
  221. if ($arr['code'] != '0') {
  222. $json['code'] = '2';
  223. $json['info'] = $arr['info'];
  224. return $json;
  225. }
  226. $tickets = $arr['tickets'];
  227. $tickets_str = '(' . $tickets . ')';
  228. $sql = "SELECT
  229. a.start_station_res_id as res_id,
  230. (SELECT res_name FROM base_resource WHERE res_id = a.start_station_res_id LIMIT 1) as res_name,
  231. (SELECT start_time from run_station where run_id = a.run_id and station_res_id = a.start_station_res_id LIMIT 1) as res_time
  232. FROM
  233. run_prod a
  234. LEFT JOIN run_station b ON a.run_id=b.run_id and a.start_station_res_id=b.station_res_id
  235. WHERE
  236. a.run_id = " . $run_id . "
  237. AND a.start_station_area_id = " . $start_area_id . "
  238. AND a.cancel_flag = 0
  239. AND b.station_inout_type in (108,109)
  240. AND a.prod_id in $tickets_str
  241. GROUP BY a.start_station_res_id";
  242. $start_station = $this->query($sql);
  243. if (count($start_station) == 0) {
  244. $json['code'] = '1';
  245. $json['info'] = '没有上车站';
  246. return $json;
  247. }
  248. $json['code'] = '0';
  249. $json['info'] = '返回上车站点数据成功';
  250. $json['list'] = $start_station;
  251. return $json;
  252. }
  253. /**
  254. * 根据班次id得到该班次是否有站点是区域
  255. * 温依莅
  256. * @param $param
  257. */
  258. public function judgeArea($param)
  259. {
  260. //判断参数
  261. $valid = zzcsUtils::validateParams(
  262. array(
  263. 'run_id' => 'number',
  264. ), $param); //参数验证
  265. if (!$valid['status']) {
  266. $result['code'] = (string)$valid['status'];
  267. $result['info'] = $valid['info'];
  268. return $result;
  269. }
  270. //获取该班次的站点中站点为区域的数量
  271. $sql = 'SELECT sum(b.ZONE_MARK) as area_num FROM `run_station` a left join base_resource b on a.STATION_RES_ID=b.RES_ID where run_id=' . $param['run_id'];
  272. $res = $this->query($sql);
  273. if (false === $res) {
  274. $json['code'] = '1';
  275. $json['info'] = '获取数据失败';
  276. return $json;
  277. }
  278. $total_num = $res[0]['area_num'];
  279. $json['code'] = '0';
  280. $json['info'] = '返回班次区域数量成功';
  281. $json['num'] = $total_num;
  282. return $json;
  283. }
  284. /**
  285. * 获取下车站点(在该接口里加入获取上车区域具体站点功能--温依莅)
  286. * @param $param
  287. */
  288. public function getEndStation($param)
  289. {
  290. $run_id = isset($param['run_id']) ? trim($param['run_id']) : false;//班次id;
  291. $start_res_id = isset($param['start_res_id']) ? trim($param['start_res_id']) : false;//出发站点id;
  292. $end_area_id = isset($param['end_area_id']) ? trim($param['end_area_id']) : false;//目的地id;
  293. if (!$run_id || !$start_res_id || !$end_area_id) {
  294. $json['code'] = '2';
  295. $json['info'] = '缺少必要参数';
  296. return $json;
  297. }
  298. //根据run_id,和main_corp_id得到,可售票种(自营或代售的票种)
  299. $arr = $this->getAgentTicket($run_id);
  300. if ($arr['code'] != '0') {
  301. $json['code'] = '2';
  302. $json['info'] = $arr['info'];
  303. return $json;
  304. }
  305. $tickets = $arr['tickets'];
  306. $tickets_str = '(' . $tickets . ')';
  307. $sql = "SELECT
  308. a.end_station_res_id as res_id,
  309. (SELECT zone_mark FROM base_resource WHERE res_id = a.end_station_res_id LIMIT 1) as zone_mark,
  310. (SELECT res_name FROM base_resource WHERE res_id = a.end_station_res_id LIMIT 1) as res_name,
  311. (SELECT start_time from run_station where run_id = a.run_id and station_res_id = a.end_station_res_id LIMIT 1) as res_time
  312. FROM
  313. run_prod a
  314. LEFT JOIN run_station b ON a.run_id=b.run_id and a.end_station_res_id=b.station_res_id
  315. WHERE
  316. a.run_id = " . $run_id . "
  317. AND a.end_station_area_id = " . $end_area_id . "
  318. AND a.cancel_flag = 0
  319. AND b.station_inout_type in (109,110)
  320. AND a.start_station_res_id = " . $start_res_id . "
  321. AND a.prod_id in $tickets_str
  322. GROUP BY a.end_station_res_id";
  323. $end_station = $this->query($sql);
  324. if (count($end_station) == 0) {
  325. $json['code'] = '1';
  326. $json['info'] = '没有下车站';
  327. return $json;
  328. }
  329. //以下加入 得到(上车站点若为区域时)的具体站点信息功能---温依莅
  330. #上车区域附属站点信息
  331. $par['res_id'] = $start_res_id;
  332. $res = $this->getDetailStation($par);
  333. if ($res['code'] == '1') { //数据库错误直接返回
  334. $json['code'] = '1';
  335. $json['info'] = '获取失败';
  336. return $json;
  337. } else {
  338. $start_detail = $res['list']; //返回区域下属站点信息
  339. }
  340. //以上,得到区域站点信息结束
  341. //返回信息
  342. $json['code'] = '0';
  343. $json['info'] = '返回下车站点数据成功';
  344. $json['list'] = $end_station;
  345. $json['start_detail'] = '';//$start_detail;
  346. return $json;
  347. }
  348. /**
  349. * 获取票种信息
  350. * @param $param
  351. */
  352. public function getTicketInfo($param)
  353. {
  354. $channel_id = isset($param['channel_id']) ? trim($param['channel_id']) : false;//渠道商id;
  355. $run_id = isset($param['run_id']) ? trim($param['run_id']) : false;//班次id;
  356. $start_res_id = isset($param['start_res_id']) ? trim($param['start_res_id']) : false;//出发站点id;
  357. $end_res_id = isset($param['end_res_id']) ? trim($param['end_res_id']) : false;//目的站点id;
  358. $line_type = isset($param['line_type']) ? trim($param['line_type']) : false;//线路类型;
  359. if (!$run_id || !$start_res_id || !$end_res_id || !$channel_id || !$line_type) {
  360. $json['code'] = '2';
  361. $json['info'] = '缺少必要参数';
  362. return $json;
  363. }
  364. //判断是否是代售
  365. $arr = $this->getAgentTicket($run_id);
  366. if ($arr['code'] != '0') {
  367. $json['code'] = '2';
  368. $json['info'] = $arr['info'];
  369. return $json;
  370. }
  371. $is_agent = $arr['is_agent'];
  372. $opera_ticket_name = $is_agent ? 'opera_tickets_agent' : 'opera_tickets';
  373. $main_corp_id=$this->getMainCorpId();
  374. if($main_corp_id==0){
  375. $main_corp_id=1;
  376. }
  377. $agent_condition=$is_agent?"and a.to_main_corp_id=$main_corp_id":'';
  378. $sql = "SELECT
  379. a.ticket_id,a.seat_type,
  380. (SELECT type_name FROM dict_type WHERE id = a.seat_type LIMIT 1) AS seat_type_name,
  381. a.human_type,
  382. (SELECT type_name FROM dict_type WHERE id = a.human_type LIMIT 1) AS human_type_name,
  383. a.prod_price, a.cus_price,
  384. (
  385. SELECT
  386. min(total_count - saled_count)
  387. FROM
  388. run_stock
  389. WHERE
  390. run_id = " . $run_id . "
  391. AND cancel_flag = 0
  392. AND seq_id >= (SELECT seq_id FROM run_stock WHERE run_id = " . $run_id . " AND cancel_flag = 0 AND res_id = " . $start_res_id . " AND seat_type = a.seat_type limit 1)
  393. AND seq_id < (SELECT seq_id FROM run_stock WHERE run_id = " . $run_id . " AND cancel_flag = 0 AND res_id = " . $end_res_id . " AND seat_type = a.seat_type limit 1)
  394. AND seat_type = a.seat_type
  395. ) AS stock
  396. FROM
  397. $opera_ticket_name as a
  398. WHERE
  399. ticket_type = 1
  400. and cancel_flag=0
  401. $agent_condition
  402. AND ticket_id IN (
  403. SELECT
  404. prod_id
  405. FROM
  406. run_prod
  407. WHERE
  408. run_id = " . $run_id . "
  409. AND start_station_res_id = " . $start_res_id . "
  410. AND end_station_res_id = " . $end_res_id . "
  411. )";
  412. //zzcsUtils::writeLog($sql);
  413. $ticket_info = $this->query($sql);
  414. if (false === $ticket_info) {
  415. $json['code'] = '2';
  416. $json['info'] = '获取该渠道票种失败';
  417. return $json;
  418. }
  419. if (count($ticket_info) == 0) {
  420. $json['code'] = '1';
  421. $json['info'] = '该渠道无可销售的票种';
  422. return $json;
  423. }
  424. foreach ($ticket_info as $k => $v) {
  425. $sale_type = $this->getTicketChannelSaleType($channel_id, $v['ticket_id'], $line_type);//获取销售类型
  426. if ($sale_type)//如果该销售方式被关掉
  427. {
  428. if ($sale_type['sale_type'] == "177") {
  429. if ($sale_type['price'] == '0') {
  430. $ticket_info[$k]['price'] = $v['prod_price'];
  431. } else {
  432. $ticket_info[$k]['price'] = $sale_type['price'];
  433. }
  434. } else {
  435. $ticket_info[$k]['price'] = $v['cus_price'];
  436. }
  437. } else {
  438. unset($ticket_info[$k]);
  439. }
  440. }
  441. $json['code'] = '0';
  442. $json['info'] = '返回票种信息成功';
  443. $json['list'] = $ticket_info;
  444. return $json;
  445. }
  446. /**
  447. * 获取返程的班次情况
  448. * @param $param
  449. * @return mixed
  450. */
  451. public function getBackProductList($param)
  452. {
  453. $run_date = isset($param['run_date']) ? (empty($param['run_date']) ? date('Y-m-d', time()) : trim($param['run_date'])) : false;//返程出发日期
  454. $start_area = isset($param['start_area']) ? (empty($param['start_area']) ? "''" : "'" . trim($param['start_area']) . "'") : false;//出发地
  455. $end_area = isset($param['end_area']) ? (empty($param['end_area']) ? "''" : "'" . trim($param['end_area']) . "'") : false;//目的地
  456. $line_type = isset($param['line_type']) ? trim($param['line_type']) : false;//线路类型;
  457. $now_date = date('Y-m-d', time());
  458. if (!$run_date || !$start_area || !$end_area || !$line_type) {
  459. $json['code'] = '2';
  460. $json['info'] = '缺少必要参数';
  461. return $json;
  462. }
  463. $sql = "SELECT
  464. m.run_id,
  465. m.run_time
  466. FROM
  467. run_main AS m,
  468. run_prod AS p,
  469. opera_line AS l
  470. WHERE
  471. m.run_id = p.run_id
  472. AND m.prod_id = l.line_id
  473. AND p.start_station_area_id = " . $start_area . "
  474. AND p.end_station_area_id = " . $end_area . "
  475. AND m.run_date = '" . $run_date . "'
  476. AND m.run_status not in(137,142)
  477. AND l.line_type = " . $line_type . "
  478. GROUP BY m.run_id order by m.run_time ASC";
  479. $run_list = $this->query($sql);
  480. if (count($run_list) == 0) {
  481. $json['code'] = '1';
  482. $json['info'] = '没有符合的班次情况';
  483. return $json;
  484. }
  485. $json['code'] = '0';
  486. $json['info'] = '返回班次列表成功';
  487. $json['run_list'] = $run_list;
  488. return $json;
  489. }
  490. /**
  491. * 获取去程票种的订单渠道
  492. */
  493. public function getGoChannel($param)
  494. {
  495. $run_id = isset($param['run_id']) ? trim($param['run_id']) : false;//班次id;
  496. $start_res_id = isset($param['start_res_id']) ? trim($param['start_res_id']) : false;//出发站点id;
  497. $end_res_id = isset($param['end_res_id']) ? trim($param['end_res_id']) : false;//目的站点id;
  498. $line_type = isset($param['line_type']) ? trim($param['line_type']) : false;//线路类型;
  499. if (!$run_id || !$start_res_id || !$end_res_id || !$line_type) {
  500. $json['code'] = '2';
  501. $json['info'] = '缺少必要参数';
  502. return $json;
  503. }
  504. $date_month = date('Y-m', strtotime("-1 month "));
  505. //$main_corp_id = isset($_COOKIE["user_main_corp"]) ? $_COOKIE["user_main_corp"] : 0;
  506. $main_corp_id=$this->getMainCorpId($this->user_id);
  507. $extra_sql = "";
  508. if ($main_corp_id > 0) {
  509. $extra_sql = $main_corp_id == 1 ? " AND b.MAIN_CORP_ID = $main_corp_id " : " AND b.MAIN_CORP_ID IN(0,{$main_corp_id}) ";
  510. }
  511. //原厦门渠道,暂不再虑
  512. /*if ($main_corp_id != 3) {
  513. $extra_sql = " AND b.MAIN_CORP_ID NOT IN(3) ";
  514. }*/
  515. //如果只需要一个渠道商信息
  516. $where_supplier = isset($param['supplier_id']) ? " and a.supplier_id = " . $param['supplier_id'] : "";
  517. $sql = "SELECT
  518. a.supplier_id,b.supplier_name,b.sales_man
  519. FROM
  520. base_supplier_sale AS a
  521. INNER JOIN base_supplier AS b ON a.supplier_id = b.id
  522. LEFT JOIN base_supplier_sequence AS s ON b.id = s.supplier_id and s.date_month = '" . $date_month . "'
  523. WHERE
  524. a.parent_type = 310
  525. $where_supplier
  526. AND a.product_type in (" . $line_type . ",0)
  527. AND a.cancel_flag = 0
  528. AND b.cancel_flag = 0
  529. {$extra_sql}
  530. AND b.is_disabled = 0
  531. AND a.supplier_id NOT IN (
  532. SELECT supplier_id FROM opera_tickets_distrib
  533. WHERE cancel_flag = 0
  534. AND authority_status = 0
  535. AND ticket_id IN (
  536. SELECT
  537. prod_id
  538. FROM
  539. run_prod
  540. WHERE
  541. run_id = " . $run_id . "
  542. AND start_station_res_id = " . $start_res_id . "
  543. AND end_station_res_id = " . $end_res_id . "
  544. )
  545. )
  546. GROUP BY
  547. a.supplier_id
  548. ORDER BY
  549. s.order_num DESC,s.person_trip DESC,s.sales DESC";
  550. $channel_list = $this->query($sql);
  551. if (count($channel_list) == 0) {
  552. $json['code'] = '0';
  553. $json['info'] = '无销售渠道';
  554. $json['list'] = array();
  555. return $json;
  556. }
  557. //以下加入 得到(下车站点若为区域时)的具体站点信息功能---温依莅
  558. #下车区域附属站点信息
  559. $par['res_id'] = $end_res_id;
  560. $res = $this->getDetailStation($par);
  561. if ($res['code'] == '1') { //数据库错误直接返回
  562. $json['code'] = '1';
  563. $json['info'] = $res['info'];
  564. return $json;
  565. } else {
  566. $end_detail = $res['list']; //返回区域下属站点信息
  567. }
  568. //以上,得到区域站点信息结束
  569. /*$end_detail=array(
  570. '0'=>array('parent_res_id'=>'10368','sub_res_id'=>'10369','sub_res_name'=>'厦门安兜'),
  571. '1'=>array('parent_res_id'=>'10368','sub_res_id'=>'10370','sub_res_name'=>'厦门车管所车站'),
  572. '2'=>array('parent_res_id'=>'10368','sub_res_id'=>'10371','sub_res_name'=>'厦门大唐世家')
  573. );*/
  574. $json['code'] = '0';
  575. $json['info'] = '返回渠道商信息成功';
  576. $json['list'] = $channel_list;
  577. $json['end_detail'] = $end_detail;
  578. return $json;
  579. }
  580. /**
  581. * 获取返程票种和去程票种清单渠道的交集
  582. * @param $param
  583. */
  584. public function getBackChannel($param)
  585. {
  586. $go_run_id = isset($param['go_run_id']) ? trim($param['go_run_id']) : false;//去程班次id;
  587. $go_start_res_id = isset($param['go_start_res_id']) ? trim($param['go_start_res_id']) : false;//去程出发站点id;
  588. $go_end_res_id = isset($param['go_end_res_id']) ? trim($param['go_end_res_id']) : false;//去程目的站点id;
  589. $back_run_id = isset($param['back_run_id']) ? trim($param['back_run_id']) : false;//反程班次id;
  590. $back_start_res_id = isset($param['back_start_res_id']) ? trim($param['back_start_res_id']) : false;//反程出发站点id;
  591. $back_end_res_id = isset($param['back_end_res_id']) ? trim($param['back_end_res_id']) : false;//反程目的站点id;
  592. $line_type = isset($param['line_type']) ? trim($param['line_type']) : false;//线路类型;
  593. if (!$go_run_id || !$go_start_res_id || !$go_end_res_id || !$line_type || !$back_run_id || !$back_start_res_id || !$back_end_res_id) {
  594. $json['code'] = '2';
  595. $json['info'] = '缺少必要参数';
  596. return $json;
  597. }
  598. $go_array = array(
  599. 'run_id' => $go_run_id,
  600. 'start_res_id' => $go_start_res_id,
  601. 'end_res_id' => $go_end_res_id,
  602. 'line_type' => $line_type
  603. );
  604. $back_array = array(
  605. 'run_id' => $back_run_id,
  606. 'start_res_id' => $back_start_res_id,
  607. 'end_res_id' => $back_end_res_id,
  608. 'line_type' => $line_type
  609. );
  610. $go_channel_list = $this->getGoChannel($go_array);
  611. $back_channel_list = $this->getGoChannel($back_array);
  612. $go_channel_list = $go_channel_list['list'];
  613. $back_channel_list = $back_channel_list['list'];
  614. $channel_list = array();
  615. if (count($go_channel_list) > 0 && count($back_channel_list) > 0) {
  616. foreach ($go_channel_list as $k => $v) {
  617. $channel_list1[$v['supplier_id']] = $v;
  618. }
  619. foreach ($back_channel_list as $k => $v) {
  620. $channel_list2[$v['supplier_id']] = $v;
  621. }
  622. foreach ($channel_list1 as $k => $v) {
  623. if (isset($channel_list2[$k])) {
  624. $channel_list[] = $v;
  625. }
  626. }
  627. }
  628. $json['code'] = '0';
  629. $json['info'] = '返回渠道列表信息成功';
  630. $json['list'] = $channel_list;
  631. return $json;
  632. }
  633. /**
  634. * 获取返程的票种详情
  635. * @param $param
  636. */
  637. public function getBackTicketInfo($param)
  638. {
  639. $channel_id = isset($param['channel_id']) ? trim($param['channel_id']) : false;//渠道商id;
  640. $go_run_id = isset($param['go_run_id']) ? trim($param['go_run_id']) : false;//去程班次id;
  641. $go_start_res_id = isset($param['go_start_res_id']) ? trim($param['go_start_res_id']) : false;//去程出发站点id;
  642. $go_end_res_id = isset($param['go_end_res_id']) ? trim($param['go_end_res_id']) : false;//去程目的站点id;
  643. $back_run_id = isset($param['back_run_id']) ? trim($param['back_run_id']) : false;//反程班次id;
  644. $back_start_res_id = isset($param['back_start_res_id']) ? trim($param['back_start_res_id']) : false;//反程出发站点id;
  645. $back_end_res_id = isset($param['back_end_res_id']) ? trim($param['back_end_res_id']) : false;//反程目的站点id;
  646. $line_type = isset($param['line_type']) ? trim($param['line_type']) : false;//线路类型;
  647. if (!$channel_id || !$go_run_id || !$go_start_res_id || !$go_end_res_id || !$line_type || !$back_run_id || !$back_start_res_id || !$back_end_res_id) {
  648. $json['code'] = '2';
  649. $json['info'] = '缺少必要参数';
  650. return $json;
  651. }
  652. $go_array = array(
  653. 'channel_id' => $channel_id,
  654. 'run_id' => $go_run_id,
  655. 'start_res_id' => $go_start_res_id,
  656. 'end_res_id' => $go_end_res_id,
  657. 'line_type' => $line_type
  658. );
  659. $back_array = array(
  660. 'channel_id' => $channel_id,
  661. 'run_id' => $back_run_id,
  662. 'start_res_id' => $back_start_res_id,
  663. 'end_res_id' => $back_end_res_id,
  664. 'line_type' => $line_type
  665. );
  666. //获取去程票种详情
  667. $go_ticket_info = $this->getTicketInfo($go_array);
  668. if ($go_ticket_info['code'] != '0') {
  669. $json['code'] = '1';
  670. $json['info'] = '去程有问题';
  671. return $json;
  672. }
  673. $go_ticket_info = $go_ticket_info['list'];
  674. //获取返程票种详情
  675. $back_ticket_info = $this->getTicketInfo($back_array);
  676. if ($back_ticket_info['code'] != '0') {
  677. $json['code'] = '1';
  678. $json['info'] = '返程有问题';
  679. return $json;
  680. }
  681. $back_ticket_info = $back_ticket_info['list'];
  682. foreach ($go_ticket_info as $k => $v) {
  683. $go_ticket_array[$v['seat_type'] . "-" . $v['human_type']] = $v;
  684. $ticket_array_id[] = $v['ticket_id'];
  685. }
  686. foreach ($back_ticket_info as $k => $v) {
  687. $back_ticket_array[$v['seat_type'] . "-" . $v['human_type']] = $v;
  688. $ticket_array_id[] = $v['ticket_id'];
  689. }
  690. //获取促销优惠
  691. $sql = "SELECT
  692. ticket_id,
  693. off_value
  694. FROM
  695. opera_tickets_discount
  696. WHERE
  697. ticket_id IN (" . implode(",", $ticket_array_id) . ")
  698. AND supplier_id = " . $channel_id . "
  699. AND is_onsale = 1
  700. AND cancel_flag = 0
  701. AND discount_type = 332
  702. AND discount_day_type = 0
  703. GROUP BY ticket_id";
  704. //zzcsUtils::writeLog($sql);
  705. $discount_info = $this->query($sql);
  706. if (false === $discount_info) {
  707. $json['code'] = '1';
  708. $json['info'] = '获取促销优惠失败';
  709. return $json;
  710. }
  711. $discount_info_array = array();
  712. if (count($discount_info) > 0) {
  713. foreach ($discount_info as $k => $v) {
  714. $discount_info_array[$v['ticket_id']] = $v['off_value'];
  715. }
  716. }
  717. foreach ($go_ticket_array as $k => $v) {
  718. if (isset($back_ticket_array[$k])) {
  719. $go_discount = '0';
  720. if (isset($discount_info_array[$go_ticket_array[$k]['ticket_id']])) {
  721. $go_discount = $discount_info_array[$go_ticket_array[$k]['ticket_id']];
  722. }
  723. $back_discount = '0';
  724. if (isset($discount_info_array[$back_ticket_array[$k]['ticket_id']])) {
  725. $back_discount = $discount_info_array[$back_ticket_array[$k]['ticket_id']];
  726. }
  727. $ticket_one = array(
  728. 'go_run_id' => $go_run_id,
  729. 'go_ticket_id' => $go_ticket_array[$k]['ticket_id'],
  730. 'go_price' => $go_ticket_array[$k]['price'],
  731. 'go_discount_price' => $go_ticket_array[$k]['price'] - $go_discount,
  732. 'go_discount' => $go_discount,
  733. 'go_stock' => $go_ticket_array[$k]['stock'],
  734. 'back_run_id' => $back_run_id,
  735. 'back_ticket_id' => $back_ticket_array[$k]['ticket_id'],
  736. 'back_price' => $back_ticket_array[$k]['price'],
  737. 'back_discount_price' => $back_ticket_array[$k]['price'] - $back_discount,
  738. 'back_discount' => $back_discount,
  739. 'back_stock' => $back_ticket_array[$k]['stock'],
  740. 'seat_type' => $go_ticket_array[$k]['seat_type'],
  741. 'seat_type_name' => $go_ticket_array[$k]['seat_type_name'],
  742. 'human_type' => $go_ticket_array[$k]['human_type'],
  743. 'human_type_name' => $go_ticket_array[$k]['human_type_name'],
  744. 'price' => $go_ticket_array[$k]['price'] + $back_ticket_array[$k]['price'] - $go_discount - $back_discount,
  745. 'stock' => min($go_ticket_array[$k]['stock'], $back_ticket_array[$k]['stock'])
  746. );
  747. $ticket_array[] = $ticket_one;
  748. }
  749. }
  750. $json['code'] = '0';
  751. $json['info'] = '成功';
  752. $json['list'] = $ticket_array;
  753. return $json;
  754. }
  755. /**
  756. * 提交单一线路订单(统一cs系统和厦门的单一线路下单)
  757. */
  758. public function submitOrder($param)
  759. {
  760. $valid = zzcsUtils::validateParams(
  761. array(
  762. 'channel_id,ticket_info,customer_info,travel_peoples,sub_start_res_id,sub_end_res_id,count_num' => 'empty',
  763. 'receive_value' => 'amount'
  764. ), $param); //参数验证
  765. if (!$valid['status']) {
  766. $result['code'] = (string)$valid['status'];
  767. $result['info'] = $valid['info'];
  768. return $result;
  769. }
  770. $channel_id = $param['channel_id'];//渠道商id;
  771. $channel_order_id = isset($param['channel_order_id']) ? $param['channel_order_id'] : '';
  772. $salesman = isset($param['salesman']) ? $param['salesman'] : '';
  773. $ticket_info = $param['ticket_info'];
  774. $customer_info = $param['customer_info'];
  775. $travel_peoples = $param['travel_peoples']; //fuhc 2017-11-07
  776. $receive_value = $param['receive_value'];//代收总价
  777. $count_num = $param['count_num']; //订单人数
  778. $id_card = $param['id_card']; //身份证号
  779. $door_price = $param['door_price'] ? $param['door_price'] : 0; //套餐产品--门票价格
  780. $hotel_price = $param['hotel_price'] ? $param['hotel_price'] : 0; //套餐产品--酒店价格
  781. $pay_type = 275;
  782. $start_res_id = $param['sub_start_res_id']; //如果上车为区域,传入具体上车站点res_id,否则传 0
  783. $end_res_id = $param['sub_end_res_id']; //如果下车为区域,传入具体下车站点res_id,否则传 0
  784. //customer_info中,手机和联系人只要有1个信息就可以
  785. $tmp = substr($customer_info, 1, -1);
  786. $tmpArray = explode(',', $tmp);
  787. //前台传过来的顺序不能变 1、联系人 2、手机号 3、备注 4、后期添加的新字段
  788. if (trim($tmpArray[0]) == '' && trim($tmpArray[1]) == '')
  789. $customer_info = false;
  790. $user_id = $this->user_id;
  791. $time = date('Y-m-d H:i:s', time());
  792. if (false === $channel_id || false === $ticket_info || false === $customer_info) {
  793. $json['code'] = '2';
  794. $json['info'] = '缺少必要参数';
  795. return $json;
  796. }
  797. #===================================以下 调用巴士统一下单接口下单===================================================#
  798. //1,获取参数
  799. $customer_info_arr = array($tmpArray[0], $tmpArray[1], 150, $id_card, $tmpArray[2]);
  800. $customer_info_str = '{' . implode(',', $customer_info_arr) . '}';//联系人信息,格式为{联系人,联系电话,z证件类型,联系人身份证,备注}
  801. $order_info_str = '{' . $user_id . ',' . $user_id . ',' . $channel_id . ',' . $channel_order_id . ',1,275,1,' . $salesman . '}';//'订单信息 {下单用户,会员号,渠道id,渠道订单号,是否自动退票(0否1是),支付方式(授信275),是否支付(0否1是),业务员}'
  802. $order_append_str = '{' . $door_price . ',' . $hotel_price . '}';//订单附加 ,格式为{门票价格,酒店价格}
  803. $sin_rec = round($receive_value / $count_num, 2);//单价
  804. $receiver_value_str = '{' . $sin_rec . ',' . $receive_value . '}';//代收,格式为{代收单价,代收总价}
  805. $buy_insurance = $param['buy_insurance'];//购买保险;
  806. //2,整理参数
  807. $url = 'http://' . CS1_DOMAIN . '/api/submit-order';
  808. $data = array();
  809. $data['action'] = 'submit_bus_order';
  810. $data['prod_str'] = $ticket_info;//购买票种列表 格式为{去程/返程标志(1:去程 2:返程),去程/返程班次ID,票种ID,票种单价,预定数量,车号}...
  811. $data['order_info_str'] = $order_info_str;//'订单信息 {下单用户,会员号,渠道id,渠道订单号,是否自动退票(0否1是),支付方式(授信275),是否支付(0否1是),业务员}'
  812. $data['customer_info_str'] = $customer_info_str;//联系人信息,格式为{联系人,联系电话,z证件类型,联系人身份证,备注}
  813. $data['passenger_info'] = $travel_peoples;
  814. $data['order_append_str'] = $order_append_str;//订单附加 ,格式为{门票价格,酒店价格}
  815. $data['receiver_value_str'] = $receiver_value_str;//代收,格式为{代收单价,代收总价}
  816. $data['buy_insurance'] = $buy_insurance;//购买保险
  817. $data['is_send_msg'] = 1;//是否发短信(0否1是) 默认1
  818. //3,发送请求到巴士统一下单接口
  819. $result = httpRequest($url, $data);
  820. $final_result = json_decode($result, true);
  821. return $final_result;
  822. #====================================以上 调用巴士统一下单接口下单==================================================#
  823. /*----------------原下单逻辑
  824. //如果修改了存储过程的参数,批量订单的下单的参数也要修改
  825. $sql = "call sp_make_order_xm(" . $user_id . ",'" . $ticket_info . "','" . $customer_info . "'," . $channel_id . ",'" . $channel_order_id . "','" . $salesman . "'," . $pay_type . "," . $start_res_id . "," . $end_res_id . "," . $receive_value . ")";
  826. //$sql = "call sp_make_order_xm(" . $user_id . ",'" . $ticket_info . "','" . $customer_info . "'," . $channel_id . ",'" . $channel_order_id . "','" . $salesman . "'," . $pay_type . "," . $start_res_id . "," . $end_res_id . "," . $receive_value.")";
  827. zzcsUtils::writeLog($sql);
  828. //----------------
  829. $res = $this->procQuery($sql);
  830. if ($res['code'] != 0) { //存储过程执行出错
  831. $json["code"] = (string)$res['code'];
  832. $json["info"] = $res['info'];
  833. return $json;
  834. }
  835. //下单成功后,分单程和往返程对部分信息(1,订单状态,2,联系人身份证号,3,门票价格和酒店价格,4,代收单价总价)进行修改
  836. $order_ids = $res['data'][0][0]['order_id'];
  837. $order_arr = explode(',', $order_ids);
  838. $update_sql = '';//拼接的sql语句
  839. //得到插入后的订单信息
  840. $get_sql = "SELECT
  841. a.order_id,
  842. b.run_date,
  843. a.outside_sale_org_id,
  844. c.supplier_name,
  845. b.order_price AS sin_price,
  846. a.order_price AS total_price,
  847. a.customer_name,
  848. a.customer_mobile,
  849. a.customer_id_no,
  850. a.customer_memo
  851. FROM
  852. order_main a
  853. LEFT JOIN order_main b ON a.order_id = b.PARENT_ORDER_ID
  854. left join base_supplier c on a.OUTSIDE_SALE_ORG_ID=c.ID
  855. WHERE
  856. a.order_id in ($order_ids)
  857. AND b.CANCEL_FLAG = 0
  858. AND b.ORDER_VALID_STATUS = 1
  859. group by a.order_id;";
  860. $orders = $this->query($get_sql);
  861. if (count($order_arr) == 1) {
  862. //单程下单
  863. $sin_rec = round($receive_value / $count_num, 2);//单价
  864. $total_rec = $receive_value;//总价
  865. #0写入订单日志
  866. $detail_extra = ''; //如果有套餐产品,代收单价,代收总价也记录下来
  867. $door_price && ($detail_extra .= '门票价格:' . $door_price);
  868. $hotel_price && ($detail_extra .= '酒店价格:' . $hotel_price);
  869. $total_rec && ($detail_extra .= '代收单价:' . $sin_rec . ',代收总价:' . $total_rec);
  870. $opera_detail = "创建订单,出发日期{$orders[0]['run_date']},订单渠道:{$orders[0]['supplier_name']},人数:{$count_num},金额{$orders[0]['sin_price']}总额{$orders[0]['total_price']}" . $detail_extra . ",联系人信息:{$orders[0]['customer_name']},{$orders[0]['customer_mobile']},{$id_card},备注信息:{$orders[0]['customer_memo']}";
  871. $update_sql .= "insert into order_opera_log(order_id,opera_user_id,opera_type,opera_time,opera_detail,opera_platform) VALUES ({$orders[0]['order_id']},$user_id,1,'{$time}','{$opera_detail}','CS系统');";
  872. #1修改代收价(主订单代收总价,子订单代收单价)
  873. $update_sql .= "UPDATE order_main SET RECEIVE_VALUE=$total_rec WHERE order_id in ($order_ids) ;UPDATE order_main SET RECEIVE_VALUE=$sin_rec WHERE parent_order_id in($order_ids);";
  874. #2修改订单状态和联系人身份证号
  875. $update_sql .= "UPDATE order_main
  876. SET update_user_id = " . $user_id . ",
  877. update_time = '" . $time . "',
  878. order_status = 146,
  879. customer_id_no ='$id_card'
  880. WHERE
  881. order_id in ($order_ids)
  882. OR parent_order_id in ($order_ids);";
  883. #3对order_extra_info表插入(如果门票价格和酒店价格有一个不为空则插入)
  884. if ($hotel_price || $door_price) {
  885. $update_sql .= "INSERT INTO order_extra_info (
  886. order_id,
  887. hotel_price,
  888. gate_price
  889. )
  890. VALUES
  891. ($order_arr[0], $hotel_price, $door_price);";
  892. }
  893. zzcsUtils::writeLog($update_sql);
  894. $res2 = $this->exec($update_sql);
  895. if (false === $res2) {
  896. $json['code'] = '1';
  897. $json['info'] = '增加单程订单项失败';
  898. return $json;
  899. }
  900. //region 短信发送模块
  901. #对时间和班次发车时间做判断,如果当前时间小于发车时间则发送短信
  902. $time_diff = $this->get_time_diff($order_arr[0]);
  903. if ($time_diff >= 0) {
  904. //$res_content = $this->send_msg($order_arr[0]);
  905. $url = 'http://' . CS1_DOMAIN . '/api/msg/order-send-msg';
  906. $sendInfo = array();
  907. $sendInfo['order_id'] = $order_arr[0];
  908. $sendInfo['msg_type'] = 'cs';
  909. $res_content = httpRequest($url, $sendInfo);
  910. }
  911. //endregion
  912. } else if (count($order_arr) == 2) {
  913. //往返程下单
  914. $sin_rec = round($receive_value / (2 * $count_num), 2);//单价
  915. $total_rec = $receive_value / 2;//总价
  916. #0写入订单日志
  917. $detail_extra = ''; //如果有套餐产品,代收单价,代收总价也记录下来
  918. $door_price && ($detail_extra .= '门票价格:' . $door_price);
  919. $hotel_price && ($detail_extra .= '酒店价格:' . $hotel_price);
  920. $total_rec && ($detail_extra .= '代收单价:' . $sin_rec . ',代收总价:' . $total_rec);
  921. $opera_detail1 = "创建订单,出发日期{$orders[0]['run_date']},订单渠道:{$orders[0]['supplier_name']},人数:{$count_num},金额{$orders[0]['sin_price']}总额{$orders[0]['total_price']}" . $detail_extra . ",联系人信息:{$orders[0]['customer_name']},{$orders[0]['customer_mobile']},{$id_card},备注信息:{$orders[0]['customer_memo']}";
  922. $opera_detail2 = "创建订单,出发日期{$orders[1]['run_date']},订单渠道:{$orders[1]['supplier_name']},人数:{$count_num},金额{$orders[1]['sin_price']}总额{$orders[1]['total_price']}" . $detail_extra . ",联系人信息:{$orders[1]['customer_name']},{$orders[1]['customer_mobile']},{$id_card},备注信息:{$orders[1]['customer_memo']}";
  923. $update_sql .= "insert into order_opera_log(order_id,opera_user_id,opera_type,opera_time,opera_detail,opera_platform) VALUES ({$orders[0]['order_id']},$user_id,1,'{$time}','{$opera_detail1}','CS系统'),({$orders[1]['order_id']},$user_id,1,'{$time}','{$opera_detail2}','CS系统');";
  924. #1修改代收价(主订单总价,子订单单价)
  925. $update_sql .= "UPDATE order_main SET RECEIVE_VALUE=$total_rec WHERE order_id in ($order_ids) ;UPDATE order_main SET RECEIVE_VALUE=$sin_rec WHERE parent_order_id in($order_ids);";
  926. #2修改订单状态和联系人身份证号
  927. $update_sql .= "UPDATE order_main
  928. SET update_user_id = " . $user_id . ",
  929. update_time = '" . $time . "',
  930. order_status = 146,
  931. customer_id_no ='$id_card'
  932. WHERE
  933. order_id in ($order_ids)
  934. OR parent_order_id in ($order_ids);";
  935. #3对order_extra_info表插入(如果门票价格和酒店价格有一个不为空则插入)
  936. if ($hotel_price || $door_price) {
  937. $update_sql .= "INSERT INTO order_extra_info (
  938. order_id,
  939. hotel_price,
  940. gate_price
  941. )
  942. VALUES
  943. ($order_arr[0], $hotel_price, $door_price),
  944. ($order_arr[1], $hotel_price, $door_price);";
  945. }
  946. zzcsUtils::writeLog($update_sql);
  947. $res2 = $this->exec($update_sql);
  948. if (false === $res2) {
  949. $json['code'] = '1';
  950. $json['info'] = '增加往返程订单项失败';
  951. return $json;
  952. }
  953. //往返订单需要插入关联表
  954. $sql = "insert into to_from(to_orderid,back_orderid) VALUES ({$order_arr[0]},{$order_arr[1]})";
  955. $result = $this->exec($sql);
  956. //region 短信发送模块
  957. #对时间和班次发车时间做判断,如果当前时间小于发车时间则发送短信
  958. $time_diff1 = $this->get_time_diff($order_arr[0]);
  959. if ($time_diff1 >= 0) {
  960. //$res_content1 = $this->send_msg($order_arr[0]);
  961. $url = 'http://' . CS1_DOMAIN . '/api/msg/order-send-msg';
  962. $sendInfo = array();
  963. $sendInfo['order_id'] = $order_arr[0];
  964. $sendInfo['msg_type'] = 'cs';
  965. $res_content = httpRequest($url, $sendInfo);
  966. }
  967. $time_diff2 = $this->get_time_diff($order_arr[1]);
  968. if ($time_diff2 >= 0) {
  969. //$res_content2 = $this->send_msg($order_arr[1]);
  970. $url = 'http://' . CS1_DOMAIN . '/api/msg/order-send-msg';
  971. $sendInfo = array();
  972. $sendInfo['order_id'] = $order_arr[1];
  973. $sendInfo['msg_type'] = 'cs';
  974. $res_content = httpRequest($url, $sendInfo);
  975. }
  976. //endregion
  977. }
  978. //添加订单状态记录
  979. $post_data['order_id'] = $order_ids;
  980. $post_data['order_status'] = "451,452,453";
  981. $res = $this->post2("http://" . CS_DOMAIN . "/st-xm/Api/add_order_status_log.php", $post_data);//这里线下测试时应该屏蔽掉,否则会把数据插入到正式数据库
  982. $final_json["code"] = '0';
  983. $final_json["info"] = '下单成功';
  984. return $final_json;*/
  985. }
  986. /**
  987. * Function Description:根据订单id得到 【(班次发车时间-现在时间)的时间戳差值】
  988. * Function Name: get_run_time
  989. * @param $order_id
  990. * @author 温依莅
  991. */
  992. public function get_time_diff($order_id)
  993. {
  994. $now = time();
  995. //$sql="select b.run_date,b.RUN_MINUTES,(UNIX_TIMESTAMP(b.run_date)+b.run_minutes*60) as stamp from order_main a left join run_main b on a.run_id=b.run_id where a.PARENT_ORDER_ID=$order_id limit 1";
  996. $sql = "select b.run_date,b.RUN_MINUTES,(UNIX_TIMESTAMP(b.run_date)) as stamp from order_main a left join run_main b on a.run_id=b.run_id where a.PARENT_ORDER_ID=$order_id limit 1";
  997. $res = $this->query($sql);
  998. $run_stamp = $res[0]['stamp'];
  999. return ($run_stamp + 3600 * 24) - $now;
  1000. }
  1001. /**
  1002. * Function Description:发短信
  1003. * Function Name: send_msg
  1004. * @param $ORDER_ID
  1005. *
  1006. * @return array|bool|string
  1007. *
  1008. */
  1009. public function send_msg($ORDER_ID)
  1010. {
  1011. $order_id = $ORDER_ID;
  1012. $res_content = $this->get_msg_info($order_id);
  1013. if (false == $res_content) {
  1014. return false;
  1015. }
  1016. //$url = BASE_TICKET_URL.$order_id;
  1017. //$short_url = sinaShortenUrl(filterUrl($url)); //根据传入的长网址生产短网址
  1018. $name = $res_content[0];
  1019. $tel = $res_content[1];
  1020. $content = $res_content[2];
  1021. //$content .= "或者点击以下链接生成二维码:".$short_url;
  1022. $response = null;
  1023. $send_success = "-100"; // 默认-100
  1024. zzcsUtils::writeLog("短信模板内容:" . $name . "tel" . $tel . "【" . $content . "】");
  1025. if ($tel != "-1") {
  1026. //..发短信
  1027. $send_success = "-90"; // 说明手机号不是-1
  1028. $response = sendTelMessage($tel, $name, $content, $order_id);
  1029. zzcsUtils::writeLog(json_encode($response));
  1030. } else {
  1031. $send_success = "-1"; // 说明手机号为-1
  1032. zzcsUtils::writeLog('send_msg==tel===' . $tel . ":内容:==》" . $content);
  1033. }
  1034. $comment_type = 0;
  1035. $comment_text = "";
  1036. $current_time = date("Y-m-d H:i:s");
  1037. $user_id = $this->user_id;
  1038. if ($response != null) {
  1039. //$send_success = (int)$response;//原代码
  1040. //这里用正则处理返回的xml信息得到error值
  1041. $pattern = "/\<error\>([-0-9]*?)\<\/error\>/";
  1042. preg_match($pattern, $response, $match);
  1043. $send_success = $match[1];
  1044. }
  1045. $sql1 = "insert into order_send_message(ORDER_ID,SEND_MOBILE,SEND_MESSAGE,SEND_TIME,SEND_ERROR,CREATE_USER_ID,CREATE_TIME,UPDATE_USER_ID,UPDATE_TIME) VALUES ({$order_id},'{$tel}', '{$content}','{$current_time}', {$send_success}, {$user_id},'{$current_time}', {$user_id},'{$current_time}' )";
  1046. $this->exec($sql1);
  1047. //zzcsUtils::writeLog("hotel_order_status.php HT_ADD_MSG_COMMENT()::" . $sql1);
  1048. return $res_content;
  1049. }
  1050. /**
  1051. * Function Description:..短信模板-改为17:30后OK,当天下单也OK
  1052. * Function Name: get_msg_info
  1053. * @param $ORDER_ID
  1054. *
  1055. * @return array
  1056. *
  1057. */
  1058. public function get_msg_info($ORDER_ID)
  1059. {
  1060. $not_send_prod = array(451023, 451024, 451025, 451026, 451027, 451028, 451623, 451624, 451625, 451626, 451627, 451628, 451629, 451630, 451636, 451637);
  1061. $msg_pdo = $this->conn_waice();
  1062. $msg_sql = "CALL SP_GET_MESSAGE_TEMPLATE('" . $ORDER_ID . "')";
  1063. $content = '';
  1064. if (is_object($msg_pdo)) {
  1065. $msg_result = $msg_pdo->query($msg_sql);
  1066. $i = 1;
  1067. $data = array();
  1068. if ($msg_result) {
  1069. $data['code'] = "0";
  1070. $data['info'] = "";
  1071. do {
  1072. $row = $msg_result->fetchAll(PDO::FETCH_ASSOC);
  1073. if ($i == 1) {
  1074. $data['seat'] = isset($row) ? $row : array();
  1075. } else if ($i == 2) {
  1076. $data['run_info'] = isset($row) ? $row : array();
  1077. } else if ($i == 3) {
  1078. $data['driver'] = isset($row) ? $row : array();
  1079. } else if ($i == 4) {
  1080. $data['dsn_prod'] = isset($row) ? $row : array();
  1081. } else if ($i == 5) {
  1082. $data['zhou_su_prod'] = isset($row) ? $row : array();
  1083. }
  1084. $i++;
  1085. } while ($msg_result->nextRowset());
  1086. }
  1087. $json_obj = json_decode(json_encode($data), TRUE);
  1088. $seat = isset($json_obj['seat'][0]) ? $json_obj['seat'][0] : array();
  1089. $run_info = isset($json_obj['run_info'][0]) ? $json_obj['run_info'][0] : array();
  1090. $driver = isset($json_obj['driver'][0]) ? $json_obj['driver'][0] : array();
  1091. $dsn_prod = isset($json_obj['dsn_prod']) ? $json_obj['dsn_prod'] : array();
  1092. $zhou_su_prod = isset($json_obj['zhou_su_prod']) ? $json_obj['zhou_su_prod'] : array();
  1093. $bus_res_id = isset($json_obj['driver'][0]) ? $json_obj['driver'][0]["bus_res_id"] : 0;
  1094. if (in_array($run_info['parent_prod_id'], $not_send_prod)) {
  1095. return false;
  1096. }
  1097. //出票成功
  1098. // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车,车牌号{车牌号},司机电话{司机姓司机电话}。";
  1099. // 得到明天的时间
  1100. date_default_timezone_set('PRC');
  1101. //解决时区问题
  1102. $tomorrow = date("Y-m-d", strtotime("+1 day"));
  1103. $now_time = date('H:i:s', time());
  1104. //判断当前时间是否在17:30:00之后
  1105. $cur_date = date('Y-m-d', time());
  1106. //迪士尼特殊情况parent_prod_id
  1107. // $dsn_arr_prod = array(152752, 152759, 152763, 152770, 152777, 152784, 152791, 152801, 152808, 152815, 152822, 152832, 152842, 152852, 152859, 152866, 152873, 152877, 152884, 152891, 152898, 152905, 152915, 152922, 152929, 152936, 152946, 152956, 152966, 152973, 152980, 152990, 153003, 153016, 153023, 153033, 153034, 153044, 153057, 153070, 153083, 153090, 153100, 153110);
  1108. $dsn_arr_prod = array(); //用来保存迪士尼产品的prod_id
  1109. foreach ($dsn_prod as $temp) {
  1110. $dsn_arr_prod[] = $temp['prod_id'];
  1111. }
  1112. $zhou_su_arr_prod = array();
  1113. foreach ($zhou_su_prod as $temp) {
  1114. $zhou_su_arr_prod[] = $temp['prod_id'];
  1115. }
  1116. $short_url = false;
  1117. $ticket_url = TICKET_QR_URL . $ORDER_ID;
  1118. $short_url = sinaShortenUrl($ticket_url);
  1119. $extra_message = "";
  1120. if ($short_url != false) {
  1121. $extra_message = "您的电子车票链接{$short_url},请在上车前点开,扫码乘车。";
  1122. }
  1123. if (($now_time > "18:30:00" && $run_info['start_date'] == $tomorrow) || $cur_date == $run_info['start_date']) {//17:30之后的订单或者下单时间为今天出行为今天下午 发送短信模板
  1124. // if("18:30:00">"17:30:00" && $run_info['start_date']==$tomorrow){ //17:30之后的订单 发送短信模板
  1125. // $content = "您预订的{出发日期 出发时间}{出发地}-{目的地}{票种名}{张数}张,已购票成功。乘车订单号为{订单号},请凭订单号或绑定微信(微信服务号“蜘蛛出行”)扫码上车,车牌号{车牌号},司机电话{司机姓司机电话}。";
  1126. $content = "订单号{订单号},{出发地}({上车站点})—{目的地}({下车站点})标准票{张数}张将于{出发日期} {出发时间}准点发车。车牌号{车牌号},司机电话{司机姓司机电话},请提前10分钟抵达上车地点:{上车站点详细地址}并点开电子车票 {$short_url} 进行验票。如有疑问请拨打客服电话021-33280519。";
  1127. } else {
  1128. $content = "订单号{订单号},{出发日期} {出发时间}{出发地}({上车站点})—{目的地}({下车站点})标准票{张数}张预定成功。发车前一天19点会短信通知您车牌号及司机电话,如未收到短信请拨打客服电话021-33280519。";
  1129. }
  1130. $new_message_array3 = array(450517, 450522);
  1131. if (in_array($run_info['parent_prod_id'], $new_message_array3)) {
  1132. if ($run_info['parent_prod_id'] == 450517) {
  1133. $address_txt = "上车地点:吴山广场西侧河坊巷8号(吴山广场旅游集散中心候车室); 上车方式:请至吴山广场旅游集散中心候车室服务台,凭预定姓名和手机号码上车。";
  1134. } else {
  1135. $address_txt = "上车地点:普陀城北长途客运中心;取票方式:请提前到达(学运路18号)普陀城北长途客运中心候车大厅服务台报预订名字和电话取票。";
  1136. }
  1137. $content = "您已成功预定{出发日期} {出发时间} {出发地}-{目的地}汽车票{张数}张(请最晚提前10分钟到达)。{$address_txt}紧急电话:15888866564。";
  1138. }
  1139. $new_message_array4 = array(450588, 450589);
  1140. if (in_array($run_info['parent_prod_id'], $new_message_array4)) {
  1141. $content .= "紧急联系电话:18100158199。";
  1142. }
  1143. //$content .= "提前一天19点之前,如未收到司机电话,请速与021-52218088联系。";
  1144. $new_message_array5 = array(451437, 451438);
  1145. if (in_array($run_info['parent_prod_id'], $new_message_array5)) {
  1146. $content = "车票订单号{订单号}:您预订的{上车站点}-{下车站点}标准票{张数}张已经预订成功,车牌号{车牌号},司机电话{司机姓司机电话}。发车时间为{出发日期} {出发时间},发车地址为:{上车站点详细地址}。 您的电子车票链接 {$short_url} ,请在上车前点开扫码,或凭短信乘车。请关注微信公众号[蜘蛛出行],提前获取车辆信息。司机会提前与您联系,如有疑问,请联系021-33280578 。";
  1147. }
  1148. $new_message_array5 = array(451440, 451441);
  1149. $new_message_array6 = array(448780, 450008, 448781);
  1150. if (in_array($run_info['parent_prod_id'], $new_message_array5)) {
  1151. $content = "订单号{订单号},{出发日期} {出发时间}{上车站点}—{目的地}标准票{张数}张预定成功。发车前一天19点会短信通知您车牌号及司机电话,如未收到短信请拨打客服电话021-33280519。";
  1152. } else if (in_array($run_info['parent_prod_id'], $new_message_array6)) {
  1153. $content = "订单号{订单号},{出发日期} {出发时间}{上车站点}—{目的地}标准票{张数}张预定成功。发车前一天19点会短信通知您乘车信息,如未收到短信请拨打客服电话021-33280519。";
  1154. }
  1155. if ($seat) {
  1156. $seat_x = isset($seat['seat_x']) ? $seat['seat_x'] : "";
  1157. $seat_y = isset($seat['seat_y']) ? $seat['seat_y'] : "";
  1158. $seat_name = isset($seat['seat_name']) ? $seat['seat_name'] : "";
  1159. $order_main_id = isset($seat['order_main_id']) ? $seat['order_main_id'] : "";
  1160. } else {
  1161. }
  1162. if ($run_info) {
  1163. $order_count = $run_info['order_count'];
  1164. $start_date = $run_info['start_date'];
  1165. $start_time = $run_info['start_time'];
  1166. $parent_order_id = $run_info['parent_order_id'];
  1167. $end_date = $run_info['end_date'];
  1168. $start_area = $run_info['start_area'];
  1169. $end_area = $run_info['end_area'];
  1170. $res_name = $run_info['res_name'];
  1171. $parent_prod_id = $run_info['parent_prod_id'];
  1172. $prod_name = $run_info['prod_name'];
  1173. $prod_name = "标准票";
  1174. $customer_name = $run_info['customer_name'];
  1175. $customer_mobile = $run_info['customer_mobile'];
  1176. $start_station_address = $run_info['start_station_address'];
  1177. $start_end_date = $start_date . "," . $start_time;
  1178. if ($parent_prod_id == 450504 && $start_date >= "2017-01-27" && $start_date <= "2017-02-02") {
  1179. $res_name = "迪士尼唐老鸭P停车场";
  1180. $start_station_address = "上海迪士尼度假区迪士尼唐老鸭P停车场";
  1181. }
  1182. $content = str_replace("{下车站点}", $run_info['end_res_name'], $content);
  1183. $content = str_replace("{出发日期}", $start_date, $content);
  1184. $content = str_replace("{出发时间}", $start_time, $content);
  1185. $content = str_replace("{上车站点}", $res_name, $content);
  1186. $content = str_replace("{出发地}", $start_area, $content);
  1187. $content = str_replace("{目的地}", $end_area, $content);
  1188. $content = str_replace("{票种名}", $prod_name, $content);
  1189. $content = str_replace("{张数}", $order_count, $content);
  1190. $content = str_replace("{上车站点详细地址}", $start_station_address, $content);
  1191. $content = str_replace("{订单号}", $ORDER_ID, $content);
  1192. } else {
  1193. $content = str_replace("{下车站点}", "", $content);
  1194. $content = str_replace("{出发日期}", "", $content);
  1195. $content = str_replace("{出发时间}", "", $content);
  1196. $content = str_replace("{出发地}", "", $content);
  1197. $content = str_replace("{目的地}", "", $content);
  1198. $content = str_replace("{票种名}", "", $content);
  1199. $content = str_replace("{张数}", "", $content);
  1200. $content = str_replace("{订单号}", "", $content);
  1201. $content = str_replace("{上车站点详细地址}", "", $content);
  1202. }
  1203. if ($driver) {
  1204. $bus_no = isset($driver['bus_no']) ? $driver['bus_no'] : "";
  1205. $driver_name = isset($driver['driver_name']) ? $driver['driver_name'] : "";
  1206. $driver_mobile = isset($driver['driver_mobile']) ? $driver['driver_mobile'] : "";
  1207. if ($bus_no == "") {
  1208. $content = str_replace(",车牌号{车牌号}", "", $content);
  1209. } else {
  1210. $content = str_replace("{车牌号}", $bus_no, $content);
  1211. }
  1212. if ($driver_name == "") {
  1213. $content = str_replace(",司机电话{司机姓司机电话},", "。", $content);
  1214. } else {
  1215. $driver_xing = mb_substr($driver_name, 0, 1, 'utf-8');
  1216. $driver_name_mobile = $driver_xing . $driver_mobile;
  1217. $content = str_replace("{司机姓司机电话}", $driver_name_mobile, $content);
  1218. }
  1219. } else {
  1220. $content = str_replace("车牌号{车牌号},", "", $content);
  1221. $content = str_replace("司机电话{司机姓司机电话},", "", $content);
  1222. }
  1223. /*
  1224. if( $now_time < "18:30:00" ) {
  1225. //判断是不是苏州或周庄
  1226. // 判断如果不是迪士尼的票就不发短信
  1227. if (!in_array($run_info['parent_prod_id'], $dsn_arr_prod) && !in_array($run_info['parent_prod_id'], $zhou_su_arr_prod)) {
  1228. return array("", "-1", "不是迪士尼、苏州、周庄的票,目前不发送短信");
  1229. }
  1230. }*/
  1231. return array(isset($customer_name) ? $customer_name : "", isset($customer_mobile) ? $customer_mobile : "", isset($content) ? $content : "短信错误,联系客服!!!", $run_info);
  1232. }
  1233. }
  1234. /**
  1235. * Function Description:发送post数据
  1236. * Function Name: post2
  1237. * @param $url
  1238. * @param $data
  1239. *
  1240. * @return string
  1241. *
  1242. */
  1243. public function post2($url, $data){//file_get_content
  1244. $postdata = http_build_query(
  1245. $data
  1246. );
  1247. $opts = array('http' =>
  1248. array(
  1249. 'method' => 'POST',
  1250. 'header' => 'Content-type: application/x-www-form-urlencoded',
  1251. 'content' => $postdata
  1252. )
  1253. );
  1254. $context = stream_context_create($opts);
  1255. $result = file_get_contents($url, false, $context);
  1256. return $result;
  1257. }
  1258. /**
  1259. * 获取渠道的票种销售方式
  1260. * @param $channel_id
  1261. * @param $ticket_id
  1262. */
  1263. public function getTicketChannelSaleType($channel_id, $ticket_id, $line_type)
  1264. {
  1265. $sql = "SELECT
  1266. sale_type,
  1267. '0' as price
  1268. FROM
  1269. base_supplier_sale as a
  1270. WHERE
  1271. NOT EXISTS
  1272. (
  1273. SELECT
  1274. supplier_id
  1275. FROM
  1276. opera_tickets_distrib
  1277. WHERE
  1278. supplier_id = a.supplier_id
  1279. AND ticket_id = " . $ticket_id . "
  1280. AND cancel_flag = 0
  1281. )
  1282. AND supplier_id = " . $channel_id . "
  1283. AND parent_type = 310
  1284. AND product_type IN (" . $line_type . ", 0)
  1285. AND cancel_flag = 0
  1286. UNION ALL
  1287. SELECT
  1288. sale_type,
  1289. prod_price as price
  1290. FROM
  1291. opera_tickets_distrib
  1292. WHERE
  1293. supplier_id = " . $channel_id . "
  1294. AND ticket_id = " . $ticket_id . "
  1295. AND authority_status = 1
  1296. AND cancel_flag = 0";
  1297. //zzcsUtils::writeLog($sql);
  1298. $sale_type = $this->query($sql);
  1299. if (count($sale_type) == 0) {
  1300. return false;
  1301. }
  1302. $sale_type = $sale_type[0];
  1303. return $sale_type;
  1304. }
  1305. /**
  1306. * ////单产品和组合产品订单列表头文件
  1307. * //hyk
  1308. * @param $web_date
  1309. * @return array
  1310. */
  1311. function singleOrderListHeadInfo($web_date)
  1312. {
  1313. ////单产品和组合产品订单列表头文件
  1314. //hyk
  1315. // if (isset($web_date['type']) && $web_date['type'] != 0) {
  1316. // $res1 = $this->productLine();
  1317. // $sql = "SELECT
  1318. // a.supplier_id,
  1319. // b.supplier_name
  1320. // FROM
  1321. // base_supplier_sale AS a
  1322. // INNER JOIN base_supplier AS b ON a.supplier_id = b.id
  1323. // WHERE
  1324. // a.parent_type = 310
  1325. // AND a.product_type in(" . $web_date['type'] . ",0)
  1326. // AND a.cancel_flag = 0
  1327. // AND b.cancel_flag = 0
  1328. // AND b.is_disabled = 0
  1329. // GROUP BY
  1330. // a.supplier_id";
  1331. // $res = $this->query($sql);
  1332. // $biller_list = $this->getBiller();
  1333. // $json = array();
  1334. // $json['code'] = '0';
  1335. // $json['info'] = '渠道商和产品线,计调员返回';
  1336. // $json['supplier_list'] = $res;
  1337. // $json['product_line'] = $res1;
  1338. // $json['biller_list'] = $biller_list;
  1339. // return $json;
  1340. // } else {
  1341. // $res1 = $this->productLine();
  1342. // $biller_list = $this->getBiller();
  1343. // $sql = "SELECT
  1344. // a.supplier_id,
  1345. // b.supplier_name
  1346. // FROM
  1347. // base_supplier_sale AS a
  1348. // INNER JOIN base_supplier AS b ON a.supplier_id = b.id
  1349. // WHERE
  1350. // a.parent_type = 310
  1351. // AND a.cancel_flag = 0
  1352. // AND b.cancel_flag = 0
  1353. // AND b.is_disabled = 0
  1354. // GROUP BY
  1355. // a.supplier_id";
  1356. // $res = $this->query($sql);
  1357. // $json = array();
  1358. // $json['code'] = '0';
  1359. // $json['info'] = '渠道商和产品线,计调员返回';
  1360. // $json['supplier_list'] = $res;
  1361. // $json['product_line'] = $res1;
  1362. // $json['biller_list'] = $biller_list;
  1363. // return $json;
  1364. // }
  1365. //娄梦宁2017.1.17修改订单列表头部信息获取
  1366. $res1 = $this->productLine();
  1367. $biller_list = $this->getBiller();
  1368. $sql = ''."SELECT
  1369. a.supplier_id,
  1370. b.supplier_name
  1371. FROM
  1372. base_supplier_sale AS a
  1373. INNER JOIN base_supplier AS b ON a.supplier_id = b.id
  1374. WHERE
  1375. a.parent_type = 310
  1376. AND a.cancel_flag = 0
  1377. AND b.cancel_flag = 0
  1378. AND b.is_disabled = 0
  1379. GROUP BY
  1380. a.supplier_id";
  1381. $res = $this->query($sql);
  1382. //厦门上车区域数组
  1383. $sql=''."select id,area_name as name from base_area where parent_id=1161";
  1384. $start_area_arr=$this->query($sql);
  1385. //厦门上车点数组
  1386. $sql=''."select id,res_name as name from base_resource where area_id in (select id from base_area where parent_id=1161) and zone_mark =0 and res_type_id=24";
  1387. $start_res_arr=$this->query($sql);
  1388. //车牌号数组
  1389. $sql=''."select bus_id as id,bus_no as num from base_bus where bus_no like '闽%'";
  1390. $bus_no_arr=$this->query($sql);
  1391. //司机导游姓名id数组
  1392. $sql=''."select guide_id as id ,guide_name as name from base_guide
  1393. UNION select driver_id as id,driver_name as name from base_driver where org_id in (417,10997)";
  1394. $send_driver_arr=$this->query($sql);
  1395. $json = array();
  1396. $json['code'] = '0';
  1397. $json['info'] = '渠道商和产品线,计调员返回';
  1398. $json['supplier_list'] = $res;
  1399. $json['product_line'] = $res1;
  1400. $json['biller_list'] = $biller_list;
  1401. $json['start_area_arr'] = $start_area_arr;
  1402. $json['start_res_arr'] = $start_res_arr;
  1403. $json['bus_no_arr'] = $bus_no_arr;
  1404. $json['send_driver_arr'] = $send_driver_arr;
  1405. return $json;
  1406. }
  1407. /**
  1408. * //单产品订单列表
  1409. * @param $web_data
  1410. * @return int
  1411. */
  1412. function singleOrderList1($web_data)
  1413. {
  1414. //单产品订单列表
  1415. //hyk
  1416. $user_id = $this->user_id;
  1417. $time_limit = isset($web_data['time_limit']) ? trim($web_data['time_limit']) : false;
  1418. $start_time = isset($web_data["start_time"]) ? trim($web_data["start_time"]) : false;
  1419. $end_time = isset($web_data["end_time"]) ? trim($web_data["end_time"]) : false;
  1420. $order_source = isset($web_data["order_source"]) ? trim($web_data["order_source"]) : false;
  1421. $order_status = isset($web_data["order_status"]) ? trim($web_data["order_status"]) : false;
  1422. $current_page = isset($web_data["current_page"]) ? trim($web_data["current_page"]) : false;
  1423. $page_size = isset($web_data["page_size"]) ? trim($web_data["page_size"]) : false;
  1424. $product_line = isset($web_data["product_line"]) ? trim($web_data["product_line"]) : false;
  1425. $biller = isset($web_data["biller"]) ? trim($web_data["biller"]) : false;//添加计调员id
  1426. $create_user_id = $biller;
  1427. $line = isset($web_data["line"]) ? trim($web_data["line"]) : false;
  1428. $more_search = isset($web_data["more_search"]) ? trim($web_data["more_search"]) : false;
  1429. $search_type = isset($web_data["search_type"]) ? trim($web_data["search_type"]) : false;
  1430. if ($time_limit === false || $start_time === false || $end_time === false || $order_source === false || $order_status === false || $current_page === false || $page_size === false || $product_line === false || $search_type === false || $line === false || $more_search === false || $biller === false) {
  1431. //参数不完整;
  1432. $json["code"] = '2';
  1433. $json["info"] = "缺少必要参数";
  1434. return $json;
  1435. }
  1436. //此处添加计调员id后存储过程为
  1437. /*$sql = "CALL xm_order_get_list_xm(" . $user_id . "," . $time_limit . ",'" .
  1438. $start_time . "','" . $end_time . "'," . $order_source . "," . $order_status . ",'"
  1439. . $more_search . "'," . $current_page . "," . $page_size . ",'" . $line . "','',''," . $search_type . "," . $product_line . "," . $biller.")";*/
  1440. $sql = "CALL xm_order_get_list_xm(" . $user_id . "," . $create_user_id . "," . $time_limit . ",'" .
  1441. $start_time . "','" . $end_time . "'," . $order_source . "," . $order_status . ",'"
  1442. . $more_search . "'," . $current_page . "," . $page_size . ",'" . $line . "','',''," . $search_type . "," . $product_line . ")";
  1443. zzcsUtils::writeLog($sql);
  1444. $res = $this->procQuery($sql);
  1445. if ($res['code'] != 0) {
  1446. //执行存储过程出错
  1447. $json["code"] = $res['code'];
  1448. $json["info"] = $res['info'];
  1449. return $json;
  1450. } else {
  1451. $json["code"] = "0";
  1452. $json["info"] = "订单列表";
  1453. $json["page"]["total_count"] = $res["data"][0][0]["num"];
  1454. $json["page"]["page_count"] = $res["data"][0][0]["pagecount"];
  1455. $json["page"]["curr_page"] = $res["data"][0][0]["currpage"];
  1456. $json["page"]["page_size"] = $res["data"][0][0]["pagesize"];
  1457. $json["order_list"] = $res["data"][1];
  1458. $label_data = array();
  1459. if (empty($res["data"][2])) {
  1460. // $json["label"]["pay"]=$res["data"][2];
  1461. $label_data["pay"] = 0;
  1462. $label_data["out"] = 0;
  1463. $label_data["end"] = 0;
  1464. $label_data["cancle"] = 0;
  1465. $label_data["all"] = 0;
  1466. } else {
  1467. $label_data["pay"] = 0;
  1468. $label_data["out"] = 0;
  1469. $label_data["end"] = 0;
  1470. $label_data["cancle"] = 0;
  1471. $label_data["all"] = 0;
  1472. $ttt = 0;
  1473. foreach ($res["data"][2] as $temp) {
  1474. $ttt = $ttt + $temp["order_cnt"];
  1475. switch ($temp["order_status"]) {
  1476. case 145:
  1477. $label_data["pay"] = $temp["order_cnt"];
  1478. break;
  1479. case 146:
  1480. $label_data["out"] = $temp["order_cnt"];
  1481. break;
  1482. case 147:
  1483. $label_data["end"] = $temp["order_cnt"];
  1484. break;
  1485. case 148:
  1486. $label_data["cancle"] = $temp["order_cnt"];
  1487. break;
  1488. }
  1489. }
  1490. $label_data["all"] = $ttt;
  1491. }
  1492. $json["label"] = $label_data;
  1493. return $json;
  1494. }
  1495. }
  1496. /**
  1497. * ZS
  1498. * 取消订单
  1499. */
  1500. public function cancelOrder($param)
  1501. {
  1502. $order_id = isset($param["order_id"]) ? trim($param["order_id"]) : false;
  1503. $user_id = $this->user_id;
  1504. if (!$order_id) {
  1505. //参数不完整;
  1506. $json["code"] = '2';
  1507. $json["info"] = "缺少必要参数";
  1508. return $json;
  1509. }
  1510. $sql = "call sp_cancel_order(" . $user_id . "," . $order_id . ")";
  1511. zzcsUtils::writeLog($sql);
  1512. $res = $this->procQuery($sql);
  1513. if ($res['code'] != 0) {
  1514. //执行存储过程出错
  1515. $json["code"] = $res['code'];
  1516. $json["info"] = $res['info'];
  1517. } else {
  1518. $json["code"] = "0";
  1519. $json["info"] = "退票成功";
  1520. }
  1521. return $json;
  1522. }
  1523. /**
  1524. * User: wangxj
  1525. *
  1526. * excel导入订单
  1527. *
  1528. * @params
  1529. *
  1530. * @return array 返回没有生成订单的数据
  1531. */
  1532. public function importOrder($param)
  1533. {
  1534. $channel_id = 9; //渠道商,目前先固定 渠道商对应业务员sales_man
  1535. $flag = 0; //1上传全部成功,-1全部失败,2部分成功
  1536. $line_id_fly = 0;
  1537. $line_id_back = 0;
  1538. $result = array('code' => 0, 'info' => 'sheet名称必须为“专车接机”和“专车送机”', 'data' => array());
  1539. $line_id = 0;
  1540. $sql = "select line_id, line_name from opera_line where cancel_flag = 0 and (line_name='机场接驳接机' or line_name = '机场接驳送机')";
  1541. $res = $this->query($sql);
  1542. if (!$res || count($res) == 0) {
  1543. foreach ($res as $line) {
  1544. if (trim($line['line_name']) == '机场接驳接机')
  1545. $line_id_back = $line['line_id'];
  1546. else if (trim($line['line_name']) == '机场接驳送机')
  1547. $line_id_fly = $line['line_id'];
  1548. }
  1549. } else {
  1550. $result['code'] = '2';
  1551. $result["info"] = "缺少必要参数";
  1552. return $result;
  1553. }
  1554. if (isset($_FILES['file']) && file_exists($_FILES['file']['tmp_name'])) {
  1555. require_once ROOT_PATH . '/ZZCS/Common/PHPExcel/IOFactory.php';
  1556. $excel = PHPExcel_IOFactory::load($_FILES['file']['tmp_name']);
  1557. $allSheet = array('专车接机', '专车送机');
  1558. foreach ($allSheet as $type => $sheetName) {
  1559. //run_main查找run_id取prod_id,在opera_line可以查看line_id
  1560. if ($sheetName == '专车送机')
  1561. $line_id = $line_id_fly; //450917;
  1562. else
  1563. $line_id = $line_id_back; //450916;
  1564. $worksheet = $excel->getSheetByName($sheetName);
  1565. if (!$worksheet || $line_id == 0)
  1566. continue;
  1567. $worksheet = $worksheet->toArray();
  1568. $worksheet = array_slice($worksheet, 1);
  1569. //先按酒店排序,再按出发或抵达时间排序
  1570. // usort($worksheet, function ($a, $b) {
  1571. // $c = $a['8'] - $b['8'];
  1572. // return $c != 0 ? $c : $a['6'] - $b['6'];
  1573. // });
  1574. foreach ($worksheet as $key => $item) {
  1575. $valid = zzcsUtils::validateParams(array(
  1576. '1,2,3,4' => 'empty'
  1577. ), $item);
  1578. if (!$valid['status']) {
  1579. continue;
  1580. }
  1581. $res = $this->initOrder($line_id, $channel_id, $item, $type);
  1582. if ($res['code'] != 0) { //为0下单成功
  1583. $result['data'][] = $item + array('error' => $res['info'], 'type' => $sheetName);
  1584. if ($flag == 0)
  1585. $flag = -1;
  1586. elseif ($flag == 1)
  1587. $flag = 2;
  1588. } else {
  1589. if ($flag == 0)
  1590. $flag = 1;
  1591. elseif ($flag == -1)
  1592. $flag = 2;
  1593. }
  1594. }
  1595. }
  1596. if ($flag == "1") {
  1597. $result['info'] = "批量导入成功";
  1598. } else if ($flag == "2") {
  1599. $result['info'] = "部分导入成功";
  1600. } else if ($flag == "-1") {
  1601. $result['info'] = "导入失败";
  1602. }
  1603. $result['code'] = $flag;
  1604. } else {
  1605. $result['code'] = '2';
  1606. $result["info"] = "缺少必要参数";
  1607. }
  1608. return $result;
  1609. }
  1610. /**
  1611. * User: wangxj
  1612. *
  1613. * 加载接送机数据
  1614. *
  1615. * @params
  1616. *
  1617. * @return array
  1618. */
  1619. protected function initOrder($line_id, $channel_id, $params, $type)
  1620. {
  1621. $EXCEL_ORDER_ID = 0;
  1622. $EXCEL_NAME = 3;
  1623. $EXCEL_TEL = 4;
  1624. $EXCEL_FLIGHT = 5;
  1625. $EXCEL_DATE = 6;
  1626. $EXCEL_FLIGHT_T = 7;
  1627. $EXCEL_TIME = 8;
  1628. $EXCEL_MOUNT = 9;
  1629. $EXCEL_HOTEL = 10;
  1630. $EXCEL_NOTE = 11;
  1631. $EXCEL_SUPPLIER = 2;
  1632. $result = array();
  1633. $airport_res_id = 10575; //目前先固定
  1634. $pay_type = 275;
  1635. $supplier_name = $params[$EXCEL_SUPPLIER];
  1636. //渠道商ID
  1637. $sql = "select id from base_supplier where supplier_name = '$supplier_name' and cancel_flag = 0 and SUPPLIER_TYPE = 301 and is_disabled = 0 ";
  1638. $res = $this->query($sql);
  1639. if (!$res || count($res) == 0)
  1640. return array('code' => 2, 'info' => '没有对应渠道商: ' . $supplier_name);
  1641. else {
  1642. $channel_id = $res[0]['id'];
  1643. }
  1644. //代收金额
  1645. $receive_value = 0;
  1646. $user_id = $this->user_id;
  1647. $channel_order_id = $params[$EXCEL_ORDER_ID];
  1648. // $run_date = date('Y-M-d', strtotime($params[4]));
  1649. // ::todo 日期格式有待匹配优化
  1650. if (DateTime::createFromFormat('m-d-y', $params[$EXCEL_DATE]))
  1651. $run_date = DateTime::createFromFormat('m-d-y', $params[$EXCEL_DATE])->format('Y-m-d');
  1652. else
  1653. $run_date = date('Y-m-d', strtotime($params[$EXCEL_DATE]));
  1654. //查看商家自己的订单号在数据库中是否存在,如果已经存在说明已经导入过订单,提示重复
  1655. if (trim($params[$EXCEL_ORDER_ID]) != '') {
  1656. $sql = "select order_id from order_main where cancel_flag = 0 and ORDER_STATUS <> 148 and OUTSIDE_ORDER_NO='" . $params[$EXCEL_ORDER_ID] . "' limit 1";
  1657. $res = $this->query($sql);
  1658. if ($res && !empty($res)) {
  1659. return array('code' => 2, 'info' => '商家订单号已经录入过订单');
  1660. }
  1661. }
  1662. $reg = '/^\d?\d:\d?\d/';
  1663. $run_minutes = 0;
  1664. if (!preg_match($reg, $params[$EXCEL_TIME], $run_time)) {
  1665. return array('code' => 2, 'info' => '时间格式不正确');
  1666. } else {
  1667. //把时间转换为 分钟
  1668. $tmpArray = explode(':', $run_time[0]);
  1669. $run_minutes += $tmpArray[0] * 60 + $tmpArray[1];
  1670. }
  1671. // 去程票种,格式为{去程/返程标志(1:去程 2:返程),去程/返程班次ID,票种ID,票种单价,预定数量}
  1672. $sql = "select run_id from RUN_MAIN where RUN_DATE='$run_date' and RUN_MINUTES >= '$run_minutes' and PROD_ID = $line_id and RUN_STATUS=138 order by RUN_MINUTES limit 1";
  1673. $res = $this->query($sql);
  1674. if (!$res || empty($res)) {
  1675. return array('code' => 2, 'info' => '对应线路无该时间段班次');
  1676. }
  1677. $run_id = $res[0]['run_id'];
  1678. //先获取起始站点和目的站点的res_id, zone_mark:0为站点 1为区域,需要根据具体站点查出区域,票种都是以区域为准
  1679. $res_name = trim($params[$EXCEL_HOTEL]);
  1680. //需要用正则匹配删除部分多余字符
  1681. $reg = "/[^\x{4e00}-\x{9fa5}a-zA-Z]/u";
  1682. $res_name = preg_replace($reg, '', $res_name);
  1683. $full_res_name = $res_name;
  1684. $res_name = str_replace(array("大酒店", "客栈", "酒店"), '', $res_name);
  1685. $sql = "select parent_id,area_id, res_id from base_resource where cancel_flag = 0 and zone_mark = 0 and res_name like '$res_name%' limit 1";
  1686. $res = $this->query($sql);
  1687. if (!$res || empty($res)) {
  1688. return array('code' => 2, 'info' => '当前线路没有这个站点: ' . $full_res_name);
  1689. }
  1690. $res_station_area_id = $res[0]['parent_id'] != 0 ? $res[0]['parent_id'] : $res[0]['res_id'];
  1691. $res_station_id = $res[0]['res_id'];
  1692. $line_type = 256; //穿梭巴士
  1693. if ($type == 0) {
  1694. $start_area_res_id = $airport_res_id;
  1695. $end_area_res_id = $res_station_area_id;
  1696. $start_res_id = $airport_res_id;
  1697. $end_res_id = $res_station_id;
  1698. } else {
  1699. $start_area_res_id = $res_station_area_id;
  1700. $end_area_res_id = $airport_res_id;
  1701. $start_res_id = $res_station_id;
  1702. $end_res_id = $airport_res_id;
  1703. }
  1704. $ticket_info = $this->getTicketInfo(array(
  1705. 'channel_id' => $channel_id,
  1706. 'run_id' => $run_id,
  1707. 'start_res_id' => $start_area_res_id,
  1708. 'end_res_id' => $end_area_res_id,
  1709. 'line_type' => $line_type,
  1710. ));
  1711. if ($ticket_info['code'] != 0)
  1712. return $ticket_info;
  1713. $ticket_id = $ticket_info['list'][0]['ticket_id'];
  1714. $ticket_amount = $ticket_info['list'][0]['price'];
  1715. $count = $params[$EXCEL_MOUNT];
  1716. $ticket_info = "{1,$run_id,$ticket_id,$ticket_amount,$count}";
  1717. //渠道商信息,
  1718. $chanel_info = $this->getGoChannel(array(
  1719. 'run_id' => $run_id,
  1720. 'start_res_id' => $start_res_id,
  1721. 'end_res_id' => $end_res_id,
  1722. 'line_type' => $line_type,
  1723. 'supplier_id' => $channel_id
  1724. ));
  1725. if ($chanel_info['code'] != 0)
  1726. return $chanel_info;
  1727. $salesman = $chanel_info['list'][0]['sales_man'];
  1728. //{联系人,联系电话,备注}
  1729. $customer_info = "{" . $params[$EXCEL_NAME] . "," . $params[$EXCEL_TEL] . "," . $params[$EXCEL_NOTE] . "_" . $params[$EXCEL_FLIGHT] . "_" . $params[$EXCEL_FLIGHT_T] . "}";
  1730. //由于穿梭巴士下单时,票种信息是区域到区域,实际订单其实需要定位到具体站点,所以加2个参数,start_res_id, end_res_id
  1731. //$sql = "call sp_make_order_xm(" . $user_id . ",'" . $ticket_info . "','" . $customer_info . "'," . $channel_id . ",'" . $channel_order_id . "','" . $salesman . "'," . $pay_type . ")";
  1732. $sql = "call sp_make_order_xm(" . $user_id . ",'" . $ticket_info . "','" . $customer_info . "'," . $channel_id . ",'" . $channel_order_id . "','" . $salesman . "'," . $pay_type . "," . $start_res_id . "," . $end_res_id . "," . $receive_value . ")";
  1733. $res = $this->procQuery($sql);
  1734. if ($res['code'] == 0) {
  1735. $time = date('Y-m-d H:i:s', time());
  1736. $json['code'] = '0';
  1737. $json['info'] = '录入订单成功';
  1738. $json['order_id'] = $res['data'][0][0]['order_id'];
  1739. $update_status_sql = "UPDATE order_main
  1740. SET update_user_id = " . $user_id . ",
  1741. update_time = '" . $time . "',
  1742. order_status = 146
  1743. WHERE
  1744. order_id in (" . $json["order_id"] . ")
  1745. OR parent_order_id in (" . $json["order_id"] . ")";
  1746. $this->query($update_status_sql);
  1747. }
  1748. $result = $res;
  1749. return $result;
  1750. }
  1751. /**
  1752. * User:温依莅
  1753. * 获取计调员信息
  1754. * @param
  1755. */
  1756. public function getBiller()
  1757. {
  1758. $sql = "select id,user_name,IF(true_name='',user_name,true_name) 'true_name' from base_user where cancel_flag=0 and user_role in(6,7,14)";
  1759. $biller_info = $this->query($sql);
  1760. if (count($biller_info) == 0) {
  1761. return array();
  1762. }
  1763. return $biller_info;
  1764. }
  1765. /**
  1766. * Function Description:订单列表统一查询入口
  1767. * Function Name: singleOrderList1
  1768. * @param $web_data
  1769. *
  1770. * @return array
  1771. *
  1772. * @author 娄梦宁
  1773. */
  1774. public function singleOrderList($web_data){
  1775. $time_limit = isset($web_data["time_limit"]) ? trim($web_data["time_limit"]) : false;
  1776. $start_time = isset($web_data["start_time"]) ? trim($web_data["start_time"]) : false;
  1777. $end_time = isset($web_data["end_time"]) ? trim($web_data["end_time"]) : false;
  1778. $order_source = isset($web_data["order_source"]) ? trim($web_data["order_source"]) : false;
  1779. $order_status = isset($web_data["order_status"]) ? trim($web_data["order_status"]) : false;
  1780. $current_page = isset($web_data["current_page"]) ? trim($web_data["current_page"]) : false;
  1781. $page_size = isset($web_data["page_size"]) ? trim($web_data["page_size"]) : false;
  1782. $product_line = isset($web_data["product_line"]) ? trim($web_data["product_line"]) : false;
  1783. $biller = isset($web_data["biller"]) ? trim($web_data["biller"]) : false;//添加计调员id
  1784. $user_id = $this->user_id;
  1785. $line = isset($web_data["line"]) ? trim($web_data["line"]) : false;
  1786. $more_search = isset($web_data["more_search"]) ? trim($web_data["more_search"]) : false;
  1787. $search_type = isset($web_data["search_type"]) ? trim($web_data["search_type"]) : false;
  1788. //1.13新增条件参数
  1789. $start_area_id=isset($web_data["start_area_id"]) ? trim($web_data["start_area_id"]) : false;
  1790. $start_res_id=isset($web_data["start_res_id"]) ? trim($web_data["start_res_id"]) : false;
  1791. $end_area_id=isset($web_data["end_area_id"]) ? trim($web_data["end_area_id"]) : false;
  1792. $end_res_id=isset($web_data["end_res_id"]) ? trim($web_data["end_res_id"]) : false;
  1793. $run_length=isset($web_data["run_length"]) ? trim($web_data["run_length"]) : false;
  1794. $bus_send_no=isset($web_data["bus_send_no"]) ? trim($web_data["bus_send_no"]) : false;
  1795. $send_driver_name=isset($web_data["send_driver_name"]) ? trim($web_data["send_driver_name"]) : false;
  1796. $send_driver_mobile=isset($web_data["send_driver_mobile"]) ? trim($web_data["send_driver_mobile"]) : false;
  1797. if ($time_limit === false || $start_time === false || $end_time === false || $order_source === false || $order_status === false || $current_page === false || $page_size === false || $product_line === false || $search_type === false || $line === false || $more_search === false || $biller === false ||
  1798. $start_area_id === false || $start_res_id === false || $bus_send_no === false ||$send_driver_name === false ||$send_driver_mobile === false ) {
  1799. //参数不完整;
  1800. $json["code"] = '2';
  1801. $json["info"] = "缺少必要参数";
  1802. return $json;
  1803. }
  1804. //1. 筛选所有出行信息符合条件的订单
  1805. //1.1拼接where语句
  1806. if($time_limit==1){//下单时间或者出发时间
  1807. $start_time_where=" a.CREATE_TIME between '$start_time' and '$end_time' ";
  1808. }else{
  1809. $start_time_where=" a.prod_start_station_date between '$start_time' and '$end_time' ";
  1810. }
  1811. if($order_source==0){//订单渠道
  1812. $order_source_where=" ";
  1813. }else{
  1814. $order_source_where=" and a.OUTSIDE_SALE_ORG_ID=$order_source ";
  1815. }
  1816. if($product_line==0){//产品线
  1817. $product_line_where=" ";
  1818. }else{
  1819. $product_line_where=" and b.product_type=$product_line ";
  1820. }
  1821. if($line==''){//线路编号或名称
  1822. $line_where=" ";
  1823. }else{
  1824. $line_where=" and ( a.parent_prod_name='$line' or a.PARENT_PROD_ID=$line) ";
  1825. }
  1826. if($order_status==0){//订单状态
  1827. $order_status_where=" ";
  1828. }else{
  1829. $order_status_where=" and a.order_status=$order_status ";
  1830. }
  1831. if($more_search==''){//更多查询
  1832. $more_search_where=" ";
  1833. }else{
  1834. $more_search_where=" and ( a.order_id=$more_search or a.customer_name ='$more_search' or a.customer_mobile='$more_search' or a.SALES_MAN='$more_search' or a.OUTSIDE_ORDER_NO='$more_search' ) ";
  1835. }
  1836. if($biller==0){//计调
  1837. $biller_where=" ";
  1838. }else{
  1839. $biller_where="and a.main_create_user_id=$biller ";
  1840. }
  1841. if($search_type==0){//上车区域
  1842. $search_type_where=" ";
  1843. }else{
  1844. $search_type_where=" and e.line_type=$search_type ";
  1845. }
  1846. if($start_area_id==0){//上车区域
  1847. $start_area_id_where=" ";
  1848. }else{
  1849. $start_area_id_where=" and a.PROD_START_STATION_AREA_ID=$start_area_id ";
  1850. }
  1851. if($start_res_id==0){//上车点
  1852. $start_res_id_where=" ";
  1853. }else{
  1854. $start_res_id_where=" and a.PROD_START_STATION_res_ID=$start_res_id ";
  1855. }
  1856. if($end_area_id==0){//下车区域
  1857. $end_area_id_where=" ";
  1858. }else{
  1859. $end_area_id_where=" and and a.PROD_end_STATION_AREA_ID=$end_area_id ";
  1860. }
  1861. if($end_res_id==0){//下车点
  1862. $end_res_id_where=" ";
  1863. }else{
  1864. $end_res_id_where=" and and a.PROD_end_STATION_AREA_ID=$end_area_id ";
  1865. }
  1866. if($run_length==0){//行程段
  1867. $run_length_where ='';
  1868. }elseif($run_length==1){
  1869. $run_length_where =" and c.parent_prod_name ='岛内接驳' ";
  1870. }elseif($run_length==2){
  1871. $run_length_where =" and c.parent_prod_name != '岛内接驳' and c.prod_start_station_date =a.prod_start_station_date ";
  1872. }else{
  1873. $run_length_where =" and c.prod_start_station_date !=a.prod_start_station_date ";
  1874. }
  1875. if($bus_send_no=='请选择'){//车牌号
  1876. $bus_send_no_where=" ";
  1877. }else{
  1878. $bus_send_no_where=" AND b.SEND_BUS_NO = '$bus_send_no' ";
  1879. }
  1880. if($send_driver_name=='请选择'){//司机或导游名
  1881. $send_driver_name_where=" ";
  1882. }else{
  1883. $send_driver_name_where=" AND (b.SEND_DRIVER_NAME = '$send_driver_name' OR b.SEND_TOUR_GUIDE_NAME = '$send_driver_name') ";
  1884. }
  1885. if($send_driver_mobile==0){//司机或导游手机号
  1886. $send_driver_mobile_where=" ";
  1887. }else{
  1888. $send_driver_mobile_where=" AND (b.SEND_DRIVER_MOBILE = '$send_driver_mobile' OR b.SEND_TOUR_GUIDE_MOBILE = '$send_driver_mobile') ";
  1889. }
  1890. $current_page=($current_page-1)*$page_size;
  1891. //符合条件的订单ID
  1892. $sql=''."SELECT GROUP_CONCAT(x.M_ID) as arr
  1893. from(
  1894. SELECT
  1895. IFNULL(d.status,2) as status,
  1896. a.order_id M_ID
  1897. FROM
  1898. order_main a
  1899. inner join order_main c on a.order_id=c.parent_order_id
  1900. INNER JOIN run_bus b ON c.run_id = b.run_id
  1901. LEFT JOIN order_unusual_process d on d.order_id= a.order_id
  1902. LEFT JOIN opera_line e on a.PARENT_PROD_ID= e.line_id
  1903. where
  1904. $start_time_where
  1905. $order_source_where
  1906. $product_line_where
  1907. $line_where
  1908. $order_status_where
  1909. $more_search_where
  1910. $biller_where
  1911. $start_area_id_where
  1912. $start_res_id_where
  1913. $end_area_id_where
  1914. $end_res_id_where
  1915. and a.PARENT_ORDER_ID=0
  1916. $run_length_where
  1917. $bus_send_no_where
  1918. $send_driver_name_where
  1919. $send_driver_mobile_where
  1920. and a.CANCEL_FLAG=0
  1921. and b.CANCEL_FLAG=0
  1922. and c.CANCEL_FLAG=0
  1923. and e.CANCEL_FLAG=0
  1924. $search_type_where
  1925. GROUP BY
  1926. a.order_id
  1927. order by status,a.create_time desc
  1928. limit $current_page,$page_size )x";
  1929. $order_id_arr=$this->query($sql);
  1930. $id_arr=$order_id_arr[0]['arr'];
  1931. //查询展示数据
  1932. $sql=''."SELECT
  1933. a.order_id M_ID,
  1934. a.create_time,
  1935. ifnull((SELECT true_name FROM base_user WHERE id = a.main_create_user_id),'') create_user_name,
  1936. ifnull((SELECT supplier_name FROM base_supplier WHERE id = a.OUTSIDE_SALE_ORG_ID),'') org_name,
  1937. a.outside_order_no,
  1938. ifnull(a.sales_man,'') as sales_man_name,
  1939. a.parent_prod_name line,
  1940. a.order_description,
  1941. a.PROD_START_STATION_RES_name start_station,
  1942. a.PROD_START_STATION_area_name AS start_area,
  1943. a.prod_start_station_date AS travel_time,
  1944. a.customer_name contacts,
  1945. a.customer_mobile AS tel,
  1946. a.order_price AS total_price,
  1947. ifnull((SELECT type_name FROM dict_type WHERE id = (SELECT pay_type_id_1 FROM order_pay_detail WHERE id = (SELECT id FROM order_pay_main WHERE order_id = a.order_id))),'授信支付') as pay_type_name,
  1948. a.order_status,
  1949. (a.receive_value) as receive_value,
  1950. ifnull(a.customer_memo,'') as memo,
  1951. IFNULL(d.status,2) as status,
  1952. ifnull(d.special_state,'') as special_state,
  1953. a.real_passenger_num real_passager_num
  1954. FROM
  1955. order_main a
  1956. inner join order_main c on a.order_id=c.parent_order_id
  1957. INNER JOIN run_bus b ON c.run_id = b.run_id
  1958. LEFT JOIN order_unusual_process d on d.order_id= a.order_id
  1959. LEFT JOIN opera_line e on a.PARENT_PROD_ID= e.line_id
  1960. WHERE
  1961. a.order_id in($id_arr)
  1962. GROUP BY
  1963. a.order_id
  1964. order by status,a.create_time desc
  1965. ";
  1966. //获取订单状态分组信息
  1967. $order_list=$this->query($sql);
  1968. $sql=''."SELECT ifnull(SUM(x.145cnt),0) as pay,ifnull(SUM(x.146cnt),0) as `out`, ifnull(SUM(x.147cnt),0) as end,ifnull(SUM(x.148cnt),0) as cancel,ifnull(SUM(1),0) as `all`
  1969. from(
  1970. SELECT
  1971. a.order_id M_ID,
  1972. if(a.order_status ='145', 1,0) '145cnt',
  1973. if(a.order_status ='146', 1,0) '146cnt',
  1974. if(a.order_status ='147', 1,0) '147cnt',
  1975. if(a.order_status ='148', 1,0) '148cnt',
  1976. a.order_status
  1977. FROM
  1978. order_main a
  1979. inner join order_main c on a.order_id=c.parent_order_id
  1980. INNER JOIN run_bus b ON c.run_id = b.run_id
  1981. LEFT JOIN order_unusual_process d on d.order_id= a.order_id
  1982. LEFT JOIN opera_line e on a.PARENT_PROD_ID= e.line_id
  1983. WHERE
  1984. $start_time_where
  1985. $order_source_where
  1986. $product_line_where
  1987. $line_where
  1988. $order_status_where
  1989. $more_search_where
  1990. $biller_where
  1991. $start_area_id_where
  1992. $start_res_id_where
  1993. $end_area_id_where
  1994. $end_res_id_where
  1995. and a.PARENT_ORDER_ID=0
  1996. $run_length_where
  1997. $bus_send_no_where
  1998. $send_driver_name_where
  1999. $send_driver_mobile_where
  2000. and a.CANCEL_FLAG=0
  2001. and b.CANCEL_FLAG=0
  2002. and c.CANCEL_FLAG=0
  2003. and e.CANCEL_FLAG=0
  2004. $search_type_where
  2005. GROUP BY
  2006. a.order_id
  2007. )x";
  2008. $label=$this->query($sql);
  2009. $total_count=intval($label[0]['all']);
  2010. $page_count=ceil($total_count/$page_size);
  2011. //出行信息内容拼接
  2012. foreach ($order_list as $key=>$val){
  2013. $order_id=$val['M_ID'];
  2014. $sql=''."SELECT
  2015. SEND_BUS_NO,
  2016. SEND_DRIVER_NAME,
  2017. SEND_TOUR_GUIDE_NAME,
  2018. SEND_DRIVER_MOBILE,
  2019. SEND_TOUR_GUIDE_MOBILE,
  2020. if(b.parent_prod_name ='岛内接驳','1. ',(if(b.PROD_START_STATION_DATE=c.PROD_START_STATION_DATE,'2. ','3. '))) as seq
  2021. FROM
  2022. order_main c,run_bus a
  2023. INNER JOIN order_main b ON a.run_id = b.run_id
  2024. WHERE
  2025. b.parent_order_id = $order_id
  2026. and b.RUN_BUS_ORDER_ID=a.BUS_ORDER_ID
  2027. and c.order_id=$order_id
  2028. GROUP BY
  2029. a.run_id
  2030. ORDER BY
  2031. seq";
  2032. $trip_info=$this->query($sql);
  2033. $trip_str='';
  2034. foreach($trip_info as $v){
  2035. $trip_str.=$v['seq'].$v['SEND_BUS_NO'].' '.$v['SEND_DRIVER_NAME'].' '.$v['SEND_DRIVER_MOBILE'].' '.$v['SEND_TOUR_GUIDE_NAME'].' '.$v['SEND_TOUR_GUIDE_MOBILE'].'</br> ';
  2036. }
  2037. $order_list[$key]['trip_info']=$trip_str;
  2038. }
  2039. $json=array(
  2040. 'code'=>0,
  2041. 'info'=>'订单列表',
  2042. 'page'=>array(
  2043. 'total_count'=>$total_count,
  2044. 'curr_page'=>$current_page+1,
  2045. 'page_size'=>intval($page_size),
  2046. 'page_count'=>$page_count
  2047. ),
  2048. 'label'=>$label[0],
  2049. 'order_list'=>$order_list
  2050. );
  2051. return $json;
  2052. }
  2053. /**
  2054. * Function Description:校验渠道订单号是否唯一存在
  2055. * Function Name: checkOutsideNo
  2056. * @param $post
  2057. *
  2058. * @return array
  2059. *
  2060. * @author 娄梦宁
  2061. */
  2062. public function checkOutsideNo($post){
  2063. $ouside_no = isset($post["outside_no"]) ? trim($post["outside_no"]) : false;
  2064. $sql='select count(1) as cnt from order_main where cancel_flag=0 and outside_order_no = "'.$ouside_no.'"';
  2065. $res=$this->query($sql);
  2066. $cnt=$res[0]['cnt'];
  2067. if($cnt!=0){
  2068. return array(
  2069. 'code'=>1,
  2070. 'info'=>'该渠道订单号已存在!',
  2071. );
  2072. }
  2073. return array(
  2074. 'code'=>0,
  2075. 'info'=>'该渠道订单号可添加!'
  2076. );
  2077. }
  2078. }