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.
 
 
 
 
 
 

771 line
25 KiB

  1. <?php
  2. /**
  3. *
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 张帅
  12. * PhpStorm OrderService.php
  13. * Create By 2016/11/16 17:13 $
  14. */
  15. namespace Order\Service;
  16. use Base\Tool\LoginTool;
  17. use Base\Tool\WxPayService;
  18. use Order\Model\BaseSupplier;
  19. use Order\Model\OrderlistModel;
  20. use Model\Model\OrderMain;
  21. use Order\Model\RunMain;
  22. use Base\Lib\phpqrcode\QrCode;
  23. use Order\Model\WechatCustomer;
  24. use Service\Service\OrderLog;
  25. use Trip\Service\BaseService;
  26. use Util\Util\CurlInterface;
  27. use Util\Util\Util;
  28. class OrderService
  29. {
  30. /**
  31. * Function Description:获取初始化数据
  32. * Function Name: getRunDetail
  33. * @param $run_id
  34. * @param $start_area_id
  35. * @param $end_area_id
  36. * @param $channel_id
  37. *
  38. * @return array|mixed|string
  39. *
  40. * @author 张帅
  41. */
  42. public function getRunDetail($run_id, $start_area_id, $end_area_id, $channel_id)
  43. {
  44. //获取班次详情
  45. $run_info = $this->getRunInfo($run_id);
  46. if (!$run_info['flag']) {
  47. return $run_info;
  48. }
  49. $BaseService = new BaseService();
  50. $poi_info = $BaseService->getPoiInfoArr();
  51. $poi_info = $poi_info['poi_info'];
  52. $run['run_id'] = $run_info['data']['run_id'];
  53. $run['start_area_id'] = $start_area_id;
  54. $run['start_area_name'] = $poi_info[$start_area_id]['area_name'];
  55. $run['end_area_id'] = $end_area_id;
  56. $run['end_area_name'] = $poi_info[$end_area_id]['area_name'];
  57. $run['run_date'] = $run_info['data']['run_date'];
  58. $run['run_time'] = $run_info['data']['run_time'];
  59. //获取上车站点
  60. $start_station = $this->getStartStation($run_id, $start_area_id);
  61. if (!$start_station['flag']) {
  62. return $start_station;
  63. }
  64. $start_res_arr = $start_station['data'];
  65. $run['start_res_arr'] = $start_res_arr;
  66. //获取默认选中的上车站
  67. $start_res_id = $start_res_arr[0]['res_id'];
  68. $run['select_start_res']['res_id'] = $start_res_arr[0]['res_id'];
  69. $run['select_start_res']['res_name'] = $start_res_arr[0]['res_name'];
  70. $run['select_start_res']['res_time'] = $start_res_arr[0]['res_time'];
  71. //获取下车站点
  72. $end_station = $this->getEndStation($run_id, $run_id, $start_res_id, $end_area_id);
  73. if (!$end_station['flag']) {
  74. return $end_station;
  75. }
  76. $end_res_arr = $end_station['data'];
  77. $run['end_res_arr'] = $end_res_arr;
  78. //获取默认选中的上车站
  79. $end_res_id = $end_res_arr[0]['res_id'];
  80. $run['select_end_res']['res_id'] = $end_res_arr[0]['res_id'];
  81. $run['select_end_res']['res_name'] = $end_res_arr[0]['res_name'];
  82. $run['select_end_res']['res_time'] = $end_res_arr[0]['res_time'];
  83. //获取票种信息
  84. $ticket_info = $this->getTicketInfo($run_id, $start_res_id, $end_res_id);
  85. if (!$ticket_info['flag']) {
  86. return $ticket_info;
  87. }
  88. $ticket_info = $ticket_info['data'];
  89. //处理票种详情
  90. $ticket_info = $this->execTicket($ticket_info);
  91. //获取票种id
  92. $ticket_id = $ticket_info['ticket_id'];
  93. //获取优惠价
  94. $discount_price = $this->getDiscountPrice($ticket_id, $channel_id);
  95. if (!$discount_price['flag']) {
  96. return $discount_price;
  97. }
  98. $discount_price = $discount_price['data'];
  99. if (count($discount_price) == 0) {
  100. $discount_price = '0';
  101. } else {
  102. $discount_price = $discount_price['off_value'];
  103. }
  104. $ticket_info['discount_price'] = $discount_price;
  105. $run['ticket_info'] = $ticket_info;
  106. return Util::returnArrSu('', $run);
  107. }
  108. /**
  109. * Function Description:通过上车站点获取初始化数据
  110. * Function Name: getRunDetailByStart
  111. * @param $run_id
  112. * @param $start_res_id
  113. * @param $end_area_id
  114. * @param $channel_id
  115. *
  116. * @return array|mixed|string
  117. *
  118. * @author 张帅
  119. */
  120. public function getRunDetailByStart($run_id, $start_res_id, $end_area_id, $channel_id)
  121. {
  122. //获取下车站点
  123. $end_station = $this->getEndStation($run_id, $run_id, $start_res_id, $end_area_id);
  124. if (!$end_station['flag']) {
  125. return $end_station;
  126. }
  127. $end_res_arr = $end_station['data'];
  128. $run['end_res_arr'] = $end_res_arr;
  129. //获取默认选中的上车站
  130. $end_res_id = $end_res_arr[0]['res_id'];
  131. $run['select_end_res']['res_id'] = $end_res_arr[0]['res_id'];
  132. $run['select_end_res']['res_name'] = $end_res_arr[0]['res_name'];
  133. $run['select_end_res']['res_time'] = $end_res_arr[0]['res_time'];
  134. //获取票种信息
  135. $ticket_info = $this->getTicketInfo($run_id, $start_res_id, $end_res_id);
  136. if (!$ticket_info['flag']) {
  137. return $ticket_info;
  138. }
  139. $ticket_info = $ticket_info['data'];
  140. //处理票种详情
  141. $ticket_info = $this->execTicket($ticket_info);
  142. //获取票种id
  143. $ticket_id = $ticket_info['ticket_id'];
  144. //获取优惠价
  145. $discount_price = $this->getDiscountPrice($ticket_id, $channel_id);
  146. if (!$discount_price['flag']) {
  147. return $discount_price;
  148. }
  149. $discount_price = $discount_price['data'];
  150. if (count($discount_price) == 0) {
  151. $discount_price = '0';
  152. } else {
  153. $discount_price = $discount_price['off_value'];
  154. }
  155. $ticket_info['discount_price'] = $discount_price;
  156. $run['ticket_info'] = $ticket_info;
  157. return Util::returnArrSu('', $run);
  158. }
  159. /**
  160. * Function Description:通过下车站点获取初始化数据
  161. * Function Name: getRunDetailByEnd
  162. * @param $run_id
  163. * @param $start_res_id
  164. * @param $end_res_id
  165. * @param $channel_id
  166. *
  167. * @return array|mixed|string
  168. *
  169. * @author 张帅
  170. */
  171. public function getRunDetailByEnd($run_id, $start_res_id, $end_res_id, $channel_id)
  172. {
  173. //获取票种信息
  174. $ticket_info = $this->getTicketInfo($run_id, $start_res_id, $end_res_id);
  175. if (!$ticket_info['flag']) {
  176. return $ticket_info;
  177. }
  178. $ticket_info = $ticket_info['data'];
  179. //处理票种详情
  180. $ticket_info = $this->execTicket($ticket_info);
  181. //获取票种id
  182. $ticket_id = $ticket_info['ticket_id'];
  183. //获取优惠价
  184. $discount_price = $this->getDiscountPrice($ticket_id, $channel_id);
  185. if (!$discount_price['flag']) {
  186. return $discount_price;
  187. }
  188. $discount_price = $discount_price['data'];
  189. if (count($discount_price) == 0) {
  190. $discount_price = '0';
  191. } else {
  192. $discount_price = $discount_price['off_value'];
  193. }
  194. $ticket_info['discount_price'] = $discount_price;
  195. $run['ticket_info'] = $ticket_info;
  196. return Util::returnArrSu('', $run);
  197. }
  198. /**
  199. * Function Description:获取班次信息详情
  200. * Function Name: getRunInfo
  201. * @param $run_id
  202. *
  203. * @return mixed
  204. *
  205. * @author 张帅
  206. */
  207. public function getRunInfo($run_id)
  208. {
  209. $run_main = new RunMain();
  210. $run_info = $run_main->getRunDetail($run_id);
  211. return $run_info;
  212. }
  213. /**
  214. * Function Description:获取上车站点数据
  215. * Function Name: getStartStation
  216. * @param $run_id
  217. * @param $start_area_id
  218. *
  219. * @return array
  220. *
  221. * @author 张帅
  222. */
  223. public function getStartStation($run_id, $start_area_id)
  224. {
  225. $run_main = new RunMain();
  226. $start_station = $run_main->getStartStation($run_id, $start_area_id);
  227. return $start_station;
  228. }
  229. /**
  230. * Function Description:获取下车站点数据
  231. * Function Name: getEndStation
  232. * @param $run_id
  233. * @param $run_id
  234. * @param $start_res_id
  235. * @param $end_area_id
  236. *
  237. * @return array
  238. *
  239. * @author 张帅
  240. */
  241. public function getEndStation($run_id, $run_id, $start_res_id, $end_area_id)
  242. {
  243. $run_main = new RunMain();
  244. $end_station = $run_main->getEndStation($run_id, $start_res_id, $end_area_id);
  245. return $end_station;
  246. }
  247. /**
  248. * Function Description:获取票种信息
  249. * Function Name: getTicketInfo
  250. * @param $run_id
  251. * @param $start_res_id
  252. * @param $end_res_id
  253. *
  254. * @return array
  255. *
  256. * @author 张帅
  257. */
  258. public function getTicketInfo($run_id, $start_res_id, $end_res_id)
  259. {
  260. $run_main = new RunMain();
  261. $ticket_info = $run_main->getTicketInfo($run_id, $start_res_id, $end_res_id);
  262. return $ticket_info;
  263. }
  264. /**
  265. * Function Description:获取优惠价格
  266. * Function Name: getDiscountPrice
  267. * @param $ticket_id
  268. * @param $channel_id
  269. *
  270. * @return array
  271. *
  272. * @author 张帅
  273. */
  274. public function getDiscountPrice($ticket_id, $channel_id)
  275. {
  276. $run_main = new RunMain();
  277. $discount_price = $run_main->getDiscountPrice($ticket_id, $channel_id);
  278. return $discount_price;
  279. }
  280. /**
  281. * Function Description:
  282. * Function Name: execTicket
  283. * @param $ticket_info
  284. *
  285. * @return mixed
  286. *
  287. * @author 倪宗锋
  288. */
  289. public function execTicket($ticket_info)
  290. {
  291. $time_diff = strtotime($ticket_info['end_time']) - strtotime($ticket_info['start_time']);
  292. $remain = $time_diff % 86400;
  293. if ($remain <= 0) {
  294. $remain = 24 * 3600 + $remain;
  295. }
  296. $hours = intval($remain / 3600);
  297. $remain = $remain % 3600;
  298. $min = intval($remain / 60);
  299. $ticket_info['price'] = ceil($ticket_info['price']);
  300. $ticket_info['total_time'] = $hours . '时' . $min . '分';
  301. unset($ticket_info['line_id']);
  302. unset($ticket_info['start_time']);
  303. unset($ticket_info['end_time']);
  304. return $ticket_info;
  305. }
  306. /**
  307. * Function Description:添加乘客人
  308. * Function Name: addCustomer
  309. * @param $customer_name
  310. * @param $customer_id_card
  311. *
  312. * @return string
  313. *
  314. * @author 张帅
  315. */
  316. public function addCustomer($customer_name, $customer_id_card)
  317. {
  318. $we_user_id = LoginTool::$userId;//$_SESSION['we_user_id'];
  319. $wechat_customer = new WechatCustomer();
  320. $result = $wechat_customer->addCustomer($customer_name, $customer_id_card, $we_user_id);
  321. return $result;
  322. }
  323. /**
  324. * Function Description:修改联系人信息
  325. * Function Name: uptCustomer
  326. * @param $customer_name
  327. * @param $customer_id_card
  328. * @param $customer_id
  329. *
  330. * @return array
  331. *
  332. * @author 娄梦宁
  333. */
  334. public function uptCustomer($customer_name, $customer_id_card, $customer_id)
  335. {
  336. $wechat_customer = new WechatCustomer();
  337. $result = $wechat_customer->uptCustomer($customer_name, $customer_id_card, $customer_id);
  338. return $result;
  339. }
  340. /**
  341. * Function Description:获取乘客人
  342. * Function Name: getCustomerList
  343. *
  344. * @return string
  345. *
  346. * @author 张帅
  347. */
  348. public function getCustomerList()
  349. {
  350. $we_user_id = LoginTool::$userId;//$_SESSION['we_user_id'];
  351. $wechat_customer = new WechatCustomer();
  352. $result = $wechat_customer->getCustomerList($we_user_id);
  353. return $result;
  354. }
  355. /**
  356. * Function Description:订单提交
  357. * Function Name: submitOrder
  358. * @param $params
  359. *
  360. * @return array
  361. *
  362. * @author 倪宗锋
  363. */
  364. public function submitOrder($params)
  365. {
  366. //第一步 本地下单
  367. //价格校验
  368. // $getOrder = $this->getPrice($params['ticket_info'], $params['channel_id']);
  369. // if (!$getOrder) {
  370. // return Util::returnArrEr('订票失败');
  371. // }
  372. $result = $this->addOrder($params);
  373. $orderId = $result['data'];
  374. if (!$result['flag'] && !empty($result['data'])) {
  375. //如果下单失败,执行退票操作
  376. $this->cancelOrder($orderId);
  377. return Util::returnArrEr($result['msg']);
  378. }
  379. //本地下单成功后 则前往微信下单
  380. //如果是M站 web 则跳转
  381. if ($params['pay_type'] == '278') {
  382. //跳转地址 用于网页跳转
  383. $url = 'http://wx.zhizhuchuxing.com/wechat/WxPay/realpay/weChatShopPay.php?order_id=' . $orderId;
  384. //记录下单日志
  385. OrderLog::addOrder($orderId, 2);
  386. return Util::returnArrSu('', '', $url);
  387. }
  388. //否则就是app站点 则调用微信下单接口 并获取返回值`
  389. $wxPayService = new WxPayService();
  390. $result = $wxPayService->unifiedOrderByOrderId($orderId);//去微信下单并获取返回值
  391. if ($result['flag'] == true) {//记录下单日志
  392. OrderLog::addOrder($orderId, 2);
  393. }
  394. return $result;
  395. }
  396. /**
  397. * Function Description:添加订单 服务器数据库添加订单信息
  398. * Function Name: addOrder
  399. * @param $params
  400. *
  401. * @return array
  402. *
  403. * @author 张帅
  404. */
  405. public function addOrder($params)
  406. {
  407. $base_supplier = new BaseSupplier();
  408. $member_id = LoginTool::$userId;
  409. //1.获取业务员
  410. $salesman = $base_supplier->getSalesman($params['channel_id']);
  411. if (!$salesman['flag']) {
  412. return $salesman;
  413. }
  414. $params['salesman'] = $salesman['data']['sales_man'];
  415. //2.提交订单
  416. $order_main = new OrderMain();
  417. $order_id = $order_main->submitOrder($params);
  418. if (!$order_id['flag']) {
  419. return $order_id;
  420. }
  421. //3.获取订单号
  422. $order_id = $order_id['data'];
  423. //4.更新订单order_book_status
  424. $order_book_status_result = $order_main->updateBookStatus($order_id);
  425. if (!$order_book_status_result['flag']) {
  426. return $order_book_status_result;
  427. }
  428. //5.如果是往返订单,把订单手机城数组
  429. $order_id3 = explode(',', $order_id);
  430. if (count($order_id3) > 1) {
  431. $order_id1 = $order_id3[0];//去程订单
  432. $order_id2 = $order_id3[1];//返程订单
  433. //将往返订单连接起来
  434. $result = $order_main->linkOrder($order_id1, $order_id2);
  435. if (!$result) {
  436. return Util::returnArrEr('订单连接失败', $order_id1);
  437. }
  438. } else {
  439. $order_id1 = $order_id3[0];//单程订单
  440. }
  441. //6.修改订单的会员id
  442. $member_result = $order_main->updateMemberId($member_id, $order_id);
  443. if (!$member_result) {
  444. return Util::returnArrEr('插入订单失败', $order_id1);
  445. }
  446. return $result = Util::returnArrSu('', $order_id1);
  447. }
  448. /**
  449. * Function Description:验证身份证
  450. * Function Name: isCardID
  451. * @param $sId
  452. *
  453. * @return array
  454. *
  455. * @author 张帅
  456. */
  457. public function isCardID($sId)
  458. {
  459. $aCity = array(
  460. 11 => "北京",
  461. 12 => "天津",
  462. 13 => "河北",
  463. 14 => "山西",
  464. 15 => "内蒙古",
  465. 21 => "辽宁",
  466. 22 => "吉林",
  467. 23 => "黑龙江",
  468. 31 => "上海",
  469. 32 => "江苏",
  470. 33 => "浙江",
  471. 34 => "安徽",
  472. 35 => "福建",
  473. 36 => "江西",
  474. 37 => "山东",
  475. 41 => "河南",
  476. 42 => "湖北",
  477. 43 => "湖南",
  478. 44 => "广东",
  479. 45 => "广西",
  480. 46 => "海南",
  481. 50 => "重庆",
  482. 51 => "四川",
  483. 52 => "贵州",
  484. 53 => "云南",
  485. 54 => "西藏",
  486. 61 => "陕西",
  487. 62 => "甘肃",
  488. 63 => "青海",
  489. 64 => "宁夏",
  490. 65 => "新疆",
  491. 71 => "台湾",
  492. 81 => "香港",
  493. 82 => "澳门",
  494. 91 => "国外"
  495. );
  496. $iSum = 0;
  497. $result1 = Util::checkPattern('', $sId, '/^\d{17}(\d|x)$/i');
  498. //你输入的身份证长度或格式错误
  499. if (!$result1) {
  500. return Util::returnArrEr('你输入的身份证长度或格式错误');
  501. }
  502. $sId = str_replace('X', 'a', $sId);
  503. $sId = str_replace('x', 'a', $sId);
  504. $city = substr($sId, 0, 2);
  505. //你的身份证地区非法
  506. if (!isset($aCity[$city])) {
  507. return Util::returnArrEr('你的身份证地区非法');
  508. }
  509. $sBirthday = substr($sId, 6, 4) . '-' . substr($sId, 10, 2) . '-' . substr($sId, 12, 2);
  510. $result2 = Util::checkPattern('', $sBirthday, '/^(19|20)\d{2}-(1[0-2]|0?[1-9])-(0?[1-9]|[1-2][0-9]|3[0-1])$/');
  511. //身份证上的出生日期非法
  512. if (!$result2) {
  513. return Util::returnArrEr('身份证上的出生日期非法');
  514. }
  515. for ($i = 17; $i >= 0; $i--) {
  516. $pow = 1;
  517. for ($j = 1; $j <= $i; $j++) {
  518. $pow *= 2;
  519. }
  520. $charAt = 17 - $i;
  521. if ($sId[$charAt] == 'a') {
  522. $sId[$charAt] = 10;
  523. }
  524. $iSum += ($pow % 11) * $sId[$charAt];
  525. }
  526. //你输入的身份证号非法
  527. if ($iSum % 11 != 1) {
  528. return Util::returnArrEr('你输入的身份证号非法');
  529. }
  530. return Util::returnArrSu();
  531. }
  532. /**
  533. * Des:获取电子车票二维码,根据订单号生成二维码和检票信息
  534. * Name: getETicket
  535. * @param $order_id
  536. * @return string
  537. * @author 倪宗锋
  538. */
  539. public function getETicket($order_id)
  540. {
  541. $qr_path = "images/temp/QrCode/$order_id.png";
  542. $logo_qr_path = "images/temp/QrCode/logo$order_id.png";
  543. $errorCorrectionLevel = 'L'; //容错级别
  544. $matrixPointSize = 7; //生成图片大小
  545. $content = $order_id;
  546. // 生成二维码图片
  547. if (file_exists($qr_path))
  548. unlink($qr_path);
  549. if (file_exists($logo_qr_path))
  550. unlink($logo_qr_path);
  551. QrCode::png($content, $qr_path, $errorCorrectionLevel, $matrixPointSize, 2);
  552. $QR = $qr_path;
  553. // 输出二维码图片
  554. return "/public/$QR";
  555. }
  556. /**
  557. * Des:修改订单状态,插入支付凭证
  558. * Name: updateOrderStatus
  559. * @param $order_id
  560. * @param $pay_num
  561. * @return array
  562. * @author 张帅
  563. */
  564. public function updateOrderStatus($order_id, $pay_num)
  565. {
  566. $order_main = new OrderMain();
  567. //1.判断订单是否完成
  568. $check_result = $order_main->checkStatus($order_id);
  569. //执行sql 错误
  570. if (!$check_result['flag']) {
  571. return $check_result;
  572. }
  573. //已出票
  574. if ($check_result['data'] == 146) {
  575. return $check_result;
  576. }
  577. $result1 = $order_main->updateOrderStatus($order_id);
  578. if (!$result1) {
  579. return $result1;
  580. }
  581. $order_group = $result1['data'];
  582. $order_group = explode(',', $order_group);
  583. $result = $order_main->insSerialNumber($order_id, $pay_num);
  584. //7.发短信
  585. $url1='http://cs1.zhizhuchuxing.com/api/msg/order-send-msg';
  586. $data = array('order_id' => $order_group[0], 'msg_type' => 'wx' );
  587. $a = new CurlInterface($data, 5);
  588. $a->setBaseUrl($url1);
  589. $a->execute('', 'POST');
  590. if (isset($order_group[1])) {
  591. $data = array('order_id' => $order_group[1]);
  592. $a = new CurlInterface($data, 5);
  593. $a->setBaseUrl($url1);
  594. $a->execute('', 'POST');
  595. }
  596. OrderLog::addOrderStatusLog($order_id, 2);//添加订单状态变更记录 2:支付
  597. return $result;
  598. }
  599. /**
  600. * Function Description:退票
  601. * Function Name: cancelOrder
  602. * @param $order_id
  603. *
  604. * @return string
  605. *
  606. * @author 张帅
  607. */
  608. public function cancelOrder($order_id)
  609. {
  610. $order_main = new OrderMain();
  611. $result = $order_main->cancelOrder($order_id);
  612. if (!$result) {
  613. return Util::returnJsEr('退票失败');
  614. } else {
  615. return Util::returnJsSu('退票成功');
  616. }
  617. }
  618. /**
  619. * Function Description:退钱
  620. * Function Name: cancelPay
  621. * @param $order_id
  622. *
  623. * @return string
  624. *
  625. * @author 张帅
  626. */
  627. public function cancelPay($order_id)
  628. {
  629. //1.获取订单详情
  630. $order_list = new OrderlistModel();
  631. $order_detail = $order_list->getOrderall($order_id);
  632. if (!$order_detail['flag']) {
  633. return Util::returnJsEr('网络原因,退票失败');
  634. }
  635. $order_detail = $order_detail['data'];
  636. $price = $order_detail['price'];
  637. $order_id = $order_detail['order_id'];
  638. //2.判断时间是否符合退票时间
  639. $run_time = $order_detail[0]['run_date'] . ' ' . $order_detail[0]['start_time'];
  640. $time_check = strtotime($run_time) - time();
  641. if ($time_check < 1800) {
  642. return Util::returnJsEr('开车前30分钟禁止退票,请刷新页面确认时间');
  643. }
  644. $order_id_arr = explode(',', $order_id);
  645. if (count($order_id_arr) > 1) {
  646. $go_order_id = $order_id_arr[0];//去程订单号
  647. $back_order_id = $order_id_arr[1];//返程订单号
  648. } else {
  649. $go_order_id = $order_id_arr[0];
  650. $back_order_id = '';
  651. }
  652. //3.获取支付凭证
  653. $order_main = new OrderMain();
  654. $serial_result = $order_main->getSerialNumber($go_order_id);
  655. if (!$serial_result['flag']) {
  656. return json_encode($serial_result);
  657. }
  658. $serial_number = $serial_result['data'];
  659. //4.数据库系统退票
  660. $cancel_result = $order_main->cancelOrderOne($go_order_id);
  661. if (!$cancel_result) {
  662. return Util::returnJsEr('去返程订单系统退票出错,请稍后重试' . $go_order_id);
  663. }
  664. if ($back_order_id != '') {
  665. $cancel_result = $order_main->cancelOrderOne($back_order_id);
  666. if (!$cancel_result) {
  667. return Util::returnJsEr('返程订单系统退票出错,请稍后重试' . $back_order_id);
  668. }
  669. }
  670. //5.将数据插入退票表
  671. $insert_result = $order_main->insCancelWeChatOrder($go_order_id, $price, $serial_number);
  672. if (!$insert_result) {
  673. return json_encode($insert_result);
  674. }
  675. OrderLog::cancelOrder($order_id, 2);
  676. return Util::returnJsSu('退票成功');
  677. }
  678. /**
  679. * Function Description:校验价格
  680. * Function Name: getPrice
  681. * @param $tick_info
  682. * @param $channel_id
  683. *
  684. * @return bool
  685. *
  686. * @author 娄梦宁
  687. */
  688. public function getPrice($tick_info, $channel_id)
  689. {
  690. $orderMain = new OrderMain();
  691. $runMain = new RunMain();
  692. $count = substr_count($tick_info, '{');
  693. if ($count == 1) {//单程票
  694. $tick_info = ltrim($tick_info, '{');
  695. $tick_info = rtrim($tick_info, '}');
  696. $tick_info_arr = explode(',', $tick_info);
  697. $tick_id = $tick_info_arr[2];
  698. $price_check = $orderMain->getPriceGo($tick_id);
  699. $price = $tick_info_arr[3];
  700. if ($price_check == $price) {
  701. return true;
  702. }
  703. } elseif ($count == 2) {//往返票种
  704. $tick_info = str_replace('}{', ',', $tick_info);
  705. $tick_info = ltrim($tick_info, '{');
  706. $tick_info = rtrim($tick_info, '}');
  707. $tick_info_arr = explode(',', $tick_info);
  708. $go_tick_id = $tick_info_arr[2];
  709. $go_tick_price = $tick_info_arr[3];
  710. $go_discount_price1 = $runMain->getDiscountPrice($go_tick_id, $channel_id);
  711. $go_price = $orderMain->getPriceGo($go_tick_id);
  712. if (count($go_discount_price1) == 0) {
  713. $go_discount_price = '0';
  714. } else {
  715. $go_discount_price = $go_discount_price1['data']['off_value'];
  716. }
  717. $back_tick_id = $tick_info_arr[7];
  718. $back_tick_price = $tick_info_arr[8];
  719. $back_discount_price1 = $runMain->getDiscountPrice($back_tick_id, $channel_id);
  720. $back_price = $orderMain->getPriceGo($back_tick_id);
  721. if (count($back_discount_price1) == 0) {
  722. $back_discount_price = '0';
  723. } else {
  724. $back_discount_price = $back_discount_price1['data']['off_value'];
  725. }
  726. if ($go_tick_price == ($go_price - $go_discount_price) && $back_tick_price == ($back_price - $back_discount_price)) {
  727. return true;
  728. }
  729. }
  730. return false;
  731. }
  732. }