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

416 rader
16 KiB

  1. <?php
  2. /**
  3. *
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 娄梦宁
  12. * PhpStorm OrderlistModel.php
  13. * Create By 2016/11/11 10:31 $
  14. */
  15. namespace Order\Model;
  16. use Base\Tool\DbTable;
  17. use Base\Tool\Tool;
  18. use Util\Util\Util;
  19. class OrderlistModel extends DbTable
  20. {
  21. public $db = 'CST';
  22. /**
  23. * Function Description:获取订单列表
  24. * Function Name: getordering
  25. * @param $userId
  26. *
  27. * @return array
  28. *
  29. * @author 娄梦宁
  30. */
  31. public function getordering($userId)
  32. {
  33. //判断哪些是周边游订单,哪些是普通订单
  34. $sql = "" . "SELECT
  35. c.line_type,
  36. a.order_id
  37. FROM
  38. order_main a
  39. LEFT JOIN opera_line c ON c.line_id = a.PARENT_PROD_ID
  40. WHERE
  41. a.MEMBER_ID = $userId
  42. and a.outside_sale_org_id = 164
  43. AND a.parent_order_id = 0
  44. AND a.cancel_flag = 0
  45. GROUP BY
  46. a.order_id";
  47. $arr1 = $this->fetchAll($sql);
  48. $around = '';
  49. $normol = '';
  50. foreach ($arr1 as $v) {
  51. if ($v['line_type'] == 369) {
  52. $around .= $v['order_id'] . ',';
  53. } else {
  54. $normol .= $v['order_id'] . ',';
  55. }
  56. }
  57. $around = rtrim($around, ',');
  58. $normol = rtrim($normol, ',');
  59. //进行中
  60. $sql = "" . "SELECT
  61. a.order_status,
  62. a.order_id,
  63. a.create_time,
  64. floor(a.order_price) as price,
  65. a.order_status,
  66. substring_index(substring_index(a.ORDER_DESCRIPTION,',',-1),'|',1) AS pnum,
  67. b.PROD_START_STATION_DATE AS start_date,
  68. b.PROD_START_STATION_TIME AS start_time,
  69. b.PROD_end_STATION_TIME AS end_time,
  70. b.PROD_START_STATION_res_NAME AS start_station,
  71. b.PROD_end_STATION_res_NAME AS end_station,
  72. curdate() AS WEEK,
  73. b.PROD_START_STATION_area_NAME as start_city,
  74. b.PROD_end_STATION_area_NAME as end_city
  75. FROM
  76. order_main a
  77. INNER JOIN order_main b ON a.order_id = b.PARENT_ORDER_ID
  78. WHERE
  79. a.order_id in ($normol)
  80. and a.outside_sale_org_id = 164
  81. and a.order_status in (145,146)
  82. and a.cancel_flag=0
  83. and b.cancel_flag=0
  84. GROUP BY
  85. a.ORDER_ID
  86. ORDER BY start_date desc ,start_time desc
  87. ";
  88. $result1 = $this->fetchAll($sql);
  89. $sql = "" . "SELECT
  90. a.order_status,
  91. a.order_id,
  92. a.create_time,
  93. floor(a.order_price) as price,
  94. a.order_status,
  95. 369 as 'line_type',
  96. substring_index(a.ORDER_DESCRIPTION, '|' ,- 1) AS pnum,
  97. b.PROD_START_STATION_DATE AS start_date,
  98. b.PROD_START_STATION_TIME AS start_time,
  99. b.PROD_end_STATION_TIME AS end_time,
  100. b.PROD_START_STATION_res_NAME AS start_station,
  101. b.PROD_end_STATION_res_NAME AS end_station,
  102. curdate() AS WEEK,
  103. b.PROD_START_STATION_area_NAME as start_city,
  104. b.PROD_end_STATION_area_NAME as end_city,
  105. c.line_name,
  106. ifnull(c.line_describe,'') as line_describe
  107. FROM
  108. order_main a
  109. INNER JOIN order_main b ON a.order_id = b.PARENT_ORDER_ID
  110. LEFT JOIN opera_line c ON a.PARENT_PROD_ID = c.line_id
  111. WHERE
  112. a.order_id in ($around)
  113. and a.outside_sale_org_id = 164
  114. and a.order_status in (145,146)
  115. and a.cancel_flag=0
  116. and b.cancel_flag=0
  117. GROUP BY
  118. a.ORDER_ID
  119. ORDER BY start_date desc ,start_time desc
  120. ";
  121. $result3 = $this->fetchAll($sql);
  122. $result1 = array_merge($result1, $result3);
  123. //已完成
  124. $sql = "" . "SELECT
  125. a.order_status,
  126. a.order_id,
  127. a.create_time,
  128. floor(a.order_price) as price,
  129. a.order_status,
  130. substring_index(substring_index(a.ORDER_DESCRIPTION,',',-1),'|',1) AS pnum,
  131. b.PROD_START_STATION_DATE AS start_date,
  132. b.PROD_START_STATION_TIME AS start_time,
  133. b.PROD_end_STATION_TIME AS end_time,
  134. b.PROD_START_STATION_res_NAME AS start_station,
  135. b.PROD_end_STATION_res_NAME AS end_station,
  136. curdate() AS WEEK,
  137. b.PROD_START_STATION_area_NAME as start_city,
  138. b.PROD_end_STATION_area_NAME as end_city,
  139. curdate() AS WEEK
  140. FROM
  141. order_main a
  142. INNER JOIN order_main b ON a.order_id = b.PARENT_ORDER_ID
  143. WHERE
  144. a.order_id in ($normol)
  145. and a.outside_sale_org_id = 164
  146. and a.order_status in (147,148)
  147. and a.cancel_flag=0
  148. and b.cancel_flag=0
  149. GROUP BY
  150. a.ORDER_ID
  151. ORDER BY start_date desc ,start_time desc
  152. ";
  153. $result2 = $this->fetchAll($sql);
  154. $sql = "" . "SELECT
  155. a.order_status,
  156. a.order_id,
  157. a.PARENT_ORDER_ID,
  158. a.create_time,
  159. 369 as 'line_type',
  160. floor(a.order_price) as price,
  161. a.order_status,
  162. substring_index(a.ORDER_DESCRIPTION, '|' ,- 1) AS pnum,
  163. b.PROD_START_STATION_DATE AS start_date,
  164. b.PROD_START_STATION_TIME AS start_time,
  165. b.PROD_end_STATION_TIME AS end_time,
  166. b.PROD_START_STATION_res_NAME AS start_station,
  167. b.PROD_end_STATION_res_NAME AS end_station,
  168. curdate() AS WEEK,
  169. b.PROD_START_STATION_area_NAME as start_city,
  170. b.PROD_end_STATION_area_NAME as end_city,
  171. c.line_name,
  172. ifnull(c.line_describe,'') as line_describe
  173. FROM
  174. order_main a
  175. INNER JOIN order_main b ON a.order_id = b.PARENT_ORDER_ID
  176. LEFT JOIN opera_line c ON a.PARENT_PROD_ID = c.line_id
  177. WHERE
  178. a.order_id in ($around)
  179. and a.outside_sale_org_id = 164
  180. and a.order_status in (147,148)
  181. and a.cancel_flag=0
  182. and b.cancel_flag=0
  183. GROUP BY
  184. a.ORDER_ID
  185. ORDER BY start_date desc ,start_time desc
  186. ";
  187. $result4 = $this->fetchAll($sql);
  188. $result2 = array_merge($result2, $result4);
  189. if ($result1 === false || $result2 === false) {
  190. return Util::returnArrEr('获取订单失败!');
  191. } else {
  192. $new1 = array();
  193. $new2 = array();
  194. foreach ($result1 as $k => $v) {
  195. if ($v['week'] != $v['start_date']) {
  196. $wek =Tool::getWeek($v['start_date']);
  197. $result1[$k]['week'] = $wek;
  198. } else {
  199. $result1[$k]['week'] = "今天";
  200. }
  201. $result1[$k]['start_date'] = substr($result1[$k]['start_date'], 5, 5);
  202. $key = $result1[$k]['start_date'].$result1[$k]['start_time'].$result1[$k]['order_id'];
  203. $new1[$key] = $result1[$k];
  204. }
  205. foreach ($result2 as $k => $v) {
  206. if ($v['week'] != $v['start_date']) {
  207. $wek =Tool::getWeek($v['start_date']);
  208. $result2[$k]['week'] = $wek;
  209. } else {
  210. $result2[$k]['week'] = "今天";
  211. }
  212. $key = $result2[$k]['start_date'].$result2[$k]['start_time'].$result2[$k]['order_id'];
  213. $result2[$k]['start_date'] = substr($result2[$k]['start_date'], 5, 5);
  214. $new2[$key] = $result2[$k];
  215. }
  216. krsort($new1);
  217. krsort($new2);
  218. $new1=array_values($new1);
  219. $new2=array_values($new2);
  220. $result = array(
  221. 'doing' => $new1,
  222. 'done' => $new2
  223. );
  224. return Util::returnArrSu('', $result);
  225. }
  226. }
  227. /**
  228. * Function Description:获取订单详情
  229. * Function Name: getOrderall
  230. * @param $order_id
  231. *
  232. * @return array
  233. *
  234. * @author 娄梦宁
  235. */
  236. public function getOrderall($order_id)
  237. {
  238. //判断是否有返程,若有返程,获取返程order_id
  239. $sql = "select back_orderid,to_orderid from to_from where to_orderid= $order_id or back_orderid=$order_id limit 1";
  240. $back = $this->fetchAll($sql);
  241. if (count($back) == 1) {
  242. //有返程
  243. $back_orderid = $back[0]['back_orderid'];
  244. $to_orderid = $back[0]['to_orderid'];
  245. $id = "$to_orderid,$back_orderid";
  246. } elseif (count($back) == 0) {
  247. $id = $order_id;
  248. } else {
  249. return Util::returnArrEr('获取返程详情失败!');
  250. }
  251. $sql = '' . "select PARENT_PROD_ID from order_main where order_id=$order_id ";
  252. $around = $this->fetchOne($sql);
  253. if ($around != 0) {
  254. $temp = 'a';
  255. $pnum = "substring_index(a.ORDER_DESCRIPTION, '|' ,- 1)";
  256. } else {
  257. $temp = 'c';
  258. $pnum = "substring_index(substring_index(a.ORDER_DESCRIPTION,',',-1),'|',1)";
  259. }
  260. $sql = '' . "SELECT
  261. c.run_date,
  262. b.line_id,
  263. a.order_id,
  264. a.create_time,
  265. a.order_status,
  266. c.PROD_START_STATION_res_NAME AS start_station,
  267. c.PROD_end_STATION_res_NAME AS end_station,
  268. $pnum AS pcount,
  269. substring_index(a.ORDER_DESCRIPTION, ',', 1) AS seat_type,
  270. a.customer_name,
  271. a.customer_mobile,
  272. floor(a.order_price) as order_price,
  273. c.PROD_START_STATION_DATE AS start_date,
  274. c.PROD_START_STATION_TIME AS start_time,
  275. c.PROD_end_STATION_TIME AS end_time,
  276. b.line_type,
  277. ifnull(b.line_describe,'') as line_describe,
  278. b.line_name,
  279. a.ORDER_PROD_TYPE as testaround
  280. FROM
  281. order_main a
  282. LEFT JOIN order_main c ON c.PARENT_ORDER_ID = a.order_id
  283. LEFT JOIN opera_line b ON $temp.PARENT_PROD_ID = b.line_id
  284. WHERE
  285. a.cancel_flag = 0
  286. AND b.cancel_flag = 0
  287. AND a.order_id IN ($id)
  288. and a.outside_sale_org_id = 164
  289. GROUP BY
  290. a.order_id
  291. ORDER BY
  292. a.order_id ";
  293. $result = $this->fetchAll($sql);
  294. if ($result === false) {
  295. return Util::returnArrEr('获取订单详情失败!');
  296. } else {
  297. $price = 0;
  298. foreach ($result as $v) {
  299. $price += (int)$v['order_price'];
  300. }
  301. $result['price'] = $price;
  302. $starttime = $result[0]['start_date'] . " " . $result[0]['start_time'];
  303. $timer = strtotime($starttime) - time();
  304. //判断是否可以退票
  305. if ($timer > 1800) {
  306. $result['back_ticket'] = 1;
  307. } else {
  308. $result['back_ticket'] = 0;
  309. }
  310. //判断是否是周边游,是周边游则查出出行人信息
  311. if ($result[0]['testaround'] == 369) {
  312. $sql = ""."SELECT DISTINCT
  313. c.PROD_start_STATION_res_NAME AS start_station,
  314. c.PROD_START_STATION_DATE AS end_date,
  315. c.PROD_START_STATION_TIME AS end_time,
  316. c.PROD_end_STATION_res_NAME as end_station
  317. FROM
  318. order_main a
  319. INNER JOIN order_main c ON a.order_id = c.PARENT_ORDER_ID
  320. WHERE
  321. a.PROD_START_STATION_res_id <> c.PROD_START_STATION_res_id
  322. and a.order_id=$order_id
  323. ";
  324. $shou = $this->fetchAll($sql);
  325. $result[1] = $result[0];
  326. $result[1]['start_station'] = $shou[0]['start_station'];
  327. $result[1]['start_date'] = $shou[0]['end_date'];
  328. $result[1]['start_time'] = $shou[0]['end_time'];
  329. $result[1]['end_station'] = $shou[0]['end_station'];
  330. $result[1]['line_type'] = 369;
  331. $sql = ""."SELECT DISTINCT
  332. b.customer_name as p_name,
  333. b.CUSTOMER_ID_NO as p_phone
  334. FROM
  335. order_main a
  336. INNER JOIN order_main b ON a.order_id = b.parent_order_id
  337. WHERE
  338. a.order_id IN ($id)
  339. ";
  340. $result1 = $this->fetchAll($sql);
  341. if ($result1 === false) {
  342. return Util::returnArrEr('获取出行人信息失败!');
  343. } else {
  344. $result['customer'] = $result1;
  345. }
  346. }
  347. foreach ($result as $k => $v) {
  348. if ( strtotime(date('Y-m-d', time())) != strtotime($v['start_date'])) {
  349. $wek =Tool::getWeek($v['start_date']);
  350. $result[$k]['week'] = $wek;
  351. } else {
  352. $result[$k]['week'] = '今天';
  353. }
  354. $result[$k]['start_date'] = date('m月j日', strtotime($result[$k]['start_date']));
  355. }
  356. if (isset($result[1])) {
  357. $result['trip_type'] = 2;
  358. } else {
  359. $result['trip_type'] = 1;
  360. }
  361. if ($result[0]['order_status'] == 145) {
  362. $timer = time() - strtotime($result[0]['create_time']);
  363. if ($timer < 900 && $timer > 0) {
  364. $result['timer'] = 900 - $timer;
  365. } else {
  366. $result['timer'] = 0;
  367. }
  368. } else {
  369. $result['timer'] = 0;
  370. }
  371. $result['order_id'] = $id;
  372. $result['order_status'] = $result[0]['order_status'];
  373. $result['line_type'] = $result[0]['line_type'];
  374. return Util::returnArrSu('', $result);
  375. }
  376. }
  377. /**
  378. * Function Description:取消订单调用存储过程
  379. * Function Name: cancel_order
  380. * @param $order_id
  381. * @param $user_id
  382. *
  383. * @return array
  384. *
  385. * @author 娄梦宁
  386. */
  387. public function cancel_order($order_id, $user_id)
  388. {
  389. // $sql = "call SP_CANCEL_ORDER($user_id,$order_id) ";
  390. // $result = $this->execSql($sql);
  391. $cancel_url = 'http://'.CS1_DOMAIN.'/api/submit-order/cancel-bus-order';
  392. $send_post_data = array(
  393. "order_id" => $order_id,
  394. "user_id" => $user_id,
  395. "if_link" => 0,
  396. "cancel_reason" => "用户取消订单",
  397. 'opera_platform' => '微信商城'
  398. );
  399. $result = Util::httpRequest( $cancel_url, $send_post_data );
  400. $result_array = json_decode($result, true);
  401. if ($result_array === false || !isset($result_array["code"]) || $result_array["code"] != 0 ) {
  402. return Util::returnArrEr('取消订单失败!');
  403. } else {
  404. return Util::returnArrSu('取消订单成功');
  405. }
  406. }
  407. }