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.
 
 
 
 

378 lines
17 KiB

  1. <?php
  2. /*
  3. Author:fuhc
  4. Compeny:Spiders Travel
  5. */
  6. //require_once '../../Common/Mysql.php';
  7. if (ALLOW_ORIGIN)
  8. header("Access-Control-Allow-Origin:*");
  9. $method = isset($_POST['method']) ? $_POST['method'] : "";
  10. $user_id = getUserId();
  11. //$user_id=1;
  12. if ($user_id == false) {
  13. echo json_encode(array("code" => "1", "info" => "用户未登录"));
  14. exit;
  15. }
  16. //$user_id=450;
  17. //取消订单原因
  18. if (isset($_POST['reason'])) {
  19. $reason = $_POST['reason'];
  20. $order_id = $_POST['order_id'];
  21. $clock = $_POST['clock'];
  22. // $return_data = array();
  23. // $return_data["code"] = 1;
  24. // $return_data["info"] = $reason;
  25. $pdo_insert = conn();
  26. $sql = "insert into order_comment(ORDER_ID,COMMENT_TXT,CREATE_TIME) VALUES ({$order_id},'{$reason}','{$clock}')";
  27. $result = $pdo_insert->exec($sql);
  28. }
  29. if ($method == "cancelOrder") {
  30. } else {
  31. $condition = array();
  32. $timelimit = isset($_POST['timelimit']) ? $_POST['timelimit'] : '';
  33. $starttime = isset($_POST['starttime']) ? $_POST['starttime'] : '';
  34. $endtime = isset($_POST['endtime']) ? $_POST['endtime'] : '';
  35. $ordersource = isset($_POST['ordersource']) ? $_POST['ordersource'] : 0;
  36. $typelimit = isset($_POST['typelimit']) ? $_POST['typelimit'] : '';
  37. $moresearch = isset($_POST['moresearch']) ? trim($_POST['moresearch']) : '';
  38. $orderstatus = isset($_POST['orderstatus']) ? $_POST['orderstatus'] : 0;
  39. if ($orderstatus) {
  40. $condition[] = " a.order_status =" . $orderstatus;
  41. }
  42. if ($timelimit == 0) {
  43. empty($starttime) ? null : $condition[] = ' a.create_time >= "' . $starttime . ' 00:00:00' . '"'; //创建时间条件筛选
  44. empty($endtime) ? null : $condition[] = ' a.create_time <= "' . $endtime . ' 23:59:01' . '"';
  45. } elseif ($timelimit == 1) {
  46. empty($starttime) ? null : $condition[] = ' a.run_date >= "' . $starttime . '"'; // 出发时间筛选
  47. empty($endtime) ? null : $condition[] = ' a.run_date <= "' . $endtime . ' 23:59:01' . '"';
  48. }
  49. if ($ordersource == '-1') {
  50. } else {
  51. empty($ordersource) ? null : $condition[] = ' a.outside_sale_org_id = ' . $ordersource;
  52. }
  53. if ($typelimit == 1) {
  54. $condition[] = ' a.order_prod_type in (258,259,282,311)';
  55. } else if( $typelimit == 3873593 ) {
  56. $condition[] = ' a.order_prod_type=311 AND a.parent_prod_id=' . $typelimit;
  57. } else {
  58. empty($typelimit) ? $condition[] = ' a.order_prod_type in (258,259)' : $condition[] = ' a.order_prod_type= ' . $typelimit;
  59. }
  60. empty($moresearch) ? $condition2 = 1 : $condition2 = ' a.order_id like "%' . $moresearch . '%" or a.customer_name like "%' . $moresearch . '%" or a.customer_mobile like "%' . $moresearch . '%" or a.outside_order_no like "%' . $moresearch . '%" or a.customer_memo like "%'.$moresearch.'%" ';
  61. if( $condition2 != 1 ) {
  62. $condition[] = " ( ".$condition2." ) ";
  63. }
  64. $condition = implode(' AND ', $condition);
  65. //状态筛选环境
  66. $condition1 = array();
  67. if ($timelimit == 0) {
  68. empty($starttime) ? null : $condition1[] = ' a.create_time >= "' . $starttime . ' 00:00:00' . '"'; //创建时间条件筛选
  69. empty($endtime) ? null : $condition1[] = ' a.create_time <= "' . $endtime . ' 23:59:01' . '"';
  70. } elseif ($timelimit == 1) {
  71. empty($starttime) ? null : $condition1[] = ' a.run_date >= "' . $starttime . '"'; // 出发时间筛选
  72. empty($endtime) ? null : $condition1[] = ' a.run_date <= "' . $endtime . ' 23:59:01' . '"';
  73. }
  74. if ($ordersource == '-1') {
  75. } else {
  76. empty($ordersource) ? null : $condition1[] = ' a.outside_sale_org_id = ' . $ordersource;
  77. }
  78. if ($typelimit == 1) {
  79. $condition1[] = ' a.order_prod_type in (258,259,282,311)';
  80. } else if( $typelimit == 3873593 ) {
  81. $condition1[] = ' a.order_prod_type=311 AND a.parent_prod_id=' . $typelimit;
  82. } else {
  83. empty($typelimit) ? $condition1[] = ' a.order_prod_type in (258,259) AND a.parent_prod_id<>3873593 ' : $condition1[] = ' a.order_prod_type= ' . $typelimit.' AND a.parent_prod_id<>3873593 ';
  84. }
  85. //2017.3.30 筛选条件新增当前用户运营主体
  86. $sql=''."select main_corp_id from base_user where id=$user_id limit 1";
  87. $user_corp_id=$pdo->query($sql);
  88. $rowset = $user_corp_id->fetchAll(PDO::FETCH_ASSOC);
  89. $main_corp_id=$rowset[0]['main_corp_id'];
  90. if($main_corp_id!=0){
  91. $sql=''."select group_concat(prod_id) as prod_arr from opera_product a where main_corp_id = $main_corp_id and parent_id=0 and cancel_flag=0";
  92. $result=$pdo->query($sql);
  93. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  94. $result=$rowset[0]['prod_arr'];
  95. $condition1[] = " a.prod_id in($result)";
  96. }
  97. if( $condition2 != 1 ) {
  98. $condition1[] = " ( ".$condition2." ) ";
  99. }
  100. $condition1 = implode(' AND ', $condition1);
  101. //结束
  102. $orderstatus = isset($_POST['orderstatus']) ? (empty($_POST['orderstatus']) ? 0 : $_POST['orderstatus']) : 0;
  103. $paystatus = isset($_POST['paystatus']) ? (empty($_POST['paystatus']) ? -1 : $_POST['paystatus']) : -1;
  104. $billingstatus = isset($_POST['billingstatus']) ? $_POST['billingstatus'] : '';
  105. $mealbounce = isset($_POST['mealbounce']) ? $_POST['mealbounce'] : '';
  106. $refund = isset($_POST['refund']) ? $_POST['refund'] : '';
  107. $export = isset($_POST['export']) ? $_POST['export'] : '';
  108. //2016-07-15新增
  109. $start_area = isset($_POST['start_area']) ? $_POST['start_area'] : '';
  110. $end_area = isset($_POST['end_area']) ? $_POST['end_area'] : '';
  111. $line = isset($_POST['line']) ? $_POST['line'] : '';
  112. //..暂未加入存储过程
  113. $currpage = isset($_POST['currpage']) ? (empty($_POST['currpage']) ? 1 : $_POST['currpage']) : 1;
  114. $pagesize = isset($_POST['pagesize']) ? (empty($_POST['pagesize']) ? 10 : $_POST['pagesize']) : 10;
  115. $pdo = conn();
  116. // $sql = "select count(*) as will from order_main as a where a.order_status=145 and a.PARENT_ORDER_ID=0 and a.CANCEL_FLAG=0 and " . $condition1 . ";
  117. // select count(order_id) as pay from order_main as a where a.order_status=146 and a.PARENT_ORDER_ID=0 and a.CANCEL_FLAG=0 and " . $condition1 . ";
  118. // select count(order_id) as over from order_main as a where a.order_status=147 and a.PARENT_ORDER_ID=0 and a.CANCEL_FLAG=0 and " . $condition1 . ";
  119. // select count(order_id) as cancel from order_main as a where a.order_status=148 and a.PARENT_ORDER_ID=0 and a.CANCEL_FLAG=0 and " . $condition1;
  120. //
  121. $sql = "select a.order_status, count(a.order_id) as order_num from order_main as a where a.PARENT_ORDER_ID=0 and a.CANCEL_FLAG=0 and " . $condition1 . " group by a.order_status ";
  122. $result = $pdo->query($sql);
  123. writeLog("--des_order_list:" . __LINE__ . "|" . $sql);
  124. $data_count_list = array("will" => 0, "pay" => 0, "over" => "0", "cancel" => 0);
  125. // $rowset = $result -> fetchAll(PDO::FETCH_ASSOC);
  126. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  127. $result->closeCursor();
  128. foreach ($rowset as $row_info) {
  129. switch ($row_info["order_status"]) {
  130. case 145:
  131. $row_index = "will";
  132. break;
  133. case 146:
  134. $row_index = "pay";
  135. break;
  136. case 147:
  137. $row_index = "over";
  138. break;
  139. case 148:
  140. $row_index = "cancel";
  141. break;
  142. default:
  143. $row_index = "will";
  144. break;
  145. }
  146. $data_count_list[$row_index] = $row_info["order_num"];
  147. }
  148. if ($condition2 != 1) {
  149. $condition2 = " where ( " . $condition2 . " ) AND " . $condition1;
  150. } else {
  151. $condition2 = " where " . $condition1;
  152. }
  153. $sql = "select a.order_id "
  154. . "from order_main as a "
  155. . $condition2;
  156. //echo $sql;die;
  157. writeLog("--des_order_list:" . __LINE__ . "|" . $sql);
  158. $result = $pdo->query($sql);
  159. $json22 = array();
  160. do {
  161. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  162. if ($rowset) {
  163. $json22 = $rowset;
  164. }
  165. } while ($result->nextRowset());
  166. if (empty($json22)) {
  167. $data = (array("code" => "1", "info" => "此条件下没有订单", "list_count" => 0, "searchInfo" => array()));
  168. echo json_encode($data);
  169. die;
  170. }
  171. foreach ($json22 as $v) {
  172. $arr_o[] = $v['order_id'];
  173. }
  174. $arr_o = implode(',', $arr_o);
  175. // $sql_org = "select org_id,org_name from base_organization ";
  176. $sql_org = "select id as org_id, supplier_name as org_name from base_supplier ";
  177. $result_org = $pdo->query($sql_org);
  178. $org_list = $result_org->fetchAll(PDO::FETCH_ASSOC);
  179. $o_list = array();
  180. foreach ($org_list as $v) {
  181. $o_list[$v['org_id']] = array('org_name' => $v['org_name'], 'org_id' => $v['org_id']);
  182. }
  183. //3-28新增查询退款截止日期,退款截止时间--娄梦宁
  184. $sql = "select c.true_name as create_user_name, b.refund_limit_time,b.refund_limit_day,a.prod_name,bs.supplier_name as top_org_name, a.order_prod_type,a.order_description,a.run_date,a.ORDER_PAY_MAIN_ID,a.order_id,a.customer_name,a.customer_mobile,a.customer_id_type,a.customer_id_no,a.order_price,a.order_status,a.create_time,a.prod_id,a.customer_memo,a.main_create_user_id,a.outside_sale_org_id,a.outside_order_no,a.order_title_id "
  185. . "from order_main as a left join opera_product as b on a.prod_id=b.prod_id left join base_user as c on c.id = a.create_user_id left join base_supplier as bs on b.top_org_id = bs.id "
  186. . "where a.PARENT_ORDER_ID=0 and a.CANCEL_FLAG=0 and a.order_id in (" . $arr_o . ") AND " . $condition . " order by a.create_time desc";
  187. $result = $pdo->query($sql);
  188. writeLog("--des_order_list:" . __LINE__ . "|" . $sql);
  189. if (false != $result) {
  190. $json = array();
  191. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  192. if ($rowset) {
  193. $json = $rowset;
  194. }
  195. $result->closeCursor();
  196. }
  197. if (empty($json)) {
  198. $data = (array("code" => "1", "info" => '此条件下没有订单', "list_count" => 0, "searchInfo" => array()));
  199. echo json_encode($data);
  200. die;
  201. }
  202. //获取销售渠道信息
  203. $json_id = array();
  204. foreach ($json as $v) {
  205. $json_id[] = $v['order_id'];
  206. $json2[] = $v['order_id'];
  207. $org[$v['order_id']] = $v['main_create_user_id'];
  208. if ($v['outside_sale_org_id'] == 0 || !isset($o_list[$v['outside_sale_org_id']])) {
  209. $v['org_name'] = 'CS平台下单';
  210. } else {
  211. $v['org_name'] = $o_list[$v['outside_sale_org_id']]["org_name"];
  212. }
  213. $org_name[$v['order_id']] = $v['org_name'];
  214. $outside_order_no[$v['order_id']] = $v['outside_order_no'];
  215. $order_info[$v['order_id']] = $v; //价格手机 姓名 run_time pay_time
  216. }
  217. $array_order_desc = array();
  218. foreach ($order_info as $v) {
  219. $arr_temp = explode('|', $v['order_description']);
  220. $arr = array();
  221. foreach ($arr_temp as $k => $v2) {
  222. if (!empty($v2))
  223. $arr[] = explode(',', $v2);
  224. }
  225. $array_order_desc[$v['order_id']] = $arr;
  226. }
  227. //var_dump($array_order_desc);die;
  228. $sql3 = "select parent_order_id,run_date,run_time,PROD_START_STATION_AREA_NAME,PROD_START_STATION_RES_NAME,PROD_END_STATION_AREA_NAME,PROD_END_STATION_RES_NAME,order_title_id "
  229. . "from order_main "
  230. . "where parent_order_id in (" . implode(",", $json_id) . ")";
  231. $result3 = $pdo->query($sql3);
  232. $rowset3 = $result3->fetchAll(PDO::FETCH_ASSOC);
  233. foreach ($rowset3 as $v) {
  234. $station[$v['parent_order_id']] = $v;//上车站下车站 详情
  235. }
  236. //获取支付方式
  237. $sql2 = "select a.ORDER_ID,b.PAY_TYPE_ID_1,c.TYPE_NAME from (ORDER_MAIN a left join ORDER_PAY_DETAIL b on a.ORDER_PAY_MAIN_ID=b.pay_main_id)
  238. left join dict_type c on c.id=b.PAY_TYPE_ID_1 "
  239. . " where a.ORDER_ID in (" . implode(",", $json_id) . ")";
  240. $result2 = $pdo->query($sql2);
  241. do {
  242. $rowset2 = $result2->fetchAll(PDO::FETCH_ASSOC);
  243. if ($rowset2) {
  244. $pay_type[] = $rowset2;
  245. }
  246. } while ($result2->nextRowset());
  247. foreach ($pay_type[0] as $v) {
  248. $pay_type_arr[$v['ORDER_ID']] = $v['TYPE_NAME']; //支付方式
  249. }
  250. //支付状态
  251. $sql4 = "select a.ORDER_ID,a.order_status,c.TYPE_NAME from (ORDER_MAIN a left join ORDER_PAY_DETAIL b on a.ORDER_PAY_MAIN_ID=b.pay_main_id)
  252. left join dict_type c on c.id=a.ORDER_STATUS "
  253. . " where a.ORDER_ID in (" . implode(",", $json_id) . ")";
  254. $result4 = $pdo->query($sql4);
  255. do {
  256. $rowset4 = $result4->fetchAll(PDO::FETCH_ASSOC);
  257. if ($rowset4) {
  258. $order_sta[] = $rowset4;
  259. }
  260. } while ($result4->nextRowset());
  261. foreach ($order_sta[0] as $v) {
  262. $order_status[$v['ORDER_ID']] = $v['TYPE_NAME']; //订单的状态
  263. }
  264. $array_order_list = array();
  265. //echo count($pay_type_arr),'--', count($json_id);
  266. //var_dump($array_order_desc);die;
  267. foreach ($json_id as $v) {
  268. $tic = '';
  269. $product_info = array();
  270. if ($order_info[$v]['order_prod_type'] == 258 || $order_info[$v]['order_prod_type'] == 259) {
  271. foreach ($array_order_desc[$v] as $v1) {
  272. $tic .= str_replace('迪士尼剧场', '', $v1[0]) . '×' . $v1[2] . ' ';
  273. if (isset($v1['ifback']))
  274. $ifback = $v1['ifback'];
  275. }
  276. $product_info = $order_info[$v]['prod_name'] . '<br> ' . $tic;
  277. $ifdisn = 0;
  278. } elseif ($order_info[$v]['order_prod_type'] == 282) {
  279. foreach ($array_order_desc[$v] as $v1) {
  280. $tic .= str_replace('周庄门票', '', $v1[0]) . '×' . $v1[2] . ' ';
  281. if (isset($v1['ifback']))
  282. $ifback = $v1['ifback'];
  283. }
  284. $product_info = $order_info[$v]['prod_name'] . '' . $tic;
  285. if ($order_info[$v]['run_date'] <= date('Y-m-d', time()) || $order_info[$v]['order_status'] != 146) {
  286. $ifdisn = 0;
  287. } else {
  288. $ifdisn = 1;
  289. }
  290. } else {//不是周庄也不是迪士尼--娄梦宁
  291. foreach ($array_order_desc[$v] as $ky=>$v1) {
  292. $num=count($array_order_desc[$v]);
  293. if($ky!=($num-1)){
  294. $tic .=$v1[0].'×' . $v1[2] . ' ';
  295. } else {
  296. continue;
  297. }
  298. if (isset($v1['ifback']))
  299. $ifback = $v1['ifback'];
  300. }
  301. $product_info = $order_info[$v]['prod_name'] . '<br> ' . $tic;
  302. //下面这句判断是否可退票
  303. $time1='-'.$order_info[$v]['refund_limit_day'].' day';
  304. $time2=$order_info[$v]['run_date'].' '.$order_info[$v]['refund_limit_time'];
  305. $refund_time=strtotime($time1,strtotime($time2));
  306. if (time()>$refund_time|| $order_info[$v]['order_status'] != 146 || $order_info[$v]['prod_id']==3873593) {
  307. $ifdisn = 0;
  308. } else {
  309. $ifdisn = 1;
  310. }
  311. }
  312. if ($product_info != array()) {
  313. $array_order_list[] = array(
  314. 'order_id' => $v,
  315. 'create_user_name' => $order_info[$v]['create_user_name'],
  316. 'create_time' => $order_info[$v]['create_time'],
  317. 'top_org_name' => $order_info[$v]['top_org_name'],
  318. 'org_name' => $org_name[$v],
  319. 'product_info' => $product_info,
  320. 'outside_order_no' => $outside_order_no[$v],
  321. 'ifdisney' => $ifdisn,
  322. 'ifzhouzhuang' => (isset($station[$v]) && isset($station[$v]["order_title_id"]) && $station[$v]["order_title_id"] > 0) ? 0 : $ifdisn,
  323. 'order_title_id' => (isset($station[$v]) && isset($station[$v]["order_title_id"])) ? $station[$v]["order_title_id"] : 0,
  324. 'run_time' => (isset($station[$v]['run_date']) && isset($station[$v]['run_time'])) ? $station[$v]['run_date'] . ' ' . $station[$v]['run_time'] : "",
  325. 'customer_info' => $order_info[$v]['customer_name'] . ' <br>' . $order_info[$v]['customer_mobile'] . '<br> ' . $order_info[$v]['customer_id_no'],
  326. 'order_pay' => $order_info[$v]['order_price'],
  327. 'customer_memo' => $order_info[$v]['customer_memo'],
  328. 'order_pay_type' => $pay_type_arr[$v],
  329. 'order_status' => $order_status[$v],
  330. );
  331. }
  332. }
  333. $list_count = count($array_order_list);
  334. //echo $list_count;
  335. $sta = ($currpage - 1) * ($pagesize + 0);
  336. $array_order_list = array_slice($array_order_list, $sta, $pagesize);
  337. $data = (array("code" => "0", "info" => "", "list_count" => $list_count, "searchInfo" => $array_order_list));
  338. if (1) {
  339. $json = array("code" => "0", "info" => "");
  340. $json['list_count'] = $list_count;
  341. $json['totalTickets'] = $list_count;
  342. $json['totalPages'] = ceil($list_count / $pagesize);
  343. $json['currentpage'] = $currpage;
  344. $json['pagesize'] = $pagesize;
  345. $json['orderSource'] = $o_list;//销售渠道
  346. $json['orderList'] = $array_order_list; //订单详情
  347. $json['count_list'] = isset($data_count_list) ? $data_count_list : array();
  348. echo json_encode($json);
  349. die;
  350. } else {
  351. echo json_encode(array("code" => "0", "info" => "", "searchInfo" => array()));
  352. }
  353. }
  354. echo json_encode(array("code" => "1", "info" => "出现一些错误", "searchInfo" => array()));
  355. die;